Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
formatIO.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file formatIO.C
1 /*
2 ** formatIO.C
3 **
4 ** Author: $Author: phnxbld $
5 ** Date: $Date: 2009/08/19 12:31:53 $
6 **
7 ** $Log: formatIO.C,v $
8 ** Revision 1.4 2009/08/19 12:31:53 phnxbld
9 ** fix compiler warning
10 **
11 ** Revision 1.3 2005/12/19 16:29:24 pinkenbu
12 ** fix insure bad format warnings
13 **
14 ** Revision 1.2 2002/05/31 22:15:42 purschke
15 ** mlp -- went through the insure report and tried to fix
16 ** every little problem there is, unused variables, dead statements,
17 ** all. It'll probably take another round to complete, but it should get
18 ** rid of most warnings.
19 **
20 ** Revision 1.1.1.1 2000/07/21 01:51:13 purschke
21 ** mlp -- adding the new automakified "basic" module to CVS.
22 **
23 **
24 ** Revision 1.4 1998/12/11 22:02:03 markacs
25 ** (stephen markacs) adding log into cvs tags
26 **
27 */
28 /*
29 ** formatIO.C
30 **
31 **
32 ** Routines to dump frames and packets
33 **
34 */
35 
36 #include <stdio.h>
37 #include "phenixOnline.h"
38 #include "Cframe.h"
39 #include "framePublic.h"
40 #include "packetPublic.h"
41 #include "Cpacket.h"
42 #include "dataBlock.h"
43 #include "formatIO.h"
44 
45 /*
46 ** dumpFrame
47 */
48 
50 {
51  PHDWORD *dump_ptr;
52  UINT nDwords;
53  VALUE_ret result;
54 
55  /*
56  ** Dump the header
57  */
58  result = dumpFrameHdr (frame_ptr);
59  if (result == valueFailure)
60  {
61  printf ("Unknown or invalid Frame header \n");
62  return valueFailure;
63  }
64 
65  /*
66  ** Get number of Dwords in frame contents
67  */
68  nDwords = getFrameDataLength (frame_ptr);
69  dump_ptr = findFrameDataStart (frame_ptr);
70 
71  /*
72  ** For now just dump data + history in Hex format
73  */
74  printf ("Dump of frame data: \n");
75 
76  {
77  /*
78  ** Loop through entire frame dumping each word
79  */
80  UINT iDword;
81 
82  for (iDword = 0; iDword < nDwords; iDword++)
83  printf ("Frame Word %u = %#8x \n", iDword, *dump_ptr++);
84  }
85 
86  return 0;
87 }
88 
90 {
91  PHDWORD *dump_ptr;
92  VALUE_ret result;
93 
94  /*
95  ** Dump the frame header
96  */
97  result = dumpFrameHdr (frame_ptr);
98  if (result == valueFailure)
99  {
100  printf ("Unknown or invalid Frame header \n");
101  return valueFailure;
102  }
103 
104 
105  /*
106  ** Now loop through the frame dumping the packets
107  */
108  dump_ptr = findFirstFramePacket(frame_ptr);
109  while (dump_ptr != ptrFailure)
110  {
111  VALUE_ret result;
112 
113  /*
114  ** Dump the packet.
115  */
116  result = dumpPacket((PACKET_ptr) dump_ptr);
117  if (result == valueFailure)
118  {
119  printf ("Error in frame data -- unknown or invalid packet \n");
120  return valueFailure;
121  }
122 
123  dump_ptr = findNextFramePacket(frame_ptr, dump_ptr);
124  }
125 
126  return 0;
127 }
128 
129 
131 {
132  /*
133  ** Check for valid frame header and correct version
134  */
135  if (!validFrameHdr (frame_ptr))
136  {
137  /*
138  ** We have received an "invalid" frame, report error
139  */
140  return valueFailure;
141  }
142 
143  /*
144  ** Now that we are satisfied that we have a valid header
145  ** define a proper pointer to the current header type
146  */
147 
148  printf ("Frame Mark = %#.8x \n", getFrameMark(frame_ptr));
149 
150  printf ("Frame version = %u, Frame Hdr length = %u \n",
151  getFrameHdrVersion(frame_ptr), getFrameHdrLength(frame_ptr));
152 
153 
154  printf ("data type = %u, Frame type = %u, Source Id = %u \n",
155  getFrameDataType(frame_ptr), getFrameType(frame_ptr),
156  getFrameSourceId(frame_ptr));
157 
158  printf ("Frame length = %u, Error Length = %u, History Length = %u \n",
159  getFrameLength(frame_ptr), getFrameErrorLength(frame_ptr),
160  getFrameHistoryLength(frame_ptr));
161 
162  printf ("Frame status = %#.4x, Frame padding = %u, Align length = %u \n",
163  getFrameStatus(frame_ptr), getFramePadding(frame_ptr),
164  getFrameAlignLength(frame_ptr));
165  {
166  UINT iAlign;
167  /*
168  ** Dump the alignment block
169  */
170 
171  PHDWORD* align_ptr = findFrameAlignBlock(frame_ptr);
172 
173  for (iAlign = 0; iAlign < getFrameAlignLength(frame_ptr); iAlign++)
174  printf ("Alignment block word %u = %#.8x \n", iAlign, *align_ptr++);
175  }
176 
177  return 0;
178 }
179 
180 /*
181 ** Routine to dump the header and contents of a packet
182 */
184 {
185  /*
186  ** Check for valid packet header and correct version
187  */
188  if (!validPacketHdr (packet_ptr)) {
189  /*
190  ** We have received an "invalid" packet, report error
191  */
192  return valueFailure;
193  }
194 
195  /*
196  ** Dump the header
197  */
198  printf ("Packet Length: %u", getPacketLength(packet_ptr));
199 
200  printf ("Packet HDR version: %u, Packet HDR length:%u",
201  getPacketHdrVersion(packet_ptr), getPacketHdrLength(packet_ptr));
202 
203  printf ("Packet Status bits: %#.4x \n", getPacketStatus(packet_ptr));
204 
205  printf ("Packet Ident: %u", getPacketId(packet_ptr));
206 
207  printf ("Endianism: %u, Padding: %u \n", getPacketEndianism(packet_ptr),
208  getPacketPadding(packet_ptr));
209 
210  printf ("Error Length: %u, Debug Length: %u \n",
211  getPacketErrorLength(packet_ptr), getPacketDebugLength(packet_ptr));
212 
213  /*
214  ** Print-out structure-specific information
215  */
216  switch (getPacketStructure(packet_ptr)) {
217  case Unstructured:
218  {
219  UINT wordSize = getUnstructPacketWordSize(packet_ptr);
220  PHDWORD numWords = getUnstructPacketDataLengthWords(packet_ptr);
221 
222  printf ("Unstructured packet, Format: %u, Word Size: %u, Length (words): %u",
223  getUnstructPacketHitFormat(packet_ptr), wordSize, numWords);
224 
225  /*
226  ** Now dump the contents of the packet
227  */
228  {
229  UINT iWord;
230  PHDWORD dataWord = 0; // init not needed but it suppresses compiler warning
231  BYTE *dump_ptr;
232 
233  printf ("Dump of packet data: \n");
234  /*
235  ** Do a word-by-word dump of the packet
236  */
237 
238  dump_ptr = (BYTE*) findPacketDataStart(packet_ptr);
239 
240  for (iWord = 0; iWord < numWords; iWord++) {
241  switch(wordSize)
242  {
243  case 1: { dataWord = *dump_ptr; break; }
244  case 2: {dataWord = *((SWORD*) dump_ptr); break;}
245  case 4: {dataWord = *((PHDWORD*) dump_ptr); break;}
246  default: break;
247  }
248  printf ("Packet Word %u = %#8x \n", iWord, dataWord);
249  dump_ptr+=wordSize;
250  }
251  }
252  }
253  }
254 
255  /*
256  ** Return success
257  */
258  return 0;
259 }
260 
261