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