Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
prdfcheck.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file prdfcheck.cc
1 
2 
3 #include "buffer.h"
4 #include <cstdio>
5 #include <iostream>
6 #include <iomanip>
7 #include <cstdlib>
8 #include <csignal>
9 
10 #include <unistd.h>
11 #include <sys/types.h>
12 #include <sys/stat.h>
13 #include <fcntl.h>
14 
15 
16 
17 void exitmsg()
18 {
19  std::cout << "** usage: prdfcheck [-v] file name" << std::endl;
20  exit(0);
21 }
22 
23 
24 int
25 main(int argc, char *argv[])
26 {
27 
28  unsigned int buffer[8*8192];
29 
30  int fd;
31 
32  fd = open(argv[1], O_RDONLY | O_LARGEFILE);
33 
34  int needs_swap = 0;
35  int length;
36  int ip;
37 
38  int total_read = 0;
39 
40  int xc;
41 
42  xc = read ( fd, (char *)buffer, 8192);
43  // total_read++;
44  while ( xc == 8192 )
45  {
46 
47  ip = 8192;
48 
49 
50  if ( buffer[1] == BUFFERMARKER ||
51  buffer::u4swap(buffer[1]) == BUFFERMARKER ||
52  buffer[1] == ONCSBUFFERMARKER ||
53  buffer::u4swap(buffer[1]) == ONCSBUFFERMARKER ||
54  buffer[1] == GZBUFFERMARKER ||
55  buffer::u4swap(buffer[1]) == GZBUFFERMARKER ||
56  buffer[1] == LZO1XBUFFERMARKER ||
57  buffer::u4swap(buffer[1]) == LZO1XBUFFERMARKER )
58  {
59 
60 
61  if ( buffer::u4swap(buffer[1]) == BUFFERMARKER ||
62  buffer::u4swap(buffer[1]) == ONCSBUFFERMARKER ||
63  buffer::u4swap(buffer[1]) == GZBUFFERMARKER ||
64  buffer::u4swap(buffer[1]) == LZO1XBUFFERMARKER )
65  {
66  needs_swap = 1;
67  }
68 
69  if (needs_swap)
70  {
71  length = buffer::i4swap(buffer[0]);
72  }
73  else
74  {
75  length = buffer[0];
76  }
77 
78  if ( needs_swap )
79  {
80  std::cout << "buffer at record " << std::setw(4) << total_read
81  << " length = " << std::setw(7) << buffer::i4swap(buffer[0])
82  << " " << (buffer::i4swap(buffer[0]) + 8192)/8192
83  << " marker = " << std::hex << buffer::i4swap(buffer[1]) << std::dec << " ";
84  }
85  else
86  {
87  std::cout << "buffer at record " << std::setw(4) << total_read
88  << " length = " << std::setw(7) << buffer[0]
89  << " " << ( buffer[0] + 8192)/8192
90  << " marker = " << std::hex << buffer[1] << std::dec << " ";
91  }
92 
93  if ( buffer[1] == BUFFERMARKER ||
94  buffer::u4swap(buffer[1]) == BUFFERMARKER ) std::cout << "Uncomp. Marker" << std::endl;
95  else if ( buffer[1] == ONCSBUFFERMARKER ||
96  buffer::u4swap(buffer[1]) == ONCSBUFFERMARKER ) std::cout << "sPHENIX Marker" << std::endl;
97  else if ( buffer[1] == GZBUFFERMARKER ||
98  buffer::u4swap(buffer[1]) == GZBUFFERMARKER ) std::cout << "GZIP Marker" << std::endl;
99  else if ( buffer[1] == LZO1XBUFFERMARKER ||
100  buffer::u4swap(buffer[1]) == LZO1XBUFFERMARKER )
101  {
102  std::cout << "LZO Marker ";
103  std::cout << " Or.length: " << buffer[3];
104  float ratio = 100.*buffer[0]/buffer[3];
105  std::cout << " " << ratio << "%";
106 
107  int e = buffer[2] & 0xffff;
108  int atp = (buffer[2] >> 16) & 0xffff;
109  if ( atp)
110  {
111  std::cout << " events: " << e << " from ATP " << atp << std::endl;
112  }
113  else
114  {
115  std::cout << std::endl;
116  }
117  }
118 
119 
120  while ( ip < length)
121  {
122  xc = read ( fd, (char *)buffer, 8192);
123  if ( xc < 8192 )
124  {
125  std::cout << "end or error in read loop at rec " << total_read << std::endl;
126  exit(1);
127  }
128  total_read++;
129  ip+= 8192;
130  }
131  xc = read ( fd, (char *)buffer, 8192);
132  if ( xc < 8192 )
133  {
134  std::cout << "legitimate end or error at rec " << total_read << std::endl;
135  exit(1);
136  }
137  total_read++;
138 
139  }
140 
141  else
142  {
143  if (needs_swap)
144  {
145  std::cout << "found a non-buffer start..."<< total_read
146  << " length = " << buffer::u4swap(buffer[0]) << " marker = " << std::hex << buffer::i4swap(buffer[1]) << std::dec ;
147  }
148  else
149  {
150  std::cout << "found a non-buffer start..."<< total_read
151  << " length = " << buffer[0] << " marker = " << std::hex << buffer[1] << std::dec ;
152  }
153 
154  int skipped = 0;
155  while ( buffer[1] != BUFFERMARKER &&
156  buffer::u4swap(buffer[1]) != BUFFERMARKER &&
157  buffer[1] != GZBUFFERMARKER &&
158  buffer::u4swap(buffer[1]) != GZBUFFERMARKER )
159  {
160  xc = read ( fd, (char *)buffer, 8192);
161  if ( xc < 8192 )
162  {
163  std::cout << "end or error in salavge loop at rec " << total_read << std::endl;
164  exit(1);
165  }
166  total_read++;
167  skipped++;
168  }
169  std::cout << " Skipped " << skipped << std::endl;
170  }
171  }
172  return 0;
173 
174 }
175