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