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 AliRawData(const AliRawData& rawData): TObject(rawData)
142 {Fatal("AliRawData", "copy constructor not implemented");};
143 AliRawData& operator = (const AliRawData& /*rawData*/) {
144 Fatal("operator =", "assignment operator not implemented");
147 virtual ~AliRawData() { if (fOwner) delete [] fRawData; }
149 inline void SetSize(Int_t size);
150 inline void SetBuffer(void *buf, Int_t size);
151 Int_t GetSize() const { return fSize; }
152 void *GetBuffer() { return fRawData; }
155 Int_t fSize; // number of raw data bytes
156 Int_t fBufSize; //!actual size of fRawData
157 char *fRawData; //[fSize] raw event data
158 Bool_t fOwner; //!if true object owns fRawData buffer
160 ClassDef(AliRawData,1) // Alice raw event buffer
163 void AliRawData::SetSize(Int_t size)
165 if (size > fBufSize) {
166 if (fOwner) delete [] fRawData;
167 fRawData = new char [size];
174 void AliRawData::SetBuffer(void *buf, Int_t size)
176 if (fOwner) delete [] fRawData;
177 fRawData = (char *) buf;
184 class AliRawEvent : public TObject {
188 AliRawEvent(const AliRawEvent& rawEvent): TObject(rawEvent)
189 {Fatal("AliRawEvent", "copy constructor not implemented");};
190 AliRawEvent& operator = (const AliRawEvent& /*rawEvent*/) {
191 Fatal("operator =", "assignment operator not implemented");
194 virtual ~AliRawEvent();
196 AliRawEventHeader *GetHeader();
197 AliRawEquipmentHeader *GetEquipmentHeader();
198 AliRawData *GetRawData();
199 Int_t GetNSubEvents() const { return fNSubEvents; }
200 AliRawEvent *NextSubEvent();
201 AliRawEvent *GetSubEvent(Int_t index) const;
205 Int_t fNSubEvents; // number of valid sub-events
206 AliRawEventHeader *fEvtHdr; // event header object
207 AliRawEquipmentHeader *fEqpHdr; // equipment header
208 AliRawData *fRawData; // raw data container
209 TObjArray *fSubEvents; // sub AliRawEvent's
211 ClassDef(AliRawEvent,1) // ALICE raw event object
215 class AliStats : public TObject {
218 AliStats(const char *filename = "", Int_t compmode = 0, Bool_t filter = kFALSE);
219 AliStats(const AliStats& stats): TObject(stats)
220 {Fatal("AliStats", "copy constructor not implemented");};
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; }
249 Int_t fEvents; // number of events in this file
250 Int_t fFirstRun; // run number of first event in file
251 Int_t fFirstEvent; // event number of first event in file
252 Int_t fLastRun; // run number of last event in file
253 Int_t fLastEvent; // event number of last event in file
254 TDatime fBegin; // begin of filling time
255 TDatime fEnd; // end of filling time
256 TString fFileName; // name of file containing this data
257 Double_t fFileSize; // size of file
258 Float_t fCompFactor; // tree compression factor
259 Int_t fCompMode; // compression mode
260 Bool_t fFilter; // 3rd level filter on/off
261 TH1F *fRTHist; // histogram of real-time to process chunck of data
262 Float_t fChunk; //!chunk to be histogrammed
264 ClassDef(AliStats,1) // Statistics object
268 class AliRawDB : public TObject {
271 AliRawDB(AliRawEvent *event, Double_t maxsize, Int_t compress,
272 Bool_t create = kTRUE);
273 AliRawDB(const AliRawDB& rawDB): TObject(rawDB)
274 {Fatal("AliRawDB", "copy constructor not implemented");};
275 AliRawDB& operator = (const AliRawDB& /*rawDB*/) {
276 Fatal("operator =", "assignment operator not implemented");
279 virtual ~AliRawDB() { Close(); }
281 virtual const char *GetOpenOption() const { return "RECREATE"; }
282 virtual Bool_t Create();
283 virtual void Close();
284 void Fill() { fTree->Fill(); }
285 Bool_t FileFull() { return (fRawDB->GetBytesWritten() > fMaxSize) ?
290 Double_t GetBytesWritten() const { return fRawDB->GetBytesWritten(); }
291 TFile *GetDB() const { return fRawDB; }
292 const char *GetDBName() const { return fRawDB->GetName(); }
293 Int_t GetEvents() const { return (Int_t) fTree->GetEntries(); }
294 AliRawEvent *GetEvent() const { return fEvent; }
295 Float_t GetCompressionFactor() const;
296 Int_t GetCompressionMode() const { return fRawDB->GetCompressionLevel(); }
299 TFile *fRawDB; // DB to store raw data
300 TTree *fTree; // tree used to store raw data
301 AliRawEvent *fEvent; // AliRawEvent via which data is stored
302 Int_t fCompress; // compression mode (1 default)
303 Double_t fMaxSize; // maximum size in bytes of the raw DB
305 virtual const char *GetFileName() const;
306 virtual Bool_t FSHasSpace(const char *fs) const;
307 virtual void MakeTree();
309 ClassDef(AliRawDB,0) // Raw DB
313 class AliRawRFIODB : public AliRawDB {
316 AliRawRFIODB(AliRawEvent *event, Double_t maxsize, Int_t compress);
317 ~AliRawRFIODB() { Close(); }
322 const char *GetFileName() const;
324 ClassDef(AliRawRFIODB,0) // Raw DB via RFIO
328 class AliRawCastorDB : public AliRawDB {
331 AliRawCastorDB(AliRawEvent *event, Double_t maxsize, Int_t compress);
332 ~AliRawCastorDB() { Close(); }
334 const char *GetOpenOption() const { return "-RECREATE"; }
338 const char *GetFileName() const;
340 ClassDef(AliRawCastorDB,0) // Raw DB via CASTOR and rootd
344 class AliRawRootdDB : public AliRawDB {
347 AliRawRootdDB(AliRawEvent *event, Double_t maxsize, Int_t compress);
348 ~AliRawRootdDB() { Close(); }
353 const char *GetFileName() const;
355 ClassDef(AliRawRootdDB,0) // Raw DB via rootd
359 class AliRawNullDB : public AliRawDB {
362 AliRawNullDB(AliRawEvent *event, Double_t maxsize, Int_t compress);
363 ~AliRawNullDB() { Close(); }
368 const char *GetFileName() const;
370 ClassDef(AliRawNullDB,0) // Raw DB to /dev/null
374 class AliTagDB : public TObject {
377 AliTagDB(AliRawEventHeader *header, Double_t maxsize, Bool_t create = kTRUE);
378 AliTagDB(const AliTagDB& tagDB): TObject(tagDB)
379 {Fatal("AliTagDB", "copy constructor not implemented");};
380 AliTagDB& operator = (const AliTagDB& /*tagDB*/) {
381 Fatal("operator =", "assignment operator not implemented");
384 virtual ~AliTagDB() { Close(); }
387 virtual void Close();
388 void Fill() { fTree->Fill(); }
390 { return (fTagDB->GetBytesWritten() > fMaxSize) ? kTRUE : kFALSE; }
394 Double_t GetBytesWritten() const { return fTagDB->GetBytesWritten(); }
395 TFile *GetDB() const { return fTagDB; }
396 const char *GetDBName() const { return fTagDB->GetName(); }
397 AliRawEventHeader *GetHeader() const { return fHeader; }
398 Int_t GetEvents() const { return (Int_t) fTree->GetEntries(); }
399 Float_t GetCompressionFactor() const;
402 TFile *fTagDB; // DB to store header information only (tag)
403 TTree *fTree; // tree use to store header
404 AliRawEventHeader *fHeader; // header via which data is stored
405 Double_t fMaxSize; // maximum size in bytes of tag DB
407 virtual const char *GetFileName() const;
409 ClassDef(AliTagDB,0) // Tag DB
413 class AliTagNullDB : public AliTagDB {
416 AliTagNullDB(AliRawEventHeader *header, Double_t maxsize);
417 ~AliTagNullDB() { Close(); }
422 const char *GetFileName() const;
424 ClassDef(AliTagNullDB,0) // Tag DB to /dev/null
428 class AliRunDB : public TObject {
431 AliRunDB(Bool_t noLocalDB = kFALSE);
432 AliRunDB(const AliRunDB& runDB): TObject(runDB)
433 {Fatal("AliRunDB", "copy constructor not implemented");};
434 AliRunDB& operator = (const AliRunDB& /*runDB*/) {
435 Fatal("operator =", "assignment operator not implemented");
438 ~AliRunDB() { Close(); }
440 void Update(AliStats *stats);
441 void UpdateRDBMS(AliStats *stats);
442 void UpdateAliEn(AliStats *stats);
446 TFile *fRunDB; // run database
448 ClassDef(AliRunDB,0) // Run (bookkeeping) DB
452 class AliMDC : public TObject {
455 enum EWriteMode { kLOCAL, kRFIO, kROOTD, kCASTOR, kDEVNULL };
457 AliMDC(Int_t fd, Int_t compress, Double_t maxFileSize, Bool_t useFilter,
458 EWriteMode mode, Bool_t useLoop, Bool_t delFiles);
462 void SetStopLoop() { fStopLoop = kTRUE; }
463 Bool_t StopLoop() const { return fStopLoop; }
465 void SetDebugLevel(Int_t level) { fDebugLevel = level; }
466 Int_t GetDebugLevel() const { return fDebugLevel; }
468 static Bool_t DeleteFiles() { return fgDeleteFiles; }
471 Int_t fFd; // DATE input stream
472 Int_t fCompress; // compression factor used for raw output DB
473 Int_t fNumEvents; // number of events processed
474 Int_t fDebugLevel; // controls debug print-out
475 Double_t fMaxFileSize; // maximum size of raw output DB
476 EWriteMode fWriteMode; // write mode (local, rfio, rootd, castor, /dev/null)
477 Bool_t fUseFifo; // read from fifo, file otherwise
478 Bool_t fUseEb; // use event builder API instead of fifo
479 Bool_t fUseFilter; // use 3rd level trigger filter
480 Bool_t fUseLoop; // loop on input source (must be file)
481 Bool_t fStopLoop; // break from endless loop (triggered by SIGUSR1)
483 static Bool_t fgDeleteFiles; // flag for deletion of files
485 Int_t Read(const char *name) { return TObject::Read(name); }
486 Int_t Read(void *buffer, Int_t length);
487 Int_t ReadHeader(AliRawEventHeader &header, void *eb = 0);
488 Int_t ReadEquipmentHeader(AliRawEquipmentHeader &header,
489 Bool_t isSwapped, void *eb = 0);
490 Int_t ReadRawData(AliRawData &raw, Int_t size, void *eb = 0);
491 Int_t DumpEvent(Int_t toRead);
492 Int_t Filter(AliRawData &raw);
494 ClassDef(AliMDC,0) // MDC processor
497 R__EXTERN AliMDC *gAliMDC;
499 #define ALIDEBUG(level) \
500 if (gAliMDC && (gAliMDC->GetDebugLevel() >= (level)))