]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliFMDMap.h
small fix
[u/mrichter/AliRoot.git] / STEER / AliFMDMap.h
1 #ifndef ALIFMDMAP_H
2 #define ALIFMDMAP_H
3 /* Copyright(c) 1998-2000, ALICE Experiment at CERN, All rights
4  * reserved. 
5  *
6  * See cxx source for full Copyright notice                               
7  */
8 #ifndef ROOT_TObject
9 # include <TObject.h>
10 #endif 
11 //____________________________________________________________________
12 //
13 // Base class for caches of per-strip information.
14 // This is used to index a strip. 
15 // Data stored depends on derived class. 
16 //
17 class AliFMDMap : public TObject 
18 {
19 public:
20   enum { 
21     kMaxDetectors = 3, 
22     kMaxRings     = 2, 
23     kMaxSectors   = 40, 
24     kMaxStrips    = 512
25   };
26   AliFMDMap(size_t maxDet = kMaxDetectors, 
27             size_t maxRing= kMaxRings, 
28             size_t maxSec = kMaxSectors, 
29             size_t maxStr = kMaxStrips);
30   virtual ~AliFMDMap() {}
31   size_t MaxDetectors() const { return fMaxDetectors; }
32   size_t MaxRings()     const { return fMaxRings; }
33   size_t MaxSectors()   const { return fMaxSectors; }
34   size_t MaxStrips()    const { return fMaxStrips; }
35   Int_t  CheckIndex(size_t det, Char_t ring, size_t sec, size_t str) const;
36 protected:
37   size_t CalcIndex(size_t det, Char_t ring, size_t sec, size_t str) const;
38   size_t fMaxDetectors;             // Maximum # of detectors
39   size_t fMaxRings;                 // Maximum # of rings
40   size_t fMaxSectors;               // Maximum # of sectors
41   size_t fMaxStrips;                // Maximum # of strips
42   ClassDef(AliFMDMap, 1) // Cache of per strip information
43 };
44
45 #ifdef  MAY_USE_TEMPLATES
46 #ifndef __VECTOR__
47 # include <vector>
48 #endif 
49 //____________________________________________________________________
50 //
51 // Class template for classes that cache per strip information.  
52 // Access to the data goes via 
53 //
54 //   Type& AliFMDMap<Type>::operator()(size_t detector,
55 //                                     Char_t ring, 
56 //                                     size_t sector,
57 //                                     size_t strip);
58 // 
59 // (as well as a const version of this member function). 
60 // The elements can be reset to the default value by calling 
61 // AliFMDMap<Type>::Clear().  This resets the values to `Type()'. 
62 //
63 template <typename Type> 
64 class AliFMDMap : public TObject 
65 {
66 public:
67   AliFMDMap(size_t maxDet=3, size_t maxRing=2, size_t maxSec=40, 
68             size_t maxStr=512);
69   virtual ~AliFMDMap() {}
70   void Clear(const Type& val=Type());
71   Type& operator()(size_t det, Char_t ring, size_t sec, size_t str);
72   const Type& operator()(size_t det, Char_t ring, size_t sec, size_t str)const;
73 private:
74   typedef std::vector<Type> ValueVector; // Type of container
75   ValueVector fValues;                   // Contained values
76   size_t      fMaxDetectors;             // Maximum # of detectors
77   size_t      fMaxRings;                 // Maximum # of rings
78   size_t      fMaxSectors;               // Maximum # of sectors
79   size_t      fMaxStrips;                // Maximum # of strips
80   
81   size_t CalcIndex(size_t det, Char_t ring, size_t sec, size_t str) const;
82   ClassDef(AliFMDMap, 0); // Map of FMD index's to values 
83 };
84
85
86 //____________________________________________________________________
87 template <typename Type>
88 inline 
89 AliFMDMap<Type>::AliFMDMap(size_t maxDet, 
90                            size_t maxRing, 
91                            size_t maxSec, 
92                            size_t maxStr)
93   : fValues(maxDet * maxRing * maxSec * maxStr), 
94     fMaxDetectors(maxDet), 
95     fMaxRings(maxRing), 
96     fMaxSectors(maxSec), 
97     fMaxStrips(maxStr)
98 {
99   // Construct a map
100   //
101   // Parameters:
102   //     maxDet       Maximum # of detectors
103   //     maxRinf      Maximum # of rings
104   //     maxSec       Maximum # of sectors
105   //     maxStr       Maximum # of strips
106 }
107
108
109 //____________________________________________________________________
110 template <typename Type>
111 inline size_t 
112 AliFMDMap<Type>::CalcIndex(size_t det, Char_t ring, size_t sec, size_t str) const
113 {
114   // Calculate index into storage from arguments. 
115   // 
116   // Parameters: 
117   //     det       Detector #
118   //     ring      Ring ID
119   //     sec       Sector # 
120   //     str       Strip # 
121   //
122   // Returns appropriate index into storage 
123   //
124   size_t ringi = (ring == 'I' ||  ring == 'i' ? 0 : 1);
125   size_t idx = 
126     (det + fMaxDetectors * (ringi + fMaxRings * (sec + fMaxSectors * str)));
127   if (idx >= fMaxDetectors * fMaxRings * fMaxSectors * fMaxStrips) {
128     Fatal("CalcIndex", "Index (%d,'%c',%d,%d) out of bounds, "
129           "in particular the %s index", 
130           det, ring, sec, str, 
131           (det >= fMaxDetectors ? "Detector" : 
132            (ringi >= fMaxRings ? "Ring" : 
133             (sec >= fMaxSectors ? "Sector" : "Strip"))));
134     return 0;
135   }
136   return idx;
137 }
138
139 //____________________________________________________________________
140 template <typename Type>
141 inline void
142 AliFMDMap<Type>::Clear(const Type& val) 
143 {
144   // Resets stored values to the default value for that type 
145   for (size_t i = 0; i < fValues.size(); ++i) fValues[i] = val;
146 }
147
148 //____________________________________________________________________
149 template <typename Type>
150 inline Type& 
151 AliFMDMap<Type>::operator()(size_t det, Char_t ring, size_t sec, size_t str)
152 {
153   // Parameters: 
154   //     det       Detector #
155   //     ring      Ring ID
156   //     sec       Sector # 
157   //     str       Strip # 
158   //
159   // Returns data[det][ring][sec][str]
160   return fValues[CalcIndex(det, ring, sec, str)];
161 }
162
163 //____________________________________________________________________
164 template <typename Type>
165 inline const Type& 
166 AliFMDMap<Type>::operator()(size_t det, 
167                             Char_t ring, 
168                             size_t sec, 
169                             size_t str) const
170 {
171   // Parameters: 
172   //     det       Detector #
173   //     ring      Ring ID
174   //     sec       Sector # 
175   //     str       Strip # 
176   //
177   // Returns data[det][ring][sec][str]
178   return fValues[CalcIndex(det, ring, sec, str)];
179 }
180
181
182 //____________________________________________________________________
183 // 
184 // Some specialisations 
185 //
186 typedef AliFMDMap<UShort_t> AliFMDAdcMap;
187 typedef AliFMDMap<std::pair<Float_t, UShort_t> > AliFMDEdepMap;
188
189 #endif
190 #endif 
191 //____________________________________________________________________
192 //
193 // Local Variables:
194 //   mode: C++
195 // End:
196 //
197 // EOF
198 //
199
200