1 /*
2  *  (C) 2001 by Argonne National Laboratory
3  *      See COPYRIGHT in top-level directory.
4  */
5 
6 /*
7  *  @author  Anthony Chan
8  */
9 
10 package logformat.slog2;
11 
12 import base.io.MixedDataInput;
13 import base.io.MixedDataOutput;
14 import base.io.MixedDataIO;
15 import base.io.MixedRandomAccessFile;
16 
17 public class Header implements MixedDataIO
18 {
19     public static final int
20         BYTESIZE = MixedRandomAccessFile.getStringByteSize( Const.version_ID )
21                  + 2  /* num_children_per_node */
22                  + 4  /* treeleaf_bytesize */
23                  + 2  /* max_treedepth */
24                  + 4  /* max_buffer_bytesize */
25                  + 7 * FileBlockPtr.BYTESIZE ;
26 
27     private String          version_ID;
28     private short           num_children_per_node;
29     private int             treeleaf_bytesize;
30     private short           max_treedepth;
31     private int             max_buffer_bytesize;
32 
33     // leave FileBlockPtr type public to allow easy access
34     public  FileBlockPtr    blockptr2categories;
35     public  FileBlockPtr    blockptr2methoddefs;
36     public  FileBlockPtr    blockptr2lineIDmaps;
37     public  FileBlockPtr    blockptr2treeroot;
38     public  FileBlockPtr    blockptr2treedir;
39     public  FileBlockPtr    blockptr2annotations;
40     public  FileBlockPtr    blockptr2postamble;
41 
Header()42     public Header()
43     {
44         // version_ID assignment of Const.version_ID is for SLOG-2 Output API.
45         // But it should NOT affect the Input API, because version_ID is
46         // updated by readObject() later.
47         version_ID              = Const.version_ID;
48         num_children_per_node   = Const.NUM_LEAFS;
49         treeleaf_bytesize       = Const.LEAF_BYTESIZE;
50         max_treedepth           = 0;
51         max_buffer_bytesize     = 0;
52 
53         // Initialize all the FileBlockPtrs so FileBlockPtr.isNULL() == true
54         blockptr2categories     = new FileBlockPtr();
55         blockptr2methoddefs     = new FileBlockPtr();
56         blockptr2lineIDmaps     = new FileBlockPtr();
57         blockptr2treeroot       = new FileBlockPtr();
58         blockptr2treedir        = new FileBlockPtr();
59         blockptr2annotations    = new FileBlockPtr();
60         blockptr2postamble      = new FileBlockPtr();
61 
62 	// System.out.println( "SLOG version = " + version_ID );
63     }
64 
writeObject( MixedDataOutput outs )65     public void writeObject( MixedDataOutput outs )
66     throws java.io.IOException
67     {
68         outs.writeString( version_ID );
69         outs.writeShort( num_children_per_node );
70         outs.writeInt( treeleaf_bytesize );
71         outs.writeShort( max_treedepth );
72         outs.writeInt( max_buffer_bytesize );
73         blockptr2categories.writeObject( outs );
74         blockptr2methoddefs.writeObject( outs );
75         blockptr2lineIDmaps.writeObject( outs );
76         blockptr2treeroot.writeObject( outs );
77         blockptr2treedir.writeObject( outs );
78         blockptr2annotations.writeObject( outs );
79         blockptr2postamble.writeObject( outs );
80     }
81 
Header( MixedDataInput ins )82     public Header( MixedDataInput ins )
83     throws java.io.IOException
84     {
85         this();
86         this.readObject( ins );
87     }
88 
readObject( MixedDataInput ins )89     public void readObject( MixedDataInput ins )
90     throws java.io.IOException
91     {
92         short  max_str_length;
93         max_str_length          = (short) Const.version_ID.length();
94         version_ID              = ins.readStringWithLimit( max_str_length );
95         num_children_per_node   = ins.readShort();
96         treeleaf_bytesize       = ins.readInt();
97         max_treedepth           = ins.readShort();
98         max_buffer_bytesize     = ins.readInt();
99         blockptr2categories.readObject( ins );
100         blockptr2methoddefs.readObject( ins );
101         blockptr2lineIDmaps.readObject( ins );
102         blockptr2treeroot.readObject( ins );
103         blockptr2treedir.readObject( ins );
104         blockptr2annotations.readObject( ins );
105         blockptr2postamble.readObject( ins );
106     }
107 
108     // For SLOG-2 Input API
isSLOG2()109     public boolean isSLOG2()
110     {
111         return version_ID != null && version_ID.startsWith( Const.SLOG2_ID );
112     }
113 
114     // For SLOG-2 Input API
getCompatibleVersionMessage()115     public String getCompatibleVersionMessage()
116     {
117         if (    version_ID != null
118              && version_ID.compareTo( Const.version_ID ) == 0 )
119             return null;
120         else
121             return ( "Incompatible Version IDs detected! \n"
122                    + "The logfile's version ID is "
123                    + version_ID + ",\n"
124                    + "but this input program reads logfile of version "
125                    + Const.version_ID + ".\n" );
126     }
127 
setTreeLeafByteSize( int in_bytesize )128     public void setTreeLeafByteSize( int in_bytesize )
129     {
130         treeleaf_bytesize   = in_bytesize;
131     }
132 
getTreeLeafByteSize()133     public int getTreeLeafByteSize()
134     {
135        	return treeleaf_bytesize;
136     }
137 
setNumChildrenPerNode( short num_leafs )138     public void setNumChildrenPerNode( short num_leafs )
139     {
140         num_children_per_node = num_leafs;
141     }
142 
getNumChildrenPerNode()143     public short getNumChildrenPerNode()
144     {
145         return num_children_per_node;
146     }
147 
setMaxTreeDepth( short in_depth )148     public void setMaxTreeDepth( short in_depth )
149     {
150         max_treedepth = in_depth;
151     }
152 
getMaxTreeDepth()153     public short getMaxTreeDepth()
154     {
155         return max_treedepth;
156     }
157 
setMaxBufferByteSize( int bufsize )158     public void setMaxBufferByteSize( int bufsize )
159     {
160         max_buffer_bytesize = bufsize;
161     }
162 
getMaxBufferByteSize()163     public int  getMaxBufferByteSize()
164     {
165         return max_buffer_bytesize;
166     }
167 
toString()168     public String toString()
169     {
170         StringBuffer rep = new StringBuffer( "\t SLOG-2 Header:\n" );
171         rep.append( "version = " + version_ID + "\n" );
172         rep.append( "NumOfChildrenPerNode = " + num_children_per_node + "\n" );
173         rep.append( "TreeLeafByteSize = " + treeleaf_bytesize + "\n" );
174         rep.append( "MaxTreeDepth = " + max_treedepth + "\n" );
175         rep.append( "MaxBufferByteSize = " + max_buffer_bytesize + "\n" );
176         rep.append( "Categories  is " + blockptr2categories  + "\n" );
177         rep.append( "MethodDefs  is " + blockptr2methoddefs  + "\n" );
178         rep.append( "LineIDMaps  is " + blockptr2lineIDmaps  + "\n" );
179         rep.append( "TreeRoot    is " + blockptr2treeroot    + "\n" );
180         rep.append( "TreeDir     is " + blockptr2treedir     + "\n" );
181         rep.append( "Annotations is " + blockptr2annotations + "\n" );
182         rep.append( "Postamble   is " + blockptr2postamble   + "\n" );
183         return rep.toString();
184     }
185 }
186