3 // @(#)alimdc:$Name$:$Id$
4 // Author: Fons Rademakers 26/11/99
5 // Updated: Dario Favretto 15/04/2003
7 /* Copyright(c) 1998-2003, ALICE Experiment at CERN, All rights reserved. *
8 * See cxx source for full Copyright notice */
10 //////////////////////////////////////////////////////////////////////////
14 // Set of classes defining the ALICE RAW event format. The AliRawEvent //
15 // class defines a RAW event. It consists of an AliEventHeader object //
16 // an AliEquipmentHeader object, an AliRawData object and an array of //
17 // sub-events, themselves also being AliRawEvents. The number of //
18 // sub-events depends on the number of DATE LDC's. //
19 // The AliRawEvent objects are written to a ROOT file using different //
20 // technologies, i.e. to local disk via AliRawDB or via rfiod using //
21 // AliRawRFIODB or via rootd using AliRawRootdDB or to CASTOR via //
22 // rootd using AliRawCastorDB (and for performance testing there is //
23 // also AliRawNullDB). //
24 // The AliRunDB class provides the interface to the run and file //
25 // catalogues (AliEn or plain MySQL). //
26 // The AliStats class provides statics information that is added as //
27 // a single keyed object to each raw file. //
28 // The AliTagDB provides an interface to a TAG database. //
29 // The AliMDC class is usid by the "alimdc" stand-alone program //
30 // that reads data directly from DATE. //
32 //////////////////////////////////////////////////////////////////////////
55 // Forward class declarations
60 // The following enumeration can be used once the kEventTypeMask has been
61 // applied to the raw event type
62 enum EAliRawEventType {
63 kStartOfRun = 1, // START_OF_RUN
64 kEndOfRun = 2, // END_OF_RUN
65 kStartOfRunFiles = 3, // START_OF_RUN_FILES
66 kEndOfRunFiles = 4, // END_OF_RUN_FILES
67 kStartOfBurst = 5, // START_OF_BURST
68 kEndOfBurst = 6, // END_OF_BURST
69 kPhysicsEvent = 7, // PHYSICS_EVENT
70 kCalibrationEvent = 8, // CALIBRATION_EVENT
71 kFormatError = 9 // EVENT_FORMAT_ERROR
74 const Int_t kEventTypeMin = kStartOfRun;
75 const Int_t kEventTypeMax = kFormatError;
77 const UInt_t kEventMagicNumber = 0xDA1E5AFE;
78 const UInt_t kEventMagicNumberSwapped = 0xFE5A1EDA;
81 const Int_t kIdWords = 2;
82 const Int_t kTriggerWords = 2;
83 const Int_t kDetectorWords = 1;
84 const Int_t kAttributeWords = 3;
87 class AliRawEventHeader : public TObject {
90 AliRawEventHeader() { fSize = 0; }
91 virtual ~AliRawEventHeader() { }
93 void *HeaderBegin() { return (void *) &fSize; }
94 Int_t HeaderSize() const { return (Long_t) &fGDCId - (Long_t) &fSize + sizeof(fGDCId); }
95 Bool_t DataIsSwapped() const;
96 Bool_t IsSwapped() const { return (fMagic == kEventMagicNumberSwapped) ? kTRUE : kFALSE; }
97 Bool_t IsValid() const { return IsSwapped() ? kTRUE : ((fMagic == kEventMagicNumber) ? kTRUE : kFALSE); }
100 UInt_t GetEventSize() const { return fSize; }
101 UInt_t GetMagic() const { return fMagic; }
102 UInt_t GetHeaderLength() const { return fHeadLen; }
103 UInt_t GetVersion() const { return fVersion; }
104 UInt_t GetType() const { return fType; }
105 const char *GetTypeName() const;
106 UInt_t GetRunNumber() const { return fRunNb; }
107 UInt_t GetEventInRun() const;
108 const UInt_t *GetId() const { return fId; }
109 const UInt_t *GetTriggerPattern() const { return fTriggerPattern; }
110 const UInt_t *GetDetectorPattern() const { return fDetectorPattern; }
111 const UInt_t *GetTypeAttribute() const { return fTypeAttribute; }
112 UInt_t GetLDCId() const { return fLDCId; }
113 UInt_t GetGDCId() const { return fGDCId; }
116 UInt_t fSize; // size of event in bytes
117 UInt_t fMagic; // magic number used for consistency check
118 UInt_t fHeadLen; // size of header in bytes
119 UInt_t fVersion; // unique version identifier
120 UInt_t fType; // event type
121 UInt_t fRunNb; // run number
122 UInt_t fId[kIdWords]; // id field
123 UInt_t fTriggerPattern[kTriggerWords]; // trigger pattern
124 UInt_t fDetectorPattern[kDetectorWords]; // detector pattern
125 UInt_t fTypeAttribute[kAttributeWords]; // system (0,1) and user (2) attributes
126 UInt_t fLDCId; // LDC id
127 UInt_t fGDCId; // GDC id
129 ClassDef(AliRawEventHeader,1) // Alice raw event header
133 class AliRawEquipmentHeader : public TObject {
136 AliRawEquipmentHeader() { fSize = 0; }
137 ~AliRawEquipmentHeader() { }
139 void *HeaderBegin() { return (void *) &fSize; }
140 Int_t HeaderSize() const { return (Long_t) &fBasicElementSizeType - (Long_t) &fSize + sizeof(fBasicElementSizeType); }
143 UInt_t GetEquipmentSize() const { return fSize; }
144 UInt_t GetEquipmentType() const { return fEquipmentType; }
145 UInt_t GetId() const { return fEquipmentID; }
146 const UInt_t *GetTypeAttribute() const { return fTypeAttribute; }
147 UInt_t GetBasicSizeType() const { return fBasicElementSizeType; }
150 UInt_t fSize; // number of raw data bytes
151 UInt_t fEquipmentType; // equipment type
152 UInt_t fEquipmentID; // equipment ID
153 UInt_t fTypeAttribute[kAttributeWords]; // system (0,1) and user (2) attributes
154 UInt_t fBasicElementSizeType; // basic element size type
156 ClassDef(AliRawEquipmentHeader,1) //Alice equipment header
160 class AliRawData : public TObject {
163 AliRawData() { fSize = fBufSize = 0; fRawData = 0; fOwner = kTRUE; }
164 virtual ~AliRawData() { if (fOwner) delete [] fRawData; }
166 inline void SetSize(Int_t size);
167 inline void SetBuffer(void *buf, Int_t size);
168 Int_t GetSize() const { return fSize; }
169 void *GetBuffer() { return fRawData; }
172 Int_t fSize; // number of raw data bytes
173 Int_t fBufSize; //!actual size of fRawData
174 char *fRawData; //[fSize] raw event data
175 Bool_t fOwner; //!if true object owns fRawData buffer
177 AliRawData(const AliRawData &); // not implemented, usage causes
178 void operator=(const AliRawData &); // link time error
180 ClassDef(AliRawData,1) // Alice raw event buffer
183 void AliRawData::SetSize(Int_t size)
185 if (size > fBufSize) {
186 if (fOwner) delete [] fRawData;
187 fRawData = new char [size];
194 void AliRawData::SetBuffer(void *buf, Int_t size)
196 if (fOwner) delete [] fRawData;
197 fRawData = (char *) buf;
204 class AliRawEvent : public TObject {
208 virtual ~AliRawEvent();
210 AliRawEventHeader *GetHeader();
211 AliRawEquipmentHeader *GetEquipmentHeader();
212 AliRawData *GetRawData();
213 Int_t GetNSubEvents() const { return fNSubEvents; }
214 AliRawEvent *NextSubEvent();
215 AliRawEvent *GetSubEvent(Int_t index) const;
219 Int_t fNSubEvents; // number of valid sub-events
220 AliRawEventHeader *fEvtHdr; // event header object
221 AliRawEquipmentHeader *fEqpHdr; // equipment header
222 AliRawData *fRawData; // raw data container
223 TObjArray *fSubEvents; // sub AliRawEvent's
225 AliRawEvent(const AliRawEvent &); // not implemented, usage causes
226 void operator=(const AliRawEvent &); // link time error
228 ClassDef(AliRawEvent,1) // ALICE raw event object
232 class AliStats : public TObject {
235 AliStats(const char *filename = "", Int_t compmode = 0, Bool_t filter = kFALSE);
237 AliStats &operator=(const AliStats &rhs);
239 void SetEvents(Int_t events) { fEvents = events; }
240 void SetFirstId(Int_t run, Int_t event) { fFirstRun = run; fFirstEvent = event; }
241 void SetLastId(Int_t run, Int_t event) { fLastRun = run; fLastEvent = event; }
242 void SetBeginTime() { fBegin.Set(); }
243 void SetEndTime() { fEnd.Set(); }
244 void SetFileSize(Double_t size) { fFileSize = size; }
245 void SetCompressionFactor(Float_t comp) { fCompFactor = comp; }
246 void Fill(Float_t time);
247 void WriteToDB(AliRawDB *rawdb);
249 Int_t GetEvents() const { return fEvents; }
250 Int_t GetFirstRun() const { return fFirstRun; }
251 Int_t GetFirstEvent() const { return fFirstEvent; }
252 Int_t GetLastRun() const { return fLastRun; }
253 Int_t GetLastEvent() const { return fLastEvent; }
254 TDatime &GetBeginTime() { return fBegin; }
255 TDatime &GetEndTime() { return fEnd; }
256 Double_t GetFileSize() const { return fFileSize; }
257 Int_t GetCompressionMode() const { return fCompMode; }
258 Float_t GetCompressionFactor() const { return fCompFactor; }
259 Bool_t GetFilterState() const { return fFilter; }
260 const char *GetFileName() const { return fFileName; }
261 TH1F *GetRTHist() const { return fRTHist; }
264 Int_t fEvents; // number of events in this file
265 Int_t fFirstRun; // run number of first event in file
266 Int_t fFirstEvent; // event number of first event in file
267 Int_t fLastRun; // run number of last event in file
268 Int_t fLastEvent; // event number of last event in file
269 TDatime fBegin; // begin of filling time
270 TDatime fEnd; // end of filling time
271 TString fFileName; // name of file containing this data
272 Double_t fFileSize; // size of file
273 Float_t fCompFactor; // tree compression factor
274 Int_t fCompMode; // compression mode
275 Bool_t fFilter; // 3rd level filter on/off
276 TH1F *fRTHist; // histogram of real-time to process chunck of data
277 Float_t fChunk; //!chunk to be histogrammed
279 AliStats(const AliStats &); // not implemented
281 ClassDef(AliStats,1) // Statistics object
285 class AliRawDB : public TObject {
288 AliRawDB(AliRawEvent *event, Double_t maxsize, Int_t compress,
289 Bool_t create = kTRUE);
290 virtual ~AliRawDB() { Close(); }
292 virtual const char *GetOpenOption() const { return "RECREATE"; }
293 virtual Int_t GetNetopt() const { return 0; }
294 virtual Bool_t Create();
295 virtual void Close();
296 void Fill() { fTree->Fill(); }
297 Bool_t FileFull() { return (fRawDB->GetBytesWritten() > fMaxSize) ?
302 Double_t GetBytesWritten() const { return fRawDB->GetBytesWritten(); }
303 TFile *GetDB() const { return fRawDB; }
304 const char *GetDBName() const { return fRawDB->GetName(); }
305 Int_t GetEvents() const { return (Int_t) fTree->GetEntries(); }
306 AliRawEvent *GetEvent() const { return fEvent; }
307 Float_t GetCompressionFactor() const;
308 Int_t GetCompressionMode() const { return fRawDB->GetCompressionLevel(); }
311 TFile *fRawDB; // DB to store raw data
312 TTree *fTree; // tree used to store raw data
313 AliRawEvent *fEvent; // AliRawEvent via which data is stored
314 Int_t fCompress; // compression mode (1 default)
315 Double_t fMaxSize; // maximum size in bytes of the raw DB
317 virtual const char *GetFileName() const;
318 virtual Bool_t FSHasSpace(const char *fs) const;
319 virtual void MakeTree();
322 AliRawDB(const AliRawDB &); // not implemented, usage causes
323 void operator=(const AliRawDB &); // link time error
325 ClassDef(AliRawDB,0) // Raw DB
329 class AliRawRFIODB : public AliRawDB {
332 AliRawRFIODB(AliRawEvent *event, Double_t maxsize, Int_t compress);
333 ~AliRawRFIODB() { Close(); }
338 const char *GetFileName() const;
340 ClassDef(AliRawRFIODB,0) // Raw DB via RFIO
344 class AliRawCastorDB : public AliRawDB {
347 AliRawCastorDB(AliRawEvent *event, Double_t maxsize, Int_t compress);
348 ~AliRawCastorDB() { Close(); }
350 const char *GetOpenOption() const { return "-RECREATE"; }
351 Int_t GetNetopt() const { return 0; }
355 const char *GetFileName() const;
357 ClassDef(AliRawCastorDB,0) // Raw DB via CASTOR and rootd
361 class AliRawRootdDB : public AliRawDB {
364 AliRawRootdDB(AliRawEvent *event, Double_t maxsize, Int_t compress);
365 ~AliRawRootdDB() { Close(); }
370 const char *GetFileName() const;
372 ClassDef(AliRawRootdDB,0) // Raw DB via rootd
376 class AliRawNullDB : public AliRawDB {
379 AliRawNullDB(AliRawEvent *event, Double_t maxsize, Int_t compress);
380 ~AliRawNullDB() { Close(); }
385 const char *GetFileName() const;
387 ClassDef(AliRawNullDB,0) // Raw DB to /dev/null
391 class AliTagDB : public TObject {
394 AliTagDB(AliRawEventHeader *header, Double_t maxsize, Bool_t create = kTRUE);
395 virtual ~AliTagDB() { Close(); }
398 virtual void Close();
399 void Fill() { fTree->Fill(); }
401 { return (fTagDB->GetBytesWritten() > fMaxSize) ? kTRUE : kFALSE; }
405 Double_t GetBytesWritten() const { return fTagDB->GetBytesWritten(); }
406 TFile *GetDB() const { return fTagDB; }
407 const char *GetDBName() const { return fTagDB->GetName(); }
408 AliRawEventHeader *GetHeader() const { return fHeader; }
409 Int_t GetEvents() const { return (Int_t) fTree->GetEntries(); }
410 Float_t GetCompressionFactor() const;
413 TFile *fTagDB; // DB to store header information only (tag)
414 TTree *fTree; // tree use to store header
415 AliRawEventHeader *fHeader; // header via which data is stored
416 Double_t fMaxSize; // maximum size in bytes of tag DB
418 virtual const char *GetFileName() const;
421 AliTagDB(const AliTagDB &); // not implemented, usage causes
422 void operator=(const AliTagDB &); // link time error
424 ClassDef(AliTagDB,0) // Tag DB
428 class AliTagNullDB : public AliTagDB {
431 AliTagNullDB(AliRawEventHeader *header, Double_t maxsize);
432 ~AliTagNullDB() { Close(); }
437 const char *GetFileName() const;
439 ClassDef(AliTagNullDB,0) // Tag DB to /dev/null
443 class AliRunDB : public TObject {
446 AliRunDB(Bool_t noLocalDB = kFALSE);
447 ~AliRunDB() { Close(); }
449 void Update(AliStats *stats);
450 void UpdateRDBMS(AliStats *stats);
451 void UpdateAliEn(AliStats *stats);
455 TFile *fRunDB; // run database
457 AliRunDB(const AliRunDB &); // not implemented, usage causes
458 void operator=(const AliRunDB &); // link time error
460 ClassDef(AliRunDB,0) // Run (bookkeeping) DB
464 class AliMDC : public TObject {
467 enum EWriteMode { kLOCAL, kRFIO, kROOTD, kCASTOR, kDEVNULL };
469 AliMDC(Int_t fd, Int_t compress, Double_t maxFileSize, Bool_t useFilter,
470 EWriteMode mode, Bool_t useLoop, Bool_t delFiles);
474 void SetStopLoop() { fStopLoop = kTRUE; }
475 Bool_t StopLoop() const { return fStopLoop; }
477 void SetDebugLevel(Int_t level) { fDebugLevel = level; }
478 Int_t GetDebugLevel() const { return fDebugLevel; }
480 static Bool_t DeleteFiles() { return fgDeleteFiles; }
483 Int_t fFd; // DATE input stream
484 Int_t fCompress; // compression factor used for raw output DB
485 Int_t fNumEvents; // number of events processed
486 Int_t fDebugLevel; // controls debug print-out
487 Double_t fMaxFileSize; // maximum size of raw output DB
488 EWriteMode fWriteMode; // write mode (local, rfio, rootd, castor, /dev/null)
489 Bool_t fUseFifo; // read from fifo, file otherwise
490 Bool_t fUseEb; // use event builder API instead of fifo
491 Bool_t fUseFilter; // use 3rd level trigger filter
492 Bool_t fUseLoop; // loop on input source (must be file)
493 Bool_t fStopLoop; // break from endless loop (triggered by SIGUSR1)
495 static Bool_t fgDeleteFiles; // flag for deletion of files
497 Int_t Read(const char *name) { return TObject::Read(name); }
498 Int_t Read(void *buffer, Int_t length);
499 Int_t ReadHeader(AliRawEventHeader &header, void *eb = 0);
500 Int_t ReadEquipmentHeader(AliRawEquipmentHeader &header,
501 Bool_t isSwapped, void *eb = 0);
502 Int_t ReadRawData(AliRawData &raw, Int_t size, void *eb = 0);
503 Int_t DumpEvent(Int_t toRead);
504 Int_t Filter(AliRawData &raw);
506 ClassDef(AliMDC,0) // MDC processor
509 R__EXTERN AliMDC *gAliMDC;
511 #define ALIDEBUG(level) \
512 if (gAliMDC && (gAliMDC->GetDebugLevel() >= (level)))