1 // @(#)alimdc:$Name$:$Id$
2 // Author: Fons Rademakers 26/11/99
3 // Updated: Dario Favretto 15/04/2003
37 // Forward class declarations
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
55 const Int_t kEventTypeMin = kStartOfRun;
56 const Int_t kEventTypeMax = kFormatError;
58 const UInt_t kEventMagicNumber = 0xDA1E5AFE;
59 const UInt_t kEventMagicNumberSwapped = 0xFE5A1EDA;
62 const Int_t kIdWords = 2;
63 const Int_t kTriggerWords = 2;
64 const Int_t kDetectorWords = 1;
65 const Int_t kAttributeWords = 3;
68 class AliRawEventHeader : public TObject {
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
85 AliRawEventHeader() { fSize = 0; }
86 virtual ~AliRawEventHeader() { }
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); }
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; }
110 ClassDef(AliRawEventHeader,1) // Alice raw event header
114 class AliRawEquipmentHeader : public TObject {
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
124 AliRawEquipmentHeader() { fSize = 0; }
125 ~AliRawEquipmentHeader() { }
127 void *HeaderBegin() { return (void *) &fSize; }
128 Int_t HeaderSize() const { return (Long_t) &fBasicElementSizeType - (Long_t) &fSize + sizeof(fBasicElementSizeType); }
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; }
137 ClassDef(AliRawEquipmentHeader,1) //Alice equipment header
141 class AliRawData : public TObject {
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
150 AliRawData() { fSize = fBufSize = 0; fRawData = 0; fOwner = kTRUE; }
151 virtual ~AliRawData() { if (fOwner) delete [] fRawData; }
153 void SetSize(Int_t size) {
154 if (size > fBufSize) {
155 if (fOwner) delete [] fRawData;
156 fRawData = new char [size];
162 void SetBuffer(void *buf, Int_t size) {
163 if (fOwner) delete [] fRawData;
164 fRawData = (char *) buf;
169 Int_t GetSize() const { return fSize; }
170 void *GetBuffer() { return fRawData; }
172 ClassDef(AliRawData,1) // Alice raw event buffer
176 class AliRawEvent : public TObject {
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
187 virtual ~AliRawEvent();
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;
197 ClassDef(AliRawEvent,1) // ALICE raw event object
201 class AliStats : public TObject {
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
220 AliStats(const char *filename = "", Int_t compmode = 0, Bool_t filter = kFALSE);
222 AliStats &operator=(const AliStats &rhs);
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);
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; }
248 ClassDef(AliStats,1) // Statistics object
252 class AliRawDB : public TObject {
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
261 virtual const char *GetFileName();
262 virtual Bool_t FSHasSpace(const char *fs);
263 virtual void MakeTree();
266 AliRawDB(AliRawEvent *event, Double_t maxsize, Int_t compress,
267 Bool_t create = kTRUE);
268 ~AliRawDB() { Close(); }
270 virtual const char *GetOpenOption() const { return "RECREATE"; }
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(); }
287 ClassDef(AliRawDB,0) // Raw DB
291 class AliRawRFIODB : public AliRawDB {
294 const char *GetFileName();
297 AliRawRFIODB(AliRawEvent *event, Double_t maxsize, Int_t compress);
298 ~AliRawRFIODB() { Close(); }
302 ClassDef(AliRawRFIODB,0) // Raw DB via RFIO
306 class AliRawCastorDB : public AliRawDB {
309 const char *GetFileName();
312 AliRawCastorDB(AliRawEvent *event, Double_t maxsize, Int_t compress);
313 ~AliRawCastorDB() { Close(); }
315 const char *GetOpenOption() const { return "-RECREATE"; }
318 ClassDef(AliRawCastorDB,0) // Raw DB via CASTOR and rootd
322 class AliRawRootdDB : public AliRawDB {
325 const char *GetFileName();
328 AliRawRootdDB(AliRawEvent *event, Double_t maxsize, Int_t compress);
329 ~AliRawRootdDB() { Close(); }
333 ClassDef(AliRawRootdDB,0) // Raw DB via rootd
337 class AliRawNullDB : public AliRawDB {
340 const char *GetFileName();
343 AliRawNullDB(AliRawEvent *event, Double_t maxsize, Int_t compress);
344 ~AliRawNullDB() { Close(); }
348 ClassDef(AliRawNullDB,0) // Raw DB to /dev/null
352 class AliTagDB : public TObject {
355 TFile *fTagDB; // DB to store header information only (tag)
356 TTree *fTree; // tree use to store header
357 AliRawEventHeader *fHeader; // header via which data is stored
358 Double_t fMaxSize; // maximum size in bytes of tag DB
360 virtual const char *GetFileName();
363 AliTagDB(AliRawEventHeader *header, Double_t maxsize, Bool_t create = kTRUE);
364 ~AliTagDB() { Close(); }
367 virtual void Close();
368 void Fill() { fTree->Fill(); }
370 { return (fTagDB->GetBytesWritten() > fMaxSize) ? kTRUE : kFALSE; }
374 Double_t GetBytesWritten() const { return fTagDB->GetBytesWritten(); }
375 TFile *GetDB() const { return fTagDB; }
376 const char *GetDBName() const { return fTagDB->GetName(); }
377 AliRawEventHeader *GetHeader() const { return fHeader; }
378 Int_t GetEvents() const { return (Int_t) fTree->GetEntries(); }
379 Float_t GetCompressionFactor() const;
381 ClassDef(AliTagDB,0) // Tag DB
385 class AliTagNullDB : public AliTagDB {
388 const char *GetFileName();
391 AliTagNullDB(AliRawEventHeader *header, Double_t maxsize);
392 ~AliTagNullDB() { Close(); }
396 ClassDef(AliTagNullDB,0) // Tag DB to /dev/null
400 class AliRunDB : public TObject {
403 TFile *fRunDB; // run database
406 AliRunDB(Bool_t noLocalDB = kFALSE);
407 ~AliRunDB() { Close(); }
409 void Update(AliStats *stats);
410 void UpdateRDBMS(AliStats *stats);
411 void UpdateAliEn(AliStats *stats);
414 ClassDef(AliRunDB,0) // Run (bookkeeping) DB
418 class AliMDC : public TObject {
421 enum EWriteMode { kLOCAL, kRFIO, kROOTD, kCASTOR, kDEVNULL };
424 Int_t fFd; // DATE input stream
425 Int_t fCompress; // compression factor used for raw output DB
426 Int_t fNumEvents; // number of events processed
427 Int_t fDebugLevel; // controls debug print-out
428 Double_t fMaxFileSize; // maximum size of raw output DB
429 EWriteMode fWriteMode; // write mode (local, rfio, rootd, castor, /dev/null)
430 Bool_t fUseFifo; // read from fifo, file otherwise
431 Bool_t fUseEb; // use event builder API instead of fifo
432 Bool_t fUseFilter; // use 3rd level trigger filter
433 Bool_t fUseLoop; // loop on input source (must be file)
434 Bool_t fStopLoop; // break from endless loop (triggered by SIGUSR1)
436 static Bool_t fgDeleteFiles;
438 Int_t Read(const char *name) { return TObject::Read(name); }
439 Int_t Read(void *buffer, Int_t length);
440 Int_t ReadHeader(AliRawEventHeader &header, void *eb = 0);
441 Int_t ReadEquipmentHeader(AliRawEquipmentHeader &header,
442 Bool_t isSwapped, void *eb = 0);
443 Int_t ReadRawData(AliRawData &raw, Int_t size, void *eb = 0);
444 Int_t DumpEvent(Int_t toRead);
445 Int_t Filter(AliRawData &raw);
448 AliMDC(Int_t fd, Int_t compress, Double_t maxFileSize, Bool_t useFilter,
449 EWriteMode mode, Bool_t useLoop, Bool_t delFiles);
453 void SetStopLoop() { fStopLoop = kTRUE; }
454 Bool_t StopLoop() const { return fStopLoop; }
456 void SetDebugLevel(Int_t level) { fDebugLevel = level; }
457 Int_t GetDebugLevel() const { return fDebugLevel; }
459 static Bool_t DeleteFiles() { return fgDeleteFiles; }
461 ClassDef(AliMDC,0) // MDC processor
464 R__EXTERN AliMDC *gAliMDC;
466 #define ALIDEBUG(level) \
467 if (gAliMDC && (gAliMDC->GetDebugLevel() >= (level)))