1 // @(#)alimdc:$Name$:$Id$
2 // Author: Fons Rademakers 26/11/99
3 // Updated: Dario Favretto 15/04/2003
33 // Forward class declarations
38 // The following enumeration can be used once the kEventTypeMask has been
39 // applied to the raw event type
40 enum EAliRawEventType {
41 kStartOfRun = 1, // START_OF_RUN
42 kEndOfRun = 2, // END_OF_RUN
43 kStartOfRunFiles = 3, // START_OF_RUN_FILES
44 kEndOfRunFiles = 4, // END_OF_RUN_FILES
45 kStartOfBurst = 5, // START_OF_BURST
46 kEndOfBurst = 6, // END_OF_BURST
47 kPhysicsEvent = 7, // PHYSICS_EVENT
48 kCalibrationEvent = 8, // CALIBRATION_EVENT
49 kFormatError = 9 // EVENT_FORMAT_ERROR
52 const Int_t kEventTypeMin = kStartOfRun;
53 const Int_t kEventTypeMax = kFormatError;
55 const UInt_t kEventMagicNumber = 0xDA1E5AFE;
56 const UInt_t kEventMagicNumberSwapped = 0xFE5A1EDA;
59 const Int_t kIdWords = 2;
60 const Int_t kTriggerWords = 2;
61 const Int_t kDetectorWords = 1;
62 const Int_t kAttributeWords = 3;
65 class AliRawEventHeader : public TObject {
68 UInt_t fSize; // size of event in bytes
69 UInt_t fMagic; // magic number used for consistency check
70 UInt_t fHeadLen; // size of header in bytes
71 UInt_t fVersion; // unique version identifier
72 UInt_t fType; // event type
73 UInt_t fRunNb; // run number
74 UInt_t fId[kIdWords]; // id field
75 UInt_t fTriggerPattern[kTriggerWords]; // trigger pattern
76 UInt_t fDetectorPattern[kDetectorWords]; // detector pattern
77 UInt_t fTypeAttribute[kAttributeWords]; // system (0,1) and user (2) attributes
78 UInt_t fLDCId; // LDC id
79 UInt_t fGDCId; // GDC id
82 AliRawEventHeader() { fSize = 0; }
83 virtual ~AliRawEventHeader() { }
85 void *HeaderBegin() { return (void *) &fSize; }
86 Int_t HeaderSize() const { return (Long_t) &fGDCId - (Long_t) &fSize + sizeof(fGDCId); }
87 Bool_t DataIsSwapped() const;
88 Bool_t IsSwapped() const { return (fMagic == kEventMagicNumberSwapped) ? kTRUE : kFALSE; }
89 Bool_t IsValid() const { return IsSwapped() ? kTRUE : ((fMagic == kEventMagicNumber) ? kTRUE : kFALSE); }
92 UInt_t GetEventSize() const { return fSize; }
93 UInt_t GetMagic() const { return fMagic; }
94 UInt_t GetHeaderLength() const { return fHeadLen; }
95 UInt_t GetVersion() const { return fVersion; }
96 UInt_t GetType() const { return fType; }
97 const char *GetTypeName() const;
98 UInt_t GetRunNumber() const { return fRunNb; }
99 UInt_t GetEventInRun() const;
100 const UInt_t *GetId() const { return fId; }
101 const UInt_t *GetTriggerPattern() const { return fTriggerPattern; }
102 const UInt_t *GetDetectorPattern() const { return fDetectorPattern; }
103 const UInt_t *GetTypeAttribute() const { return fTypeAttribute; }
104 UInt_t GetLDCId() const { return fLDCId; }
105 UInt_t GetGDCId() const { return fGDCId; }
107 ClassDef(AliRawEventHeader,1) // Alice raw event header
111 class AliRawEquipmentHeader : public TObject {
114 UInt_t fSize; // number of raw data bytes
115 UInt_t fEquipmentType; // equipment type
116 UInt_t fEquipmentID; // equipment ID
117 UInt_t fTypeAttribute[kAttributeWords]; // system (0,1) and user (2) attributes
118 UInt_t fBasicElementSizeType; // basic element size type
121 AliRawEquipmentHeader() { fSize = 0; }
122 ~AliRawEquipmentHeader() { }
124 void *HeaderBegin() { return (void *) &fSize; }
125 Int_t HeaderSize() const { return (Long_t) &fBasicElementSizeType - (Long_t) &fSize + sizeof(fBasicElementSizeType); }
128 UInt_t GetEquipmentSize() const { return fSize; }
129 UInt_t GetEquipmentType() const { return fEquipmentType; }
130 UInt_t GetId() const { return fEquipmentID; }
131 const UInt_t *GetTypeAttribute() const { return fTypeAttribute; }
132 UInt_t GetBasicSizeType() const { return fBasicElementSizeType; }
134 ClassDef(AliRawEquipmentHeader,1) //Alice equipment header
138 class AliRawData : public TObject {
141 Int_t fSize; // number of raw data bytes
142 Int_t fBufSize; //!actual size of fRawData
143 char *fRawData; //[fSize] raw event data
144 Bool_t fOwner; //!if true object owns fRawData buffer
147 AliRawData() { fSize = fBufSize = 0; fRawData = 0; fOwner = kFALSE; }
148 virtual ~AliRawData() { if (fOwner) delete [] fRawData; }
150 void SetSize(Int_t size) {
151 if (size > fBufSize) {
152 if (fOwner) delete [] fRawData;
153 fRawData = new char [size];
159 void SetBuffer(void *buf, Int_t size) {
160 if (fOwner) delete [] fRawData;
161 fRawData = (char *) buf;
166 Int_t GetSize() const { return fSize; }
167 void *GetBuffer() { return fRawData; }
169 ClassDef(AliRawData,1) // Alice raw event buffer
173 class AliRawEvent : public TObject {
176 Int_t fNSubEvents; // number of valid sub-events
177 AliRawEventHeader *fEvtHdr; // event header object
178 AliRawEquipmentHeader *fEqpHdr; // equipment header
179 AliRawData *fRawData; // raw data container
180 TObjArray *fSubEvents; // sub AliRawEvent's
184 virtual ~AliRawEvent();
186 AliRawEventHeader *GetHeader() const { return fEvtHdr; }
187 AliRawEquipmentHeader *GetEquipmentHeader();
188 AliRawData *GetRawData();
189 Int_t GetNSubEvents() const { return fNSubEvents; }
190 AliRawEvent *NextSubEvent();
193 ClassDef(AliRawEvent,1) // ALICE raw event object
197 class AliStats : public TObject {
200 Int_t fEvents; // number of events in this file
201 Int_t fFirstRun; // run number of first event in file
202 Int_t fFirstEvent; // event number of first event in file
203 Int_t fLastRun; // run number of last event in file
204 Int_t fLastEvent; // event number of last event in file
205 TDatime fBegin; // begin of filling time
206 TDatime fEnd; // end of filling time
207 TString fFileName; // name of file containing this data
208 Double_t fFileSize; // size of file
209 Float_t fCompFactor; // tree compression factor
210 Int_t fCompMode; // compression mode
211 Bool_t fFilter; // 3rd level filter on/off
212 TH1F *fRTHist; // histogram of real-time to process chunck of data
213 Float_t fChunk; //!chunk to be histogrammed
216 AliStats(const char *filename = "", Int_t compmode = 0, Bool_t filter = kFALSE);
218 AliStats &operator=(const AliStats &rhs);
220 void SetEvents(Int_t events) { fEvents = events; }
221 void SetFirstId(Int_t run, Int_t event) { fFirstRun = run; fFirstEvent = event; }
222 void SetLastId(Int_t run, Int_t event) { fLastRun = run; fLastEvent = event; }
223 void SetBeginTime() { fBegin.Set(); }
224 void SetEndTime() { fEnd.Set(); }
225 void SetFileSize(Double_t size) { fFileSize = size; }
226 void SetCompressionFactor(Float_t comp) { fCompFactor = comp; }
227 void Fill(Float_t time);
228 void WriteToDB(AliRawDB *rawdb);
230 Int_t GetEvents() const { return fEvents; }
231 Int_t GetFirstRun() const { return fFirstRun; }
232 Int_t GetFirstEvent() const { return fFirstEvent; }
233 Int_t GetLastRun() const { return fLastRun; }
234 Int_t GetLastEvent() const { return fLastEvent; }
235 TDatime &GetBeginTime() { return fBegin; }
236 TDatime &GetEndTime() { return fEnd; }
237 Double_t GetFileSize() const { return fFileSize; }
238 Int_t GetCompressionMode() const { return fCompMode; }
239 Float_t GetCompressionFactor() const { return fCompFactor; }
240 Bool_t GetFilterState() const { return fFilter; }
241 const char *GetFileName() const { return fFileName; }
242 TH1F *GetRTHist() const { return fRTHist; }
244 ClassDef(AliStats,1) // Statistics object
248 class AliRawDB : public TObject {
251 TFile *fRawDB; // DB to store raw data
252 TTree *fTree; // tree used to store raw data
253 AliRawEvent *fEvent; // AliRawEvent via which data is stored
254 Int_t fCompress; // compression mode (1 default)
255 Double_t fMaxSize; // maximum size in bytes of the raw DB
257 virtual const char *GetFileName();
258 virtual Bool_t FSHasSpace(const char *fs);
259 virtual void MakeTree();
262 AliRawDB(AliRawEvent *event, Double_t maxsize, Int_t compress,
263 Bool_t create = kTRUE);
264 ~AliRawDB() { Close(); }
266 virtual Bool_t Create();
267 virtual void Close();
268 void Fill() { fTree->Fill(); }
269 Bool_t FileFull() { return (fRawDB->GetBytesWritten() > fMaxSize) ?
274 Double_t GetBytesWritten() const { return fRawDB->GetBytesWritten(); }
275 TFile *GetDB() const { return fRawDB; }
276 const char *GetDBName() const { return fRawDB->GetName(); }
277 Int_t GetEvents() const { return (Int_t) fTree->GetEntries(); }
278 AliRawEvent *GetEvent() const { return fEvent; }
279 Float_t GetCompressionFactor() const;
280 Int_t GetCompressionMode() const { return fRawDB->GetCompressionLevel(); }
282 ClassDef(AliRawDB,0) // Raw DB
286 class AliRawRFIODB : public AliRawDB {
289 const char *GetFileName();
292 AliRawRFIODB(AliRawEvent *event, Double_t maxsize, Int_t compress);
293 ~AliRawRFIODB() { Close(); }
297 ClassDef(AliRawRFIODB,0) // Raw DB via RFIO
301 class AliRawRootdDB : public AliRawDB {
304 const char *GetFileName();
307 AliRawRootdDB(AliRawEvent *event, Double_t maxsize, Int_t compress);
308 ~AliRawRootdDB() { Close(); }
312 ClassDef(AliRawRootdDB,0) // Raw DB via rootd
316 class AliRawNullDB : public AliRawDB {
319 const char *GetFileName();
322 AliRawNullDB(AliRawEvent *event, Double_t maxsize, Int_t compress);
323 ~AliRawNullDB() { Close(); }
327 ClassDef(AliRawNullDB,0) // Raw DB to /dev/null
331 class AliTagDB : public TObject {
334 TFile *fTagDB; // DB to store header information only (tag)
335 TTree *fTree; // tree use to store header
336 AliRawEventHeader *fHeader; // header via which data is stored
337 Double_t fMaxSize; // maximum size in bytes of tag DB
339 virtual const char *GetFileName();
342 AliTagDB(AliRawEventHeader *header, Double_t maxsize, Bool_t create = kTRUE);
343 ~AliTagDB() { Close(); }
346 virtual void Close();
347 void Fill() { fTree->Fill(); }
349 { return (fTagDB->GetBytesWritten() > fMaxSize) ? kTRUE : kFALSE; }
353 Double_t GetBytesWritten() const { return fTagDB->GetBytesWritten(); }
354 TFile *GetDB() const { return fTagDB; }
355 const char *GetDBName() const { return fTagDB->GetName(); }
356 AliRawEventHeader *GetHeader() const { return fHeader; }
357 Int_t GetEvents() const { return (Int_t) fTree->GetEntries(); }
358 Float_t GetCompressionFactor() const;
360 ClassDef(AliTagDB,0) // Tag DB
364 class AliTagNullDB : public AliTagDB {
367 const char *GetFileName();
370 AliTagNullDB(AliRawEventHeader *header, Double_t maxsize);
371 ~AliTagNullDB() { Close(); }
375 ClassDef(AliTagNullDB,0) // Tag DB to /dev/null
379 class AliRunDB : public TObject {
382 TFile *fRunDB; // run database
386 ~AliRunDB() { Close(); }
388 void Update(AliStats *stats);
389 void UpdateRDBMS(AliStats *stats);
392 ClassDef(AliRunDB,0) // Run (bookkeeping) DB
396 class AliMDC : public TObject {
399 Int_t fFd; // DATE input stream
400 Int_t fCompress; // compression factor used for raw output DB
401 Int_t fNumEvents; // number of events processed
402 Int_t fDebugLevel; // controls debug print-out
403 Double_t fMaxFileSize; // maximum size of raw output DB
404 Bool_t fUseFifo; // read from fifo, file otherwise
405 Bool_t fUseEb; // use event builder API instead of fifo
406 Bool_t fUseFilter; // use 3rd level trigger filter
407 Bool_t fUseRFIO; // write directly to RFIO file
408 Bool_t fUseRootd; // write directly to rootd file
409 Bool_t fUseDevNull; // write to /dev/null
410 Bool_t fUseLoop; // loop on input source (must be file)
411 Bool_t fStopLoop; // break from endless loop (triggered by SIGUSR1)
413 static Bool_t fgDeleteFiles;
415 Int_t Read(const char *name) { return TObject::Read(name); }
416 Int_t Read(void *buffer, Int_t length);
417 Int_t ReadHeader(AliRawEventHeader &header, void *eb = 0);
418 Int_t ReadEquipmentHeader(AliRawEquipmentHeader &header,
419 Bool_t isSwapped, void *eb = 0);
420 Int_t ReadRawData(AliRawData &raw, Int_t size, void *eb = 0);
421 Int_t DumpEvent(Int_t toRead);
422 Int_t Filter(AliRawData &raw);
425 AliMDC(Int_t fd, Int_t compress, Double_t maxFileSize, Bool_t useFilter,
426 Bool_t useRFIO, Bool_t useROOTD, Bool_t useDEVNULL,
427 Bool_t useLoop, Bool_t delFiles);
431 void SetStopLoop() { fStopLoop = kTRUE; }
432 Bool_t StopLoop() const { return fStopLoop; }
434 void SetDebugLevel(Int_t level) { fDebugLevel = level; }
435 Bool_t GetDebugLevel() const { return fDebugLevel; }
437 static Bool_t DeleteFiles() { return fgDeleteFiles; }
439 ClassDef(AliMDC,0) // MDC processor
442 R__EXTERN AliMDC *gAliMDC;
444 #define ALIDEBUG(level) \
445 if (gAliMDC && gAliMDC->GetDebugLevel() >= (level))