]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/Alieve/TPCSectorData.h
Merge from EVE-dev.
[u/mrichter/AliRoot.git] / EVE / Alieve / TPCSectorData.h
1 // $Header$
2
3 #ifndef ALIEVE_TPCSectorData_H
4 #define ALIEVE_TPCSectorData_H
5
6 #include <Reve/Reve.h>
7
8 #include <TObject.h>
9
10 #include <vector>
11
12 class AliTPCParam;
13
14 namespace Alieve {
15
16 class TPCSectorData : public TObject
17 {
18 public:
19
20   class PadData
21   {
22   protected:
23     Short_t* fData;
24     Short_t  fLength;
25
26   public:
27     PadData(Short_t* d=0, Short_t l=0) : fData(d), fLength(l) {}
28
29     Short_t* Data()   const { return fData; }
30     Short_t  Length() const { return fLength; }
31
32     void SetDataLength(Short_t* d, Short_t l) { fData = d; fLength = l; }
33
34     void Print(Option_t* opt="");
35   };
36
37   class PadIterator
38   {
39   protected:
40     Short_t *fBeg, *fEnd, *fPos;
41     Short_t  fTime, fSignal;
42     Short_t  fThreshold;
43     Short_t  fNChunk;
44
45   public:
46     PadIterator(const PadData& pd, Short_t thr=0) :
47       fBeg(pd.Data()), fEnd(pd.Data() + pd.Length()), fPos(pd.Data()),
48       fTime(-1), fSignal(-1), fThreshold(thr), fNChunk(0)
49     {}
50
51     Bool_t Next();
52     void   Reset();
53     void   Reset(const PadData& pd);
54
55     Short_t Time()   const { return fTime; }
56     Short_t Signal() const { return fSignal; }
57
58     Short_t Threshold()    const { return fThreshold; }
59     void SetThreshold(Short_t t) { fThreshold = t; }
60
61     void Test();
62   };
63
64   class RowIterator : public PadIterator
65   {
66   protected:
67     const PadData* fPadArray;
68     Short_t fNPads;
69     Short_t fPad;
70
71   public:
72     RowIterator(const PadData* first, Short_t npads, Short_t thr=0) :
73       PadIterator(*first, thr),
74       fPadArray(first), fNPads(npads),
75       fPad(-1)
76     {}
77
78     Bool_t NextPad();
79     void   ResetRow();
80     void   ResetRow(const PadData* first, Short_t npads);
81     
82     Short_t Pad() const { return fPad; }
83
84     void Test();
85   };
86
87   class SegmentInfo : public TObject
88   {
89     friend class TPCSectorData;
90
91   private:
92     Float_t   fPadWidth;
93     Float_t   fPadHeight;
94     Float_t   fRLow;      // Radius at the bottom of first row
95     Int_t     fNRows;     // Number of rows in this segment
96     Int_t     fFirstRow;  // First row index within sector
97     Int_t     fLastRow;   // Last row index within sector
98     Int_t     fNMaxPads;  // Maximum number of pads in a row
99     Int_t     fNYSteps;   // Number of steps in pad-count
100     Float_t   fYStep[64]; // Y coords where pad-count changes
101
102   public:
103     SegmentInfo();
104
105     Float_t GetPadWidth()  const { return fPadWidth; }
106     Float_t GetPadHeight() const { return fPadHeight; }
107     Float_t GetRLow()      const { return fRLow; }
108     Int_t   GetNRows()     const { return fNRows; }
109     Int_t   GetFirstRow()  const { return fFirstRow; }
110     Int_t   GetLastRow()   const { return fLastRow; }
111     Int_t   GetNMaxPads()  const { return fNMaxPads; }
112     Int_t   GetNYSteps()   const { return fNYSteps; }
113     Float_t GetYStep(Int_t step) const { return fYStep[step]; }
114
115     ClassDef(SegmentInfo, 0);
116   };
117
118 private:
119   static AliTPCParam *fgParam;
120   static Float_t      fgZLength;
121   static Int_t        fgNAllRows;
122   static Int_t        fgNAllPads;
123   static Int_t       *fgRowBegs;
124
125   static SegmentInfo  fgInnSeg;
126   static SegmentInfo  fgOut1Seg;
127   static SegmentInfo  fgOut2Seg;
128
129   static SegmentInfo* fgSegInfoPtrs[3];
130
131 protected:
132   Int_t                 fSectorID;
133   Int_t                 fNPadsFilled;
134   std::vector<PadData>  fPads;
135
136   // Blocks of pad-data.
137   const Int_t           fBlockSize;
138   Int_t                 fBlockPos;
139   std::vector<Short_t*> fBlocks;
140
141   void NewBlock();
142
143   // Intermediate buffer/vars for pad-data.
144   Short_t fPadBuffer[2048];
145   Int_t   fCurrentRow, fCurrentPad, fCurrentPos, fCurrentStep;
146
147   Int_t PadIndex(Int_t row, Int_t pad) { return fgRowBegs[row] + pad; }
148
149 public:
150   TPCSectorData(Int_t sector, Int_t bsize=65536);
151   virtual ~TPCSectorData();
152
153   void DropData();
154
155   virtual void Print(Option_t* opt="") const;
156
157   void BeginPad(Int_t row, Int_t pad, Bool_t reverseTime=kFALSE);
158   void RegisterData(Short_t time, Short_t signal);
159   void EndPad(Bool_t autoPedestal=kFALSE, Short_t threshold=0);
160
161   const PadData& GetPadData(Int_t padAddr);
162   const PadData& GetPadData(Int_t row, Int_t pad);
163
164   PadIterator MakePadIterator(Int_t padAddr, Short_t thr=0);
165   PadIterator MakePadIterator(Int_t row, Int_t pad, Short_t thr=0);
166
167   RowIterator MakeRowIterator(Int_t row, Short_t thr=0);
168
169   // --- Static functions
170
171   static const AliTPCParam& GetParam() { return *fgParam; }
172   static Float_t GetZLength()  { return fgZLength;  }
173   static Int_t   GetNAllRows() { return fgNAllRows; }
174   static Int_t   GetNAllPads() { return fgNAllPads; }
175
176   static Int_t GetNPadsInRow(Int_t row);
177
178   static const SegmentInfo& GetInnSeg()  { return fgInnSeg;  }
179   static const SegmentInfo& GetOut1Seg() { return fgOut1Seg; }
180   static const SegmentInfo& GetOut2Seg() { return fgOut2Seg; }
181
182   static const SegmentInfo& GetSeg(Int_t seg);
183   
184   static void InitStatics();
185
186
187   //----------------------------------------------------------------
188   // Hack for noisy pad-row removal
189   //----------------------------------------------------------------
190
191   class PadRowHack
192   {
193   public:
194     Int_t   fRow, fPad;
195     Int_t   fThrExt;
196     Float_t fThrFac; // Actual threshold = fThrExt + fThrFac*thr
197
198     PadRowHack(Int_t r, Int_t p, Int_t te=0, Float_t tf=1) :
199       fRow(r), fPad(p), fThrExt(te), fThrFac(tf) {}
200     bool operator<(const PadRowHack& a) const
201     { return (fRow == a.fRow) ? fPad < a.fPad : fRow < a.fRow; }
202   };
203
204   PadRowHack* GetPadRowHack(Int_t r, Int_t p);
205   void AddPadRowHack(Int_t r, Int_t p, Int_t te=0, Float_t tf=1);
206   void RemovePadRowHack(Int_t r, Int_t p);
207   void DeletePadRowHack();
208
209 protected:
210   void* fPadRowHackSet;
211   
212
213   ClassDef(TPCSectorData, 0);
214 }; // endclass TPCSectorData
215
216
217 inline void TPCSectorData::RegisterData(Short_t time, Short_t signal)
218 {
219   fPadBuffer[fCurrentPos]   = time;
220   fPadBuffer[fCurrentPos+1] = signal;
221   fCurrentPos += fCurrentStep;
222 }
223
224 }
225
226 #endif