]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RAW/AliRawEvent.h
fix memory leak
[u/mrichter/AliRoot.git] / RAW / AliRawEvent.h
CommitLineData
5ea08be4 1// @(#)alimdc:$Name$:$Id$
2// Author: Fons Rademakers 26/11/99
3// Updated: Dario Favretto 15/04/2003
4
5#ifndef ALIRAWEVENT_H
6#define ALIRAWEVENT_H
7
8#ifndef ROOT_TObject
9#include <TObject.h>
10#endif
11
12#ifndef ROOT_Bytes
13#include <Bytes.h>
14#endif
15
16#ifndef ROOT_TDatime
17#include <TDatime.h>
18#endif
19
20#ifndef ROOT_TString
21#include <TString.h>
22#endif
23
24#ifndef ROOT_TFile
25#include <TFile.h>
26#endif
27
28#ifndef ROOT_TTree
29#include <TTree.h>
30#endif
31
04fa961a 32#ifndef ROOT_TH1
33#include <TH1.h>
34#endif
35
5ea08be4 36
37// Forward class declarations
5ea08be4 38class AliRawDB;
39
40
41// The following enumeration can be used once the kEventTypeMask has been
42// applied to the raw event type
43enum 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
53};
54
55const Int_t kEventTypeMin = kStartOfRun;
56const Int_t kEventTypeMax = kFormatError;
57
58const UInt_t kEventMagicNumber = 0xDA1E5AFE;
59const UInt_t kEventMagicNumberSwapped = 0xFE5A1EDA;
60
61// Type sizes
62const Int_t kIdWords = 2;
63const Int_t kTriggerWords = 2;
64const Int_t kDetectorWords = 1;
65const Int_t kAttributeWords = 3;
66
67
68class AliRawEventHeader : public TObject {
69
70private:
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
83
84public:
85 AliRawEventHeader() { fSize = 0; }
86 virtual ~AliRawEventHeader() { }
87
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); }
93 void Swap();
94
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; }
109
110 ClassDef(AliRawEventHeader,1) // Alice raw event header
111};
112
113
114class AliRawEquipmentHeader : public TObject {
115
116private:
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
122
123public:
124 AliRawEquipmentHeader() { fSize = 0; }
125 ~AliRawEquipmentHeader() { }
126
127 void *HeaderBegin() { return (void *) &fSize; }
128 Int_t HeaderSize() const { return (Long_t) &fBasicElementSizeType - (Long_t) &fSize + sizeof(fBasicElementSizeType); }
129 void Swap();
130
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; }
136
137 ClassDef(AliRawEquipmentHeader,1) //Alice equipment header
138};
139
140
141class AliRawData : public TObject {
142
143private:
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
148
149public:
8f66d77e 150 AliRawData() { fSize = fBufSize = 0; fRawData = 0; fOwner = kTRUE; }
5ea08be4 151 virtual ~AliRawData() { if (fOwner) delete [] fRawData; }
152
153 void SetSize(Int_t size) {
154 if (size > fBufSize) {
155 if (fOwner) delete [] fRawData;
156 fRawData = new char [size];
157 fBufSize = size;
158 fOwner = kTRUE;
159 }
160 fSize = size;
161 }
162 void SetBuffer(void *buf, Int_t size) {
163 if (fOwner) delete [] fRawData;
164 fRawData = (char *) buf;
165 fBufSize = size;
166 fSize = size;
167 fOwner = kFALSE;
168 }
169 Int_t GetSize() const { return fSize; }
170 void *GetBuffer() { return fRawData; }
171
172 ClassDef(AliRawData,1) // Alice raw event buffer
173};
174
175
176class AliRawEvent : public TObject {
177
178private:
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
184
185public:
186 AliRawEvent();
187 virtual ~AliRawEvent();
188
c51de60d 189 AliRawEventHeader *GetHeader();
5ea08be4 190 AliRawEquipmentHeader *GetEquipmentHeader();
191 AliRawData *GetRawData();
192 Int_t GetNSubEvents() const { return fNSubEvents; }
193 AliRawEvent *NextSubEvent();
5459c838 194 AliRawEvent *GetSubEvent(Int_t index) const;
5ea08be4 195 void Reset();
196
197 ClassDef(AliRawEvent,1) // ALICE raw event object
198};
199
200
201class AliStats : public TObject {
202
203private:
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
218
219public:
220 AliStats(const char *filename = "", Int_t compmode = 0, Bool_t filter = kFALSE);
221 virtual ~AliStats();
222 AliStats &operator=(const AliStats &rhs);
223
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);
233
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; }
247
248 ClassDef(AliStats,1) // Statistics object
249};
250
251
252class AliRawDB : public TObject {
253
254protected:
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
260
261 virtual const char *GetFileName();
262 virtual Bool_t FSHasSpace(const char *fs);
263 virtual void MakeTree();
264
265public:
266 AliRawDB(AliRawEvent *event, Double_t maxsize, Int_t compress,
267 Bool_t create = kTRUE);
268 ~AliRawDB() { Close(); }
269
06c6fef1 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) ?
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
287 ClassDef(AliRawDB,0) // Raw DB
288};
289
290
291class AliRawRFIODB : public AliRawDB {
292
293private:
294 const char *GetFileName();
295
296public:
297 AliRawRFIODB(AliRawEvent *event, Double_t maxsize, Int_t compress);
298 ~AliRawRFIODB() { Close(); }
299
300 void Close();
301
302 ClassDef(AliRawRFIODB,0) // Raw DB via RFIO
303};
304
305
9174317d 306class AliRawCastorDB : public AliRawDB {
307
308private:
309 const char *GetFileName();
310
311public:
312 AliRawCastorDB(AliRawEvent *event, Double_t maxsize, Int_t compress);
313 ~AliRawCastorDB() { Close(); }
314
06c6fef1 315 const char *GetOpenOption() const { return "-RECREATE"; }
316 void Close();
9174317d 317
318 ClassDef(AliRawCastorDB,0) // Raw DB via CASTOR and rootd
319};
320
321
5ea08be4 322class AliRawRootdDB : public AliRawDB {
323
324private:
325 const char *GetFileName();
326
327public:
328 AliRawRootdDB(AliRawEvent *event, Double_t maxsize, Int_t compress);
329 ~AliRawRootdDB() { Close(); }
330
331 void Close();
332
333 ClassDef(AliRawRootdDB,0) // Raw DB via rootd
334};
335
336
337class AliRawNullDB : public AliRawDB {
338
339private:
340 const char *GetFileName();
341
342public:
343 AliRawNullDB(AliRawEvent *event, Double_t maxsize, Int_t compress);
344 ~AliRawNullDB() { Close(); }
345
346 void Close();
347
348 ClassDef(AliRawNullDB,0) // Raw DB to /dev/null
349};
350
351
352class AliTagDB : public TObject {
353
354protected:
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
359
360 virtual const char *GetFileName();
361
362public:
363 AliTagDB(AliRawEventHeader *header, Double_t maxsize, Bool_t create = kTRUE);
364 ~AliTagDB() { Close(); }
365
366 Bool_t Create();
367 virtual void Close();
368 void Fill() { fTree->Fill(); }
369 Bool_t FileFull()
370 { return (fTagDB->GetBytesWritten() > fMaxSize) ? kTRUE : kFALSE; }
371
372 Bool_t NextFile();
373
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;
380
381 ClassDef(AliTagDB,0) // Tag DB
382};
383
384
385class AliTagNullDB : public AliTagDB {
386
387private:
388 const char *GetFileName();
389
390public:
391 AliTagNullDB(AliRawEventHeader *header, Double_t maxsize);
392 ~AliTagNullDB() { Close(); }
393
394 void Close();
395
396 ClassDef(AliTagNullDB,0) // Tag DB to /dev/null
397};
398
399
400class AliRunDB : public TObject {
401
402private:
403 TFile *fRunDB; // run database
404
405public:
8ee17d63 406 AliRunDB(Bool_t noLocalDB = kFALSE);
5ea08be4 407 ~AliRunDB() { Close(); }
408
409 void Update(AliStats *stats);
410 void UpdateRDBMS(AliStats *stats);
9174317d 411 void UpdateAliEn(AliStats *stats);
5ea08be4 412 void Close();
413
414 ClassDef(AliRunDB,0) // Run (bookkeeping) DB
415};
416
417
418class AliMDC : public TObject {
419
9174317d 420public:
421 enum EWriteMode { kLOCAL, kRFIO, kROOTD, kCASTOR, kDEVNULL };
422
5ea08be4 423private:
9174317d 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)
5ea08be4 435
436 static Bool_t fgDeleteFiles;
437
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);
446
447public:
448 AliMDC(Int_t fd, Int_t compress, Double_t maxFileSize, Bool_t useFilter,
9174317d 449 EWriteMode mode, Bool_t useLoop, Bool_t delFiles);
5ea08be4 450 ~AliMDC() { }
451
452 Int_t Run();
453 void SetStopLoop() { fStopLoop = kTRUE; }
454 Bool_t StopLoop() const { return fStopLoop; }
455
456 void SetDebugLevel(Int_t level) { fDebugLevel = level; }
86f15b50 457 Int_t GetDebugLevel() const { return fDebugLevel; }
5ea08be4 458
459 static Bool_t DeleteFiles() { return fgDeleteFiles; }
460
461 ClassDef(AliMDC,0) // MDC processor
462};
463
464R__EXTERN AliMDC *gAliMDC;
465
466#define ALIDEBUG(level) \
86f15b50 467 if (gAliMDC && (gAliMDC->GetDebugLevel() >= (level)))
5ea08be4 468
469#endif