]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCMemHandler.h
minor changes in code documentation
[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 ALIHLTTPC_MEMHANDLER_H
4 #define ALIHLTTPC_MEMHANDLER_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 // see below for class documentation
17 // or
18 // refer to README to build package
19 // or
20 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
21                                                                           */
22 //_____________________________________________________________
23 // AliHLTTPCMemHandler
24 //
25 // The HLT Binary File handler 
26 //
27 //  This class does all the memory I/O handling of HLT binary files.
28 //  
29 // Author: Uli Frankenfeld <mailto:franken@fi.uib.no>, 
30 //         Anders Vestbo <mailto:vestbo$fi.uib.no>, 
31 //         Constantin Loizides <mailto:loizides@ikf.uni-frankfurt.de>
32 // *-- Copyright &copy ALICE HLT Group 
33
34 class AliHLTTPCDigitData;
35 class AliHLTTPCSpacePointData;
36 class AliHLTTPCDigitRowData;
37 class AliHLTTPCTrackSegmentData;
38 class AliHLTTPCTrackArray;
39 class AliHLTTPCRandomPointData;
40 class AliHLTTPCRandomDigitData;
41
42 class AliRunLoader;
43 class AliRawEvent;
44 #include "AliTPCRawStream.h"
45
46 class AliHLTTPCMemHandler { 
47
48  public:
49   AliHLTTPCMemHandler();
50   virtual ~AliHLTTPCMemHandler();
51    
52   void Reset(){CloseBinaryInput();CloseBinaryOutput();Free();}  
53   void Init(Int_t s,Int_t p, Int_t *r=0);
54
55   Bool_t SetBinaryInput(char *name);
56   Bool_t SetBinaryInput(FILE *file);
57   void CloseBinaryInput();
58   
59   Bool_t SetBinaryOutput(char *name);
60   Bool_t SetBinaryOutput(FILE *file);
61   void CloseBinaryOutput();
62
63   //Random cluster
64   void SetRandomCluster(Int_t maxnumber);
65   void SetRandomSeed(UInt_t seed){srand(seed);}
66   void SetRandomSeed();
67
68   void ResetRandom(){fNDigits = 0; fNUsed = 0;}
69   void Generate(Int_t row);
70   void SetNGenerate(Int_t number){(number>fNRandom)?fNGenerate=fNRandom:fNGenerate = number;}
71
72   void SetROI(Float_t *eta,Int_t *slice);
73   void ResetROI();
74
75   ////////////////////////////////////////////////////////////////////////////////////
76   //
77   // Digit IO
78
79   /**
80    * Write digit data to binary file.
81    * The function loops over the rows and dumps all data of the
82    * AliHLTTPCDigitRowData in binary format to the file.
83    * @param nrow    size of the array
84    * @param data    data array
85    * @return kTRUE if succeeded, kFALSE if error
86    */
87   Bool_t Memory2BinaryFile(UInt_t nrow,AliHLTTPCDigitRowData *data);
88
89   /**
90    * Read digit data from binary file.
91    * @param nrow    size of the array
92    * @param data    data buffer to receive the data
93    * @param sz      [IN] buffer size [OUT] total output size
94    * @return kTRUE if succeeded, kFALSE if error
95    */
96   Bool_t Binary2Memory(UInt_t & nrow,AliHLTTPCDigitRowData *data, UInt_t& sz);
97
98   // Matthias 18.09.2007
99   // this function is highly error prone, no size check for data buffer
100   // depricated
101   //Bool_t Binary2Memory(UInt_t & nrow,AliHLTTPCDigitRowData *data){UInt_t tmp;return Binary2Memory(nrow,data,tmp);};
102
103   Int_t Memory2CompMemory(UInt_t nrow,AliHLTTPCDigitRowData *data,UInt_t *comp);
104   Int_t CompMemory2Memory(UInt_t nrow,AliHLTTPCDigitRowData *data,UInt_t *comp,UInt_t& sz);
105   Int_t CompMemory2Memory(UInt_t nrow,AliHLTTPCDigitRowData *data,UInt_t *comp) {UInt_t tmp;return CompMemory2Memory(nrow,data,comp,tmp);};
106   Bool_t CompMemory2CompBinary(UInt_t nrow,UInt_t *comp, UInt_t size=0);
107   Bool_t CompBinary2CompMemory(UInt_t & nrow,UInt_t *comp);
108
109   virtual AliHLTTPCDigitRowData *CompBinary2Memory(UInt_t & nrow, UInt_t& sz);
110   virtual AliHLTTPCDigitRowData *CompBinary2Memory(UInt_t & nrow){UInt_t tmp;return CompBinary2Memory(nrow,tmp);};
111   virtual Bool_t Memory2CompBinary(UInt_t nrow,AliHLTTPCDigitRowData *data);
112   
113   UInt_t GetNRow(UInt_t *comp,UInt_t size);
114
115   //Point IO
116   Bool_t Memory2Binary(UInt_t npoint,AliHLTTPCSpacePointData *data);
117   Bool_t Binary2Memory(UInt_t & npoint,AliHLTTPCSpacePointData *data, UInt_t& sz);
118   Bool_t Binary2Memory(UInt_t & npoint,AliHLTTPCSpacePointData *data) {UInt_t tmp; return Binary2Memory(npoint,data,tmp);};
119   Bool_t Transform(UInt_t npoint,AliHLTTPCSpacePointData *data,Int_t slice);
120   static void UpdateRowPointer(AliHLTTPCDigitRowData *&tempPt);
121   
122   //Track IO
123   Bool_t Memory2Binary(UInt_t ntrack,AliHLTTPCTrackSegmentData *data);
124   Bool_t Binary2Memory(UInt_t & ntrack,AliHLTTPCTrackSegmentData *data);
125   Bool_t TrackArray2Binary(AliHLTTPCTrackArray *array);
126   Bool_t Binary2TrackArray(AliHLTTPCTrackArray *array);
127   Bool_t TrackArray2Memory(UInt_t & ntrack,AliHLTTPCTrackSegmentData *data,AliHLTTPCTrackArray *array) const;
128   Bool_t Memory2TrackArray(UInt_t ntrack,AliHLTTPCTrackSegmentData *data,AliHLTTPCTrackArray *array) const;
129   Bool_t Memory2TrackArray(UInt_t ntrack,AliHLTTPCTrackSegmentData *data,AliHLTTPCTrackArray *array,Int_t slice) const;
130     
131   //Memory Allocation
132   UInt_t GetAllocatedSize() const {return fSize;}  
133   UInt_t GetFileSize();
134   UInt_t GetMemorySize(UInt_t nrow,UInt_t *comp) const;
135   UInt_t GetCompMemorySize(UInt_t nrow,AliHLTTPCDigitRowData *data) const;
136   UInt_t GetRandomSize() const;
137
138   Byte_t *Allocate(UInt_t size);
139   Byte_t *Allocate();  // allocate size of Binary Input File
140   Byte_t *Allocate(AliHLTTPCTrackArray *array);
141   Byte_t *GetDataPointer(UInt_t &size) {size = fSize; return fPt;}
142   FILE *GetFilePointer() {return fInBinary;}
143   void   Free();
144   
145   //Getters:
146   Int_t GetRowMin() const {return fRowMin;}
147   Int_t GetRowMax() const {return fRowMax;}
148   Int_t GetSlice() const {return fSlice;}
149   Int_t GetPatch() const {return fPatch;}
150   
151   //virtual functions:
152   virtual void FreeDigitsTree() {fDummy=0; return;}
153   virtual Bool_t SetAliInput(char */*name*/){fDummy=0; return 0;}
154   virtual Bool_t SetAliInput(AliRunLoader */*runloader*/){fDummy=0; return 0;}
155   virtual void CloseAliInput(){fDummy=0; return;} 
156   virtual Bool_t IsDigit(Int_t /*i*/=0){fDummy=0; return 0;}
157   virtual Bool_t SetMCOutput(char */*name*/){fDummy=0; return 0;}
158   virtual Bool_t SetMCOutput(FILE */*file*/){fDummy=0; return 0;}
159   virtual void CloseMCOutput(){fDummy=0; return;}
160   virtual Bool_t AliDigits2Binary(Int_t /*event*/=0,Bool_t /*altro*/=kFALSE){fDummy=0; return 0;}
161   virtual Bool_t AliDigits2CompBinary(Int_t /*event*/=0,Bool_t /*altro*/=kFALSE){fDummy=0; return 0;}  
162   virtual AliHLTTPCDigitRowData *AliDigits2Memory(UInt_t & /*nrow*/,Int_t /*event*/=0){fDummy=0; return 0;}
163   virtual AliHLTTPCDigitRowData *AliAltroDigits2Memory(UInt_t & /*nrow*/,Int_t /*event*/=0,Bool_t /*eventmerge*/=kFALSE){fDummy=0; return 0;}
164   virtual void AliDigits2RootFile(AliHLTTPCDigitRowData */*rowPt*/,Char_t */*new_digitsfile*/){fDummy=0; return;}
165   virtual Bool_t AliPoints2Binary(Int_t /*eventn*/=0){fDummy=0; return 0;}
166   virtual AliHLTTPCSpacePointData *AliPoints2Memory(UInt_t & /*npoint*/,Int_t /*eventn*/=0){fDummy=0; return 0;}
167
168   //AliHLTTPCRawDataFileHandler
169   virtual Bool_t SetRawInput(Char_t */*name*/){fDummy=0; return 0;}
170   virtual Bool_t SetRawInput(ifstream */*file*/){fDummy=0; return 0;}
171   virtual void CloseRawInput(){} 
172   virtual Int_t ReadRawInput(){fDummy=0; return 0;}
173   virtual Short_t** GetRawData(Int_t &/*channels*/, Int_t & /*timebins*/){fDummy=0; return 0;}
174
175   virtual Bool_t SetRawOutput(Char_t */*name*/){fDummy=0; return 0;}
176   virtual Bool_t SetRawOutput(ofstream */*file*/){fDummy=0; return 0;}
177   virtual void CloseRawOutput(){} 
178   virtual Bool_t SaveRawOutput(){fDummy=0; return 0;}
179
180   virtual Bool_t SetMappingFile(Char_t */*name*/){fDummy=0; return 0;}
181   virtual Bool_t SetMappingFile(FILE */*file*/){fDummy=0; return 0;}
182   virtual void CloseMappingFile(){} 
183   virtual Int_t ReadMappingFile(){fDummy=0; return 0;}
184   
185   virtual Bool_t SetRawPedestalsInput(Char_t */*name*/){fDummy=0; return 0;}
186   virtual Bool_t SetRawPedestalsInput(ifstream */*file*/){fDummy=0; return 0;}
187   virtual void CloseRawPedestalsInput(){} 
188   virtual Int_t ReadRawPedestalsInput(){fDummy=0; return 0;}
189
190   virtual AliHLTTPCDigitRowData* RawData2Memory(UInt_t &/*nrow*/,Int_t /*event*/=-1){fDummy=0; return 0;}
191   virtual Bool_t RawData2CompMemory(Int_t /*event*/=-1){fDummy=0; return 0;}
192
193   //AliHLTTPCDDLDataFileHandler
194   virtual Bool_t SetReaderInput(AliRawEvent */*rawevent*/){fDummy=0; return 0;}
195   virtual Bool_t SetReaderInput(Char_t */*name*/,Int_t /*event*/=0){fDummy=0; return 0;}
196   virtual void CloseReaderInput(){};
197
198   virtual AliHLTTPCDigitRowData* DDLData2Memory(UInt_t &/*nrow*/,Int_t /*event*/=-1){fDummy=0; return 0;}
199   virtual Bool_t DDLData2CompBinary(Int_t /*event*/=-1){fDummy=0; return 0;}
200
201   virtual AliTPCRawStream* GetTPCRawStream(){fDummy=0; return 0;}
202
203  protected:
204   Int_t fRowMin; //min row
205   Int_t fRowMax; //max row
206   Int_t fSlice;  //slice
207   Int_t fPatch;  //patch
208
209   static const Int_t fgkNSlice = 36; //!
210   static const Int_t fgkNRow = 159; //!
211
212   Int_t fEtaMinTimeBin[fgkNRow]; //for ROI in eta only
213   Int_t fEtaMaxTimeBin[fgkNRow]; //for ROI in eta only
214   
215   FILE *fInBinary;//!
216   FILE *fOutBinary;//!
217
218  private:
219   /** copy constructor prohibited */
220   AliHLTTPCMemHandler(const AliHLTTPCMemHandler& src);
221   /** assignment operator prohibited */
222   AliHLTTPCMemHandler& operator=(const AliHLTTPCMemHandler& src);
223   
224   Byte_t *fPt;//!
225   UInt_t fSize; //size of allocated data structure
226
227   Bool_t fIsRandom; //random data generated
228   Int_t fNRandom;   //count random digits 
229   Int_t fNGenerate; //count generated digits
230   Int_t fNUsed;     //count used digits
231   Int_t fNDigits;   //count digits from digitstree
232
233   AliHLTTPCRandomDigitData **fDPt;//!
234   AliHLTTPCRandomDigitData *fRandomDigits;//!
235
236   Int_t fDummy; // to fool the virtual const problem 
237                 // of the coding conventions tool
238
239   void Write(UInt_t *comp, UInt_t & index, UInt_t & subindex, UShort_t value) const;
240   UShort_t Read(UInt_t *comp, UInt_t & index, UInt_t & subindex) const;
241   UShort_t Test(UInt_t *comp, UInt_t index, UInt_t subindex) const; 
242   
243   void DigitizePoint(Int_t row,Int_t pad, Int_t time,Int_t charge);
244   void QSort(AliHLTTPCRandomDigitData **a, Int_t first, Int_t last);
245   Int_t ComparePoints(UInt_t row,UShort_t pad,UShort_t time) const ;
246   Int_t CompareDigits(AliHLTTPCRandomDigitData *a,AliHLTTPCRandomDigitData *b) const;
247   void AddData(AliHLTTPCDigitData *data,UInt_t & ndata,
248                       UInt_t row,UShort_t pad,UShort_t time,UShort_t charge) const;
249   void AddRandom(AliHLTTPCDigitData *data,UInt_t & ndata);
250   void MergeDataRandom(AliHLTTPCDigitData *data,UInt_t & ndata,
251                       UInt_t row,UShort_t pad,UShort_t time,UShort_t charge);
252   void AddDataRandom(AliHLTTPCDigitData *data,UInt_t & ndata,
253                       UInt_t row,UShort_t pad,UShort_t time,UShort_t charge);
254
255
256   ClassDef(AliHLTTPCMemHandler,1) // Memory handler class
257 };
258 #endif