2 #include "CaloOnlineTools/HcalOnlineDb/interface/ConfigurationDatabaseImplOracle.hh" 6 #include <toolbox/string.h> 17 DECLARE_PLUGGABLE(hcal::ConfigurationDatabaseImpl,ConfigurationDatabaseImplOracle)
19 ConfigurationDatabaseImplOracle::ConfigurationDatabaseImplOracle()
24 bool ConfigurationDatabaseImplOracle::canHandleMethod(
const std::string&
method)
const {
25 return (method==
"occi");
28 ConfigurationDatabaseImplOracle::~ConfigurationDatabaseImplOracle() {
34 std::map<std::string,std::string> params;
36 ConfigurationDatabaseImpl::parseAccessor(accessor,method,host,port,user,db,params);
38 if (method!=
"occi") XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,
std::string(
"Invalid accessor for Oracle : ")+accessor);
40 if (params.find(
"PASSWORD")!=params.end()) password=params[
"PASSWORD"];
41 if (params.find(
"LHWM_VERSION")!=params.end()) lhwm_version=params[
"LHWM_VERSION"];
45 conn_ = env_->createConnection (user, password, db);
46 }
catch (SQLException&
e) {
47 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,::
toolbox::toString(
"Oracle exception : %s",e.getMessage().c_str()));
51 if (env_ ==
nullptr || conn_ ==
nullptr) {
52 std::string message(
"Error connecting on accessor '");
54 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,message);
58 void ConfigurationDatabaseImplOracle::disconnect() {
62 env_->terminateConnection(conn_);
63 Environment::terminateEnvironment(env_);
64 }
catch (SQLException& e) {
65 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,::
toolbox::toString(
"Oracle exception : %s",e.getMessage().c_str()));
72 string ConfigurationDatabaseImplOracle::clobToString(
const oracle::occi::Clob& _clob){
73 oracle::occi::Clob clob = _clob;
74 Stream *instream = clob.getStream (1,0);
75 unsigned int size = clob.length();
76 char *cbuffer =
new char[
size];
77 memset (cbuffer, 0, size);
78 instream->readBuffer (cbuffer, size);
84 if (c>=
'0' && c<=
'9') c-=
'0';
85 if ((c>=
'a' && c<=
'f')||(c>=
'A' && c<=
'F')) c-=
'A'+10;
89 void ConfigurationDatabaseImplOracle::getLUTChecksums(
const std::string&
tag,
90 std::map<hcal::ConfigurationDatabase::LUTId,
91 hcal::ConfigurationDatabase::MD5Fingerprint>& checksums)
noexcept(
false) {
93 if (env_ ==
nullptr || conn_ ==
nullptr) XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,
"Database is not open");
97 Statement* stmt = conn_->createStatement();
99 std::string query = (
"SELECT TRIG_PRIM_LOOKUPTBL_DATA_CLOB FROM CMS_HCL_HCAL_CONDITION_OWNER.V_HCAL_TRIG_LOOKUP_TABLES");
100 query+=
" WHERE CRATE=-1";
104 ResultSet *rs = stmt->executeQuery(query);
107 oracle::occi::Clob clob = rs->getClob (1);
108 std::list<ConfigurationDatabaseStandardXMLParser::Item>
items;
111 m_parser.parseMultiple(buffer,items);
113 for (std::list<ConfigurationDatabaseStandardXMLParser::Item>::iterator
i=items.begin();
i!=items.end(); ++
i) {
115 hcal::ConfigurationDatabase::FPGASelection ifpga =
116 (hcal::ConfigurationDatabase::FPGASelection)atoi(
i->parameters[
"topbottom"].c_str());
117 int islot = atoi(
i->parameters[
"slot"].c_str());
118 hcal::ConfigurationDatabase::LUTType ilut_type =
119 (hcal::ConfigurationDatabase::LUTType)atoi(
i->parameters[
"luttype"].c_str());
120 int crate=atoi(
i->parameters[
"crate"].c_str());
121 int islb=atoi(
i->parameters[
"slb"].c_str());
122 int islbch=atoi(
i->parameters[
"slbchan"].c_str());
123 hcal::ConfigurationDatabase::LUTId lut_id;
124 lut_id=hcal::ConfigurationDatabase::LUTId(crate, islot, ifpga, islb, islbch, ilut_type);
126 hcal::ConfigurationDatabase::MD5Fingerprint csum(16);
128 for (
int i=0;
i<16;
i++) {
133 checksums[lut_id]=csum;
137 conn_->terminateStatement(stmt);
138 }
catch (SQLException& e) {
139 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,::
toolbox::toString(
"Oracle exception : %s",e.getMessage().c_str()));
144 void ConfigurationDatabaseImplOracle::getLUTs(
const std::string& tag,
int crate,
int slot, std::map<hcal::ConfigurationDatabase::LUTId, hcal::ConfigurationDatabase::LUT >& LUTs)
noexcept(
false) {
145 if (m_lutCache.crate!=crate || m_lutCache.tag!=tag) {
147 getLUTs_real(tag,crate,m_lutCache.luts);
148 m_lutCache.crate=crate;
153 std::map<hcal::ConfigurationDatabase::LUTId, hcal::ConfigurationDatabase::LUT >::const_iterator
i;
154 for (i=m_lutCache.luts.begin(); i!=m_lutCache.luts.end(); i++) {
155 if (i->first.slot==slot)
161 void ConfigurationDatabaseImplOracle::getLUTs_real(
const std::string& tag,
int crate,
162 std::map<hcal::ConfigurationDatabase::LUTId, hcal::ConfigurationDatabase::LUT >& LUTs)
168 Statement* stmt = conn_->createStatement();
170 std::string query = (
"SELECT TRIG_PRIM_LOOKUPTBL_DATA_CLOB FROM CMS_HCL_HCAL_CONDITION_OWNER.V_HCAL_TRIG_LOOKUP_TABLES");
171 query+=
toolbox::toString(
" WHERE TAG_NAME='%s' AND CRATE=%d", tag.c_str(), crate);
174 ResultSet *rs = stmt->executeQuery(query);
179 oracle::occi::Clob clob = rs->getClob (1);
180 std::list<ConfigurationDatabaseStandardXMLParser::Item>
items;
182 m_parser.parseMultiple(buffer,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") strtol_base=16;
209 else if (
i->encoding==
"dec") strtol_base=10;
212 for (
unsigned int j=0; j<
i->items.size(); j++)
213 lut.push_back(strtol(
i->items[j].c_str(),
nullptr,strtol_base));
215 LUTs.insert(make_pair(lut_id, lut));
221 conn_->terminateStatement(stmt);
222 }
catch (SQLException& e) {
223 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,::
toolbox::toString(
"Oracle exception : %s",e.getMessage().c_str()));
228 void ConfigurationDatabaseImplOracle::getPatterns(
const std::string& tag,
int crate,
int slot, std::map<hcal::ConfigurationDatabase::PatternId, hcal::ConfigurationDatabase::HTRPattern >& patterns)
noexcept(
false) {
229 if (m_patternCache.crate!=crate || m_patternCache.tag!=tag) {
230 m_patternCache.clear();
231 getPatterns_real(tag,crate,m_patternCache.patterns);
232 m_patternCache.crate=crate;
233 m_patternCache.tag=
tag;
237 std::map<hcal::ConfigurationDatabase::PatternId, hcal::ConfigurationDatabase::HTRPattern >::const_iterator
i;
238 for (i=m_patternCache.patterns.begin(); i!=m_patternCache.patterns.end(); i++) {
239 if (i->first.slot==slot)
244 void ConfigurationDatabaseImplOracle::getPatterns_real(
const std::string& tag,
int crate,
245 std::map<hcal::ConfigurationDatabase::PatternId, hcal::ConfigurationDatabase::HTRPattern >& patterns)
249 Statement* stmt = conn_->createStatement();
251 std::string query = (
"SELECT HTR_DATA_PATTERNS_DATA_CLOB FROM CMS_HCL_HCAL_CONDITION_OWNER.V_HCAL_HTR_DATA_PATTERNS");
252 query+=
toolbox::toString(
" WHERE TAG_NAME='%s' AND CRATE=%d", tag.c_str(), crate);
255 ResultSet *rs = stmt->executeQuery(query);
260 oracle::occi::Clob clob = rs->getClob (1);
261 std::list<ConfigurationDatabaseStandardXMLParser::Item>
items;
264 m_parser.parseMultiple(buffer,items);
266 for (std::list<ConfigurationDatabaseStandardXMLParser::Item>::iterator
i=items.begin();
i!=items.end(); ++
i) {
267 int islot=atoi(
i->parameters[
"SLOT"].c_str());
270 hcal::ConfigurationDatabase::FPGASelection ifpga =
271 (hcal::ConfigurationDatabase::FPGASelection)atoi(
i->parameters[
"TOPBOTTOM"].c_str());
272 int ifiber=atoi(
i->parameters[
"FIBER"].c_str());
274 hcal::ConfigurationDatabase::PatternId pat_id(crate, islot, ifpga, ifiber);
275 hcal::ConfigurationDatabase::HTRPattern&
pat=patterns[pat_id];
276 pat.reserve(
i->items.size());
279 if (
i->encoding==
"hex") strtol_base=16;
280 else if (
i->encoding==
"dec") strtol_base=10;
283 for (
unsigned int j=0; j<
i->items.size(); j++)
284 pat.push_back(strtol(
i->items[j].c_str(),
nullptr,strtol_base));
289 conn_->terminateStatement(stmt);
290 }
catch (SQLException& e) {
291 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,::
toolbox::toString(
"Oracle exception : %s",e.getMessage().c_str()));
298 hcal::ConfigurationDatabase::RBXdatumType
dtype,
299 std::map<ConfigurationDatabase::RBXdatumId, hcal::ConfigurationDatabase::RBXdatum>& RBXdata)
304 Statement* stmt = conn_->createStatement();
310 case (ConfigurationDatabase::eRBXpedestal):
314 query =
"SELECT MODULE_POSITION, QIE_CARD_POSITION, QIE_ADC_NUMBER, INTEGER_VALUE ";
315 query +=
" FROM CMS_HCL_HCAL_CONDITION_OWNER.V_HCAL_RBX_PEDESTAL_CONFIG ";
316 query +=
toolbox::toString(
" WHERE TAG_NAME='%s' AND NAME_LABEL='%s'", tag.c_str(), rbx.c_str());
320 case (ConfigurationDatabase::eRBXdelay):
323 query =
"SELECT MODULE_POSITION, QIE_CARD_POSITION, QIE_ADC_NUMBER, INTEGER_VALUE ";
324 query +=
" FROM CMS_HCL_HCAL_CONDITION_OWNER.V_HCAL_RBX_DELAY_CONFIG ";
325 query +=
toolbox::toString(
" WHERE TAG_NAME='%s' AND NAME_LABEL='%s'", tag.c_str(), rbx.c_str());
329 case (ConfigurationDatabase::eRBXgolCurrent):
332 query =
"SELECT MODULE_POSITION, QIE_CARD_POSITION, FIBER_NUMBER, INTEGER_VALUE ";
333 query +=
" FROM CMS_HCL_HCAL_CONDITION_OWNER.V_HCAL_RBX_GOL_CONFIG ";
334 query +=
toolbox::toString(
" WHERE TAG_NAME='%s' AND NAME_LABEL='%s'", tag.c_str(), rbx.c_str());
337 case (ConfigurationDatabase::eRBXledData):
339 query =
"SELECT LED_AMPLITUDE, SET_LEDS_IS_CHECKED, BUNCH_NUMBER ";
340 query +=
" FROM CMS_HCL_HCAL_CONDITION_OWNER.V_HCAL_RBX_INITPAR_T02_CONFIG ";
341 query +=
toolbox::toString(
" WHERE TAG_NAME='%s' AND NAME_LABEL='%s'", tag.c_str(), rbx.c_str());
345 case (ConfigurationDatabase::eRBXbroadcast):
347 printf(
"ConfigurationDatabaseImplMySQL::getRBXdata Can't handle BROADCAST yet\n");
349 case (ConfigurationDatabase::eRBXttcrxPhase):
351 printf(
"ConfigurationDatabaseImplMySQL::getRBXdata Can't handle TTCRX PHASE yet\n");
353 case (ConfigurationDatabase::eRBXqieResetDelay):
355 printf(
"ConfigurationDatabaseImplMySQL::getRBXdata Can't handle QIE RESET DELAY yet\n");
357 case (ConfigurationDatabase::eRBXccaPatterns):
358 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,
"Patterns must use getRBXPatterns, not getRBXData");
361 printf(
"ConfigurationDatabaseImplMySQL::getRBXdata Can't handle dtype=%d yet\n",dtype);
367 ResultSet *rs = stmt->executeQuery(query);
370 if (dtype==ConfigurationDatabase::eRBXledData) {
372 unsigned int ampl = rs->getInt(1);
373 unsigned int enable = rs->getInt(2);
374 unsigned int bunch = rs->getInt(3);
376 if (enable) enable|=0x1;
377 RBXdata.insert(std::pair<ConfigurationDatabase::RBXdatumId,ConfigurationDatabase::RBXdatum>
378 (ConfigurationDatabase::eLEDenable,enable));
379 RBXdata.insert(std::pair<ConfigurationDatabase::RBXdatumId,ConfigurationDatabase::RBXdatum>
380 (ConfigurationDatabase::eLEDamplitude,ampl));
381 RBXdata.insert(std::pair<ConfigurationDatabase::RBXdatumId,ConfigurationDatabase::RBXdatum>
382 (ConfigurationDatabase::eLEDtiming_hb,((bunch&0xFF00)>>8)));
383 RBXdata.insert(std::pair<ConfigurationDatabase::RBXdatumId,ConfigurationDatabase::RBXdatum>
384 (ConfigurationDatabase::eLEDtiming_lb,(bunch&0xFF)));
387 int rm = rs->getInt(1);
388 int card = rs->getInt(2);
389 int qie_or_gol = rs->getInt(3);
390 unsigned int data = rs->getInt(4);
392 ConfigurationDatabase::RBXdatumId
id(rm,card,qie_or_gol,dtype);
393 RBXdata.insert(std::pair<ConfigurationDatabase::RBXdatumId,ConfigurationDatabase::RBXdatum>(
id,(
unsigned char)(data)));
398 conn_->terminateStatement(stmt);
399 }
catch (SQLException& e) {
400 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,::
toolbox::toString(
"Oracle exception : %s",e.getMessage().c_str()));
405 void ConfigurationDatabaseImplOracle::getZSThresholds(
const std::string& tag,
int crate,
int slot,
406 std::map<hcal::ConfigurationDatabase::ZSChannelId, int>&
thresholds)
411 Statement* stmt = conn_->createStatement();
417 std::string query = (
"SELECT HTR_FIBER, FIBER_CHANNEL, ZERO_SUPPRESSION, HTR_FPGA ");
418 query +=
" FROM CMS_HCL_HCAL_CONDITION_OWNER.V_HCAL_ZERO_SUPPRESSION_LHWM ";
419 query+=
toolbox::toString(
" WHERE TAG_NAME='%s' AND CRATE=%d AND HTR_SLOT=%d", tag.c_str(), crate, slot);
423 ResultSet *rs = stmt->executeQuery(query);
428 unsigned int fiber = rs->getInt(1);
429 unsigned int fc = rs->getInt(2);
430 unsigned int zs = rs->getInt(3);
433 if (fpga==
"top") tb = 1;
435 std::cout <<
"crate,slot,tb,fiber,fc:" << crate<<slot<<tb<<fiber<<fc<<std::endl;
436 hcal::ConfigurationDatabase::ZSChannelId
id(crate,slot,(hcal::ConfigurationDatabase::FPGASelection)tb,fiber,fc);
440 conn_->terminateStatement(stmt);
441 }
catch (SQLException& e) {
442 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,::
toolbox::toString(
"Oracle exception : %s",e.getMessage().c_str()));
448 void ConfigurationDatabaseImplOracle::getHLXMasks(
const std::string& tag,
int crate,
int slot,
449 std::map<hcal::ConfigurationDatabase::FPGAId, hcal::ConfigurationDatabase::HLXMasks>& masks)
451 if (m_hlxMaskCache.crate!=crate || m_hlxMaskCache.tag!=tag) {
452 m_hlxMaskCache.clear();
453 getHLXMasks_real(tag,crate,m_hlxMaskCache.masks);
454 m_hlxMaskCache.crate=crate;
455 m_hlxMaskCache.tag=
tag;
459 std::map<ConfigurationDatabase::FPGAId, ConfigurationDatabase::HLXMasks>::const_iterator
i;
460 for (i=m_hlxMaskCache.masks.begin(); i!=m_hlxMaskCache.masks.end(); i++) {
461 if (i->first.slot==slot)
467 void ConfigurationDatabaseImplOracle::getHLXMasks_real(
const std::string& tag,
int crate,
468 std::map<ConfigurationDatabase::FPGAId, ConfigurationDatabase::HLXMasks>& masks)
472 Statement* stmt = conn_->createStatement();
473 std::string query = (
"SELECT SLOT_NUMBER, FPGA, OCC_MASK, LHC_MASK, SUM_ET_MASK ");
474 query +=
" FROM CMS_HCL_HCAL_CONDITION_OWNER.V_HCAL_HLX_MASKS ";
475 query +=
toolbox::toString(
" WHERE TAG_NAME='%s' AND CRATE_NUMBER=%d ", tag.c_str(), crate);
478 ResultSet *rs = stmt->executeQuery(query);
481 int islot = rs->getInt(1);
485 if (fpga==
"top") ifpga = 1;
488 hcal::ConfigurationDatabase::FPGAId fpga_id;
489 fpga_id=hcal::ConfigurationDatabase::FPGAId(crate, islot,
490 (hcal::ConfigurationDatabase::FPGASelectionEnum)ifpga);
491 hcal::ConfigurationDatabase::HLXMasks hlxMask;
492 hlxMask.occMask = rs->getInt(3);
493 hlxMask.lhcMask = rs->getInt(4);
494 hlxMask.sumEtMask = rs->getInt(5);
496 masks[fpga_id]=hlxMask;
499 conn_->terminateStatement(stmt);
500 }
catch (SQLException& e) {
501 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,::
toolbox::toString(
"Oracle exception : %s",e.getMessage().c_str()));
506 oracle::occi::Connection * ConfigurationDatabaseImplOracle::getConnection(
void ){
510 oracle::occi::Environment * ConfigurationDatabaseImplOracle::getEnvironment(
void ){
static int cvtChar(int c)
def query(query_str, verbose=False)
char data[epos_bytes_allocation]
std::vector< unsigned short int > LUT