]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/src/AliL3MemHandler.h
Small change in GetCrossingAngle.
[u/mrichter/AliRoot.git] / HLT / src / AliL3MemHandler.h
1 #ifndef ALIL3MEMHANDLER_H
2 #define ALIL3MEMHANDLER_H
3
4 #include "AliL3RootTypes.h"
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include "AliL3DigitData.h"
8
9 class AliL3SpacePointData;
10 class AliL3DigitRowData;
11 class AliL3TrackSegmentData;
12 class AliL3TrackArray;
13 class AliL3RandomPointData;
14
15 class AliL3MemHandler{
16  private:
17   
18   Byte_t *fPt;//!
19   UInt_t fSize;
20
21   AliL3RandomDigitData **fDPt;//!
22   AliL3RandomDigitData *fDigits;//!
23   Bool_t IsRandom;
24   Int_t fNRandom;
25   Int_t fNGenerate;
26   Int_t fNUsed;
27   Int_t fNDigits;
28
29   void Write(UInt_t *comp, UInt_t & index, UInt_t & subindex, UShort_t value);
30   UShort_t Read(UInt_t *comp, UInt_t & index, UInt_t & subindex);
31   UShort_t Test(UInt_t *comp, UInt_t index, UInt_t subindex); 
32   
33   void DigitizePoint(Int_t row,Int_t pad, Int_t time,Int_t charge);
34   void QSort(AliL3RandomDigitData **a, Int_t first, Int_t last);
35   Int_t ComparePoints(UInt_t row,UShort_t pad,UShort_t time);
36   Int_t CompareDigits(AliL3RandomDigitData *a,AliL3RandomDigitData *b);
37   void AddData(AliL3DigitData *data,UInt_t & ndata,
38                       UInt_t row,UShort_t pad,UShort_t time,UShort_t charge);
39   void AddRandom(AliL3DigitData *data,UInt_t & ndata);
40   void MergeDataRandom(AliL3DigitData *data,UInt_t & ndata,
41                       UInt_t row,UShort_t pad,UShort_t time,UShort_t charge);
42   void AddDataRandom(AliL3DigitData *data,UInt_t & ndata,
43                       UInt_t row,UShort_t pad,UShort_t time,UShort_t charge);
44   
45
46  protected:
47   Int_t fRowMin;
48   Int_t fRowMax;
49   Int_t fSlice;
50   Int_t fPatch;
51
52   Int_t fEtaMinTimeBin[176];
53   Int_t fEtaMaxTimeBin[176];
54   
55   FILE *fInBinary;//!
56   FILE *fOutBinary;//!
57   
58  public:
59   AliL3MemHandler();
60   virtual ~AliL3MemHandler();
61   
62   void Reset(){CloseBinaryInput();CloseBinaryOutput();Free();}  
63   void Init(Int_t s,Int_t p,const Int_t* row){fSlice=s;fPatch=p;fRowMin=row[0];fRowMax=row[1]; ResetROI();}
64
65   Bool_t SetBinaryInput(char *name);
66   Bool_t SetBinaryInput(FILE *file);
67   void CloseBinaryInput();
68   
69   Bool_t SetBinaryOutput(char *name);
70   Bool_t SetBinaryOutput(FILE *file);
71   void CloseBinaryOutput();
72
73   //Random cluster
74   void SetRandomCluster(Int_t maxnumber);
75   void SetRandomSeed(UInt_t seed){srand(seed);}
76   void SetRandomSeed();
77
78   void ResetRandom(){fNDigits = 0; fNUsed = 0;}
79   void Generate(Int_t row);
80   void SetNGenerate(Int_t number){(number>fNRandom)?fNGenerate=fNRandom:fNGenerate = number;}
81
82   void SetROI(Float_t *eta,Int_t *slice);
83   void ResetROI();
84
85   //Digit IO
86   Bool_t Memory2Binary(UInt_t nrow,AliL3DigitRowData *data);
87   Bool_t Binary2Memory(UInt_t & nrow,AliL3DigitRowData *data);
88
89   Int_t Memory2CompMemory(UInt_t nrow,AliL3DigitRowData *data,UInt_t *comp);
90   Int_t CompMemory2Memory(UInt_t nrow,AliL3DigitRowData *data,UInt_t *comp);
91   Bool_t CompMemory2CompBinary(UInt_t nrow,UInt_t *comp, UInt_t size=0);
92   Bool_t CompBinary2CompMemory(UInt_t & nrow,UInt_t *comp);
93
94   virtual AliL3DigitRowData *CompBinary2Memory(UInt_t & nrow);
95   virtual Bool_t Memory2CompBinary(UInt_t nrow,AliL3DigitRowData *data);
96   
97   UInt_t GetNRow(UInt_t *comp,UInt_t size);
98
99   //Point IO
100   Bool_t Memory2Binary(UInt_t npoint,AliL3SpacePointData *data);
101   Bool_t Binary2Memory(UInt_t & npoint,AliL3SpacePointData *data);
102   Bool_t Transform(UInt_t npoint,AliL3SpacePointData *data,Int_t slice);
103   static void UpdateRowPointer(AliL3DigitRowData *&tempPt);
104   
105   //Track IO
106   Bool_t Memory2Binary(UInt_t ntrack,AliL3TrackSegmentData *data);
107   Bool_t Binary2Memory(UInt_t & ntrack,AliL3TrackSegmentData *data);
108   Bool_t TrackArray2Binary(AliL3TrackArray *array);
109   Bool_t Binary2TrackArray(AliL3TrackArray *array);
110   Bool_t TrackArray2Memory(UInt_t & ntrack,AliL3TrackSegmentData *data,
111                                              AliL3TrackArray *array);
112   Bool_t Memory2TrackArray(UInt_t ntrack,AliL3TrackSegmentData *data,
113                                              AliL3TrackArray *array);
114   Bool_t Memory2TrackArray(UInt_t ntrack,AliL3TrackSegmentData *data,
115                            AliL3TrackArray *array,Int_t slice);
116   
117   
118   //Memory Allocation
119   UInt_t GetAllocatedSize(){return fSize;}  
120   UInt_t GetFileSize();
121   UInt_t GetMemorySize(UInt_t nrow,UInt_t *comp);
122   UInt_t GetCompMemorySize(UInt_t nrow,AliL3DigitRowData *data);
123   UInt_t GetRandomSize();
124
125   Byte_t *Allocate(UInt_t size);
126   Byte_t *Allocate();  // allocate size of Binary Input File
127   Byte_t *Allocate(AliL3TrackArray *array);
128   Byte_t *GetDataPointer(UInt_t &size) {size = fSize; return fPt;}
129   void   Free();
130   
131   ClassDef(AliL3MemHandler,1) // Memory handler class
132 };
133
134 inline Int_t  AliL3MemHandler::ComparePoints(UInt_t row,UShort_t pad,UShort_t time){
135   if(fNUsed>=fNDigits) return -2;
136
137   if(pad==fDPt[fNUsed]->fPad&&time==fDPt[fNUsed]->fTime) return 0;
138
139   if(pad<fDPt[fNUsed]->fPad) return -1;
140   if(pad==fDPt[fNUsed]->fPad&&time<fDPt[fNUsed]->fTime)  return -1;
141
142   return 1;
143 }
144
145 inline Int_t AliL3MemHandler::CompareDigits(AliL3RandomDigitData *a,AliL3RandomDigitData *b){
146   if(a->fPad==b->fPad && a->fTime == b->fTime) return 0;
147
148   if(a->fPad<b->fPad) return -1;
149   if(a->fPad==b->fPad && a->fTime<b->fTime) return -1;
150   
151   return 1;
152 }
153
154 #endif