Line data Source code
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 : #include "AliRawDataHeaderV3.h"
21 :
22 : class THashList;
23 : class TChain;
24 : class AliRawEventHeaderBase;
25 : class AliRawVEvent;
26 :
27 : class AliRawReader: public TObject {
28 : friend class AliEveEventManager;
29 : public :
30 : AliRawReader();
31 : AliRawReader(const AliRawReader& rawReader);
32 : AliRawReader& operator = (const AliRawReader& rawReader);
33 : virtual ~AliRawReader();
34 :
35 : static AliRawReader* Create(const char *uri);
36 :
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 0 : {fSkipInvalid = skip;};
46 : virtual void RequireHeader(Bool_t required)
47 8 : {fRequireHeader = required;};
48 :
49 0 : virtual const AliRawEventHeaderBase* GetEventHeader() const {return NULL;};
50 0 : virtual const AliRawVEvent* GetEvent() const {return NULL;}
51 :
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 16 : const UInt_t *id = GetEventId();
57 24 : return id ? (((id)[0]>>4)&0x0fffffff): 0;
58 : }
59 : UInt_t GetOrbitID() const {
60 16 : const UInt_t *id = GetEventId();
61 24 : return id ? ((((id)[0]<<20)&0xf00000)|(((id)[1]>>12)&0xfffff)) : 0;
62 : }
63 : UShort_t GetBCID() const {
64 32 : const UInt_t *id = GetEventId();
65 48 : return id ? ((id)[1]&0x00000fff) : 0;
66 : }
67 : ULong64_t GetEventIdAsLong() const {
68 0 : return (((ULong64_t)GetPeriod() << 36) |
69 0 : ((ULong64_t)GetOrbitID() << 12) |
70 0 : (ULong64_t)GetBCID());
71 : }
72 : virtual const UInt_t* GetTriggerPattern() const = 0;
73 : ULong64_t GetClassMask() const {
74 10 : const UInt_t *pattern = GetTriggerPattern();
75 15 : return pattern ? (((ULong64_t)pattern[1] & 0x3ffff) << 32)|(pattern[0]) : 0;
76 : }
77 : ULong64_t GetClassMaskNext50() const {
78 10 : const UInt_t *pattern = GetTriggerPattern();
79 15 : return pattern ? ((ULong64_t)(pattern[1]>>18) & 0x3fff)|((ULong64_t)(pattern[2]&0xffffffff)<<14)|((ULong64_t)(pattern[3]&0xf)<<46): 0;
80 : }
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;
87 :
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;
96 :
97 : Int_t GetDetectorID() const;
98 : Int_t GetDDLID() const;
99 :
100 : Int_t GetDataSize() const
101 41530 : {if (fHeader) {
102 0 : if (fHeader->fSize != 0xFFFFFFFF) return fHeader->fSize - sizeof(AliRawDataHeader);
103 0 : else return GetEquipmentSize() - GetEquipmentHeaderSize() - sizeof(AliRawDataHeader);
104 20765 : } else if(fHeaderV3){
105 41490 : if (fHeaderV3->fSize != 0xFFFFFFFF) return fHeaderV3->fSize - sizeof(AliRawDataHeaderV3);
106 0 : else return GetEquipmentSize() - GetEquipmentHeaderSize() - sizeof(AliRawDataHeaderV3);
107 : }
108 20785 : else return GetEquipmentSize() - GetEquipmentHeaderSize();};
109 :
110 : Int_t GetVersion() const
111 0 : {if (fHeader) return fHeader->GetVersion();
112 0 : else if (fHeaderV3) return fHeaderV3->GetVersion();
113 0 : else return -1;};
114 : Bool_t IsValid() const
115 0 : {if (fHeader) return fHeader->TestAttribute(0);
116 0 : else if (fHeaderV3) return fHeaderV3->TestAttribute(0);
117 0 : else return kFALSE;};
118 : Bool_t IsCompressed() const
119 0 : {if (fHeader) return fHeader->TestAttribute(1);
120 0 : else if (fHeaderV3) return fHeaderV3->TestAttribute(1);
121 0 : else return kFALSE;};
122 : Bool_t TestBlockAttribute(Int_t index) const
123 10880 : {if (fHeader) return fHeader->TestAttribute(index);
124 10880 : else if (fHeaderV3) return fHeaderV3->TestAttribute(index);
125 5440 : else return kFALSE;};
126 : UChar_t GetBlockAttributes() const
127 1744 : {if (fHeader) return fHeader->GetAttributes();
128 1744 : else if (fHeaderV3) return fHeaderV3->GetAttributes();
129 872 : else return 0;};
130 : UInt_t GetStatusBits() const
131 160 : {if (fHeader) return fHeader->GetStatus();
132 160 : else if (fHeaderV3) return fHeaderV3->GetStatus();
133 80 : else return 0;};
134 : const AliRawDataHeader* GetDataHeader() const
135 1176 : {return fHeader;}
136 : const AliRawDataHeaderV3* GetDataHeaderV3() const
137 1176 : {return fHeaderV3;}
138 :
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;
145 :
146 : virtual Bool_t Reset() = 0;
147 :
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,
152 : UInt_t period,
153 : UInt_t orbitID,
154 : UShort_t bcID);
155 0 : virtual Int_t GetEventIndex() const { return -1; }
156 0 : virtual Int_t GetNumberOfEvents() const { return -1; }
157 :
158 : enum {kErrMagic=1, kErrNoDataHeader=2,
159 : kErrSize=4, kErrOutOfBounds=8};
160 : virtual Int_t CheckData() const;
161 0 : Int_t GetErrorCode() const {return fErrorCode;};
162 :
163 : void DumpData(Int_t limit = -1);
164 :
165 : void AddErrorLog(AliRawDataErrorLog::ERawDataErrorLevel level,
166 : Int_t code,
167 : const char *message = NULL);
168 : void AddMinorErrorLog(Int_t code,
169 : const char *message = NULL) {
170 0 : return AddErrorLog(AliRawDataErrorLog::kMinor,code,message);
171 : }
172 : void AddMajorErrorLog(Int_t code,
173 : const char *message = NULL) {
174 312 : return AddErrorLog(AliRawDataErrorLog::kMajor,code,message);
175 : }
176 : void AddFatalErrorLog(Int_t code,
177 : const char *message = NULL) {
178 0 : return AddErrorLog(AliRawDataErrorLog::kFatal,code,message);
179 : }
180 140 : Int_t GetNumberOfErrorLogs() const { return fErrorLogs.GetEntriesFast(); }
181 0 : const TClonesArray &GetAllErrorLogs() const { return fErrorLogs; }
182 : AliRawDataErrorLog *GetErrorLog(Int_t i) const {
183 132 : return (AliRawDataErrorLog *)fErrorLogs.UncheckedAt(i);
184 : }
185 :
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 16 : virtual Bool_t UseAutoSaveESD() const { return kFALSE; }
190 2 : virtual TChain* GetChain() const { return NULL; }
191 :
192 2 : Bool_t IsRawReaderValid() const { return fIsValid; }
193 :
194 : void LoadTriggerClass(const char* name, Int_t index);
195 : void LoadTriggerAlias(const THashList *lst);
196 :
197 0 : virtual AliRawReader* CloneSingleEvent() const { return NULL; }
198 :
199 : protected :
200 : virtual void SelectEvents(Int_t type,ULong64_t triggerMask=0,const char *triggerExpr=NULL,ULong64_t triggerMask50=0);
201 : Bool_t IsSelected() const;
202 : Bool_t IsEventSelected() const;
203 :
204 : TArrayI *fEquipmentIdsIn; // array of equipment Ids to be mapped
205 : TArrayI *fEquipmentIdsOut; // array of mapped equipment Ids
206 :
207 : Bool_t fRequireHeader; // if false, data without header is accepted
208 :
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
212 :
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 : ULong64_t fSelectTriggerMask50; // trigger maskNext50 for selecting events (0 = no selection)
220 : TString fSelectTriggerExpr; // trigger expression for selecting events (empty = no selection)
221 :
222 : Int_t fErrorCode; // code of last error
223 :
224 : Int_t fEventNumber; // current event number
225 : TClonesArray fErrorLogs; // raw data decoding errors
226 :
227 : AliRawDataHeader* fHeaderSwapped; // temporary buffer for swapping header on PowerPC
228 : AliRawDataHeaderV3* fHeaderSwappedV3; // temporary buffer for swapping header on PowerPC
229 :
230 : UInt_t SwapWord(UInt_t x) const;
231 : UShort_t SwapShort(UShort_t x) const;
232 :
233 : Bool_t fIsValid; // is raw-reader created successfully
234 : Bool_t fIsTriggerClassLoaded; // flags the call to LoadTriggerClass
235 :
236 128 : ClassDef(AliRawReader, 0) // base class for reading raw digits
237 : };
238 :
239 : #endif
|