10 #include "toolbox/string.h"
12 #include "CaloOnlineTools/HcalOnlineDb/interface/ConfigurationItemNotFoundException.hh"
15 using namespace oracle::occi;
34 long long int _res_this, _res_other;
35 int _sub_this, _sub_other;
37 if (this->subdetector ==
"HE") _sub_this=1;
38 else if (this->subdetector ==
"HF") _sub_this=2;
39 else if (this->subdetector ==
"HO") _sub_this=3;
48 _res_this = 100+
eta + (
phi+100)*1000 + (depth+10)*1000000 + _sub_this*1000000000;
49 _res_other = 100+other.
eta + (other.
phi+100)*1000 + (other.
depth+10)*1000000 + _sub_other*1000000000;
51 return _res_this < _res_other;
56 std::map<HcalChannelId,HcalQIECaps> * result_sup =
new std::map<HcalChannelId,HcalQIECaps>;
57 std::map<HcalChannelId,HcalQIECaps> &
result = (*result_sup);
59 ifstream
infile( _filename . c_str() );
62 if ( infile . is_open() ){
64 while ( getline( infile, buf ) > 0 ){
65 std::vector<std::string> _line =
splitString( buf );
68 sscanf(_line[0].c_str(),
"%d", &_id .
eta);
69 sscanf(_line[1].c_str(),
"%d", &_id .
phi);
70 sscanf(_line[2].c_str(),
"%d", &_id . depth);
71 _id . subdetector = _line[3];
74 int _columns = _line .
size();
75 for(
int i = 4;
i != _columns;
i++){
76 sscanf(_line[
i].c_str(),
"%lf", &_adc . caps[
i-4]);
86 result.insert( std::pair<HcalChannelId,HcalQIECaps>(_id, _adc ) );
100 std::vector <std::string>
result;
103 for (
unsigned i = 0;
i <= fLine.size ();
i++) {
104 if (fLine [
i] ==
' ' || fLine [
i] ==
'\n' || fLine [
i] ==
' ' ||
i == fLine.size ()) {
107 result.push_back (item);
113 if (empty) empty =
false;
123 std::cout <<
"Creating the output file: " << output_file <<
"... ";
125 out_file . open( output_file.c_str() );
129 const std::string _accessor =
"occi://CMS_HCL_PRTTYPE_HCAL_READER@anyhost/int2r?PASSWORD=HCAL_Reader_88,LHWM_VERSION=22";
132 oracle::occi::Connection * _connection = db -> getConnection();
134 std::cout <<
"Preparing to request the QIE table from the database..." << std::endl;
137 for (
int _rm=1; _rm!=5; _rm++){
138 for (
int _qie=1; _qie!=4; _qie++){
140 cout <<
"Preparing the query..." << std::endl;
141 Statement* stmt = _connection -> createStatement();
145 std::cout <<
" Unable to open file with query!" << std::endl;
148 std::cout <<
"Query file opened successfully: " << query_file << std::endl;
150 while ( getline( inFile, buf ) > 0 ){
155 char query_fixed[50000];
156 sprintf(query_fixed,query.c_str(),_rm,_rm,_qie,_qie);
158 cout <<
"Preparing the query... done" << std::endl;
161 cout <<
"Executing the query..." << std::endl;
163 ResultSet *rs = stmt->executeQuery(query_fixed);
164 cout <<
"Executing the query... done" << std::endl;
166 cout <<
"Processing the query results..." << std::endl;
174 _id.
eta = rs->getInt(1);
175 _id.
phi = rs->getInt(2);
176 _id.
depth = rs->getInt(3);
178 for (
int j=0;
j!=32;
j++){
179 _caps.
caps[
j] = rs -> getDouble(
j+5);
187 for (
int j = 0;
j != 32;
j++){
188 double _x = _caps . caps[
j];
189 sprintf(buffer,
" %8.5f", _x);
194 out_file << std::endl;
199 _connection -> terminateStatement(stmt);
202 cout <<
"Query line count: " << _lines.
getCount() << std::endl;
204 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,::
toolbox::toString(
"Oracle exception : %s",e.getMessage().c_str()));
221 std::cout <<
"Creating the output file: " << output_file <<
"... ";
223 out_file . open( output_file.c_str() );
226 std::string badchan_file = output_file +
".badchannels";
227 std::cout <<
"Creating the output file for bad channels: " << badchan_file <<
"... ";
229 bad_file . open( badchan_file.c_str() );
232 std::map<HcalChannelId,HcalQIECaps> & _old = getQIETableFromFile( old_file . c_str() );
233 std::map<HcalChannelId,HcalQIECaps> & _new = getQIETableFromFile( db_file . c_str() );
237 int goodChannels = 0;
239 std::cout <<
"old size: " << _old.size() << std::endl;
240 std::cout <<
"new size: " << _new.size() << std::endl;
241 for (std::map<HcalChannelId,HcalQIECaps>::const_iterator
line=_old.begin();
line!=_old.end();
line++ ){
244 bool badchannel =
false;
245 if (_new.find(theId)==_new.end()){
248 the_caps = &_old[theId];
252 the_caps = &_new[theId];
257 int depth = theId.
depth;
258 sprintf(buffer,
"%15d %15d %15d %15s", eta, phi, depth, theId.
subdetector.c_str());
260 if (badchannel) bad_file << buffer;
262 for (
int j = 0;
j != 32;
j++){
263 double _x = the_caps->
caps[
j];
264 sprintf(buffer,
" %8.5f", _x);
266 if (badchannel) bad_file << buffer;
268 out_file << std::endl;
269 if (badchannel) bad_file << std::endl;
272 std::cout<< goodChannels<<
" " << badChannels <<
" " << goodChannels+badChannels << std::endl;
288 std::cout <<
"Creating the output file: " << output_file <<
"... ";
289 std::ofstream out_file;
290 out_file . open( output_file.c_str() );
294 std::map<std::string,std::vector<int> > _qie;
295 std::ifstream
infile( input_file . c_str() );
297 if ( infile . is_open() ){
298 std::cout <<
"File is open" << std::endl;
299 getline( infile, buf );
300 std::cout <<
"Table legend: " << std::endl << buf << std::endl;
301 while ( getline( infile, buf ) > 0 ){
302 std::vector<std::string> _line =
splitString( buf );
303 if ( _line .
size() != 17){
304 cout <<
"Table line is malformed, not clear what to do... exiting." << std::endl;
308 std::vector<int> _barcodes;
309 for (
int i=0;
i!=12;
i++){
311 sscanf(_line[
i+5].c_str(),
"%d", &_code);
312 _barcodes . push_back(_code);
320 const std::string _accessor =
"occi://CMS_HCL_PRTTYPE_HCAL_READER@anyhost/int2r?PASSWORD=HCAL_Reader_88,LHWM_VERSION=22";
322 oracle::occi::Connection * _connection = db -> getConnection();
323 std::cout <<
"Preparing to request the HF channels from LMAP in the database..." << std::endl;
325 std::cout <<
"Preparing the query..." << std::endl;
326 Statement* stmt = _connection -> createStatement();
328 std::cout <<
"Preparing the query... done" << std::endl;
330 query .
append(
"select\n");
331 query .
append(
"lmap.side*lmap.eta, lmap.phi, lmap.depth, lmap.subdetector,\n");
332 query .
append(
"lmap.rbx, lmap.rm_slot, lmap.qie_slot, lmap.adc\n");
333 query .
append(
"from cms_hcl_hcal_condition_owner.hcal_hardware_logical_maps_v3 lmap\n");
334 query .
append(
"inner join cms_hcl_core_condition_owner.cond_data_sets cds\n");
335 query .
append(
"on cds.condition_data_set_id=lmap.condition_data_set_id\n");
336 query .
append(
"where cds.version='30'\n");
337 query .
append(
"and lmap.subdetector='HF'\n");
338 query .
append(
"order by lmap.rbx, lmap.rm_slot, lmap.qie_slot, lmap.adc\n");
341 std::cout <<
"Executing the query..." << std::endl;
343 ResultSet *rs = stmt->executeQuery(query.c_str());
344 std::cout <<
"Executing the query... done" << std::endl;
346 std::cout <<
"Processing the query results..." << std::endl;
352 int rm_slot, qie_slot,
adc, qie_barcode;
354 _id.
eta = rs->getInt(1);
355 _id.
phi = rs->getInt(2);
356 _id.
depth = rs->getInt(3);
358 rbx = rs->getString(5);
359 rm_slot = rs->getInt(6);
360 qie_slot = rs->getInt(7);
362 qie_barcode = _qie[rbx][(rm_slot-1)*4+qie_slot-1];
368 Statement* stmt2 = _connection -> createStatement();
370 query2 .
append(
"select\n");
371 query2 .
append(
"vadcs.cap0_range0_offset,vadcs.cap0_range1_offset,vadcs.cap0_range2_offset,vadcs.cap0_range3_offset,\n");
372 query2 .
append(
"vadcs.cap1_range0_offset,vadcs.cap1_range1_offset,vadcs.cap1_range2_offset,vadcs.cap1_range3_offset,\n");
373 query2 .
append(
"vadcs.cap2_range0_offset,vadcs.cap2_range1_offset,vadcs.cap2_range2_offset,vadcs.cap2_range3_offset,\n");
374 query2 .
append(
"vadcs.cap3_range0_offset,vadcs.cap3_range1_offset,vadcs.cap3_range2_offset,vadcs.cap3_range3_offset,\n");
375 query2 .
append(
"vadcs.cap0_range0_slope,vadcs.cap0_range1_slope,vadcs.cap0_range2_slope,vadcs.cap0_range3_slope,\n");
376 query2 .
append(
"vadcs.cap1_range0_slope,vadcs.cap1_range1_slope,vadcs.cap1_range2_slope,vadcs.cap1_range3_slope,\n");
377 query2 .
append(
"vadcs.cap2_range0_slope,vadcs.cap2_range1_slope,vadcs.cap2_range2_slope,vadcs.cap2_range3_slope,\n");
378 query2 .
append(
"vadcs.cap3_range0_slope,vadcs.cap3_range1_slope,vadcs.cap3_range2_slope,vadcs.cap3_range3_slope\n");
379 query2 .
append(
"from CMS_HCL_HCAL_CONDITION_OWNER.V_QIECARD_ADC_NORMMODE vadcs\n");
380 query2 .
append(
"where substr(vadcs.name_label,14,6)='%d'\n");
381 query2 .
append(
"and substr(vadcs.name_label,21,1)='%d'\n");
382 query2 .
append(
"order by version desc,record_id desc, condition_data_set_id desc\n");
383 char query2_fixed[5000];
384 sprintf(query2_fixed,query2.c_str(),qie_barcode,
adc);
391 ResultSet *rs2 = stmt2->executeQuery(query2_fixed);
398 for (
int j=0;
j!=32;
j++){
399 _caps.
caps[
j] = rs2 -> getDouble(
j+1);
406 for (
int j = 0;
j != 32;
j++){
407 double _x = _caps . caps[
j];
408 sprintf(buffer,
" %8.5f", _x);
413 out_file << std::endl;
417 _connection -> terminateStatement(stmt2);
420 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,::
toolbox::toString(
"Oracle exception : %s",e.getMessage().c_str()));
424 _connection -> terminateStatement(stmt);
429 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)
std::string toString(const std::pair< T, T > &aT)
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.