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