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;
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,
43  toolbox::toString("Unable to open database using '%s'", accessor.c_str()));
44  m_implementation->setLogger(m_logger);
45  m_implementation->connect(accessor);
46  }
47 
48  void ConfigurationDatabase::close() {
49  if (m_implementation != nullptr)
50  m_implementation->disconnect();
51  }
52 
53  unsigned int ConfigurationDatabase::getFirmwareChecksum(const std::string& board,
54  unsigned int version) noexcept(false) {
55  if (m_implementation == nullptr) {
56  XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException, "Database connection not open");
57  }
58 
59  return m_implementation->getFirmwareChecksum(board, version);
60  }
61 
62  ConfigurationDatabase::ApplicationConfig ConfigurationDatabase::getApplicationConfig(const std::string& tag,
63  const std::string& classname,
64  int instance) noexcept(false) {
65  if (m_implementation == nullptr) {
66  XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException, "Database connection not open");
67  }
68  return m_implementation->getApplicationConfig(tag, classname, instance);
69  }
70 
71  std::string ConfigurationDatabase::getConfigurationDocument(const std::string& tag) noexcept(false) {
72  if (m_implementation == nullptr) {
73  XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException, "Database connection not open");
74  }
75  return m_implementation->getConfigurationDocument(tag);
76  }
77 
78  void ConfigurationDatabase::getFirmwareMCS(const std::string& board,
79  unsigned int version,
80  std::vector<std::string>& mcsLines) noexcept(false) {
81  if (m_implementation == nullptr) {
82  XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException, "Database connection not open");
83  }
84 
85  m_implementation->getFirmwareMCS(board, version, mcsLines);
86  }
87 
88  void ConfigurationDatabase::getLUTs(const std::string& tag,
89  int crate,
90  int slot,
91  std::map<LUTId, LUT>& LUTs) noexcept(false) {
92  if (m_implementation == nullptr) {
93  XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException, "Database connection not open");
94  }
95 
96  std::map<unsigned int, std::string> results;
97 
98  m_implementation->getLUTs(tag, crate, slot, LUTs);
99 
100  if (LUTs.empty()) {
101  XCEPT_RAISE(hcal::exception::ConfigurationItemNotFoundException,
102  toolbox::toString("Not enough found (%d)", LUTs.size()));
103  }
104  }
105 
106  void ConfigurationDatabase::getLUTChecksums(const std::string& tag,
107  std::map<LUTId, MD5Fingerprint>& checksums) noexcept(false) {
108  checksums.clear();
109 
110  if (m_implementation == nullptr) {
111  XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException, "Database connection not open");
112  }
113 
114  m_implementation->getLUTChecksums(tag, checksums);
115  }
116 
117  void ConfigurationDatabase::getPatterns(const std::string& tag,
118  int crate,
119  int slot,
120  std::map<PatternId, HTRPattern>& patterns) noexcept(false) {
121  if (m_implementation == nullptr) {
122  XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException, "Database connection not open");
123  }
124 
125  m_implementation->getPatterns(tag, crate, slot, patterns);
126 
127  if (patterns.empty()) {
128  XCEPT_RAISE(hcal::exception::ConfigurationItemNotFoundException,
129  toolbox::toString("Not found '$s',%d,%d", tag.c_str(), crate, slot));
130  }
131  }
132 
133  void ConfigurationDatabase::getRBXdata(const std::string& tag,
134  const std::string& rbx,
135  RBXdatumType dtype,
136  std::map<RBXdatumId, RBXdatum>& RBXdata) noexcept(false) {
137  if (m_implementation == nullptr) {
138  XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException, "Database connection not open");
139  }
140 
141  m_implementation->getRBXdata(tag, rbx, dtype, RBXdata);
142  }
143 
144  void ConfigurationDatabase::getRBXpatterns(const std::string& tag,
145  const std::string& rbx,
146  std::map<RBXdatumId, RBXpattern>& patterns) noexcept(false) {
147  if (m_implementation == nullptr) {
148  XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException, "Database connection not open");
149  }
150 
151  m_implementation->getRBXpatterns(tag, rbx, patterns);
152  }
153 
154  void ConfigurationDatabase::getZSThresholds(const std::string& tag,
155  int crate,
156  int slot,
157  std::map<ZSChannelId, int>& thresholds) noexcept(false) {
158  if (m_implementation == nullptr) {
159  XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException, "Database connection not open");
160  }
161 
162  m_implementation->getZSThresholds(tag, crate, slot, thresholds);
163  }
164 
165  void ConfigurationDatabase::getHLXMasks(const std::string& tag,
166  int crate,
167  int slot,
168  std::map<FPGAId, HLXMasks>& m) noexcept(false) {
169  if (m_implementation == nullptr) {
170  XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException, "Database connection not open");
171  }
172 
173  m_implementation->getHLXMasks(tag, crate, slot, m);
174  }
175 
176  bool ConfigurationDatabase::FPGAId::operator<(const FPGAId& a) const {
177  if (crate < a.crate)
178  return true;
179  if (crate > a.crate)
180  return false;
181  if (slot < a.slot)
182  return true;
183  if (slot > a.slot)
184  return false;
185  if (fpga < a.fpga)
186  return true;
187  if (fpga > a.fpga)
188  return false;
189  return false; // equal is not less
190  }
191  bool ConfigurationDatabase::LUTId::operator<(const LUTId& a) const {
192  if (crate < a.crate)
193  return true;
194  if (crate > a.crate)
195  return false;
196  if (slot < a.slot)
197  return true;
198  if (slot > a.slot)
199  return false;
200  if (fpga < a.fpga)
201  return true;
202  if (fpga > a.fpga)
203  return false;
204  if (fiber_slb < a.fiber_slb)
205  return true;
206  if (fiber_slb > a.fiber_slb)
207  return false;
208  if (channel < a.channel)
209  return true;
210  if (channel > a.channel)
211  return false;
212  if (lut_type < a.lut_type)
213  return true;
214  if (lut_type > a.lut_type)
215  return false;
216  return false; // equal is not less
217  }
218  bool ConfigurationDatabase::PatternId::operator<(const PatternId& a) const {
219  if (crate < a.crate)
220  return true;
221  if (crate > a.crate)
222  return false;
223  if (slot < a.slot)
224  return true;
225  if (slot > a.slot)
226  return false;
227  if (fpga < a.fpga)
228  return true;
229  if (fpga > a.fpga)
230  return false;
231  if (fiber < a.fiber)
232  return true;
233  if (fiber > a.fiber)
234  return false;
235  return false; // equal is not less
236  }
237  bool ConfigurationDatabase::ZSChannelId::operator<(const ZSChannelId& a) const {
238  if (crate < a.crate)
239  return true;
240  if (crate > a.crate)
241  return false;
242  if (slot < a.slot)
243  return true;
244  if (slot > a.slot)
245  return false;
246  if (fpga < a.fpga)
247  return true;
248  if (fpga > a.fpga)
249  return false;
250  if (fiber < a.fiber)
251  return true;
252  if (fiber > a.fiber)
253  return false;
254  if (channel < a.channel)
255  return true;
256  if (channel > a.channel)
257  return false;
258  return false; // equal is not less
259  }
260  bool ConfigurationDatabase::RBXdatumId::operator<(const RBXdatumId& a) const {
261  if (rm < a.rm)
262  return true;
263  if (rm > a.rm)
264  return false;
265  if (card < a.card)
266  return true;
267  if (card > a.card)
268  return false;
269  if (qie_or_gol < a.qie_or_gol)
270  return true;
271  if (qie_or_gol > a.qie_or_gol)
272  return false;
273  if (dtype < a.dtype)
274  return true;
275  if (dtype > a.dtype)
276  return false;
277  if (ltype < a.ltype)
278  return true;
279  if (ltype > a.ltype)
280  return false;
281  return false; // equal is not less
282  }
283 
284 } // namespace hcal
def rm(path, rec=False)
Definition: eostools.py:363
string host
Definition: query.py:115
std::ostream * Logger
Definition: xdaq_compat.h:11
static PFTauRenderPlugin instance
int port
Definition: query.py:116
std::string toString(const char *format,...)
Definition: xdaq_compat.cc:4
Definition: logger.py:1
bool operator<(DTCELinkId const &lhs, DTCELinkId const &rhs)
Definition: DTCELinkId.h:70
double a
Definition: hdecay.h:119