CbmRoot
CbmMuchAddress.h
Go to the documentation of this file.
1 #ifndef CBMMUCHADDRESS_H
2 #define CBMMUCHADDRESS_H 1
3 
4 #include <Rtypes.h> // for ClassDef
5 #include <RtypesCore.h> // for Int_t, UInt_t
6 
7 #include <FairLogger.h> // for Logger, LOG
8 
9 #include "CbmAddress.h" // for CbmAddress
10 
24 };
25 
26 
49 class CbmMuchAddress : public CbmAddress {
50 
51 public:
61  static UInt_t GetAddress(Int_t station = 0,
62  Int_t layer = 0,
63  Int_t side = 0,
64  Int_t module = 0,
65  Int_t sector = 0,
66  Int_t channel = 0);
67 
68 
69  static UInt_t GetAddress(Int_t* elementIds);
70 
71 
76  static Int_t GetNofLevels() { return kMuchNofLevels; }
77 
78 
83  static Int_t GetNofBits(Int_t level) {
84  if (level < 0 || level >= kMuchNofLevels) return 0;
85  return fgkBits[level];
86  }
87 
88 
94  static Int_t GetElementId(UInt_t address, Int_t level) {
95  if (level < 0 || level >= kMuchNofLevels) return -1;
96  return (address & (fgkMask[level] << fgkShift[level])) >> fgkShift[level];
97  }
98 
100  static Int_t GetSystemIndex(Int_t address) {
101  return GetElementId(address, kMuchSystem);
102  }
103  static Int_t GetStationIndex(Int_t address) {
104  return GetElementId(address, kMuchStation);
105  }
106  static Int_t GetLayerIndex(Int_t address) {
107  return GetElementId(address, kMuchLayer);
108  }
109  static Int_t GetLayerSideIndex(Int_t address) {
110  return GetElementId(address, kMuchLayerSide);
111  }
112  static Int_t GetModuleIndex(Int_t address) {
113  return GetElementId(address, kMuchModule);
114  }
115  static Int_t GetSectorIndex(Int_t address) {
116  return GetElementId(address, kMuchSector);
117  }
118  static Int_t GetChannelIndex(Int_t address) {
119  return GetElementId(address, kMuchChannel);
120  }
121 
122  static Int_t GetElementAddress(Int_t address, Int_t level) {
123  Int_t mask =
124  (1 << (CbmMuchAddress::fgkShift[level] + CbmMuchAddress::fgkBits[level]))
125  - 1;
126  return address & mask;
127  }
128 
130  static void Print();
131 
132 
140  static UInt_t SetElementId(UInt_t address, Int_t level, Int_t newId) {
141  if (level < 0 || level >= kMuchNofLevels) return address;
142  if (newId >= (1 << fgkBits[level])) {
143  LOG(error) << "Id " << newId << " for MUCH level " << level
144  << " exceeds maximum (" << (1 << fgkBits[level]) - 1 << ")";
145  return 0;
146  }
147  return (address & (~(fgkMask[level] << fgkShift[level])))
148  | (newId << fgkShift[level]);
149  }
150 
151 private:
153  static const Int_t fgkBits[kMuchNofLevels];
154 
156  static const Int_t fgkShift[kMuchNofLevels];
157 
159  static const Int_t fgkMask[kMuchNofLevels];
160 
161 
163 };
164 
165 
166 #endif /* CBMMUCHADDRESS_H */
CbmMuchAddress::GetNofBits
static Int_t GetNofBits(Int_t level)
Definition: CbmMuchAddress.h:83
CbmMuchAddress
Interface class to unique address for the MUCH.
Definition: CbmMuchAddress.h:49
kMuchSystem
@ kMuchSystem
System = MUCH.
Definition: CbmMuchAddress.h:16
kMuchChannel
@ kMuchChannel
Channel.
Definition: CbmMuchAddress.h:22
kMuchStation
@ kMuchStation
Station.
Definition: CbmMuchAddress.h:17
kMuchSector
@ kMuchSector
Sector.
Definition: CbmMuchAddress.h:21
kMuchNofLevels
@ kMuchNofLevels
Number of MUCH levels.
Definition: CbmMuchAddress.h:23
kMuchLayerSide
@ kMuchLayerSide
LayerSide.
Definition: CbmMuchAddress.h:19
CbmMuchAddress::GetSystemIndex
static Int_t GetSystemIndex(Int_t address)
Definition: CbmMuchAddress.h:100
CbmMuchAddress::GetElementId
static Int_t GetElementId(UInt_t address, Int_t level)
Definition: CbmMuchAddress.h:94
MuchElementLevel
MuchElementLevel
Definition: CbmMuchAddress.h:15
CbmAddress
Base class for interfaces to the unique address.
Definition: CbmAddress.h:23
CbmMuchAddress::GetModuleIndex
static Int_t GetModuleIndex(Int_t address)
Definition: CbmMuchAddress.h:112
CbmMuchAddress::fgkShift
static const Int_t fgkShift[kMuchNofLevels]
Definition: CbmMuchAddress.h:156
kMuchLayer
@ kMuchLayer
Layer.
Definition: CbmMuchAddress.h:18
CbmMuchAddress::ClassDef
ClassDef(CbmMuchAddress, 1)
CbmMuchAddress::fgkBits
static const Int_t fgkBits[kMuchNofLevels]
Definition: CbmMuchAddress.h:153
CbmMuchAddress::fgkMask
static const Int_t fgkMask[kMuchNofLevels]
Definition: CbmMuchAddress.h:159
CbmMuchAddress::SetElementId
static UInt_t SetElementId(UInt_t address, Int_t level, Int_t newId)
Definition: CbmMuchAddress.h:140
CbmMuchAddress::GetLayerIndex
static Int_t GetLayerIndex(Int_t address)
Definition: CbmMuchAddress.h:106
CbmMuchAddress::GetStationIndex
static Int_t GetStationIndex(Int_t address)
Definition: CbmMuchAddress.h:103
CbmMuchAddress::Print
static void Print()
Definition: CbmMuchAddress.cxx:110
CbmMuchAddress::GetElementAddress
static Int_t GetElementAddress(Int_t address, Int_t level)
Definition: CbmMuchAddress.h:122
CbmAddress.h
kMuchModule
@ kMuchModule
Module.
Definition: CbmMuchAddress.h:20
CbmMuchAddress::GetAddress
static UInt_t GetAddress(Int_t station=0, Int_t layer=0, Int_t side=0, Int_t module=0, Int_t sector=0, Int_t channel=0)
Definition: CbmMuchAddress.cxx:43
CbmMuchAddress::GetNofLevels
static Int_t GetNofLevels()
Definition: CbmMuchAddress.h:76
CbmMuchAddress::GetLayerSideIndex
static Int_t GetLayerSideIndex(Int_t address)
Definition: CbmMuchAddress.h:109
CbmMuchAddress::GetChannelIndex
static Int_t GetChannelIndex(Int_t address)
Definition: CbmMuchAddress.h:118
CbmMuchAddress::GetSectorIndex
static Int_t GetSectorIndex(Int_t address)
Definition: CbmMuchAddress.h:115