]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RAW/AliRawReader.h
Bug fix: the pointer was not reset after freeing the event.
[u/mrichter/AliRoot.git] / RAW / AliRawReader.h
1 #ifndef ALIRAWREADER_H
2 #define ALIRAWREADER_H
3 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4  * See cxx source for full Copyright notice                               */
5
6 /* $Id$ */
7
8 ///////////////////////////////////////////////////////////////////////////////
9 ///
10 /// This is the base class for reading raw data.
11 ///
12 ///////////////////////////////////////////////////////////////////////////////
13
14 #include <TObject.h>
15 #include <TArrayI.h>
16 #include <TClonesArray.h>
17
18 #include "AliRawDataErrorLog.h"
19 #include "AliRawDataHeader.h"
20
21 class TChain;
22 class AliRawEventHeaderBase;
23 class AliRawVEvent;
24
25 class AliRawReader: public TObject {
26   public :
27     AliRawReader();
28     AliRawReader(const AliRawReader& rawReader);
29     AliRawReader& operator = (const AliRawReader& rawReader);
30     virtual ~AliRawReader();
31
32     static  AliRawReader* Create(const char *uri);
33
34     virtual void     Select(Int_t detectorID, 
35                             Int_t minDDLID = -1, Int_t maxDDLID = -1);
36     virtual void     Select(const char *detectorName, 
37                             Int_t minDDLID = -1, Int_t maxDDLID = -1);
38     virtual void     SelectEquipment(Int_t equipmentType, 
39                                      Int_t minEquipmentId = -1, 
40                                      Int_t maxEquipmentId = -1);
41     virtual void     SkipInvalid(Bool_t skip = kTRUE)
42       {fSkipInvalid = skip;};
43     virtual void     RequireHeader(Bool_t required)
44       {fRequireHeader = required;};
45
46     virtual const AliRawEventHeaderBase* GetEventHeader() const {return NULL;};
47     virtual const AliRawVEvent* GetEvent() const {return NULL;}
48
49     virtual UInt_t   GetType() const = 0;
50     virtual UInt_t   GetRunNumber() const = 0;
51     virtual const UInt_t* GetEventId() const = 0;
52     UInt_t                GetPeriod() const {
53       const UInt_t *id = GetEventId();
54       return id ? (((id)[0]>>4)&0x0fffffff): 0;
55     }
56     UInt_t                GetOrbitID() const {
57       const UInt_t *id = GetEventId();
58       return id ? ((((id)[0]<<20)&0xf00000)|(((id)[1]>>12)&0xfffff)) : 0;
59     }
60     UShort_t              GetBCID() const {
61       const UInt_t *id = GetEventId();
62       return id ? ((id)[1]&0x00000fff) : 0;
63     }
64     virtual const UInt_t* GetTriggerPattern() const = 0;
65     ULong64_t             GetClassMask() const {
66       const UInt_t *pattern = GetTriggerPattern();
67       return pattern ? (((ULong64_t)pattern[1] & 0x3ffff) << 32)|(pattern[0]) : 0;
68     }
69     virtual const UInt_t* GetDetectorPattern() const = 0;
70     virtual const UInt_t* GetAttributes() const = 0;
71     virtual const UInt_t* GetSubEventAttributes() const = 0;
72     virtual UInt_t   GetLDCId() const = 0;
73     virtual UInt_t   GetGDCId() const = 0;
74     virtual UInt_t   GetTimestamp() const = 0;
75
76     virtual Int_t    GetEquipmentSize() const = 0;
77     virtual Int_t    GetEquipmentType() const = 0;
78     virtual Int_t    GetEquipmentId() const = 0;
79     Int_t            GetMappedEquipmentId() const;
80     Bool_t           LoadEquipmentIdsMap(const char *fileName);
81     virtual const UInt_t* GetEquipmentAttributes() const = 0;
82     virtual Int_t    GetEquipmentElementSize() const = 0;
83     virtual Int_t    GetEquipmentHeaderSize() const = 0;
84
85     Int_t            GetDetectorID() const;
86     Int_t            GetDDLID() const;
87
88     Int_t            GetDataSize() const 
89       {if (fHeader) {
90         if (fHeader->fSize != 0xFFFFFFFF) return fHeader->fSize - sizeof(AliRawDataHeader); 
91         else return GetEquipmentSize() - GetEquipmentHeaderSize() - sizeof(AliRawDataHeader);
92       } else return GetEquipmentSize() - GetEquipmentHeaderSize();};
93
94     Int_t            GetVersion() const 
95       {if (fHeader) return fHeader->GetVersion(); else return -1;};
96     Bool_t           IsValid() const 
97       {if (fHeader) return fHeader->TestAttribute(0); 
98       else return kFALSE;};
99     Bool_t           IsCompressed() const 
100       {if (fHeader) return fHeader->TestAttribute(1); 
101       else return kFALSE;};
102     Bool_t           TestBlockAttribute(Int_t index) const
103       {if (fHeader) return fHeader->TestAttribute(index); 
104       else return kFALSE;};
105     UChar_t          GetBlockAttributes() const 
106       {if (fHeader) return fHeader->GetAttributes(); 
107       else return 0;};
108     UInt_t           GetStatusBits() const
109       {if (fHeader) return fHeader->GetStatus(); 
110       else return 0;};
111     const AliRawDataHeader* GetDataHeader() const
112       {return fHeader;}
113
114     virtual Bool_t   ReadHeader() = 0;
115     virtual Bool_t   ReadNextData(UChar_t*& data) = 0;
116     virtual Bool_t   ReadNextInt(UInt_t& data);
117     virtual Bool_t   ReadNextShort(UShort_t& data);
118     virtual Bool_t   ReadNextChar(UChar_t& data);
119     virtual Bool_t   ReadNext(UChar_t* data, Int_t size) = 0;
120
121     virtual Bool_t   Reset() = 0;
122
123     virtual Bool_t   NextEvent() = 0;
124     virtual Bool_t   RewindEvents() = 0;
125     virtual Bool_t   GotoEvent(Int_t event);
126     virtual Bool_t   GotoEventWithID(Int_t event,
127                                      UInt_t period,
128                                      UInt_t orbitID,
129                                      UShort_t bcID);
130     virtual Int_t    GetEventIndex() const { return -1; }
131     virtual Int_t    GetNumberOfEvents() const { return -1; }
132
133     enum {kErrMagic=1, kErrNoDataHeader=2, 
134           kErrSize=4, kErrOutOfBounds=8};
135     virtual Int_t    CheckData() const;
136     Int_t            GetErrorCode() const {return fErrorCode;};
137
138     void             DumpData(Int_t limit = -1);
139
140     void             AddErrorLog(AliRawDataErrorLog::ERawDataErrorLevel level,
141                                  Int_t code,
142                                  const char *message = NULL);
143     void             AddMinorErrorLog(Int_t code,
144                                       const char *message = NULL) {
145       return AddErrorLog(AliRawDataErrorLog::kMinor,code,message);
146     }
147     void             AddMajorErrorLog(Int_t code,
148                                       const char *message = NULL) {
149       return AddErrorLog(AliRawDataErrorLog::kMajor,code,message);
150     }
151     void             AddFatalErrorLog(Int_t code,
152                                       const char *message = NULL) {
153       return AddErrorLog(AliRawDataErrorLog::kFatal,code,message);
154     }
155     Int_t            GetNumberOfErrorLogs() const { return fErrorLogs.GetEntriesFast(); }
156     const TClonesArray &GetAllErrorLogs() const { return fErrorLogs; }
157     AliRawDataErrorLog *GetErrorLog(Int_t i) const {
158       return (AliRawDataErrorLog *)fErrorLogs.UncheckedAt(i);
159     }
160
161     // Method which can be used in order to force the auto-save on
162     // ESD tree inside AliReconstruction. For the moment it will be
163     // activated only for AliRawReaderDateOnline.
164     virtual Bool_t   UseAutoSaveESD() const { return kFALSE; }
165     virtual TChain*  GetChain() const { return NULL; }
166
167     Bool_t           IsRawReaderValid() const { return fIsValid; }
168
169     void             LoadTriggerClass(const char* name, Int_t index);
170
171     virtual AliRawReader* CloneSingleEvent() const { return NULL; }
172
173   protected :
174     virtual void     SelectEvents(Int_t type, ULong64_t triggerMask = 0, const char *triggerExpr = NULL);
175     Bool_t           IsSelected() const;
176     Bool_t           IsEventSelected() const;
177
178     TArrayI         *fEquipmentIdsIn;       // array of equipment Ids to be mapped
179     TArrayI         *fEquipmentIdsOut;      // array of mapped equipment Ids
180
181     Bool_t           fRequireHeader;        // if false, data without header is accepted
182
183     AliRawDataHeader* fHeader;              // current data header
184     Int_t            fCount;                // counter of bytes to be read for current DDL
185
186     Int_t            fSelectEquipmentType;  // type of selected equipment (<0 = no selection)
187     Int_t            fSelectMinEquipmentId; // minimal index of selected equipment (<0 = no selection)
188     Int_t            fSelectMaxEquipmentId; // maximal index of selected equipment (<0 = no selection)
189     Bool_t           fSkipInvalid;          // skip invalid data
190     Int_t            fSelectEventType;      // type of selected events (<0 = no selection)
191     ULong64_t        fSelectTriggerMask;    // trigger mask for selecting events (0 = no selection)
192     TString          fSelectTriggerExpr;    // trigger expression for selecting events (empty = no selection)
193
194     Int_t            fErrorCode;            // code of last error
195
196     Int_t            fEventNumber;          // current event number
197     TClonesArray     fErrorLogs;            // raw data decoding errors
198
199     AliRawDataHeader* fHeaderSwapped;       // temporary buffer for swapping header on PowerPC
200
201     UInt_t SwapWord(UInt_t x) const;
202     UShort_t SwapShort(UShort_t x) const;
203
204     Bool_t           fIsValid;              // is raw-reader created successfully
205
206     ClassDef(AliRawReader, 0) // base class for reading raw digits
207 };
208
209 #endif