]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RAW/AliRawEvent.h
corrections to obey coding conventions
[u/mrichter/AliRoot.git] / RAW / AliRawEvent.h
1 #ifndef ALIRAWEVENT_H
2 #define ALIRAWEVENT_H
3 // @(#)alimdc:$Name$:$Id$
4 // Author: Fons Rademakers  26/11/99
5 // Updated: Dario Favretto  15/04/2003
6
7
8 #ifndef ROOT_TObject
9 #include <TObject.h>
10 #endif
11
12 #ifndef ROOT_TDatime
13 #include <TDatime.h>
14 #endif
15
16 #ifndef ROOT_TString
17 #include <TString.h>
18 #endif
19
20 #ifndef ROOT_TFile
21 #include <TFile.h>
22 #endif
23
24 #ifndef ROOT_TTree
25 #include <TTree.h>
26 #endif
27
28 #ifndef ROOT_TH1
29 #include <TH1.h>
30 #endif
31
32
33 // Forward class declarations
34 class AliRawDB;
35
36
37 // The following enumeration can be used once the kEventTypeMask has been
38 // applied to the raw event type
39 enum EAliRawEventType {
40    kStartOfRun =       1,    // START_OF_RUN
41    kEndOfRun =         2,    // END_OF_RUN
42    kStartOfRunFiles =  3,    // START_OF_RUN_FILES
43    kEndOfRunFiles =    4,    // END_OF_RUN_FILES
44    kStartOfBurst =     5,    // START_OF_BURST
45    kEndOfBurst =       6,    // END_OF_BURST
46    kPhysicsEvent =     7,    // PHYSICS_EVENT
47    kCalibrationEvent = 8,    // CALIBRATION_EVENT
48    kFormatError =      9     // EVENT_FORMAT_ERROR
49 };
50
51 const Int_t kEventTypeMin = kStartOfRun;
52 const Int_t kEventTypeMax = kFormatError;
53
54 const UInt_t kEventMagicNumber        = 0xDA1E5AFE;
55 const UInt_t kEventMagicNumberSwapped = 0xFE5A1EDA;
56
57 // Type sizes
58 const Int_t kIdWords        = 2;
59 const Int_t kTriggerWords   = 2;
60 const Int_t kDetectorWords  = 1;
61 const Int_t kAttributeWords = 3;
62
63
64 class AliRawEventHeader : public TObject {
65
66 public:
67    AliRawEventHeader() { fSize = 0; }
68    virtual ~AliRawEventHeader() { }
69
70    void         *HeaderBegin() { return (void *) &fSize; }
71    Int_t         HeaderSize() const { return (Long_t) &fGDCId - (Long_t) &fSize + sizeof(fGDCId); }
72    Bool_t        DataIsSwapped() const;
73    Bool_t        IsSwapped() const { return (fMagic == kEventMagicNumberSwapped) ? kTRUE : kFALSE; }
74    Bool_t        IsValid() const { return IsSwapped() ? kTRUE : ((fMagic == kEventMagicNumber) ? kTRUE : kFALSE); }
75    void          Swap();
76
77    UInt_t        GetEventSize() const { return fSize; }
78    UInt_t        GetMagic() const { return fMagic; }
79    UInt_t        GetHeaderLength() const { return fHeadLen; }
80    UInt_t        GetVersion() const { return fVersion; }
81    UInt_t        GetType() const { return fType; }
82    const char   *GetTypeName() const;
83    UInt_t        GetRunNumber() const { return fRunNb; }
84    UInt_t        GetEventInRun() const;
85    const UInt_t *GetId() const { return fId; }
86    const UInt_t *GetTriggerPattern() const { return fTriggerPattern; }
87    const UInt_t *GetDetectorPattern() const { return fDetectorPattern; }
88    const UInt_t *GetTypeAttribute() const { return fTypeAttribute; }
89    UInt_t        GetLDCId() const { return fLDCId; }
90    UInt_t        GetGDCId() const { return fGDCId; }
91
92 private:
93    UInt_t fSize;          // size of event in bytes
94    UInt_t fMagic;         // magic number used for consistency check
95    UInt_t fHeadLen;       // size of header in bytes
96    UInt_t fVersion;       // unique version identifier
97    UInt_t fType;          // event type
98    UInt_t fRunNb;         // run number
99    UInt_t fId[kIdWords];  // id field
100    UInt_t fTriggerPattern[kTriggerWords];   // trigger pattern
101    UInt_t fDetectorPattern[kDetectorWords]; // detector pattern
102    UInt_t fTypeAttribute[kAttributeWords];  // system (0,1) and user (2) attributes
103    UInt_t fLDCId;         // LDC id
104    UInt_t fGDCId;         // GDC id
105
106    ClassDef(AliRawEventHeader,1)  // Alice raw event header
107 };
108
109
110 class AliRawEquipmentHeader : public TObject {
111
112 public:
113    AliRawEquipmentHeader() { fSize = 0; }
114    ~AliRawEquipmentHeader() { }
115
116    void         *HeaderBegin() { return (void *) &fSize; }
117    Int_t         HeaderSize() const { return (Long_t) &fBasicElementSizeType - (Long_t) &fSize + sizeof(fBasicElementSizeType); }
118    void          Swap();
119
120    UInt_t        GetEquipmentSize() const { return fSize; }
121    UInt_t        GetEquipmentType() const { return fEquipmentType; }
122    UInt_t        GetId() const { return fEquipmentID; }
123    const UInt_t *GetTypeAttribute() const { return fTypeAttribute; }
124    UInt_t        GetBasicSizeType() const { return fBasicElementSizeType; }
125
126 private:
127    UInt_t fSize;                            // number of raw data bytes
128    UInt_t fEquipmentType;                   // equipment type
129    UInt_t fEquipmentID;                     // equipment ID
130    UInt_t fTypeAttribute[kAttributeWords];  // system (0,1) and user (2) attributes
131    UInt_t fBasicElementSizeType;            // basic element size type
132
133    ClassDef(AliRawEquipmentHeader,1) //Alice equipment header
134 };
135
136
137 class AliRawData : public TObject {
138
139 public:
140    AliRawData() { fSize = fBufSize = 0; fRawData = 0; fOwner = kTRUE; }
141    AliRawData(const AliRawData& rawData): TObject(rawData) 
142      {Fatal("AliRawData", "copy constructor not implemented");};
143    AliRawData& operator = (const AliRawData& /*rawData*/) {
144      Fatal("operator =", "assignment operator not implemented"); 
145      return *this;
146    };
147    virtual ~AliRawData() { if (fOwner) delete [] fRawData; }
148
149    inline void SetSize(Int_t size);
150    inline void  SetBuffer(void *buf, Int_t size);
151    Int_t    GetSize() const { return fSize; }
152    void    *GetBuffer() { return fRawData; }
153
154 private:
155    Int_t   fSize;         // number of raw data bytes
156    Int_t   fBufSize;      //!actual size of fRawData
157    char   *fRawData;      //[fSize] raw event data
158    Bool_t  fOwner;        //!if true object owns fRawData buffer
159
160    ClassDef(AliRawData,1)  // Alice raw event buffer
161 };
162
163 void AliRawData::SetSize(Int_t size) 
164 {
165   if (size > fBufSize) {
166     if (fOwner) delete [] fRawData;
167     fRawData = new char [size];
168     fBufSize = size;
169     fOwner   = kTRUE;
170   }
171   fSize = size;
172 }
173
174 void AliRawData::SetBuffer(void *buf, Int_t size) 
175 {
176   if (fOwner) delete [] fRawData;
177   fRawData = (char *) buf;
178   fBufSize = size;
179   fSize    = size;
180   fOwner   = kFALSE;
181 }
182
183
184 class AliRawEvent : public TObject {
185
186 public:
187    AliRawEvent();
188    AliRawEvent(const AliRawEvent& rawEvent): TObject(rawEvent) 
189      {Fatal("AliRawEvent", "copy constructor not implemented");};
190    AliRawEvent& operator = (const AliRawEvent& /*rawEvent*/) {
191      Fatal("operator =", "assignment operator not implemented"); 
192      return *this;
193    };
194    virtual ~AliRawEvent();
195
196    AliRawEventHeader     *GetHeader();
197    AliRawEquipmentHeader *GetEquipmentHeader();
198    AliRawData            *GetRawData();
199    Int_t                  GetNSubEvents() const { return fNSubEvents; }
200    AliRawEvent           *NextSubEvent();
201    AliRawEvent           *GetSubEvent(Int_t index) const;
202    void                   Reset();
203
204 private:
205    Int_t                  fNSubEvents;  // number of valid sub-events
206    AliRawEventHeader     *fEvtHdr;      // event header object
207    AliRawEquipmentHeader *fEqpHdr;      // equipment header
208    AliRawData            *fRawData;     // raw data container
209    TObjArray             *fSubEvents;   // sub AliRawEvent's
210
211    ClassDef(AliRawEvent,1)  // ALICE raw event object
212 };
213
214
215 class AliStats : public TObject {
216
217 public:
218    AliStats(const char *filename = "", Int_t compmode = 0, Bool_t filter = kFALSE);
219    AliStats(const AliStats& stats): TObject(stats) 
220      {Fatal("AliStats", "copy constructor not implemented");};
221    virtual ~AliStats();
222    AliStats &operator=(const AliStats &rhs);
223
224    void SetEvents(Int_t events) { fEvents = events; }
225    void SetFirstId(Int_t run, Int_t event) { fFirstRun = run; fFirstEvent = event; }
226    void SetLastId(Int_t run, Int_t event) { fLastRun = run; fLastEvent = event; }
227    void SetBeginTime() { fBegin.Set(); }
228    void SetEndTime() { fEnd.Set(); }
229    void SetFileSize(Double_t size) { fFileSize = size; }
230    void SetCompressionFactor(Float_t comp) { fCompFactor = comp; }
231    void Fill(Float_t time);
232    void WriteToDB(AliRawDB *rawdb);
233
234    Int_t       GetEvents() const { return fEvents; }
235    Int_t       GetFirstRun() const { return fFirstRun; }
236    Int_t       GetFirstEvent() const { return fFirstEvent; }
237    Int_t       GetLastRun() const { return fLastRun; }
238    Int_t       GetLastEvent() const { return fLastEvent; }
239    TDatime    &GetBeginTime() { return fBegin; }
240    TDatime    &GetEndTime() { return fEnd; }
241    Double_t    GetFileSize() const { return fFileSize; }
242    Int_t       GetCompressionMode() const { return fCompMode; }
243    Float_t     GetCompressionFactor() const { return fCompFactor; }
244    Bool_t      GetFilterState() const { return fFilter; }
245    const char *GetFileName() const { return fFileName; }
246    TH1F       *GetRTHist() const { return fRTHist; }
247
248 private:
249    Int_t    fEvents;     // number of events in this file
250    Int_t    fFirstRun;   // run number of first event in file
251    Int_t    fFirstEvent; // event number of first event in file
252    Int_t    fLastRun;    // run number of last event in file
253    Int_t    fLastEvent;  // event number of last event in file
254    TDatime  fBegin;      // begin of filling time
255    TDatime  fEnd;        // end of filling time
256    TString  fFileName;   // name of file containing this data
257    Double_t fFileSize;   // size of file
258    Float_t  fCompFactor; // tree compression factor
259    Int_t    fCompMode;   // compression mode
260    Bool_t   fFilter;     // 3rd level filter on/off
261    TH1F    *fRTHist;     // histogram of real-time to process chunck of data
262    Float_t  fChunk;      //!chunk to be histogrammed
263
264    ClassDef(AliStats,1)  // Statistics object
265 };
266
267
268 class AliRawDB : public TObject {
269
270 public:
271    AliRawDB(AliRawEvent *event, Double_t maxsize, Int_t compress,
272             Bool_t create = kTRUE);
273    AliRawDB(const AliRawDB& rawDB): TObject(rawDB) 
274      {Fatal("AliRawDB", "copy constructor not implemented");};
275    AliRawDB& operator = (const AliRawDB& /*rawDB*/) {
276      Fatal("operator =", "assignment operator not implemented"); 
277      return *this;
278    };
279    virtual ~AliRawDB() { Close(); }
280
281    virtual const char *GetOpenOption() const { return "RECREATE"; }
282    virtual Bool_t      Create();
283    virtual void        Close();
284    void                Fill() { fTree->Fill(); }
285    Bool_t              FileFull() { return (fRawDB->GetBytesWritten() > fMaxSize) ?
286                                     kTRUE : kFALSE; }
287
288    Bool_t       NextFile();
289
290    Double_t     GetBytesWritten() const { return fRawDB->GetBytesWritten(); }
291    TFile       *GetDB() const { return fRawDB; }
292    const char  *GetDBName() const { return fRawDB->GetName(); }
293    Int_t        GetEvents() const { return (Int_t) fTree->GetEntries(); }
294    AliRawEvent *GetEvent() const { return fEvent; }
295    Float_t      GetCompressionFactor() const;
296    Int_t        GetCompressionMode() const { return fRawDB->GetCompressionLevel(); }
297
298 protected:
299    TFile         *fRawDB;         // DB to store raw data
300    TTree         *fTree;          // tree used to store raw data
301    AliRawEvent   *fEvent;         // AliRawEvent via which data is stored
302    Int_t          fCompress;      // compression mode (1 default)
303    Double_t       fMaxSize;       // maximum size in bytes of the raw DB
304
305    virtual const char *GetFileName() const;
306    virtual Bool_t      FSHasSpace(const char *fs) const;
307    virtual void        MakeTree();
308
309    ClassDef(AliRawDB,0)  // Raw DB
310 };
311
312
313 class AliRawRFIODB : public AliRawDB {
314
315 public:
316    AliRawRFIODB(AliRawEvent *event, Double_t maxsize, Int_t compress);
317    ~AliRawRFIODB() { Close(); }
318
319    void Close();
320
321 private:
322    const char *GetFileName() const;
323
324    ClassDef(AliRawRFIODB,0)  // Raw DB via RFIO
325 };
326
327
328 class AliRawCastorDB : public AliRawDB {
329
330 public:
331    AliRawCastorDB(AliRawEvent *event, Double_t maxsize, Int_t compress);
332    ~AliRawCastorDB() { Close(); }
333
334    const char *GetOpenOption() const { return "-RECREATE"; }
335    void        Close();
336
337 private:
338    const char *GetFileName() const;
339
340    ClassDef(AliRawCastorDB,0)  // Raw DB via CASTOR and rootd
341 };
342
343
344 class AliRawRootdDB : public AliRawDB {
345
346 public:
347    AliRawRootdDB(AliRawEvent *event, Double_t maxsize, Int_t compress);
348    ~AliRawRootdDB() { Close(); }
349
350    void Close();
351
352 private:
353    const char *GetFileName() const;
354
355    ClassDef(AliRawRootdDB,0)  // Raw DB via rootd
356 };
357
358
359 class AliRawNullDB : public AliRawDB {
360
361 public:
362    AliRawNullDB(AliRawEvent *event, Double_t maxsize, Int_t compress);
363    ~AliRawNullDB() { Close(); }
364
365    void Close();
366
367 private:
368    const char *GetFileName() const;
369
370    ClassDef(AliRawNullDB,0)  // Raw DB to /dev/null
371 };
372
373
374 class AliTagDB : public TObject {
375
376 public:
377    AliTagDB(AliRawEventHeader *header, Double_t maxsize, Bool_t create = kTRUE);
378    AliTagDB(const AliTagDB& tagDB): TObject(tagDB) 
379      {Fatal("AliTagDB", "copy constructor not implemented");};
380    AliTagDB& operator = (const AliTagDB& /*tagDB*/) {
381      Fatal("operator =", "assignment operator not implemented"); 
382      return *this;
383    };
384    virtual ~AliTagDB() { Close(); }
385
386    Bool_t          Create();
387    virtual void    Close();
388    void            Fill() { fTree->Fill(); }
389    Bool_t          FileFull()
390             { return (fTagDB->GetBytesWritten() > fMaxSize) ? kTRUE : kFALSE; }
391
392    Bool_t          NextFile();
393
394    Double_t           GetBytesWritten() const { return fTagDB->GetBytesWritten(); }
395    TFile             *GetDB() const { return fTagDB; }
396    const char        *GetDBName() const { return fTagDB->GetName(); }
397    AliRawEventHeader *GetHeader() const { return fHeader; }
398    Int_t              GetEvents() const { return (Int_t) fTree->GetEntries(); }
399    Float_t            GetCompressionFactor() const;
400
401 protected:
402    TFile             *fTagDB;     // DB to store header information only (tag)
403    TTree             *fTree;      // tree use to store header
404    AliRawEventHeader *fHeader;    // header via which data is stored
405    Double_t           fMaxSize;   // maximum size in bytes of tag DB
406
407    virtual const char *GetFileName() const;
408
409    ClassDef(AliTagDB,0)  // Tag DB
410 };
411
412
413 class AliTagNullDB : public AliTagDB {
414
415 public:
416    AliTagNullDB(AliRawEventHeader *header, Double_t maxsize);
417    ~AliTagNullDB() { Close(); }
418
419    void Close();
420
421 private:
422    const char *GetFileName() const;
423
424    ClassDef(AliTagNullDB,0)   // Tag DB to /dev/null
425 };
426
427
428 class AliRunDB : public TObject {
429
430 public:
431    AliRunDB(Bool_t noLocalDB = kFALSE);
432    AliRunDB(const AliRunDB& runDB): TObject(runDB) 
433      {Fatal("AliRunDB", "copy constructor not implemented");};
434    AliRunDB& operator = (const AliRunDB& /*runDB*/) {
435      Fatal("operator =", "assignment operator not implemented"); 
436      return *this;
437    };
438    ~AliRunDB() { Close(); }
439
440    void Update(AliStats *stats);
441    void UpdateRDBMS(AliStats *stats);
442    void UpdateAliEn(AliStats *stats);
443    void Close();
444
445 private:
446    TFile  *fRunDB;     // run database
447
448    ClassDef(AliRunDB,0)  // Run (bookkeeping) DB
449 };
450
451
452 class AliMDC : public TObject {
453
454 public:
455    enum EWriteMode { kLOCAL, kRFIO, kROOTD, kCASTOR, kDEVNULL };
456
457    AliMDC(Int_t fd, Int_t compress, Double_t maxFileSize, Bool_t useFilter,
458           EWriteMode mode, Bool_t useLoop, Bool_t delFiles);
459    ~AliMDC() { }
460
461    Int_t  Run();
462    void   SetStopLoop() { fStopLoop = kTRUE; }
463    Bool_t StopLoop() const { return fStopLoop; }
464
465    void   SetDebugLevel(Int_t level) { fDebugLevel = level; }
466    Int_t  GetDebugLevel() const { return fDebugLevel; }
467
468    static Bool_t DeleteFiles() { return fgDeleteFiles; }
469
470 private:
471    Int_t      fFd;          // DATE input stream
472    Int_t      fCompress;    // compression factor used for raw output DB
473    Int_t      fNumEvents;   // number of events processed
474    Int_t      fDebugLevel;  // controls debug print-out
475    Double_t   fMaxFileSize; // maximum size of raw output DB
476    EWriteMode fWriteMode;   // write mode (local, rfio, rootd, castor, /dev/null)
477    Bool_t     fUseFifo;     // read from fifo, file otherwise
478    Bool_t     fUseEb;       // use event builder API instead of fifo
479    Bool_t     fUseFilter;   // use 3rd level trigger filter
480    Bool_t     fUseLoop;     // loop on input source (must be file)
481    Bool_t     fStopLoop;    // break from endless loop (triggered by SIGUSR1)
482
483    static Bool_t fgDeleteFiles;  // flag for deletion of files
484
485    Int_t     Read(const char *name) { return TObject::Read(name); }
486    Int_t     Read(void *buffer, Int_t length);
487    Int_t     ReadHeader(AliRawEventHeader &header, void *eb = 0);
488    Int_t     ReadEquipmentHeader(AliRawEquipmentHeader &header,
489                                  Bool_t isSwapped, void *eb = 0);
490    Int_t     ReadRawData(AliRawData &raw, Int_t size, void *eb = 0);
491    Int_t     DumpEvent(Int_t toRead);
492    Int_t     Filter(AliRawData &raw);
493
494    ClassDef(AliMDC,0)  // MDC processor
495 };
496
497 R__EXTERN AliMDC *gAliMDC;
498
499 #define ALIDEBUG(level) \
500    if (gAliMDC && (gAliMDC->GetDebugLevel() >= (level)))
501
502 #endif