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"
23 class AliRawEventHeaderBase;
26 class AliRawReader: public TObject {
27 friend class AliEveEventManager;
30 AliRawReader(const AliRawReader& rawReader);
31 AliRawReader& operator = (const AliRawReader& rawReader);
32 virtual ~AliRawReader();
34 static AliRawReader* Create(const char *uri);
36 virtual void Select(Int_t detectorID,
37 Int_t minDDLID = -1, Int_t maxDDLID = -1);
38 virtual void Select(const char *detectorName,
39 Int_t minDDLID = -1, Int_t maxDDLID = -1);
40 virtual void SelectEquipment(Int_t equipmentType,
41 Int_t minEquipmentId = -1,
42 Int_t maxEquipmentId = -1);
43 virtual void SkipInvalid(Bool_t skip = kTRUE)
44 {fSkipInvalid = skip;};
45 virtual void RequireHeader(Bool_t required)
46 {fRequireHeader = required;};
48 virtual const AliRawEventHeaderBase* GetEventHeader() const {return NULL;};
49 virtual const AliRawVEvent* GetEvent() const {return NULL;}
51 virtual UInt_t GetType() const = 0;
52 virtual UInt_t GetRunNumber() const = 0;
53 virtual const UInt_t* GetEventId() const = 0;
54 UInt_t GetPeriod() const {
55 const UInt_t *id = GetEventId();
56 return id ? (((id)[0]>>4)&0x0fffffff): 0;
58 UInt_t GetOrbitID() const {
59 const UInt_t *id = GetEventId();
60 return id ? ((((id)[0]<<20)&0xf00000)|(((id)[1]>>12)&0xfffff)) : 0;
62 UShort_t GetBCID() const {
63 const UInt_t *id = GetEventId();
64 return id ? ((id)[1]&0x00000fff) : 0;
66 ULong64_t GetEventIdAsLong() const {
67 return (((ULong64_t)GetPeriod() << 36) |
68 ((ULong64_t)GetOrbitID() << 12) |
69 (ULong64_t)GetBCID());
71 virtual const UInt_t* GetTriggerPattern() const = 0;
72 ULong64_t GetClassMask() const {
73 const UInt_t *pattern = GetTriggerPattern();
74 return pattern ? (((ULong64_t)pattern[1] & 0x3ffff) << 32)|(pattern[0]) : 0;
76 virtual const UInt_t* GetDetectorPattern() const = 0;
77 virtual const UInt_t* GetAttributes() const = 0;
78 virtual const UInt_t* GetSubEventAttributes() const = 0;
79 virtual UInt_t GetLDCId() const = 0;
80 virtual UInt_t GetGDCId() const = 0;
81 virtual UInt_t GetTimestamp() const = 0;
83 virtual Int_t GetEquipmentSize() const = 0;
84 virtual Int_t GetEquipmentType() const = 0;
85 virtual Int_t GetEquipmentId() const = 0;
86 Int_t GetMappedEquipmentId() const;
87 Bool_t LoadEquipmentIdsMap(const char *fileName);
88 virtual const UInt_t* GetEquipmentAttributes() const = 0;
89 virtual Int_t GetEquipmentElementSize() const = 0;
90 virtual Int_t GetEquipmentHeaderSize() const = 0;
92 Int_t GetDetectorID() const;
93 Int_t GetDDLID() const;
95 Int_t GetDataSize() const
97 if (fHeader->fSize != 0xFFFFFFFF) return fHeader->fSize - sizeof(AliRawDataHeader);
98 else return GetEquipmentSize() - GetEquipmentHeaderSize() - sizeof(AliRawDataHeader);
99 } else return GetEquipmentSize() - GetEquipmentHeaderSize();};
101 Int_t GetVersion() const
102 {if (fHeader) return fHeader->GetVersion(); else return -1;};
103 Bool_t IsValid() const
104 {if (fHeader) return fHeader->TestAttribute(0);
105 else return kFALSE;};
106 Bool_t IsCompressed() const
107 {if (fHeader) return fHeader->TestAttribute(1);
108 else return kFALSE;};
109 Bool_t TestBlockAttribute(Int_t index) const
110 {if (fHeader) return fHeader->TestAttribute(index);
111 else return kFALSE;};
112 UChar_t GetBlockAttributes() const
113 {if (fHeader) return fHeader->GetAttributes();
115 UInt_t GetStatusBits() const
116 {if (fHeader) return fHeader->GetStatus();
118 const AliRawDataHeader* GetDataHeader() const
121 virtual Bool_t ReadHeader() = 0;
122 virtual Bool_t ReadNextData(UChar_t*& data) = 0;
123 virtual Bool_t ReadNextInt(UInt_t& data);
124 virtual Bool_t ReadNextShort(UShort_t& data);
125 virtual Bool_t ReadNextChar(UChar_t& data);
126 virtual Bool_t ReadNext(UChar_t* data, Int_t size) = 0;
128 virtual Bool_t Reset() = 0;
130 virtual Bool_t NextEvent() = 0;
131 virtual Bool_t RewindEvents() = 0;
132 virtual Bool_t GotoEvent(Int_t event);
133 virtual Bool_t GotoEventWithID(Int_t event,
137 virtual Int_t GetEventIndex() const { return -1; }
138 virtual Int_t GetNumberOfEvents() const { return -1; }
140 enum {kErrMagic=1, kErrNoDataHeader=2,
141 kErrSize=4, kErrOutOfBounds=8};
142 virtual Int_t CheckData() const;
143 Int_t GetErrorCode() const {return fErrorCode;};
145 void DumpData(Int_t limit = -1);
147 void AddErrorLog(AliRawDataErrorLog::ERawDataErrorLevel level,
149 const char *message = NULL);
150 void AddMinorErrorLog(Int_t code,
151 const char *message = NULL) {
152 return AddErrorLog(AliRawDataErrorLog::kMinor,code,message);
154 void AddMajorErrorLog(Int_t code,
155 const char *message = NULL) {
156 return AddErrorLog(AliRawDataErrorLog::kMajor,code,message);
158 void AddFatalErrorLog(Int_t code,
159 const char *message = NULL) {
160 return AddErrorLog(AliRawDataErrorLog::kFatal,code,message);
162 Int_t GetNumberOfErrorLogs() const { return fErrorLogs.GetEntriesFast(); }
163 const TClonesArray &GetAllErrorLogs() const { return fErrorLogs; }
164 AliRawDataErrorLog *GetErrorLog(Int_t i) const {
165 return (AliRawDataErrorLog *)fErrorLogs.UncheckedAt(i);
168 // Method which can be used in order to force the auto-save on
169 // ESD tree inside AliReconstruction. For the moment it will be
170 // activated only for AliRawReaderDateOnline.
171 virtual Bool_t UseAutoSaveESD() const { return kFALSE; }
172 virtual TChain* GetChain() const { return NULL; }
174 Bool_t IsRawReaderValid() const { return fIsValid; }
176 void LoadTriggerClass(const char* name, Int_t index);
177 void LoadTriggerAlias(const THashList *lst);
179 virtual AliRawReader* CloneSingleEvent() const { return NULL; }
182 virtual void SelectEvents(Int_t type, ULong64_t triggerMask = 0, const char *triggerExpr = NULL);
183 Bool_t IsSelected() const;
184 Bool_t IsEventSelected() const;
186 TArrayI *fEquipmentIdsIn; // array of equipment Ids to be mapped
187 TArrayI *fEquipmentIdsOut; // array of mapped equipment Ids
189 Bool_t fRequireHeader; // if false, data without header is accepted
191 AliRawDataHeader* fHeader; // current data header
192 Int_t fCount; // counter of bytes to be read for current DDL
194 Int_t fSelectEquipmentType; // type of selected equipment (<0 = no selection)
195 Int_t fSelectMinEquipmentId; // minimal index of selected equipment (<0 = no selection)
196 Int_t fSelectMaxEquipmentId; // maximal index of selected equipment (<0 = no selection)
197 Bool_t fSkipInvalid; // skip invalid data
198 Int_t fSelectEventType; // type of selected events (<0 = no selection)
199 ULong64_t fSelectTriggerMask; // trigger mask for selecting events (0 = no selection)
200 TString fSelectTriggerExpr; // trigger expression for selecting events (empty = no selection)
202 Int_t fErrorCode; // code of last error
204 Int_t fEventNumber; // current event number
205 TClonesArray fErrorLogs; // raw data decoding errors
207 AliRawDataHeader* fHeaderSwapped; // temporary buffer for swapping header on PowerPC
209 UInt_t SwapWord(UInt_t x) const;
210 UShort_t SwapShort(UShort_t x) const;
212 Bool_t fIsValid; // is raw-reader created successfully
213 Bool_t fIsTriggerClassLoaded; // flags the call to LoadTriggerClass
215 ClassDef(AliRawReader, 0) // base class for reading raw digits