CMS 3D CMS Logo

ConfigurationDatabase.cc
Go to the documentation of this file.
1 #include "CaloOnlineTools/HcalOnlineDb/interface/ConfigurationDatabaseImpl.hh"
2 #include "CaloOnlineTools/HcalOnlineDb/interface/ConfigurationDatabase.hh"
3 #include "CaloOnlineTools/HcalOnlineDb/interface/ConfigurationItemNotFoundException.hh"
4 #include "CaloOnlineTools/HcalOnlineDb/interface/PluginManager.hh"
5 #include <cctype>
6 
7 #ifdef HAVE_XDAQ
8 #include <toolbox/string.h>
9 #else
10 #include "CaloOnlineTools/HcalOnlineDb/interface/xdaq_compat.h" // Includes typedef for log4cplus::Logger
11 #endif
12 
13 namespace hcal {
14 
15  ConfigurationDatabase::ConfigurationDatabase(log4cplus::Logger logger) : m_logger(logger) {
16  m_implementation=nullptr;
17  }
18 
19  void ConfigurationDatabase::open(const std::string& accessor) noexcept(false) {
20  if (m_implementationOptions.empty()) {
21  std::vector<hcal::AbstractPluginFactory*> facts;
22  hcal::PluginManager::getFactories("hcal::ConfigurationDatabaseImpl",facts);
23  for (std::vector<hcal::AbstractPluginFactory*>::iterator j=facts.begin(); j!=facts.end(); j++)
24  m_implementationOptions.push_back(dynamic_cast<hcal::ConfigurationDatabaseImpl*>((*j)->newInstance()));
25  }
26 
27  std::map<std::string,std::string> params;
28  std::string user, host, method, db, port,password;
29  ConfigurationDatabaseImpl::parseAccessor(accessor,method,host,port,user,db,params);
30 
31  if (m_implementation==nullptr || !m_implementation->canHandleMethod(method)) {
32  m_implementation=nullptr;
33  std::vector<ConfigurationDatabaseImpl*>::iterator j;
34  for (j=m_implementationOptions.begin(); j!=m_implementationOptions.end(); j++)
35  if ((*j)->canHandleMethod(method)) {
36  m_implementation=*j;
37  break;
38  }
39  }
40 
41  if (m_implementation==nullptr)
42  XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,toolbox::toString("Unable to open database using '%s'",accessor.c_str()));
43  m_implementation->setLogger(m_logger);
44  m_implementation->connect(accessor);
45 
46  }
47 
48  void ConfigurationDatabase::close() {
49  if (m_implementation!=nullptr) m_implementation->disconnect();
50  }
51 
52  unsigned int ConfigurationDatabase::getFirmwareChecksum(const std::string& board, unsigned int version) noexcept(false) {
53  if (m_implementation==nullptr) {
54  XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,"Database connection not open");
55  }
56 
57  return m_implementation->getFirmwareChecksum(board,version);
58  }
59 
60  ConfigurationDatabase::ApplicationConfig ConfigurationDatabase::getApplicationConfig(const std::string& tag, const std::string& classname, int instance) noexcept(false) {
61  if (m_implementation==nullptr) {
62  XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,"Database connection not open");
63  }
64  return m_implementation->getApplicationConfig(tag,classname,instance);
65 
66  }
67 
68 
69  std::string ConfigurationDatabase::getConfigurationDocument(const std::string& tag) noexcept(false) {
70  if (m_implementation==nullptr) {
71  XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,"Database connection not open");
72  }
73  return m_implementation->getConfigurationDocument(tag);
74  }
75 
76  void ConfigurationDatabase::getFirmwareMCS(const std::string& board, unsigned int version, std::vector<std::string>& mcsLines) noexcept(false) {
77  if (m_implementation==nullptr) {
78  XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,"Database connection not open");
79  }
80 
81  m_implementation->getFirmwareMCS(board, version, mcsLines);
82 
83  }
84 
85  void ConfigurationDatabase::getLUTs(const std::string& tag, int crate, int slot, std::map<LUTId, LUT >& LUTs) noexcept(false) {
86 
87  if (m_implementation==nullptr) {
88  XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,"Database connection not open");
89  }
90 
91  std::map<unsigned int, std::string> results;
92 
93  m_implementation->getLUTs(tag, crate, slot, LUTs);
94 
95  if (LUTs.empty()) {
96  XCEPT_RAISE(hcal::exception::ConfigurationItemNotFoundException,toolbox::toString("Not enough found (%d)",LUTs.size()));
97  }
98  }
99 
100  void ConfigurationDatabase::getLUTChecksums(const std::string& tag, std::map<LUTId, MD5Fingerprint>& checksums) noexcept(false) {
101  checksums.clear();
102 
103  if (m_implementation==nullptr) {
104  XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,"Database connection not open");
105  }
106 
107  m_implementation->getLUTChecksums(tag, checksums);
108  }
109 
110  void ConfigurationDatabase::getPatterns(const std::string& tag, int crate, int slot, std::map<PatternId, HTRPattern>& patterns) noexcept(false) {
111 
112  if (m_implementation==nullptr) {
113  XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,"Database connection not open");
114  }
115 
116  m_implementation->getPatterns(tag,crate,slot,patterns);
117 
118  if (patterns.empty()) {
119  XCEPT_RAISE(hcal::exception::ConfigurationItemNotFoundException,toolbox::toString("Not found '$s',%d,%d",tag.c_str(),crate,slot));
120  }
121  }
122 
123 
124  void ConfigurationDatabase::getRBXdata(const std::string& tag,
125  const std::string& rbx,
126  RBXdatumType dtype,
127  std::map<RBXdatumId, RBXdatum>& RBXdata)
128  noexcept(false) {
129 
130  if (m_implementation==nullptr) {
131  XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,"Database connection not open");
132  }
133 
134  m_implementation->getRBXdata(tag,rbx,dtype,RBXdata);
135  }
136 
137  void ConfigurationDatabase::getRBXpatterns(const std::string& tag,
138  const std::string& rbx,
139  std::map<RBXdatumId, RBXpattern>& patterns)
140  noexcept(false) {
141 
142  if (m_implementation==nullptr) {
143  XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,"Database connection not open");
144  }
145 
146  m_implementation->getRBXpatterns(tag,rbx,patterns);
147  }
148 
149  void ConfigurationDatabase::getZSThresholds(const std::string& tag, int crate, int slot, std::map<ZSChannelId, int>& thresholds)
150  noexcept(false) {
151 
152  if (m_implementation==nullptr) {
153  XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,"Database connection not open");
154  }
155 
156  m_implementation->getZSThresholds(tag,crate,slot,thresholds);
157  }
158 
159  void ConfigurationDatabase::getHLXMasks(const std::string& tag, int crate, int slot, std::map<FPGAId, HLXMasks>& m)
160  noexcept(false) {
161 
162  if (m_implementation==nullptr) {
163  XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,"Database connection not open");
164  }
165 
166  m_implementation->getHLXMasks(tag,crate,slot,m);
167  }
168 
169 
170 
171  bool ConfigurationDatabase::FPGAId::operator<(const FPGAId& a) const {
172  if (crate<a.crate) return true;
173  if (crate>a.crate) return false;
174  if (slot<a.slot) return true;
175  if (slot>a.slot) return false;
176  if (fpga<a.fpga) return true;
177  if (fpga>a.fpga) return false;
178  return false; // equal is not less
179  }
180  bool ConfigurationDatabase::LUTId::operator<(const LUTId& a) const {
181  if (crate<a.crate) return true;
182  if (crate>a.crate) return false;
183  if (slot<a.slot) return true;
184  if (slot>a.slot) return false;
185  if (fpga<a.fpga) return true;
186  if (fpga>a.fpga) return false;
187  if (fiber_slb<a.fiber_slb) return true;
188  if (fiber_slb>a.fiber_slb) return false;
189  if (channel<a.channel) return true;
190  if (channel>a.channel) return false;
191  if (lut_type<a.lut_type) return true;
192  if (lut_type>a.lut_type) return false;
193  return false; // equal is not less
194  }
195  bool ConfigurationDatabase::PatternId::operator<(const PatternId& a) const {
196  if (crate<a.crate) return true;
197  if (crate>a.crate) return false;
198  if (slot<a.slot) return true;
199  if (slot>a.slot) return false;
200  if (fpga<a.fpga) return true;
201  if (fpga>a.fpga) return false;
202  if (fiber<a.fiber) return true;
203  if (fiber>a.fiber) return false;
204  return false; // equal is not less
205  }
206  bool ConfigurationDatabase::ZSChannelId::operator<(const ZSChannelId& a) const {
207  if (crate<a.crate) return true;
208  if (crate>a.crate) return false;
209  if (slot<a.slot) return true;
210  if (slot>a.slot) return false;
211  if (fpga<a.fpga) return true;
212  if (fpga>a.fpga) return false;
213  if (fiber<a.fiber) return true;
214  if (fiber>a.fiber) return false;
215  if (channel<a.channel) return true;
216  if (channel>a.channel) return false;
217  return false; // equal is not less
218  }
219  bool ConfigurationDatabase::RBXdatumId::operator<(const RBXdatumId& a) const {
220  if (rm<a.rm) return true;
221  if (rm>a.rm) return false;
222  if (card<a.card) return true;
223  if (card>a.card) return false;
224  if (qie_or_gol<a.qie_or_gol) return true;
225  if (qie_or_gol>a.qie_or_gol) return false;
226  if (dtype<a.dtype) return true;
227  if (dtype>a.dtype) return false;
228  if (ltype<a.ltype) return true;
229  if (ltype>a.ltype) return false;
230  return false; // equal is not less
231  }
232 
233 }
host
Definition: query.py:115
std::ostream * Logger
Definition: xdaq_compat.h:11
static PFTauRenderPlugin instance
port
Definition: query.py:116
std::string toString(const char *format,...)
Definition: xdaq_compat.cc:4
Definition: logger.py:1
#define noexcept
bool operator<(DTCELinkId const &lhs, DTCELinkId const &rhs)
Definition: DTCELinkId.h:73
double a
Definition: hdecay.h:121
rm
Definition: submit.py:77