16 #include <boost/algorithm/string.hpp>
17 #include <boost/lexical_cast.hpp>
21 #define RCDAQEVENTITERATOR 1
22 #define FILEEVENTITERATOR 2
23 #define TESTEVENTITERATOR 3
24 #define ONCSEVENTITERATOR 4
26 #if defined(SunOS) || defined(Linux) || defined(OSF1)
38 COUT <<
"** usage: ddump -ecnstdfghiIFTOv datastream" << std::endl;
39 COUT <<
" type ddump -h for more help" << std::endl;
45 COUT <<
"** cannot specify both -e and -c!" << std::endl;
46 COUT <<
" type dlist -h for more help" << std::endl;
55 COUT <<
" ddump dumps selected packets from a given event. The event can come" << std::endl;
56 COUT <<
" from any of the standard sources, ET pool, file, or test stream. " << std::endl;
57 COUT <<
" The default is to get the next available event from a ET pool." << std::endl;
59 COUT <<
" ddump can optionally identify the event with the -i option." << std::endl;
60 COUT <<
" You can request a certain event number with the -e option. " << std::endl;
61 COUT <<
" You can ask for a certain event type (data, beg-run, etc) with -t." << std::endl;
62 COUT <<
" -t takes a number (e.g. 9 for begin-run) for an exact match," << std::endl;
63 COUT <<
" or DATA or SPECIAL to selct data or special events (DATA is default)" << std::endl;
64 COUT <<
" you can abbreviate DATA to D or d and SPECIAL to S or s." << std::endl;
67 COUT <<
" Note: In order to find out which packets are contained in an event, you can" << std::endl;
68 COUT <<
" use the dlist utility." << std::endl;
70 COUT <<
" Example:" << std::endl;
72 COUT <<
" -T says that the input stream is a test stream (where events have 3 " << std::endl;
73 COUT <<
" predictable packets 1001, 1002, and 1003); we dump packet 1002:" << std::endl;
75 COUT <<
" > ddump -p 1002 -T" << std::endl;
76 COUT <<
" Packet 1002 16 0 (Unformatted) 30005 (ID2EVT)" << std::endl;
77 COUT <<
" 0 | 1 2 3 4 5 6 7 8 " << std::endl;
78 COUT <<
" 8 | 9 a b c d e f 10 " << std::endl;
79 COUT <<
" 10 | 11 12 13 14 " << std::endl;
81 COUT <<
" The -i option also lets the event identify itself." << std::endl;
82 COUT <<
" The -I option gets you an in-depth identification of the packets." << std::endl;
85 COUT <<
" > ddump -p 1002 -T -i" << std::endl;
86 COUT <<
" -- Event 1 Run: 1331 length: 68 frames: 1 type: 1 (Data Event)" << std::endl;
87 COUT <<
" Packet 1002 16 0 (Unformatted) 30005 (ID2EVT)" << std::endl;
88 COUT <<
" 0 | 1 2 3 4 5 6 7 8 " << std::endl;
89 COUT <<
" 8 | 9 a b c d e f 10 " << std::endl;
90 COUT <<
" 10 | 11 12 13 14 " << std::endl;
92 COUT <<
" The -F option also causes the frames in the event to be listed." << std::endl;
93 COUT <<
" If you list a particular packet, you will get the frame where" << std::endl;
94 COUT <<
" this packet is in." << std::endl;
98 COUT <<
" The -p option takes a number, a list, or a range of packets" << std::endl;
99 COUT <<
" You can combine ranges and lists:" << std::endl;
100 COUT <<
" > ddump -p 1001 -T -i" << std::endl;
101 COUT <<
" > ddump -p 1001,1002 -T -i" << std::endl;
102 COUT <<
" > ddump -p 1001-1003 -T -i" << std::endl;
103 COUT <<
" > ddump -p 1001-1002,1003 -T -i" << std::endl;
107 COUT <<
" List of options: " << std::endl;
108 COUT <<
" -e <event number>" << std::endl;
109 COUT <<
" -c <number> get nth event (-e gives event with number n)" << std::endl;
110 COUT <<
" -n <number> repeat for n events (0: until end of stream)" << std::endl;
111 COUT <<
" -p <Packet Id>" << std::endl;
112 COUT <<
" -t <event type>" << std::endl;
113 COUT <<
" -i <print event identity>" << std::endl;
114 COUT <<
" -I <print in-depth packet identity (default is short form)>" << std::endl;
115 COUT <<
" -f (stream is a file)" << std::endl;
116 COUT <<
" -T (stream is a test stream)" << std::endl;
117 COUT <<
" -r (stream is a rcdaq monitoring stream)" << std::endl;
118 COUT <<
" -O (stream is a legacy ONCS format file)" << std::endl;
119 COUT <<
" -g use generic dump" << std::endl;
120 COUT <<
" -d numbers are std::decimal (default std::hex) for generic dump" << std::endl;
121 COUT <<
" -o numbers are octal (default std::hex) for generic dump" << std::endl;
122 COUT <<
" -s for a generic dump, send packet raw payloadc to stdout for further manipulation" << std::endl;
123 COUT <<
" -x like -s, but also include the packet header" << std::endl;
124 COUT <<
" -v verbose" << std::endl;
125 COUT <<
" -h this message" << std::endl << std::endl;
129 #if defined(SunOS) || defined(Linux) || defined(OSF1)
135 COUT <<
"sig_handler: signal seen " << std::endl;
142 std::vector<std::string>::const_iterator
it, itr;
143 std::vector<std::string> strs,
r;
147 boost::split(strs,
string, boost::is_any_of(
","));
149 for (it= strs.begin(); it!= strs.end(); ++
it)
151 boost::split(r,*it,boost::is_any_of(
"-"));
154 low = high =boost::lexical_cast<
int>(r[0]);
158 high = boost::lexical_cast<
int>(r[1]);
160 for(i=low;i<=high;++
i)
162 selection.push_back(i);
188 int eventtypemin = 1;
189 int eventtypemax = 7;
191 int type_is_a_range = 1;
198 int fullidentify = 0;
207 std::vector<int> packetSelection;
209 while ((c = getopt(argc, argv,
"n:c:e:p:t:idsxfrghIFTOHEv")) != EOF)
213 if ( !sscanf(optarg,
"%d", &eventnumber) )
exitmsg();
217 if ( !sscanf(optarg,
"%d", &countnumber) )
exitmsg();
221 if ( !sscanf(optarg,
"%d", &repeatcount) )
exitmsg();
231 if (*optarg ==
'S' || *optarg ==
's' )
237 else if (*optarg ==
'A' || *optarg ==
'a')
243 else if (*optarg ==
'D' || *optarg ==
'd')
251 if ( !sscanf(optarg,
"%d", &eventtype) )
exitmsg();
340 if ( getenv(
"RCDAQHOST") )
342 host = getenv(
"RCDAQHOST");
381 COUT <<
"Could not open input stream" << std::endl;
407 int accepted_count = 0;
423 if ( countnumber && count < countnumber)
426 if ( type_is_a_range)
434 if (evt->
getEvtType() != eventtype) take_this = 0;
443 std::vector<int>::const_iterator vit;
444 for (vit= packetSelection.begin(); vit!= packetSelection.end(); ++vit)
450 if (
generic) s->
gdump(dumpstyle);
466 if (
generic) p[
i]->
gdump(dumpstyle);
476 if ( repeatcount==0 || ++accepted_count < repeatcount) evt = it->
getNextEvent();