]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/ESD/AliFMDMap.h
Updates in event mixing code for low-pt code
[u/mrichter/AliRoot.git] / STEER / ESD / AliFMDMap.h
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 
11 class TFile;
12
13 //____________________________________________________________________
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.  */
19 class AliFMDMap : public TObject 
20 {
21 public:
22   enum { 
23     /** Default maximum detector number */
24     kMaxDetectors = 3, 
25     /** Default maximum number of rings */
26     kMaxRings     = 2, 
27     /** Default maximum number of sectors */
28     kMaxSectors   = 40, 
29     /** Default maximum number of strips */
30     kMaxStrips    = 512
31   };
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    * Class to print content of map 
128    * 
129    */
130   class Printer : public ForOne
131   {
132   public:
133     /** 
134      * Constructor 
135      * 
136      * @param format Output format (argument to printf)
137      */
138     Printer(const char* format);
139     /** 
140      * Destructor 
141      */
142     virtual ~Printer() {}
143     /** 
144      * Print a floating point entry
145      * 
146      * @return true
147      */
148     Bool_t operator()(UShort_t d, Char_t r, UShort_t s, UShort_t t, Float_t m);
149     /** 
150      * Print a integer entry
151      * 
152      * @return true
153      */
154     Bool_t operator()(UShort_t d, Char_t r, UShort_t s, UShort_t t, Int_t m);
155     /** 
156      * Print a integer entry
157      * 
158      * @return true
159      */
160     Bool_t operator()(UShort_t d, Char_t r, UShort_t s, UShort_t t, UShort_t m);
161     /** 
162      * Print a boolean entry
163      * 
164      * @return true
165      */
166     Bool_t operator()(UShort_t d, Char_t r, UShort_t s, UShort_t t, Bool_t m);
167   private:
168     /** 
169      * Copy constructor
170      * 
171      * @param p Object to copy from 
172      */
173     Printer(const Printer& p);
174     /** 
175      * Assignment operator
176      * 
177      * @return Reference to this 
178      */
179     Printer& operator=(const Printer&) { return *this; }
180     /** 
181      * Print headings 
182      * 
183      * @param d Current detector
184      * @param r Current ring 
185      * @param s Current sector
186      * @param t Current strip
187      */
188     virtual void PrintHeadings(UShort_t d, Char_t r, UShort_t s, UShort_t t);
189     /** Printf like format */
190     const char* fFormat;
191     /** Last detector */
192     UShort_t    fOldD;
193     /** Last ring */
194     Char_t      fOldR;
195     /** Last sector */
196     UShort_t    fOldS;
197   };
198
199   /** 
200    * Constructor 
201    * 
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
206    */
207   AliFMDMap(UShort_t maxDet = 0, 
208             UShort_t maxRing= 0, 
209             UShort_t maxSec = 0, 
210             UShort_t maxStr = 0);
211   /** 
212    * Copy constructor
213    * 
214    * @param other Object to construct from
215    */  
216   AliFMDMap(const AliFMDMap& other);
217   /** Destructor */
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; }
227   /** 
228    * Calculate the detector coordinates for a given index number
229    * 
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 
235    */
236   void CalcCoords(Int_t     idx, 
237                   UShort_t& det, 
238                   Char_t&   ring, 
239                   UShort_t& sec, 
240                   UShort_t& str) const;
241   /** 
242    * Calculate index and return 
243    *
244    * @param det  Detector number
245    * @param ring Ring identifier 
246    * @param sec  Sector number 
247    * @param str  Strip number 
248    * 
249    * @return  Index (not checked) 
250    */
251   Int_t CalcIndex(UShort_t det, Char_t ring, 
252                   UShort_t sec, UShort_t str) const;
253   /** 
254    * Calculate index and return 
255    *
256    * @param det  Detector number
257    * @param ring Ring identifier 
258    * @param sec  Sector number 
259    * @param str  Strip number 
260    * 
261    * @return  Index or -1 if the coordinates are invalid
262    */
263   Int_t  CheckIndex(UShort_t det, Char_t ring, 
264                     UShort_t sec, UShort_t str) const;
265   /** 
266    * Check if we need UShort_t hack 
267    * 
268    * @param file File this object was read from 
269    */
270   void CheckNeedUShort(TFile* file);
271   /** 
272    * Right multiplication operator
273    * 
274    * @param o Other map to multuiply with
275    * 
276    * @return Reference to this object
277    */
278   AliFMDMap& operator*=(const AliFMDMap& o);
279   /** 
280    * Right division operator
281    * 
282    * @param o Other map to divide with
283    * 
284    * @return Reference to this object
285    */
286   AliFMDMap& operator/=(const AliFMDMap& o);
287   /** 
288    * Right addision operator
289    * 
290    * @param o Other map to add to this
291    * 
292    * @return Reference to this object
293    */
294   AliFMDMap& operator+=(const AliFMDMap& o);
295   /** 
296    * Right subtraction operator
297    * 
298    * @param o Other map to substract from this
299    * 
300    * @return Reference to this object
301    */
302   AliFMDMap& operator-=(const AliFMDMap& o);
303   /** 
304    * For each element of the map, call the user defined overloaded
305    * @c ForOne::operator() 
306    * 
307    * @param algo Algorithm to use
308    * 
309    * @return @c true on success, @c false if for any element, @c
310    * algo(d,r,s,t,v) returns false. 
311    */
312   virtual Bool_t  ForEach(ForOne& algo) const;
313   /** 
314    * Get the total size of the internal array - that is the maximum
315    * index possible plus one. 
316    * 
317    * @return maximum index, plus 1
318    */
319   virtual Int_t MaxIndex() const = 0;
320   /** 
321    * Print content of the map 
322    * 
323    * @param option If not null or empty string, print map 
324    */
325   virtual void Print(Option_t* option="") const;
326   /** 
327    * Virtal function to get the value at index @a idx as a floating
328    * point number.  
329    * 
330    * @note 
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 
336    *
337    * @verbatim
338    *   a += b;
339    * @endverbatim 
340    *
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).   
344    *
345    * @param idx Index number
346    * 
347    * @return Value at index as a floating point number 
348    */
349   virtual Float_t AtAsFloat(Int_t idx) const;
350   /** 
351    * Virtal function to get the value at index @a idx as a floating
352    * point number.  
353    * 
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 
359    *
360    * @code 
361    *   a += b;
362    * @endcode
363    * 
364    * where @c a is non-floating point valued, and @c b is floating
365    * point valued (only).
366    *
367    * @param idx Index number
368    * 
369    * @return Value at index as a floating point number 
370    */
371   virtual Float_t& AtAsFloat(Int_t idx);
372   /** 
373    * Virtal function to get the value at index @a idx as an integer
374    * 
375    * @see Float_t AliFMDMap::AtAsFloat(Int_t) const
376    *
377    * @param idx Index number
378    * 
379    * @return Value at index as an integer
380    */
381   virtual Int_t   AtAsInt(Int_t idx) const;
382   /** 
383    * Virtal function to get the value at index @a idx as an integer
384    * 
385    * @see Float_t& AliFMDMap::AtAsFloat(Int_t)
386    *
387    * @param idx Index number
388    * 
389    * @return Value at index as an integer
390    */
391   virtual Int_t&   AtAsInt(Int_t idx);
392   /** 
393    * Virtal function to get the value at index @a idx as an boolean  
394    * 
395    * @see Float_t AliFMDMap::AtAsFloat(Int_t) const
396    *
397    * @param idx Index number
398    * 
399    * @return Value at index as a boolean
400    */
401   virtual UShort_t   AtAsUShort(Int_t idx) const;
402   /** 
403    * Virtal function to get the value at index @a idx as an boolean
404    * 
405    * @see Float_t& AliFMDMap::AtAsFloat(Int_t)
406    *
407    * @param idx Index number
408    * 
409    * @return Value at index as a boolean
410    */
411   virtual UShort_t&   AtAsUShort(Int_t idx);
412   /** 
413    * Virtal function to get the value at index @a idx as an unsigned
414    * short integer  
415    * 
416    * @see Float_t AliFMDMap::AtAsFloat(Int_t) const
417    *
418    * @param idx Index number
419    * 
420    * @return Value at index as an unsigned short integer
421    */
422   virtual Bool_t   AtAsBool(Int_t idx) const;
423   /** 
424    * Virtal function to get the value at index @a idx as an unsigned
425    * short integer
426    * 
427    * @see Float_t& AliFMDMap::AtAsFloat(Int_t)
428    *
429    * @param idx Index number
430    * 
431    * @return Value at index as an unsigned short integer
432    */
433   virtual Bool_t&   AtAsBool(Int_t idx);
434   /**
435    * Whether this map is floating point valued - that is, it can be
436    * assigned floating point valued values.
437    * 
438    * @return @c true if the map is floating point valued 
439    */
440   virtual Bool_t IsFloat() const { return kFALSE; }
441   /**
442    * Whether this map is floating point valued or integer valued -
443    * that is, it can be assigned integer valued values
444    * 
445    * @return @c true if the map is integer valued 
446    */
447   virtual Bool_t IsInt() const { return kFALSE; }
448   /**
449    * Whether this map is unsigned short integer valued - that is it
450    * can be assigned unsigned short integer values
451    * 
452    * @return @c true if the map is unsigned short integer valued 
453    */
454   virtual Bool_t IsUShort() const { return kFALSE; }
455   /**
456    * Whether this map is boolean valued - that is it can be assigned
457    * boolean values
458    * 
459    * @return @c true if the map is boolean valued 
460    */
461   virtual Bool_t IsBool() const { return kFALSE; }
462   /** 
463    * Get raw data pointer. 
464    * 
465    * @return Raw data pointer 
466    */
467   virtual void* Ptr() const = 0;
468   enum {
469     /** In case of version 2 of this class, this bit should be set. */
470     kNeedUShort = 14
471   };
472 protected:
473   /** 
474    * Calculate, check, and return index for strip.  If the index is
475    * invalid, -1 is returned
476    * 
477    * This is only used when a full map is used, signalled by
478    * fMaxDetector = 0
479    * 
480    * @param det   Detector number
481    * @param ring  Ring identifier
482    * @param sec   Sector number 
483    * @param str   Strip number
484    * 
485    * @return  Unique index, or -1 in case of errors 
486    */
487   Int_t  Coords2Index(UShort_t det, Char_t ring, 
488                   UShort_t sec, UShort_t str) const;
489   /** 
490    * Calculate, check, and return index for strip.  If the index is
491    * invalid, -1 is returned
492    * 
493    * This is for back-ward compatibility and for when a map does not
494    * cover all of the FMD strips
495    * 
496    * @param det   Detector number
497    * @param ring  Ring identifier
498    * @param sec   Sector number 
499    * @param str   Strip number
500    *
501    * @return  Unique index, or -1 in case of errors 
502    */
503   Int_t  Coords2IndexOld(UShort_t det, Char_t ring, 
504                          UShort_t sec, UShort_t str) const;
505   /** 
506    * Calculate the detector coordinates from an array index. 
507    * 
508    * This is used for backward compatibility and for when a map does not
509    * cover all of the FMD strips
510    * 
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
516    */
517   void Index2CoordsOld(Int_t     idx, 
518                        UShort_t& det, 
519                        Char_t&   ring, 
520                        UShort_t& sec, 
521                        UShort_t& str) const;
522   /** 
523    * Calculate the detector coordinates from an array index. 
524    * 
525    * This is used for a full map only, signalled by fMaxDetector = 0
526    * 
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
532    */
533   void Index2Coords(Int_t     idx, 
534                     UShort_t& det, 
535                     Char_t&   ring, 
536                     UShort_t& sec, 
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
542
543   ClassDef(AliFMDMap, 4) // Cache of per strip information
544 };
545
546 inline Float_t
547 AliFMDMap::AtAsFloat(Int_t) const
548 {
549   return 0;
550 }
551 inline Float_t&
552 AliFMDMap::AtAsFloat(Int_t)
553 {
554   static Float_t d;
555   return d;
556 }
557 inline Int_t
558 AliFMDMap::AtAsInt(Int_t) const
559 {
560   return 0;
561 }
562 inline Int_t&
563 AliFMDMap::AtAsInt(Int_t)
564 {
565   static Int_t d;
566   return d;
567 }
568 inline UShort_t
569 AliFMDMap::AtAsUShort(Int_t) const
570 {
571   return 0;
572 }
573 inline UShort_t&
574 AliFMDMap::AtAsUShort(Int_t)
575 {
576   static UShort_t d;
577   return d;
578 }
579 inline Bool_t
580 AliFMDMap::AtAsBool(Int_t) const
581 {
582   return kFALSE;
583 }
584 inline Bool_t&
585 AliFMDMap::AtAsBool(Int_t)
586 {
587   static Bool_t d;
588   return d;
589 }
590 inline Bool_t
591 AliFMDMap::ForOne::operator()(UShort_t, Char_t, UShort_t, UShort_t, Float_t)
592 {
593   return kTRUE;
594 }
595 inline Bool_t
596 AliFMDMap::ForOne::operator()(UShort_t, Char_t, UShort_t, UShort_t, Int_t)
597 {
598   return kTRUE;
599 }
600 inline Bool_t
601 AliFMDMap::ForOne::operator()(UShort_t, Char_t, UShort_t, UShort_t, UShort_t)
602 {
603   return kTRUE;
604 }
605 inline Bool_t
606 AliFMDMap::ForOne::operator()(UShort_t, Char_t, UShort_t, UShort_t, Bool_t)
607 {
608   return kTRUE;
609 }
610
611
612
613 #endif 
614 //____________________________________________________________________
615 //
616 // Local Variables:
617 //   mode: C++
618 // End:
619 //
620 // EOF
621 //
622
623