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