2 // Original: AliHLTMemHandler.h,v 1.30 2004/10/06 08:51:20 cvetan
3 #ifndef ALIHLTTPCMEMHANDLER_H
4 #define ALIHLTTPCMEMHANDLER_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 AliHLTTPCMemHandler.h
10 // @author U. Frankenfeld, A. Vestbo, C. Loizides, maintained by
13 // @brief input interface base class for the TPC tracking code before
14 // migration to the HLT component framework
16 class AliHLTTPCDigitData;
17 class AliHLTTPCSpacePointData;
18 class AliHLTTPCDigitRowData;
19 class AliHLTTPCTrackSegmentData;
20 class AliHLTTPCTrackArray;
21 class AliHLTTPCRandomPointData;
22 class AliHLTTPCRandomDigitData;
26 class AliTPCRawStream;
29 * @class AliHLTTPCMemHandler
30 * The HLT Binary File handler
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
40 * 1) Reading a binary file:
42 * AliHLTTPCMemHandler file;
43 * file.SetBinaryInput(filename);
44 * file.Init(slice,patch);
47 * AliHLTTPCDigitRowData *data = file.CompBinary2Memory(nrows);
49 * for(int i=0; i<nrows; i++)
52 * AliHLTTPCDigitData *dataPt = (AliHLTTPCDigitData*)data->fDigitData;
53 * for(int j=0; j<data->fNDigit; j++)
55 * pad = dataPt[j].fPad;
56 * time = dataPt[j].fTime;
57 * charge = dataPt[j].fCharge;
60 * file.UpdateRowPointer(data);
63 * file.CloseBinaryInput();
64 * ________________________
66 * 2) Writing a binary file:
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:
73 * AliHLTTPCMemHandler newfile;
74 * newfile.Init(slice,patch);
75 * newfile.SetBinaryOutput(newfilename);
76 * newfile.Memory2CompBinary((UInt_t)NumberOfRowsInPatch,(AliHLTTPCDigitRowData*)data);
77 * newfile.CloseBinaryOutput();
80 * Compressed file format:
81 * -----------------------
83 * The data is RLE encoded and currently using _10_ bit range for the ADC-values.
88 class AliHLTTPCMemHandler {
91 AliHLTTPCMemHandler();
92 virtual ~AliHLTTPCMemHandler();
94 void Reset(){CloseBinaryInput();CloseBinaryOutput();Free();}
95 void Init(Int_t s,Int_t p, Int_t *r=0);
97 Bool_t SetBinaryInput(char *name);
98 Bool_t SetBinaryInput(FILE *file);
99 void CloseBinaryInput();
101 Bool_t SetBinaryOutput(char *name);
102 Bool_t SetBinaryOutput(FILE *file);
103 void CloseBinaryOutput();
106 void SetRandomCluster(Int_t maxnumber);
107 void SetRandomSeed(UInt_t seed){srand(seed);}
108 void SetRandomSeed();
110 void ResetRandom(){fNDigits = 0; fNUsed = 0;}
111 void SetNGenerate(Int_t number){(number>fNRandom)?fNGenerate=fNRandom:fNGenerate = number;}
113 void SetROI(const Float_t *eta,Int_t *slice);
116 ////////////////////////////////////////////////////////////////////////////////////
121 * Write digit data to binary file.
122 * The function loops over the rows and dumps all data of the
123 * AliHLTTPCDigitRowData in binary format to the file.
124 * @param nrow size of the array
125 * @param data data array
126 * @return kTRUE if succeeded, kFALSE if error
128 Bool_t Memory2BinaryFile(UInt_t nrow,AliHLTTPCDigitRowData *data);
130 Int_t Memory2CompMemory(UInt_t nrow,AliHLTTPCDigitRowData *data,UInt_t *comp);
131 Bool_t CompMemory2CompBinary(UInt_t nrow,UInt_t *comp, UInt_t size=0);
133 virtual Bool_t Memory2CompBinary(UInt_t nrow,AliHLTTPCDigitRowData *data);
135 UInt_t GetNRow(UInt_t *comp,UInt_t size);
138 Bool_t Memory2Binary(UInt_t npoint,AliHLTTPCSpacePointData *data);
139 Bool_t Transform(UInt_t npoint,AliHLTTPCSpacePointData *data,Int_t slice);
140 static void UpdateRowPointer(AliHLTTPCDigitRowData *&tempPt);
143 Bool_t Memory2Binary(UInt_t ntrack,AliHLTTPCTrackSegmentData *data);
144 Bool_t TrackArray2Binary(AliHLTTPCTrackArray *array);
145 Bool_t TrackArray2Memory(UInt_t & ntrack,AliHLTTPCTrackSegmentData *data,AliHLTTPCTrackArray *array) const;
146 Bool_t Memory2TrackArray(UInt_t ntrack,AliHLTTPCTrackSegmentData *data,AliHLTTPCTrackArray *array) const;
147 Bool_t Memory2TrackArray(UInt_t ntrack,AliHLTTPCTrackSegmentData *data,AliHLTTPCTrackArray *array,Int_t slice) const;
150 UInt_t GetAllocatedSize() const {return fSize;}
151 UInt_t GetFileSize();
152 UInt_t GetMemorySize(UInt_t nrow,UInt_t *comp) const;
153 UInt_t GetCompMemorySize(UInt_t nrow,AliHLTTPCDigitRowData *data) const;
154 UInt_t GetRandomSize() const;
156 Byte_t *Allocate(UInt_t size);
157 Byte_t *Allocate(); // allocate size of Binary Input File
158 Byte_t *Allocate(AliHLTTPCTrackArray *array);
159 Byte_t *GetDataPointer(UInt_t &size) const {size = fSize; return fPt;}
160 FILE *GetFilePointer() const {return fInBinary;}
164 Int_t GetRowMin() const {return fRowMin;}
165 Int_t GetRowMax() const {return fRowMax;}
166 Int_t GetSlice() const {return fSlice;}
167 Int_t GetPatch() const {return fPatch;}
170 virtual void FreeDigitsTree() {fDummy=0; return;}
171 virtual Bool_t SetAliInput(char */*name*/){fDummy=0; return 0;}
172 virtual Bool_t SetAliInput(AliRunLoader */*runloader*/){fDummy=0; return 0;}
173 virtual void CloseAliInput(){fDummy=0; return;}
174 virtual Bool_t IsDigit(Int_t /*i*/=0){fDummy=0; return 0;}
175 virtual Bool_t SetMCOutput(char */*name*/){fDummy=0; return 0;}
176 virtual Bool_t SetMCOutput(FILE */*file*/){fDummy=0; return 0;}
177 virtual void CloseMCOutput(){fDummy=0; return;}
178 virtual Bool_t AliDigits2Binary(Int_t /*event*/=0,Bool_t /*altro*/=kFALSE){fDummy=0; return 0;}
179 virtual Bool_t AliDigits2CompBinary(Int_t /*event*/=0,Bool_t /*altro*/=kFALSE){fDummy=0; return 0;}
180 virtual AliHLTTPCDigitRowData *AliDigits2Memory(UInt_t & /*nrow*/,Int_t /*event*/=0){fDummy=0; return 0;}
181 virtual AliHLTTPCDigitRowData *AliAltroDigits2Memory(UInt_t & /*nrow*/,Int_t /*event*/=0,Bool_t /*eventmerge*/=kFALSE){fDummy=0; return 0;}
182 virtual void AliDigits2RootFile(AliHLTTPCDigitRowData */*rowPt*/,Char_t */*new_digitsfile*/){fDummy=0; return;}
183 virtual Bool_t AliPoints2Binary(Int_t /*eventn*/=0){fDummy=0; return 0;}
184 virtual AliHLTTPCSpacePointData *AliPoints2Memory(UInt_t & /*npoint*/,Int_t /*eventn*/=0){fDummy=0; return 0;}
186 //AliHLTTPCRawDataFileHandler
187 virtual Bool_t SetRawInput(Char_t */*name*/){fDummy=0; return 0;}
188 virtual Bool_t SetRawInput(ifstream */*file*/){fDummy=0; return 0;}
189 virtual void CloseRawInput(){}
190 virtual Int_t ReadRawInput(){fDummy=0; return 0;}
191 virtual Short_t** GetRawData(Int_t &/*channels*/, Int_t & /*timebins*/){fDummy=0; return 0;}
193 virtual Bool_t SetRawOutput(Char_t */*name*/){fDummy=0; return 0;}
194 virtual Bool_t SetRawOutput(ofstream */*file*/){fDummy=0; return 0;}
195 virtual void CloseRawOutput(){}
196 virtual Bool_t SaveRawOutput(){fDummy=0; return 0;}
198 virtual Bool_t SetMappingFile(Char_t */*name*/){fDummy=0; return 0;}
199 virtual Bool_t SetMappingFile(FILE */*file*/){fDummy=0; return 0;}
200 virtual void CloseMappingFile(){}
201 virtual Int_t ReadMappingFile(){fDummy=0; return 0;}
203 virtual Bool_t SetRawPedestalsInput(Char_t */*name*/){fDummy=0; return 0;}
204 virtual Bool_t SetRawPedestalsInput(ifstream */*file*/){fDummy=0; return 0;}
205 virtual void CloseRawPedestalsInput(){}
206 virtual Int_t ReadRawPedestalsInput(){fDummy=0; return 0;}
208 virtual AliHLTTPCDigitRowData* RawData2Memory(UInt_t &/*nrow*/,Int_t /*event*/=-1){fDummy=0; return 0;}
209 virtual Bool_t RawData2CompMemory(Int_t /*event*/=-1){fDummy=0; return 0;}
211 //AliHLTTPCDDLDataFileHandler
212 virtual Bool_t SetReaderInput(AliRawEvent */*rawevent*/){fDummy=0; return 0;}
213 virtual Bool_t SetReaderInput(Char_t */*name*/,Int_t /*event*/=0){fDummy=0; return 0;}
214 virtual void CloseReaderInput(){};
216 virtual AliHLTTPCDigitRowData* DDLData2Memory(UInt_t &/*nrow*/,Int_t /*event*/=-1){fDummy=0; return 0;}
217 virtual Bool_t DDLData2CompBinary(Int_t /*event*/=-1){fDummy=0; return 0;}
219 virtual AliTPCRawStream* GetTPCRawStream(){fDummy=0; return 0;}
222 Int_t fRowMin; //min row
223 Int_t fRowMax; //max row
224 Int_t fSlice; //slice
225 Int_t fPatch; //patch
227 static const Int_t fgkNSlice = 36; //!
228 static const Int_t fgkNRow = 159; //!
230 Int_t fEtaMinTimeBin[fgkNRow]; //for ROI in eta only
231 Int_t fEtaMaxTimeBin[fgkNRow]; //for ROI in eta only
237 /** copy constructor prohibited */
238 AliHLTTPCMemHandler(const AliHLTTPCMemHandler& src);
239 /** assignment operator prohibited */
240 AliHLTTPCMemHandler& operator=(const AliHLTTPCMemHandler& src);
243 UInt_t fSize; //size of allocated data structure
245 Bool_t fIsRandom; //random data generated
246 Int_t fNRandom; //count random digits
247 Int_t fNGenerate; //count generated digits
248 Int_t fNUsed; //count used digits
249 Int_t fNDigits; //count digits from digitstree
251 AliHLTTPCRandomDigitData **fDPt;//!
252 AliHLTTPCRandomDigitData *fRandomDigits;//!
254 Int_t fDummy; // to fool the virtual const problem
255 // of the coding conventions tool
257 void Write(UInt_t *comp, UInt_t & index, UInt_t & subindex, UShort_t value) const;
258 UShort_t Read(UInt_t *comp, UInt_t & index, UInt_t & subindex) const;
259 UShort_t Test(const UInt_t *comp, UInt_t index, UInt_t subindex) const;
261 void DigitizePoint(Int_t row,Int_t pad, Int_t time,Int_t charge);
262 void QSort(AliHLTTPCRandomDigitData **a, Int_t first, Int_t last);
263 Int_t ComparePoints(UInt_t row,UShort_t pad,UShort_t time) const ;
264 Int_t CompareDigits(const AliHLTTPCRandomDigitData *a, const AliHLTTPCRandomDigitData *b) const;
265 void AddData(AliHLTTPCDigitData *data,UInt_t & ndata,
266 UInt_t row,UShort_t pad,UShort_t time,UShort_t charge) const;
267 void AddRandom(AliHLTTPCDigitData *data,UInt_t & ndata);
268 void MergeDataRandom(AliHLTTPCDigitData *data,UInt_t & ndata,
269 UInt_t row,UShort_t pad,UShort_t time,UShort_t charge);
270 void AddDataRandom(AliHLTTPCDigitData *data,UInt_t & ndata,
271 UInt_t row,UShort_t pad,UShort_t time,UShort_t charge);
274 ClassDef(AliHLTTPCMemHandler,0) // Memory handler class