]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/Alieve/TPCSectorData.h
Merge from EVE-dev to HEAD.
[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 Int_t        fgNAllRows;
121   static Int_t        fgNAllPads;
122   static Int_t       *fgRowBegs;
123
124   static SegmentInfo  fgInnSeg;
125   static SegmentInfo  fgOut1Seg;
126   static SegmentInfo  fgOut2Seg;
127
128   static SegmentInfo* fgSegInfoPtrs[3];
129
130 protected:
131   Int_t                 fSectorID;
132   Int_t                 fNPadsFilled;
133   std::vector<PadData>  fPads;
134
135   // Blocks of pad-data.
136   const Int_t           fBlockSize;
137   Int_t                 fBlockPos;
138   std::vector<Short_t*> fBlocks;
139
140   void NewBlock();
141
142   // Intermediate buffer/vars for pad-data.
143   Short_t fPadBuffer[2048];
144   Int_t   fCurrentRow, fCurrentPad, fCurrentPos, fCurrentStep;
145
146   Int_t PadIndex(Int_t row, Int_t pad) { return fgRowBegs[row] + pad; }
147
148 public:
149   TPCSectorData(Int_t sector, Int_t bsize=65536);
150   virtual ~TPCSectorData();
151
152   void DropData();
153
154   virtual void Print(Option_t* opt="") const;
155
156   void BeginPad(Int_t row, Int_t pad, Bool_t reverseTime=kFALSE);
157   void RegisterData(Short_t time, Short_t signal);
158   void EndPad(Bool_t autoPedestal=kFALSE, Short_t threshold=0);
159
160   const PadData& GetPadData(Int_t padAddr);
161   const PadData& GetPadData(Int_t row, Int_t pad);
162
163   PadIterator MakePadIterator(Int_t padAddr, Short_t thr=0);
164   PadIterator MakePadIterator(Int_t row, Int_t pad, Short_t thr=0);
165
166   RowIterator MakeRowIterator(Int_t row, Short_t thr=0);
167
168   // --- Static functions
169
170   static const AliTPCParam& GetParam() { return *fgParam; }
171   static Int_t GetNAllRows() { return fgNAllRows; }
172   static Int_t GetNAllPads() { return fgNAllPads; }
173
174   static Int_t GetNPadsInRow(Int_t row);
175
176   static const SegmentInfo& GetInnSeg()  { return fgInnSeg;  }
177   static const SegmentInfo& GetOut1Seg() { return fgOut1Seg; }
178   static const SegmentInfo& GetOut2Seg() { return fgOut2Seg; }
179
180   static const SegmentInfo& GetSeg(Int_t seg);
181   
182   static void InitStatics();
183
184   ClassDef(TPCSectorData, 0);
185 }; // endclass TPCSectorData
186
187
188 inline void TPCSectorData::RegisterData(Short_t time, Short_t signal)
189 {
190   fPadBuffer[fCurrentPos]   = time;
191   fPadBuffer[fCurrentPos+1] = signal;
192   fCurrentPos += fCurrentStep;
193 }
194
195 }
196
197 #endif