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