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