Hall A ROOT/C++ Analyzer (podd)
Loading...
Searching...
No Matches
THaDetMap.h
Go to the documentation of this file.
1#ifndef Podd_THaDetMap_h_
2#define Podd_THaDetMap_h_
3
5//
6// THaDetMap
7//
8// Standard detector map.
9// The detector map defines the hardware channels that correspond to a
10// single detector. Typically, "channels" are Fastbus or VME addresses
11// characterized by
12//
13// Crate, Slot, range of channels
14//
16
17//FIXME: Several things here are duplicates of information that already is
18// (or should be) available from the cratemap: specifically "model" and
19// "resolution", as well as the "model map" in AddModule. We should get it from
20// there - to ensure consistency and have one less maintenance headache.
21
22#include "THaEvData.h"
23#include "Decoder.h"
24#include <vector>
25#include <string>
26#include <memory>
27
28class THaDetMap {
29
30public:
31 class Iterator;
32 class MultiHitIterator;
33
34 // Configuration data for a frontend module
35 class Module {
36 public:
37 Module() = default;
38#if __clang__ || __GNUC__ > 4
39 Module( const Module& rhs ) = default;
40 Module& operator=( const Module& rhs ) = default;
41#else
42 // work around apparent g++ 4 bug
43 Module( Module& rhs ) = default;
44 Module& operator=( Module& rhs ) = default;
45#endif
50 UInt_t first; // logical number of first channel
51 Int_t model; // model number of module (for ADC/TDC identification).
53 UInt_t plane; // Detector plane
54 UInt_t signal; // (eg. PosADC, NegADC, PosTDC, NegTDC)
55 Int_t refchan; // for pipeline TDCs: reference channel number
56 Int_t refindex; // for pipeline TDCs: index into reference channel map
57 Double_t resolution; // Resolution (s/chan) for TDCs
58 Bool_t reverse; // Indicates that "first" corresponds to hi, not lo
59 Bool_t cmnstart; // TDC in common start mode (default false)
60
61 bool operator==( const Module& rhs ) const
62 { return crate == rhs.crate && slot == rhs.slot; }
63 bool operator!=( const Module& rhs ) const
64 { return !(*this==rhs); }
65 UInt_t GetNchan() const { return hi-lo+1; }
66 Int_t GetModel() const { return model; }
74 Bool_t IsCommonStart() const { return cmnstart; }
75 void SetModel( Int_t model );
77 // For legacy modules
78 void SetTDCMode( Bool_t cstart );
79 void MakeTDC();
80 void MakeADC();
81 // Get logical detector channel from physical one, starting at 0.
82 // For historical reasons, 'first' starts at 1, so subtract 1 here.
84 { return static_cast<Int_t>(first + (reverse ? hi-chan : chan-lo) - 1); }
85 };
86
87 // Flags for GetMinMaxChan()
92 // Flags for Fill()
94 kDoNotClear = BIT(0), // Don't clear the map first
95 kSkipLogicalChannel = BIT(9), // Parse but ignore the logical channel number
96 kFillLogicalChannel = BIT(10), // Parse the logical channel number
97 kFillModel = BIT(11), // Parse the model number
98 kFillRefIndex = BIT(12), // Parse the reference index
99 kFillRefChan = BIT(13), // Parse the reference channel
100 kFillPlane = BIT(14), // Parse the detector plane (for Hall C)
101 kFillSignal = BIT(15) // Parse the signal type (for Hall C)
102 };
103
105 THaDetMap( const THaDetMap& );
106 THaDetMap& operator=( const THaDetMap& );
107 virtual ~THaDetMap() = default;
108
111
112 virtual Int_t AddModule( UInt_t crate, UInt_t slot,
113 UInt_t chan_lo, UInt_t chan_hi,
114 UInt_t first = 0, Int_t model = 0,
115 Int_t refindex = -1, Int_t refchan = -1,
116 UInt_t plane = 0, UInt_t signal = 0 );
117 void Clear() { fMap.clear(); }
118 virtual Module* Find( UInt_t crate, UInt_t slot, UInt_t chan );
119 virtual Int_t Fill( const std::vector<Int_t>& values, UInt_t flags = 0 );
120 void GetMinMaxChan( UInt_t& min, UInt_t& max,
121 ECountMode mode = kLogicalChan ) const;
122 Module* GetModule( UInt_t i ) const;
123 UInt_t GetNchan( UInt_t i ) const;
124 UInt_t GetTotNumChan() const;
125 UInt_t GetSize() const { return fMap.size(); }
126
127 Int_t GetModel( UInt_t i ) const;
128 Bool_t IsADC( UInt_t i ) const;
129 Bool_t IsTDC( UInt_t i ) const;
130 static Int_t GetModel( Module* d );
131 static Bool_t IsADC( Module* d );
132 static Bool_t IsTDC( Module* d );
133
134 virtual void Print( Option_t* opt="" ) const;
135 virtual void Reset();
136 virtual void Sort();
137
139
140protected:
141 using ModuleVec_t = std::vector<std::unique_ptr<Module>>;
142 ModuleVec_t fMap; // Modules of this detector map
143
144 Module* uGetModule( UInt_t i ) const { return fMap[i].get(); }
145 void CopyMap( const ModuleVec_t& map );
146
147 // Channels in this map start counting at 0. Used by hit iterators.
149
150 //___________________________________________________________________________
151 // Utility classes for iterating over active channels in current event data
152public:
153 class Iterator {
154 public:
155 Iterator( THaDetMap& detmap, const THaEvData& evdata, bool do_init = true );
156 Iterator() = delete;
157 virtual ~Iterator() = default;
158
159 // Positioning
160 virtual Iterator& operator++();
161 const Iterator operator++(int) {
162 Iterator clone(*this); ++(*this); return clone;
163 }
164 virtual void reset();
165 UInt_t size() const { return fNTotChan; }
166
167 // Status
168 explicit virtual operator bool() const {
169 return (fIMod >= 0 and fIMod < static_cast<Int_t>(fNMod) and
170 fIChan >= 0 and fIChan < static_cast<Int_t>(fNChan));
171 }
172 bool operator!() const { return !static_cast<bool>(*this); }
173
174 // Current value
175 class HitInfo_t {
176 public:
178 module{nullptr}, type{Decoder::ChannelType::kUndefined},
179 modtype{Decoder::ChannelType::kUndefined},
181 hit{kMaxUInt}, lchan{-1} {}
183 if( mod->IsADC() )
185 else if( mod->IsTDC() )
188 modtype = mod->type;
189 crate = mod->crate;
190 slot = mod->slot;
191 }
192 void reset() {
193 module = nullptr; type = modtype = Decoder::ChannelType::kUndefined;
194 crate = slot = chan = hit = kMaxUInt; nhit = 0; lchan = -1;
195 }
196 Decoder::Module* module; // Current frontend module being decoded
197 Decoder::ChannelType type; // Measurement type for current channel (ADC/TDC)
198 Decoder::ChannelType modtype; // Module type (ADC/TDC/MultiFunctionADC etc.)
199 UInt_t ev; // Event number (for error messages)
200 UInt_t crate; // Hardware crate
201 UInt_t slot; // Hardware slot
202 UInt_t chan; // Physical channel in current module
203 UInt_t nhit; // Number of hits in current channel
204 UInt_t hit; // Hit number in current channel
205 Int_t lchan; // Logical channel according to detector map
206 };
207
208 const HitInfo_t* operator->() const { return &fHitInfo; }
209 const HitInfo_t& operator* () const { return fHitInfo; }
210
211 protected:
215 UInt_t fNMod; // Number of modules in detector map (cached)
216 UInt_t fNTotChan; // Total number of detector map channels (cached)
217 UInt_t fNChan; // Number of channels active in current module
218 Int_t fIMod; // Current module index in detector map
219 Int_t fIChan; // Current channel
220 HitInfo_t fHitInfo; // Current state of this iterator
221
222 // Formatter for exception messages
223 std::string msg( const char* txt ) const;
224 };
225
226 class MultiHitIterator : public Iterator {
227 public:
228 MultiHitIterator( THaDetMap& detmap, const THaEvData& evdata,
229 bool do_init = true );
231 virtual ~MultiHitIterator() = default;
232 explicit virtual operator bool() const {
233 return (Iterator::operator bool() and fIHit >= 0 and
234 fIHit < static_cast<Int_t>(fHitInfo.nhit));
235 }
236 virtual Iterator& operator++();
237 virtual void reset();
238 protected:
239 Int_t fIHit; // Current raw hit number
240 };
241
242 ClassDef(THaDetMap,1) //The standard detector map
243};
244
246
247//________ inlines ____________________________________________________________
249 return i<fMap.size() ? uGetModule(i) : nullptr;
250}
251
253 if( !d ) return false;
254 return d->IsADC();
255}
256
258 if( !d ) return false;
259 return d->IsTDC();
260}
261
263 if( !d ) return 0;
264 return d->GetModel();
265}
266
267inline Bool_t THaDetMap::IsADC( UInt_t i ) const {
268 if( i >= fMap.size() ) return false;
269 return uGetModule(i)->IsADC();
270}
271
272inline Bool_t THaDetMap::IsTDC( UInt_t i ) const {
273 if( i >= fMap.size() ) return false;
274 return uGetModule(i)->IsTDC();
275}
276
278 if( i >= fMap.size() ) return 0;
279 return uGetModule(i)->GetModel();
280}
281
283 // Return the number of channels of the i-th module
284 if( i >= fMap.size() ) return 0;
285 return uGetModule(i)->GetNchan();
286}
287
288#endif
int Int_t
unsigned int UInt_t
uint32_t chan
#define d(i)
TObject * clone(const char *newname) const override
bool Bool_t
const UInt_t kMaxUInt
double Double_t
const char Option_t
#define ClassDef(name, id)
#define BIT(n)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Decoder::ChannelType modtype
Definition THaDetMap.h:198
void set_crate_slot(const THaDetMap::Module *mod)
Definition THaDetMap.h:182
Decoder::Module *Decoder::ChannelType type
Definition THaDetMap.h:197
virtual void reset()
const THaEvData & fEvData
Definition THaDetMap.h:213
const HitInfo_t & operator*() const
Definition THaDetMap.h:209
const THaDetMap::Module * fMod
Definition THaDetMap.h:214
std::string msg(const char *txt) const
bool operator!() const
Definition THaDetMap.h:172
const HitInfo_t * operator->() const
Definition THaDetMap.h:208
const Iterator operator++(int)
Definition THaDetMap.h:161
virtual ~Iterator()=default
UInt_t size() const
Definition THaDetMap.h:165
virtual Iterator & operator++()
THaDetMap & fDetMap
Definition THaDetMap.h:212
bool operator==(const Module &rhs) const
Definition THaDetMap.h:61
Int_t ConvertToLogicalChannel(UInt_t chan) const
Definition THaDetMap.h:83
Double_t resolution
Definition THaDetMap.h:57
Bool_t IsADC() const
Definition THaDetMap.h:71
Bool_t IsCommonStart() const
Definition THaDetMap.h:74
void SetResolution(Double_t resolution)
Definition THaDetMap.cxx:61
void SetTDCMode(Bool_t cstart)
Definition THaDetMap.cxx:67
void SetModel(Int_t model)
Definition THaDetMap.cxx:49
Int_t GetModel() const
Definition THaDetMap.h:66
Module(Module &rhs)=default
Module & operator=(Module &rhs)=default
bool operator!=(const Module &rhs) const
Definition THaDetMap.h:63
Bool_t IsTDC() const
Definition THaDetMap.h:67
UInt_t GetNchan() const
Definition THaDetMap.h:65
Decoder::ChannelType type
Definition THaDetMap.h:52
virtual ~MultiHitIterator()=default
virtual Iterator & operator++()
virtual Module * Find(UInt_t crate, UInt_t slot, UInt_t chan)
Int_t GetModel(UInt_t i) const
Definition THaDetMap.h:277
void GetMinMaxChan(UInt_t &min, UInt_t &max, ECountMode mode=kLogicalChan) const
virtual Int_t AddModule(UInt_t crate, UInt_t slot, UInt_t chan_lo, UInt_t chan_hi, UInt_t first=0, Int_t model=0, Int_t refindex=-1, Int_t refchan=-1, UInt_t plane=0, UInt_t signal=0)
ModuleVec_t fMap
Definition THaDetMap.h:142
Module * uGetModule(UInt_t i) const
Definition THaDetMap.h:144
virtual ~THaDetMap()=default
UInt_t GetSize() const
Definition THaDetMap.h:125
virtual void Print(Option_t *opt="") const
void Clear()
Definition THaDetMap.h:117
virtual void Sort()
void CopyMap(const ModuleVec_t &map)
Definition THaDetMap.cxx:92
THaDetMap::Iterator MakeIterator(const THaEvData &evdata)
void SetStartAtZero(Bool_t value)
Definition THaDetMap.h:138
UInt_t GetNchan(UInt_t i) const
Definition THaDetMap.h:282
std::vector< std::unique_ptr< Module > > ModuleVec_t
Definition THaDetMap.h:141
@ kLogicalChan
Definition THaDetMap.h:89
@ kFillLogicalChannel
Definition THaDetMap.h:96
@ kFillRefChan
Definition THaDetMap.h:99
@ kDoNotClear
Definition THaDetMap.h:94
@ kFillRefIndex
Definition THaDetMap.h:98
@ kSkipLogicalChannel
Definition THaDetMap.h:95
Bool_t IsTDC(UInt_t i) const
Definition THaDetMap.h:272
THaDetMap::MultiHitIterator MakeMultiHitIterator(const THaEvData &evdata)
virtual Int_t Fill(const std::vector< Int_t > &values, UInt_t flags=0)
Module * GetModule(UInt_t i) const
Definition THaDetMap.h:248
Bool_t fStartAtZero
Definition THaDetMap.h:148
UInt_t GetTotNumChan() const
virtual void Reset()
Bool_t IsADC(UInt_t i) const
Definition THaDetMap.h:267
THaDetMap & operator=(const THaDetMap &)
ChannelType
Definition Decoder.h:61