StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
readEvents.C
1 #include <stdio.h>
2 #include <unistd.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include <time.h>
6 
7 // This source relies on the RTS "LOG" machinery to print log messages
8 // of misc. severities...
9 // If you don't like it, uncomment the following line
10 //#define NO_RTS_LOG
11 // This changes the default swwitches when running in the STAR environment
12 //#define STAR_OFFLINE_ENVIRONMENT
13 
14 #include <rtsLog.h>
15 
16 // main include file - resides in daqman.star.bnl.gov:/RTS/include
17 // which MUST be in your include path....
18 
19 #include "daqReader.h"
20 
21 int main(int argc, char *argv[])
22 {
23  rtsLogOutput(RTS_LOG_STDERR);
24  rtsLogLevel(NOTE);
25 
26  daqReader *reader;
27 
28  if(argc > 1) {
29  reader = new daqReader(argv[1]);
30  }
31  else {
32  LOG(ERR,"Need a filename...");
33  exit(0);
34  }
35 
36  if(reader == NULL) {
37  LOG(ERR, "Error constructing daqReader with %s", argv[1]);
38  exit(0);
39  }
40 
41  if(reader->status) {
42  LOG(ERR, "Bad status constructing daqReader with %s",argv[1]);
43  exit(0);
44  }
45 
46  for(int i=1;;i++) {
47  char *mem = reader->get(0,0);
48  if(mem == NULL) {
49  LOG(ERR, "Event %d not valid");
50  exit(0);
51  }
52 
53  if(reader->status == EVP_STAT_EOR) {
54  LOG(NOTE, "End of run");
55  exit(0);
56  }
57 
58  if(reader->status != EVP_STAT_OK) {
59  LOG(ERR, "Error on %dth event...");
60  continue;
61  }
62 
63  LOG(INFO,"**** Event %d (file: %d): bytes %d, token %d, FILE %s",reader->seq, reader->event_number,reader->bytes,
64  reader->token,(int)reader->file_name) ;
65 
66  LOG(NOTE,"**** Event %d: bytes %d, token %d, trg_cmd %d, FILE %s",reader->event_number,reader->bytes,
67  reader->token,reader->trgcmd,(int)reader->file_name) ;
68 
69 
70 
71  // make humanly readable time from the UNIX time...
72  char *stime ;
73  stime = ctime((long int *)&reader->evt_time) ;
74  *(stime+strlen(stime)-1) = 0 ;
75 
76  LOG(NOTE," Trigger Word 0x%02X, time %u (%s), daqbits 0x%04X, evpgroups 0x%04X",reader->trgword,reader->evt_time,(int)stime,reader->daqbits,reader->evpgroups) ;
77 
78 
79  }
80 }