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 virtual const UInt_t* GetDetectorPattern() const = 0;
78 virtual const UInt_t* GetAttributes() const = 0;
79 virtual const UInt_t* GetSubEventAttributes() const = 0;
80 virtual UInt_t GetLDCId() const = 0;
81 virtual UInt_t GetGDCId() const = 0;
82 virtual UInt_t GetTimestamp() const = 0;
84 virtual Int_t GetEquipmentSize() const = 0;
85 virtual Int_t GetEquipmentType() const = 0;
86 virtual Int_t GetEquipmentId() const = 0;
87 Int_t GetMappedEquipmentId() const;
88 Bool_t LoadEquipmentIdsMap(const char *fileName);
89 virtual const UInt_t* GetEquipmentAttributes() const = 0;
90 virtual Int_t GetEquipmentElementSize() const = 0;
91 virtual Int_t GetEquipmentHeaderSize() const = 0;
93 Int_t GetDetectorID() const;
94 Int_t GetDDLID() const;
96 Int_t GetDataSize() const
98 if (fHeader->fSize != 0xFFFFFFFF) return fHeader->fSize - sizeof(AliRawDataHeader);
99 else return GetEquipmentSize() - GetEquipmentHeaderSize() - sizeof(AliRawDataHeader);
100 } else if(fHeaderV3){
101 if (fHeaderV3->fSize != 0xFFFFFFFF) return fHeaderV3->fSize - sizeof(AliRawDataHeaderV3);
102 else return GetEquipmentSize() - GetEquipmentHeaderSize() - sizeof(AliRawDataHeaderV3);
104 else return GetEquipmentSize() - GetEquipmentHeaderSize();};
106 Int_t GetVersion() const
107 {if (fHeader) return fHeader->GetVersion();
108 else if (fHeaderV3) return fHeaderV3->GetVersion();
110 Bool_t IsValid() const
111 {if (fHeader) return fHeader->TestAttribute(0);
112 else if (fHeaderV3) return fHeaderV3->TestAttribute(0);
113 else return kFALSE;};
114 Bool_t IsCompressed() const
115 {if (fHeader) return fHeader->TestAttribute(1);
116 else if (fHeaderV3) return fHeaderV3->TestAttribute(1);
117 else return kFALSE;};
118 Bool_t TestBlockAttribute(Int_t index) const
119 {if (fHeader) return fHeader->TestAttribute(index);
120 else if (fHeaderV3) return fHeaderV3->TestAttribute(index);
121 else return kFALSE;};
122 UChar_t GetBlockAttributes() const
123 {if (fHeader) return fHeader->GetAttributes();
124 else if (fHeaderV3) return fHeaderV3->GetAttributes();
126 UInt_t GetStatusBits() const
127 {if (fHeader) return fHeader->GetStatus();
128 else if (fHeaderV3) return fHeaderV3->GetStatus();
130 const AliRawDataHeader* GetDataHeader() const
132 const AliRawDataHeaderV3* GetDataHeaderV3() const
135 virtual Bool_t ReadHeader() = 0;
136 virtual Bool_t ReadNextData(UChar_t*& data) = 0;
137 virtual Bool_t ReadNextInt(UInt_t& data);
138 virtual Bool_t ReadNextShort(UShort_t& data);
139 virtual Bool_t ReadNextChar(UChar_t& data);
140 virtual Bool_t ReadNext(UChar_t* data, Int_t size) = 0;
142 virtual Bool_t Reset() = 0;
144 virtual Bool_t NextEvent() = 0;
145 virtual Bool_t RewindEvents() = 0;
146 virtual Bool_t GotoEvent(Int_t event);
147 virtual Bool_t GotoEventWithID(Int_t event,
151 virtual Int_t GetEventIndex() const { return -1; }
152 virtual Int_t GetNumberOfEvents() const { return -1; }
154 enum {kErrMagic=1, kErrNoDataHeader=2,
155 kErrSize=4, kErrOutOfBounds=8};
156 virtual Int_t CheckData() const;
157 Int_t GetErrorCode() const {return fErrorCode;};
159 void DumpData(Int_t limit = -1);
161 void AddErrorLog(AliRawDataErrorLog::ERawDataErrorLevel level,
163 const char *message = NULL);
164 void AddMinorErrorLog(Int_t code,
165 const char *message = NULL) {
166 return AddErrorLog(AliRawDataErrorLog::kMinor,code,message);
168 void AddMajorErrorLog(Int_t code,
169 const char *message = NULL) {
170 return AddErrorLog(AliRawDataErrorLog::kMajor,code,message);
172 void AddFatalErrorLog(Int_t code,
173 const char *message = NULL) {
174 return AddErrorLog(AliRawDataErrorLog::kFatal,code,message);
176 Int_t GetNumberOfErrorLogs() const { return fErrorLogs.GetEntriesFast(); }
177 const TClonesArray &GetAllErrorLogs() const { return fErrorLogs; }
178 AliRawDataErrorLog *GetErrorLog(Int_t i) const {
179 return (AliRawDataErrorLog *)fErrorLogs.UncheckedAt(i);
182 // Method which can be used in order to force the auto-save on
183 // ESD tree inside AliReconstruction. For the moment it will be
184 // activated only for AliRawReaderDateOnline.
185 virtual Bool_t UseAutoSaveESD() const { return kFALSE; }
186 virtual TChain* GetChain() const { return NULL; }
188 Bool_t IsRawReaderValid() const { return fIsValid; }
190 void LoadTriggerClass(const char* name, Int_t index);
191 void LoadTriggerAlias(const THashList *lst);
193 virtual AliRawReader* CloneSingleEvent() const { return NULL; }
196 virtual void SelectEvents(Int_t type, ULong64_t triggerMask = 0, const char *triggerExpr = NULL);
197 Bool_t IsSelected() const;
198 Bool_t IsEventSelected() const;
200 TArrayI *fEquipmentIdsIn; // array of equipment Ids to be mapped
201 TArrayI *fEquipmentIdsOut; // array of mapped equipment Ids
203 Bool_t fRequireHeader; // if false, data without header is accepted
205 AliRawDataHeader* fHeader; // current data header
206 AliRawDataHeaderV3* fHeaderV3; // current data header
207 Int_t fCount; // counter of bytes to be read for current DDL
209 Int_t fSelectEquipmentType; // type of selected equipment (<0 = no selection)
210 Int_t fSelectMinEquipmentId; // minimal index of selected equipment (<0 = no selection)
211 Int_t fSelectMaxEquipmentId; // maximal index of selected equipment (<0 = no selection)
212 Bool_t fSkipInvalid; // skip invalid data
213 Int_t fSelectEventType; // type of selected events (<0 = no selection)
214 ULong64_t fSelectTriggerMask; // trigger mask for selecting events (0 = no selection)
215 TString fSelectTriggerExpr; // trigger expression for selecting events (empty = no selection)
217 Int_t fErrorCode; // code of last error
219 Int_t fEventNumber; // current event number
220 TClonesArray fErrorLogs; // raw data decoding errors
222 AliRawDataHeader* fHeaderSwapped; // temporary buffer for swapping header on PowerPC
223 AliRawDataHeaderV3* fHeaderSwappedV3; // temporary buffer for swapping header on PowerPC
225 UInt_t SwapWord(UInt_t x) const;
226 UShort_t SwapShort(UShort_t x) const;
228 Bool_t fIsValid; // is raw-reader created successfully
229 Bool_t fIsTriggerClassLoaded; // flags the call to LoadTriggerClass
231 ClassDef(AliRawReader, 0) // base class for reading raw digits