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