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