]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RAW/AliRawEvent.h
Update for station2:
[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:
150 AliRawData() { fSize = fBufSize = 0; fRawData = 0; fOwner = kFALSE; }
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
189 AliRawEventHeader *GetHeader() const { return fEvtHdr; }
190 AliRawEquipmentHeader *GetEquipmentHeader();
191 AliRawData *GetRawData();
192 Int_t GetNSubEvents() const { return fNSubEvents; }
193 AliRawEvent *NextSubEvent();
04fa961a 194 AliRawEvent *GetSubEvent(Int_t index);
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
270 virtual Bool_t Create();
271 virtual void Close();
272 void Fill() { fTree->Fill(); }
273 Bool_t FileFull() { return (fRawDB->GetBytesWritten() > fMaxSize) ?
274 kTRUE : kFALSE; }
275
276 Bool_t NextFile();
277
278 Double_t GetBytesWritten() const { return fRawDB->GetBytesWritten(); }
279 TFile *GetDB() const { return fRawDB; }
280 const char *GetDBName() const { return fRawDB->GetName(); }
281 Int_t GetEvents() const { return (Int_t) fTree->GetEntries(); }
282 AliRawEvent *GetEvent() const { return fEvent; }
283 Float_t GetCompressionFactor() const;
284 Int_t GetCompressionMode() const { return fRawDB->GetCompressionLevel(); }
285
286 ClassDef(AliRawDB,0) // Raw DB
287};
288
289
290class AliRawRFIODB : public AliRawDB {
291
292private:
293 const char *GetFileName();
294
295public:
296 AliRawRFIODB(AliRawEvent *event, Double_t maxsize, Int_t compress);
297 ~AliRawRFIODB() { Close(); }
298
299 void Close();
300
301 ClassDef(AliRawRFIODB,0) // Raw DB via RFIO
302};
303
304
305class AliRawRootdDB : public AliRawDB {
306
307private:
308 const char *GetFileName();
309
310public:
311 AliRawRootdDB(AliRawEvent *event, Double_t maxsize, Int_t compress);
312 ~AliRawRootdDB() { Close(); }
313
314 void Close();
315
316 ClassDef(AliRawRootdDB,0) // Raw DB via rootd
317};
318
319
320class AliRawNullDB : public AliRawDB {
321
322private:
323 const char *GetFileName();
324
325public:
326 AliRawNullDB(AliRawEvent *event, Double_t maxsize, Int_t compress);
327 ~AliRawNullDB() { Close(); }
328
329 void Close();
330
331 ClassDef(AliRawNullDB,0) // Raw DB to /dev/null
332};
333
334
335class AliTagDB : public TObject {
336
337protected:
338 TFile *fTagDB; // DB to store header information only (tag)
339 TTree *fTree; // tree use to store header
340 AliRawEventHeader *fHeader; // header via which data is stored
341 Double_t fMaxSize; // maximum size in bytes of tag DB
342
343 virtual const char *GetFileName();
344
345public:
346 AliTagDB(AliRawEventHeader *header, Double_t maxsize, Bool_t create = kTRUE);
347 ~AliTagDB() { Close(); }
348
349 Bool_t Create();
350 virtual void Close();
351 void Fill() { fTree->Fill(); }
352 Bool_t FileFull()
353 { return (fTagDB->GetBytesWritten() > fMaxSize) ? kTRUE : kFALSE; }
354
355 Bool_t NextFile();
356
357 Double_t GetBytesWritten() const { return fTagDB->GetBytesWritten(); }
358 TFile *GetDB() const { return fTagDB; }
359 const char *GetDBName() const { return fTagDB->GetName(); }
360 AliRawEventHeader *GetHeader() const { return fHeader; }
361 Int_t GetEvents() const { return (Int_t) fTree->GetEntries(); }
362 Float_t GetCompressionFactor() const;
363
364 ClassDef(AliTagDB,0) // Tag DB
365};
366
367
368class AliTagNullDB : public AliTagDB {
369
370private:
371 const char *GetFileName();
372
373public:
374 AliTagNullDB(AliRawEventHeader *header, Double_t maxsize);
375 ~AliTagNullDB() { Close(); }
376
377 void Close();
378
379 ClassDef(AliTagNullDB,0) // Tag DB to /dev/null
380};
381
382
383class AliRunDB : public TObject {
384
385private:
386 TFile *fRunDB; // run database
387
388public:
389 AliRunDB();
390 ~AliRunDB() { Close(); }
391
392 void Update(AliStats *stats);
393 void UpdateRDBMS(AliStats *stats);
394 void Close();
395
396 ClassDef(AliRunDB,0) // Run (bookkeeping) DB
397};
398
399
400class AliMDC : public TObject {
401
402private:
403 Int_t fFd; // DATE input stream
404 Int_t fCompress; // compression factor used for raw output DB
405 Int_t fNumEvents; // number of events processed
406 Int_t fDebugLevel; // controls debug print-out
407 Double_t fMaxFileSize; // maximum size of raw output DB
408 Bool_t fUseFifo; // read from fifo, file otherwise
409 Bool_t fUseEb; // use event builder API instead of fifo
410 Bool_t fUseFilter; // use 3rd level trigger filter
411 Bool_t fUseRFIO; // write directly to RFIO file
412 Bool_t fUseRootd; // write directly to rootd file
413 Bool_t fUseDevNull; // write to /dev/null
414 Bool_t fUseLoop; // loop on input source (must be file)
415 Bool_t fStopLoop; // break from endless loop (triggered by SIGUSR1)
416
417 static Bool_t fgDeleteFiles;
418
419 Int_t Read(const char *name) { return TObject::Read(name); }
420 Int_t Read(void *buffer, Int_t length);
421 Int_t ReadHeader(AliRawEventHeader &header, void *eb = 0);
422 Int_t ReadEquipmentHeader(AliRawEquipmentHeader &header,
423 Bool_t isSwapped, void *eb = 0);
424 Int_t ReadRawData(AliRawData &raw, Int_t size, void *eb = 0);
425 Int_t DumpEvent(Int_t toRead);
426 Int_t Filter(AliRawData &raw);
427
428public:
429 AliMDC(Int_t fd, Int_t compress, Double_t maxFileSize, Bool_t useFilter,
430 Bool_t useRFIO, Bool_t useROOTD, Bool_t useDEVNULL,
431 Bool_t useLoop, Bool_t delFiles);
432 ~AliMDC() { }
433
434 Int_t Run();
435 void SetStopLoop() { fStopLoop = kTRUE; }
436 Bool_t StopLoop() const { return fStopLoop; }
437
438 void SetDebugLevel(Int_t level) { fDebugLevel = level; }
439 Bool_t GetDebugLevel() const { return fDebugLevel; }
440
441 static Bool_t DeleteFiles() { return fgDeleteFiles; }
442
443 ClassDef(AliMDC,0) // MDC processor
444};
445
446R__EXTERN AliMDC *gAliMDC;
447
448#define ALIDEBUG(level) \
449 if (gAliMDC && gAliMDC->GetDebugLevel() >= (level))
450
451#endif