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