Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:00:06

0001 #include "CaloOnlineTools/HcalOnlineDb/interface/ConfigurationDatabaseImpl.hh"
0002 #include "CaloOnlineTools/HcalOnlineDb/interface/ConfigurationDatabase.hh"
0003 #include "CaloOnlineTools/HcalOnlineDb/interface/ConfigurationItemNotFoundException.hh"
0004 #include "CaloOnlineTools/HcalOnlineDb/interface/PluginManager.hh"
0005 #include <cctype>
0006 
0007 #ifdef HAVE_XDAQ
0008 #include <toolbox/string.h>
0009 #else
0010 #include "CaloOnlineTools/HcalOnlineDb/interface/xdaq_compat.h"  // Includes typedef for log4cplus::Logger
0011 #endif
0012 
0013 namespace hcal {
0014 
0015   ConfigurationDatabase::ConfigurationDatabase(log4cplus::Logger logger) : m_logger(logger) {
0016     m_implementation = nullptr;
0017   }
0018 
0019   void ConfigurationDatabase::open(const std::string& accessor) noexcept(false) {
0020     if (m_implementationOptions.empty()) {
0021       std::vector<hcal::AbstractPluginFactory*> facts;
0022       hcal::PluginManager::getFactories("hcal::ConfigurationDatabaseImpl", facts);
0023       for (std::vector<hcal::AbstractPluginFactory*>::iterator j = facts.begin(); j != facts.end(); j++)
0024         m_implementationOptions.push_back(dynamic_cast<hcal::ConfigurationDatabaseImpl*>((*j)->newInstance()));
0025     }
0026 
0027     std::map<std::string, std::string> params;
0028     std::string user, host, method, db, port, password;
0029     ConfigurationDatabaseImpl::parseAccessor(accessor, method, host, port, user, db, params);
0030 
0031     if (m_implementation == nullptr || !m_implementation->canHandleMethod(method)) {
0032       m_implementation = nullptr;
0033       std::vector<ConfigurationDatabaseImpl*>::iterator j;
0034       for (j = m_implementationOptions.begin(); j != m_implementationOptions.end(); j++)
0035         if ((*j)->canHandleMethod(method)) {
0036           m_implementation = *j;
0037           break;
0038         }
0039     }
0040 
0041     if (m_implementation == nullptr)
0042       XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,
0043                   toolbox::toString("Unable to open database using '%s'", accessor.c_str()));
0044     m_implementation->setLogger(m_logger);
0045     m_implementation->connect(accessor);
0046   }
0047 
0048   void ConfigurationDatabase::close() {
0049     if (m_implementation != nullptr)
0050       m_implementation->disconnect();
0051   }
0052 
0053   unsigned int ConfigurationDatabase::getFirmwareChecksum(const std::string& board,
0054                                                           unsigned int version) noexcept(false) {
0055     if (m_implementation == nullptr) {
0056       XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException, "Database connection not open");
0057     }
0058 
0059     return m_implementation->getFirmwareChecksum(board, version);
0060   }
0061 
0062   ConfigurationDatabase::ApplicationConfig ConfigurationDatabase::getApplicationConfig(const std::string& tag,
0063                                                                                        const std::string& classname,
0064                                                                                        int instance) noexcept(false) {
0065     if (m_implementation == nullptr) {
0066       XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException, "Database connection not open");
0067     }
0068     return m_implementation->getApplicationConfig(tag, classname, instance);
0069   }
0070 
0071   std::string ConfigurationDatabase::getConfigurationDocument(const std::string& tag) noexcept(false) {
0072     if (m_implementation == nullptr) {
0073       XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException, "Database connection not open");
0074     }
0075     return m_implementation->getConfigurationDocument(tag);
0076   }
0077 
0078   void ConfigurationDatabase::getFirmwareMCS(const std::string& board,
0079                                              unsigned int version,
0080                                              std::vector<std::string>& mcsLines) noexcept(false) {
0081     if (m_implementation == nullptr) {
0082       XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException, "Database connection not open");
0083     }
0084 
0085     m_implementation->getFirmwareMCS(board, version, mcsLines);
0086   }
0087 
0088   void ConfigurationDatabase::getLUTs(const std::string& tag,
0089                                       int crate,
0090                                       int slot,
0091                                       std::map<LUTId, LUT>& LUTs) noexcept(false) {
0092     if (m_implementation == nullptr) {
0093       XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException, "Database connection not open");
0094     }
0095 
0096     std::map<unsigned int, std::string> results;
0097 
0098     m_implementation->getLUTs(tag, crate, slot, LUTs);
0099 
0100     if (LUTs.empty()) {
0101       XCEPT_RAISE(hcal::exception::ConfigurationItemNotFoundException,
0102                   toolbox::toString("Not enough found (%d)", LUTs.size()));
0103     }
0104   }
0105 
0106   void ConfigurationDatabase::getLUTChecksums(const std::string& tag,
0107                                               std::map<LUTId, MD5Fingerprint>& checksums) noexcept(false) {
0108     checksums.clear();
0109 
0110     if (m_implementation == nullptr) {
0111       XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException, "Database connection not open");
0112     }
0113 
0114     m_implementation->getLUTChecksums(tag, checksums);
0115   }
0116 
0117   void ConfigurationDatabase::getPatterns(const std::string& tag,
0118                                           int crate,
0119                                           int slot,
0120                                           std::map<PatternId, HTRPattern>& patterns) noexcept(false) {
0121     if (m_implementation == nullptr) {
0122       XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException, "Database connection not open");
0123     }
0124 
0125     m_implementation->getPatterns(tag, crate, slot, patterns);
0126 
0127     if (patterns.empty()) {
0128       XCEPT_RAISE(hcal::exception::ConfigurationItemNotFoundException,
0129                   toolbox::toString("Not found '$s',%d,%d", tag.c_str(), crate, slot));
0130     }
0131   }
0132 
0133   void ConfigurationDatabase::getRBXdata(const std::string& tag,
0134                                          const std::string& rbx,
0135                                          RBXdatumType dtype,
0136                                          std::map<RBXdatumId, RBXdatum>& RBXdata) noexcept(false) {
0137     if (m_implementation == nullptr) {
0138       XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException, "Database connection not open");
0139     }
0140 
0141     m_implementation->getRBXdata(tag, rbx, dtype, RBXdata);
0142   }
0143 
0144   void ConfigurationDatabase::getRBXpatterns(const std::string& tag,
0145                                              const std::string& rbx,
0146                                              std::map<RBXdatumId, RBXpattern>& patterns) noexcept(false) {
0147     if (m_implementation == nullptr) {
0148       XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException, "Database connection not open");
0149     }
0150 
0151     m_implementation->getRBXpatterns(tag, rbx, patterns);
0152   }
0153 
0154   void ConfigurationDatabase::getZSThresholds(const std::string& tag,
0155                                               int crate,
0156                                               int slot,
0157                                               std::map<ZSChannelId, int>& thresholds) noexcept(false) {
0158     if (m_implementation == nullptr) {
0159       XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException, "Database connection not open");
0160     }
0161 
0162     m_implementation->getZSThresholds(tag, crate, slot, thresholds);
0163   }
0164 
0165   void ConfigurationDatabase::getHLXMasks(const std::string& tag,
0166                                           int crate,
0167                                           int slot,
0168                                           std::map<FPGAId, HLXMasks>& m) noexcept(false) {
0169     if (m_implementation == nullptr) {
0170       XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException, "Database connection not open");
0171     }
0172 
0173     m_implementation->getHLXMasks(tag, crate, slot, m);
0174   }
0175 
0176   bool ConfigurationDatabase::FPGAId::operator<(const FPGAId& a) const {
0177     if (crate < a.crate)
0178       return true;
0179     if (crate > a.crate)
0180       return false;
0181     if (slot < a.slot)
0182       return true;
0183     if (slot > a.slot)
0184       return false;
0185     if (fpga < a.fpga)
0186       return true;
0187     if (fpga > a.fpga)
0188       return false;
0189     return false;  // equal is not less
0190   }
0191   bool ConfigurationDatabase::LUTId::operator<(const LUTId& a) const {
0192     if (crate < a.crate)
0193       return true;
0194     if (crate > a.crate)
0195       return false;
0196     if (slot < a.slot)
0197       return true;
0198     if (slot > a.slot)
0199       return false;
0200     if (fpga < a.fpga)
0201       return true;
0202     if (fpga > a.fpga)
0203       return false;
0204     if (fiber_slb < a.fiber_slb)
0205       return true;
0206     if (fiber_slb > a.fiber_slb)
0207       return false;
0208     if (channel < a.channel)
0209       return true;
0210     if (channel > a.channel)
0211       return false;
0212     if (lut_type < a.lut_type)
0213       return true;
0214     if (lut_type > a.lut_type)
0215       return false;
0216     return false;  // equal is not less
0217   }
0218   bool ConfigurationDatabase::PatternId::operator<(const PatternId& a) const {
0219     if (crate < a.crate)
0220       return true;
0221     if (crate > a.crate)
0222       return false;
0223     if (slot < a.slot)
0224       return true;
0225     if (slot > a.slot)
0226       return false;
0227     if (fpga < a.fpga)
0228       return true;
0229     if (fpga > a.fpga)
0230       return false;
0231     if (fiber < a.fiber)
0232       return true;
0233     if (fiber > a.fiber)
0234       return false;
0235     return false;  // equal is not less
0236   }
0237   bool ConfigurationDatabase::ZSChannelId::operator<(const ZSChannelId& a) const {
0238     if (crate < a.crate)
0239       return true;
0240     if (crate > a.crate)
0241       return false;
0242     if (slot < a.slot)
0243       return true;
0244     if (slot > a.slot)
0245       return false;
0246     if (fpga < a.fpga)
0247       return true;
0248     if (fpga > a.fpga)
0249       return false;
0250     if (fiber < a.fiber)
0251       return true;
0252     if (fiber > a.fiber)
0253       return false;
0254     if (channel < a.channel)
0255       return true;
0256     if (channel > a.channel)
0257       return false;
0258     return false;  // equal is not less
0259   }
0260   bool ConfigurationDatabase::RBXdatumId::operator<(const RBXdatumId& a) const {
0261     if (rm < a.rm)
0262       return true;
0263     if (rm > a.rm)
0264       return false;
0265     if (card < a.card)
0266       return true;
0267     if (card > a.card)
0268       return false;
0269     if (qie_or_gol < a.qie_or_gol)
0270       return true;
0271     if (qie_or_gol > a.qie_or_gol)
0272       return false;
0273     if (dtype < a.dtype)
0274       return true;
0275     if (dtype > a.dtype)
0276       return false;
0277     if (ltype < a.ltype)
0278       return true;
0279     if (ltype > a.ltype)
0280       return false;
0281     return false;  // equal is not less
0282   }
0283 
0284 }  // namespace hcal