]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RAW/AliRawReader.h
ALIROOT-5420 Uniform interface to CDH v2 and CDH v3
[u/mrichter/AliRoot.git] / RAW / AliRawReader.h
CommitLineData
a6e7b125 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
bea6b2a4 6/* $Id$ */
7
8///////////////////////////////////////////////////////////////////////////////
9///
10/// This is the base class for reading raw data.
11///
12///////////////////////////////////////////////////////////////////////////////
13
a6e7b125 14#include <TObject.h>
0cfe2438 15#include <TArrayI.h>
38cf12f3 16#include <TClonesArray.h>
17
18#include "AliRawDataErrorLog.h"
39f9963f 19#include "AliRawDataHeader.h"
480f0332 20#include "AliRawDataHeaderV3.h"
8de97894 21
5dfb32c1 22class THashList;
636c1780 23class TChain;
1fb5b4a8 24class AliRawEventHeaderBase;
33314186 25class AliRawVEvent;
a6e7b125 26
a6e7b125 27class AliRawReader: public TObject {
969d3431 28 friend class AliEveEventManager;
a6e7b125 29 public :
8de97894 30 AliRawReader();
42d20574 31 AliRawReader(const AliRawReader& rawReader);
32 AliRawReader& operator = (const AliRawReader& rawReader);
0cfe2438 33 virtual ~AliRawReader();
8de97894 34
43787b8e 35 static AliRawReader* Create(const char *uri);
36
eb808725 37 virtual void Select(Int_t detectorID,
8de97894 38 Int_t minDDLID = -1, Int_t maxDDLID = -1);
eb808725 39 virtual void Select(const char *detectorName,
362c9d61 40 Int_t minDDLID = -1, Int_t maxDDLID = -1);
eb808725 41 virtual void SelectEquipment(Int_t equipmentType,
f224de6c 42 Int_t minEquipmentId = -1,
43 Int_t maxEquipmentId = -1);
eb808725 44 virtual void SkipInvalid(Bool_t skip = kTRUE)
39f9963f 45 {fSkipInvalid = skip;};
299738b9 46 virtual void RequireHeader(Bool_t required)
18882b3b 47 {fRequireHeader = required;};
a6e7b125 48
1fb5b4a8 49 virtual const AliRawEventHeaderBase* GetEventHeader() const {return NULL;};
33314186 50 virtual const AliRawVEvent* GetEvent() const {return NULL;}
1fb5b4a8 51
42d20574 52 virtual UInt_t GetType() const = 0;
53 virtual UInt_t GetRunNumber() const = 0;
54 virtual const UInt_t* GetEventId() const = 0;
151bea4e 55 UInt_t GetPeriod() const {
56 const UInt_t *id = GetEventId();
4bf6d23d 57 return id ? (((id)[0]>>4)&0x0fffffff): 0;
151bea4e 58 }
59 UInt_t GetOrbitID() const {
60 const UInt_t *id = GetEventId();
4bf6d23d 61 return id ? ((((id)[0]<<20)&0xf00000)|(((id)[1]>>12)&0xfffff)) : 0;
151bea4e 62 }
63 UShort_t GetBCID() const {
64 const UInt_t *id = GetEventId();
4bf6d23d 65 return id ? ((id)[1]&0x00000fff) : 0;
151bea4e 66 }
99b7ff2d 67 ULong64_t GetEventIdAsLong() const {
95f2890d 68 return (((ULong64_t)GetPeriod() << 36) |
69 ((ULong64_t)GetOrbitID() << 12) |
70 (ULong64_t)GetBCID());
99b7ff2d 71 }
42d20574 72 virtual const UInt_t* GetTriggerPattern() const = 0;
4bf6d23d 73 ULong64_t GetClassMask() const {
74 const UInt_t *pattern = GetTriggerPattern();
75 return pattern ? (((ULong64_t)pattern[1] & 0x3ffff) << 32)|(pattern[0]) : 0;
76 }
42d20574 77 virtual const UInt_t* GetDetectorPattern() const = 0;
78 virtual const UInt_t* GetAttributes() const = 0;
e94ad92c 79 virtual const UInt_t* GetSubEventAttributes() const = 0;
c946ab02 80 virtual UInt_t GetLDCId() const = 0;
42d20574 81 virtual UInt_t GetGDCId() const = 0;
741c154c 82 virtual UInt_t GetTimestamp() const = 0;
04fa961a 83
c946ab02 84 virtual Int_t GetEquipmentSize() const = 0;
85 virtual Int_t GetEquipmentType() const = 0;
86 virtual Int_t GetEquipmentId() const = 0;
0cfe2438 87 Int_t GetMappedEquipmentId() const;
88 Bool_t LoadEquipmentIdsMap(const char *fileName);
c946ab02 89 virtual const UInt_t* GetEquipmentAttributes() const = 0;
90 virtual Int_t GetEquipmentElementSize() const = 0;
299738b9 91 virtual Int_t GetEquipmentHeaderSize() const = 0;
a6e7b125 92
0cfe2438 93 Int_t GetDetectorID() const;
94 Int_t GetDDLID() const;
39f9963f 95
c946ab02 96 Int_t GetDataSize() const
527a1d3f 97 {if (fHeader) {
480f0332 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);
103 }
104 else return GetEquipmentSize() - GetEquipmentHeaderSize();};
509a7696 105
c946ab02 106 Int_t GetVersion() const
480f0332 107 {if (fHeader) return fHeader->GetVersion();
108 else if (fHeaderV3) return fHeaderV3->GetVersion();
109 else return -1;};
39f9963f 110 Bool_t IsValid() const
480f0332 111 {if (fHeader) return fHeader->TestAttribute(0);
112 else if (fHeaderV3) return fHeaderV3->TestAttribute(0);
113 else return kFALSE;};
c946ab02 114 Bool_t IsCompressed() const
39f9963f 115 {if (fHeader) return fHeader->TestAttribute(1);
480f0332 116 else if (fHeaderV3) return fHeaderV3->TestAttribute(1);
c946ab02 117 else return kFALSE;};
c3408d7d 118 Bool_t TestBlockAttribute(Int_t index) const
480f0332 119 {if (fHeader) return fHeader->TestAttribute(index);
120 else if (fHeaderV3) return fHeaderV3->TestAttribute(index);
c3408d7d 121 else return kFALSE;};
122 UChar_t GetBlockAttributes() const
123 {if (fHeader) return fHeader->GetAttributes();
480f0332 124 else if (fHeaderV3) return fHeaderV3->GetAttributes();
c3408d7d 125 else return 0;};
f58b3254 126 UInt_t GetStatusBits() const
127 {if (fHeader) return fHeader->GetStatus();
480f0332 128 else if (fHeaderV3) return fHeaderV3->GetStatus();
f58b3254 129 else return 0;};
c3408d7d 130 const AliRawDataHeader* GetDataHeader() const
131 {return fHeader;}
480f0332 132 const AliRawDataHeaderV3* GetDataHeaderV3() const
133 {return fHeaderV3;}
c946ab02 134
135 virtual Bool_t ReadHeader() = 0;
8de97894 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);
bf22797a 140 virtual Bool_t ReadNext(UChar_t* data, Int_t size) = 0;
8de97894 141
142 virtual Bool_t Reset() = 0;
a6e7b125 143
dd9a70fe 144 virtual Bool_t NextEvent() = 0;
145 virtual Bool_t RewindEvents() = 0;
636c1780 146 virtual Bool_t GotoEvent(Int_t event);
66964465 147 virtual Bool_t GotoEventWithID(Int_t event,
148 UInt_t period,
149 UInt_t orbitID,
150 UShort_t bcID);
636c1780 151 virtual Int_t GetEventIndex() const { return -1; }
25e82ff5 152 virtual Int_t GetNumberOfEvents() const { return -1; }
dd9a70fe 153
39f9963f 154 enum {kErrMagic=1, kErrNoDataHeader=2,
155 kErrSize=4, kErrOutOfBounds=8};
b4857df7 156 virtual Int_t CheckData() const;
bea6b2a4 157 Int_t GetErrorCode() const {return fErrorCode;};
b4857df7 158
509a7696 159 void DumpData(Int_t limit = -1);
160
9fc249d9 161 void AddErrorLog(AliRawDataErrorLog::ERawDataErrorLevel level,
162 Int_t code,
38cf12f3 163 const char *message = NULL);
9fc249d9 164 void AddMinorErrorLog(Int_t code,
165 const char *message = NULL) {
166 return AddErrorLog(AliRawDataErrorLog::kMinor,code,message);
167 }
168 void AddMajorErrorLog(Int_t code,
169 const char *message = NULL) {
170 return AddErrorLog(AliRawDataErrorLog::kMajor,code,message);
171 }
172 void AddFatalErrorLog(Int_t code,
173 const char *message = NULL) {
174 return AddErrorLog(AliRawDataErrorLog::kFatal,code,message);
175 }
38cf12f3 176 Int_t GetNumberOfErrorLogs() const { return fErrorLogs.GetEntriesFast(); }
79dac785 177 const TClonesArray &GetAllErrorLogs() const { return fErrorLogs; }
38cf12f3 178 AliRawDataErrorLog *GetErrorLog(Int_t i) const {
179 return (AliRawDataErrorLog *)fErrorLogs.UncheckedAt(i);
180 }
181
2d91a353 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; }
636c1780 186 virtual TChain* GetChain() const { return NULL; }
2d91a353 187
a97af23d 188 Bool_t IsRawReaderValid() const { return fIsValid; }
189
56918e2f 190 void LoadTriggerClass(const char* name, Int_t index);
5dfb32c1 191 void LoadTriggerAlias(const THashList *lst);
56918e2f 192
b900a426 193 virtual AliRawReader* CloneSingleEvent() const { return NULL; }
194
a6e7b125 195 protected :
56918e2f 196 virtual void SelectEvents(Int_t type, ULong64_t triggerMask = 0, const char *triggerExpr = NULL);
42d20574 197 Bool_t IsSelected() const;
dd9a70fe 198 Bool_t IsEventSelected() const;
a6e7b125 199
0cfe2438 200 TArrayI *fEquipmentIdsIn; // array of equipment Ids to be mapped
201 TArrayI *fEquipmentIdsOut; // array of mapped equipment Ids
18882b3b 202
0cfe2438 203 Bool_t fRequireHeader; // if false, data without header is accepted
204
205 AliRawDataHeader* fHeader; // current data header
480f0332 206 AliRawDataHeaderV3* fHeaderV3; // current data header
0cfe2438 207 Int_t fCount; // counter of bytes to be read for current DDL
a6e7b125 208
f224de6c 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)
0cfe2438 212 Bool_t fSkipInvalid; // skip invalid data
213 Int_t fSelectEventType; // type of selected events (<0 = no selection)
00665a00 214 ULong64_t fSelectTriggerMask; // trigger mask for selecting events (0 = no selection)
56918e2f 215 TString fSelectTriggerExpr; // trigger expression for selecting events (empty = no selection)
8de97894 216
0cfe2438 217 Int_t fErrorCode; // code of last error
b4857df7 218
38cf12f3 219 Int_t fEventNumber; // current event number
edd06192 220 TClonesArray fErrorLogs; // raw data decoding errors
221
222 AliRawDataHeader* fHeaderSwapped; // temporary buffer for swapping header on PowerPC
480f0332 223 AliRawDataHeaderV3* fHeaderSwappedV3; // temporary buffer for swapping header on PowerPC
38cf12f3 224
91f76e9b 225 UInt_t SwapWord(UInt_t x) const;
226 UShort_t SwapShort(UShort_t x) const;
227
a97af23d 228 Bool_t fIsValid; // is raw-reader created successfully
b21d9ff2 229 Bool_t fIsTriggerClassLoaded; // flags the call to LoadTriggerClass
a97af23d 230
a6e7b125 231 ClassDef(AliRawReader, 0) // base class for reading raw digits
232};
233
234#endif