File indexing completed on 2024-04-06 12:23:16
0001
0002 #ifndef OnlineDB_SiStripConfigDb_SiStripConfigDb_h
0003 #define OnlineDB_SiStripConfigDb_SiStripConfigDb_h
0004
0005 #define DATABASE
0006
0007
0008 #include "FWCore/Utilities/interface/Exception.h"
0009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0010 #include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
0011 #include "DataFormats/Common/interface/MapOfVectors.h"
0012 #include "DataFormats/SiStripCommon/interface/ConstantsForRunType.h"
0013 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
0014 #include "DataFormats/SiStripCommon/interface/SiStripFecKey.h"
0015 #include "CalibFormats/SiStripObjects/interface/SiStripFecCabling.h"
0016 #include "OnlineDB/SiStripConfigDb/interface/SiStripDbParams.h"
0017 #include "DeviceFactory.h"
0018 #include "boost/range/iterator_range.hpp"
0019 #include <iostream>
0020 #include <fstream>
0021 #include <sstream>
0022 #include <ostream>
0023 #include <vector>
0024 #include <string>
0025 #include <list>
0026 #include <map>
0027 #include <atomic>
0028
0029 #include "DbClient.h"
0030 #include <cstdint>
0031
0032 namespace sistrip {
0033 static const uint16_t FEC_CRATE_OFFSET = 0;
0034 static const uint16_t FEC_RING_OFFSET = 0;
0035 }
0036
0037
0038 namespace cms {
0039 class SiStripO2O;
0040 }
0041
0042
0043
0044
0045
0046
0047 class SiStripConfigDb {
0048 public:
0049
0050
0051
0052
0053
0054 SiStripConfigDb(const edm::ParameterSet&, const edm::ActivityRegistry&);
0055
0056
0057 ~SiStripConfigDb();
0058
0059
0060
0061 protected:
0062
0063
0064
0065
0066
0067
0068
0069
0070 friend class SiStripFedCablingBuilderFromDb;
0071 friend class SiStripPedestalsBuilderFromDb;
0072 friend class SiStripNoiseBuilderFromDb;
0073 friend class SiStripCondObjBuilderFromDb;
0074 friend class SiStripPsuDetIdMap;
0075
0076
0077 friend class SiStripCommissioningDbClient;
0078 friend class SiStripCommissioningOfflineDbClient;
0079 friend class CommissioningHistosUsingDb;
0080 friend class FastFedCablingHistosUsingDb;
0081 friend class FedCablingHistosUsingDb;
0082 friend class ApvTimingHistosUsingDb;
0083 friend class OptoScanHistosUsingDb;
0084 friend class PedestalsHistosUsingDb;
0085 friend class PedsFullNoiseHistosUsingDb;
0086 friend class PedsOnlyHistosUsingDb;
0087 friend class NoiseHistosUsingDb;
0088 friend class VpspScanHistosUsingDb;
0089 friend class LatencyHistosUsingDb;
0090 friend class FineDelayHistosUsingDb;
0091 friend class CalibrationHistosUsingDb;
0092 friend class DaqScopeModeHistosUsingDb;
0093
0094
0095 friend class SiStripPartition;
0096 friend class testSiStripConfigDb;
0097
0098
0099
0100
0101 typedef ConnectionDescription FedConnection;
0102 typedef edm::MapOfVectors<std::string, FedConnection*> FedConnections;
0103 typedef FedConnections::range FedConnectionsRange;
0104 typedef std::vector<FedConnection*> FedConnectionsV;
0105
0106
0107 typedef enumDeviceType DeviceType;
0108 typedef deviceDescription DeviceDescription;
0109 typedef edm::MapOfVectors<std::string, DeviceDescription*> DeviceDescriptions;
0110 typedef DeviceDescriptions::range DeviceDescriptionsRange;
0111 typedef std::vector<DeviceDescription*> DeviceDescriptionsV;
0112
0113
0114 typedef Fed9U::Fed9UDescription FedDescription;
0115 typedef edm::MapOfVectors<std::string, FedDescription*> FedDescriptions;
0116 typedef FedDescriptions::range FedDescriptionsRange;
0117 typedef std::vector<FedDescription*> FedDescriptionsV;
0118
0119
0120 typedef std::vector<uint16_t> FedIds;
0121 typedef boost::iterator_range<FedIds::const_iterator> FedIdsRange;
0122
0123
0124 typedef Sgi::hash_map<unsigned long, TkDcuInfo*> DcuDetIdMap;
0125 typedef std::pair<uint32_t, TkDcuInfo*> DcuDetId;
0126 typedef edm::MapOfVectors<std::string, DcuDetId> DcuDetIds;
0127 typedef DcuDetIds::range DcuDetIdsRange;
0128 typedef std::vector<DcuDetId> DcuDetIdsV;
0129
0130
0131 typedef CommissioningAnalysisDescription::commissioningType AnalysisType;
0132 typedef CommissioningAnalysisDescription AnalysisDescription;
0133 typedef edm::MapOfVectors<std::string, AnalysisDescription*> AnalysisDescriptions;
0134 typedef AnalysisDescriptions::range AnalysisDescriptionsRange;
0135 typedef std::vector<AnalysisDescription*> AnalysisDescriptionsV;
0136
0137
0138
0139
0140
0141 class DeviceAddress {
0142 public:
0143 DeviceAddress();
0144 void reset();
0145 uint16_t fecCrate_;
0146 uint16_t fecSlot_;
0147 uint16_t fecRing_;
0148 uint16_t ccuAddr_;
0149 uint16_t ccuChan_;
0150 uint16_t lldChan_;
0151 uint16_t i2cAddr_;
0152 uint16_t fedId_;
0153 uint16_t feUnit_;
0154 uint16_t feChan_;
0155 };
0156
0157
0158
0159
0160 void openDbConnection();
0161
0162
0163 void closeDbConnection();
0164
0165
0166 inline const SiStripDbParams& dbParams() const;
0167
0168
0169 inline bool usingDb() const;
0170
0171
0172 DeviceFactory* const deviceFactory(std::string method_name = "") const;
0173
0174
0175 DbClient* const databaseCache(std::string method_name = "") const;
0176
0177
0178
0179 class Run {
0180 public:
0181 sistrip::RunType type_;
0182 std::string partition_;
0183 uint16_t number_;
0184 Run() : type_(sistrip::UNDEFINED_RUN_TYPE), partition_(""), number_(0) { ; }
0185 };
0186
0187 typedef std::vector<Run> Runs;
0188
0189 typedef std::map<sistrip::RunType, Runs> RunsByType;
0190
0191 typedef std::map<std::string, Runs> RunsByPartition;
0192
0193
0194 void runs(Runs&) const;
0195
0196
0197 void runs(const Runs& in, RunsByType& out, std::string optional_partition = "") const;
0198
0199
0200 void runs(const Runs& in, RunsByPartition& out, sistrip::RunType optional_type = sistrip::UNDEFINED_RUN_TYPE) const;
0201
0202
0203 void partitions(std::list<std::string>&) const;
0204
0205
0206
0207
0208
0209
0210 FedConnectionsRange getFedConnections(std::string partition = "");
0211
0212
0213 void addFedConnections(std::string partition, FedConnectionsV&);
0214
0215
0216 void uploadFedConnections(std::string partition = "");
0217
0218
0219 void clearFedConnections(std::string partition = "");
0220
0221
0222 void printFedConnections(std::string partition = "");
0223
0224
0225
0226
0227 DeviceDescriptionsRange getDeviceDescriptions(std::string partition = "");
0228
0229
0230
0231 DeviceDescriptionsRange getDeviceDescriptions(DeviceType, std::string partition = "");
0232
0233
0234 void addDeviceDescriptions(std::string partition, DeviceDescriptionsV&);
0235
0236
0237 void uploadDeviceDescriptions(std::string partition = "");
0238
0239
0240 void clearDeviceDescriptions(std::string partition = "");
0241
0242
0243 void printDeviceDescriptions(std::string partition = "");
0244
0245
0246 DeviceAddress deviceAddress(const deviceDescription&);
0247
0248
0249
0250
0251 FedDescriptionsRange getFedDescriptions(std::string partition = "");
0252
0253
0254 void addFedDescriptions(std::string partition, FedDescriptionsV&);
0255
0256
0257 void uploadFedDescriptions(std::string partition = "");
0258
0259
0260 void clearFedDescriptions(std::string partition = "");
0261
0262
0263 void printFedDescriptions(std::string partition = "");
0264
0265
0266 FedIdsRange getFedIds(std::string partition = "");
0267
0268
0269 inline bool usingStrips() const;
0270
0271
0272 inline void usingStrips(bool);
0273
0274
0275
0276
0277 DcuDetIdsRange getDcuDetIds(std::string partition = "");
0278
0279
0280 void addDcuDetIds(std::string partition, DcuDetIdsV&);
0281
0282
0283 void uploadDcuDetIds(std::string partition = "");
0284
0285
0286 void clearDcuDetIds(std::string partition = "");
0287
0288
0289 void printDcuDetIds(std::string partition = "");
0290
0291
0292 static DcuDetIdsV::const_iterator findDcuDetId(DcuDetIdsV::const_iterator begin,
0293 DcuDetIdsV::const_iterator end,
0294 uint32_t dcu_id);
0295
0296
0297 static DcuDetIdsV::iterator findDcuDetId(DcuDetIdsV::iterator begin, DcuDetIdsV::iterator end, uint32_t dcu_id);
0298
0299
0300
0301
0302 AnalysisDescriptionsRange getAnalysisDescriptions(AnalysisType, std::string partition = "");
0303
0304
0305 void addAnalysisDescriptions(std::string partition, AnalysisDescriptionsV&);
0306
0307
0308 void uploadAnalysisDescriptions(bool calibration_for_physics = false, std::string partition = "");
0309
0310
0311 void clearAnalysisDescriptions(std::string partition = "");
0312
0313
0314 void printAnalysisDescriptions(std::string partition = "");
0315
0316
0317 DeviceAddress deviceAddress(const AnalysisDescription&);
0318
0319
0320 std::string analysisType(AnalysisType) const;
0321
0322 private:
0323
0324
0325
0326 void clearLocalCache();
0327
0328
0329 void usingDatabase();
0330
0331
0332 void usingDatabaseCache();
0333
0334
0335 void usingXmlFiles();
0336
0337
0338 void handleException(const std::string& method_name, const std::string& extra_info = "") const;
0339
0340
0341 bool checkFileExists(const std::string& path);
0342
0343
0344 std::string deviceType(const enumDeviceType& device_type) const;
0345
0346 void clone(const DcuDetIdMap& in, DcuDetIdsV& out) const;
0347
0348 void clone(const DcuDetIdsV& in, DcuDetIdMap& out) const;
0349
0350 void clone(const DcuDetIdsV& in, DcuDetIdsV& out) const;
0351
0352
0353
0354
0355 DeviceFactory* factory_;
0356
0357
0358 DbClient* dbCache_;
0359
0360
0361 SiStripDbParams dbParams_;
0362
0363
0364
0365
0366 FedConnections connections_;
0367
0368
0369 DeviceDescriptions devices_;
0370
0371
0372 FedDescriptions feds_;
0373
0374
0375 DcuDetIds dcuDetIds_;
0376
0377
0378 AnalysisDescriptions analyses_;
0379
0380
0381 DeviceDescriptionsV apvDevices_;
0382
0383
0384 DeviceDescriptionsV muxDevices_;
0385
0386
0387 DeviceDescriptionsV dcuDevices_;
0388
0389
0390 DeviceDescriptionsV lldDevices_;
0391
0392
0393 DeviceDescriptionsV pllDevices_;
0394
0395
0396 DeviceDescriptionsV dohDevices_;
0397
0398
0399 DeviceDescriptionsV typedDevices_;
0400
0401
0402 FedIds fedIds_;
0403
0404
0405
0406
0407 bool usingStrips_;
0408
0409
0410 bool openConnection_;
0411
0412
0413 static std::atomic<uint32_t> cntr_;
0414
0415 static std::atomic<bool> allowCalibUpload_;
0416 };
0417
0418
0419
0420
0421 const SiStripDbParams& SiStripConfigDb::dbParams() const { return dbParams_; }
0422
0423
0424 bool SiStripConfigDb::usingDb() const { return dbParams_.usingDb(); }
0425
0426
0427 bool SiStripConfigDb::usingStrips() const { return usingStrips_; }
0428
0429
0430 void SiStripConfigDb::usingStrips(bool using_strips) { usingStrips_ = using_strips; }
0431
0432 #endif