]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/src/AliL3MemHandler.h
de2cfbd6841a07117d3665b97954baadea5049c3
[u/mrichter/AliRoot.git] / HLT / src / AliL3MemHandler.h
1 // @(#) $Id$
2
3 #ifndef ALIL3_MEMHANDLER_H
4 #define ALIL3_MEMHANDLER_H
5
6 //_____________________________________________________________
7 // AliL3MemHandler
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 AliL3DigitData;
19 class AliL3SpacePointData;
20 class AliL3DigitRowData;
21 class AliL3TrackSegmentData;
22 class AliL3TrackArray;
23 class AliL3RandomPointData;
24 class AliL3RandomDigitData;
25
26 #ifdef use_newio
27 class AliRunLoader;
28 #endif
29 class AliTPCRawStream;
30
31 class AliL3MemHandler { 
32
33  public:
34   AliL3MemHandler();
35   virtual ~AliL3MemHandler();
36   AliL3MemHandler(const AliL3MemHandler& /*m*/){};
37   AliL3MemHandler& operator=(const AliL3MemHandler& /*&m*/)
38     {return (*this);}
39    
40   void Reset(){CloseBinaryInput();CloseBinaryOutput();Free();}  
41   void Init(Int_t s,Int_t p, Int_t *r=0);
42
43   Bool_t SetBinaryInput(char *name);
44   Bool_t SetBinaryInput(FILE *file);
45   void CloseBinaryInput();
46   
47   Bool_t SetBinaryOutput(char *name);
48   Bool_t SetBinaryOutput(FILE *file);
49   void CloseBinaryOutput();
50
51   //Random cluster
52   void SetRandomCluster(Int_t maxnumber);
53   void SetRandomSeed(UInt_t seed){srand(seed);}
54   void SetRandomSeed();
55
56   void ResetRandom(){fNDigits = 0; fNUsed = 0;}
57   void Generate(Int_t row);
58   void SetNGenerate(Int_t number){(number>fNRandom)?fNGenerate=fNRandom:fNGenerate = number;}
59
60   void SetROI(Float_t *eta,Int_t *slice);
61   void ResetROI();
62
63   //Digit IO
64   Bool_t Memory2Binary(UInt_t nrow,AliL3DigitRowData *data);
65   Bool_t Binary2Memory(UInt_t & nrow,AliL3DigitRowData *data);
66
67   Int_t Memory2CompMemory(UInt_t nrow,AliL3DigitRowData *data,UInt_t *comp);
68   Int_t CompMemory2Memory(UInt_t nrow,AliL3DigitRowData *data,UInt_t *comp);
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 AliL3DigitRowData *CompBinary2Memory(UInt_t & nrow);
73   virtual Bool_t Memory2CompBinary(UInt_t nrow,AliL3DigitRowData *data);
74   
75   UInt_t GetNRow(UInt_t *comp,UInt_t size);
76
77   //Point IO
78   Bool_t Memory2Binary(UInt_t npoint,AliL3SpacePointData *data);
79   Bool_t Binary2Memory(UInt_t & npoint,AliL3SpacePointData *data);
80   Bool_t Transform(UInt_t npoint,AliL3SpacePointData *data,Int_t slice);
81   static void UpdateRowPointer(AliL3DigitRowData *&tempPt);
82   
83   //Track IO
84   Bool_t Memory2Binary(UInt_t ntrack,AliL3TrackSegmentData *data);
85   Bool_t Binary2Memory(UInt_t & ntrack,AliL3TrackSegmentData *data);
86   Bool_t TrackArray2Binary(AliL3TrackArray *array);
87   Bool_t Binary2TrackArray(AliL3TrackArray *array);
88   Bool_t TrackArray2Memory(UInt_t & ntrack,AliL3TrackSegmentData *data,AliL3TrackArray *array) const;
89   Bool_t Memory2TrackArray(UInt_t ntrack,AliL3TrackSegmentData *data,AliL3TrackArray *array) const;
90   Bool_t Memory2TrackArray(UInt_t ntrack,AliL3TrackSegmentData *data,AliL3TrackArray *array,Int_t slice) const;
91     
92   //Memory Allocation
93   UInt_t GetAllocatedSize() const {return fSize;}  
94   UInt_t GetFileSize();
95   UInt_t GetMemorySize(UInt_t nrow,UInt_t *comp) const;
96   UInt_t GetCompMemorySize(UInt_t nrow,AliL3DigitRowData *data) const;
97   UInt_t GetRandomSize() const;
98
99   Byte_t *Allocate(UInt_t size);
100   Byte_t *Allocate();  // allocate size of Binary Input File
101   Byte_t *Allocate(AliL3TrackArray *array);
102   Byte_t *GetDataPointer(UInt_t &size) {size = fSize; return fPt;}
103   FILE *GetFilePointer() {return fInBinary;}
104   void   Free();
105   
106   //Getters:
107   Int_t GetRowMin() const {return fRowMin;}
108   Int_t GetRowMax() const {return fRowMax;}
109   Int_t GetSlice() const {return fSlice;}
110   Int_t GetPatch() const {return fPatch;}
111   
112   //virtual functions:
113   virtual void FreeDigitsTree() {fDummy=0; return;}
114   virtual Bool_t SetAliInput(char */*name*/){fDummy=0; return 0;}
115 #ifdef use_newio
116   virtual Bool_t SetAliInput(AliRunLoader */*runloader*/){fDummy=0; return 0;}
117 #endif
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 AliL3DigitRowData *AliDigits2Memory(UInt_t & /*nrow*/,Int_t /*event*/=0){fDummy=0; return 0;}
126   virtual AliL3DigitRowData *AliAltroDigits2Memory(UInt_t & /*nrow*/,Int_t /*event*/=0,Bool_t /*eventmerge*/=kFALSE){fDummy=0; return 0;}
127   virtual void AliDigits2RootFile(AliL3DigitRowData */*rowPt*/,Char_t */*new_digitsfile*/){fDummy=0; return;}
128   virtual Bool_t AliPoints2Binary(Int_t /*eventn*/=0){fDummy=0; return 0;}
129   virtual AliL3SpacePointData *AliPoints2Memory(UInt_t & /*npoint*/,Int_t /*eventn*/=0){fDummy=0; return 0;}
130
131   //AliL3RawDataFileHandler
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 AliL3DigitRowData* 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   //AliL3DDLDataFileHandler
157 #ifdef use_newio
158   virtual Bool_t SetReaderInput(Char_t */*name*/,Int_t /*event*/=0){fDummy=0; return 0;}
159 #else
160   virtual Bool_t SetReaderInput(Char_t */*name*/,Bool_t /*add*/=kTRUE){fDummy=0; return 0;}
161 #endif
162   virtual void CloseReaderInput(){};
163
164   virtual AliL3DigitRowData* DDLData2Memory(UInt_t &/*nrow*/,Int_t /*event*/=-1){fDummy=0; return 0;}
165   virtual Bool_t DDLData2CompBinary(Int_t /*event*/=-1){fDummy=0; return 0;}
166
167   virtual AliTPCRawStream* GetTPCRawStream(){fDummy=0; return 0;}
168
169  protected:
170   Int_t fRowMin; //min row
171   Int_t fRowMax; //max row
172   Int_t fSlice;  //slice
173   Int_t fPatch;  //patch
174
175   Int_t fEtaMinTimeBin[159]; //for ROI in eta only
176   Int_t fEtaMaxTimeBin[159]; //for ROI in eta only
177   
178   FILE *fInBinary;//!
179   FILE *fOutBinary;//!
180
181  private:
182   
183   Byte_t *fPt;//!
184   UInt_t fSize; //size of allocated data structure
185
186   Bool_t fIsRandom; //random data generated
187   Int_t fNRandom;   //count random digits 
188   Int_t fNGenerate; //count generated digits
189   Int_t fNUsed;     //count used digits
190   Int_t fNDigits;   //count digits from digitstree
191
192   AliL3RandomDigitData **fDPt;//!
193   AliL3RandomDigitData *fRandomDigits;//!
194
195   Int_t fDummy; // to fool the virtual const problem 
196                 // of the coding conventions tool
197
198   void Write(UInt_t *comp, UInt_t & index, UInt_t & subindex, UShort_t value) const;
199   UShort_t Read(UInt_t *comp, UInt_t & index, UInt_t & subindex) const;
200   UShort_t Test(UInt_t *comp, UInt_t index, UInt_t subindex) const; 
201   
202   void DigitizePoint(Int_t row,Int_t pad, Int_t time,Int_t charge);
203   void QSort(AliL3RandomDigitData **a, Int_t first, Int_t last);
204   Int_t ComparePoints(UInt_t row,UShort_t pad,UShort_t time) const ;
205   Int_t CompareDigits(AliL3RandomDigitData *a,AliL3RandomDigitData *b) const;
206   void AddData(AliL3DigitData *data,UInt_t & ndata,
207                       UInt_t row,UShort_t pad,UShort_t time,UShort_t charge) const;
208   void AddRandom(AliL3DigitData *data,UInt_t & ndata);
209   void MergeDataRandom(AliL3DigitData *data,UInt_t & ndata,
210                       UInt_t row,UShort_t pad,UShort_t time,UShort_t charge);
211   void AddDataRandom(AliL3DigitData *data,UInt_t & ndata,
212                       UInt_t row,UShort_t pad,UShort_t time,UShort_t charge);
213
214
215   ClassDef(AliL3MemHandler,1) // Memory handler class
216 };
217 #endif