3 // @(#)alimdc:$Name$:$Id$
4 // Author: Fons Rademakers 26/11/99
5 // Updated: Dario Favretto 15/04/2003
33 // Forward class declarations
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
51 const Int_t kEventTypeMin = kStartOfRun;
52 const Int_t kEventTypeMax = kFormatError;
54 const UInt_t kEventMagicNumber = 0xDA1E5AFE;
55 const UInt_t kEventMagicNumberSwapped = 0xFE5A1EDA;
58 const Int_t kIdWords = 2;
59 const Int_t kTriggerWords = 2;
60 const Int_t kDetectorWords = 1;
61 const Int_t kAttributeWords = 3;
64 class AliRawEventHeader : public TObject {
67 AliRawEventHeader() { fSize = 0; }
68 virtual ~AliRawEventHeader() { }
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); }
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; }
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
106 ClassDef(AliRawEventHeader,1) // Alice raw event header
110 class AliRawEquipmentHeader : public TObject {
113 AliRawEquipmentHeader() { fSize = 0; }
114 ~AliRawEquipmentHeader() { }
116 void *HeaderBegin() { return (void *) &fSize; }
117 Int_t HeaderSize() const { return (Long_t) &fBasicElementSizeType - (Long_t) &fSize + sizeof(fBasicElementSizeType); }
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; }
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
133 ClassDef(AliRawEquipmentHeader,1) //Alice equipment header
137 class AliRawData : public TObject {
140 AliRawData() { fSize = fBufSize = 0; fRawData = 0; fOwner = kTRUE; }
141 virtual ~AliRawData() { if (fOwner) delete [] fRawData; }
143 inline void SetSize(Int_t size);
144 inline void SetBuffer(void *buf, Int_t size);
145 Int_t GetSize() const { return fSize; }
146 void *GetBuffer() { return fRawData; }
149 Int_t fSize; // number of raw data bytes
150 Int_t fBufSize; //!actual size of fRawData
151 char *fRawData; //[fSize] raw event data
152 Bool_t fOwner; //!if true object owns fRawData buffer
154 AliRawData(const AliRawData &); // not implemented, usage causes
155 void operator=(const AliRawData &); // link time error
157 ClassDef(AliRawData,1) // Alice raw event buffer
160 void AliRawData::SetSize(Int_t size)
162 if (size > fBufSize) {
163 if (fOwner) delete [] fRawData;
164 fRawData = new char [size];
171 void AliRawData::SetBuffer(void *buf, Int_t size)
173 if (fOwner) delete [] fRawData;
174 fRawData = (char *) buf;
181 class AliRawEvent : public TObject {
185 virtual ~AliRawEvent();
187 AliRawEventHeader *GetHeader();
188 AliRawEquipmentHeader *GetEquipmentHeader();
189 AliRawData *GetRawData();
190 Int_t GetNSubEvents() const { return fNSubEvents; }
191 AliRawEvent *NextSubEvent();
192 AliRawEvent *GetSubEvent(Int_t index) const;
196 Int_t fNSubEvents; // number of valid sub-events
197 AliRawEventHeader *fEvtHdr; // event header object
198 AliRawEquipmentHeader *fEqpHdr; // equipment header
199 AliRawData *fRawData; // raw data container
200 TObjArray *fSubEvents; // sub AliRawEvent's
202 AliRawEvent(const AliRawEvent &); // not implemented, usage causes
203 void operator=(const AliRawEvent &); // link time error
205 ClassDef(AliRawEvent,1) // ALICE raw event object
209 class AliStats : public TObject {
212 AliStats(const char *filename = "", Int_t compmode = 0, Bool_t filter = kFALSE);
214 AliStats &operator=(const AliStats &rhs);
216 void SetEvents(Int_t events) { fEvents = events; }
217 void SetFirstId(Int_t run, Int_t event) { fFirstRun = run; fFirstEvent = event; }
218 void SetLastId(Int_t run, Int_t event) { fLastRun = run; fLastEvent = event; }
219 void SetBeginTime() { fBegin.Set(); }
220 void SetEndTime() { fEnd.Set(); }
221 void SetFileSize(Double_t size) { fFileSize = size; }
222 void SetCompressionFactor(Float_t comp) { fCompFactor = comp; }
223 void Fill(Float_t time);
224 void WriteToDB(AliRawDB *rawdb);
226 Int_t GetEvents() const { return fEvents; }
227 Int_t GetFirstRun() const { return fFirstRun; }
228 Int_t GetFirstEvent() const { return fFirstEvent; }
229 Int_t GetLastRun() const { return fLastRun; }
230 Int_t GetLastEvent() const { return fLastEvent; }
231 TDatime &GetBeginTime() { return fBegin; }
232 TDatime &GetEndTime() { return fEnd; }
233 Double_t GetFileSize() const { return fFileSize; }
234 Int_t GetCompressionMode() const { return fCompMode; }
235 Float_t GetCompressionFactor() const { return fCompFactor; }
236 Bool_t GetFilterState() const { return fFilter; }
237 const char *GetFileName() const { return fFileName; }
238 TH1F *GetRTHist() const { return fRTHist; }
241 Int_t fEvents; // number of events in this file
242 Int_t fFirstRun; // run number of first event in file
243 Int_t fFirstEvent; // event number of first event in file
244 Int_t fLastRun; // run number of last event in file
245 Int_t fLastEvent; // event number of last event in file
246 TDatime fBegin; // begin of filling time
247 TDatime fEnd; // end of filling time
248 TString fFileName; // name of file containing this data
249 Double_t fFileSize; // size of file
250 Float_t fCompFactor; // tree compression factor
251 Int_t fCompMode; // compression mode
252 Bool_t fFilter; // 3rd level filter on/off
253 TH1F *fRTHist; // histogram of real-time to process chunck of data
254 Float_t fChunk; //!chunk to be histogrammed
256 AliStats(const AliStats &); // not implemented
258 ClassDef(AliStats,1) // Statistics object
262 class AliRawDB : public TObject {
265 AliRawDB(AliRawEvent *event, Double_t maxsize, Int_t compress,
266 Bool_t create = kTRUE);
267 virtual ~AliRawDB() { Close(); }
269 virtual const char *GetOpenOption() const { return "RECREATE"; }
270 virtual Int_t GetNetopt() const { return 0; }
271 virtual Bool_t Create();
272 virtual void Close();
273 void Fill() { fTree->Fill(); }
274 Bool_t FileFull() { return (fRawDB->GetBytesWritten() > fMaxSize) ?
279 Double_t GetBytesWritten() const { return fRawDB->GetBytesWritten(); }
280 TFile *GetDB() const { return fRawDB; }
281 const char *GetDBName() const { return fRawDB->GetName(); }
282 Int_t GetEvents() const { return (Int_t) fTree->GetEntries(); }
283 AliRawEvent *GetEvent() const { return fEvent; }
284 Float_t GetCompressionFactor() const;
285 Int_t GetCompressionMode() const { return fRawDB->GetCompressionLevel(); }
288 TFile *fRawDB; // DB to store raw data
289 TTree *fTree; // tree used to store raw data
290 AliRawEvent *fEvent; // AliRawEvent via which data is stored
291 Int_t fCompress; // compression mode (1 default)
292 Double_t fMaxSize; // maximum size in bytes of the raw DB
294 virtual const char *GetFileName() const;
295 virtual Bool_t FSHasSpace(const char *fs) const;
296 virtual void MakeTree();
299 AliRawDB(const AliRawDB &); // not implemented, usage causes
300 void operator=(const AliRawDB &); // link time error
302 ClassDef(AliRawDB,0) // Raw DB
306 class AliRawRFIODB : public AliRawDB {
309 AliRawRFIODB(AliRawEvent *event, Double_t maxsize, Int_t compress);
310 ~AliRawRFIODB() { Close(); }
315 const char *GetFileName() const;
317 ClassDef(AliRawRFIODB,0) // Raw DB via RFIO
321 class AliRawCastorDB : public AliRawDB {
324 AliRawCastorDB(AliRawEvent *event, Double_t maxsize, Int_t compress);
325 ~AliRawCastorDB() { Close(); }
327 const char *GetOpenOption() const { return "-RECREATE"; }
328 Int_t GetNetopt() const { return 0; }
332 const char *GetFileName() const;
334 ClassDef(AliRawCastorDB,0) // Raw DB via CASTOR and rootd
338 class AliRawRootdDB : public AliRawDB {
341 AliRawRootdDB(AliRawEvent *event, Double_t maxsize, Int_t compress);
342 ~AliRawRootdDB() { Close(); }
347 const char *GetFileName() const;
349 ClassDef(AliRawRootdDB,0) // Raw DB via rootd
353 class AliRawNullDB : public AliRawDB {
356 AliRawNullDB(AliRawEvent *event, Double_t maxsize, Int_t compress);
357 ~AliRawNullDB() { Close(); }
362 const char *GetFileName() const;
364 ClassDef(AliRawNullDB,0) // Raw DB to /dev/null
368 class AliTagDB : public TObject {
371 AliTagDB(AliRawEventHeader *header, Double_t maxsize, Bool_t create = kTRUE);
372 virtual ~AliTagDB() { Close(); }
375 virtual void Close();
376 void Fill() { fTree->Fill(); }
378 { return (fTagDB->GetBytesWritten() > fMaxSize) ? kTRUE : kFALSE; }
382 Double_t GetBytesWritten() const { return fTagDB->GetBytesWritten(); }
383 TFile *GetDB() const { return fTagDB; }
384 const char *GetDBName() const { return fTagDB->GetName(); }
385 AliRawEventHeader *GetHeader() const { return fHeader; }
386 Int_t GetEvents() const { return (Int_t) fTree->GetEntries(); }
387 Float_t GetCompressionFactor() const;
390 TFile *fTagDB; // DB to store header information only (tag)
391 TTree *fTree; // tree use to store header
392 AliRawEventHeader *fHeader; // header via which data is stored
393 Double_t fMaxSize; // maximum size in bytes of tag DB
395 virtual const char *GetFileName() const;
398 AliTagDB(const AliTagDB &); // not implemented, usage causes
399 void operator=(const AliTagDB &); // link time error
401 ClassDef(AliTagDB,0) // Tag DB
405 class AliTagNullDB : public AliTagDB {
408 AliTagNullDB(AliRawEventHeader *header, Double_t maxsize);
409 ~AliTagNullDB() { Close(); }
414 const char *GetFileName() const;
416 ClassDef(AliTagNullDB,0) // Tag DB to /dev/null
420 class AliRunDB : public TObject {
423 AliRunDB(Bool_t noLocalDB = kFALSE);
424 ~AliRunDB() { Close(); }
426 void Update(AliStats *stats);
427 void UpdateRDBMS(AliStats *stats);
428 void UpdateAliEn(AliStats *stats);
432 TFile *fRunDB; // run database
434 AliRunDB(const AliRunDB &); // not implemented, usage causes
435 void operator=(const AliRunDB &); // link time error
437 ClassDef(AliRunDB,0) // Run (bookkeeping) DB
441 class AliMDC : public TObject {
444 enum EWriteMode { kLOCAL, kRFIO, kROOTD, kCASTOR, kDEVNULL };
446 AliMDC(Int_t fd, Int_t compress, Double_t maxFileSize, Bool_t useFilter,
447 EWriteMode mode, Bool_t useLoop, Bool_t delFiles);
451 void SetStopLoop() { fStopLoop = kTRUE; }
452 Bool_t StopLoop() const { return fStopLoop; }
454 void SetDebugLevel(Int_t level) { fDebugLevel = level; }
455 Int_t GetDebugLevel() const { return fDebugLevel; }
457 static Bool_t DeleteFiles() { return fgDeleteFiles; }
460 Int_t fFd; // DATE input stream
461 Int_t fCompress; // compression factor used for raw output DB
462 Int_t fNumEvents; // number of events processed
463 Int_t fDebugLevel; // controls debug print-out
464 Double_t fMaxFileSize; // maximum size of raw output DB
465 EWriteMode fWriteMode; // write mode (local, rfio, rootd, castor, /dev/null)
466 Bool_t fUseFifo; // read from fifo, file otherwise
467 Bool_t fUseEb; // use event builder API instead of fifo
468 Bool_t fUseFilter; // use 3rd level trigger filter
469 Bool_t fUseLoop; // loop on input source (must be file)
470 Bool_t fStopLoop; // break from endless loop (triggered by SIGUSR1)
472 static Bool_t fgDeleteFiles; // flag for deletion of files
474 Int_t Read(const char *name) { return TObject::Read(name); }
475 Int_t Read(void *buffer, Int_t length);
476 Int_t ReadHeader(AliRawEventHeader &header, void *eb = 0);
477 Int_t ReadEquipmentHeader(AliRawEquipmentHeader &header,
478 Bool_t isSwapped, void *eb = 0);
479 Int_t ReadRawData(AliRawData &raw, Int_t size, void *eb = 0);
480 Int_t DumpEvent(Int_t toRead);
481 Int_t Filter(AliRawData &raw);
483 ClassDef(AliMDC,0) // MDC processor
486 R__EXTERN AliMDC *gAliMDC;
488 #define ALIDEBUG(level) \
489 if (gAliMDC && (gAliMDC->GetDebugLevel() >= (level)))