]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RAW/AliRawEvent.h
provide non-void return type for operator=() to make the
[u/mrichter/AliRoot.git] / RAW / AliRawEvent.h
CommitLineData
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
35aa01d6 7/* Copyright(c) 1998-2003, ALICE Experiment at CERN, All rights reserved. *
8 * See cxx source for full Copyright notice */
9
10//////////////////////////////////////////////////////////////////////////
11// //
12// AliRawEvent //
13// //
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. //
31// //
32//////////////////////////////////////////////////////////////////////////
5ea08be4 33
34#ifndef ROOT_TObject
35#include <TObject.h>
36#endif
37
5ea08be4 38#ifndef ROOT_TDatime
39#include <TDatime.h>
40#endif
41
42#ifndef ROOT_TString
43#include <TString.h>
44#endif
45
46#ifndef ROOT_TFile
47#include <TFile.h>
48#endif
49
50#ifndef ROOT_TTree
51#include <TTree.h>
52#endif
53
54
55// Forward class declarations
35aa01d6 56class TH1F;
5ea08be4 57class AliRawDB;
58
59
60// The following enumeration can be used once the kEventTypeMask has been
61// applied to the raw event type
62enum 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
72};
73
74const Int_t kEventTypeMin = kStartOfRun;
75const Int_t kEventTypeMax = kFormatError;
76
77const UInt_t kEventMagicNumber = 0xDA1E5AFE;
78const UInt_t kEventMagicNumberSwapped = 0xFE5A1EDA;
79
80// Type sizes
81const Int_t kIdWords = 2;
82const Int_t kTriggerWords = 2;
83const Int_t kDetectorWords = 1;
84const Int_t kAttributeWords = 3;
85
86
87class AliRawEventHeader : public TObject {
88
5ea08be4 89public:
90 AliRawEventHeader() { fSize = 0; }
91 virtual ~AliRawEventHeader() { }
92
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); }
98 void Swap();
99
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; }
114
c689d2f6 115private:
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
128
5ea08be4 129 ClassDef(AliRawEventHeader,1) // Alice raw event header
130};
131
132
133class AliRawEquipmentHeader : public TObject {
134
5ea08be4 135public:
136 AliRawEquipmentHeader() { fSize = 0; }
137 ~AliRawEquipmentHeader() { }
138
139 void *HeaderBegin() { return (void *) &fSize; }
140 Int_t HeaderSize() const { return (Long_t) &fBasicElementSizeType - (Long_t) &fSize + sizeof(fBasicElementSizeType); }
141 void Swap();
142
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; }
148
c689d2f6 149private:
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
155
5ea08be4 156 ClassDef(AliRawEquipmentHeader,1) //Alice equipment header
157};
158
159
160class AliRawData : public TObject {
161
5ea08be4 162public:
8f66d77e 163 AliRawData() { fSize = fBufSize = 0; fRawData = 0; fOwner = kTRUE; }
5ea08be4 164 virtual ~AliRawData() { if (fOwner) delete [] fRawData; }
165
c689d2f6 166 inline void SetSize(Int_t size);
edbfa2f2 167 inline void SetBuffer(void *buf, Int_t size);
168 Int_t GetSize() const { return fSize; }
169 void *GetBuffer() { return fRawData; }
5ea08be4 170
c689d2f6 171private:
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
176
edbfa2f2 177 AliRawData(const AliRawData &); // not implemented, usage causes
04a8f0f9 178 AliRawData &operator=(const AliRawData &); // link time error
edbfa2f2 179
5ea08be4 180 ClassDef(AliRawData,1) // Alice raw event buffer
181};
182
edbfa2f2 183void AliRawData::SetSize(Int_t size)
c689d2f6 184{
edbfa2f2 185 if (size > fBufSize) {
186 if (fOwner) delete [] fRawData;
187 fRawData = new char [size];
188 fBufSize = size;
189 fOwner = kTRUE;
190 }
191 fSize = size;
c689d2f6 192}
193
edbfa2f2 194void AliRawData::SetBuffer(void *buf, Int_t size)
c689d2f6 195{
edbfa2f2 196 if (fOwner) delete [] fRawData;
197 fRawData = (char *) buf;
198 fBufSize = size;
199 fSize = size;
200 fOwner = kFALSE;
c689d2f6 201}
5ea08be4 202
5ea08be4 203
c689d2f6 204class AliRawEvent : public TObject {
5ea08be4 205
206public:
207 AliRawEvent();
208 virtual ~AliRawEvent();
209
c51de60d 210 AliRawEventHeader *GetHeader();
5ea08be4 211 AliRawEquipmentHeader *GetEquipmentHeader();
212 AliRawData *GetRawData();
213 Int_t GetNSubEvents() const { return fNSubEvents; }
214 AliRawEvent *NextSubEvent();
5459c838 215 AliRawEvent *GetSubEvent(Int_t index) const;
5ea08be4 216 void Reset();
217
c689d2f6 218private:
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
224
edbfa2f2 225 AliRawEvent(const AliRawEvent &); // not implemented, usage causes
04a8f0f9 226 AliRawEvent &operator=(const AliRawEvent &); // link time error
edbfa2f2 227
5ea08be4 228 ClassDef(AliRawEvent,1) // ALICE raw event object
229};
230
231
232class AliStats : public TObject {
233
5ea08be4 234public:
235 AliStats(const char *filename = "", Int_t compmode = 0, Bool_t filter = kFALSE);
236 virtual ~AliStats();
237 AliStats &operator=(const AliStats &rhs);
238
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);
248
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; }
262
c689d2f6 263private:
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
278
edbfa2f2 279 AliStats(const AliStats &); // not implemented
280
5ea08be4 281 ClassDef(AliStats,1) // Statistics object
282};
283
284
285class AliRawDB : public TObject {
286
5ea08be4 287public:
288 AliRawDB(AliRawEvent *event, Double_t maxsize, Int_t compress,
289 Bool_t create = kTRUE);
c689d2f6 290 virtual ~AliRawDB() { Close(); }
5ea08be4 291
06c6fef1 292 virtual const char *GetOpenOption() const { return "RECREATE"; }
edbfa2f2 293 virtual Int_t GetNetopt() const { return 0; }
06c6fef1 294 virtual Bool_t Create();
295 virtual void Close();
296 void Fill() { fTree->Fill(); }
297 Bool_t FileFull() { return (fRawDB->GetBytesWritten() > fMaxSize) ?
298 kTRUE : kFALSE; }
5ea08be4 299
06c6fef1 300 Bool_t NextFile();
5ea08be4 301
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(); }
309
c689d2f6 310protected:
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
316
317 virtual const char *GetFileName() const;
318 virtual Bool_t FSHasSpace(const char *fs) const;
319 virtual void MakeTree();
320
edbfa2f2 321private:
322 AliRawDB(const AliRawDB &); // not implemented, usage causes
04a8f0f9 323 AliRawDB &operator=(const AliRawDB &); // link time error
edbfa2f2 324
5ea08be4 325 ClassDef(AliRawDB,0) // Raw DB
326};
327
328
329class AliRawRFIODB : public AliRawDB {
330
5ea08be4 331public:
332 AliRawRFIODB(AliRawEvent *event, Double_t maxsize, Int_t compress);
333 ~AliRawRFIODB() { Close(); }
334
335 void Close();
336
c689d2f6 337private:
338 const char *GetFileName() const;
339
5ea08be4 340 ClassDef(AliRawRFIODB,0) // Raw DB via RFIO
341};
342
343
9174317d 344class AliRawCastorDB : public AliRawDB {
345
9174317d 346public:
347 AliRawCastorDB(AliRawEvent *event, Double_t maxsize, Int_t compress);
348 ~AliRawCastorDB() { Close(); }
349
06c6fef1 350 const char *GetOpenOption() const { return "-RECREATE"; }
edbfa2f2 351 Int_t GetNetopt() const { return 0; }
06c6fef1 352 void Close();
9174317d 353
c689d2f6 354private:
355 const char *GetFileName() const;
356
9174317d 357 ClassDef(AliRawCastorDB,0) // Raw DB via CASTOR and rootd
358};
359
360
5ea08be4 361class AliRawRootdDB : public AliRawDB {
362
5ea08be4 363public:
364 AliRawRootdDB(AliRawEvent *event, Double_t maxsize, Int_t compress);
365 ~AliRawRootdDB() { Close(); }
366
367 void Close();
368
c689d2f6 369private:
370 const char *GetFileName() const;
371
5ea08be4 372 ClassDef(AliRawRootdDB,0) // Raw DB via rootd
373};
374
375
376class AliRawNullDB : public AliRawDB {
377
5ea08be4 378public:
379 AliRawNullDB(AliRawEvent *event, Double_t maxsize, Int_t compress);
380 ~AliRawNullDB() { Close(); }
381
382 void Close();
383
c689d2f6 384private:
385 const char *GetFileName() const;
386
5ea08be4 387 ClassDef(AliRawNullDB,0) // Raw DB to /dev/null
388};
389
390
391class AliTagDB : public TObject {
392
5ea08be4 393public:
394 AliTagDB(AliRawEventHeader *header, Double_t maxsize, Bool_t create = kTRUE);
c689d2f6 395 virtual ~AliTagDB() { Close(); }
5ea08be4 396
397 Bool_t Create();
398 virtual void Close();
399 void Fill() { fTree->Fill(); }
400 Bool_t FileFull()
401 { return (fTagDB->GetBytesWritten() > fMaxSize) ? kTRUE : kFALSE; }
402
403 Bool_t NextFile();
404
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;
411
c689d2f6 412protected:
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
417
418 virtual const char *GetFileName() const;
419
edbfa2f2 420private:
421 AliTagDB(const AliTagDB &); // not implemented, usage causes
04a8f0f9 422 AliTagDB &operator=(const AliTagDB &); // link time error
edbfa2f2 423
5ea08be4 424 ClassDef(AliTagDB,0) // Tag DB
425};
426
427
428class AliTagNullDB : public AliTagDB {
429
5ea08be4 430public:
431 AliTagNullDB(AliRawEventHeader *header, Double_t maxsize);
432 ~AliTagNullDB() { Close(); }
433
434 void Close();
435
c689d2f6 436private:
437 const char *GetFileName() const;
438
5ea08be4 439 ClassDef(AliTagNullDB,0) // Tag DB to /dev/null
440};
441
442
443class AliRunDB : public TObject {
444
5ea08be4 445public:
8ee17d63 446 AliRunDB(Bool_t noLocalDB = kFALSE);
5ea08be4 447 ~AliRunDB() { Close(); }
448
449 void Update(AliStats *stats);
450 void UpdateRDBMS(AliStats *stats);
9174317d 451 void UpdateAliEn(AliStats *stats);
5ea08be4 452 void Close();
453
c689d2f6 454private:
455 TFile *fRunDB; // run database
456
edbfa2f2 457 AliRunDB(const AliRunDB &); // not implemented, usage causes
04a8f0f9 458 AliRunDB &operator=(const AliRunDB &); // link time error
edbfa2f2 459
5ea08be4 460 ClassDef(AliRunDB,0) // Run (bookkeeping) DB
461};
462
463
464class AliMDC : public TObject {
465
9174317d 466public:
467 enum EWriteMode { kLOCAL, kRFIO, kROOTD, kCASTOR, kDEVNULL };
468
c689d2f6 469 AliMDC(Int_t fd, Int_t compress, Double_t maxFileSize, Bool_t useFilter,
470 EWriteMode mode, Bool_t useLoop, Bool_t delFiles);
471 ~AliMDC() { }
472
473 Int_t Run();
474 void SetStopLoop() { fStopLoop = kTRUE; }
475 Bool_t StopLoop() const { return fStopLoop; }
476
477 void SetDebugLevel(Int_t level) { fDebugLevel = level; }
478 Int_t GetDebugLevel() const { return fDebugLevel; }
479
480 static Bool_t DeleteFiles() { return fgDeleteFiles; }
481
5ea08be4 482private:
9174317d 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)
5ea08be4 494
c689d2f6 495 static Bool_t fgDeleteFiles; // flag for deletion of files
5ea08be4 496
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);
505
5ea08be4 506 ClassDef(AliMDC,0) // MDC processor
507};
508
509R__EXTERN AliMDC *gAliMDC;
510
511#define ALIDEBUG(level) \
86f15b50 512 if (gAliMDC && (gAliMDC->GetDebugLevel() >= (level)))
5ea08be4 513
514#endif