ROOT logo
#ifndef ALIFMDINDEX_H
#define ALIFMDINDEX_H
/** @file    AliFMDIndex.h
    @author  Christian Holm Christensen <cholm@nbi.dk>
    @date    Mon Mar 27 12:37:41 2006
    @brief   FMD detector coordinates
*/
//___________________________________________________________________
//
//  Class that holds an FMD index.  That is, it holds the detector
//  coordinates for a given strip:
//
//     Variable | Type     | Range   | Description
//     ---------+----------+---------+------------------
//     detector | UShort_t | 1-3     | Detector number 
//     ring     | Char_t   | 'I'/'O' | Ring identifier 
//     sector   | UShort_t | 0-39    | Sector number
//     strip    | UShort_t | 0-511   | Strip number
//
#ifndef ROOT_Rtypes
# include <Rtypes.h>
#endif
#ifndef ROOT_TObject
# include <TObject.h>
#endif
#ifndef ROOT_TString
# include <TString.h>
#endif
#include <iosfwd>

//____________________________________________________________________
/** @class AliFMDIndex AliFMDIndex.h <FMD/AliFMDIndex.h>
    @brief FMD detector coordinates 
    @ingroup FMD_base
 */
class AliFMDIndex 
{
public: 
  /** CTOR */
  AliFMDIndex();
  /** Copy CTOR 
      @param o Object to copy from */
  AliFMDIndex(const AliFMDIndex& o);
  /** Constrctor 
      @param detector Detector 
      @param ring     Ring
      @param sector   Sector
      @param strip    Strip */
  AliFMDIndex(UShort_t detector, 
	      Char_t   ring='\0', 
	      UShort_t sector=0, 
	      UShort_t strip=0);
  /** Assignment operator 
      @param o Object to assign from 
      @return Reference to this object  */
  AliFMDIndex& operator=(const AliFMDIndex& o);
  /** Comparison operator 
      @param o Object to compare to 
      @return @c true if these refer to the same index  */
  bool operator==(const AliFMDIndex& o) const;
  /** Comparison operator 
      @param o Object to compare to 
      @return @c true if this is smaller than @a o */
  bool operator<(const AliFMDIndex& o) const;
  /** DTOR */
  virtual ~AliFMDIndex() {}
  /** @return Detector # */
  UShort_t     Detector()	   const { return fDetector; }
  /** @return Ring ID */
  Char_t       Ring()	           const { return fRing;     }
  /** @return sector # */
  UShort_t     Sector()	           const { return fSector;   }
  /** @return strip # */
  UShort_t     Strip()	           const { return fStrip;    }
  /** @param x Detector # */
  void SetDetector(UShort_t x)	   { fHash = -1; fDetector = x; }
  /** @param x Ring ID */
  void SetRing(Char_t x)	   { fHash = -1; fRing = x; }
  /** @param x sector # */
  void SetSector(UShort_t x)	   { fHash = -1; fSector = x; }
  /** @param x strip # */
  void SetStrip(UShort_t x)	   { fHash = -1; fStrip = x; }
  /** Print information 
      @param opt Not used */
  virtual void Print(Option_t* opt="") const;
  /** @return Name */
  const char*  Name() const;
protected:
  Int_t Hash() const;
  UShort_t fDetector;      // (Sub) Detector # (1,2, or 3)
  Char_t   fRing;          // Ring ID ('I' or 'O')
  UShort_t fSector;        // Sector # (phi division)
  UShort_t fStrip;         // Strip # (radial division)
  mutable TString  fName;  //! Cached name
  mutable Int_t    fHash;  //! Cached hash value
  ClassDef(AliFMDIndex, 1) // Base class for FMD digits 
};

//____________________________________________________________________
class AliFMDObjIndex : public TObject, public AliFMDIndex
{
public:
  /** CTOR */
  AliFMDObjIndex() {}
  /** Copy CTOR 
      @param o Object to copy from */
  AliFMDObjIndex(const AliFMDObjIndex& o) : TObject(o), AliFMDIndex(o) {}
  /** Construct from a pure index
      @param o Object to copy from */
  explicit AliFMDObjIndex(const AliFMDIndex& o) : AliFMDIndex(o) {}
  /** Constrctor 
      @param detector Detector 
      @param ring     Ring
      @param sector   Sector
      @param strip    Strip */
  AliFMDObjIndex(UShort_t detector, 
		 Char_t   ring='\0', 
		 UShort_t sector=0, 
		 UShort_t strip=0) 
    : AliFMDIndex(detector, ring, sector, strip)
  {}
  /** DTOR */
  virtual ~AliFMDObjIndex() {}
  AliFMDObjIndex& operator=(const AliFMDObjIndex& o) 
  {
    if (&o == this) return *this;
    AliFMDIndex::operator=(o);
    return *this; 
  }
  /** @return name */
  virtual const char* GetName() const { return AliFMDIndex::Name(); }
  /** sort compare for TCollection's
      @param o Object to compare to
      @return  -1 if this is @e smaller than @a o, 0 if @e equal to 
      @a o, and 1 if this is @e larger than @a o */
  virtual Int_t Compare(const TObject* o) const;
  /** @return always true */
  Bool_t IsSortable() const { return kTRUE; }
  ClassDef(AliFMDObjIndex, 1) // Base class for FMD digits 
};
 
//____________________________________________________________________
inline
bool
AliFMDIndex::operator==(const AliFMDIndex& o) const
{
  return (o.Hash() == Hash());
}

//____________________________________________________________________
inline
bool
AliFMDIndex::operator<(const AliFMDIndex& rhs) const
{
  return (Hash() < rhs.Hash());
}

#if 0
//____________________________________________________________________
inline
bool
operator<(const AliFMDIndex& lhs, const AliFMDIndex& rhs)
{
  return (lhs.Detector() < rhs.Detector() ? true : 
	  (lhs.Ring()    < rhs.Ring()     ? true :
	   (lhs.Sector() < rhs.Sector()   ? true :
	    (lhs.Strip() < rhs.Strip()    ? true : false))));
}
#endif 
#endif
//____________________________________________________________________
//
// Local Variables:
//   mode: C++
// End:
//
//
// EOF
//
 AliFMDIndex.h:1
 AliFMDIndex.h:2
 AliFMDIndex.h:3
 AliFMDIndex.h:4
 AliFMDIndex.h:5
 AliFMDIndex.h:6
 AliFMDIndex.h:7
 AliFMDIndex.h:8
 AliFMDIndex.h:9
 AliFMDIndex.h:10
 AliFMDIndex.h:11
 AliFMDIndex.h:12
 AliFMDIndex.h:13
 AliFMDIndex.h:14
 AliFMDIndex.h:15
 AliFMDIndex.h:16
 AliFMDIndex.h:17
 AliFMDIndex.h:18
 AliFMDIndex.h:19
 AliFMDIndex.h:20
 AliFMDIndex.h:21
 AliFMDIndex.h:22
 AliFMDIndex.h:23
 AliFMDIndex.h:24
 AliFMDIndex.h:25
 AliFMDIndex.h:26
 AliFMDIndex.h:27
 AliFMDIndex.h:28
 AliFMDIndex.h:29
 AliFMDIndex.h:30
 AliFMDIndex.h:31
 AliFMDIndex.h:32
 AliFMDIndex.h:33
 AliFMDIndex.h:34
 AliFMDIndex.h:35
 AliFMDIndex.h:36
 AliFMDIndex.h:37
 AliFMDIndex.h:38
 AliFMDIndex.h:39
 AliFMDIndex.h:40
 AliFMDIndex.h:41
 AliFMDIndex.h:42
 AliFMDIndex.h:43
 AliFMDIndex.h:44
 AliFMDIndex.h:45
 AliFMDIndex.h:46
 AliFMDIndex.h:47
 AliFMDIndex.h:48
 AliFMDIndex.h:49
 AliFMDIndex.h:50
 AliFMDIndex.h:51
 AliFMDIndex.h:52
 AliFMDIndex.h:53
 AliFMDIndex.h:54
 AliFMDIndex.h:55
 AliFMDIndex.h:56
 AliFMDIndex.h:57
 AliFMDIndex.h:58
 AliFMDIndex.h:59
 AliFMDIndex.h:60
 AliFMDIndex.h:61
 AliFMDIndex.h:62
 AliFMDIndex.h:63
 AliFMDIndex.h:64
 AliFMDIndex.h:65
 AliFMDIndex.h:66
 AliFMDIndex.h:67
 AliFMDIndex.h:68
 AliFMDIndex.h:69
 AliFMDIndex.h:70
 AliFMDIndex.h:71
 AliFMDIndex.h:72
 AliFMDIndex.h:73
 AliFMDIndex.h:74
 AliFMDIndex.h:75
 AliFMDIndex.h:76
 AliFMDIndex.h:77
 AliFMDIndex.h:78
 AliFMDIndex.h:79
 AliFMDIndex.h:80
 AliFMDIndex.h:81
 AliFMDIndex.h:82
 AliFMDIndex.h:83
 AliFMDIndex.h:84
 AliFMDIndex.h:85
 AliFMDIndex.h:86
 AliFMDIndex.h:87
 AliFMDIndex.h:88
 AliFMDIndex.h:89
 AliFMDIndex.h:90
 AliFMDIndex.h:91
 AliFMDIndex.h:92
 AliFMDIndex.h:93
 AliFMDIndex.h:94
 AliFMDIndex.h:95
 AliFMDIndex.h:96
 AliFMDIndex.h:97
 AliFMDIndex.h:98
 AliFMDIndex.h:99
 AliFMDIndex.h:100
 AliFMDIndex.h:101
 AliFMDIndex.h:102
 AliFMDIndex.h:103
 AliFMDIndex.h:104
 AliFMDIndex.h:105
 AliFMDIndex.h:106
 AliFMDIndex.h:107
 AliFMDIndex.h:108
 AliFMDIndex.h:109
 AliFMDIndex.h:110
 AliFMDIndex.h:111
 AliFMDIndex.h:112
 AliFMDIndex.h:113
 AliFMDIndex.h:114
 AliFMDIndex.h:115
 AliFMDIndex.h:116
 AliFMDIndex.h:117
 AliFMDIndex.h:118
 AliFMDIndex.h:119
 AliFMDIndex.h:120
 AliFMDIndex.h:121
 AliFMDIndex.h:122
 AliFMDIndex.h:123
 AliFMDIndex.h:124
 AliFMDIndex.h:125
 AliFMDIndex.h:126
 AliFMDIndex.h:127
 AliFMDIndex.h:128
 AliFMDIndex.h:129
 AliFMDIndex.h:130
 AliFMDIndex.h:131
 AliFMDIndex.h:132
 AliFMDIndex.h:133
 AliFMDIndex.h:134
 AliFMDIndex.h:135
 AliFMDIndex.h:136
 AliFMDIndex.h:137
 AliFMDIndex.h:138
 AliFMDIndex.h:139
 AliFMDIndex.h:140
 AliFMDIndex.h:141
 AliFMDIndex.h:142
 AliFMDIndex.h:143
 AliFMDIndex.h:144
 AliFMDIndex.h:145
 AliFMDIndex.h:146
 AliFMDIndex.h:147
 AliFMDIndex.h:148
 AliFMDIndex.h:149
 AliFMDIndex.h:150
 AliFMDIndex.h:151
 AliFMDIndex.h:152
 AliFMDIndex.h:153
 AliFMDIndex.h:154
 AliFMDIndex.h:155
 AliFMDIndex.h:156
 AliFMDIndex.h:157
 AliFMDIndex.h:158
 AliFMDIndex.h:159
 AliFMDIndex.h:160
 AliFMDIndex.h:161
 AliFMDIndex.h:162
 AliFMDIndex.h:163
 AliFMDIndex.h:164
 AliFMDIndex.h:165
 AliFMDIndex.h:166
 AliFMDIndex.h:167
 AliFMDIndex.h:168
 AliFMDIndex.h:169
 AliFMDIndex.h:170
 AliFMDIndex.h:171
 AliFMDIndex.h:172
 AliFMDIndex.h:173
 AliFMDIndex.h:174
 AliFMDIndex.h:175
 AliFMDIndex.h:176
 AliFMDIndex.h:177
 AliFMDIndex.h:178
 AliFMDIndex.h:179