10 #include "CaloOnlineTools/HcalOnlineDb/interface/ConfigurationItemNotFoundException.hh"
13 #include "toolbox/string.h"
19 using namespace oracle::occi;
38 long long int _res_this, _res_other;
39 int _sub_this, _sub_other;
41 if (this->subdetector ==
"HE") _sub_this=1;
42 else if (this->subdetector ==
"HF") _sub_this=2;
43 else if (this->subdetector ==
"HO") _sub_this=3;
52 _res_this = 100+
eta + (
phi+100)*1000 + (
depth+10)*1000000 + _sub_this*1000000000;
53 _res_other = 100+other.
eta + (other.
phi+100)*1000 + (other.
depth+10)*1000000 + _sub_other*1000000000;
55 return _res_this < _res_other;
60 std::map<HcalChannelId,HcalQIECaps> * result_sup =
new std::map<HcalChannelId,HcalQIECaps>;
61 std::map<HcalChannelId,HcalQIECaps> &
result = (*result_sup);
63 ifstream
infile( _filename . c_str() );
66 if ( infile . is_open() ){
68 while ( getline( infile, buf ) > 0 ){
69 std::vector<std::string> _line =
splitString( buf );
72 sscanf(_line[0].c_str(),
"%d", &_id .
eta);
73 sscanf(_line[1].c_str(),
"%d", &_id .
phi);
74 sscanf(_line[2].c_str(),
"%d", &_id .
depth);
75 _id . subdetector = _line[3];
78 int _columns = _line .
size();
79 for(
int i = 4;
i != _columns;
i++){
80 sscanf(_line[
i].c_str(),
"%lf", &_adc . caps[
i-4]);
90 result.insert( std::pair<HcalChannelId,HcalQIECaps>(_id, _adc ) );
104 std::vector <std::string>
result;
107 for (
unsigned i = 0;
i <= fLine.size ();
i++) {
108 if (fLine [
i] ==
' ' || fLine [
i] ==
'\n' || fLine [
i] ==
' ' ||
i == fLine.size ()) {
111 result.push_back (item);
117 if (empty) empty =
false;
127 std::cout <<
"Creating the output file: " << output_file <<
"... ";
129 out_file . open( output_file.c_str() );
133 const std::string _accessor =
"occi://CMS_HCL_PRTTYPE_HCAL_READER@anyhost/int2r?PASSWORD=HCAL_Reader_88,LHWM_VERSION=22";
136 oracle::occi::Connection * _connection = db -> getConnection();
138 std::cout <<
"Preparing to request the QIE table from the database..." << std::endl;
141 for (
int _rm=1; _rm!=5; _rm++){
142 for (
int _qie=1; _qie!=4; _qie++){
144 cout <<
"Preparing the query..." << std::endl;
145 Statement* stmt = _connection -> createStatement();
149 std::cout <<
" Unable to open file with query!" << std::endl;
152 std::cout <<
"Query file opened successfully: " << query_file << std::endl;
154 while ( getline( inFile, buf ) > 0 ){
159 char query_fixed[50000];
160 sprintf(query_fixed,query.c_str(),_rm,_rm,_qie,_qie);
162 cout <<
"Preparing the query... done" << std::endl;
165 cout <<
"Executing the query..." << std::endl;
167 ResultSet *rs = stmt->executeQuery(query_fixed);
168 cout <<
"Executing the query... done" << std::endl;
170 cout <<
"Processing the query results..." << std::endl;
178 _id.
eta = rs->getInt(1);
179 _id.
phi = rs->getInt(2);
180 _id.
depth = rs->getInt(3);
182 for (
int j=0;
j!=32;
j++){
183 _caps.
caps[
j] = rs -> getDouble(
j+5);
191 for (
int j = 0;
j != 32;
j++){
192 double _x = _caps . caps[
j];
193 sprintf(buffer,
" %8.5f", _x);
198 out_file << std::endl;
203 _connection -> terminateStatement(stmt);
206 cout <<
"Query line count: " << _lines.
getCount() << std::endl;
208 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,::
toolbox::toString(
"Oracle exception : %s",e.getMessage().c_str()));
225 std::cout <<
"Creating the output file: " << output_file <<
"... ";
227 out_file . open( output_file.c_str() );
230 std::string badchan_file = output_file +
".badchannels";
231 std::cout <<
"Creating the output file for bad channels: " << badchan_file <<
"... ";
233 bad_file . open( badchan_file.c_str() );
236 std::map<HcalChannelId,HcalQIECaps> & _old = getQIETableFromFile( old_file . c_str() );
237 std::map<HcalChannelId,HcalQIECaps> & _new = getQIETableFromFile( db_file . c_str() );
241 int goodChannels = 0;
243 std::cout <<
"old size: " << _old.size() << std::endl;
244 std::cout <<
"new size: " << _new.size() << std::endl;
245 for (std::map<HcalChannelId,HcalQIECaps>::const_iterator
line=_old.begin();
line!=_old.end();
line++ ){
248 bool badchannel =
false;
249 if (_new.find(theId)==_new.end()){
252 the_caps = &_old[theId];
256 the_caps = &_new[theId];
262 sprintf(buffer,
"%15d %15d %15d %15s", eta, phi, depth, theId.
subdetector.c_str());
264 if (badchannel) bad_file << buffer;
266 for (
int j = 0;
j != 32;
j++){
267 double _x = the_caps->
caps[
j];
268 sprintf(buffer,
" %8.5f", _x);
270 if (badchannel) bad_file << buffer;
272 out_file << std::endl;
273 if (badchannel) bad_file << std::endl;
276 std::cout<< goodChannels<<
" " << badChannels <<
" " << goodChannels+badChannels << std::endl;
292 std::cout <<
"Creating the output file: " << output_file <<
"... ";
293 std::ofstream out_file;
294 out_file . open( output_file.c_str() );
298 std::map<std::string,std::vector<int> > _qie;
299 std::ifstream
infile( input_file . c_str() );
301 if ( infile . is_open() ){
302 std::cout <<
"File is open" << std::endl;
303 getline( infile, buf );
304 std::cout <<
"Table legend: " << std::endl << buf << std::endl;
305 while ( getline( infile, buf ) > 0 ){
306 std::vector<std::string> _line =
splitString( buf );
307 if ( _line .
size() != 17){
308 cout <<
"Table line is malformed, not clear what to do... exiting." << std::endl;
312 std::vector<int> _barcodes;
313 for (
int i=0;
i!=12;
i++){
315 sscanf(_line[
i+5].c_str(),
"%d", &_code);
316 _barcodes . push_back(_code);
324 const std::string _accessor =
"occi://CMS_HCL_PRTTYPE_HCAL_READER@anyhost/int2r?PASSWORD=HCAL_Reader_88,LHWM_VERSION=22";
326 oracle::occi::Connection * _connection = db -> getConnection();
327 std::cout <<
"Preparing to request the HF channels from LMAP in the database..." << std::endl;
329 std::cout <<
"Preparing the query..." << std::endl;
330 Statement* stmt = _connection -> createStatement();
332 std::cout <<
"Preparing the query... done" << std::endl;
334 query .
append(
"select\n");
335 query .
append(
"lmap.side*lmap.eta, lmap.phi, lmap.depth, lmap.subdetector,\n");
336 query .
append(
"lmap.rbx, lmap.rm_slot, lmap.qie_slot, lmap.adc\n");
337 query .
append(
"from cms_hcl_hcal_condition_owner.hcal_hardware_logical_maps_v3 lmap\n");
338 query .
append(
"inner join cms_hcl_core_condition_owner.cond_data_sets cds\n");
339 query .
append(
"on cds.condition_data_set_id=lmap.condition_data_set_id\n");
340 query .
append(
"where cds.version='30'\n");
341 query .
append(
"and lmap.subdetector='HF'\n");
342 query .
append(
"order by lmap.rbx, lmap.rm_slot, lmap.qie_slot, lmap.adc\n");
345 std::cout <<
"Executing the query..." << std::endl;
347 ResultSet *rs = stmt->executeQuery(query.c_str());
348 std::cout <<
"Executing the query... done" << std::endl;
350 std::cout <<
"Processing the query results..." << std::endl;
356 int rm_slot, qie_slot,
adc, qie_barcode;
358 _id.
eta = rs->getInt(1);
359 _id.
phi = rs->getInt(2);
360 _id.
depth = rs->getInt(3);
362 rbx = rs->getString(5);
363 rm_slot = rs->getInt(6);
364 qie_slot = rs->getInt(7);
366 qie_barcode = _qie[rbx][(rm_slot-1)*4+qie_slot-1];
372 Statement* stmt2 = _connection -> createStatement();
374 query2 .
append(
"select\n");
375 query2 .
append(
"vadcs.cap0_range0_offset,vadcs.cap0_range1_offset,vadcs.cap0_range2_offset,vadcs.cap0_range3_offset,\n");
376 query2 .
append(
"vadcs.cap1_range0_offset,vadcs.cap1_range1_offset,vadcs.cap1_range2_offset,vadcs.cap1_range3_offset,\n");
377 query2 .
append(
"vadcs.cap2_range0_offset,vadcs.cap2_range1_offset,vadcs.cap2_range2_offset,vadcs.cap2_range3_offset,\n");
378 query2 .
append(
"vadcs.cap3_range0_offset,vadcs.cap3_range1_offset,vadcs.cap3_range2_offset,vadcs.cap3_range3_offset,\n");
379 query2 .
append(
"vadcs.cap0_range0_slope,vadcs.cap0_range1_slope,vadcs.cap0_range2_slope,vadcs.cap0_range3_slope,\n");
380 query2 .
append(
"vadcs.cap1_range0_slope,vadcs.cap1_range1_slope,vadcs.cap1_range2_slope,vadcs.cap1_range3_slope,\n");
381 query2 .
append(
"vadcs.cap2_range0_slope,vadcs.cap2_range1_slope,vadcs.cap2_range2_slope,vadcs.cap2_range3_slope,\n");
382 query2 .
append(
"vadcs.cap3_range0_slope,vadcs.cap3_range1_slope,vadcs.cap3_range2_slope,vadcs.cap3_range3_slope\n");
383 query2 .
append(
"from CMS_HCL_HCAL_CONDITION_OWNER.V_QIECARD_ADC_NORMMODE vadcs\n");
384 query2 .
append(
"where substr(vadcs.name_label,14,6)='%d'\n");
385 query2 .
append(
"and substr(vadcs.name_label,21,1)='%d'\n");
386 query2 .
append(
"order by version desc,record_id desc, condition_data_set_id desc\n");
387 char query2_fixed[5000];
388 sprintf(query2_fixed,query2.c_str(),qie_barcode,
adc);
395 ResultSet *rs2 = stmt2->executeQuery(query2_fixed);
402 for (
int j=0;
j!=32;
j++){
403 _caps.
caps[
j] = rs2 -> getDouble(
j+1);
410 for (
int j = 0;
j != 32;
j++){
411 double _x = _caps . caps[
j];
412 sprintf(buffer,
" %8.5f", _x);
417 out_file << std::endl;
421 _connection -> terminateStatement(stmt2);
424 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,::
toolbox::toString(
"Oracle exception : %s",e.getMessage().c_str()));
428 _connection -> terminateStatement(stmt);
433 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,::
toolbox::toString(
"Oracle exception : %s",e.getMessage().c_str()));
int adc(sample_type sample)
get the ADC sample (12 bits)
tuple start
Check for commandline option errors.
int generateQieTable(std::string db_file, std::string old_file, std::string output_file)
unsigned long int getCount(void)
std::vector< std::string > splitString(const std::string &fLine)
oracle::occi::SQLException SQLException
static std::vector< std::string > splitString(const std::string &fLine)
bool operator<(const HcalChannelId &other) const
bool insert(Storage &iStorage, ItemType *iItem, const IdTag &iIdTag)
Gather config data from online DB.
std::map< HcalChannelId, HcalQIECaps > & getQIETableFromFile(std::string _filename)
oracle::occi::ResultSet ResultSet
void getTableFromDb(std::string query_file, std::string output_file)
int getHfQieTable(std::string input_file, std::string output_file)
tuple size
Write out results.