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