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