#ifndef ROOT_TObject
# include <TObject.h>
#endif
+class TFile;
+
//____________________________________________________________________
-//
-// Base class for caches of per-strip information.
-// This is used to index a strip.
-// Data stored depends on derived class.
-//
+/** @class AliFMDMap
+ @brief Base class for caches of per-strip information.
+ @ingroup FMD_data
+ This is used to index a strip. Data stored depends on derived
+ class. */
class AliFMDMap : public TObject
{
public:
enum {
+ /** Default maximum detector number */
kMaxDetectors = 3,
+ /** Default maximum number of rings */
kMaxRings = 2,
+ /** Default maximum number of sectors */
kMaxSectors = 40,
+ /** Default maximum number of strips */
kMaxStrips = 512
};
- AliFMDMap(size_t maxDet = kMaxDetectors,
- size_t maxRing= kMaxRings,
- size_t maxSec = kMaxSectors,
- size_t maxStr = kMaxStrips);
+ enum {
+ /** Number used for inner rings */
+ kInner = 0,
+ /** Number used for outer rings */
+ kOuter
+ };
+ enum {
+ /** Number of strips in outer rings */
+ kNStripOuter = 256,
+ /** Number of strips in the inner rings */
+ kNStripInner = 512
+ };
+ enum {
+ /** Number of sectors in the inner rings */
+ kNSectorInner = 20,
+ /** Number of sectorts in the outer rings */
+ kNSectorOuter = 40
+ };
+ enum {
+ /** Base index for inner rings */
+ kBaseInner = 0,
+ /** Base index for outer rings */
+ kBaseOuter = kNSectorInner * kNStripInner
+ };
+ enum {
+ /** Base for FMD1 index */
+ kFMD1Base = 0,
+ /** Base for FMD2 index */
+ kFMD2Base = kNSectorInner * kNStripInner,
+ /** Base for FMD3 index */
+ kFMD3Base = (kBaseOuter + kNSectorOuter * kNStripOuter + kFMD2Base)
+ };
+ /**
+ * Class to do stuff on each element of a map in an efficient
+ * way.
+ */
+ class ForOne
+ {
+ public:
+ /** Destructor */
+ virtual ~ForOne() { }
+ /**
+ * Called for each element considered a floating point number
+ *
+ * @param d Detector number
+ * @param r Ring identifier
+ * @param s Sector number
+ * @param t Strip number
+ * @param v Value (as a floating point number)
+ *
+ * @return Should return @c true on success, @c false otherwise
+ */
+ virtual Bool_t operator()(UShort_t d, Char_t r, UShort_t s, UShort_t t,
+ Float_t v);
+ /**
+ * Called for each element considered an integer
+ *
+ * @param d Detector number
+ * @param r Ring identifier
+ * @param s Sector number
+ * @param t Strip number
+ * @param v Value (as an integer)
+ *
+ * @return Should return @c true on success, @c false otherwise
+ */
+ virtual Bool_t operator()(UShort_t d, Char_t r, UShort_t s, UShort_t t,
+ Int_t v);
+ /**
+ * Called for each element considered an integer
+ *
+ * @param d Detector number
+ * @param r Ring identifier
+ * @param s Sector number
+ * @param t Strip number
+ * @param v Value (as an unsigned short integer)
+ *
+ * @return Should return @c true on success, @c false otherwise
+ */
+ virtual Bool_t operator()(UShort_t d, Char_t r, UShort_t s, UShort_t t,
+ UShort_t v);
+ /**
+ * Called for each element considered an integer
+ *
+ * @param d Detector number
+ * @param r Ring identifier
+ * @param s Sector number
+ * @param t Strip number
+ * @param v Value (as a boolean)
+ *
+ * @return Should return @c true on success, @c false otherwise
+ */
+ virtual Bool_t operator()(UShort_t d, Char_t r, UShort_t s, UShort_t t,
+ Bool_t v);
+ };
+
+ /**
+ * Constructor
+ *
+ * @param maxDet Maximum allowed detector number
+ * @param maxRing Maximum number of rings
+ * @param maxSec Maximum number of sectors
+ * @param maxStr Maximum number of strips
+ */
+ AliFMDMap(UShort_t maxDet = 0,
+ UShort_t maxRing= 0,
+ UShort_t maxSec = 0,
+ UShort_t maxStr = 0);
+ /**
+ * Copy constructor
+ *
+ * @param other Object to construct from
+ */
+ AliFMDMap(const AliFMDMap& other);
+ /** Destructor */
virtual ~AliFMDMap() {}
- size_t MaxDetectors() const { return fMaxDetectors; }
- size_t MaxRings() const { return fMaxRings; }
- size_t MaxSectors() const { return fMaxSectors; }
- size_t MaxStrips() const { return fMaxStrips; }
- Int_t CheckIndex(size_t det, Char_t ring, size_t sec, size_t str) const;
+ /** @return Maximum detector number */
+ UShort_t MaxDetectors() const { return fMaxDetectors==0 ? 3 :fMaxDetectors;}
+ /** @return Maximum number of rings */
+ UShort_t MaxRings() const { return fMaxRings ==0 ? 2 :fMaxRings; }
+ /** @return Maximum number of sectors */
+ UShort_t MaxSectors() const { return fMaxSectors ==0 ? 40 :fMaxSectors; }
+ /** @return Maximum number of strip */
+ UShort_t MaxStrips() const { return fMaxStrips ==0 ? 512 :fMaxStrips; }
+ /**
+ * Calculate the detector coordinates for a given index number
+ *
+ * @param idx Index to find cooresponding detector coordinates for
+ * @param det On return, contain the detector number
+ * @param ring On return, contain the ring identifier
+ * @param sec On return, contain the sector number
+ * @param str On return, contain the strip number
+ */
+ void CalcCoords(Int_t idx,
+ UShort_t& det,
+ Char_t& ring,
+ UShort_t& sec,
+ UShort_t& str) const;
+ /**
+ * Calculate index and return
+ *
+ * @param det Detector number
+ * @param ring Ring identifier
+ * @param sec Sector number
+ * @param str Strip number
+ *
+ * @return Index (not checked)
+ */
+ Int_t CalcIndex(UShort_t det, Char_t ring,
+ UShort_t sec, UShort_t str) const;
+ /**
+ * Calculate index and return
+ *
+ * @param det Detector number
+ * @param ring Ring identifier
+ * @param sec Sector number
+ * @param str Strip number
+ *
+ * @return Index or -1 if the coordinates are invalid
+ */
+ Int_t CheckIndex(UShort_t det, Char_t ring,
+ UShort_t sec, UShort_t str) const;
+ /**
+ * Check if we need UShort_t hack
+ *
+ * @param file File this object was read from
+ */
+ void CheckNeedUShort(TFile* file);
+ /**
+ * Right multiplication operator
+ *
+ * @param o Other map to multuiply with
+ *
+ * @return Reference to this object
+ */
+ AliFMDMap& operator*=(const AliFMDMap& o);
+ /**
+ * Right division operator
+ *
+ * @param o Other map to divide with
+ *
+ * @return Reference to this object
+ */
+ AliFMDMap& operator/=(const AliFMDMap& o);
+ /**
+ * Right addision operator
+ *
+ * @param o Other map to add to this
+ *
+ * @return Reference to this object
+ */
+ AliFMDMap& operator+=(const AliFMDMap& o);
+ /**
+ * Right subtraction operator
+ *
+ * @param o Other map to substract from this
+ *
+ * @return Reference to this object
+ */
+ AliFMDMap& operator-=(const AliFMDMap& o);
+ /**
+ * For each element of the map, call the user defined overloaded
+ * @c ForOne::operator()
+ *
+ * @param algo Algorithm to use
+ *
+ * @return @c true on success, @c false if for any element, @c
+ * algo(d,r,s,t,v) returns false.
+ */
+ virtual Bool_t ForEach(ForOne& algo) const;
+ /**
+ * Get the total size of the internal array - that is the maximum
+ * index possible plus one.
+ *
+ * @return maximum index, plus 1
+ */
+ virtual Int_t MaxIndex() const = 0;
+ /**
+ * Virtal function to get the value at index @a idx as a floating
+ * point number.
+ *
+ * @note
+ * Even if the map is not floating point valued the
+ * sub-class can define this member function to allow non l-value
+ * usage of the data in the map. That is, if @c a is a floating
+ * point valued map, and @c b is not, then if the class @c B of @c b
+ * implements this member function, expression like
+ *
+ * @verbatim
+ * a += b;
+ * @endverbatim
+ *
+ * multiplies each element of @c a (floating points) with each
+ * element of @c c according to the definition of @c B::AtAsFloat
+ * (@c const version).
+ *
+ * @param idx Index number
+ *
+ * @return Value at index as a floating point number
+ */
+ virtual Float_t AtAsFloat(Int_t idx) const;
+ /**
+ * Virtal function to get the value at index @a idx as a floating
+ * point number.
+ *
+ * This member function should only be defined if the map is a
+ * floating point valued, and can be assigned floating point valued
+ * values. That is, if the map's elements are anything but @c
+ * float then this member function should not be defined in the
+ * derived class. That will prevent expressions like
+ *
+ * @code
+ * a += b;
+ * @endcode
+ *
+ * where @c a is non-floating point valued, and @c b is floating
+ * point valued (only).
+ *
+ * @param idx Index number
+ *
+ * @return Value at index as a floating point number
+ */
+ virtual Float_t& AtAsFloat(Int_t idx);
+ /**
+ * Virtal function to get the value at index @a idx as an integer
+ *
+ * @see Float_t AliFMDMap::AtAsFloat(Int_t) const
+ *
+ * @param idx Index number
+ *
+ * @return Value at index as an integer
+ */
+ virtual Int_t AtAsInt(Int_t idx) const;
+ /**
+ * Virtal function to get the value at index @a idx as an integer
+ *
+ * @see Float_t& AliFMDMap::AtAsFloat(Int_t)
+ *
+ * @param idx Index number
+ *
+ * @return Value at index as an integer
+ */
+ virtual Int_t& AtAsInt(Int_t idx);
+ /**
+ * Virtal function to get the value at index @a idx as an boolean
+ *
+ * @see Float_t AliFMDMap::AtAsFloat(Int_t) const
+ *
+ * @param idx Index number
+ *
+ * @return Value at index as a boolean
+ */
+ virtual UShort_t AtAsUShort(Int_t idx) const;
+ /**
+ * Virtal function to get the value at index @a idx as an boolean
+ *
+ * @see Float_t& AliFMDMap::AtAsFloat(Int_t)
+ *
+ * @param idx Index number
+ *
+ * @return Value at index as a boolean
+ */
+ virtual UShort_t& AtAsUShort(Int_t idx);
+ /**
+ * Virtal function to get the value at index @a idx as an unsigned
+ * short integer
+ *
+ * @see Float_t AliFMDMap::AtAsFloat(Int_t) const
+ *
+ * @param idx Index number
+ *
+ * @return Value at index as an unsigned short integer
+ */
+ virtual Bool_t AtAsBool(Int_t idx) const;
+ /**
+ * Virtal function to get the value at index @a idx as an unsigned
+ * short integer
+ *
+ * @see Float_t& AliFMDMap::AtAsFloat(Int_t)
+ *
+ * @param idx Index number
+ *
+ * @return Value at index as an unsigned short integer
+ */
+ virtual Bool_t& AtAsBool(Int_t idx);
+ /**
+ * Whether this map is floating point valued - that is, it can be
+ * assigned floating point valued values.
+ *
+ * @return @c true if the map is floating point valued
+ */
+ virtual Bool_t IsFloat() const { return kFALSE; }
+ /**
+ * Whether this map is floating point valued or integer valued -
+ * that is, it can be assigned integer valued values
+ *
+ * @return @c true if the map is integer valued
+ */
+ virtual Bool_t IsInt() const { return kFALSE; }
+ /**
+ * Whether this map is unsigned short integer valued - that is it
+ * can be assigned unsigned short integer values
+ *
+ * @return @c true if the map is unsigned short integer valued
+ */
+ virtual Bool_t IsUShort() const { return kFALSE; }
+ /**
+ * Whether this map is boolean valued - that is it can be assigned
+ * boolean values
+ *
+ * @return @c true if the map is boolean valued
+ */
+ virtual Bool_t IsBool() const { return kFALSE; }
+
+ enum {
+ /** In case of version 2 of this class, this bit should be set. */
+ kNeedUShort = 14
+ };
protected:
- size_t CalcIndex(size_t det, Char_t ring, size_t sec, size_t str) const;
- size_t fMaxDetectors; // Maximum # of detectors
- size_t fMaxRings; // Maximum # of rings
- size_t fMaxSectors; // Maximum # of sectors
- size_t fMaxStrips; // Maximum # of strips
- ClassDef(AliFMDMap, 1) // Cache of per strip information
-};
+ /**
+ * Calculate, check, and return index for strip. If the index is
+ * invalid, -1 is returned
+ *
+ * This is only used when a full map is used, signalled by
+ * fMaxDetector = 0
+ *
+ * @param det Detector number
+ * @param ring Ring identifier
+ * @param sec Sector number
+ * @param str Strip number
+ *
+ * @return Unique index, or -1 in case of errors
+ */
+ Int_t Coords2Index(UShort_t det, Char_t ring,
+ UShort_t sec, UShort_t str) const;
+ /**
+ * Calculate, check, and return index for strip. If the index is
+ * invalid, -1 is returned
+ *
+ * This is for back-ward compatibility and for when a map does not
+ * cover all of the FMD strips
+ *
+ * @param det Detector number
+ * @param ring Ring identifier
+ * @param sec Sector number
+ * @param str Strip number
+ *
+ * @return Unique index, or -1 in case of errors
+ */
+ Int_t Coords2IndexOld(UShort_t det, Char_t ring,
+ UShort_t sec, UShort_t str) const;
+ /**
+ * Calculate the detector coordinates from an array index.
+ *
+ * This is used for backward compatibility and for when a map does not
+ * cover all of the FMD strips
+ *
+ * @param idx Index to convert
+ * @param det Detector number on return
+ * @param ring Ring identifier on return
+ * @param sec Sector number on return
+ * @param str Strip number on return
+ */
+ void Index2CoordsOld(Int_t idx,
+ UShort_t& det,
+ Char_t& ring,
+ UShort_t& sec,
+ UShort_t& str) const;
+ /**
+ * Calculate the detector coordinates from an array index.
+ *
+ * This is used for a full map only, signalled by fMaxDetector = 0
+ *
+ * @param idx Index to convert
+ * @param det Detector number on return
+ * @param ring Ring identifier on return
+ * @param sec Sector number on return
+ * @param str Strip number on return
+ */
+ void Index2Coords(Int_t idx,
+ UShort_t& det,
+ Char_t& ring,
+ UShort_t& sec,
+ UShort_t& str) const;
+ UShort_t fMaxDetectors; // Maximum # of detectors
+ UShort_t fMaxRings; // Maximum # of rings
+ UShort_t fMaxSectors; // Maximum # of sectors
+ UShort_t fMaxStrips; // Maximum # of strips
-#ifdef MAY_USE_TEMPLATES
-#ifndef __VECTOR__
-# include <vector>
-#endif
-//____________________________________________________________________
-//
-// Class template for classes that cache per strip information.
-// Access to the data goes via
-//
-// Type& AliFMDMap<Type>::operator()(size_t detector,
-// Char_t ring,
-// size_t sector,
-// size_t strip);
-//
-// (as well as a const version of this member function).
-// The elements can be reset to the default value by calling
-// AliFMDMap<Type>::Clear(). This resets the values to `Type()'.
-//
-template <typename Type>
-class AliFMDMap : public TObject
-{
-public:
- AliFMDMap(size_t maxDet=3, size_t maxRing=2, size_t maxSec=40,
- size_t maxStr=512);
- virtual ~AliFMDMap() {}
- void Clear(const Type& val=Type());
- Type& operator()(size_t det, Char_t ring, size_t sec, size_t str);
- const Type& operator()(size_t det, Char_t ring, size_t sec, size_t str)const;
-private:
- typedef std::vector<Type> ValueVector; // Type of container
- ValueVector fValues; // Contained values
- size_t fMaxDetectors; // Maximum # of detectors
- size_t fMaxRings; // Maximum # of rings
- size_t fMaxSectors; // Maximum # of sectors
- size_t fMaxStrips; // Maximum # of strips
-
- size_t CalcIndex(size_t det, Char_t ring, size_t sec, size_t str) const;
- ClassDef(AliFMDMap, 0); // Map of FMD index's to values
+ ClassDef(AliFMDMap, 4) // Cache of per strip information
};
-
-//____________________________________________________________________
-template <typename Type>
-inline
-AliFMDMap<Type>::AliFMDMap(size_t maxDet,
- size_t maxRing,
- size_t maxSec,
- size_t maxStr)
- : fValues(maxDet * maxRing * maxSec * maxStr),
- fMaxDetectors(maxDet),
- fMaxRings(maxRing),
- fMaxSectors(maxSec),
- fMaxStrips(maxStr)
+inline Float_t
+AliFMDMap::AtAsFloat(Int_t) const
{
- // Construct a map
- //
- // Parameters:
- // maxDet Maximum # of detectors
- // maxRinf Maximum # of rings
- // maxSec Maximum # of sectors
- // maxStr Maximum # of strips
+ return 0;
}
-
-
-//____________________________________________________________________
-template <typename Type>
-inline size_t
-AliFMDMap<Type>::CalcIndex(size_t det, Char_t ring, size_t sec, size_t str) const
+inline Float_t&
+AliFMDMap::AtAsFloat(Int_t)
{
- // Calculate index into storage from arguments.
- //
- // Parameters:
- // det Detector #
- // ring Ring ID
- // sec Sector #
- // str Strip #
- //
- // Returns appropriate index into storage
- //
- size_t ringi = (ring == 'I' || ring == 'i' ? 0 : 1);
- size_t idx =
- (det + fMaxDetectors * (ringi + fMaxRings * (sec + fMaxSectors * str)));
- if (idx >= fMaxDetectors * fMaxRings * fMaxSectors * fMaxStrips) {
- Fatal("CalcIndex", "Index (%d,'%c',%d,%d) out of bounds, "
- "in particular the %s index",
- det, ring, sec, str,
- (det >= fMaxDetectors ? "Detector" :
- (ringi >= fMaxRings ? "Ring" :
- (sec >= fMaxSectors ? "Sector" : "Strip"))));
- return 0;
- }
- return idx;
+ static Float_t d;
+ return d;
}
-
-//____________________________________________________________________
-template <typename Type>
-inline void
-AliFMDMap<Type>::Clear(const Type& val)
+inline Int_t
+AliFMDMap::AtAsInt(Int_t) const
{
- // Resets stored values to the default value for that type
- for (size_t i = 0; i < fValues.size(); ++i) fValues[i] = val;
+ return 0;
}
-
-//____________________________________________________________________
-template <typename Type>
-inline Type&
-AliFMDMap<Type>::operator()(size_t det, Char_t ring, size_t sec, size_t str)
+inline Int_t&
+AliFMDMap::AtAsInt(Int_t)
{
- // Parameters:
- // det Detector #
- // ring Ring ID
- // sec Sector #
- // str Strip #
- //
- // Returns data[det][ring][sec][str]
- return fValues[CalcIndex(det, ring, sec, str)];
+ static Int_t d;
+ return d;
}
-
-//____________________________________________________________________
-template <typename Type>
-inline const Type&
-AliFMDMap<Type>::operator()(size_t det,
- Char_t ring,
- size_t sec,
- size_t str) const
+inline UShort_t
+AliFMDMap::AtAsUShort(Int_t) const
+{
+ return 0;
+}
+inline UShort_t&
+AliFMDMap::AtAsUShort(Int_t)
+{
+ static UShort_t d;
+ return d;
+}
+inline Bool_t
+AliFMDMap::AtAsBool(Int_t) const
+{
+ return kFALSE;
+}
+inline Bool_t&
+AliFMDMap::AtAsBool(Int_t)
+{
+ static Bool_t d;
+ return d;
+}
+inline Bool_t
+AliFMDMap::ForOne::operator()(UShort_t, Char_t, UShort_t, UShort_t, Float_t)
+{
+ return kTRUE;
+}
+inline Bool_t
+AliFMDMap::ForOne::operator()(UShort_t, Char_t, UShort_t, UShort_t, Int_t)
{
- // Parameters:
- // det Detector #
- // ring Ring ID
- // sec Sector #
- // str Strip #
- //
- // Returns data[det][ring][sec][str]
- return fValues[CalcIndex(det, ring, sec, str)];
+ return kTRUE;
+}
+inline Bool_t
+AliFMDMap::ForOne::operator()(UShort_t, Char_t, UShort_t, UShort_t, UShort_t)
+{
+ return kTRUE;
+}
+inline Bool_t
+AliFMDMap::ForOne::operator()(UShort_t, Char_t, UShort_t, UShort_t, Bool_t)
+{
+ return kTRUE;
}
-//____________________________________________________________________
-//
-// Some specialisations
-//
-typedef AliFMDMap<UShort_t> AliFMDAdcMap;
-typedef AliFMDMap<std::pair<Float_t, UShort_t> > AliFMDEdepMap;
-#endif
#endif
//____________________________________________________________________
//