StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
daqReader.h
1 #ifndef _DAQ_READERCLASS_HH_
2 #define _DAQ_READERCLASS_HH_
3 
4 #include <ctype.h>
5 #include <sys/types.h>
6 #include "daqConfig.h"
7 // Define the old EVP_READER-based interface:
8 
9 #define DAQ_LEGACY_DEF(xxx) \
10 struct _NAME2_(xxx,_t) _NAME1_(xxx);\
11  \
12 int _NAME2_(xxx,Reader)(char *m) { \
13  if(!m) return -1; \
14  daqReader *rrr = (daqReader *)m; \
15  daq_dta *dd= rrr->det( _QUOTE_(xxx))->get("legacy"); \
16  int size = 0; \
17  if (dd && (size = dd->iterate())) { \
18  memcpy(&_NAME1_(xxx),dd->Void,dd->get_size_t());} \
19  return (dd && size) ? dd->ncontent: 0; }
20 
21 #define DAQ_LEGACY_DECL(xxx) \
22 extern struct _NAME2_(xxx,_t) _NAME1_(xxx);\
23 extern int _NAME2_(xxx,Reader)(char *mem)
24 struct DATAP;
25 struct rccnf ;
26 struct gbPayload;
27 struct gbPayload_0x02;
28 struct gbPayload_0x01a;
29 struct gbPayload_0x01;
30 
31 class sfs_index;
32 //class rts_reader;
33 class MemMap;
34 class daq_det ;
35 
36 enum Input_Type { none, live, file, pointer, dir };
37 
38 #ifdef RTS_PROJECT_PP
39 #define _EVP_HOSTNAME "ppdaq1.pp2pp.bnl.gov"
40 #else
41 #define _EVP_HOSTNAME "evp.starp.bnl.gov"
42 #endif
43 
44 #define EVP_PORT 8020
45 
46 
47 #define EVP_TYPE_0 1
48 #define EVP_TYPE_PHYS 2
49 #define EVP_TYPE_SPEC 4
50 #define EVP_TYPE_ANY (EVP_TYPE_PHYS|EVP_TYPE_SPEC|EVP_TYPE_0)
51 #define EVT_TYPE_MON 8
52 
53 
54 #define EVP_STAT_OK 0
55 #define EVP_STAT_EOR (-1)
56 #define EVP_STAT_EVT (-2)
57 #define EVP_STAT_CRIT (-3)
58 #define EVP_STAT_LOG (-4)
59 
60 typedef unsigned int u_int;
61 typedef unsigned long long int u_longlong;
62 typedef unsigned long long int UINT64;
63 
64 struct SummaryInfo {
65  u_int token ; // current token
66  u_int evt_time ; // time in UNIX seconds
67  u_int detectors ; // detectors present bit mask according to DAQ!
68  UINT64 detectors64;
69  u_int daqbits;
70  u_int daqbits_l1;
71  u_int daqbits_l2;
72  u_int evpgroups;
73  u_int evp_daqbits;
74  u_int flags;
75 
76  u_int trgword;
77  u_int trgcmd; // current trigger command
78  u_int daqcmd; // current DAQ command
79 
80  u_int L1summary[2];
81  u_int L2summary[2];
82  u_int L3summary[4];
83 
84  u_int seq ; // event sequence from EVB ????
85 };
86 
87 class daqReader {
88  public:
89 
90  // Filename can be:
91  // NULL --> read from event pool
92  // Directory --> read from each file "1, 2, 3, .... N" in the directory
93  // filename --> .daq file
94  // space separated files --> read from each file in turn
95  //
96  daqReader(char *buffer, int size);
97  daqReader(const char *fname) ;
98  ~daqReader(void) ;
99 
100  void init();
101 
102  int trgIds[64];
103  int trgIdsSet;
104  int trgIdsNotPresent;
105 
106  static const int DAQ_READER_MAX_DETS = 48 ;
107  daq_det *dets[DAQ_READER_MAX_DETS] ;
108  daq_det *pseudo_dets[DAQ_READER_MAX_DETS] ;
109 
110  daq_det *det(const char *det) ;
111  void insert(daq_det *which, int rts_id) ;
112  void de_insert(int rts_id) ;
113  void Make() ;
114  char *get_sfs_name(const char *snippet=0) ; // returns the full name of the SFS
115  char *get(int which, int type=EVP_TYPE_ANY) ;
116  char *skip_then_get(int numToSkip, int num, int type=EVP_TYPE_ANY);
117  // The following are the descriptors and pointers defining the event
118 
119 
120  // These variables describe the "input source"
121  //
122  // live -> file is: file_name = evp_disk/base_dir/run#/evt#
123  // file -> file is: file_name
124  // pointer -> file is at: *data_memory
125  // dir -> file is at: file_name = fname/evt#
126  char *data_memory;
127  int data_size;
128 
129  char evp_disk[256];
130  char fname[256] ; // This is the name argument of the evpReader
131  char file_name[256] ; // fully qualified file name containing evt data
132  long long int file_size ; // size of the file in bytes
133  int desc ; // file descriptor
134 
135  int isevp; // backward compatability...
136  int IsEvp() { return (input_type == live); };
137  daqReader *rts() const { return (daqReader *)this; } // to simplify the offline transition
138 
139  // Return the offlineId for a daqId. If present in file...
140  int getOfflineId(int daqId);
141 
142  // These variables describe the event storage
143  //
144  // All events are eventually mapped into memory
145  // The event_memory points to the first LRHD/DATAP/FILE record
146  // whatever it might be...
147  char *event_memory;
148  int event_size; // size of the current event measured from beginning of memmap
149  u_int bytes ; // size of the current event measured from beginning of datap
150 
151  int getDetectorSize(const char *str); // actually gets the size of any arbitrary file/directory...
152 
153  long long int evt_offset_in_file;
154 
155  char *mem; // a datap pointer if applicable...
156  sfs_index *sfs; // the sfs reader object... (if no sfs only contains "/");
157 
158  // These variables describe the characteristics of the event
159  //
160 
161  // year: pre-2006 - .daq format
162  // 2007 - .daq format, tpx bank in sfs format
163  // 2008 - .sfs format/compat .daq format/ + legacy bank in .daq format
164  // 2009- - .sfs format + legacy bank in .daq format
165  //
166 
167  //int lrhd_offset;
168  //int datap_offset;
169 
170  int sfs_lastevt;
171 
172  //char *getSFSEventNumber();
173 
174  int setMmap(int flag) ; // flag=1 - enable memory mapping
175  int setOpen(int flag) ; // flag=1 - enable file open
176  int setLog(int flag) ; // flag=1 - enable logging...
177  char *setEvpDisk(char *fs) ; // sets the local directory name where the evp.star disks
178  // are mounted
179 
180 
181  int writeCurrentEventToDisk(char *fname);
182  int status ; // 0 OK, all others should disregard the event!
183 
184  // all the variables below are valid ONLY if the status is 0!!!
185 
186  // These parameters are used for the evp reads with event number non-zero
187  // readall_lastevt --
188  u_int readall_rundone;
189  u_int readall_lastevt;
190  u_int readall_run;
191  void readall_reset() { readall_rundone = 0; readall_lastevt = 0; readall_run=0; };
192 
193 
194  u_int event_number ; // current event in the evp or file
195  u_int total_events ; // total number of events seen by this object so far
196 
197 
198 
199 
200 
201  u_int run ; // current run number
202 
203  u_int evb_type ; // event type (only from ACTIVE run)
204  u_int evb_cou ; // total events in this run (only from ACTIVE run)
205  u_int evb_type_cou ; // total events of the above type in this run (only from ACTIVE run)
206 
207  u_int token ; // current token
208  u_int trgcmd ; // current trigger command
209  u_int daqcmd ; // current DAQ command
210  u_int trgword ; // the Trigger Word
211  u_int phyword ; // the Physics Word
212  u_int daqbits ; // "offline" bits aka L3 summary...
213  u_int daqbits_l1; // triggers satisfying l1
214  u_int daqbits_l2; // triggers satisfying l2
215 
216  u_longlong daqbits64;
217  u_longlong daqbits64_l1;
218  u_longlong daqbits64_l2;
219 
220  u_int evpgroups ; // evp groups aka L3 summary[2]
221  u_int flags ;
222 
223  u_int evt_time ; // time in UNIX seconds
224  u_int seq ; // event sequence from EVB
225  u_int detectors ; // detectors present bit mask according to DAQ!
226  UINT64 detectors64;
227 
228  float triggerFrequency; // rhic frequency
229  u_int triggerFrequency_valid;
230 
231  int streaming_seq; // -1 if not streaming
232  int streaming_evb; // evb + seq is the key here, there are multiple seq per run
233  char streaming_node[12];
234 
235  u_int detector_bugs ; // for per-detector bug tracing i.e. FY12 UU future protection TPX bug
236  UINT64 detector_bugs64;
237 
238  u_int detsinrun ;
239  UINT64 detsinrun64;
240  u_int evpgroupsinrun;
241 
242  // copies from the trigger data format...
243  // the meanings potentially change year to year...
244  u_int L1summary[2];
245  u_int L2summary[2];
246  u_int L3summary[4];
247 
248  int fixDatapSummary(DATAP *datap);
249  const char *getInputType();
250  int getNextEventFilename(int num, int type);
251  int getNextEventFilenameFromLive(int type);
252  int getNextEventFilenameFromDir(int eventNum);
253  int openEventFile();
254  int addToEventSize(int sz);
255  int getEventSize();
256 
257  int hackSummaryInfo();
258  int copySummaryInfoIn(SummaryInfo *info);
259  int fillSummaryInfo(SummaryInfo *info, DATAP *datap);
260  int fillSummaryInfo(SummaryInfo *info, gbPayload *gbPayload);
261 
262  // history...
263  int fillSummaryInfo_v03(SummaryInfo *info, gbPayload *gbPayload);
264  int fillSummaryInfo_v02(SummaryInfo *info, gbPayload_0x02 *gbPayload);
265  int fillSummaryInfo_v01a(SummaryInfo *info, gbPayload_0x01a *gbPayload);
266  int fillSummaryInfo_v01(SummaryInfo *info, gbPayload_0x01 *gbPayload);
267 
268  MemMap *memmap;
269 
270  int readNextFutureSummaryInfo(SummaryInfo *info);
271 
272  char *EVP_HOSTNAME;
273 
274  void setCopyOnWriteMapping();
275 
276 
277 
278  private: // one shouldn't care...
279 
280  int map_prot;
281  int map_flags;
282 
283  char _static_str_return_[256];
284  int crit_cou;
285 
286  int reconnect(void) ;
287 
288  char _evp_basedir_[40];
289  char _last_evp_dir_[40];
290  int do_mmap ;
291  int do_open ;
292  int do_log ;
293 
294 
295  int issued ;
296  int last_issued ; // time
297 
298  int task ;
299 
300 
301  int evpDesc ; // message queue desc.
302  // file variables
303 
304  rccnf *runconfig;
305 
306  int getStatusBasedEventDelay();
307  Input_Type input_type;
308 
309  int allnumeric(char *str)
310  {
311  int i=0;
312  while(str[i] != '\0') {
313  if(!isdigit(str[i])) return 0;
314  i++;
315  }
316  return 1;
317  }
318 
319 } ;
320 
321 class MemMap {
322  public:
323  MemMap();
324  ~MemMap();
325 
326  char *mem;
327  char *map(int fd, long long int _offset, int _size, int map_prot, int map_flags);
328  void unmap();
329 
330  long long int offset;
331  int size;
332 
333  int real_mem; // map real mem?
334  char *map_real_mem(char *buffer, int _size);
335  private:
336  int page_size;
337  long long int actual_offset;
338  char *actual_mem_start;
339  int actual_size;
340  int fd;
341 };
342 
343 
344 
345 #endif
Definition: cfgutil.h:4