StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
EventReader.hh
1 /***************************************************************************
2  * $Id: EventReader.hh,v 1.25 2009/08/24 20:17:20 jml Exp $
3  * Author: M.J. LeVine
4  ***************************************************************************
5  * Description: common definitions for all detectors
6  *
7  *
8  * change log
9  * 06-June-99 MJL added EventInfo struct, changed method getEventInfo()
10  * 06-June-99 MJL added printEventInfo()
11  * 17-June-99 Herb Ward changed the dimension of errstr0 from 50 to 250
12  * 23-Jun-99 MJL add verbose flag and setVerbose() method
13  * 25-Jun-99 MJL added TPCV2P0_CPP_SR::getAsicParams(ASIC_params *);
14  * 09-Jul-99 MJL added EventReader::findBank()
15  * 20-Jul-99 MJL added EventReader::fprintError()
16  * 20-Jul-99 MJL add alternate getEventReader with name of logfile
17  * 20-Jul-99 MJL add overloaded printEventInfo(FILE *)
18  * 28-Dec-99 MJL add alternate InitEventReaders, mapped and unmapped
19  * 31-Jan-00 MJL change to #if !defined ST_NO_NAMESPACES
20  * 27-Jun-00 MJL add token to EventInfo, change access functions
21  *
22  ***************************************************************************
23  * $Log: EventReader.hh,v $
24  * Revision 1.25 2009/08/24 20:17:20 jml
25  * remove 1.57, install correct handling of detectors present
26  *
27  * Revision 1.24 2009/08/24 20:04:43 jml
28  * changing back
29  *
30  * Revision 1.23 2009/08/19 19:06:37 jeromel
31  * Basic fix for gcc 4 (explicit .h include needed)
32  *
33  * Revision 1.22 2009/01/08 22:14:49 fine
34  * teach EventReader tp provide the new daqReader pointer
35  *
36  * Revision 1.21 2004/02/18 20:31:14 ward
37  * There was a big mess. I am trying to fix it.
38  *
39  * Revision 1.19 2003/12/24 21:55:57 perev
40  * Cleanup
41  *
42  * Revision 1.18 2003/09/02 17:55:32 perev
43  * gcc 3.2 updates + WarnOff
44  *
45  * Revision 1.17 2002/12/09 18:54:23 ward
46  * EMC stuff from Subhassis.
47  *
48  * Revision 1.16 2002/10/13 20:43:37 ward
49  * Support for decoding DAQ100 data and writing it into a table.
50  *
51  * Revision 1.15 2002/01/17 18:29:55 jeromel
52  * After I looked at the code, corrections from Akio (pass2).
53  *
54  * Revision 1.14 2002/01/17 17:29:26 jeromel
55  *
56  * Files: CVS: DetectorReader.cxx EventReader.cxx EventReader.hh CVS: RecHeaderFormats.hh CVS: ----------------------------------------------------------------------
57  * Modifications for FPD support
58  *
59  * Revision 1.13 2000/09/15 21:21:17 fisyak
60  * No ulong on HP
61  *
62  * Revision 1.12 2000/08/28 22:19:12 ward
63  * Skip corrupted events. StDaqLib/GENERIC/EventReader.cxx & StDAQMaker/StDAQReader.cxx.
64  *
65  * Revision 1.11 2000/06/27 07:27:25 levine
66  * Added Token to EventInfo struct
67  *
68  * Revision 1.10 2000/02/15 23:24:27 fisyak
69  * Force to compile StPadMonitorMaker
70  *
71  * Revision 1.9 2000/01/31 19:38:51 levine
72  * chamge to #if !defined ST_NO_NAMESPACES
73  *
74  * Revision 1.8 2000/01/11 22:04:40 levine
75  * EventReader.hh // change the header file to include std::string
76  * EventReader.cxx // convert string to char* via c_str() member
77  * (changes from Brian Lasiuk)
78  *
79  * Revision 1.7 2000/01/04 20:54:47 levine
80  * Implemented memory-mapped file access in EventReader.cxx. Old method
81  * (via seeks) is still possible by setting mmapp=0 in
82  *
83  * getEventReader(fd,offset,(const char *)logfile,mmapp);
84  *
85  *
86  * but memory-mapped access is much more effective.
87  *
88  * Revision 1.6 1999/07/26 17:00:03 levine
89  * changes to RICH file organization
90  *
91  * Revision 1.5 1999/07/21 21:33:08 levine
92  *
93  *
94  * changes to include error logging to file.
95  *
96  * There are now 2 constructors for EventReader:
97  *
98  * EventReader();
99  * EventReader(const char *logfilename);
100  *
101  * Constructed with no argument, there is no error logging. Supplying a file name
102  * sends all diagnostic output to the named file (N.B. opens in append mode)
103  *
104  * See example in client.cxx for constructing a log file name based on the
105  * datafile name.
106  *
107  * It is strongly advised to use the log file capability. You can grep it for
108  * instances of "ERROR:" to trap anything noteworthy (i.e., corrupted data files).
109  *
110  * Revision 1.4 1999/07/10 21:31:17 levine
111  * Detectors RICH, EMC, TRG now have their own (defined by each detector) interfaces.
112  * Existing user code will not have to change any calls to TPC-like detector
113  * readers.
114  *
115  * Revision 1.3 1999/07/02 04:37:41 levine
116  * Many changes - see change logs in individual programs
117  *
118  *
119  **************************************************************************/
120 #ifndef EVENTREADER_HH
121 #define EVENTREADER_HH
122 
123 #include <Stiostream.h>
124 
125 #include <sys/types.h>
126 
127 #include <string>
128 #if !defined ST_NO_NAMESPACES
129 using std::string;
130 #endif
131 
132 #if (__GNUC__ >= 4)
133 # include <string.h>
134 # include <stdlib.h>
135 #endif
136 
137 #include "RecHeaderFormats.hh"
138 #include "Error.hh"
139 
140 #define TRUE 1
141 #define FALSE 0
142 
143 
144 
145 // Event Reader header files
146 // This file is included by Offline programs
147 
148 class EventReader;
149 
150 // Support Structures
151 
152 // Information regarding the event
153 struct EventInfo // return from EventReader::getEventInfo()
154 {
155  int EventLength;
156  int Token;
157  unsigned int UnixTime;
158  unsigned int EventSeqNo;
159  unsigned int TrigWord;
160  unsigned int TrigInputWord;
161  unsigned char TPCPresent; // 0
162  unsigned char SVTPresent; // 1
163  unsigned char TOFPresent; // 2
164  unsigned char BTOWPresent; // 3 EMC Barrel Tower
165  unsigned char FPDPresent; // 4
166  unsigned char FTPCPresent; // 5
167  unsigned char EXTPresent; // 6 // ignore
168  unsigned char RICHPresent; // 7
169  unsigned char TRGPresent; // 8
170  unsigned char L3Present; // 9
171  unsigned char SCPresent; // 10 // reserved for Slow Controls
172  unsigned char EXT2Present; // 11 // ignore
173  unsigned char PMDPresent; // 12
174  unsigned char SSDPresent; // 13
175  unsigned char ETOWPresent; // 14 EMC EndCup Tower
176  unsigned char DAQPresent; // 15 // ignore
177  unsigned char FP2Present; // 16 // reserved for future FPD
178  unsigned char PPPresent; // 17// ignore
179  unsigned char BSMDPresent; // 18 EMC Barrel Shower
180  unsigned char ESMDPresent; // 19 EMC Endcup Shower
181 
182  unsigned char EMCPresent; // BTOW || ETOW || BSMD || ESMD
183 
184  void printEventInfo(FILE *fd=stdout);
185 };
186 
187 // Each sequence contains one hit (zero suppressed data)
188 struct Sequence
189 {
190  u_short startTimeBin;
191  u_short Length;
192  u_char *FirstAdc;
193 };
194 
195 // Each pad contains an array of hits for that pad (zero suppressed data)
196 struct Pad
197 {
198  u_char nseq;
199  Sequence *seq;
200 };
201 
202 // A pad row contains an array of pads (zero suppressed data)
203 struct PadRow
204 {
205  u_short npads;
206  struct Pad *pad;
207 };
208 
209 
210 // Gain structure
211 struct Gain
212 {
213  int t0; // t0 * 16
214  int t0_rms; // t0_rms * 16
215  int rel_gain; // rel_gain * 64
216 };
217 
219 {
220  short start_time_bin;
221  short stop_time_bin;
222 };
223 
224 
225 struct Centroids {
226  unsigned short x; // units: 1/64 pad
227  unsigned short t; // units: 1/64 timebin
228 };
229 
230 struct SpacePt {
231  Centroids centroids;
232  unsigned short flags;
233  unsigned short q;
234 };
235 
236 
237 
238 // The sector reader virtual classes
240 {
241 public:
242  virtual int getPadList(int PadRow, u_char **padList)=0;
243  // Fills (*padList[]) with the list of pad numbers containing hits
244  // returns number of pads in (*padList)[]
245  // or negative if call fails
246 
247  virtual int getSequences(int PadRow, int Pad, int *nSeq,
248  Sequence **SeqData)=0;
249  // Fills (*SeqData)[] along with the ADC
250  // buffers pointed to by (*SeqData)[]
251  // Set nSeq to the # of elements in the (*SeqData)[] array
252  // returns 0 if OK.
253  // or negative if call fails
254 
255 // Read the clusters (space points) found in the mezzanine cluster-finder
256  virtual int getSpacePts(int PadRow, int *nSpacePts, SpacePt **SpacePts)=0;
257  // Fills (*SpacePts)[] along with the
258  // buffers pointed to by (*SpacePts)[]
259  // Set nSpacePts to the # of elements in the (*SpacePts)[] array
260  // returns 0 if OK.
261  // or negative if call fails
262 
263  virtual int MemUsed()=0;
264  virtual ~ZeroSuppressedReader() {};
265 };
266 
267 // Reads Raw ADC values
269 {
270 public:
271  virtual int getPadList(int PadRow, unsigned char **padList)=0;
272  // As for Zero suppressed data, this returns
273  // the list of pads for which data can be obtained
274  // Therefore, the padList will always contain all of the
275  // pads in the specified PadRow regardless of the data
276 
277  virtual int getSequences(int PadRow, int Pad, int *nArray, u_char **Array)=0;
278  // Fills (*Array)[] with Raw data
279  // Fills nArray with the # of elements in (*Array)[] (512 bytes / TPC)
280  // returns 0 if OK.
281  // returns negative if call fails
282 
283  virtual int MemUsed()=0;
284  virtual ~ADCRawReader() {};
285 };
286 
287 // Reads the Pedestal values
289 {
290 public:
291  virtual int getPadList(int PadRow, unsigned char **padList)=0;
292  // As for Zero suppressed data, this returns
293  // the list of pads for which data can be obtained
294  // Therefore, the padList will always contain all of the
295  // pads in the specified PadRow regardless of the data
296 
297  virtual int getSequences(int PadRow, int Pad, int *nArray, u_char **Array)=0;
298  // Fills (*Array)[] with Pedestal data
299  // Fills nArray with the # of elements in Array (512 bytes for TPC)
300  // returns 0 if OK.
301  // returns negative if call fails
302 
303  virtual int getNumberOfEvents()=0;
304  // returns the number of events the pedestal run based on
305 
306  virtual int MemUsed()=0;
307  virtual ~PedestalReader() {};
308 };
309 
310 // The RMS pedestal values
312 {
313 public:
314  virtual int getPadList(int PadRow, u_char **padList)=0;
315  // As for Zero suppressed data, this returns
316  // the list of pads for which data can be obtained
317  // Therefore, the (*padList)[] will always contain all of the
318  // pads in the specified PadRow regardless of the data
319 
320  virtual int getSequences(int PadRow, int Pad, int *nArray, u_char **Array)=0;
321  // Fills (*Array)[] with Pedestal RMS data * 16
322  // Fills nArray with the # of elements in (*Array)[] (512 bytes / TPC)
323  // returns 0 if OK.
324  // returns negative if call fails
325 
326  virtual int getNumberOfEvents()=0;
327  // returns the number of events the pedestal run based on
328 
329  virtual int MemUsed()=0;
330  virtual ~PedestalRMSReader() {};
331 };
332 
333 // The gain reader
335 {
336 public:
337  virtual int getGain(int PadRow, int Pad, struct Gain **gain)=0;
338  // sets (*gain) to a valid gain structure pointer
339  // returns 0 if OK
340  // returns negative if call fails
341 
342  virtual int getMeanGain()=0;
343  // returns mean gain
344 
345  virtual int getNumberOfEvents()=0;
346  // returns the number of events the calculation is based upon
347 
348  virtual int MemUsed()=0;
349  virtual ~GainReader() {};
350 };
351 
352 // Reads Cluster Pointer Pairs from the ASIC
354 {
355 public:
356  virtual int getClusters(int PadRow, int Pad, int *nClusters,
357  struct ASIC_Cluster **clusters)=0;
358  // sets (*clusters) to beginning of array of clusters
359  // sets nClusters to the length of the array
360  // returns 0 if OK
361  // returns negative if call fails
362 
363  virtual int getAsicParams(ASIC_params *)=0;
364 
365  virtual int MemUsed()=0;
366  virtual ~CPPReader() {};
367 };
368 
369 // Reads the bad channels
371 {
372 public:
373  virtual int IsBad(int PadRow, int Pad)=0;
374  // returns true if the pad is bad.
375  // returns false if the pad is not bad.
376 
377  virtual int MemUsed()=0;
378  virtual ~BadChannelReader() {};
379 };
380 
381 // Read the front end electronics configuration
383 {
384 public:
385  virtual int FEE_id(int PadRow, int Pad) = 0;
386  // returns FEE_id
387 
388  virtual int MemUsed()=0;
389  virtual ~ConfigReader() {};
390 };
391 
392 
393 // Detector Reader Virtual Class
395 {
396  friend class EventReader;
397  friend class StTPCReader; // Herb Oct 2002 for DAQ100.
398 
399 public:
400  virtual ZeroSuppressedReader *getZeroSuppressedReader(int sector)=0;
401  virtual ADCRawReader *getADCRawReader(int sector)=0;
402  virtual PedestalReader *getPedestalReader(int sector)=0;
403  virtual PedestalRMSReader *getPedestalRMSReader(int sector)=0;
404  virtual GainReader *getGainReader(int sector)=0;
405  virtual CPPReader *getCPPReader(int sector)=0;
406  virtual BadChannelReader *getBadChannelReader(int sector)=0;
407 
408  virtual ~DetectorReader() { };
409 
410  virtual int MemUsed()=0;
411 
412  int errorNo() { return errnum; };
413  string errstr() { return string(errstr0); };
414 
415 protected:
416 
417  // Buffer and index functions for the various readers.
418  // Initially these will do nothing. Add functionality
419  // to increase performance
420  virtual int InformBuffers(ZeroSuppressedReader *, int sector)=0;
421  virtual int InformBuffers(ADCRawReader *,int sector)=0;
422  virtual int InformBuffers(PedestalReader *,int sector)=0;
423  virtual int InformBuffers(PedestalRMSReader *,int sector)=0;
424  virtual int InformBuffers(GainReader *,int sector)=0;
425  virtual int InformBuffers(CPPReader *,int sector)=0;
426  virtual int InformBuffers(BadChannelReader *,int sector)=0;
427  virtual int InformBuffers(ConfigReader *,int sector)=0;
428 
429  virtual int AttachBuffers(ZeroSuppressedReader *, int sector)=0;
430  virtual int AttachBuffers(ADCRawReader *, int sector)=0;
431  virtual int AttachBuffers(PedestalReader *, int sector)=0;
432  virtual int AttachBuffers(PedestalRMSReader *, int sector)=0;
433  virtual int AttachBuffers(GainReader *, int sector)=0;
434  virtual int AttachBuffers(CPPReader *, int sector)=0;
435  virtual int AttachBuffers(BadChannelReader *, int sector)=0;
436  virtual int AttachBuffers(ConfigReader *, int sector)=0;
437 
438  int errnum;
439  char errstr0[250];
440  void *motherPointerBank; // Herb Oct 2002 for DAQ100.
441 
442 private:
443  EventReader *er;
444 };
445 
446 class daqReader;
447 // Event Reader Class
449 {
450 public:
451  EventReader();
452  EventReader(const char *logfilename);
453 
454  void InitEventReader(int fd, long offset, int mmap);
455  // takes open file descripter-offset
456  // works on MAPPED file
457  void InitEventReader(int fd, long offset);
458  // takes open file descripter-offset
459  // works on file
460  void InitEventReader(void *event); // pointer to the event
461  // There is an ambiguity here. The specifier may point to
462  // A logical record header, or it may point to a DATAP Bank
463  // This ambiguity must be resolved by these functions before
464  // They store the DATAP pointer
465 
466  long NextEventOffset();
467  void setVerbose(int); // 0 turns off all internal printout
468  char * findBank(const char *bankid); // navigates to pointer bnk below DATAP
469  int verbose;
470 
471  ~EventReader();
472 
473  char *getDATAP() { return DATAP; };
474  daqReader *getDaqReader() { return fDaqReader; };
475  void setDaqReader(daqReader *rdr) { fDaqReader = rdr; }
476  struct EventInfo getEventInfo();
477  int system_present(Bank_DATAP *datap, int sys);
478 
479  void printEventInfo(FILE *fd=stdout);
480  void fprintError(int err, const char *file, int line, const char *userstring);
481 
482  int runno() { return runnum; }
483  int errorNo() { return errnum; };
484  string errstr() { return string(errstr0); };
485  FILE *logfd; //file handle for log file
486  char err_string[MX_MESSAGE][30];
487 
488  int MemUsed();
489  char eventIsCorrupted(int fdes,long offsetInFile); // Herb, Aug 28 2000
490 
491 protected:
492  char *DATAP; // Pointer to the memory mapped buffer
493  int event_size;
494  daqReader *fDaqReader; // the new reader instance
495  // Detector Buffering Functions
496  int InformBuffers(DetectorReader *) { return FALSE; };
497  // returns false.
498  // later will be used to give EventReader a detectors buffers
499  int AttachBuffers(DetectorReader *) { return FALSE; };
500  // returns false.
501  // later will be used to give buffers back to DetectorReader
502 
503 private:
504  int fd; // -1 if the event is in memory
505  char *MMAPP; // Begining of memory mapping
506 
507  long next_event_offset;
508 
509  int errnum;
510  char errstr0[250];
511  int runnum;
512  char *ConvertToString(unsigned long *input); // Herb, Aug 28 2000
513  void WhereAreThePointers(int *beg,int *end,char *xx); // Herb, Aug 28 2000
514  void Swap4(unsigned long *data); // Herb, Aug 28 2000
515  char BankOrItsDescendentsIsBad(int fd,long currentOffset); // Herb, Aug 28 2000
516  char mLastBank[30];
517  int mWordIndex;
518  // later storage for detector buffers
519 };
520 
521 //#include "../RICH/RICH_Reader.hh"
522 
523 // Declaration for the factories
524 DetectorReader *getDetectorReader(EventReader *, string);
525 EventReader *getEventReader(int fd, long offset, int MMap=1);
526 EventReader *getEventReader(int fd, long offset, const char *logfile, int MMap=1);
527 EventReader *getEventReader(char *event);
528 // declared in RICH_Reader.hh
529 // RICH_Reader *getRichReader(EventReader *er);
530 
531 
532 
533 #endif