CMS 3D CMS Logo

SiStripConfigDb.h
Go to the documentation of this file.
1 
2 #ifndef OnlineDB_SiStripConfigDb_SiStripConfigDb_h
3 #define OnlineDB_SiStripConfigDb_SiStripConfigDb_h
4 
5 #define DATABASE // Needed by DeviceFactory API! Do not comment!
6 //#define USING_DATABASE_MASKING
7 
17 #include "DeviceFactory.h"
18 #include "boost/range/iterator_range.hpp"
19 #include <iostream>
20 #include <fstream>
21 #include <sstream>
22 #include <ostream>
23 #include <vector>
24 #include <string>
25 #include <list>
26 #include <map>
27 #include <atomic>
28 
29 #include "DbClient.h"
30 #include <cstdint>
31 
32 namespace sistrip {
33  static const uint16_t FEC_CRATE_OFFSET = 0; //@@ temporary
34  static const uint16_t FEC_RING_OFFSET = 0; //@@ temporary
35 } // namespace sistrip
36 
37 // Friend class
38 namespace cms {
39  class SiStripO2O;
40 }
41 
48 public:
49  // ---------- Constructors, destructors ----------
50 
55 
57  ~SiStripConfigDb();
58 
59  // ---------- PROTECTED INTERFACE ----------
60 
61 protected:
62  /*
63  Access to the configuration database is reserved solely for the
64  commissioning (database) client and the online-to-offline transfer
65  tool. If you wish to use this interface to the configuration
66  database, then please contact one of the package administrators.
67  */
68 
69  // ESSources and O2O
74  friend class SiStripPsuDetIdMap;
75 
76  // Commissioning clients
77  friend class SiStripCommissioningDbClient;
81  friend class FedCablingHistosUsingDb;
82  friend class ApvTimingHistosUsingDb;
83  friend class OptoScanHistosUsingDb;
84  friend class PedestalsHistosUsingDb;
86  friend class PedsOnlyHistosUsingDb;
87  friend class NoiseHistosUsingDb;
88  friend class VpspScanHistosUsingDb;
89  friend class LatencyHistosUsingDb;
90  friend class FineDelayHistosUsingDb;
93 
94  // Utility and tests
95  friend class SiStripPartition;
96  friend class testSiStripConfigDb;
97 
98  // ---------- Typedefs ----------
99 
100  // FED connections
101  typedef ConnectionDescription FedConnection;
104  typedef std::vector<FedConnection*> FedConnectionsV;
105 
106  // Device descriptions
107  typedef enumDeviceType DeviceType;
108  typedef deviceDescription DeviceDescription;
111  typedef std::vector<DeviceDescription*> DeviceDescriptionsV;
112 
113  // FED descriptions
114  typedef Fed9U::Fed9UDescription FedDescription;
117  typedef std::vector<FedDescription*> FedDescriptionsV;
118 
119  // FED ids
120  typedef std::vector<uint16_t> FedIds;
121  typedef boost::iterator_range<FedIds::const_iterator> FedIdsRange;
122 
123  // DCU-DetId map
124  typedef Sgi::hash_map<unsigned long, TkDcuInfo*> DcuDetIdMap;
125  typedef std::pair<uint32_t, TkDcuInfo*> DcuDetId;
128  typedef std::vector<DcuDetId> DcuDetIdsV;
129 
130  // Analysis descriptions
131  typedef CommissioningAnalysisDescription::commissioningType AnalysisType;
132  typedef CommissioningAnalysisDescription AnalysisDescription;
135  typedef std::vector<AnalysisDescription*> AnalysisDescriptionsV;
136 
137  // ---------- Useful structs ----------
138 
142  public:
143  DeviceAddress();
144  void reset();
145  uint16_t fecCrate_;
146  uint16_t fecSlot_;
147  uint16_t fecRing_;
148  uint16_t ccuAddr_;
149  uint16_t ccuChan_;
150  uint16_t lldChan_;
151  uint16_t i2cAddr_;
152  uint16_t fedId_;
153  uint16_t feUnit_;
154  uint16_t feChan_;
155  };
156 
157  // ---------- Connection and useful methods ----------
158 
160  void openDbConnection();
161 
163  void closeDbConnection();
164 
166  inline const SiStripDbParams& dbParams() const;
167 
169  inline bool usingDb() const;
170 
172  DeviceFactory* const deviceFactory(std::string method_name = "") const;
173 
175  DbClient* const databaseCache(std::string method_name = "") const;
176 
177  // ---------- Run numbers for partitions and run types ----------
178 
179  class Run {
180  public:
183  uint16_t number_;
184  Run() : type_(sistrip::UNDEFINED_RUN_TYPE), partition_(""), number_(0) { ; }
185  };
186 
187  typedef std::vector<Run> Runs;
188 
189  typedef std::map<sistrip::RunType, Runs> RunsByType;
190 
191  typedef std::map<std::string, Runs> RunsByPartition;
192 
194  void runs(Runs&) const;
195 
197  void runs(const Runs& in, RunsByType& out, std::string optional_partition = "") const;
198 
200  void runs(const Runs& in, RunsByPartition& out, sistrip::RunType optional_type = sistrip::UNDEFINED_RUN_TYPE) const;
201 
203  void partitions(std::list<std::string>&) const;
204 
205  //@@ SiStripPartition::Versions ???
206 
207  // ---------- FED connections ----------
208 
210  FedConnectionsRange getFedConnections(std::string partition = "");
211 
213  void addFedConnections(std::string partition, FedConnectionsV&);
214 
216  void uploadFedConnections(std::string partition = "");
217 
219  void clearFedConnections(std::string partition = "");
220 
222  void printFedConnections(std::string partition = "");
223 
224  // ---------- FEC / Front-End devices ----------
225 
227  DeviceDescriptionsRange getDeviceDescriptions(std::string partition = "");
228 
231  DeviceDescriptionsRange getDeviceDescriptions(DeviceType, std::string partition = "");
232 
234  void addDeviceDescriptions(std::string partition, DeviceDescriptionsV&);
235 
237  void uploadDeviceDescriptions(std::string partition = "");
238 
240  void clearDeviceDescriptions(std::string partition = "");
241 
243  void printDeviceDescriptions(std::string partition = "");
244 
246  DeviceAddress deviceAddress(const deviceDescription&); //@@ uses temp offsets!
247 
248  // ---------- FED descriptions ----------
249 
251  FedDescriptionsRange getFedDescriptions(std::string partition = "");
252 
254  void addFedDescriptions(std::string partition, FedDescriptionsV&);
255 
257  void uploadFedDescriptions(std::string partition = "");
258 
260  void clearFedDescriptions(std::string partition = "");
261 
263  void printFedDescriptions(std::string partition = "");
264 
266  FedIdsRange getFedIds(std::string partition = "");
267 
269  inline bool usingStrips() const;
270 
272  inline void usingStrips(bool);
273 
274  // ---------- DCU-DetId info ----------
275 
277  DcuDetIdsRange getDcuDetIds(std::string partition = "");
278 
280  void addDcuDetIds(std::string partition, DcuDetIdsV&);
281 
283  void uploadDcuDetIds(std::string partition = "");
284 
286  void clearDcuDetIds(std::string partition = "");
287 
289  void printDcuDetIds(std::string partition = "");
290 
292  static DcuDetIdsV::const_iterator findDcuDetId(DcuDetIdsV::const_iterator begin,
293  DcuDetIdsV::const_iterator end,
294  uint32_t dcu_id);
295 
297  static DcuDetIdsV::iterator findDcuDetId(DcuDetIdsV::iterator begin, DcuDetIdsV::iterator end, uint32_t dcu_id);
298 
299  // ---------- Commissioning analyses ----------
300 
302  AnalysisDescriptionsRange getAnalysisDescriptions(AnalysisType, std::string partition = "");
303 
305  void addAnalysisDescriptions(std::string partition, AnalysisDescriptionsV&);
306 
308  void uploadAnalysisDescriptions(bool calibration_for_physics = false, std::string partition = "");
309 
311  void clearAnalysisDescriptions(std::string partition = "");
312 
314  void printAnalysisDescriptions(std::string partition = "");
315 
317  DeviceAddress deviceAddress(const AnalysisDescription&); //@@ uses temp offsets!
318 
320  std::string analysisType(AnalysisType) const;
321 
322 private:
323  // ---------- Private methods ----------
324 
326  void clearLocalCache();
327 
329  void usingDatabase();
330 
332  void usingDatabaseCache();
333 
335  void usingXmlFiles();
336 
338  void handleException(const std::string& method_name, const std::string& extra_info = "") const;
339 
341  bool checkFileExists(const std::string& path);
342 
344  std::string deviceType(const enumDeviceType& device_type) const;
345 
346  void clone(const DcuDetIdMap& in, DcuDetIdsV& out) const;
347 
348  void clone(const DcuDetIdsV& in, DcuDetIdMap& out) const;
349 
350  void clone(const DcuDetIdsV& in, DcuDetIdsV& out) const;
351 
352  // ---------- Database connection, partitions and versions ----------
353 
355  DeviceFactory* factory_;
356 
358  DbClient* dbCache_;
359 
362 
363  // ---------- Local cache of vectors ----------
364 
366  FedConnections connections_;
367 
369  DeviceDescriptions devices_;
370 
372  FedDescriptions feds_;
373 
375  DcuDetIds dcuDetIds_;
376 
378  AnalysisDescriptions analyses_;
379 
381  DeviceDescriptionsV apvDevices_;
382 
384  DeviceDescriptionsV muxDevices_;
385 
387  DeviceDescriptionsV dcuDevices_;
388 
390  DeviceDescriptionsV lldDevices_;
391 
393  DeviceDescriptionsV pllDevices_;
394 
396  DeviceDescriptionsV dohDevices_;
397 
399  DeviceDescriptionsV typedDevices_;
400 
402  FedIds fedIds_;
403 
404  // ---------- Miscellaneous ----------
405 
408 
411 
413  static std::atomic<uint32_t> cntr_;
414 
415  static std::atomic<bool> allowCalibUpload_;
416 };
417 
418 // ---------- Inline methods ----------
419 
421 const SiStripDbParams& SiStripConfigDb::dbParams() const { return dbParams_; }
422 
424 bool SiStripConfigDb::usingDb() const { return dbParams_.usingDb(); }
425 
427 bool SiStripConfigDb::usingStrips() const { return usingStrips_; }
428 
430 void SiStripConfigDb::usingStrips(bool using_strips) { usingStrips_ = using_strips; }
431 
432 #endif // OnlineDB_SiStripConfigDb_SiStripConfigDb_h
DeviceDescriptionsV apvDevices_
bool usingStrips() const
DeviceDescriptionsV typedDevices_
DeviceDescriptionsV dohDevices_
DcuDetIds::range DcuDetIdsRange
DeviceFactory * factory_
DeviceDescriptionsV lldDevices_
static const uint16_t FEC_RING_OFFSET
AnalysisDescriptions analyses_
Sgi::hash_map< unsigned long, TkDcuInfo * > DcuDetIdMap
FedDescriptions::range FedDescriptionsRange
std::vector< uint16_t > FedIds
Constants and enumerated type for sistrip::RunType.
Extension to SiStripConfigDb to map PSU channels to DetIDs using DCU-PSU map and DCU-DetID map...
std::map< std::string, Runs > RunsByPartition
ConnectionDescription FedConnection
edm::MapOfVectors< std::string, DeviceDescription * > DeviceDescriptions
FedConnections connections_
sistrip classes
DeviceDescriptionsV pllDevices_
Class which reads a root file containing "commissioning histograms", analyzes the histograms to extra...
edm::MapOfVectors< std::string, DcuDetId > DcuDetIds
FedConnections::range FedConnectionsRange
DeviceDescriptionsV dcuDevices_
edm::MapOfVectors< std::string, AnalysisDescription * > AnalysisDescriptions
bool usingDb() const
enumDeviceType DeviceType
CommissioningAnalysisDescription AnalysisDescription
DeviceDescriptions::range DeviceDescriptionsRange
An interface class to the DeviceFactory.
static std::atomic< uint32_t > cntr_
FedDescriptions feds_
Container class for database partition parameters.
#define end
Definition: vmac.h:39
std::map< sistrip::RunType, Runs > RunsByType
Fed9U::Fed9UDescription FedDescription
deviceDescription DeviceDescription
std::vector< Run > Runs
Namespace of DDCMS conversion namespace.
sistrip::RunType type_
std::vector< DcuDetId > DcuDetIdsV
const SiStripDbParams & dbParams() const
AnalysisDescriptions::range AnalysisDescriptionsRange
Container class for database connection parameters.
CommissioningAnalysisDescription::commissioningType AnalysisType
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
boost::iterator_range< FedIds::const_iterator > FedIdsRange
DeviceDescriptionsV muxDevices_
DeviceDescriptions devices_
edm::MapOfVectors< std::string, FedDescription * > FedDescriptions
SiStripDbParams dbParams_
#define begin
Definition: vmac.h:32
std::vector< AnalysisDescription * > AnalysisDescriptionsV
static const uint16_t FEC_CRATE_OFFSET
static std::atomic< bool > allowCalibUpload_
boost::iterator_range< data_iterator > range
Definition: MapOfVectors.h:33
std::vector< FedConnection * > FedConnectionsV
DbClient * dbCache_
std::pair< uint32_t, TkDcuInfo * > DcuDetId
std::vector< FedDescription * > FedDescriptionsV
void reset(double vett[256])
Definition: TPedValues.cc:11
std::vector< DeviceDescription * > DeviceDescriptionsV
DcuDetIds dcuDetIds_
edm::MapOfVectors< std::string, FedConnection * > FedConnections