1. Proper (?) handling of the branches in AliRawReaderChain. 2. New virtual GotoEvent...
[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"
8de97894 20
636c1780 21class TChain;
1fb5b4a8 22class AliRawEventHeaderBase;
a6e7b125 23
a6e7b125 24class AliRawReader: public TObject {
25 public :
8de97894 26 AliRawReader();
42d20574 27 AliRawReader(const AliRawReader& rawReader);
28 AliRawReader& operator = (const AliRawReader& rawReader);
0cfe2438 29 virtual ~AliRawReader();
8de97894 30
43787b8e 31 static AliRawReader* Create(const char *uri);
32
eb808725 33 virtual void Select(Int_t detectorID,
8de97894 34 Int_t minDDLID = -1, Int_t maxDDLID = -1);
eb808725 35 virtual void Select(const char *detectorName,
362c9d61 36 Int_t minDDLID = -1, Int_t maxDDLID = -1);
eb808725 37 virtual void SelectEquipment(Int_t equipmentType,
f224de6c 38 Int_t minEquipmentId = -1,
39 Int_t maxEquipmentId = -1);
eb808725 40 virtual void SkipInvalid(Bool_t skip = kTRUE)
39f9963f 41 {fSkipInvalid = skip;};
299738b9 42 virtual void RequireHeader(Bool_t required)
18882b3b 43 {fRequireHeader = required;};
a6e7b125 44
1fb5b4a8 45 virtual const AliRawEventHeaderBase* GetEventHeader() const {return NULL;};
46
42d20574 47 virtual UInt_t GetType() const = 0;
48 virtual UInt_t GetRunNumber() const = 0;
49 virtual const UInt_t* GetEventId() const = 0;
151bea4e 50 UInt_t GetPeriod() const {
51 const UInt_t *id = GetEventId();
4bf6d23d 52 return id ? (((id)[0]>>4)&0x0fffffff): 0;
151bea4e 53 }
54 UInt_t GetOrbitID() const {
55 const UInt_t *id = GetEventId();
4bf6d23d 56 return id ? ((((id)[0]<<20)&0xf00000)|(((id)[1]>>12)&0xfffff)) : 0;
151bea4e 57 }
58 UShort_t GetBCID() const {
59 const UInt_t *id = GetEventId();
4bf6d23d 60 return id ? ((id)[1]&0x00000fff) : 0;
151bea4e 61 }
42d20574 62 virtual const UInt_t* GetTriggerPattern() const = 0;
4bf6d23d 63 ULong64_t GetClassMask() const {
64 const UInt_t *pattern = GetTriggerPattern();
65 return pattern ? (((ULong64_t)pattern[1] & 0x3ffff) << 32)|(pattern[0]) : 0;
66 }
42d20574 67 virtual const UInt_t* GetDetectorPattern() const = 0;
68 virtual const UInt_t* GetAttributes() const = 0;
e94ad92c 69 virtual const UInt_t* GetSubEventAttributes() const = 0;
c946ab02 70 virtual UInt_t GetLDCId() const = 0;
42d20574 71 virtual UInt_t GetGDCId() const = 0;
741c154c 72 virtual UInt_t GetTimestamp() const = 0;
04fa961a 73
c946ab02 74 virtual Int_t GetEquipmentSize() const = 0;
75 virtual Int_t GetEquipmentType() const = 0;
76 virtual Int_t GetEquipmentId() const = 0;
0cfe2438 77 Int_t GetMappedEquipmentId() const;
78 Bool_t LoadEquipmentIdsMap(const char *fileName);
c946ab02 79 virtual const UInt_t* GetEquipmentAttributes() const = 0;
80 virtual Int_t GetEquipmentElementSize() const = 0;
299738b9 81 virtual Int_t GetEquipmentHeaderSize() const = 0;
a6e7b125 82
0cfe2438 83 Int_t GetDetectorID() const;
84 Int_t GetDDLID() const;
39f9963f 85
c946ab02 86 Int_t GetDataSize() const
527a1d3f 87 {if (fHeader) {
88 if (fHeader->fSize != 0xFFFFFFFF) return fHeader->fSize - sizeof(AliRawDataHeader);
299738b9 89 else return GetEquipmentSize() - GetEquipmentHeaderSize() - sizeof(AliRawDataHeader);
90 } else return GetEquipmentSize() - GetEquipmentHeaderSize();};
509a7696 91
c946ab02 92 Int_t GetVersion() const
4e99539f 93 {if (fHeader) return fHeader->GetVersion(); else return -1;};
39f9963f 94 Bool_t IsValid() const
95 {if (fHeader) return fHeader->TestAttribute(0);
96 else return kFALSE;};
c946ab02 97 Bool_t IsCompressed() const
39f9963f 98 {if (fHeader) return fHeader->TestAttribute(1);
c946ab02 99 else return kFALSE;};
c3408d7d 100 Bool_t TestBlockAttribute(Int_t index) const
101 {if (fHeader) return fHeader->TestAttribute(index);
102 else return kFALSE;};
103 UChar_t GetBlockAttributes() const
104 {if (fHeader) return fHeader->GetAttributes();
105 else return 0;};
f58b3254 106 UInt_t GetStatusBits() const
107 {if (fHeader) return fHeader->GetStatus();
108 else return 0;};
c3408d7d 109 const AliRawDataHeader* GetDataHeader() const
110 {return fHeader;}
c946ab02 111
112 virtual Bool_t ReadHeader() = 0;
8de97894 113 virtual Bool_t ReadNextData(UChar_t*& data) = 0;
114 virtual Bool_t ReadNextInt(UInt_t& data);
115 virtual Bool_t ReadNextShort(UShort_t& data);
116 virtual Bool_t ReadNextChar(UChar_t& data);
bf22797a 117 virtual Bool_t ReadNext(UChar_t* data, Int_t size) = 0;
8de97894 118
119 virtual Bool_t Reset() = 0;
a6e7b125 120
dd9a70fe 121 virtual Bool_t NextEvent() = 0;
122 virtual Bool_t RewindEvents() = 0;
636c1780 123 virtual Bool_t GotoEvent(Int_t event);
124 virtual Int_t GetEventIndex() const { return -1; }
dd9a70fe 125
39f9963f 126 enum {kErrMagic=1, kErrNoDataHeader=2,
127 kErrSize=4, kErrOutOfBounds=8};
b4857df7 128 virtual Int_t CheckData() const;
bea6b2a4 129 Int_t GetErrorCode() const {return fErrorCode;};
b4857df7 130
509a7696 131 void DumpData(Int_t limit = -1);
132
9fc249d9 133 void AddErrorLog(AliRawDataErrorLog::ERawDataErrorLevel level,
134 Int_t code,
38cf12f3 135 const char *message = NULL);
9fc249d9 136 void AddMinorErrorLog(Int_t code,
137 const char *message = NULL) {
138 return AddErrorLog(AliRawDataErrorLog::kMinor,code,message);
139 }
140 void AddMajorErrorLog(Int_t code,
141 const char *message = NULL) {
142 return AddErrorLog(AliRawDataErrorLog::kMajor,code,message);
143 }
144 void AddFatalErrorLog(Int_t code,
145 const char *message = NULL) {
146 return AddErrorLog(AliRawDataErrorLog::kFatal,code,message);
147 }
38cf12f3 148 Int_t GetNumberOfErrorLogs() const { return fErrorLogs.GetEntriesFast(); }
79dac785 149 const TClonesArray &GetAllErrorLogs() const { return fErrorLogs; }
38cf12f3 150 AliRawDataErrorLog *GetErrorLog(Int_t i) const {
151 return (AliRawDataErrorLog *)fErrorLogs.UncheckedAt(i);
152 }
153
2d91a353 154 // Method which can be used in order to force the auto-save on
155 // ESD tree inside AliReconstruction. For the moment it will be
156 // activated only for AliRawReaderDateOnline.
157 virtual Bool_t UseAutoSaveESD() const { return kFALSE; }
636c1780 158 virtual TChain* GetChain() const { return NULL; }
2d91a353 159
a6e7b125 160 protected :
3f7450e0 161 virtual void SelectEvents(Int_t type, ULong64_t triggerMask = 0);
42d20574 162 Bool_t IsSelected() const;
dd9a70fe 163 Bool_t IsEventSelected() const;
a6e7b125 164
0cfe2438 165 TArrayI *fEquipmentIdsIn; // array of equipment Ids to be mapped
166 TArrayI *fEquipmentIdsOut; // array of mapped equipment Ids
18882b3b 167
0cfe2438 168 Bool_t fRequireHeader; // if false, data without header is accepted
169
170 AliRawDataHeader* fHeader; // current data header
171 Int_t fCount; // counter of bytes to be read for current DDL
a6e7b125 172
f224de6c 173 Int_t fSelectEquipmentType; // type of selected equipment (<0 = no selection)
174 Int_t fSelectMinEquipmentId; // minimal index of selected equipment (<0 = no selection)
175 Int_t fSelectMaxEquipmentId; // maximal index of selected equipment (<0 = no selection)
0cfe2438 176 Bool_t fSkipInvalid; // skip invalid data
177 Int_t fSelectEventType; // type of selected events (<0 = no selection)
00665a00 178 ULong64_t fSelectTriggerMask; // trigger mask for selecting events (0 = no selection)
8de97894 179
0cfe2438 180 Int_t fErrorCode; // code of last error
b4857df7 181
38cf12f3 182 Int_t fEventNumber; // current event number
edd06192 183 TClonesArray fErrorLogs; // raw data decoding errors
184
185 AliRawDataHeader* fHeaderSwapped; // temporary buffer for swapping header on PowerPC
38cf12f3 186
91f76e9b 187 UInt_t SwapWord(UInt_t x) const;
188 UShort_t SwapShort(UShort_t x) const;
189
a6e7b125 190 ClassDef(AliRawReader, 0) // base class for reading raw digits
191};
192
193#endif