3 /* Copyright(c) 1998-2000, ALICE Experiment at CERN, All rights
6 * See cxx source for full Copyright notice
13 //____________________________________________________________________
15 @brief Base class for caches of per-strip information.
17 This is used to index a strip. Data stored depends on derived
19 class AliFMDMap : public TObject
23 /** Default maximum detector number */
25 /** Default maximum number of rings */
27 /** Default maximum number of sectors */
29 /** Default maximum number of strips */
33 /** Number used for inner rings */
35 /** Number used for outer rings */
39 /** Number of strips in outer rings */
41 /** Number of strips in the inner rings */
45 /** Number of sectors in the inner rings */
47 /** Number of sectorts in the outer rings */
51 /** Base index for inner rings */
53 /** Base index for outer rings */
54 kBaseOuter = kNSectorInner * kNStripInner
57 /** Base for FMD1 index */
59 /** Base for FMD2 index */
60 kFMD2Base = kNSectorInner * kNStripInner,
61 /** Base for FMD3 index */
62 kFMD3Base = (kBaseOuter + kNSectorOuter * kNStripOuter + kFMD2Base)
65 * Class to do stuff on each element of a map in an efficient
74 * Called for each element considered a floating point number
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)
82 * @return Should return @c true on success, @c false otherwise
84 virtual Bool_t operator()(UShort_t d, Char_t r, UShort_t s, UShort_t t,
87 * Called for each element considered an integer
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)
95 * @return Should return @c true on success, @c false otherwise
97 virtual Bool_t operator()(UShort_t d, Char_t r, UShort_t s, UShort_t t,
100 * Called for each element considered an integer
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)
108 * @return Should return @c true on success, @c false otherwise
110 virtual Bool_t operator()(UShort_t d, Char_t r, UShort_t s, UShort_t t,
113 * Called for each element considered an integer
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)
121 * @return Should return @c true on success, @c false otherwise
123 virtual Bool_t operator()(UShort_t d, Char_t r, UShort_t s, UShort_t t,
127 * Class to print content of map
130 class Printer : public ForOne
136 * @param format Output format (argument to printf)
138 Printer(const char* format);
142 virtual ~Printer() {}
144 * Print a floating point entry
148 Bool_t operator()(UShort_t d, Char_t r, UShort_t s, UShort_t t, Float_t m);
150 * Print a integer entry
154 Bool_t operator()(UShort_t d, Char_t r, UShort_t s, UShort_t t, Int_t m);
156 * Print a integer entry
160 Bool_t operator()(UShort_t d, Char_t r, UShort_t s, UShort_t t, UShort_t m);
162 * Print a boolean entry
166 Bool_t operator()(UShort_t d, Char_t r, UShort_t s, UShort_t t, Bool_t m);
171 * @param p Object to copy from
173 Printer(const Printer& p);
175 * Assignment operator
177 * @return Reference to this
179 Printer& operator=(const Printer&) { return *this; }
183 * @param d Current detector
184 * @param r Current ring
185 * @param s Current sector
186 * @param t Current strip
188 virtual void PrintHeadings(UShort_t d, Char_t r, UShort_t s, UShort_t t);
189 /** Printf like format */
202 * @param maxDet Maximum allowed detector number
203 * @param maxRing Maximum number of rings
204 * @param maxSec Maximum number of sectors
205 * @param maxStr Maximum number of strips
207 AliFMDMap(UShort_t maxDet = 0,
210 UShort_t maxStr = 0);
214 * @param other Object to construct from
216 AliFMDMap(const AliFMDMap& other);
218 virtual ~AliFMDMap() {}
219 /** @return Maximum detector number */
220 UShort_t MaxDetectors() const { return fMaxDetectors==0 ? 3 :fMaxDetectors;}
221 /** @return Maximum number of rings */
222 UShort_t MaxRings() const { return fMaxRings ==0 ? 2 :fMaxRings; }
223 /** @return Maximum number of sectors */
224 UShort_t MaxSectors() const { return fMaxSectors ==0 ? 40 :fMaxSectors; }
225 /** @return Maximum number of strip */
226 UShort_t MaxStrips() const { return fMaxStrips ==0 ? 512 :fMaxStrips; }
228 * Calculate the detector coordinates for a given index number
230 * @param idx Index to find cooresponding detector coordinates for
231 * @param det On return, contain the detector number
232 * @param ring On return, contain the ring identifier
233 * @param sec On return, contain the sector number
234 * @param str On return, contain the strip number
236 void CalcCoords(Int_t idx,
240 UShort_t& str) const;
242 * Calculate index and return
244 * @param det Detector number
245 * @param ring Ring identifier
246 * @param sec Sector number
247 * @param str Strip number
249 * @return Index (not checked)
251 Int_t CalcIndex(UShort_t det, Char_t ring,
252 UShort_t sec, UShort_t str) const;
254 * Calculate index and return
256 * @param det Detector number
257 * @param ring Ring identifier
258 * @param sec Sector number
259 * @param str Strip number
261 * @return Index or -1 if the coordinates are invalid
263 Int_t CheckIndex(UShort_t det, Char_t ring,
264 UShort_t sec, UShort_t str) const;
266 * Check if we need UShort_t hack
268 * @param file File this object was read from
270 void CheckNeedUShort(TFile* file);
272 * Right multiplication operator
274 * @param o Other map to multuiply with
276 * @return Reference to this object
278 AliFMDMap& operator*=(const AliFMDMap& o);
280 * Right division operator
282 * @param o Other map to divide with
284 * @return Reference to this object
286 AliFMDMap& operator/=(const AliFMDMap& o);
288 * Right addision operator
290 * @param o Other map to add to this
292 * @return Reference to this object
294 AliFMDMap& operator+=(const AliFMDMap& o);
296 * Right subtraction operator
298 * @param o Other map to substract from this
300 * @return Reference to this object
302 AliFMDMap& operator-=(const AliFMDMap& o);
304 * For each element of the map, call the user defined overloaded
305 * @c ForOne::operator()
307 * @param algo Algorithm to use
309 * @return @c true on success, @c false if for any element, @c
310 * algo(d,r,s,t,v) returns false.
312 virtual Bool_t ForEach(ForOne& algo) const;
314 * Get the total size of the internal array - that is the maximum
315 * index possible plus one.
317 * @return maximum index, plus 1
319 virtual Int_t MaxIndex() const = 0;
321 * Print content of the map
323 * @param option If not null or empty string, print map
325 virtual void Print(Option_t* option="") const;
327 * Virtal function to get the value at index @a idx as a floating
331 * Even if the map is not floating point valued the
332 * sub-class can define this member function to allow non l-value
333 * usage of the data in the map. That is, if @c a is a floating
334 * point valued map, and @c b is not, then if the class @c B of @c b
335 * implements this member function, expression like
341 * multiplies each element of @c a (floating points) with each
342 * element of @c c according to the definition of @c B::AtAsFloat
343 * (@c const version).
345 * @param idx Index number
347 * @return Value at index as a floating point number
349 virtual Float_t AtAsFloat(Int_t idx) const;
351 * Virtal function to get the value at index @a idx as a floating
354 * This member function should only be defined if the map is a
355 * floating point valued, and can be assigned floating point valued
356 * values. That is, if the map's elements are anything but @c
357 * float then this member function should not be defined in the
358 * derived class. That will prevent expressions like
364 * where @c a is non-floating point valued, and @c b is floating
365 * point valued (only).
367 * @param idx Index number
369 * @return Value at index as a floating point number
371 virtual Float_t& AtAsFloat(Int_t idx);
373 * Virtal function to get the value at index @a idx as an integer
375 * @see Float_t AliFMDMap::AtAsFloat(Int_t) const
377 * @param idx Index number
379 * @return Value at index as an integer
381 virtual Int_t AtAsInt(Int_t idx) const;
383 * Virtal function to get the value at index @a idx as an integer
385 * @see Float_t& AliFMDMap::AtAsFloat(Int_t)
387 * @param idx Index number
389 * @return Value at index as an integer
391 virtual Int_t& AtAsInt(Int_t idx);
393 * Virtal function to get the value at index @a idx as an boolean
395 * @see Float_t AliFMDMap::AtAsFloat(Int_t) const
397 * @param idx Index number
399 * @return Value at index as a boolean
401 virtual UShort_t AtAsUShort(Int_t idx) const;
403 * Virtal function to get the value at index @a idx as an boolean
405 * @see Float_t& AliFMDMap::AtAsFloat(Int_t)
407 * @param idx Index number
409 * @return Value at index as a boolean
411 virtual UShort_t& AtAsUShort(Int_t idx);
413 * Virtal function to get the value at index @a idx as an unsigned
416 * @see Float_t AliFMDMap::AtAsFloat(Int_t) const
418 * @param idx Index number
420 * @return Value at index as an unsigned short integer
422 virtual Bool_t AtAsBool(Int_t idx) const;
424 * Virtal function to get the value at index @a idx as an unsigned
427 * @see Float_t& AliFMDMap::AtAsFloat(Int_t)
429 * @param idx Index number
431 * @return Value at index as an unsigned short integer
433 virtual Bool_t& AtAsBool(Int_t idx);
435 * Whether this map is floating point valued - that is, it can be
436 * assigned floating point valued values.
438 * @return @c true if the map is floating point valued
440 virtual Bool_t IsFloat() const { return kFALSE; }
442 * Whether this map is floating point valued or integer valued -
443 * that is, it can be assigned integer valued values
445 * @return @c true if the map is integer valued
447 virtual Bool_t IsInt() const { return kFALSE; }
449 * Whether this map is unsigned short integer valued - that is it
450 * can be assigned unsigned short integer values
452 * @return @c true if the map is unsigned short integer valued
454 virtual Bool_t IsUShort() const { return kFALSE; }
456 * Whether this map is boolean valued - that is it can be assigned
459 * @return @c true if the map is boolean valued
461 virtual Bool_t IsBool() const { return kFALSE; }
463 * Get raw data pointer.
465 * @return Raw data pointer
467 virtual void* Ptr() const = 0;
469 /** In case of version 2 of this class, this bit should be set. */
474 * Calculate, check, and return index for strip. If the index is
475 * invalid, -1 is returned
477 * This is only used when a full map is used, signalled by
480 * @param det Detector number
481 * @param ring Ring identifier
482 * @param sec Sector number
483 * @param str Strip number
485 * @return Unique index, or -1 in case of errors
487 Int_t Coords2Index(UShort_t det, Char_t ring,
488 UShort_t sec, UShort_t str) const;
490 * Calculate, check, and return index for strip. If the index is
491 * invalid, -1 is returned
493 * This is for back-ward compatibility and for when a map does not
494 * cover all of the FMD strips
496 * @param det Detector number
497 * @param ring Ring identifier
498 * @param sec Sector number
499 * @param str Strip number
501 * @return Unique index, or -1 in case of errors
503 Int_t Coords2IndexOld(UShort_t det, Char_t ring,
504 UShort_t sec, UShort_t str) const;
506 * Calculate the detector coordinates from an array index.
508 * This is used for backward compatibility and for when a map does not
509 * cover all of the FMD strips
511 * @param idx Index to convert
512 * @param det Detector number on return
513 * @param ring Ring identifier on return
514 * @param sec Sector number on return
515 * @param str Strip number on return
517 void Index2CoordsOld(Int_t idx,
521 UShort_t& str) const;
523 * Calculate the detector coordinates from an array index.
525 * This is used for a full map only, signalled by fMaxDetector = 0
527 * @param idx Index to convert
528 * @param det Detector number on return
529 * @param ring Ring identifier on return
530 * @param sec Sector number on return
531 * @param str Strip number on return
533 void Index2Coords(Int_t idx,
537 UShort_t& str) const;
538 UShort_t fMaxDetectors; // Maximum # of detectors
539 UShort_t fMaxRings; // Maximum # of rings
540 UShort_t fMaxSectors; // Maximum # of sectors
541 UShort_t fMaxStrips; // Maximum # of strips
543 ClassDef(AliFMDMap, 4) // Cache of per strip information
547 AliFMDMap::AtAsFloat(Int_t) const
552 AliFMDMap::AtAsFloat(Int_t)
558 AliFMDMap::AtAsInt(Int_t) const
563 AliFMDMap::AtAsInt(Int_t)
569 AliFMDMap::AtAsUShort(Int_t) const
574 AliFMDMap::AtAsUShort(Int_t)
580 AliFMDMap::AtAsBool(Int_t) const
585 AliFMDMap::AtAsBool(Int_t)
591 AliFMDMap::ForOne::operator()(UShort_t, Char_t, UShort_t, UShort_t, Float_t)
596 AliFMDMap::ForOne::operator()(UShort_t, Char_t, UShort_t, UShort_t, Int_t)
601 AliFMDMap::ForOne::operator()(UShort_t, Char_t, UShort_t, UShort_t, UShort_t)
606 AliFMDMap::ForOne::operator()(UShort_t, Char_t, UShort_t, UShort_t, Bool_t)
614 //____________________________________________________________________