3 #ifndef ALIHLTTPCHWCFDATA_H
4 #define ALIHLTTPCHWCFDATA_H
5 //* This file is property of and copyright by the ALICE HLT Project *
6 //* ALICE Experiment at CERN, All rights reserved. *
7 //* See cxx source for full Copyright notice *
9 /// @file AliHLTTPCHWCFData.h
10 /// @author Matthias Richter
12 /// @brief Decoder methods for the HWCF format
16 #include "AliHLTDataTypes.h"
17 #include "AliHLTLogging.h"
18 #include "AliHLTErrorGuard.h"
23 * @class AliHLTTPCHWCFData
24 * The class provides decoding functionality for the output format of the
25 * TPC HW ClusterFinder
27 * Two formats have been defined in the past and can be detected:
28 * version 0: 5 32bit words 20 Byte
30 * word 0: header (big endian 32bit unsigned)
31 * bit 31-30: 0x11 indicates cluster
32 * bit 29-24: row number in partition
33 * bit 23-0: Qtot, fixed point number with 6 bits after the point
35 * word 2: time (float)
36 * word 3: pad variance (float)
37 * word 4: time variance (float)
40 * version 1: 6 32bit words 24 Byte
42 * word 0: header (big endian 32bit unsigned)
43 * bit 31-30: 0x11 indicates cluster
44 * bit 29-24: row number in partition
45 * bit 23-0: Qmax, fixed point number with 6 bits after the point
46 * word 1: total charge 32bit big endian, fixed point number with 12 bits after the point
48 * word 3: time (float)
49 * word 4: pad variance (float)
50 * word 5: time variance (float)
53 class AliHLTTPCHWCFData : public AliHLTLogging {
55 AliHLTTPCHWCFData(int forceVersion=-1);
56 virtual ~AliHLTTPCHWCFData();
58 int Init(const AliHLTUInt8_t* pBuffer, int bufferSize);
61 Int_t GetNumberOfClusters() const;
63 Int_t GetPadRow(int i) const;
64 Float_t GetPad(int i) const;
65 Float_t GetTime(int i) const;
66 Float_t GetSigmaY2(int i) const;
67 Float_t GetSigmaZ2(int i) const;
68 Int_t GetCharge(int i) const;
69 Int_t GetQMax(int i) const;
72 bool CheckAssumption(int format, const AliHLTUInt8_t* pData, int size) const;
74 // check if index is within bounds
76 bool CheckBounds(int i) const {
81 int elementsize=GetElementSize(fVersion);
82 if (elementsize<0) return false;
83 return ((i+1)*elementsize+fRCUTrailerSize<=fBufferSize);
86 // get the size of one element
87 int GetElementSize(int version) const {
89 case 0: return sizeof(AliHLTTPCHWClusterV0);
90 case 1: return sizeof(AliHLTTPCHWClusterV1);
92 ErrorMsg(Form("invalid format version %d", fVersion));
97 // pointer to RCU trailer
98 const AliHLTUInt8_t* GetRCUTrailer() const
100 if (fRCUTrailerSize<=0 || fpBuffer==NULL || fBufferSize<fRCUTrailerSize) return NULL;
101 return fpBuffer+(fBufferSize-fRCUTrailerSize);
104 // size of RCU trailer
105 int GetRCUTrailerSize() const { return fRCUTrailerSize; }
108 void Print(const char* option);
110 // print error message
111 void ErrorMsg( const char *str ) const;
113 // open a file and init
114 int Open(const char* filename);
121 struct AliHLTTPCHWClusterV0 {
122 AliHLTUInt32_t fHeader;
128 Int_t GetPadRow() const;
129 Float_t GetPad() const {return fPad+0.5;}
130 Float_t GetTime() const {return fTime;}
131 Float_t GetSigmaY2() const {
132 Float_t sy2 = fSigmaY2 - fPad*fPad;
133 return (sy2>0) ?sy2 :0.;
135 Float_t GetSigmaZ2() const {
136 Float_t sz2 = fSigmaZ2 - fTime*fTime;
137 return (sz2>0) ?sz2 :0.;
139 Int_t GetCharge() const;
140 Int_t GetQMax() const {return -1;}
143 struct AliHLTTPCHWClusterV1 {
144 AliHLTUInt32_t fHeader;
145 AliHLTUInt32_t fCharge;
151 Int_t GetPadRow() const;
152 Float_t GetPad() const {return fPad+0.5;}
153 Float_t GetTime() const {return fTime;}
154 Float_t GetSigmaY2() const {
155 Float_t sy2 = fSigmaY2 - fPad*fPad;
156 return (sy2>0) ?sy2 :0.;
158 Float_t GetSigmaZ2() const {
159 Float_t sz2 = fSigmaZ2 - fTime*fTime;
160 return (sz2>0) ?sz2 :0.;
162 Int_t GetCharge() const;
163 Int_t GetQMax() const;
167 class AliHLTTPCHWClusterDecoder {
169 AliHLTTPCHWClusterDecoder(const T* pClusterArray, int entries);
170 ~AliHLTTPCHWClusterDecoder();
172 // i'th element, no bounds check for performance reasons
173 const T& operator[](unsigned i) {
174 return fpClusterArray[i];
177 Int_t GetPadRow(int i) const {return fpClusterArray[i]->GetPadRow();}
178 Float_t GetPad(int i) const {return fpClusterArray[i]->GetPad();}
179 Float_t GetTime(int i) const {return fpClusterArray[i]->GetTime();}
180 Float_t GetSigmaY2(int i) const {return fpClusterArray[i]->GetSigmaY2();}
181 Float_t GetSigmaZ2(int i) const {return fpClusterArray[i]->GetSigmaZ2();}
182 Int_t GetCharge(int i) const {return fpClusterArray[i]->GetCharge();}
183 Int_t GetQMax(int i) const {return fpClusterArray[i]->GetQMax();}
186 const T* fpClusterArray; //! array of clusters
187 int fEntries; //! number of entries
193 : fData(NULL), fVersion(-1), fElementSize(0) {}
194 iterator(const AliHLTUInt8_t* pData, int version, int elementSize)
195 : fData(pData), fVersion(version), fElementSize(elementSize) {}
196 iterator(const iterator& i)
197 : fData(i.fData), fVersion(i.fVersion), fElementSize(i.fElementSize) {}
198 iterator& operator=(const iterator& i) {
199 if (this==&i) return *this;
200 fData=i.fData; fVersion=i.fVersion; fElementSize=i.fElementSize; return *this;
202 ~iterator() {fData=NULL;}
204 bool operator==(const iterator& i) const {return (fData!=NULL) && (fData==i.fData);}
205 bool operator!=(const iterator& i) const {return (fData!=NULL) && (fData!=i.fData);}
207 iterator& operator++() {fData+=fElementSize; return *this;}
208 iterator& operator--() {fData-=fElementSize; return *this;}
210 iterator operator++(int) {iterator i(*this); fData+=fElementSize; return i;}
211 iterator operator--(int) {iterator i(*this); fData-=fElementSize; return i;}
213 iterator& operator+=(int step) {fData+=step*fElementSize; return *this;}
215 Int_t GetPadRow() const {
217 case 0: return reinterpret_cast<const AliHLTTPCHWClusterV0*>(fData)->GetPadRow();
218 case 1: return reinterpret_cast<const AliHLTTPCHWClusterV1*>(fData)->GetPadRow();
221 Float_t GetPad() const {
223 case 0: return reinterpret_cast<const AliHLTTPCHWClusterV0*>(fData)->GetPad();
224 case 1: return reinterpret_cast<const AliHLTTPCHWClusterV1*>(fData)->GetPad();
227 Float_t GetTime() const {
229 case 0: return reinterpret_cast<const AliHLTTPCHWClusterV0*>(fData)->GetTime();
230 case 1: return reinterpret_cast<const AliHLTTPCHWClusterV1*>(fData)->GetTime();
233 Float_t GetSigmaY2() const {
235 case 0: return reinterpret_cast<const AliHLTTPCHWClusterV0*>(fData)->GetSigmaY2();
236 case 1: return reinterpret_cast<const AliHLTTPCHWClusterV1*>(fData)->GetSigmaY2();
239 Float_t GetSigmaZ2() const {
241 case 0: return reinterpret_cast<const AliHLTTPCHWClusterV0*>(fData)->GetSigmaZ2();
242 case 1: return reinterpret_cast<const AliHLTTPCHWClusterV1*>(fData)->GetSigmaZ2();
245 Int_t GetCharge() const {
247 case 0: return reinterpret_cast<const AliHLTTPCHWClusterV0*>(fData)->GetCharge();
248 case 1: return reinterpret_cast<const AliHLTTPCHWClusterV1*>(fData)->GetCharge();
251 Int_t GetQMax() const {
253 case 0: return reinterpret_cast<const AliHLTTPCHWClusterV0*>(fData)->GetQMax();
254 case 1: return reinterpret_cast<const AliHLTTPCHWClusterV1*>(fData)->GetQMax();
260 const AliHLTUInt8_t* fData; //! data
261 int fVersion; //! format version
262 int fElementSize; //! element size
265 // prepare iterator and end marker
267 fIterator.~iterator();
268 new (&fIterator) iterator(fpBuffer, fVersion, GetElementSize(fVersion));
269 fIteratorEnd=fIterator;
270 fIteratorEnd+=GetNumberOfClusters();
274 // get loop end marker
279 // find one single element
280 iterator& find(int i) {
281 fIterator.~iterator();
282 fIteratorEnd.~iterator();
283 if (i>=GetNumberOfClusters()) return fIterator;
284 new (&fIterator) iterator(fpBuffer, fVersion, GetElementSize(fVersion));
286 fIteratorEnd=fIterator;
291 static const unsigned fgkAliHLTTPCHWClusterSize;
295 AliHLTTPCHWCFData(const AliHLTTPCHWCFData&);
296 AliHLTTPCHWCFData& operator=(const AliHLTTPCHWCFData&);
298 // get pointer to i'th element
299 const AliHLTUInt8_t* Get(int i) const
301 if (!fpBuffer) return NULL;
302 int elementsize=GetElementSize(fVersion);
303 if (elementsize<0) return NULL;
304 return fpBuffer+(i*elementsize);
308 const AliHLTUInt8_t* fpBuffer; //! pointer to data buffer
309 int fBufferSize; //! size of data buffer
311 int fVersion; //! format version
312 int fForcedVersion; //! forced format version
313 int fRCUTrailerSize; //! size of the RCU trailer in Byte
315 TArrayC* fpFileBuffer; //! internal buffer for file content
317 iterator fIterator; //! iterator
318 iterator fIteratorEnd; //! end iterator
320 ClassDef(AliHLTTPCHWCFData, 0)