Hall A ROOT/C++ Analyzer (podd)
THaCrateMap.h
Go to the documentation of this file.
1 #ifndef Podd_THaCrateMap_h_
2 #define Podd_THaCrateMap_h_
3 
5 //
6 // THaCrateMap
7 // Layout, or "map", of DAQ Crates.
8 //
9 // THaCrateMap contains info on how the DAQ crates
10 // are arranged in Hall A, i.e whether slots are
11 // fastbus or vme, what the module types are, and
12 // what header info to expect. Probably nobody needs
13 // to know about this except the author, and at present
14 // an object of this class is a private member of the decoder.
15 //
16 // author Robert Michaels (rom@jlab.org)
17 //
19 
20 
21 #include "Decoder.h"
22 #include "TDatime.h"
23 #include <fstream>
24 #include <cstdio> // for FILE
25 #include <cassert>
26 #include <iostream>
27 #include <string>
28 #include <vector>
29 #include <array>
30 
31 namespace Decoder {
32 
33 class THaCrateMap {
34  public:
35  static const UInt_t MAXCHAN;
36  static const UInt_t MAXDATA;
37 
38  explicit THaCrateMap( const char* db = "cratemap" ); // Construct uninitialized
39  virtual ~THaCrateMap() = default;
40  bool isFastBus( UInt_t crate ) const; // True if fastbus crate;
41  bool isVme( UInt_t crate ) const; // True if VME crate;
42  bool isCamac( UInt_t crate ) const; // True if CAMAC crate;
43  bool isScalerCrate( UInt_t crate ) const; // True if a Scaler crate
44  bool isBankStructure( UInt_t crate ) const; // True if modules in banks
45  UInt_t getNslot( UInt_t crate ) const; // Returns num occupied slots
46  UInt_t getMinSlot( UInt_t crate ) const; // Returns min slot number
47  UInt_t getMaxSlot( UInt_t crate ) const; // Returns max slot number
48 
49  // This class must inform the crateslot where the modules are.
50 
51  Int_t getModel( UInt_t crate, UInt_t slot ) const; // Return module type
52  UInt_t getHeader( UInt_t crate, UInt_t slot ) const;// Return header
53  UInt_t getMask( UInt_t crate, UInt_t slot ) const; // Return header mask
54  Int_t getBank( UInt_t crate, UInt_t slot ) const; // Return bank number
55  UInt_t getScalerCrate( UInt_t word) const; // Return scaler crate if word=header
56  const char* getScalerLoc( UInt_t crate ) const; // Return scaler crate location
57  const char* getConfigStr( UInt_t crate, UInt_t slot ) const; // Configuration string
58  UInt_t getNchan( UInt_t crate, UInt_t slot ) const; // Max number of channels
59  UInt_t getNdata( UInt_t crate, UInt_t slot ) const; // Max number of data words
60  bool crateUsed( UInt_t crate ) const; // True if crate is used
61  bool slotUsed( UInt_t crate, UInt_t slot ) const; // True if slot in crate is used
62  bool slotClear( UInt_t crate, UInt_t slot ) const; // Decide if not clear ea event
63  void setUnused( UInt_t crate, UInt_t slot ); // Disables this crate,slot
64  int init(const std::string& the_map); // Initialize from text-block
65  int init(ULong64_t time = 0); // Initialize by Unix time.
66  int init( FILE* fi, const char* fname ); // Initialize from given file
67  void print(std::ostream& os = std::cout) const;
68 
69  const std::vector<UInt_t>& GetUsedCrates() const;
70  const std::vector<UInt_t>& GetUsedSlots( UInt_t crate ) const;
71 
72  static const Int_t CM_OK;
73  static const Int_t CM_ERR;
74 
75  const char* GetName() const { return fDBfileName.c_str(); }
76 
77  private:
78 
79  enum ECrateCode { kUnknown, kFastbus, kVME, kScaler, kCamac };
80 
81  std::string fDBfileName; // Database file name
82  TDatime fInitTime; // Database time stamp
83 
84  class SlotInfo_t {
85  public:
86  SlotInfo_t() :
87  model(0), header(0), headmask(0xffffffff), bank(-1),
88  nchan(0), ndata(0), used(false), clear(true) {}
89  Int_t model;
90  UInt_t header;
91  UInt_t headmask;
92  Int_t bank;
93  UInt_t nchan;
94  UInt_t ndata;
95  std::string cfgstr;
96  bool used;
97  bool clear;
98  };
99 
100  class CrateInfo_t { // Crate Information data descriptor
101  public:
102  CrateInfo_t();
103  ECrateCode crate_code;
104  std::string crate_type_name;
105  std::string scalerloc;
106  bool crate_used;
107  bool bank_structure;
108  std::vector<UInt_t> used_slots;
109  std::array<SlotInfo_t, MAXSLOT> sltdat;
110  };
111  std::vector<CrateInfo_t> crdat;
112 
113  std::vector<UInt_t> used_crates;
114 
115  Int_t loadConfig( std::string& line, std::string& cfgstr );
116  Int_t setCrateType( UInt_t crate, const char* stype ); // set the crate type
117  Int_t setModel( UInt_t crate, UInt_t slot, Int_t mod,
118  UInt_t nchan= MAXCHAN,
119  UInt_t ndata= MAXDATA ); // set the module type
120  void setUsed( UInt_t crate, UInt_t slot );
121  Int_t SetModelSize( UInt_t crate, UInt_t slot, UInt_t model );
122 
123  static Int_t readFile( FILE* fi, std::string& text );
124 
125  ClassDef(THaCrateMap,0) // Map of modules in DAQ crates
126 };
127 
128 //=============== inline functions ================================
129 inline
130 bool THaCrateMap::isFastBus( UInt_t crate ) const
131 {
132  assert( crate < crdat.size() );
133  return (crdat[crate].crate_code == kFastbus);
134 }
135 
136 inline
137 bool THaCrateMap::isVme( UInt_t crate ) const
138 {
139  assert( crate < crdat.size() );
140  return (crdat[crate].crate_code == kVME ||
141  crdat[crate].crate_code == kScaler );
142 }
143 
144 inline
145 bool THaCrateMap::isCamac( UInt_t crate ) const
146 {
147  assert( crate < crdat.size() );
148  return (crdat[crate].crate_code == kCamac);
149 }
150 
151 inline
152 bool THaCrateMap::isScalerCrate( UInt_t crate ) const
153 {
154  assert( crate < crdat.size() );
155  return (crdat[crate].crate_code == kScaler);
156 }
157 
158 inline
159 bool THaCrateMap::isBankStructure( UInt_t crate ) const
160 {
161  assert( crate < crdat.size() );
162  return (crdat[crate].bank_structure);
163 }
164 
165 inline
166 bool THaCrateMap::crateUsed( UInt_t crate ) const
167 {
168  assert( crate < crdat.size() );
169  return crdat[crate].crate_used;
170 }
171 
172 inline
173 bool THaCrateMap::slotUsed( UInt_t crate, UInt_t slot ) const
174 {
175  assert( crate < crdat.size() && slot < crdat[crate].sltdat.size() );
176  if( crate >= crdat.size() || slot >= crdat[crate].sltdat.size() )
177  return false;
178  return crdat[crate].sltdat[slot].used;
179 }
180 
181 inline
182 bool THaCrateMap::slotClear( UInt_t crate, UInt_t slot ) const
183 {
184  assert( crate < crdat.size() && slot < crdat[crate].sltdat.size() );
185  return crdat[crate].sltdat[slot].clear;
186 }
187 
188 inline
189 Int_t THaCrateMap::getModel( UInt_t crate, UInt_t slot ) const
190 {
191  assert( crate < crdat.size() && slot < crdat[crate].sltdat.size() );
192  return crdat[crate].sltdat[slot].model;
193 }
194 
195 inline
196 UInt_t THaCrateMap::getMask( UInt_t crate, UInt_t slot ) const
197 {
198  assert( crate < crdat.size() && slot < crdat[crate].sltdat.size() );
199  return crdat[crate].sltdat[slot].headmask;
200 }
201 
202 inline
203 Int_t THaCrateMap::getBank( UInt_t crate, UInt_t slot ) const
204 {
205  assert( crate < crdat.size() && slot < crdat[crate].sltdat.size() );
206  return crdat[crate].sltdat[slot].bank;
207 }
208 
209 inline
210 UInt_t THaCrateMap::getNchan( UInt_t crate, UInt_t slot ) const
211 {
212  assert( crate < crdat.size() && slot < crdat[crate].sltdat.size() );
213  return crdat[crate].sltdat[slot].nchan;
214 }
215 
216 inline
217 UInt_t THaCrateMap::getNdata( UInt_t crate, UInt_t slot ) const
218 {
219  assert( crate < crdat.size() && slot < crdat[crate].sltdat.size() );
220  return crdat[crate].sltdat[slot].ndata;
221 }
222 
223 inline
224 UInt_t THaCrateMap::getNslot( UInt_t crate ) const
225 {
226  assert( crate < crdat.size() );
227  return crdat[crate].used_slots.size();
228 }
229 
230 inline
231 const char* THaCrateMap::getScalerLoc( UInt_t crate ) const
232 {
233  assert( crate < crdat.size() );
234  return crdat[crate].scalerloc.c_str();
235 }
236 
237 inline
238 const char* THaCrateMap::getConfigStr( UInt_t crate, UInt_t slot ) const
239 {
240  assert( crate < crdat.size() && slot < crdat[crate].sltdat.size() );
241  return crdat[crate].sltdat[slot].cfgstr.c_str();
242 }
243 
244 inline
245 UInt_t THaCrateMap::getMinSlot( UInt_t crate ) const
246 {
247  assert( crate < crdat.size() );
248  if( crdat[crate].used_slots.empty() )
249  return kMaxUInt;
250  return crdat[crate].used_slots.front();
251 }
252 
253 inline
254 UInt_t THaCrateMap::getMaxSlot( UInt_t crate ) const
255 {
256  assert( crate < crdat.size() );
257  if( crdat[crate].used_slots.empty() )
258  return 0;
259  return crdat[crate].used_slots.back();
260 }
261 
262 inline
263 UInt_t THaCrateMap::getHeader( UInt_t crate, UInt_t slot ) const
264 {
265  assert( crate < crdat.size() && slot < crdat[crate].sltdat.size() );
266  return crdat[crate].sltdat[slot].header;
267 }
268 
269 inline
270 const std::vector<UInt_t>& THaCrateMap::GetUsedCrates() const
271 {
272  return used_crates;
273 }
274 
275 inline
276 const std::vector<UInt_t>& THaCrateMap::GetUsedSlots( UInt_t crate ) const
277 {
278  assert( crate < crdat.size() );
279  return crdat[crate].used_slots;
280 }
281 
282 }
283 
284 #endif
void setUnused(UInt_t crate, UInt_t slot)
Definition: THaCrateMap.cxx:193
bool slotUsed(UInt_t crate, UInt_t slot) const
Definition: THaCrateMap.h:173
Int_t getBank(UInt_t crate, UInt_t slot) const
Definition: THaCrateMap.h:203
static const UInt_t MAXCHAN
Definition: THaCrateMap.h:35
virtual ~THaCrateMap()=default
void print(std::ostream &os=std::cout) const
Definition: THaCrateMap.cxx:274
bool slotClear(UInt_t crate, UInt_t slot) const
Definition: THaCrateMap.h:182
UInt_t getNchan(UInt_t crate, UInt_t slot) const
Definition: THaCrateMap.h:210
const char * GetName() const
Definition: THaCrateMap.h:75
int init(const std::string &the_map)
Definition: THaCrateMap.cxx:345
UInt_t getMinSlot(UInt_t crate) const
Definition: THaCrateMap.h:245
bool isScalerCrate(UInt_t crate) const
Definition: THaCrateMap.h:152
UInt_t getNdata(UInt_t crate, UInt_t slot) const
Definition: THaCrateMap.h:217
const char * getScalerLoc(UInt_t crate) const
Definition: THaCrateMap.h:231
bool crateUsed(UInt_t crate) const
Definition: THaCrateMap.h:166
bool isFastBus(UInt_t crate) const
Definition: THaCrateMap.h:130
UInt_t getNslot(UInt_t crate) const
Definition: THaCrateMap.h:224
THaCrateMap(const char *db="cratemap")
Definition: THaCrateMap.cxx:70
const std::vector< UInt_t > & GetUsedCrates() const
Definition: THaCrateMap.h:270
static const Int_t CM_OK
Definition: THaCrateMap.h:72
UInt_t getHeader(UInt_t crate, UInt_t slot) const
Definition: THaCrateMap.h:263
bool isBankStructure(UInt_t crate) const
Definition: THaCrateMap.h:159
UInt_t getMask(UInt_t crate, UInt_t slot) const
Definition: THaCrateMap.h:196
UInt_t getScalerCrate(UInt_t word) const
Definition: THaCrateMap.cxx:84
Int_t getModel(UInt_t crate, UInt_t slot) const
Definition: THaCrateMap.h:189
UInt_t getMaxSlot(UInt_t crate) const
Definition: THaCrateMap.h:254
const char * getConfigStr(UInt_t crate, UInt_t slot) const
Definition: THaCrateMap.h:238
static const Int_t CM_ERR
Definition: THaCrateMap.h:73
bool isVme(UInt_t crate) const
Definition: THaCrateMap.h:137
const std::vector< UInt_t > & GetUsedSlots(UInt_t crate) const
Definition: THaCrateMap.h:276
Definition: Caen1190Module.cxx:20
bool isCamac(UInt_t crate) const
Definition: THaCrateMap.h:145
static const UInt_t MAXDATA
Definition: THaCrateMap.h:36
Definition: THaCrateMap.h:33