]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/AliFMDMap.h
No field in shielding concrete.
[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 __VECTOR__
9 # include <vector>
10 #endif 
11
12 template <typename Type> 
13 class AliFMDMap : public TObject 
14 {
15 public:
16   AliFMDMap(size_t maxDet=3, size_t maxRing=2, size_t maxSec=40, 
17             size_t maxStr=512);
18   virtual ~AliFMDMap() {}
19   void Clear();
20   Type& operator()(size_t det, Char_t ring, size_t sec, size_t str);
21   const Type& operator()(size_t det, Char_t ring, size_t sec, size_t str)const;
22 private:
23   typedef std::vector<Type> ValueVector; // Type of container
24   ValueVector fValues;                   // Contained values
25   size_t      fMaxDetectors;             // Maximum # of detectors
26   size_t      fMaxRings;                 // Maximum # of rings
27   size_t      fMaxSectors;               // Maximum # of sectors
28   size_t      fMaxStrips;                // Maximum # of strips
29   
30   size_t CalcIndex(size_t det, Char_t ring, size_t sec, size_t str) const;
31   ClassDef(AliFMDMap, 0); // Map of FMD index's to values 
32 };
33
34
35 //____________________________________________________________________
36 template <typename Type>
37 inline 
38 AliFMDMap<Type>::AliFMDMap(size_t maxDet, 
39                            size_t maxRing, 
40                            size_t maxSec, 
41                            size_t maxStr)
42   : fValues(maxDet * maxRing * maxSec * maxStr), 
43     fMaxDetectors(maxDet), 
44     fMaxRings(maxRing), 
45     fMaxSectors(maxSec), 
46     fMaxStrips(maxStr)
47 {
48   // Construct a map
49   //
50   // Parameters:
51   //     maxDet       Maximum # of detectors
52   //     maxRinf      Maximum # of rings
53   //     maxSec       Maximum # of sectors
54   //     maxStr       Maximum # of strips
55 }
56
57
58 //____________________________________________________________________
59 template <typename Type>
60 inline size_t 
61 AliFMDMap<Type>::CalcIndex(size_t det, Char_t ring, size_t sec, size_t str) const
62 {
63   // Calculate index into storage from arguments. 
64   // 
65   // Parameters: 
66   //     det       Detector #
67   //     ring      Ring ID
68   //     sec       Sector # 
69   //     str       Strip # 
70   //
71   // Returns appropriate index into storage 
72   //
73   size_t ringi = (ring == 'I' ||  ring == 'i' ? 0 : 1);
74   size_t idx = 
75     (det + fMaxDetectors * (ringi + fMaxRings * (sec + fMaxSectors * str)));
76   if (idx >= fMaxDetectors * fMaxRings * fMaxSectors * fMaxStrips) {
77     Fatal("CalcIndex", "Index (%d,'%c',%d,%d) out of bounds, "
78           "in particular the %s index", 
79           det, ring, sec, str, 
80           (det >= fMaxDetectors ? "Detector" : 
81            (ringi >= fMaxRings ? "Ring" : 
82             (sec >= fMaxSectors ? "Sector" : "Strip"))));
83     return 0;
84   }
85   return idx;
86 }
87
88 //____________________________________________________________________
89 template <typename Type>
90 inline void
91 AliFMDMap<Type>::Clear() 
92 {
93   // Resets stored values to the default value for that type 
94   for (size_t i = 0; i < fValues.size(); ++i) fValues[i] = Type();
95 }
96
97 //____________________________________________________________________
98 template <typename Type>
99 inline Type& 
100 AliFMDMap<Type>::operator()(size_t det, Char_t ring, size_t sec, size_t str)
101 {
102   // Parameters: 
103   //     det       Detector #
104   //     ring      Ring ID
105   //     sec       Sector # 
106   //     str       Strip # 
107   //
108   // Returns data[det][ring][sec][str]
109   return fValues[CalcIndex(det, ring, sec, str)];
110 }
111
112 //____________________________________________________________________
113 template <typename Type>
114 inline const Type& 
115 AliFMDMap<Type>::operator()(size_t det, Char_t ring, size_t sec, size_t str)const
116 {
117   // Parameters: 
118   //     det       Detector #
119   //     ring      Ring ID
120   //     sec       Sector # 
121   //     str       Strip # 
122   //
123   // Returns data[det][ring][sec][str]
124   return fValues[CalcIndex(det, ring, sec, str)];
125 }
126
127
128
129 #endif 
130 //____________________________________________________________________
131 //
132 // Local Variables:
133 //   mode: C++
134 // End:
135 //
136 // EOF
137 //
138
139