CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 <ctype.h>
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=0;
17  }
18 
19  void ConfigurationDatabase::open(const std::string& accessor) throw (hcal::exception::ConfigurationDatabaseException) {
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==0 || !m_implementation->canHandleMethod(method)) {
32  m_implementation=0;
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==0)
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!=0) m_implementation->disconnect();
50  }
51 
52  unsigned int ConfigurationDatabase::getFirmwareChecksum(const std::string& board, unsigned int version) throw (hcal::exception::ConfigurationDatabaseException) {
53  if (m_implementation==0) {
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) throw (hcal::exception::ConfigurationDatabaseException) {
61  if (m_implementation==0) {
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) throw (hcal::exception::ConfigurationDatabaseException) {
70  if (m_implementation==0) {
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) throw (hcal::exception::ConfigurationDatabaseException) {
77  if (m_implementation==0) {
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) throw (hcal::exception::ConfigurationDatabaseException) {
86 
87  if (m_implementation==0) {
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.size()==0) {
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) throw (hcal::exception::ConfigurationDatabaseException) {
101  checksums.clear();
102 
103  if (m_implementation==0) {
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) throw (hcal::exception::ConfigurationDatabaseException) {
111 
112  if (m_implementation==0) {
113  XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,"Database connection not open");
114  }
115 
116  m_implementation->getPatterns(tag,crate,slot,patterns);
117 
118  if (patterns.size()==0) {
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  throw (hcal::exception::ConfigurationDatabaseException) {
129 
130  if (m_implementation==0) {
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  throw (hcal::exception::ConfigurationDatabaseException) {
141 
142  if (m_implementation==0) {
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  throw (hcal::exception::ConfigurationDatabaseException) {
151 
152  if (m_implementation==0) {
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  throw (hcal::exception::ConfigurationDatabaseException) {
161 
162  if (m_implementation==0) {
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; if (crate>a.crate) return false;
173  if (slot<a.slot) return true; if (slot>a.slot) return false;
174  if (fpga<a.fpga) return true; if (fpga>a.fpga) return false;
175  return false; // equal is not less
176  }
177  bool ConfigurationDatabase::LUTId::operator<(const LUTId& a) const {
178  if (crate<a.crate) return true; if (crate>a.crate) return false;
179  if (slot<a.slot) return true; if (slot>a.slot) return false;
180  if (fpga<a.fpga) return true; if (fpga>a.fpga) return false;
181  if (fiber_slb<a.fiber_slb) return true; if (fiber_slb>a.fiber_slb) return false;
182  if (channel<a.channel) return true; if (channel>a.channel) return false;
183  if (lut_type<a.lut_type) return true; if (lut_type>a.lut_type) return false;
184  return false; // equal is not less
185  }
186  bool ConfigurationDatabase::PatternId::operator<(const PatternId& a) const {
187  if (crate<a.crate) return true; if (crate>a.crate) return false;
188  if (slot<a.slot) return true; if (slot>a.slot) return false;
189  if (fpga<a.fpga) return true; if (fpga>a.fpga) return false;
190  if (fiber<a.fiber) return true; if (fiber>a.fiber) return false;
191  return false; // equal is not less
192  }
193  bool ConfigurationDatabase::ZSChannelId::operator<(const ZSChannelId& a) const {
194  if (crate<a.crate) return true; if (crate>a.crate) return false;
195  if (slot<a.slot) return true; if (slot>a.slot) return false;
196  if (fpga<a.fpga) return true; if (fpga>a.fpga) return false;
197  if (fiber<a.fiber) return true; if (fiber>a.fiber) return false;
198  if (channel<a.channel) return true; if (channel>a.channel) return false;
199  return false; // equal is not less
200  }
201  bool ConfigurationDatabase::RBXdatumId::operator<(const RBXdatumId& a) const {
202  if (rm<a.rm) return true; if (rm>a.rm) return false;
203  if (card<a.card) return true; if (card>a.card) return false;
204  if (qie_or_gol<a.qie_or_gol) return true; if (qie_or_gol>a.qie_or_gol) return false;
205  if (dtype<a.dtype) return true; if (dtype>a.dtype) return false;
206  if (ltype<a.ltype) return true; if (ltype>a.ltype) return false;
207  return false; // equal is not less
208  }
209 
210 }
tuple logger
Definition: conddblib.py:20
std::ostream * Logger
Definition: xdaq_compat.h:11
static PFTauRenderPlugin instance
tuple db
Definition: EcalCondDB.py:151
int port
Definition: query.py:115
bool operator<(const FedChannelConnection &, const FedChannelConnection &)
std::string toString(const char *format,...)
Definition: xdaq_compat.cc:4
string rm
Definition: submit.py:76
int j
Definition: DBlmapReader.cc:9
string host
Definition: query.py:114
double a
Definition: hdecay.h:121