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 "boost/cstdint.hpp"
20 #include <iostream>
21 #include <fstream>
22 #include <sstream>
23 #include <ostream>
24 #include <vector>
25 #include <string>
26 #include <list>
27 #include <map>
28 #include <atomic>
29 
30 #include "DbClient.h"
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 }
36 
37 // Friend class
38 namespace cms { class SiStripO2O; }
39 
46 
47  public:
48 
49 
50  // ---------- Constructors, destructors ----------
51 
52 
57  const edm::ActivityRegistry& );
58 
60  ~SiStripConfigDb();
61 
62 
63  // ---------- PROTECTED INTERFACE ----------
64 
65 
66  protected:
67 
68  /*
69  Access to the configuration database is reserved solely for the
70  commissioning (database) client and the online-to-offline transfer
71  tool. If you wish to use this interface to the configuration
72  database, then please contact one of the package administrators.
73  */
74 
75  // ESSources and O2O
80  friend class SiStripPsuDetIdMap;
81 
82 
83  // Commissioning clients
84  friend class SiStripCommissioningDbClient;
88  friend class FedCablingHistosUsingDb;
89  friend class ApvTimingHistosUsingDb;
90  friend class OptoScanHistosUsingDb;
91  friend class PedestalsHistosUsingDb;
93  friend class PedsOnlyHistosUsingDb;
94  friend class NoiseHistosUsingDb;
95  friend class VpspScanHistosUsingDb;
96  friend class LatencyHistosUsingDb;
97  friend class FineDelayHistosUsingDb;
100 
101  // Utility and tests
102  friend class SiStripPartition;
103  friend class testSiStripConfigDb;
104 
105 
106 
107  // ---------- Typedefs ----------
108 
109 
110  // FED connections
111  typedef ConnectionDescription FedConnection;
114  typedef std::vector<FedConnection*> FedConnectionsV;
115 
116  // Device descriptions
117  typedef enumDeviceType DeviceType;
118  typedef deviceDescription DeviceDescription;
121  typedef std::vector<DeviceDescription*> DeviceDescriptionsV;
122 
123  // FED descriptions
124  typedef Fed9U::Fed9UDescription FedDescription;
127  typedef std::vector<FedDescription*> FedDescriptionsV;
128 
129  // FED ids
130  typedef std::vector<uint16_t> FedIds;
131  typedef boost::iterator_range<FedIds::const_iterator> FedIdsRange;
132 
133  // DCU-DetId map
134  typedef Sgi::hash_map<unsigned long,TkDcuInfo*> DcuDetIdMap;
135  typedef std::pair<uint32_t,TkDcuInfo*> DcuDetId;
138  typedef std::vector<DcuDetId> DcuDetIdsV;
139 
140 
141  // Analysis descriptions
142  typedef CommissioningAnalysisDescription::commissioningType AnalysisType;
143  typedef CommissioningAnalysisDescription AnalysisDescription;
146  typedef std::vector<AnalysisDescription*> AnalysisDescriptionsV;
147 
148 
149  // ---------- Useful structs ----------
150 
151 
154  class DeviceAddress {
155  public:
156  DeviceAddress();
157  void reset();
158  uint16_t fecCrate_;
159  uint16_t fecSlot_;
160  uint16_t fecRing_;
161  uint16_t ccuAddr_;
162  uint16_t ccuChan_;
163  uint16_t lldChan_;
164  uint16_t i2cAddr_;
165  uint16_t fedId_;
166  uint16_t feUnit_;
167  uint16_t feChan_;
168  };
169 
170 
171  // ---------- Connection and useful methods ----------
172 
173 
175  void openDbConnection();
176 
178  void closeDbConnection();
179 
181  inline const SiStripDbParams& dbParams() const;
182 
184  inline bool usingDb() const;
185 
187  DeviceFactory* const deviceFactory( std::string method_name = "" ) const;
188 
190  DbClient* const databaseCache( std::string method_name = "" ) const;
191 
192 
193  // ---------- Run numbers for partitions and run types ----------
194 
195 
196  class Run {
197  public:
200  uint16_t number_;
201  Run() : type_(sistrip::UNDEFINED_RUN_TYPE), partition_(""), number_(0) {;}
202  };
203 
204  typedef std::vector<Run> Runs;
205 
206  typedef std::map<sistrip::RunType,Runs> RunsByType;
207 
208  typedef std::map<std::string,Runs> RunsByPartition;
209 
211  void runs( Runs& ) const;
212 
214  void runs( const Runs& in,
215  RunsByType& out,
216  std::string optional_partition = "" ) const;
217 
219  void runs( const Runs& in,
220  RunsByPartition& out,
221  sistrip::RunType optional_type = sistrip::UNDEFINED_RUN_TYPE ) const;
222 
224  void partitions( std::list<std::string>& ) const;
225 
226  //@@ SiStripPartition::Versions ???
227 
228 
229  // ---------- FED connections ----------
230 
231 
233  FedConnectionsRange getFedConnections( std::string partition = "" );
234 
236  void addFedConnections( std::string partition, FedConnectionsV& );
237 
239  void uploadFedConnections( std::string partition = "" );
240 
242  void clearFedConnections( std::string partition = "" );
243 
245  void printFedConnections( std::string partition = "" );
246 
247 
248  // ---------- FEC / Front-End devices ----------
249 
250 
252  DeviceDescriptionsRange getDeviceDescriptions( std::string partition = "" );
253 
256  DeviceDescriptionsRange getDeviceDescriptions( DeviceType, std::string partition = "" );
257 
259  void addDeviceDescriptions( std::string partition, DeviceDescriptionsV& );
260 
262  void uploadDeviceDescriptions( std::string partition = "" );
263 
265  void clearDeviceDescriptions( std::string partition = "" );
266 
268  void printDeviceDescriptions( std::string partition = "" );
269 
271  DeviceAddress deviceAddress( const deviceDescription& ); //@@ uses temp offsets!
272 
273 
274  // ---------- FED descriptions ----------
275 
276 
278  FedDescriptionsRange getFedDescriptions( std::string partition = "" );
279 
281  void addFedDescriptions( std::string partition, FedDescriptionsV& );
282 
284  void uploadFedDescriptions( std::string partition = "" );
285 
287  void clearFedDescriptions( std::string partition = "" );
288 
290  void printFedDescriptions( std::string partition = "" );
291 
293  FedIdsRange getFedIds( std::string partition = "" );
294 
296  inline bool usingStrips() const;
297 
299  inline void usingStrips( bool );
300 
301 
302  // ---------- DCU-DetId info ----------
303 
304 
306  DcuDetIdsRange getDcuDetIds( std::string partition = "" );
307 
309  void addDcuDetIds( std::string partition, DcuDetIdsV& );
310 
312  void uploadDcuDetIds( std::string partition = "" );
313 
315  void clearDcuDetIds( std::string partition = "" );
316 
318  void printDcuDetIds( std::string partition = "" );
319 
321  static DcuDetIdsV::const_iterator findDcuDetId( DcuDetIdsV::const_iterator begin,
322  DcuDetIdsV::const_iterator end,
323  uint32_t dcu_id );
324 
326  static DcuDetIdsV::iterator findDcuDetId( DcuDetIdsV::iterator begin,
327  DcuDetIdsV::iterator end,
328  uint32_t dcu_id );
329 
330 
331  // ---------- Commissioning analyses ----------
332 
333 
335  AnalysisDescriptionsRange getAnalysisDescriptions( AnalysisType, std::string partition = "" );
336 
338  void addAnalysisDescriptions( std::string partition, AnalysisDescriptionsV& );
339 
341  void uploadAnalysisDescriptions( bool calibration_for_physics = false, std::string partition = "" );
342 
344  void clearAnalysisDescriptions( std::string partition = "" );
345 
347  void printAnalysisDescriptions( std::string partition = "" );
348 
350  DeviceAddress deviceAddress( const AnalysisDescription& ); //@@ uses temp offsets!
351 
353  std::string analysisType( AnalysisType ) const;
354 
355 
356  private:
357 
358 
359  // ---------- Private methods ----------
360 
361 
363  void clearLocalCache();
364 
366  void usingDatabase();
367 
369  void usingDatabaseCache();
370 
372  void usingXmlFiles();
373 
375  void handleException( const std::string& method_name,
376  const std::string& extra_info = "" ) const;
377 
379  bool checkFileExists( const std::string& path );
380 
382  std::string deviceType( const enumDeviceType& device_type ) const;
383 
384  void clone( const DcuDetIdMap& in, DcuDetIdsV& out ) const;
385 
386  void clone( const DcuDetIdsV& in, DcuDetIdMap& out ) const;
387 
388  void clone( const DcuDetIdsV& in, DcuDetIdsV& out ) const;
389 
390 
391  // ---------- Database connection, partitions and versions ----------
392 
393 
395  DeviceFactory* factory_;
396 
398  DbClient* dbCache_;
399 
402 
403 
404  // ---------- Local cache of vectors ----------
405 
406 
408  FedConnections connections_;
409 
411  DeviceDescriptions devices_;
412 
414  FedDescriptions feds_;
415 
417  DcuDetIds dcuDetIds_;
418 
420  AnalysisDescriptions analyses_;
421 
423  DeviceDescriptionsV apvDevices_;
424 
426  DeviceDescriptionsV muxDevices_;
427 
429  DeviceDescriptionsV dcuDevices_;
430 
432  DeviceDescriptionsV lldDevices_;
433 
435  DeviceDescriptionsV pllDevices_;
436 
438  DeviceDescriptionsV dohDevices_;
439 
441  DeviceDescriptionsV typedDevices_;
442 
444  FedIds fedIds_;
445 
446 
447  // ---------- Miscellaneous ----------
448 
449 
452 
455 
457  static std::atomic<uint32_t> cntr_;
458 
459  static std::atomic<bool> allowCalibUpload_;
460 
461 
462 };
463 
464 
465 // ---------- Inline methods ----------
466 
467 
469 const SiStripDbParams& SiStripConfigDb::dbParams() const { return dbParams_; }
470 
472 bool SiStripConfigDb::usingDb() const { return dbParams_.usingDb(); }
473 
475 bool SiStripConfigDb::usingStrips() const { return usingStrips_; }
476 
478 void SiStripConfigDb::usingStrips( bool using_strips ) { usingStrips_ = using_strips; }
479 
480 
481 #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
edm::MapOfVectors< std::string, DcuDetId > DcuDetIds
AnalysisDescriptions analyses_
FedDescriptions::range FedDescriptionsRange
std::map< std::string, Runs > RunsByPartition
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...
ConnectionDescription FedConnection
FedConnections connections_
sistrip classes
DeviceDescriptionsV pllDevices_
Class which reads a root file containing "commissioning histograms", analyzes the histograms to extra...
FedConnections::range FedConnectionsRange
edm::MapOfVectors< std::string, FedDescription * > FedDescriptions
DeviceDescriptionsV dcuDevices_
bool usingDb() const
enumDeviceType DeviceType
edm::MapOfVectors< std::string, DeviceDescription * > DeviceDescriptions
CommissioningAnalysisDescription AnalysisDescription
DeviceDescriptions::range DeviceDescriptionsRange
edm::MapOfVectors< std::string, AnalysisDescription * > AnalysisDescriptions
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
Fed9U::Fed9UDescription FedDescription
deviceDescription DeviceDescription
std::vector< Run > Runs
Namespace of DDCMS conversion namespace.
std::map< sistrip::RunType, Runs > RunsByType
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
edm::MapOfVectors< std::string, FedConnection * > FedConnections
boost::iterator_range< FedIds::const_iterator > FedIdsRange
Sgi::hash_map< unsigned long, TkDcuInfo * > DcuDetIdMap
DeviceDescriptionsV muxDevices_
DeviceDescriptions devices_
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:34
std::vector< FedConnection * > FedConnectionsV
DbClient * dbCache_
std::vector< FedDescription * > FedDescriptionsV
void reset(double vett[256])
Definition: TPedValues.cc:11
std::vector< DeviceDescription * > DeviceDescriptionsV
std::pair< uint32_t, TkDcuInfo * > DcuDetId
DcuDetIds dcuDetIds_