]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDSignalIndex.h
Coding rules
[u/mrichter/AliRoot.git] / TRD / AliTRDSignalIndex.h
1 #ifndef AliTRDSIGNALINDEX_H
2 #define AliTRDSIGNALINDEX_H
3
4 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5  * See cxx source for full Copyright notice                               */
6
7 /* $Id$ */
8  
9 #include "TObject.h"
10
11 ////////////////////////////////////////////////////////////////////////////
12 //                                                                        //
13 //  General container for data from TRD detector segments                 //
14 //  Adapted from AliDigits, origin M.Ivanov                               //
15 //                                                                        //
16 //  Author:                                                               //
17 //    Mateusz Ploskon (ploskon@ikf.uni-frankfurt.de)                      //
18 //                                                                        //
19 ////////////////////////////////////////////////////////////////////////////
20
21 class AliTRDSignalIndex : public TObject
22 {
23
24  public:
25
26   AliTRDSignalIndex(); 
27   AliTRDSignalIndex(Int_t nrow, Int_t ncol,Int_t ntime);
28   AliTRDSignalIndex(const AliTRDSignalIndex &d);
29   virtual ~AliTRDSignalIndex();
30   AliTRDSignalIndex &operator=(const AliTRDSignalIndex &d); 
31
32   void     Copy(TObject &d) const;
33   void     Allocate(const Int_t nrow, const Int_t ncol, const Int_t ntime);
34
35   void     Reset();
36   void     ResetContentConditional(const Int_t nrow, const Int_t ncol, const Int_t ntime);
37   void     ResetContent();
38   void     ResetCounters();
39   void     ResetTbinCounter() { }
40
41   void     ResetArrays();
42
43   void     AddIndexRC(const Int_t row, const Int_t col);
44
45   // Get the next pad (row and column) and return kTRUE on success
46   Bool_t   NextRCIndex(Int_t &row, Int_t &col); 
47   // Get the next timebin of a pad (row and column) and return kTRUE on success
48   Bool_t   NextRCTbinIndex(Int_t &row, Int_t &col, Int_t &tbin); 
49   // Get the next active timebin and return kTRUE on success
50   Bool_t   NextTbinIndex(Int_t &tbin); 
51
52   Int_t    GetCurrentRow() const  { return fCurrRow; }
53   Int_t    GetCurrentCol() const  { return fCurrCol; }
54   Int_t    GetCurrentTbin() const { return fCurrTbin; }
55
56   Bool_t   IsBoolIndex(Int_t row, Int_t col) const {return fBoolIndex[row*fNcols+col];};
57   void     InitSortedIndex();
58
59   // Clear the array, actually destroy and recreate w/o allocating
60   void     ClearAll(); 
61   // Return kTRUE if array allocated and there is no need to call allocate
62   Bool_t   IsAllocated() const    { if (!fBoolIndex)    return kFALSE; 
63                                     if (fMaxLimit <= 0) return kFALSE; 
64                                     else                return kTRUE;}
65
66   void     SetSM(const Int_t ix)        { fSM      =    ix; }
67   void     SetStack(const Int_t ix)     { fStack   =    ix; }
68   void     SetLayer(const Int_t ix)     { fLayer   =    ix; }
69   void     SetDetNumber(const Int_t ix) { fDet     =    ix; }
70   
71   Int_t    GetDetNumber() const   { return fDet;      } // Get Det number
72   Int_t    GetLayer() const       { return fLayer;    } // Layer position of the chamber in TRD
73   Int_t    GetStack() const       { return fStack;    } // Stack position of the chamber in TRD
74   Int_t    GetSM() const          { return fSM;       } // Super module of the TRD
75   Short_t *GetArray() const       { return fSortedIndex; } // Get the array pointer for god knows what reason
76
77   Bool_t   HasEntry() const       { return fHasEntry; } // Return status if has an entry
78
79   Int_t    GetNrow() const        { return fNrows;    } // Get Nrows
80   Int_t    GetNcol() const        { return fNcols;    } // Get Ncols
81   Int_t    GetNtime() const       { return fNtbins;   } // Get Ntbins
82
83  private:
84
85   Int_t     fDet;                //  Detector number
86   Int_t     fLayer;              //  Layer position in the full TRD
87   Int_t     fStack;              //  Stack position in the full TRD
88   Int_t     fSM;                 //  Super module - position in the full TRD
89
90   Bool_t   *fBoolIndex;          //  
91   Short_t  *fSortedIndex;        //  
92   Int_t     fMaxLimit;           //  Max number of things in the array
93   Int_t     fPositionRC;         //  Position in the SortedIndex
94   Bool_t    fSortedWasInit;      //  Was SortedIndex initialized?
95
96   Int_t     fCurrRow;            //  Last Row read out of SortedIndex
97   Int_t     fCurrCol;            //  Last Col read out of SortedIndex
98   Int_t     fCurrTbin;           //  Last outgiven Tbin
99   
100   Int_t     fNrows;              //  Number of rows in the chamber
101   Int_t     fNcols;              //  Number of cols in the chamber
102   Int_t     fNtbins;             //  Number of tbins in the chamber
103
104   Bool_t    fHasEntry;           //  kTRUE flag if we have an entry 
105
106   ClassDef(AliTRDSignalIndex,2)  //  Data container for one TRD detector segment
107
108 };
109 #endif
110
111 /*
112 Comment from 22 Dec 2008
113
114 The structure of the Index was changed. Now no Tbin is saved anymore,
115 only RC combination are saved! (reasons see below)
116
117 For the readout, all tbins for a RC combination must be read out to find 
118 the time bin of signal > 0.
119
120 THE WRITING PROCEDURE:
121 AddIndexTBin is now obsolate, use AddIndexRC instead as AddIndexTBin will
122 be deleted in future.
123
124 example that gives exactely the same output as before:
125 as it was: 
126            AliTRDSignalIndexes *indexes;
127            AliTRDarrayADC *Signal; //or AliTRDarraySignal *Signal;
128            if(Signal->GetDataB(row, col, time)>0)
129                indexes->AddIndexTBin(row, col, time);
130
131 as it should be from no on: 
132            AliTRDSignalIndexes *indexes;
133            AliTRDarrayADC *Signal; //or AliTRDarraySignal *Signal;
134            if(Signal->GetDataB(row, col, time)>0)
135                indexes->AddIndexRC(row, col);
136
137
138
139 THE READING PROCEDURE:
140 In most cases you can leave anything as it is.
141 See more in the example.
142
143 example:
144 as it was: 
145            AliTRDSignalIndexes *indexes;
146            AliTRDarraySignal *Signal;
147            while(indexes->NextRCTbinIndex(row, col, time)) 
148            {...}
149
150 as it should be from no on to get the exactely the same output as before: 
151            AliTRDSignalIndexes *indexes;
152            AliTRDarraySignal *Signal;
153            while(indexes->NextRCTbinIndex(row, col, time)) 
154               if(Signal->GetData(row, col, time)>0)
155                  {...}
156
157 as it should be idealy:
158            AliTRDSignalIndexes *indexes;
159            AliTRDarraySignal *Signal;
160            for(time = 0; time < Ntime; time++)
161               while(indexes->NextRCIndex(row, col, time)) 
162                  if(Signal->GetData(row, col, time)>0)
163                     {...}
164
165
166 REASON OF THE CHANGES:
167
168 The array saved the information nicely, but it turned out that sorting 
169 the array by column would have many benefits.
170 I.e. it is crucial for fivePadClusters and it if much faster to allocate.
171 But the sorting is not fast if the tbin is also saved.
172 Moreover the tbin information was alsmost useless because, 
173 whenever an RC index existed, many of the possible tbins where used.
174
175 Theodor Rascanu
176
177 */