Improving event printout
[u/mrichter/AliRoot.git] / STEER / AliFMDMap.h
CommitLineData
9da38871 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
c05d076f 11class TFile;
12
9da38871 13//____________________________________________________________________
c05d076f 14/** @class AliFMDMap
15 @brief Base class for caches of per-strip information.
16 @ingroup FMD_data
17 This is used to index a strip. Data stored depends on derived
18 class. */
9da38871 19class AliFMDMap : public TObject
20{
21public:
22 enum {
c05d076f 23 /** Default maximum detector number */
9da38871 24 kMaxDetectors = 3,
c05d076f 25 /** Default maximum number of rings */
9da38871 26 kMaxRings = 2,
c05d076f 27 /** Default maximum number of sectors */
9da38871 28 kMaxSectors = 40,
c05d076f 29 /** Default maximum number of strips */
9da38871 30 kMaxStrips = 512
31 };
021f1396 32 enum {
33 /** Number used for inner rings */
34 kInner = 0,
35 /** Number used for outer rings */
36 kOuter
37 };
38 enum {
39 /** Number of strips in outer rings */
40 kNStripOuter = 256,
41 /** Number of strips in the inner rings */
42 kNStripInner = 512
43 };
44 enum {
45 /** Number of sectors in the inner rings */
46 kNSectorInner = 20,
47 /** Number of sectorts in the outer rings */
48 kNSectorOuter = 40
49 };
50 enum {
51 /** Base index for inner rings */
52 kBaseInner = 0,
53 /** Base index for outer rings */
54 kBaseOuter = kNSectorInner * kNStripInner
55 };
56 enum {
57 /** Base for FMD1 index */
58 kFMD1Base = 0,
59 /** Base for FMD2 index */
60 kFMD2Base = kNSectorInner * kNStripInner,
61 /** Base for FMD3 index */
62 kFMD3Base = (kBaseOuter + kNSectorOuter * kNStripOuter + kFMD2Base)
63 };
64 /**
65 * Class to do stuff on each element of a map in an efficient
66 * way.
67 */
68 class ForOne
69 {
70 public:
71 /** Destructor */
72 virtual ~ForOne() { }
73 /**
74 * Called for each element considered a floating point number
75 *
76 * @param d Detector number
77 * @param r Ring identifier
78 * @param s Sector number
79 * @param t Strip number
80 * @param v Value (as a floating point number)
81 *
82 * @return Should return @c true on success, @c false otherwise
83 */
84 virtual Bool_t operator()(UShort_t d, Char_t r, UShort_t s, UShort_t t,
85 Float_t v);
86 /**
87 * Called for each element considered an integer
88 *
89 * @param d Detector number
90 * @param r Ring identifier
91 * @param s Sector number
92 * @param t Strip number
93 * @param v Value (as an integer)
94 *
95 * @return Should return @c true on success, @c false otherwise
96 */
97 virtual Bool_t operator()(UShort_t d, Char_t r, UShort_t s, UShort_t t,
98 Int_t v);
99 /**
100 * Called for each element considered an integer
101 *
102 * @param d Detector number
103 * @param r Ring identifier
104 * @param s Sector number
105 * @param t Strip number
106 * @param v Value (as an unsigned short integer)
107 *
108 * @return Should return @c true on success, @c false otherwise
109 */
110 virtual Bool_t operator()(UShort_t d, Char_t r, UShort_t s, UShort_t t,
111 UShort_t v);
112 /**
113 * Called for each element considered an integer
114 *
115 * @param d Detector number
116 * @param r Ring identifier
117 * @param s Sector number
118 * @param t Strip number
119 * @param v Value (as a boolean)
120 *
121 * @return Should return @c true on success, @c false otherwise
122 */
123 virtual Bool_t operator()(UShort_t d, Char_t r, UShort_t s, UShort_t t,
124 Bool_t v);
125 };
126
127 /**
128 * Constructor
129 *
130 * @param maxDet Maximum allowed detector number
131 * @param maxRing Maximum number of rings
132 * @param maxSec Maximum number of sectors
133 * @param maxStr Maximum number of strips
134 */
135 AliFMDMap(UShort_t maxDet = 0,
136 UShort_t maxRing= 0,
137 UShort_t maxSec = 0,
138 UShort_t maxStr = 0);
139 /**
140 * Copy constructor
141 *
142 * @param other Object to construct from
143 */
144 AliFMDMap(const AliFMDMap& other);
c05d076f 145 /** Destructor */
9da38871 146 virtual ~AliFMDMap() {}
c05d076f 147 /** @return Maximum detector number */
021f1396 148 UShort_t MaxDetectors() const { return fMaxDetectors==0 ? 3 :fMaxDetectors;}
c05d076f 149 /** @return Maximum number of rings */
021f1396 150 UShort_t MaxRings() const { return fMaxRings ==0 ? 2 :fMaxRings; }
c05d076f 151 /** @return Maximum number of sectors */
021f1396 152 UShort_t MaxSectors() const { return fMaxSectors ==0 ? 40 :fMaxSectors; }
c05d076f 153 /** @return Maximum number of strip */
021f1396 154 UShort_t MaxStrips() const { return fMaxStrips ==0 ? 512 :fMaxStrips; }
155 /**
156 * Calculate the detector coordinates for a given index number
157 *
158 * @param idx Index to find cooresponding detector coordinates for
159 * @param det On return, contain the detector number
160 * @param ring On return, contain the ring identifier
161 * @param sec On return, contain the sector number
162 * @param str On return, contain the strip number
163 */
164 void CalcCoords(Int_t idx,
165 UShort_t& det,
166 Char_t& ring,
167 UShort_t& sec,
168 UShort_t& str) const;
169 /**
170 * Calculate index and return
171 *
172 * @param det Detector number
173 * @param ring Ring identifier
174 * @param sec Sector number
175 * @param str Strip number
176 *
177 * @return Index (not checked)
178 */
179 Int_t CalcIndex(UShort_t det, Char_t ring,
180 UShort_t sec, UShort_t str) const;
181 /**
182 * Calculate index and return
183 *
184 * @param det Detector number
185 * @param ring Ring identifier
186 * @param sec Sector number
187 * @param str Strip number
188 *
189 * @return Index or -1 if the coordinates are invalid
190 */
9eeb02aa 191 Int_t CheckIndex(UShort_t det, Char_t ring,
192 UShort_t sec, UShort_t str) const;
021f1396 193 /**
194 * Check if we need UShort_t hack
195 *
196 * @param file File this object was read from
197 */
c05d076f 198 void CheckNeedUShort(TFile* file);
021f1396 199 /**
200 * Right multiplication operator
201 *
202 * @param o Other map to multuiply with
203 *
204 * @return Reference to this object
205 */
206 AliFMDMap& operator*=(const AliFMDMap& o);
207 /**
208 * Right division operator
209 *
210 * @param o Other map to divide with
211 *
212 * @return Reference to this object
213 */
214 AliFMDMap& operator/=(const AliFMDMap& o);
215 /**
216 * Right addision operator
217 *
218 * @param o Other map to add to this
219 *
220 * @return Reference to this object
221 */
222 AliFMDMap& operator+=(const AliFMDMap& o);
223 /**
224 * Right subtraction operator
225 *
226 * @param o Other map to substract from this
227 *
228 * @return Reference to this object
229 */
230 AliFMDMap& operator-=(const AliFMDMap& o);
231 /**
232 * For each element of the map, call the user defined overloaded
233 * @c ForOne::operator()
234 *
235 * @param algo Algorithm to use
236 *
237 * @return @c true on success, @c false if for any element, @c
238 * algo(d,r,s,t,v) returns false.
239 */
240 virtual Bool_t ForEach(ForOne& algo) const;
241 /**
242 * Get the total size of the internal array - that is the maximum
243 * index possible plus one.
244 *
245 * @return maximum index, plus 1
246 */
247 virtual Int_t MaxIndex() const = 0;
248 /**
249 * Virtal function to get the value at index @a idx as a floating
250 * point number.
251 *
252 * @note
253 * Even if the map is not floating point valued the
254 * sub-class can define this member function to allow non l-value
255 * usage of the data in the map. That is, if @c a is a floating
256 * point valued map, and @c b is not, then if the class @c B of @c b
257 * implements this member function, expression like
258 *
259 * @verbatim
260 * a += b;
261 * @endverbatim
262 *
263 * multiplies each element of @c a (floating points) with each
264 * element of @c c according to the definition of @c B::AtAsFloat
265 * (@c const version).
266 *
267 * @param idx Index number
268 *
269 * @return Value at index as a floating point number
270 */
271 virtual Float_t AtAsFloat(Int_t idx) const;
272 /**
273 * Virtal function to get the value at index @a idx as a floating
274 * point number.
275 *
276 * This member function should only be defined if the map is a
277 * floating point valued, and can be assigned floating point valued
278 * values. That is, if the map's elements are anything but @c
279 * float then this member function should not be defined in the
280 * derived class. That will prevent expressions like
281 *
282 * @code
283 * a += b;
284 * @endcode
285 *
286 * where @c a is non-floating point valued, and @c b is floating
287 * point valued (only).
288 *
289 * @param idx Index number
290 *
291 * @return Value at index as a floating point number
292 */
293 virtual Float_t& AtAsFloat(Int_t idx);
294 /**
295 * Virtal function to get the value at index @a idx as an integer
296 *
297 * @see Float_t AliFMDMap::AtAsFloat(Int_t) const
298 *
299 * @param idx Index number
300 *
301 * @return Value at index as an integer
302 */
303 virtual Int_t AtAsInt(Int_t idx) const;
304 /**
305 * Virtal function to get the value at index @a idx as an integer
306 *
307 * @see Float_t& AliFMDMap::AtAsFloat(Int_t)
308 *
309 * @param idx Index number
310 *
311 * @return Value at index as an integer
312 */
313 virtual Int_t& AtAsInt(Int_t idx);
314 /**
315 * Virtal function to get the value at index @a idx as an boolean
316 *
317 * @see Float_t AliFMDMap::AtAsFloat(Int_t) const
318 *
319 * @param idx Index number
320 *
321 * @return Value at index as a boolean
322 */
323 virtual UShort_t AtAsUShort(Int_t idx) const;
324 /**
325 * Virtal function to get the value at index @a idx as an boolean
326 *
327 * @see Float_t& AliFMDMap::AtAsFloat(Int_t)
328 *
329 * @param idx Index number
330 *
331 * @return Value at index as a boolean
332 */
333 virtual UShort_t& AtAsUShort(Int_t idx);
334 /**
335 * Virtal function to get the value at index @a idx as an unsigned
336 * short integer
337 *
338 * @see Float_t AliFMDMap::AtAsFloat(Int_t) const
339 *
340 * @param idx Index number
341 *
342 * @return Value at index as an unsigned short integer
343 */
344 virtual Bool_t AtAsBool(Int_t idx) const;
345 /**
346 * Virtal function to get the value at index @a idx as an unsigned
347 * short integer
348 *
349 * @see Float_t& AliFMDMap::AtAsFloat(Int_t)
350 *
351 * @param idx Index number
352 *
353 * @return Value at index as an unsigned short integer
354 */
355 virtual Bool_t& AtAsBool(Int_t idx);
356 /**
357 * Whether this map is floating point valued - that is, it can be
358 * assigned floating point valued values.
359 *
360 * @return @c true if the map is floating point valued
361 */
362 virtual Bool_t IsFloat() const { return kFALSE; }
363 /**
364 * Whether this map is floating point valued or integer valued -
365 * that is, it can be assigned integer valued values
366 *
367 * @return @c true if the map is integer valued
368 */
369 virtual Bool_t IsInt() const { return kFALSE; }
370 /**
371 * Whether this map is unsigned short integer valued - that is it
372 * can be assigned unsigned short integer values
373 *
374 * @return @c true if the map is unsigned short integer valued
375 */
376 virtual Bool_t IsUShort() const { return kFALSE; }
377 /**
378 * Whether this map is boolean valued - that is it can be assigned
379 * boolean values
380 *
381 * @return @c true if the map is boolean valued
382 */
383 virtual Bool_t IsBool() const { return kFALSE; }
384
c05d076f 385 enum {
386 /** In case of version 2 of this class, this bit should be set. */
387 kNeedUShort = 14
388 };
9da38871 389protected:
021f1396 390 /**
391 * Calculate, check, and return index for strip. If the index is
392 * invalid, -1 is returned
393 *
394 * This is only used when a full map is used, signalled by
395 * fMaxDetector = 0
396 *
397 * @param det Detector number
398 * @param ring Ring identifier
399 * @param sec Sector number
400 * @param str Strip number
401 *
402 * @return Unique index, or -1 in case of errors
403 */
404 Int_t Coords2Index(UShort_t det, Char_t ring,
c05d076f 405 UShort_t sec, UShort_t str) const;
021f1396 406 /**
407 * Calculate, check, and return index for strip. If the index is
408 * invalid, -1 is returned
409 *
410 * This is for back-ward compatibility and for when a map does not
411 * cover all of the FMD strips
412 *
413 * @param det Detector number
414 * @param ring Ring identifier
415 * @param sec Sector number
416 * @param str Strip number
417 *
418 * @return Unique index, or -1 in case of errors
419 */
420 Int_t Coords2IndexOld(UShort_t det, Char_t ring,
421 UShort_t sec, UShort_t str) const;
422 /**
423 * Calculate the detector coordinates from an array index.
424 *
425 * This is used for backward compatibility and for when a map does not
426 * cover all of the FMD strips
427 *
428 * @param idx Index to convert
429 * @param det Detector number on return
430 * @param ring Ring identifier on return
431 * @param sec Sector number on return
432 * @param str Strip number on return
433 */
434 void Index2CoordsOld(Int_t idx,
435 UShort_t& det,
436 Char_t& ring,
437 UShort_t& sec,
438 UShort_t& str) const;
439 /**
440 * Calculate the detector coordinates from an array index.
441 *
442 * This is used for a full map only, signalled by fMaxDetector = 0
443 *
444 * @param idx Index to convert
445 * @param det Detector number on return
446 * @param ring Ring identifier on return
447 * @param sec Sector number on return
448 * @param str Strip number on return
449 */
450 void Index2Coords(Int_t idx,
451 UShort_t& det,
452 Char_t& ring,
453 UShort_t& sec,
454 UShort_t& str) const;
9eeb02aa 455 UShort_t fMaxDetectors; // Maximum # of detectors
456 UShort_t fMaxRings; // Maximum # of rings
457 UShort_t fMaxSectors; // Maximum # of sectors
458 UShort_t fMaxStrips; // Maximum # of strips
9da38871 459
021f1396 460 ClassDef(AliFMDMap, 4) // Cache of per strip information
9da38871 461};
462
021f1396 463inline Float_t
464AliFMDMap::AtAsFloat(Int_t) const
465{
466 return 0;
467}
468inline Float_t&
469AliFMDMap::AtAsFloat(Int_t)
470{
471 static Float_t d;
472 return d;
473}
474inline Int_t
475AliFMDMap::AtAsInt(Int_t) const
476{
477 return 0;
478}
479inline Int_t&
480AliFMDMap::AtAsInt(Int_t)
481{
482 static Int_t d;
483 return d;
484}
485inline UShort_t
486AliFMDMap::AtAsUShort(Int_t) const
487{
488 return 0;
489}
490inline UShort_t&
491AliFMDMap::AtAsUShort(Int_t)
492{
493 static UShort_t d;
494 return d;
495}
496inline Bool_t
497AliFMDMap::AtAsBool(Int_t) const
498{
499 return kFALSE;
500}
501inline Bool_t&
502AliFMDMap::AtAsBool(Int_t)
503{
504 static Bool_t d;
505 return d;
506}
507inline Bool_t
508AliFMDMap::ForOne::operator()(UShort_t, Char_t, UShort_t, UShort_t, Float_t)
509{
510 return kTRUE;
511}
512inline Bool_t
513AliFMDMap::ForOne::operator()(UShort_t, Char_t, UShort_t, UShort_t, Int_t)
514{
515 return kTRUE;
516}
517inline Bool_t
518AliFMDMap::ForOne::operator()(UShort_t, Char_t, UShort_t, UShort_t, UShort_t)
519{
520 return kTRUE;
521}
522inline Bool_t
523AliFMDMap::ForOne::operator()(UShort_t, Char_t, UShort_t, UShort_t, Bool_t)
524{
525 return kTRUE;
526}
527
528
529
9da38871 530#endif
531//____________________________________________________________________
532//
533// Local Variables:
534// mode: C++
535// End:
536//
537// EOF
538//
539
540