File indexing completed on 2025-08-03 08:20:44
0001
0002
0003 #include <stdlib.h>
0004 #include <signal.h>
0005 #include <string>
0006
0007 #include "fileEventiterator.h"
0008 #include "rcdaqEventiterator.h"
0009 #include "testEventiterator.h"
0010 #include "oncsEventiterator.h"
0011
0012
0013 #include <stdio.h>
0014
0015 #ifdef HAVE_GETOPT_H
0016 #include "getopt.h"
0017 #endif
0018
0019 #define RCDAQEVENTITERATOR 1
0020 #define FILEEVENTITERATOR 2
0021 #define TESTEVENTITERATOR 3
0022 #define ONCSEVENTITERATOR 4
0023
0024 #if defined(SunOS) || defined(Linux) || defined(OSF1)
0025 void sig_handler(int);
0026 #else
0027 void sig_handler(...);
0028 #endif
0029
0030
0031
0032 Eventiterator *it;
0033
0034
0035 void exitmsg()
0036 {
0037 COUT << "** usage: dlist -ecntfTOiIh datastream" << std::endl;
0038 COUT << " type dlist -h for more help" << std::endl;
0039 exit(0);
0040 }
0041
0042 void evtcountexitmsg()
0043 {
0044 COUT << "** cannot specify both -e and -c!" << std::endl;
0045 COUT << " type dlist -h for more help" << std::endl;
0046 exit(0);
0047 }
0048
0049
0050
0051 void exithelp()
0052 {
0053 COUT << std::endl;
0054 int ii = 77;
0055 COUT << "test output " << 5 << ii << std::endl;
0056
0057 COUT << " dlist lists the packets contained in a given event. The event can come" << std::endl;
0058 COUT << " from any of the standard sources, rcdaq, file, or test stream. " << std::endl;
0059 COUT << " The default is to get the next available event from a file." << std::endl;
0060 COUT << " dlist can optionally identify the event with the -i option." << std::endl;
0061 COUT << " You can request a certain event number with the -e option. " << std::endl;
0062 COUT << " You can ask for a certain event type (data, beg-run, etc) with -t." << std::endl;
0063 COUT << " -t takes a number (e.g. 9 for begin-run) for an exact match," << std::endl;
0064 COUT << " or DATA or SPECIAL to selct data or special events (DATA is default)" << std::endl;
0065 COUT << " you can abbreviate DATA to D or d and SPECIAL to S or s." << std::endl;
0066 COUT << " Example:" << std::endl;
0067 COUT << std::endl;
0068 COUT << " -T says the input is a test stream (which always has 3 packets):" << std::endl;
0069 COUT << std::endl;
0070 COUT << " dlist -T" << std::endl;
0071 COUT << " Packet 1001 26 0 (Unformatted) 30006 (ID4EVT)" << std::endl;
0072 COUT << " Packet 1002 16 0 (Unformatted) 30005 (ID2EVT)" << std::endl;
0073 COUT << " Packet 1003 10 0 (Unformatted) 30006 (ID4EVT)" << std::endl;
0074 COUT << std::endl;
0075 COUT << " The -i option causes the event to be identified. " << std::endl;
0076 COUT << std::endl;
0077 COUT << " dlist -T -i" << std::endl;
0078 COUT << " -- Event 1 Run: 1331 length: 68 frames: 1 type: 1 (Data Event)" << std::endl;
0079 COUT << " Packet 1001 26 0 (Unformatted) 30006 (ID4EVT)" << std::endl;
0080 COUT << " Packet 1002 16 0 (Unformatted) 30005 (ID2EVT)" << std::endl;
0081 COUT << " Packet 1003 10 0 (Unformatted) 30006 (ID4EVT)" << std::endl;
0082 COUT << std::endl;
0083 COUT << " List of options: " << std::endl;
0084 COUT << " usage: dlist -ecntfTOih datastream" << std::endl;
0085 COUT << " -e <event number>" << std::endl;
0086 COUT << " -c <number> get nth event (-e gives event with number n)" << std::endl;
0087 COUT << " -n <number> repeat for n events (0: until end of stream)" << std::endl;
0088 COUT << " -t <event type>" << std::endl;
0089 COUT << " -i <print event identity>" << std::endl;
0090 COUT << " -I <print in-depth packet identity>" << std::endl;
0091 COUT << " -f (stream is a file)" << std::endl;
0092 COUT << " -T (stream is a test stream)" << std::endl;
0093 COUT << " -r (stream is a rcdaq monitoring stream)" << std::endl;
0094 COUT << " -O (stream is a legacy ONCS format file)" << std::endl;
0095 COUT << " -v verbose" << std::endl;
0096 COUT << " -h this message" << std::endl << std::endl;
0097 exit(0);
0098 }
0099
0100 #if defined(SunOS) || defined(Linux) || defined(OSF1)
0101 void sig_handler(int i)
0102 #else
0103 void sig_handler(...)
0104 #endif
0105 {
0106 COUT << "sig_handler: signal seen " << std::endl;
0107 if (it) delete it;
0108 exit(0);
0109 }
0110
0111 int
0112 main(int argc, char *argv[])
0113 {
0114 int c;
0115 int status;
0116
0117 int eventnumber =0;
0118 int countnumber =0;
0119 int repeatcount =1;
0120
0121 int eventtypemin = 1;
0122 int eventtypemax = 7;
0123 int eventtype = 1;
0124 int type_is_a_range = 1;
0125
0126 int verbose = 0;
0127
0128 int ittype = FILEEVENTITERATOR;
0129 int identify = 0;
0130 int fullidentify = 0;
0131
0132 extern char *optarg;
0133 extern int optind;
0134
0135 if (argc < 2) exitmsg();
0136
0137
0138 while ((c = getopt(argc, argv, "n:c:e:t:iIrfhTOv")) != EOF)
0139 switch (c)
0140 {
0141 case 'e':
0142 if ( !sscanf(optarg, "%d", &eventnumber) ) exitmsg();
0143 break;
0144
0145 case 'c':
0146 if ( !sscanf(optarg, "%d", &countnumber) ) exitmsg();
0147 break;
0148
0149 case 'n':
0150 if ( !sscanf(optarg, "%d", &repeatcount) ) exitmsg();
0151 break;
0152
0153 case 't':
0154 if (*optarg == 'S' || *optarg == 's' )
0155 {
0156 type_is_a_range =1;
0157 eventtypemin=8;
0158 eventtypemax=20;
0159 }
0160 else if (*optarg == 'D' || *optarg == 'd')
0161 {
0162 type_is_a_range =1;
0163 eventtypemin=1;
0164 eventtypemax=7;
0165 }
0166 else if (*optarg == 'A' || *optarg == 'a')
0167 {
0168 type_is_a_range =1;
0169 eventtypemin=1;
0170 eventtypemax=20;
0171 }
0172 else
0173 {
0174 if ( !sscanf(optarg, "%d", &eventtype) ) exitmsg();
0175 type_is_a_range =0;
0176 }
0177 break;
0178
0179 case 'i':
0180 identify = 1;
0181 break;
0182
0183 case 'I':
0184 fullidentify = 1;
0185 break;
0186
0187 case 'T':
0188 ittype = TESTEVENTITERATOR;
0189 break;
0190
0191 case 'f':
0192 ittype = FILEEVENTITERATOR;
0193 break;
0194
0195 case 'r':
0196 ittype = RCDAQEVENTITERATOR;
0197 break;
0198
0199 case 'O':
0200 ittype = ONCSEVENTITERATOR;
0201 break;
0202
0203 case 'v':
0204 verbose++;
0205 break;
0206
0207 case 'h':
0208 exithelp();
0209 break;
0210 }
0211
0212
0213
0214 if ( eventnumber && countnumber) evtcountexitmsg();
0215
0216 #ifndef WIN32
0217
0218 signal(SIGKILL, sig_handler);
0219 signal(SIGTERM, sig_handler);
0220 signal(SIGINT, sig_handler);
0221
0222 #endif
0223
0224
0225 it = 0;
0226 status=0;
0227 switch (ittype)
0228 {
0229
0230 case RCDAQEVENTITERATOR:
0231 if ( optind+1>argc)
0232 {
0233 std::string host = "localhost";
0234
0235 if ( getenv("RCDAQHOST") )
0236 {
0237 host = getenv("RCDAQHOST");
0238 }
0239
0240 it = new rcdaqEventiterator(host.c_str(), status);
0241 }
0242 else
0243 {
0244 it = new rcdaqEventiterator(argv[optind], status);
0245 }
0246 break;
0247
0248 case TESTEVENTITERATOR:
0249 it = new testEventiterator();
0250 status =0;
0251 break;
0252
0253 case FILEEVENTITERATOR:
0254 if ( optind+1>argc) exitmsg();
0255 it = new fileEventiterator(argv[optind], status);
0256 break;
0257
0258 case ONCSEVENTITERATOR:
0259 if ( optind+1>argc) exitmsg();
0260 it = new oncsEventiterator(argv[optind], status);
0261 break;
0262
0263 default:
0264 exitmsg();
0265 break;
0266 }
0267
0268 if (status)
0269 {
0270 delete it;
0271 it = 0;
0272 COUT << "Could not open input stream" << std::endl;
0273 exit(1);
0274 }
0275
0276
0277 it->setVerbosity(verbose);
0278
0279
0280
0281 Event *evt;
0282
0283 evt = it->getNextEvent();
0284
0285
0286
0287
0288
0289
0290
0291
0292
0293
0294
0295 int take_this;
0296 int i;
0297
0298 Packet *p[10000];
0299 int count = 0;
0300 int accepted_count = 0;
0301
0302 while (evt)
0303 {
0304 take_this = 1;
0305 count++;
0306
0307 if ( eventnumber )
0308 {
0309 if ( evt->getEvtSequence() == eventnumber)
0310 eventnumber = 0;
0311 else
0312 take_this = 0;
0313 }
0314
0315 if ( countnumber && count < countnumber)
0316 take_this = 0;
0317
0318
0319 if ( type_is_a_range)
0320 {
0321 if ( (evt->getEvtType() < eventtypemin) ||
0322 (evt->getEvtType() > eventtypemax)
0323 ) take_this = 0;
0324 }
0325 else
0326 {
0327 if (evt->getEvtType() != eventtype) take_this = 0;
0328 }
0329
0330 if (take_this)
0331 {
0332 if (identify) evt->identify();
0333
0334 int nw = evt->getPacketList(p, 10000);
0335 for (i=0; i<nw; i++)
0336 {
0337 if (fullidentify) p[i]->fullIdentify();
0338 else p[i]->identify();
0339 delete p[i];
0340 }
0341 delete evt;
0342 if ( repeatcount==0 || ++accepted_count < repeatcount) evt = it->getNextEvent();
0343 else evt = 0;
0344 }
0345 else
0346 {
0347 delete evt;
0348 evt = it->getNextEvent();
0349 }
0350 }
0351
0352 delete it;
0353 it = 0;
0354
0355 return 0;
0356 }
0357
0358