3 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * See cxx source for full Copyright notice */
8 ///////////////////////////////////////////////////////////////////////////////
10 /// This is the base class for reading raw data.
12 ///////////////////////////////////////////////////////////////////////////////
16 #include <TClonesArray.h>
18 #include "AliRawDataErrorLog.h"
19 #include "AliRawDataHeader.h"
20 #include "AliRawDataHeaderV3.h"
24 class AliRawEventHeaderBase;
27 class AliRawReader: public TObject {
28 friend class AliEveEventManager;
31 AliRawReader(const AliRawReader& rawReader);
32 AliRawReader& operator = (const AliRawReader& rawReader);
33 virtual ~AliRawReader();
35 static AliRawReader* Create(const char *uri);
37 virtual void Select(Int_t detectorID,
38 Int_t minDDLID = -1, Int_t maxDDLID = -1);
39 virtual void Select(const char *detectorName,
40 Int_t minDDLID = -1, Int_t maxDDLID = -1);
41 virtual void SelectEquipment(Int_t equipmentType,
42 Int_t minEquipmentId = -1,
43 Int_t maxEquipmentId = -1);
44 virtual void SkipInvalid(Bool_t skip = kTRUE)
45 {fSkipInvalid = skip;};
46 virtual void RequireHeader(Bool_t required)
47 {fRequireHeader = required;};
49 virtual const AliRawEventHeaderBase* GetEventHeader() const {return NULL;};
50 virtual const AliRawVEvent* GetEvent() const {return NULL;}
52 virtual UInt_t GetType() const = 0;
53 virtual UInt_t GetRunNumber() const = 0;
54 virtual const UInt_t* GetEventId() const = 0;
55 UInt_t GetPeriod() const {
56 const UInt_t *id = GetEventId();
57 return id ? (((id)[0]>>4)&0x0fffffff): 0;
59 UInt_t GetOrbitID() const {
60 const UInt_t *id = GetEventId();
61 return id ? ((((id)[0]<<20)&0xf00000)|(((id)[1]>>12)&0xfffff)) : 0;
63 UShort_t GetBCID() const {
64 const UInt_t *id = GetEventId();
65 return id ? ((id)[1]&0x00000fff) : 0;
67 ULong64_t GetEventIdAsLong() const {
68 return (((ULong64_t)GetPeriod() << 36) |
69 ((ULong64_t)GetOrbitID() << 12) |
70 (ULong64_t)GetBCID());
72 virtual const UInt_t* GetTriggerPattern() const = 0;
73 ULong64_t GetClassMask() const {
74 const UInt_t *pattern = GetTriggerPattern();
75 return pattern ? (((ULong64_t)pattern[1] & 0x3ffff) << 32)|(pattern[0]) : 0;
77 ULong64_t GetClassMaskNext50() const {
78 const UInt_t *pattern = GetTriggerPattern();
79 return pattern ? ((ULong64_t)(pattern[1]>>18) & 0x3fff)|((ULong64_t)(pattern[2]&0xffffffff)<<14)|((ULong64_t)(pattern[3]&0xf)<<46): 0;
81 virtual const UInt_t* GetDetectorPattern() const = 0;
82 virtual const UInt_t* GetAttributes() const = 0;
83 virtual const UInt_t* GetSubEventAttributes() const = 0;
84 virtual UInt_t GetLDCId() const = 0;
85 virtual UInt_t GetGDCId() const = 0;
86 virtual UInt_t GetTimestamp() const = 0;
88 virtual Int_t GetEquipmentSize() const = 0;
89 virtual Int_t GetEquipmentType() const = 0;
90 virtual Int_t GetEquipmentId() const = 0;
91 Int_t GetMappedEquipmentId() const;
92 Bool_t LoadEquipmentIdsMap(const char *fileName);
93 virtual const UInt_t* GetEquipmentAttributes() const = 0;
94 virtual Int_t GetEquipmentElementSize() const = 0;
95 virtual Int_t GetEquipmentHeaderSize() const = 0;
97 Int_t GetDetectorID() const;
98 Int_t GetDDLID() const;
100 Int_t GetDataSize() const
102 if (fHeader->fSize != 0xFFFFFFFF) return fHeader->fSize - sizeof(AliRawDataHeader);
103 else return GetEquipmentSize() - GetEquipmentHeaderSize() - sizeof(AliRawDataHeader);
104 } else if(fHeaderV3){
105 if (fHeaderV3->fSize != 0xFFFFFFFF) return fHeaderV3->fSize - sizeof(AliRawDataHeaderV3);
106 else return GetEquipmentSize() - GetEquipmentHeaderSize() - sizeof(AliRawDataHeaderV3);
108 else return GetEquipmentSize() - GetEquipmentHeaderSize();};
110 Int_t GetVersion() const
111 {if (fHeader) return fHeader->GetVersion();
112 else if (fHeaderV3) return fHeaderV3->GetVersion();
114 Bool_t IsValid() const
115 {if (fHeader) return fHeader->TestAttribute(0);
116 else if (fHeaderV3) return fHeaderV3->TestAttribute(0);
117 else return kFALSE;};
118 Bool_t IsCompressed() const
119 {if (fHeader) return fHeader->TestAttribute(1);
120 else if (fHeaderV3) return fHeaderV3->TestAttribute(1);
121 else return kFALSE;};
122 Bool_t TestBlockAttribute(Int_t index) const
123 {if (fHeader) return fHeader->TestAttribute(index);
124 else if (fHeaderV3) return fHeaderV3->TestAttribute(index);
125 else return kFALSE;};
126 UChar_t GetBlockAttributes() const
127 {if (fHeader) return fHeader->GetAttributes();
128 else if (fHeaderV3) return fHeaderV3->GetAttributes();
130 UInt_t GetStatusBits() const
131 {if (fHeader) return fHeader->GetStatus();
132 else if (fHeaderV3) return fHeaderV3->GetStatus();
134 const AliRawDataHeader* GetDataHeader() const
136 const AliRawDataHeaderV3* GetDataHeaderV3() const
139 virtual Bool_t ReadHeader() = 0;
140 virtual Bool_t ReadNextData(UChar_t*& data) = 0;
141 virtual Bool_t ReadNextInt(UInt_t& data);
142 virtual Bool_t ReadNextShort(UShort_t& data);
143 virtual Bool_t ReadNextChar(UChar_t& data);
144 virtual Bool_t ReadNext(UChar_t* data, Int_t size) = 0;
146 virtual Bool_t Reset() = 0;
148 virtual Bool_t NextEvent() = 0;
149 virtual Bool_t RewindEvents() = 0;
150 virtual Bool_t GotoEvent(Int_t event);
151 virtual Bool_t GotoEventWithID(Int_t event,
155 virtual Int_t GetEventIndex() const { return -1; }
156 virtual Int_t GetNumberOfEvents() const { return -1; }
158 enum {kErrMagic=1, kErrNoDataHeader=2,
159 kErrSize=4, kErrOutOfBounds=8};
160 virtual Int_t CheckData() const;
161 Int_t GetErrorCode() const {return fErrorCode;};
163 void DumpData(Int_t limit = -1);
165 void AddErrorLog(AliRawDataErrorLog::ERawDataErrorLevel level,
167 const char *message = NULL);
168 void AddMinorErrorLog(Int_t code,
169 const char *message = NULL) {
170 return AddErrorLog(AliRawDataErrorLog::kMinor,code,message);
172 void AddMajorErrorLog(Int_t code,
173 const char *message = NULL) {
174 return AddErrorLog(AliRawDataErrorLog::kMajor,code,message);
176 void AddFatalErrorLog(Int_t code,
177 const char *message = NULL) {
178 return AddErrorLog(AliRawDataErrorLog::kFatal,code,message);
180 Int_t GetNumberOfErrorLogs() const { return fErrorLogs.GetEntriesFast(); }
181 const TClonesArray &GetAllErrorLogs() const { return fErrorLogs; }
182 AliRawDataErrorLog *GetErrorLog(Int_t i) const {
183 return (AliRawDataErrorLog *)fErrorLogs.UncheckedAt(i);
186 // Method which can be used in order to force the auto-save on
187 // ESD tree inside AliReconstruction. For the moment it will be
188 // activated only for AliRawReaderDateOnline.
189 virtual Bool_t UseAutoSaveESD() const { return kFALSE; }
190 virtual TChain* GetChain() const { return NULL; }
192 Bool_t IsRawReaderValid() const { return fIsValid; }
194 void LoadTriggerClass(const char* name, Int_t index);
195 void LoadTriggerAlias(const THashList *lst);
197 virtual AliRawReader* CloneSingleEvent() const { return NULL; }
200 virtual void SelectEvents(Int_t type, ULong64_t triggerMask = 0, const char *triggerExpr = NULL);
201 Bool_t IsSelected() const;
202 Bool_t IsEventSelected() const;
204 TArrayI *fEquipmentIdsIn; // array of equipment Ids to be mapped
205 TArrayI *fEquipmentIdsOut; // array of mapped equipment Ids
207 Bool_t fRequireHeader; // if false, data without header is accepted
209 AliRawDataHeader* fHeader; // current data header
210 AliRawDataHeaderV3* fHeaderV3; // current data header
211 Int_t fCount; // counter of bytes to be read for current DDL
213 Int_t fSelectEquipmentType; // type of selected equipment (<0 = no selection)
214 Int_t fSelectMinEquipmentId; // minimal index of selected equipment (<0 = no selection)
215 Int_t fSelectMaxEquipmentId; // maximal index of selected equipment (<0 = no selection)
216 Bool_t fSkipInvalid; // skip invalid data
217 Int_t fSelectEventType; // type of selected events (<0 = no selection)
218 ULong64_t fSelectTriggerMask; // trigger mask for selecting events (0 = no selection)
219 TString fSelectTriggerExpr; // trigger expression for selecting events (empty = no selection)
221 Int_t fErrorCode; // code of last error
223 Int_t fEventNumber; // current event number
224 TClonesArray fErrorLogs; // raw data decoding errors
226 AliRawDataHeader* fHeaderSwapped; // temporary buffer for swapping header on PowerPC
227 AliRawDataHeaderV3* fHeaderSwappedV3; // temporary buffer for swapping header on PowerPC
229 UInt_t SwapWord(UInt_t x) const;
230 UShort_t SwapShort(UShort_t x) const;
232 Bool_t fIsValid; // is raw-reader created successfully
233 Bool_t fIsTriggerClassLoaded; // flags the call to LoadTriggerClass
235 ClassDef(AliRawReader, 0) // base class for reading raw digits