]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCMemHandler.h
- coverity fix 14179
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCMemHandler.h
1 // @(#) $Id$
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                               *
8
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
15
16 class AliHLTTPCDigitData;
17 class AliHLTTPCSpacePointData;
18 class AliHLTTPCDigitRowData;
19 class AliHLTTPCTrackSegmentData;
20 class AliHLTTPCTrackArray;
21 class AliHLTTPCRandomPointData;
22 class AliHLTTPCRandomDigitData;
23
24 class AliRunLoader;
25 class AliRawEvent;
26 class AliTPCRawStream;
27
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  */
88 class AliHLTTPCMemHandler { 
89
90  public:
91   AliHLTTPCMemHandler();
92   virtual ~AliHLTTPCMemHandler();
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 SetNGenerate(Int_t number){(number>fNRandom)?fNGenerate=fNRandom:fNGenerate = number;}
112
113   void SetROI(const Float_t *eta,Int_t *slice);
114   void ResetROI();
115
116   ////////////////////////////////////////////////////////////////////////////////////
117   //
118   // Digit IO
119
120   /**
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
127    */
128   Bool_t Memory2BinaryFile(UInt_t nrow,AliHLTTPCDigitRowData *data);
129
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);
132
133   virtual Bool_t Memory2CompBinary(UInt_t nrow,AliHLTTPCDigitRowData *data);
134   
135   UInt_t GetNRow(UInt_t *comp,UInt_t size);
136
137   //Point IO
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);
141   
142   //Track IO
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;
148     
149   //Memory Allocation
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;
155
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;}
161   void   Free();
162   
163   //Getters:
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;}
168   
169   //virtual functions:
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;}
185
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;}
192
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;}
197
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;}
202   
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;}
207
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;}
210
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(){};
215
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;}
218
219   virtual AliTPCRawStream* GetTPCRawStream(){fDummy=0; return 0;}
220
221  protected:
222   Int_t fRowMin; //min row
223   Int_t fRowMax; //max row
224   Int_t fSlice;  //slice
225   Int_t fPatch;  //patch
226
227   static const Int_t fgkNSlice = 36; //!
228   static const Int_t fgkNRow = 159; //!
229
230   Int_t fEtaMinTimeBin[fgkNRow]; //for ROI in eta only
231   Int_t fEtaMaxTimeBin[fgkNRow]; //for ROI in eta only
232   
233   FILE *fInBinary;//!
234   FILE *fOutBinary;//!
235
236  private:
237   /** copy constructor prohibited */
238   AliHLTTPCMemHandler(const AliHLTTPCMemHandler& src);
239   /** assignment operator prohibited */
240   AliHLTTPCMemHandler& operator=(const AliHLTTPCMemHandler& src);
241   
242   Byte_t *fPt;//!
243   UInt_t fSize; //size of allocated data structure
244
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
250
251   AliHLTTPCRandomDigitData **fDPt;//!
252   AliHLTTPCRandomDigitData *fRandomDigits;//!
253
254   Int_t fDummy; // to fool the virtual const problem 
255                 // of the coding conventions tool
256
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; 
260   
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);
272
273
274   ClassDef(AliHLTTPCMemHandler,0) // Memory handler class
275 };
276 #endif