-
Notifications
You must be signed in to change notification settings - Fork 26
/
dlist.cc
358 lines (286 loc) · 7.99 KB
/
dlist.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
#include <stdlib.h>
#include <signal.h>
#include <string>
#include "fileEventiterator.h"
#include "rcdaqEventiterator.h"
#include "testEventiterator.h"
#include "oncsEventiterator.h"
#include <stdio.h>
#ifdef HAVE_GETOPT_H
#include "getopt.h"
#endif
#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: dlist -ecntfTOiIh datastream" << std::endl;
COUT << " type dlist -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;
int ii = 77;
COUT << "test output " << 5 << ii << std::endl;
COUT << " dlist lists the packets contained in a given event. The event can come" << std::endl;
COUT << " from any of the standard sources, rcdaq, file, or test stream. " << std::endl;
COUT << " The default is to get the next available event from a file." << std::endl;
COUT << " dlist 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 << " Example:" << std::endl;
COUT << std::endl;
COUT << " -T says the input is a test stream (which always has 3 packets):" << std::endl;
COUT << std::endl;
COUT << " dlist -T" << std::endl;
COUT << " Packet 1001 26 0 (Unformatted) 30006 (ID4EVT)" << std::endl;
COUT << " Packet 1002 16 0 (Unformatted) 30005 (ID2EVT)" << std::endl;
COUT << " Packet 1003 10 0 (Unformatted) 30006 (ID4EVT)" << std::endl;
COUT << std::endl;
COUT << " The -i option causes the event to be identified. " << std::endl;
COUT << std::endl;
COUT << " dlist -T -i" << std::endl;
COUT << " -- Event 1 Run: 1331 length: 68 frames: 1 type: 1 (Data Event)" << std::endl;
COUT << " Packet 1001 26 0 (Unformatted) 30006 (ID4EVT)" << std::endl;
COUT << " Packet 1002 16 0 (Unformatted) 30005 (ID2EVT)" << std::endl;
COUT << " Packet 1003 10 0 (Unformatted) 30006 (ID4EVT)" << std::endl;
COUT << std::endl;
COUT << " List of options: " << std::endl;
COUT << " usage: dlist -ecntfTOih datastream" << 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 << " -t <event type>" << std::endl;
COUT << " -i <print event identity>" << std::endl;
COUT << " -I <print in-depth packet identity>" << 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 << " -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
main(int argc, char *argv[])
{
int c;
int status;
int eventnumber =0;
int countnumber =0;
int repeatcount =1;
int eventtypemin = 1;
int eventtypemax = 7;
int eventtype = 1;
int type_is_a_range = 1;
int verbose = 0;
int ittype = FILEEVENTITERATOR;
int identify = 0;
int fullidentify = 0;
extern char *optarg;
extern int optind;
if (argc < 2) exitmsg();
while ((c = getopt(argc, argv, "n:c:e:t:iIrfhTOv")) != 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 't':
if (*optarg == 'S' || *optarg == 's' )
{
type_is_a_range =1;
eventtypemin=8;
eventtypemax=20;
}
else if (*optarg == 'D' || *optarg == 'd')
{
type_is_a_range =1;
eventtypemin=1;
eventtypemax=7;
}
else if (*optarg == 'A' || *optarg == 'a')
{
type_is_a_range =1;
eventtypemin=1;
eventtypemax=20;
}
else
{
if ( !sscanf(optarg, "%d", &eventtype) ) exitmsg();
type_is_a_range =0;
}
break;
case 'i':
identify = 1;
break;
case 'I':
fullidentify = 1;
break;
case 'T':
ittype = TESTEVENTITERATOR;
break;
case 'f':
ittype = FILEEVENTITERATOR;
break;
case 'r':
ittype = RCDAQEVENTITERATOR;
break;
case 'O':
ittype = ONCSEVENTITERATOR;
break;
case 'v': // verbose
verbose++;
break;
case 'h':
exithelp();
break;
}
if ( eventnumber && countnumber) evtcountexitmsg();
#ifndef WIN32
signal(SIGKILL, sig_handler);
signal(SIGTERM, sig_handler);
signal(SIGINT, sig_handler);
#endif
// 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;
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;
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 i;
Packet *p[10000];
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();
int nw = evt->getPacketList(p, 10000);
for (i=0; i<nw; i++)
{
if (fullidentify) p[i]->fullIdentify();
else p[i]->identify();
delete p[i];
}
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;
}