forked from sPHENIX-Collaboration/online_distribution
/
ddump.cc
491 lines (400 loc) · 11.7 KB
/
ddump.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
#include <stdlib.h>
#include <signal.h>
#include <string>
#include "fileEventiterator.h"
#include "testEventiterator.h"
#include "rcdaqEventiterator.h"
#include "oncsEventiterator.h"
#include <stdio.h>
#ifdef HAVE_GETOPT_H
#include "getopt.h"
#endif
#include<vector>
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
#define RCDAQEVENTITERATOR 1
#define FILEEVENTITERATOR 2
#define TESTEVENTITERATOR 3
#define ONCSEVENTITERATOR 4
#if defined(SunOS) || defined(Linux) || defined(OSF1)
void sig_handler(int);
#else
void sig_handler(...);
#endif
// we make it a global variable so the signal; handler can get at it.
Eventiterator *it;
void exitmsg()
{
COUT << "** usage: ddump -ecnstdfghiIFTOv datastream" << std::endl;
COUT << " type ddump -h for more help" << std::endl;
exit(0);
}
void evtcountexitmsg()
{
COUT << "** cannot specify both -e and -c!" << std::endl;
COUT << " type dlist -h for more help" << std::endl;
exit(0);
}
void exithelp()
{
COUT << std::endl;
COUT << " ddump dumps selected packets from a given event. The event can come" << std::endl;
COUT << " from any of the standard sources, ET pool, file, or test stream. " << std::endl;
COUT << " The default is to get the next available event from a ET pool." << std::endl;
COUT << std::endl;
COUT << " ddump can optionally identify the event with the -i option." << std::endl;
COUT << " You can request a certain event number with the -e option. " << std::endl;
COUT << " You can ask for a certain event type (data, beg-run, etc) with -t." << std::endl;
COUT << " -t takes a number (e.g. 9 for begin-run) for an exact match," << std::endl;
COUT << " or DATA or SPECIAL to selct data or special events (DATA is default)" << std::endl;
COUT << " you can abbreviate DATA to D or d and SPECIAL to S or s." << std::endl;
COUT << std::endl;
COUT << " Note: In order to find out which packets are contained in an event, you can" << std::endl;
COUT << " use the dlist utility." << std::endl;
COUT << std::endl;
COUT << " Example:" << std::endl;
COUT << std::endl;
COUT << " -T says that the input stream is a test stream (where events have 3 " << std::endl;
COUT << " predictable packets 1001, 1002, and 1003); we dump packet 1002:" << std::endl;
COUT << std::endl;
COUT << " > ddump -p 1002 -T" << std::endl;
COUT << " Packet 1002 16 0 (Unformatted) 30005 (ID2EVT)" << std::endl;
COUT << " 0 | 1 2 3 4 5 6 7 8 " << std::endl;
COUT << " 8 | 9 a b c d e f 10 " << std::endl;
COUT << " 10 | 11 12 13 14 " << std::endl;
COUT << std::endl;
COUT << " The -i option also lets the event identify itself." << std::endl;
COUT << " The -I option gets you an in-depth identification of the packets." << std::endl;
COUT << std::endl;
COUT << " > ddump -p 1002 -T -i" << std::endl;
COUT << " -- Event 1 Run: 1331 length: 68 frames: 1 type: 1 (Data Event)" << std::endl;
COUT << " Packet 1002 16 0 (Unformatted) 30005 (ID2EVT)" << std::endl;
COUT << " 0 | 1 2 3 4 5 6 7 8 " << std::endl;
COUT << " 8 | 9 a b c d e f 10 " << std::endl;
COUT << " 10 | 11 12 13 14 " << std::endl;
COUT << " The -F option also causes the frames in the event to be listed." << std::endl;
COUT << " If you list a particular packet, you will get the frame where" << std::endl;
COUT << " this packet is in." << std::endl;
COUT << std::endl;
COUT << " The -p option takes a number, a list, or a range of packets" << std::endl;
COUT << " You can combine ranges and lists:" << std::endl;
COUT << " > ddump -p 1001 -T -i" << std::endl;
COUT << " > ddump -p 1001,1002 -T -i" << std::endl;
COUT << " > ddump -p 1001-1003 -T -i" << std::endl;
COUT << " > ddump -p 1001-1002,1003 -T -i" << std::endl;
COUT << std::endl;
COUT << " List of options: " << std::endl;
COUT << " -e <event number>" << std::endl;
COUT << " -c <number> get nth event (-e gives event with number n)" << std::endl;
COUT << " -n <number> repeat for n events (0: until end of stream)" << std::endl;
COUT << " -p <Packet Id>" << std::endl;
COUT << " -t <event type>" << std::endl;
COUT << " -i <print event identity>" << std::endl;
COUT << " -I <print in-depth packet identity (default is short form)>" << std::endl;
COUT << " -f (stream is a file)" << std::endl;
COUT << " -T (stream is a test stream)" << std::endl;
COUT << " -r (stream is a rcdaq monitoring stream)" << std::endl;
COUT << " -O (stream is a legacy ONCS format file)" << std::endl;
COUT << " -g use generic dump" << std::endl;
COUT << " -d numbers are std::decimal (default std::hex) for generic dump" << std::endl;
COUT << " -o numbers are octal (default std::hex) for generic dump" << std::endl;
COUT << " -s for a generic dump, send packet raw payloadc to stdout for further manipulation" << std::endl;
COUT << " -x like -s, but also include the packet header" << std::endl;
COUT << " -v verbose" << std::endl;
COUT << " -h this message" << std::endl << std::endl;
exit(0);
}
#if defined(SunOS) || defined(Linux) || defined(OSF1)
void sig_handler(int i)
#else
void sig_handler(...)
#endif
{
COUT << "sig_handler: signal seen " << std::endl;
if (it) delete it;
exit(0);
}
int rangeParser ( const std::string string, std::vector<int> &selection)
{
std::vector<std::string>::const_iterator it, itr;
std::vector<std::string> strs,r;
// std::vector<int>::const_iterator vit;
int low,high,i;
boost::split(strs,string, boost::is_any_of(","));
for (it= strs.begin(); it!= strs.end(); ++it)
{
boost::split(r,*it,boost::is_any_of("-"));
itr = r.begin();
low = high =boost::lexical_cast<int>(r[0]);
itr++;
if(itr!=r.end())
{
high = boost::lexical_cast<int>(r[1]);
}
for(i=low;i<=high;++i)
{
selection.push_back(i);
}
}
// for(vit= selection.begin(); vit!= selection.end(); ++vit)
// {
// std::cout<<*vit<<std::endl;
// }
return 0;
}
int
main(int argc, char *argv[])
{
if (argc < 2) exitmsg();
int c;
int status;
int eventnumber =0;
int countnumber =0;
int repeatcount =1;
int subeventid =0;
int eventtypemin = 1;
int eventtypemax = 7;
int eventtype = 1;
int type_is_a_range = 1;
int verbose = 0;
int ittype = FILEEVENTITERATOR;
int dumpstyle = EVT_HEXADECIMAL;
int identify = 0;
int fullidentify = 0;
int listframe = 0;
int listHistory = 0;
int listError = 0;
int generic = 0;
extern char *optarg;
extern int optind;
std::vector<int> packetSelection;
while ((c = getopt(argc, argv, "n:c:e:p:t:idsxfrghIFTOHEv")) != EOF)
switch (c)
{
case 'e':
if ( !sscanf(optarg, "%d", &eventnumber) ) exitmsg();
break;
case 'c':
if ( !sscanf(optarg, "%d", &countnumber) ) exitmsg();
break;
case 'n':
if ( !sscanf(optarg, "%d", &repeatcount) ) exitmsg();
break;
case 'p':
// if ( !sscanf(optarg, "%d", &subeventid) ) exitmsg();
if ( rangeParser ( optarg, packetSelection) ) exitmsg();
subeventid=1; // yes, select
break;
case 't':
if (*optarg == 'S' || *optarg == 's' )
{
type_is_a_range =1;
eventtypemin=8;
eventtypemax=20;
}
else if (*optarg == 'A' || *optarg == 'a')
{
type_is_a_range =1;
eventtypemin=1;
eventtypemax=20;
}
else if (*optarg == 'D' || *optarg == 'd')
{
type_is_a_range =1;
eventtypemin=1;
eventtypemax=7;
}
else
{
if ( !sscanf(optarg, "%d", &eventtype) ) exitmsg();
type_is_a_range =0;
}
break;
case 'i':
identify = 1;
break;
case 'I':
fullidentify = 1;
break;
case 'F':
listframe = 1;
break;
case 'H':
listHistory = 1;
break;
case 'E':
listError = 1;
break;
case 'g':
generic = 1;
break;
case 'T':
ittype = TESTEVENTITERATOR;
break;
case 'f':
ittype = FILEEVENTITERATOR;
break;
case 'r':
ittype = RCDAQEVENTITERATOR;
break;
case 'O':
ittype = ONCSEVENTITERATOR;
break;
case 'o':
dumpstyle = EVT_OCTAL;
break;
case 'd':
dumpstyle = EVT_DECIMAL;
break;
case 's':
dumpstyle = EVT_RAW;
break;
case 'x':
dumpstyle = EVT_RAW_WH;
break;
case 'v': // verbose
verbose++;
break;
case 'h':
exithelp();
break;
}
if ( eventnumber && countnumber) evtcountexitmsg();
signal(SIGKILL, sig_handler);
signal(SIGTERM, sig_handler);
signal(SIGINT, sig_handler);
// see if we can open the file
it = 0;
status = 0;
switch (ittype)
{
case RCDAQEVENTITERATOR:
if ( optind+1>argc)
{
std::string host = "localhost";
if ( getenv("RCDAQHOST") )
{
host = getenv("RCDAQHOST");
}
it = new rcdaqEventiterator(host.c_str(), status);
}
else
{
it = new rcdaqEventiterator(argv[optind], status);
}
break;
case TESTEVENTITERATOR:
it = new testEventiterator();
status =0;
break;
case FILEEVENTITERATOR:
if ( optind+1>argc) exitmsg();
it = new fileEventiterator(argv[optind], status);
break;
case ONCSEVENTITERATOR:
if ( optind+1>argc) exitmsg();
it = new oncsEventiterator(argv[optind], status);
break;
status = 1;
break;
default:
exitmsg();
break;
}
if (status)
{
delete it;
it = 0;
COUT << "Could not open input stream" << std::endl;
exit(1);
}
// set the verbosity of the iterator
it->setVerbosity(verbose);
// ok. now go through the events
Event *evt;
Packet *s;
int i;
evt = it->getNextEvent();
// first check if our requested event number is already past:
// if ( eventnumber && evt->getEvtSequence() > eventnumber)
// {
// COUT << "requested Event number " << eventnumber<<
// " but found " << evt->getEvtSequence() << " already" << std::endl;
// delete evt;
// evt = 0;
// }
int take_this;
int count = 0;
int accepted_count = 0;
while (evt) // as long as there is a next event...
{
take_this = 1;
count++;
if ( eventnumber )
{
if ( evt->getEvtSequence() == eventnumber)
eventnumber = 0;
else
take_this = 0;
}
if ( countnumber && count < countnumber)
take_this = 0;
if ( type_is_a_range)
{
if ( (evt->getEvtType() < eventtypemin) ||
(evt->getEvtType() > eventtypemax)
) take_this = 0;
}
else
{
if (evt->getEvtType() != eventtype) take_this = 0;
}
if (take_this)
{
if (identify) evt->identify();
if ( subeventid)
{
std::vector<int>::const_iterator vit;
for (vit= packetSelection.begin(); vit!= packetSelection.end(); ++vit)
{
if ( (s = evt->getPacket(*vit)) ) // get the subevent
{
if (listframe) evt->listFrame (*vit);
if (fullidentify) s->fullIdentify();
if (generic) s->gdump(dumpstyle);
else s->dump();
if (listHistory) evt->listHistory();
if (listError) evt->listError();
delete s;
}
}
}
else
{
if (listframe) evt->listFrame();
Packet *p[10000];
int nw = evt->getPacketList(p, 10000);
for (i=0; i<nw; i++)
{
if (fullidentify) p[i]->fullIdentify();
if (generic) p[i]->gdump(dumpstyle);
else p[i]->dump();
delete p[i];
}
if (listHistory) evt->listHistory();
if (listError) evt->listError();
}
delete evt;
if ( repeatcount==0 || ++accepted_count < repeatcount) evt = it->getNextEvent();
else evt = 0;
}
else
{
delete evt;
evt = it->getNextEvent(); // try to get the next event
}
}
delete it;
it = 0;
return 0;
}