]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TPCLib/AliHLTTPCMemHandler.h
minor update of documentation
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCMemHandler.h
CommitLineData
a6c02c85 1// @(#) $Id$
4aa41877 2// Original: AliHLTMemHandler.h,v 1.30 2004/10/06 08:51:20 cvetan
ad7e2f5e 3#ifndef ALIHLTTPCMEMHANDLER_H
4#define ALIHLTTPCMEMHANDLER_H
297174de 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 *
5578cf60 8
ad7e2f5e 9// @file AliHLTTPCMemHandler.h
10// @author U. Frankenfeld, A. Vestbo, C. Loizides, maintained by
11// Matthias Richter
12// @date
13// @brief input interface base class for the TPC tracking code before
14// migration to the HLT component framework
a6c02c85 15
16class AliHLTTPCDigitData;
17class AliHLTTPCSpacePointData;
18class AliHLTTPCDigitRowData;
19class AliHLTTPCTrackSegmentData;
20class AliHLTTPCTrackArray;
21class AliHLTTPCRandomPointData;
22class AliHLTTPCRandomDigitData;
23
a6c02c85 24class AliRunLoader;
25class AliRawEvent;
ad7e2f5e 26class AliTPCRawStream;
a6c02c85 27
297174de 28/**
29 * @class AliHLTTPCMemHandler
30 * The HLT Binary File handler
31 *
32 * This class is the old memory I/O handler of HLT binary files.
33 * Some functionality is still used in the current code, mainly
34 * conversion of TPC digits into the format understandable by the
35 * components.
36 * <pre>
37 * Examples:
38 * ---------
39 *
40 * 1) Reading a binary file:
41 *
42 * AliHLTTPCMemHandler file;
43 * file.SetBinaryInput(filename);
44 * file.Init(slice,patch);
45 *
46 * UInt_t nrowss;
47 * AliHLTTPCDigitRowData *data = file.CompBinary2Memory(nrows);
48 *
49 * for(int i=0; i<nrows; i++)
50 * {
51 *
52 * AliHLTTPCDigitData *dataPt = (AliHLTTPCDigitData*)data->fDigitData;
53 * for(int j=0; j<data->fNDigit; j++)
54 * {
55 * pad = dataPt[j].fPad;
56 * time = dataPt[j].fTime;
57 * charge = dataPt[j].fCharge;
58 * }
59 *
60 * file.UpdateRowPointer(data);
61 *
62 * }
63 * file.CloseBinaryInput();
64 * ________________________
65 *
66 * 2) Writing a binary file:
67 *
68 * //First of all you need to store the data in memory,
69 * //and have a pointer to it of type AliHLTTPCDigitRowData.
70 * //E.g. if you just want to write the data you read in example 1)
71 * //into a new file, you can do the following:
72 *
73 * AliHLTTPCMemHandler newfile;
74 * newfile.Init(slice,patch);
75 * newfile.SetBinaryOutput(newfilename);
76 * newfile.Memory2CompBinary((UInt_t)NumberOfRowsInPatch,(AliHLTTPCDigitRowData*)data);
77 * newfile.CloseBinaryOutput();
78 *
79 *
80 * Compressed file format:
81 * -----------------------
82 *
83 * The data is RLE encoded and currently using _10_ bit range for the ADC-values.
84 * </pre>
85 *
86 * @ingroup alihlt_tpc
87 */
a6c02c85 88class AliHLTTPCMemHandler {
89
90 public:
91 AliHLTTPCMemHandler();
92 virtual ~AliHLTTPCMemHandler();
a6c02c85 93
94 void Reset(){CloseBinaryInput();CloseBinaryOutput();Free();}
95 void Init(Int_t s,Int_t p, Int_t *r=0);
96
97 Bool_t SetBinaryInput(char *name);
98 Bool_t SetBinaryInput(FILE *file);
99 void CloseBinaryInput();
100
101 Bool_t SetBinaryOutput(char *name);
102 Bool_t SetBinaryOutput(FILE *file);
103 void CloseBinaryOutput();
104
105 //Random cluster
106 void SetRandomCluster(Int_t maxnumber);
107 void SetRandomSeed(UInt_t seed){srand(seed);}
108 void SetRandomSeed();
109
110 void ResetRandom(){fNDigits = 0; fNUsed = 0;}
111 void Generate(Int_t row);
112 void SetNGenerate(Int_t number){(number>fNRandom)?fNGenerate=fNRandom:fNGenerate = number;}
113
ad7e2f5e 114 void SetROI(const Float_t *eta,Int_t *slice);
a6c02c85 115 void ResetROI();
116
5578cf60 117 ////////////////////////////////////////////////////////////////////////////////////
118 //
119 // Digit IO
120
121 /**
122 * Write digit data to binary file.
123 * The function loops over the rows and dumps all data of the
124 * AliHLTTPCDigitRowData in binary format to the file.
125 * @param nrow size of the array
126 * @param data data array
127 * @return kTRUE if succeeded, kFALSE if error
128 */
129 Bool_t Memory2BinaryFile(UInt_t nrow,AliHLTTPCDigitRowData *data);
130
131 /**
132 * Read digit data from binary file.
133 * @param nrow size of the array
134 * @param data data buffer to receive the data
135 * @param sz [IN] buffer size [OUT] total output size
136 * @return kTRUE if succeeded, kFALSE if error
137 */
a38a7850 138 Bool_t Binary2Memory(UInt_t & nrow,AliHLTTPCDigitRowData *data, UInt_t& sz);
5578cf60 139
140 // Matthias 18.09.2007
141 // this function is highly error prone, no size check for data buffer
142 // depricated
143 //Bool_t Binary2Memory(UInt_t & nrow,AliHLTTPCDigitRowData *data){UInt_t tmp;return Binary2Memory(nrow,data,tmp);};
a6c02c85 144
145 Int_t Memory2CompMemory(UInt_t nrow,AliHLTTPCDigitRowData *data,UInt_t *comp);
a38a7850 146 Int_t CompMemory2Memory(UInt_t nrow,AliHLTTPCDigitRowData *data,UInt_t *comp,UInt_t& sz);
147 Int_t CompMemory2Memory(UInt_t nrow,AliHLTTPCDigitRowData *data,UInt_t *comp) {UInt_t tmp;return CompMemory2Memory(nrow,data,comp,tmp);};
a6c02c85 148 Bool_t CompMemory2CompBinary(UInt_t nrow,UInt_t *comp, UInt_t size=0);
149 Bool_t CompBinary2CompMemory(UInt_t & nrow,UInt_t *comp);
150
a38a7850 151 virtual AliHLTTPCDigitRowData *CompBinary2Memory(UInt_t & nrow, UInt_t& sz);
152 virtual AliHLTTPCDigitRowData *CompBinary2Memory(UInt_t & nrow){UInt_t tmp;return CompBinary2Memory(nrow,tmp);};
a6c02c85 153 virtual Bool_t Memory2CompBinary(UInt_t nrow,AliHLTTPCDigitRowData *data);
154
155 UInt_t GetNRow(UInt_t *comp,UInt_t size);
156
157 //Point IO
158 Bool_t Memory2Binary(UInt_t npoint,AliHLTTPCSpacePointData *data);
a38a7850 159 Bool_t Binary2Memory(UInt_t & npoint,AliHLTTPCSpacePointData *data, UInt_t& sz);
160 Bool_t Binary2Memory(UInt_t & npoint,AliHLTTPCSpacePointData *data) {UInt_t tmp; return Binary2Memory(npoint,data,tmp);};
a6c02c85 161 Bool_t Transform(UInt_t npoint,AliHLTTPCSpacePointData *data,Int_t slice);
162 static void UpdateRowPointer(AliHLTTPCDigitRowData *&tempPt);
163
164 //Track IO
165 Bool_t Memory2Binary(UInt_t ntrack,AliHLTTPCTrackSegmentData *data);
166 Bool_t Binary2Memory(UInt_t & ntrack,AliHLTTPCTrackSegmentData *data);
167 Bool_t TrackArray2Binary(AliHLTTPCTrackArray *array);
168 Bool_t Binary2TrackArray(AliHLTTPCTrackArray *array);
169 Bool_t TrackArray2Memory(UInt_t & ntrack,AliHLTTPCTrackSegmentData *data,AliHLTTPCTrackArray *array) const;
170 Bool_t Memory2TrackArray(UInt_t ntrack,AliHLTTPCTrackSegmentData *data,AliHLTTPCTrackArray *array) const;
171 Bool_t Memory2TrackArray(UInt_t ntrack,AliHLTTPCTrackSegmentData *data,AliHLTTPCTrackArray *array,Int_t slice) const;
172
173 //Memory Allocation
174 UInt_t GetAllocatedSize() const {return fSize;}
175 UInt_t GetFileSize();
176 UInt_t GetMemorySize(UInt_t nrow,UInt_t *comp) const;
177 UInt_t GetCompMemorySize(UInt_t nrow,AliHLTTPCDigitRowData *data) const;
178 UInt_t GetRandomSize() const;
179
180 Byte_t *Allocate(UInt_t size);
181 Byte_t *Allocate(); // allocate size of Binary Input File
182 Byte_t *Allocate(AliHLTTPCTrackArray *array);
ad7e2f5e 183 Byte_t *GetDataPointer(UInt_t &size) const {size = fSize; return fPt;}
184 FILE *GetFilePointer() const {return fInBinary;}
a6c02c85 185 void Free();
186
187 //Getters:
188 Int_t GetRowMin() const {return fRowMin;}
189 Int_t GetRowMax() const {return fRowMax;}
190 Int_t GetSlice() const {return fSlice;}
191 Int_t GetPatch() const {return fPatch;}
192
193 //virtual functions:
194 virtual void FreeDigitsTree() {fDummy=0; return;}
195 virtual Bool_t SetAliInput(char */*name*/){fDummy=0; return 0;}
a6c02c85 196 virtual Bool_t SetAliInput(AliRunLoader */*runloader*/){fDummy=0; return 0;}
a6c02c85 197 virtual void CloseAliInput(){fDummy=0; return;}
198 virtual Bool_t IsDigit(Int_t /*i*/=0){fDummy=0; return 0;}
199 virtual Bool_t SetMCOutput(char */*name*/){fDummy=0; return 0;}
200 virtual Bool_t SetMCOutput(FILE */*file*/){fDummy=0; return 0;}
201 virtual void CloseMCOutput(){fDummy=0; return;}
202 virtual Bool_t AliDigits2Binary(Int_t /*event*/=0,Bool_t /*altro*/=kFALSE){fDummy=0; return 0;}
203 virtual Bool_t AliDigits2CompBinary(Int_t /*event*/=0,Bool_t /*altro*/=kFALSE){fDummy=0; return 0;}
204 virtual AliHLTTPCDigitRowData *AliDigits2Memory(UInt_t & /*nrow*/,Int_t /*event*/=0){fDummy=0; return 0;}
205 virtual AliHLTTPCDigitRowData *AliAltroDigits2Memory(UInt_t & /*nrow*/,Int_t /*event*/=0,Bool_t /*eventmerge*/=kFALSE){fDummy=0; return 0;}
206 virtual void AliDigits2RootFile(AliHLTTPCDigitRowData */*rowPt*/,Char_t */*new_digitsfile*/){fDummy=0; return;}
207 virtual Bool_t AliPoints2Binary(Int_t /*eventn*/=0){fDummy=0; return 0;}
208 virtual AliHLTTPCSpacePointData *AliPoints2Memory(UInt_t & /*npoint*/,Int_t /*eventn*/=0){fDummy=0; return 0;}
209
210 //AliHLTTPCRawDataFileHandler
211 virtual Bool_t SetRawInput(Char_t */*name*/){fDummy=0; return 0;}
212 virtual Bool_t SetRawInput(ifstream */*file*/){fDummy=0; return 0;}
213 virtual void CloseRawInput(){}
214 virtual Int_t ReadRawInput(){fDummy=0; return 0;}
215 virtual Short_t** GetRawData(Int_t &/*channels*/, Int_t & /*timebins*/){fDummy=0; return 0;}
216
217 virtual Bool_t SetRawOutput(Char_t */*name*/){fDummy=0; return 0;}
218 virtual Bool_t SetRawOutput(ofstream */*file*/){fDummy=0; return 0;}
219 virtual void CloseRawOutput(){}
220 virtual Bool_t SaveRawOutput(){fDummy=0; return 0;}
221
222 virtual Bool_t SetMappingFile(Char_t */*name*/){fDummy=0; return 0;}
223 virtual Bool_t SetMappingFile(FILE */*file*/){fDummy=0; return 0;}
224 virtual void CloseMappingFile(){}
225 virtual Int_t ReadMappingFile(){fDummy=0; return 0;}
226
227 virtual Bool_t SetRawPedestalsInput(Char_t */*name*/){fDummy=0; return 0;}
228 virtual Bool_t SetRawPedestalsInput(ifstream */*file*/){fDummy=0; return 0;}
229 virtual void CloseRawPedestalsInput(){}
230 virtual Int_t ReadRawPedestalsInput(){fDummy=0; return 0;}
231
232 virtual AliHLTTPCDigitRowData* RawData2Memory(UInt_t &/*nrow*/,Int_t /*event*/=-1){fDummy=0; return 0;}
233 virtual Bool_t RawData2CompMemory(Int_t /*event*/=-1){fDummy=0; return 0;}
234
235 //AliHLTTPCDDLDataFileHandler
a6c02c85 236 virtual Bool_t SetReaderInput(AliRawEvent */*rawevent*/){fDummy=0; return 0;}
237 virtual Bool_t SetReaderInput(Char_t */*name*/,Int_t /*event*/=0){fDummy=0; return 0;}
a6c02c85 238 virtual void CloseReaderInput(){};
239
240 virtual AliHLTTPCDigitRowData* DDLData2Memory(UInt_t &/*nrow*/,Int_t /*event*/=-1){fDummy=0; return 0;}
241 virtual Bool_t DDLData2CompBinary(Int_t /*event*/=-1){fDummy=0; return 0;}
242
243 virtual AliTPCRawStream* GetTPCRawStream(){fDummy=0; return 0;}
244
245 protected:
246 Int_t fRowMin; //min row
247 Int_t fRowMax; //max row
248 Int_t fSlice; //slice
249 Int_t fPatch; //patch
250
0ba35c53 251 static const Int_t fgkNSlice = 36; //!
252 static const Int_t fgkNRow = 159; //!
253
254 Int_t fEtaMinTimeBin[fgkNRow]; //for ROI in eta only
255 Int_t fEtaMaxTimeBin[fgkNRow]; //for ROI in eta only
a6c02c85 256
257 FILE *fInBinary;//!
258 FILE *fOutBinary;//!
259
260 private:
5578cf60 261 /** copy constructor prohibited */
262 AliHLTTPCMemHandler(const AliHLTTPCMemHandler& src);
263 /** assignment operator prohibited */
264 AliHLTTPCMemHandler& operator=(const AliHLTTPCMemHandler& src);
a6c02c85 265
266 Byte_t *fPt;//!
267 UInt_t fSize; //size of allocated data structure
268
269 Bool_t fIsRandom; //random data generated
270 Int_t fNRandom; //count random digits
271 Int_t fNGenerate; //count generated digits
272 Int_t fNUsed; //count used digits
273 Int_t fNDigits; //count digits from digitstree
274
275 AliHLTTPCRandomDigitData **fDPt;//!
276 AliHLTTPCRandomDigitData *fRandomDigits;//!
277
278 Int_t fDummy; // to fool the virtual const problem
279 // of the coding conventions tool
280
281 void Write(UInt_t *comp, UInt_t & index, UInt_t & subindex, UShort_t value) const;
282 UShort_t Read(UInt_t *comp, UInt_t & index, UInt_t & subindex) const;
ad7e2f5e 283 UShort_t Test(const UInt_t *comp, UInt_t index, UInt_t subindex) const;
a6c02c85 284
285 void DigitizePoint(Int_t row,Int_t pad, Int_t time,Int_t charge);
286 void QSort(AliHLTTPCRandomDigitData **a, Int_t first, Int_t last);
287 Int_t ComparePoints(UInt_t row,UShort_t pad,UShort_t time) const ;
ad7e2f5e 288 Int_t CompareDigits(const AliHLTTPCRandomDigitData *a, const AliHLTTPCRandomDigitData *b) const;
a6c02c85 289 void AddData(AliHLTTPCDigitData *data,UInt_t & ndata,
290 UInt_t row,UShort_t pad,UShort_t time,UShort_t charge) const;
291 void AddRandom(AliHLTTPCDigitData *data,UInt_t & ndata);
292 void MergeDataRandom(AliHLTTPCDigitData *data,UInt_t & ndata,
293 UInt_t row,UShort_t pad,UShort_t time,UShort_t charge);
294 void AddDataRandom(AliHLTTPCDigitData *data,UInt_t & ndata,
295 UInt_t row,UShort_t pad,UShort_t time,UShort_t charge);
296
297
22240104 298 ClassDef(AliHLTTPCMemHandler,0) // Memory handler class
a6c02c85 299};
300#endif