2 #include "CaloOnlineTools/HcalOnlineDb/interface/ConfigurationDatabaseImplOracle.hh" 6 #include <toolbox/string.h> 17 DECLARE_PLUGGABLE(hcal::ConfigurationDatabaseImpl, ConfigurationDatabaseImplOracle)
19 ConfigurationDatabaseImplOracle::ConfigurationDatabaseImplOracle() {}
21 bool ConfigurationDatabaseImplOracle::canHandleMethod(
const std::string&
method)
const {
return (
method ==
"occi"); }
23 ConfigurationDatabaseImplOracle::~ConfigurationDatabaseImplOracle() { disconnect(); }
26 std::map<std::string, std::string>
params;
31 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,
32 std::string(
"Invalid accessor for Oracle : ") + accessor);
37 lhwm_version =
params[
"LHWM_VERSION"];
42 }
catch (SQLException&
e) {
43 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,
47 if (env_ ==
nullptr || conn_ ==
nullptr) {
48 std::string message(
"Error connecting on accessor '");
50 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException, message);
54 void ConfigurationDatabaseImplOracle::disconnect() {
57 env_->terminateConnection(conn_);
58 Environment::terminateEnvironment(env_);
59 }
catch (SQLException&
e) {
60 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,
66 string ConfigurationDatabaseImplOracle::clobToString(
const oracle::occi::Clob& _clob) {
67 oracle::occi::Clob clob = _clob;
68 Stream* instream = clob.getStream(1, 0);
69 unsigned int size = clob.length();
70 char* cbuffer =
new char[
size];
71 memset(cbuffer, 0,
size);
72 instream->readBuffer(cbuffer,
size);
78 if (
c >=
'0' &&
c <=
'9')
80 if ((
c >=
'a' &&
c <=
'f') || (
c >=
'A' &&
c <=
'F'))
85 void ConfigurationDatabaseImplOracle::getLUTChecksums(
87 std::map<hcal::ConfigurationDatabase::LUTId, hcal::ConfigurationDatabase::MD5Fingerprint>&
88 checksums) noexcept(
false) {
89 if (env_ ==
nullptr || conn_ ==
nullptr)
90 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,
"Database is not open");
94 Statement* stmt = conn_->createStatement();
97 (
"SELECT TRIG_PRIM_LOOKUPTBL_DATA_CLOB FROM CMS_HCL_HCAL_CONDITION_OWNER.V_HCAL_TRIG_LOOKUP_TABLES");
98 query +=
" WHERE CRATE=-1";
102 ResultSet* rs = stmt->executeQuery(
query);
105 oracle::occi::Clob clob = rs->getClob(1);
106 std::list<ConfigurationDatabaseStandardXMLParser::Item>
items;
111 for (std::list<ConfigurationDatabaseStandardXMLParser::Item>::iterator
i =
items.begin();
i !=
items.end(); ++
i) {
112 hcal::ConfigurationDatabase::FPGASelection ifpga =
113 (hcal::ConfigurationDatabase::FPGASelection)atoi(
i->parameters[
"topbottom"].c_str());
114 int islot = atoi(
i->parameters[
"slot"].c_str());
115 hcal::ConfigurationDatabase::LUTType ilut_type =
116 (hcal::ConfigurationDatabase::LUTType)atoi(
i->parameters[
"luttype"].c_str());
117 int crate = atoi(
i->parameters[
"crate"].c_str());
118 int islb = atoi(
i->parameters[
"slb"].c_str());
119 int islbch = atoi(
i->parameters[
"slbchan"].c_str());
120 hcal::ConfigurationDatabase::LUTId lut_id;
121 lut_id = hcal::ConfigurationDatabase::LUTId(crate, islot, ifpga, islb, islbch, ilut_type);
123 hcal::ConfigurationDatabase::MD5Fingerprint csum(16);
125 for (
int i = 0;
i < 16;
i++) {
130 checksums[lut_id] = csum;
134 conn_->terminateStatement(stmt);
135 }
catch (SQLException&
e) {
136 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,
141 void ConfigurationDatabaseImplOracle::getLUTs(
145 std::map<hcal::ConfigurationDatabase::LUTId, hcal::ConfigurationDatabase::LUT>& LUTs) noexcept(
false) {
146 if (m_lutCache.crate != crate || m_lutCache.tag !=
tag) {
148 getLUTs_real(
tag, crate, m_lutCache.luts);
149 m_lutCache.crate = crate;
150 m_lutCache.tag =
tag;
154 std::map<hcal::ConfigurationDatabase::LUTId, hcal::ConfigurationDatabase::LUT>::const_iterator
i;
155 for (
i = m_lutCache.luts.begin();
i != m_lutCache.luts.end();
i++) {
156 if (
i->first.slot == slot)
161 void ConfigurationDatabaseImplOracle::getLUTs_real(
164 std::map<hcal::ConfigurationDatabase::LUTId, hcal::ConfigurationDatabase::LUT>& LUTs) noexcept(
false) {
167 Statement* stmt = conn_->createStatement();
170 (
"SELECT TRIG_PRIM_LOOKUPTBL_DATA_CLOB FROM CMS_HCL_HCAL_CONDITION_OWNER.V_HCAL_TRIG_LOOKUP_TABLES");
174 ResultSet* rs = stmt->executeQuery(
query);
179 oracle::occi::Clob clob = rs->getClob(1);
180 std::list<ConfigurationDatabaseStandardXMLParser::Item>
items;
184 for (std::list<ConfigurationDatabaseStandardXMLParser::Item>::iterator
i =
items.begin();
i !=
items.end(); ++
i) {
185 hcal::ConfigurationDatabase::FPGASelection ifpga =
186 (hcal::ConfigurationDatabase::FPGASelection)atoi(
i->parameters[
"TOPBOTTOM"].c_str());
187 int islot = atoi(
i->parameters[
"SLOT"].c_str());
191 hcal::ConfigurationDatabase::LUTType ilut_type =
192 (hcal::ConfigurationDatabase::LUTType)atoi(
i->parameters[
"LUT_TYPE"].c_str());
193 hcal::ConfigurationDatabase::LUTId lut_id;
194 if (ilut_type == hcal::ConfigurationDatabase::LinearizerLUT) {
195 int ifiber = atoi(
i->parameters[
"FIBER"].c_str());
196 int ifiberch = atoi(
i->parameters[
"FIBERCHAN"].c_str());
197 lut_id = hcal::ConfigurationDatabase::LUTId(crate, islot, ifpga, ifiber, ifiberch, ilut_type);
199 int islb = atoi(
i->parameters[
"SLB"].c_str());
200 int islbch = atoi(
i->parameters[
"SLBCHAN"].c_str());
201 lut_id = hcal::ConfigurationDatabase::LUTId(crate, islot, ifpga, islb, islbch, ilut_type);
205 lut.reserve(
i->items.size());
208 if (
i->encoding ==
"hex")
210 else if (
i->encoding ==
"dec")
214 for (
unsigned int j = 0;
j <
i->items.size();
j++)
215 lut.push_back(strtol(
i->items[
j].c_str(),
nullptr, strtol_base));
217 LUTs.insert(make_pair(lut_id, lut));
223 conn_->terminateStatement(stmt);
224 }
catch (SQLException&
e) {
225 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,
230 void ConfigurationDatabaseImplOracle::getPatterns(
234 std::map<hcal::ConfigurationDatabase::PatternId, hcal::ConfigurationDatabase::HTRPattern>& patterns) noexcept(
false) {
235 if (m_patternCache.crate != crate || m_patternCache.tag !=
tag) {
236 m_patternCache.clear();
237 getPatterns_real(
tag, crate, m_patternCache.patterns);
238 m_patternCache.crate = crate;
239 m_patternCache.tag =
tag;
243 std::map<hcal::ConfigurationDatabase::PatternId, hcal::ConfigurationDatabase::HTRPattern>::const_iterator
i;
244 for (
i = m_patternCache.patterns.begin();
i != m_patternCache.patterns.end();
i++) {
245 if (
i->first.slot == slot)
250 void ConfigurationDatabaseImplOracle::getPatterns_real(
253 std::map<hcal::ConfigurationDatabase::PatternId, hcal::ConfigurationDatabase::HTRPattern>& patterns) noexcept(
false) {
256 Statement* stmt = conn_->createStatement();
259 (
"SELECT HTR_DATA_PATTERNS_DATA_CLOB FROM CMS_HCL_HCAL_CONDITION_OWNER.V_HCAL_HTR_DATA_PATTERNS");
263 ResultSet* rs = stmt->executeQuery(
query);
268 oracle::occi::Clob clob = rs->getClob(1);
269 std::list<ConfigurationDatabaseStandardXMLParser::Item>
items;
274 for (std::list<ConfigurationDatabaseStandardXMLParser::Item>::iterator
i =
items.begin();
i !=
items.end(); ++
i) {
275 int islot = atoi(
i->parameters[
"SLOT"].c_str());
278 hcal::ConfigurationDatabase::FPGASelection ifpga =
279 (hcal::ConfigurationDatabase::FPGASelection)atoi(
i->parameters[
"TOPBOTTOM"].c_str());
280 int ifiber = atoi(
i->parameters[
"FIBER"].c_str());
282 hcal::ConfigurationDatabase::PatternId pat_id(crate, islot, ifpga, ifiber);
283 hcal::ConfigurationDatabase::HTRPattern&
pat = patterns[pat_id];
284 pat.reserve(
i->items.size());
287 if (
i->encoding ==
"hex")
289 else if (
i->encoding ==
"dec")
293 for (
unsigned int j = 0;
j <
i->items.size();
j++)
294 pat.push_back(strtol(
i->items[
j].c_str(),
nullptr, strtol_base));
299 conn_->terminateStatement(stmt);
300 }
catch (SQLException&
e) {
301 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,
306 void ConfigurationDatabaseImplOracle::getRBXdata(
309 hcal::ConfigurationDatabase::RBXdatumType
dtype,
310 std::map<ConfigurationDatabase::RBXdatumId, hcal::ConfigurationDatabase::RBXdatum>& RBXdata) noexcept(
false) {
313 Statement* stmt = conn_->createStatement();
318 case (ConfigurationDatabase::eRBXpedestal):
322 query =
"SELECT MODULE_POSITION, QIE_CARD_POSITION, QIE_ADC_NUMBER, INTEGER_VALUE ";
323 query +=
" FROM CMS_HCL_HCAL_CONDITION_OWNER.V_HCAL_RBX_PEDESTAL_CONFIG ";
328 case (ConfigurationDatabase::eRBXdelay):
331 query =
"SELECT MODULE_POSITION, QIE_CARD_POSITION, QIE_ADC_NUMBER, INTEGER_VALUE ";
332 query +=
" FROM CMS_HCL_HCAL_CONDITION_OWNER.V_HCAL_RBX_DELAY_CONFIG ";
337 case (ConfigurationDatabase::eRBXgolCurrent):
340 query =
"SELECT MODULE_POSITION, QIE_CARD_POSITION, FIBER_NUMBER, INTEGER_VALUE ";
341 query +=
" FROM CMS_HCL_HCAL_CONDITION_OWNER.V_HCAL_RBX_GOL_CONFIG ";
345 case (ConfigurationDatabase::eRBXledData):
347 query =
"SELECT LED_AMPLITUDE, SET_LEDS_IS_CHECKED, BUNCH_NUMBER ";
348 query +=
" FROM CMS_HCL_HCAL_CONDITION_OWNER.V_HCAL_RBX_INITPAR_T02_CONFIG ";
352 case (ConfigurationDatabase::eRBXbroadcast):
354 printf(
"ConfigurationDatabaseImplMySQL::getRBXdata Can't handle BROADCAST yet\n");
356 case (ConfigurationDatabase::eRBXttcrxPhase):
358 printf(
"ConfigurationDatabaseImplMySQL::getRBXdata Can't handle TTCRX PHASE yet\n");
360 case (ConfigurationDatabase::eRBXqieResetDelay):
362 printf(
"ConfigurationDatabaseImplMySQL::getRBXdata Can't handle QIE RESET DELAY yet\n");
364 case (ConfigurationDatabase::eRBXccaPatterns):
365 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,
"Patterns must use getRBXPatterns, not getRBXData");
368 printf(
"ConfigurationDatabaseImplMySQL::getRBXdata Can't handle dtype=%d yet\n",
dtype);
374 ResultSet* rs = stmt->executeQuery(
query);
376 if (
dtype == ConfigurationDatabase::eRBXledData) {
378 unsigned int ampl = rs->getInt(1);
379 unsigned int enable = rs->getInt(2);
380 unsigned int bunch = rs->getInt(3);
384 RBXdata.insert(std::pair<ConfigurationDatabase::RBXdatumId, ConfigurationDatabase::RBXdatum>(
385 ConfigurationDatabase::eLEDenable,
enable));
386 RBXdata.insert(std::pair<ConfigurationDatabase::RBXdatumId, ConfigurationDatabase::RBXdatum>(
387 ConfigurationDatabase::eLEDamplitude, ampl));
388 RBXdata.insert(std::pair<ConfigurationDatabase::RBXdatumId, ConfigurationDatabase::RBXdatum>(
389 ConfigurationDatabase::eLEDtiming_hb, ((bunch & 0xFF00) >> 8)));
390 RBXdata.insert(std::pair<ConfigurationDatabase::RBXdatumId, ConfigurationDatabase::RBXdatum>(
391 ConfigurationDatabase::eLEDtiming_lb, (bunch & 0xFF)));
394 int rm = rs->getInt(1);
395 int card = rs->getInt(2);
396 int qie_or_gol = rs->getInt(3);
397 unsigned int data = rs->getInt(4);
399 ConfigurationDatabase::RBXdatumId
id(
rm, card, qie_or_gol,
dtype);
401 std::pair<ConfigurationDatabase::RBXdatumId, ConfigurationDatabase::RBXdatum>(
id, (
unsigned char)(
data)));
406 conn_->terminateStatement(stmt);
407 }
catch (SQLException&
e) {
408 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,
413 void ConfigurationDatabaseImplOracle::getZSThresholds(
417 std::map<hcal::ConfigurationDatabase::ZSChannelId, int>&
thresholds) noexcept(
false) {
420 Statement* stmt = conn_->createStatement();
426 std::string query = (
"SELECT HTR_FIBER, FIBER_CHANNEL, ZERO_SUPPRESSION, HTR_FPGA ");
427 query +=
" FROM CMS_HCL_HCAL_CONDITION_OWNER.V_HCAL_ZERO_SUPPRESSION_LHWM ";
432 ResultSet* rs = stmt->executeQuery(
query);
437 unsigned int fiber = rs->getInt(1);
438 unsigned int fc = rs->getInt(2);
439 unsigned int zs = rs->getInt(3);
446 std::cout <<
"crate,slot,tb,fiber,fc:" << crate << slot << tb << fiber << fc << std::endl;
447 hcal::ConfigurationDatabase::ZSChannelId
id(
448 crate, slot, (hcal::ConfigurationDatabase::FPGASelection)tb, fiber, fc);
452 conn_->terminateStatement(stmt);
453 }
catch (SQLException&
e) {
454 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,
459 void ConfigurationDatabaseImplOracle::getHLXMasks(
463 std::map<hcal::ConfigurationDatabase::FPGAId, hcal::ConfigurationDatabase::HLXMasks>& masks) noexcept(
false) {
464 if (m_hlxMaskCache.crate != crate || m_hlxMaskCache.tag !=
tag) {
465 m_hlxMaskCache.clear();
466 getHLXMasks_real(
tag, crate, m_hlxMaskCache.masks);
467 m_hlxMaskCache.crate = crate;
468 m_hlxMaskCache.tag =
tag;
472 std::map<ConfigurationDatabase::FPGAId, ConfigurationDatabase::HLXMasks>::const_iterator
i;
473 for (
i = m_hlxMaskCache.masks.begin();
i != m_hlxMaskCache.masks.end();
i++) {
474 if (
i->first.slot == slot)
479 void ConfigurationDatabaseImplOracle::getHLXMasks_real(
482 std::map<ConfigurationDatabase::FPGAId, ConfigurationDatabase::HLXMasks>& masks) noexcept(
false) {
485 Statement* stmt = conn_->createStatement();
486 std::string query = (
"SELECT SLOT_NUMBER, FPGA, OCC_MASK, LHC_MASK, SUM_ET_MASK ");
487 query +=
" FROM CMS_HCL_HCAL_CONDITION_OWNER.V_HCAL_HLX_MASKS ";
491 ResultSet* rs = stmt->executeQuery(
query);
494 int islot = rs->getInt(1);
503 hcal::ConfigurationDatabase::FPGAId fpga_id;
505 hcal::ConfigurationDatabase::FPGAId(crate, islot, (hcal::ConfigurationDatabase::FPGASelectionEnum)ifpga);
506 hcal::ConfigurationDatabase::HLXMasks hlxMask;
507 hlxMask.occMask = rs->getInt(3);
508 hlxMask.lhcMask = rs->getInt(4);
509 hlxMask.sumEtMask = rs->getInt(5);
511 masks[fpga_id] = hlxMask;
514 conn_->terminateStatement(stmt);
515 }
catch (SQLException&
e) {
516 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,
522 oracle::occi::Connection* ConfigurationDatabaseImplOracle::getConnection(
void) {
return conn_; }
524 oracle::occi::Environment* ConfigurationDatabaseImplOracle::getEnvironment(
void) {
return env_; }
for(int i=first, nt=offsets[nh];i< nt;i+=gridDim.x *blockDim.x)
static int cvtChar(int c)
char data[epos_bytes_allocation]
std::vector< unsigned short int > LUT