]>
Commit | Line | Data |
---|---|---|
c689d2f6 | 1 | #ifndef ALIRAWEVENT_H |
2 | #define ALIRAWEVENT_H | |
5ea08be4 | 3 | // @(#)alimdc:$Name$:$Id$ |
4 | // Author: Fons Rademakers 26/11/99 | |
5 | // Updated: Dario Favretto 15/04/2003 | |
6 | ||
5ea08be4 | 7 | |
8 | #ifndef ROOT_TObject | |
9 | #include <TObject.h> | |
10 | #endif | |
11 | ||
5ea08be4 | 12 | #ifndef ROOT_TDatime |
13 | #include <TDatime.h> | |
14 | #endif | |
15 | ||
16 | #ifndef ROOT_TString | |
17 | #include <TString.h> | |
18 | #endif | |
19 | ||
20 | #ifndef ROOT_TFile | |
21 | #include <TFile.h> | |
22 | #endif | |
23 | ||
24 | #ifndef ROOT_TTree | |
25 | #include <TTree.h> | |
26 | #endif | |
27 | ||
04fa961a | 28 | #ifndef ROOT_TH1 |
29 | #include <TH1.h> | |
30 | #endif | |
31 | ||
5ea08be4 | 32 | |
33 | // Forward class declarations | |
5ea08be4 | 34 | class AliRawDB; |
35 | ||
36 | ||
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 | |
49 | }; | |
50 | ||
51 | const Int_t kEventTypeMin = kStartOfRun; | |
52 | const Int_t kEventTypeMax = kFormatError; | |
53 | ||
54 | const UInt_t kEventMagicNumber = 0xDA1E5AFE; | |
55 | const UInt_t kEventMagicNumberSwapped = 0xFE5A1EDA; | |
56 | ||
57 | // Type sizes | |
58 | const Int_t kIdWords = 2; | |
59 | const Int_t kTriggerWords = 2; | |
60 | const Int_t kDetectorWords = 1; | |
61 | const Int_t kAttributeWords = 3; | |
62 | ||
63 | ||
64 | class AliRawEventHeader : public TObject { | |
65 | ||
5ea08be4 | 66 | public: |
67 | AliRawEventHeader() { fSize = 0; } | |
68 | virtual ~AliRawEventHeader() { } | |
69 | ||
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); } | |
75 | void Swap(); | |
76 | ||
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; } | |
91 | ||
c689d2f6 | 92 | private: |
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 | |
105 | ||
5ea08be4 | 106 | ClassDef(AliRawEventHeader,1) // Alice raw event header |
107 | }; | |
108 | ||
109 | ||
110 | class AliRawEquipmentHeader : public TObject { | |
111 | ||
5ea08be4 | 112 | public: |
113 | AliRawEquipmentHeader() { fSize = 0; } | |
114 | ~AliRawEquipmentHeader() { } | |
115 | ||
116 | void *HeaderBegin() { return (void *) &fSize; } | |
117 | Int_t HeaderSize() const { return (Long_t) &fBasicElementSizeType - (Long_t) &fSize + sizeof(fBasicElementSizeType); } | |
118 | void Swap(); | |
119 | ||
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; } | |
125 | ||
c689d2f6 | 126 | private: |
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 | |
132 | ||
5ea08be4 | 133 | ClassDef(AliRawEquipmentHeader,1) //Alice equipment header |
134 | }; | |
135 | ||
136 | ||
137 | class AliRawData : public TObject { | |
138 | ||
5ea08be4 | 139 | public: |
8f66d77e | 140 | AliRawData() { fSize = fBufSize = 0; fRawData = 0; fOwner = kTRUE; } |
5ea08be4 | 141 | virtual ~AliRawData() { if (fOwner) delete [] fRawData; } |
142 | ||
c689d2f6 | 143 | inline void SetSize(Int_t size); |
edbfa2f2 | 144 | inline void SetBuffer(void *buf, Int_t size); |
145 | Int_t GetSize() const { return fSize; } | |
146 | void *GetBuffer() { return fRawData; } | |
5ea08be4 | 147 | |
c689d2f6 | 148 | private: |
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 | |
153 | ||
edbfa2f2 | 154 | AliRawData(const AliRawData &); // not implemented, usage causes |
155 | void operator=(const AliRawData &); // link time error | |
156 | ||
5ea08be4 | 157 | ClassDef(AliRawData,1) // Alice raw event buffer |
158 | }; | |
159 | ||
edbfa2f2 | 160 | void AliRawData::SetSize(Int_t size) |
c689d2f6 | 161 | { |
edbfa2f2 | 162 | if (size > fBufSize) { |
163 | if (fOwner) delete [] fRawData; | |
164 | fRawData = new char [size]; | |
165 | fBufSize = size; | |
166 | fOwner = kTRUE; | |
167 | } | |
168 | fSize = size; | |
c689d2f6 | 169 | } |
170 | ||
edbfa2f2 | 171 | void AliRawData::SetBuffer(void *buf, Int_t size) |
c689d2f6 | 172 | { |
edbfa2f2 | 173 | if (fOwner) delete [] fRawData; |
174 | fRawData = (char *) buf; | |
175 | fBufSize = size; | |
176 | fSize = size; | |
177 | fOwner = kFALSE; | |
c689d2f6 | 178 | } |
5ea08be4 | 179 | |
5ea08be4 | 180 | |
c689d2f6 | 181 | class AliRawEvent : public TObject { |
5ea08be4 | 182 | |
183 | public: | |
184 | AliRawEvent(); | |
185 | virtual ~AliRawEvent(); | |
186 | ||
c51de60d | 187 | AliRawEventHeader *GetHeader(); |
5ea08be4 | 188 | AliRawEquipmentHeader *GetEquipmentHeader(); |
189 | AliRawData *GetRawData(); | |
190 | Int_t GetNSubEvents() const { return fNSubEvents; } | |
191 | AliRawEvent *NextSubEvent(); | |
5459c838 | 192 | AliRawEvent *GetSubEvent(Int_t index) const; |
5ea08be4 | 193 | void Reset(); |
194 | ||
c689d2f6 | 195 | private: |
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 | |
201 | ||
edbfa2f2 | 202 | AliRawEvent(const AliRawEvent &); // not implemented, usage causes |
203 | void operator=(const AliRawEvent &); // link time error | |
204 | ||
5ea08be4 | 205 | ClassDef(AliRawEvent,1) // ALICE raw event object |
206 | }; | |
207 | ||
208 | ||
209 | class AliStats : public TObject { | |
210 | ||
5ea08be4 | 211 | public: |
212 | AliStats(const char *filename = "", Int_t compmode = 0, Bool_t filter = kFALSE); | |
213 | virtual ~AliStats(); | |
214 | AliStats &operator=(const AliStats &rhs); | |
215 | ||
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); | |
225 | ||
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; } | |
239 | ||
c689d2f6 | 240 | private: |
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 | |
255 | ||
edbfa2f2 | 256 | AliStats(const AliStats &); // not implemented |
257 | ||
5ea08be4 | 258 | ClassDef(AliStats,1) // Statistics object |
259 | }; | |
260 | ||
261 | ||
262 | class AliRawDB : public TObject { | |
263 | ||
5ea08be4 | 264 | public: |
265 | AliRawDB(AliRawEvent *event, Double_t maxsize, Int_t compress, | |
266 | Bool_t create = kTRUE); | |
c689d2f6 | 267 | virtual ~AliRawDB() { Close(); } |
5ea08be4 | 268 | |
06c6fef1 | 269 | virtual const char *GetOpenOption() const { return "RECREATE"; } |
edbfa2f2 | 270 | virtual Int_t GetNetopt() const { return 0; } |
06c6fef1 | 271 | virtual Bool_t Create(); |
272 | virtual void Close(); | |
273 | void Fill() { fTree->Fill(); } | |
274 | Bool_t FileFull() { return (fRawDB->GetBytesWritten() > fMaxSize) ? | |
275 | kTRUE : kFALSE; } | |
5ea08be4 | 276 | |
06c6fef1 | 277 | Bool_t NextFile(); |
5ea08be4 | 278 | |
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(); } | |
286 | ||
c689d2f6 | 287 | protected: |
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 | |
293 | ||
294 | virtual const char *GetFileName() const; | |
295 | virtual Bool_t FSHasSpace(const char *fs) const; | |
296 | virtual void MakeTree(); | |
297 | ||
edbfa2f2 | 298 | private: |
299 | AliRawDB(const AliRawDB &); // not implemented, usage causes | |
300 | void operator=(const AliRawDB &); // link time error | |
301 | ||
5ea08be4 | 302 | ClassDef(AliRawDB,0) // Raw DB |
303 | }; | |
304 | ||
305 | ||
306 | class AliRawRFIODB : public AliRawDB { | |
307 | ||
5ea08be4 | 308 | public: |
309 | AliRawRFIODB(AliRawEvent *event, Double_t maxsize, Int_t compress); | |
310 | ~AliRawRFIODB() { Close(); } | |
311 | ||
312 | void Close(); | |
313 | ||
c689d2f6 | 314 | private: |
315 | const char *GetFileName() const; | |
316 | ||
5ea08be4 | 317 | ClassDef(AliRawRFIODB,0) // Raw DB via RFIO |
318 | }; | |
319 | ||
320 | ||
9174317d | 321 | class AliRawCastorDB : public AliRawDB { |
322 | ||
9174317d | 323 | public: |
324 | AliRawCastorDB(AliRawEvent *event, Double_t maxsize, Int_t compress); | |
325 | ~AliRawCastorDB() { Close(); } | |
326 | ||
06c6fef1 | 327 | const char *GetOpenOption() const { return "-RECREATE"; } |
edbfa2f2 | 328 | Int_t GetNetopt() const { return 0; } |
06c6fef1 | 329 | void Close(); |
9174317d | 330 | |
c689d2f6 | 331 | private: |
332 | const char *GetFileName() const; | |
333 | ||
9174317d | 334 | ClassDef(AliRawCastorDB,0) // Raw DB via CASTOR and rootd |
335 | }; | |
336 | ||
337 | ||
5ea08be4 | 338 | class AliRawRootdDB : public AliRawDB { |
339 | ||
5ea08be4 | 340 | public: |
341 | AliRawRootdDB(AliRawEvent *event, Double_t maxsize, Int_t compress); | |
342 | ~AliRawRootdDB() { Close(); } | |
343 | ||
344 | void Close(); | |
345 | ||
c689d2f6 | 346 | private: |
347 | const char *GetFileName() const; | |
348 | ||
5ea08be4 | 349 | ClassDef(AliRawRootdDB,0) // Raw DB via rootd |
350 | }; | |
351 | ||
352 | ||
353 | class AliRawNullDB : public AliRawDB { | |
354 | ||
5ea08be4 | 355 | public: |
356 | AliRawNullDB(AliRawEvent *event, Double_t maxsize, Int_t compress); | |
357 | ~AliRawNullDB() { Close(); } | |
358 | ||
359 | void Close(); | |
360 | ||
c689d2f6 | 361 | private: |
362 | const char *GetFileName() const; | |
363 | ||
5ea08be4 | 364 | ClassDef(AliRawNullDB,0) // Raw DB to /dev/null |
365 | }; | |
366 | ||
367 | ||
368 | class AliTagDB : public TObject { | |
369 | ||
5ea08be4 | 370 | public: |
371 | AliTagDB(AliRawEventHeader *header, Double_t maxsize, Bool_t create = kTRUE); | |
c689d2f6 | 372 | virtual ~AliTagDB() { Close(); } |
5ea08be4 | 373 | |
374 | Bool_t Create(); | |
375 | virtual void Close(); | |
376 | void Fill() { fTree->Fill(); } | |
377 | Bool_t FileFull() | |
378 | { return (fTagDB->GetBytesWritten() > fMaxSize) ? kTRUE : kFALSE; } | |
379 | ||
380 | Bool_t NextFile(); | |
381 | ||
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; | |
388 | ||
c689d2f6 | 389 | protected: |
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 | |
394 | ||
395 | virtual const char *GetFileName() const; | |
396 | ||
edbfa2f2 | 397 | private: |
398 | AliTagDB(const AliTagDB &); // not implemented, usage causes | |
399 | void operator=(const AliTagDB &); // link time error | |
400 | ||
5ea08be4 | 401 | ClassDef(AliTagDB,0) // Tag DB |
402 | }; | |
403 | ||
404 | ||
405 | class AliTagNullDB : public AliTagDB { | |
406 | ||
5ea08be4 | 407 | public: |
408 | AliTagNullDB(AliRawEventHeader *header, Double_t maxsize); | |
409 | ~AliTagNullDB() { Close(); } | |
410 | ||
411 | void Close(); | |
412 | ||
c689d2f6 | 413 | private: |
414 | const char *GetFileName() const; | |
415 | ||
5ea08be4 | 416 | ClassDef(AliTagNullDB,0) // Tag DB to /dev/null |
417 | }; | |
418 | ||
419 | ||
420 | class AliRunDB : public TObject { | |
421 | ||
5ea08be4 | 422 | public: |
8ee17d63 | 423 | AliRunDB(Bool_t noLocalDB = kFALSE); |
5ea08be4 | 424 | ~AliRunDB() { Close(); } |
425 | ||
426 | void Update(AliStats *stats); | |
427 | void UpdateRDBMS(AliStats *stats); | |
9174317d | 428 | void UpdateAliEn(AliStats *stats); |
5ea08be4 | 429 | void Close(); |
430 | ||
c689d2f6 | 431 | private: |
432 | TFile *fRunDB; // run database | |
433 | ||
edbfa2f2 | 434 | AliRunDB(const AliRunDB &); // not implemented, usage causes |
435 | void operator=(const AliRunDB &); // link time error | |
436 | ||
5ea08be4 | 437 | ClassDef(AliRunDB,0) // Run (bookkeeping) DB |
438 | }; | |
439 | ||
440 | ||
441 | class AliMDC : public TObject { | |
442 | ||
9174317d | 443 | public: |
444 | enum EWriteMode { kLOCAL, kRFIO, kROOTD, kCASTOR, kDEVNULL }; | |
445 | ||
c689d2f6 | 446 | AliMDC(Int_t fd, Int_t compress, Double_t maxFileSize, Bool_t useFilter, |
447 | EWriteMode mode, Bool_t useLoop, Bool_t delFiles); | |
448 | ~AliMDC() { } | |
449 | ||
450 | Int_t Run(); | |
451 | void SetStopLoop() { fStopLoop = kTRUE; } | |
452 | Bool_t StopLoop() const { return fStopLoop; } | |
453 | ||
454 | void SetDebugLevel(Int_t level) { fDebugLevel = level; } | |
455 | Int_t GetDebugLevel() const { return fDebugLevel; } | |
456 | ||
457 | static Bool_t DeleteFiles() { return fgDeleteFiles; } | |
458 | ||
5ea08be4 | 459 | private: |
9174317d | 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) | |
5ea08be4 | 471 | |
c689d2f6 | 472 | static Bool_t fgDeleteFiles; // flag for deletion of files |
5ea08be4 | 473 | |
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); | |
482 | ||
5ea08be4 | 483 | ClassDef(AliMDC,0) // MDC processor |
484 | }; | |
485 | ||
486 | R__EXTERN AliMDC *gAliMDC; | |
487 | ||
488 | #define ALIDEBUG(level) \ | |
86f15b50 | 489 | if (gAliMDC && (gAliMDC->GetDebugLevel() >= (level))) |
5ea08be4 | 490 | |
491 | #endif |