#include <CondTools/RunInfo/interface/RunInfoRead.h>
Public Member Functions | |
RunInfo::RunInfo | readData (const std::string &table, const std::string &column, const int r_number) |
void | run () |
RunInfoRead (const std::string &connectionString, const std::string &user, const std::string &pass) | |
virtual | ~RunInfoRead () |
Private Attributes | |
std::string | m_columnToRead |
std::string | m_connectionString |
std::string | m_pass |
std::string | m_tableToRead |
std::string | m_user |
Definition at line 11 of file RunInfoRead.h.
RunInfoRead::RunInfoRead | ( | const std::string & | connectionString, | |
const std::string & | user, | |||
const std::string & | pass | |||
) |
Definition at line 34 of file RunInfoRead.cc.
References m_columnToRead, and m_tableToRead.
00038 : 00039 TestBase(), 00040 00041 m_connectionString( connectionString ), 00042 m_user( user ), 00043 m_pass( pass ) 00044 { 00045 00046 m_tableToRead=""; 00047 m_columnToRead=""; 00048 00049 }
RunInfoRead::~RunInfoRead | ( | ) | [virtual] |
RunInfo::RunInfo RunInfoRead::readData | ( | const std::string & | table, | |
const std::string & | column, | |||
const int | r_number | |||
) |
The number of nanoseconds from epoch 01/01/1970 UTC, normally should fit into 64bit signed integer, depends on the BOOST installation
The number of nanoseconds from epoch 01/01/1970 UTC, normally should fit into 64bit signed integer, depends on the BOOST installation
Definition at line 68 of file RunInfoRead.cc.
References TestBase::connect(), GenMuonPlsPt100GeV_cfg::cout, lat::endl(), i, m_columnToRead, m_connectionString, m_pass, m_tableToRead, m_user, max, min, replace(), row, RunInfo::RunInfo(), python::listobjects::schema, edm::second(), python::TagTree::session, size, ss, sum(), and getDQMSummary::td.
Referenced by RunInfoHandler::getNewObjects().
00069 { 00070 m_tableToRead = table; // to be cms_runinfo.runsession_parameter 00071 m_columnToRead= column; // to be string_value; 00072 00073 00074 00075 RunInfo::RunInfo sum; 00076 RunInfo::RunInfo temp_sum; 00077 RunInfo Sum; 00078 00079 00080 00081 // if cursor is null setting null values 00082 temp_sum.m_run = r_number; 00083 00084 std::cout<< "entering readData" << std::endl; 00085 coral::ISession* session = this->connect( m_connectionString, 00086 m_user, m_pass ); 00087 session->transaction().start( ); 00088 std::cout<< "starting session " << std::endl; 00089 coral::ISchema& schema = session->nominalSchema(); 00090 std::cout<< " accessing schema " << std::endl; 00091 std::cout<< " trying to handle table :: " << m_tableToRead << std::endl; 00092 // coral::IQuery* queryI = schema.newQuery(); 00093 00094 00095 00096 // condition 00097 00098 coral::AttributeList conditionData; 00099 conditionData.extend<int>( "n_run" ); 00100 conditionData[0].data<int>() = r_number; 00101 00102 00103 00104 00105 00106 std::string m_columnToRead_id = "ID"; 00107 long long id_start=0; 00108 // new query to obtain the start_time, fist obtaining the id 00109 coral::IQuery* queryI = schema.tableHandle( m_tableToRead).newQuery(); 00110 //queryIII->addToTableList( m_tableToRead ); 00111 // implemating the query here....... 00112 queryI->addToOutputList( m_tableToRead + "." + m_columnToRead_id, m_columnToRead_id ); 00113 // condition 00114 std::string condition1 = m_tableToRead + ".runnumber=:n_run AND " + m_tableToRead + ".name='CMS.LVL0:START_TIME_T'"; 00115 queryI->setCondition( condition1, conditionData ); 00116 coral::ICursor& cursorI = queryI->execute(); 00117 00118 if ( cursorI.next()!=0 ) { 00119 const coral::AttributeList& row = cursorI.currentRow(); 00120 id_start= row[m_columnToRead_id].data<long long>(); 00121 std::cout<< " id for start time time extracted == " <<id_start << std::endl; 00122 } 00123 else{ 00124 id_start=-1; 00125 std::cout<< " id for start time time extracted == " <<id_start << std::endl; 00126 } 00127 00128 delete queryI; 00129 00130 // now exctracting the start time 00131 std::string m_tableToRead_date= "RUNSESSION_DATE"; 00132 std::string m_columnToRead_val= "VALUE"; 00133 // new query to obtain the start_time, fist obtaining the id 00134 coral::IQuery* queryII = schema.tableHandle( m_tableToRead_date).newQuery(); 00135 //queryII->addToTableList( m_tableToRead ); 00136 // implemating the query here....... 00137 queryII->addToOutputList( m_tableToRead_date + "." + m_columnToRead_val, m_columnToRead_val ); 00138 // condition 00139 coral::AttributeList conditionData2; 00140 conditionData2.extend<long long>( "n_id" ); 00141 conditionData2[0].data<long long>() = id_start; 00142 std::string condition2 = m_tableToRead_date + ".runsession_parameter_id=:n_id"; 00143 queryII->setCondition( condition2, conditionData2 ); 00144 coral::ICursor& cursorII = queryII->execute(); 00145 coral::TimeStamp start; 00146 coral::TimeStamp start_time; 00147 if ( cursorII.next()!=0 ) { 00148 const coral::AttributeList& row = cursorII.currentRow(); 00149 start = row[m_columnToRead_val].data<coral::TimeStamp>(); 00150 int year= start.year(); 00151 int month= start.month(); 00152 int day= start.day(); 00153 int hour= start.hour(); 00154 int minute= start.minute(); 00155 int second = start.second(); 00156 long nanosecond = start.nanosecond(); 00157 //const std::string toString= start.toString() ; 00159 //const signed long long int total_nanoseconds=start.total_nanoseconds() ; 00160 start_time= coral::TimeStamp(year, month, day, hour-2, minute, second , nanosecond); 00161 int adj_hour= start_time.hour(); 00162 00163 std::cout<< " start time time extracted == " << "-->year " << year 00164 << "-- month " << month 00165 << "-- day " << day 00166 << "-- hour " << hour 00167 << "-- adj_hour " << adj_hour 00168 << "-- minute " << minute 00169 << "-- second " << second 00170 << "-- nanosecond " << nanosecond<<std::endl; 00171 boost::gregorian::date dt(year,month,day); 00172 // td in microsecond 00173 boost::posix_time::time_duration td(hour,minute,second,nanosecond/1000); 00174 00175 boost::posix_time::ptime pt( dt, td); 00176 //boost::gregorian::date(year,month,day), 00177 //boost::posix_time::hours(hour)+boost::posix_time::minutes(minute)+ 00178 //boost::posix_time::seconds(second)+ 00179 //nanosec(nanosecond)); 00180 // boost::posix_time::ptime pt(start); 00181 std::cout<<"ptime == "<< pt <<std::endl; 00182 00183 temp_sum.m_start_time_str = boost::posix_time::to_iso_extended_string(pt); 00184 std::cout<<"start time string extracted == "<<temp_sum.m_start_time_str <<std::endl; 00185 boost::posix_time::ptime time_at_epoch( boost::gregorian::date( 1970, 1, 1 ) ) ; 00186 // Subtract time_at_epoch from current time to get the required value. 00187 boost::posix_time::time_duration time_diff = ( pt - time_at_epoch ) ; 00188 temp_sum.m_start_time_ll = time_diff.total_microseconds(); 00189 std::cout << "microsecond since Epoch (UTC) : " <<temp_sum.m_start_time_ll <<std::endl; 00190 } 00191 else 00192 { 00193 temp_sum.m_start_time_str = "null"; 00194 temp_sum.m_start_time_ll = -1; 00195 } 00196 delete queryII; 00197 00198 00199 // new query to obtain the stop_time, fist obtaining the id 00200 coral::IQuery* queryIII = schema.tableHandle( m_tableToRead).newQuery(); 00201 //queryII->addToTableList( m_tableToRead ); 00202 // implemating the query here....... 00203 queryIII->addToOutputList( m_tableToRead + "." + m_columnToRead_id, m_columnToRead_id ); 00204 // condition 00205 std::string condition3 = m_tableToRead + ".runnumber=:n_run AND " + m_tableToRead + ".name='CMS.LVL0:STOP_TIME_T'"; 00206 00207 queryIII->setCondition( condition3, conditionData ); 00208 00209 coral::ICursor& cursorIII = queryIII->execute(); 00210 00211 00212 long long id_stop=0; 00213 if ( cursorIII.next()!=0 ) { 00214 const coral::AttributeList& row = cursorIII.currentRow(); 00215 00216 id_stop= row[m_columnToRead_id].data<long long>(); 00217 std::cout<< " id for stop time time extracted == " <<id_stop << std::endl; 00218 } 00219 else{ 00220 id_stop=-1; 00221 } 00222 delete queryIII; 00223 00224 // now exctracting the start time 00225 // new query to obtain the start_time, fist obtaining the id 00226 coral::IQuery* queryIV = schema.tableHandle( m_tableToRead_date).newQuery(); 00227 //queryIII->addToTableList( m_tableToRead ); 00228 // implemating the query here....... 00229 queryIV->addToOutputList( m_tableToRead_date + "." + m_columnToRead_val, m_columnToRead_val ); 00230 // condition 00231 coral::AttributeList conditionData4; 00232 conditionData4.extend<long long>( "n_id" ); 00233 conditionData4[0].data<long long>() = id_stop; 00234 std::string condition4 = m_tableToRead_date + ".runsession_parameter_id=:n_id"; 00235 coral::TimeStamp stop; 00236 coral::TimeStamp stop_time; 00237 00238 00239 queryIV->setCondition( condition4, conditionData4 ); 00240 coral::ICursor& cursorIV = queryIV->execute(); 00241 if ( cursorIV.next()!=0 ) { 00242 const coral::AttributeList& row = cursorIV.currentRow(); 00243 stop = row[m_columnToRead_val].data<coral::TimeStamp>(); 00244 int year= stop.year(); 00245 int month= stop.month(); 00246 int day= stop.day(); 00247 int hour= stop.hour(); 00248 int minute= stop.minute(); 00249 int second = stop.second(); 00250 long nanosecond = stop.nanosecond(); 00251 00252 //adjust to to UTC 00253 stop_time=coral::TimeStamp(year, month, day, hour-2, minute, second , nanosecond); 00254 int adj_hour= stop_time.hour(); 00255 00256 00257 std::cout<< " stop time time extracted == " << "-->year " << year 00258 << "-- month " << month 00259 << "-- day " << day 00260 << "-- hour " << hour 00261 << "-- adj_hour " << adj_hour 00262 << "-- minute " << minute 00263 << "-- second " << second 00264 << "-- nanosecond " << nanosecond<<std::endl; 00265 boost::gregorian::date dt(year,month,day); 00266 boost::posix_time::time_duration td(hour,minute,second,nanosecond/1000); 00267 boost::posix_time::ptime pt( dt, td); 00268 std::cout<<"ptime == "<< pt <<std::endl; 00269 temp_sum.m_stop_time_str = boost::posix_time::to_iso_extended_string(pt); 00270 std::cout<<"stop time string extracted == "<<temp_sum.m_stop_time_str <<std::endl; 00271 boost::posix_time::ptime time_at_epoch( boost::gregorian::date( 1970, 1, 1 ) ) ; 00272 // Subtract time_at_epoch from current time to get the required value. 00273 boost::posix_time::time_duration time_diff = ( pt - time_at_epoch ) ; 00274 temp_sum.m_stop_time_ll = time_diff.total_microseconds(); 00275 std::cout << "microsecond since Epoch (UTC) : " <<temp_sum.m_stop_time_ll <<std::endl; 00276 00277 00278 } 00279 else{ 00280 temp_sum.m_stop_time_str="null"; 00281 temp_sum.m_stop_time_ll=-1; 00282 } 00283 delete queryIV; 00284 00285 00286 coral::IQuery* queryV = schema.tableHandle( m_tableToRead).newQuery(); 00287 00288 queryV->addToOutputList( m_tableToRead + "." + m_columnToRead, m_columnToRead ); 00289 // cond 00290 00291 00292 std::string condition5 = m_tableToRead + ".runnumber=:n_run AND " + m_tableToRead + ".name='CMS.LVL0:FED_ENABLE_MASK'"; 00293 queryV->setCondition( condition5, conditionData ); 00294 coral::ICursor& cursorV = queryV->execute(); 00295 std::string fed; 00296 if ( cursorV.next()!=0 ) { 00297 const coral::AttributeList& row = cursorV.currentRow(); 00298 fed= row[m_columnToRead].data<std::string>(); 00299 // std::cout<< " string fed emask == " << fed << std::endl; 00300 } 00301 else{ 00302 fed="null"; 00303 // std::cout<< " string fed emask == " << fed << std::endl; 00304 } 00305 00306 delete queryV; 00307 00308 std::replace(fed.begin(), fed.end(), '%', ' '); 00309 std::stringstream stream(fed); 00310 for(;;) { 00311 std::string word; 00312 if (!(stream>> word)){break;} 00313 std::replace(word.begin(), word.end(), '&', ' '); 00314 std::stringstream ss(word); 00315 int fed; int val; 00316 ss>>fed>>val; 00317 if ( (val % 2) ==1 ) temp_sum.m_fed_in.push_back(fed); 00318 00319 } 00320 00321 for (size_t i =0; i<temp_sum.m_fed_in.size() ;i++){ 00322 std::cout<< "fed in run" << temp_sum.m_fed_in[i] << std::endl; 00323 } 00324 00325 00326 00327 00328 coral::ISchema& schema2 = session->schema("CMS_DCS_ENV_PVSS_COND"); 00329 00330 std::string m_tableToRead_cur= "CMSFWMAGNET"; 00331 std::string m_columnToRead_cur= "CURRENT"; 00332 std::string m_columnToRead_date= "CHANGE_DATE"; 00333 00334 coral::IQuery* queryVI = schema2.tableHandle( m_tableToRead_cur).newQuery(); 00335 00336 queryVI->addToOutputList( m_tableToRead_cur + "." + m_columnToRead_cur , m_columnToRead_cur ); 00337 queryVI->addToOutputList( m_tableToRead_cur + "." + m_columnToRead_date , m_columnToRead_date ); 00338 00339 // condition 00340 coral::AttributeList conditionData6; 00341 00342 if (temp_sum.m_stop_time_str!="null") { 00343 conditionData6.extend<coral::TimeStamp>( "runstart_time" ); 00344 conditionData6.extend<coral::TimeStamp>( "runstop_time" ); 00345 conditionData6["runstart_time"].data<coral::TimeStamp>() = start ; 00346 conditionData6["runstop_time"].data<coral::TimeStamp>() = stop ; 00347 std::string conditionVI = " NOT " + m_tableToRead_cur + "." + m_columnToRead_cur + " IS NULL AND "+ m_columnToRead_date+ ">:runstart_time AND "+ m_columnToRead_date + "<:runstop_time " "ORDER BY " + m_columnToRead_date + " DESC"; 00348 queryVI->setCondition( conditionVI , conditionData6 ); 00349 } else { 00350 00351 std::string conditionVI = " NOT " + m_tableToRead_cur + "." + m_columnToRead_cur + " IS NULL ORDER BY " + m_columnToRead_date + " DESC"; 00352 queryVI->setCondition( conditionVI , conditionData6 ); 00353 } 00354 00355 queryVI->limitReturnedRows( 10000 ); 00356 coral::ICursor& cursorVI = queryVI->execute(); 00357 std::string last_date; 00358 00359 std::vector<double> time_curr; 00360 00361 if (cursorVI.next()==0 ){ 00362 last_date=="null"; 00363 std::cout<<"last current extracted == "<<last_date <<std::endl; 00364 00365 00366 } 00367 00368 while ( cursorVI.next()!=0 ) { 00369 const coral::AttributeList& row = cursorVI.currentRow(); 00370 coral::TimeStamp ld = row[m_columnToRead_date].data<coral::TimeStamp>(); 00371 00372 temp_sum.m_current.push_back( row[m_columnToRead_cur].data<float>()); 00373 if (temp_sum.m_stop_time_str=="null") break; 00374 00375 00376 00377 00378 int year= ld.year(); 00379 int month= ld.month(); 00380 int day= ld.day(); 00381 int hour= ld.hour(); 00382 int minute= ld.minute(); 00383 int second = ld.second(); 00384 long nanosecond = ld.nanosecond(); 00385 //const std::string toString= ld.toString() ; 00387 //const signed long long int total_nanoseconds=ld.total_nanoseconds() ; 00388 00389 00390 // std::cout<< " start time time extracted == " << "-->year " << year 00391 // << "-- month " << month 00392 // << "-- day " << day 00393 // << "-- hour " << hour 00394 // << "-- minute " << minute 00395 // << "-- second " << second 00396 // << "-- nanosecond " << nanosecond<<std::endl; 00397 00398 boost::gregorian::date dt(year,month,day); 00399 // td in microsecond 00400 boost::posix_time::time_duration td(hour,minute,second,nanosecond/1000); 00401 boost::posix_time::ptime pt( dt, td); 00402 00403 //std::cout<<"ptime == "<< pt <<std::endl; 00404 00405 last_date = boost::posix_time::to_iso_extended_string(pt); 00406 std::cout<<"last current time extracted == "<<last_date <<std::endl; 00407 boost::posix_time::ptime time_at_epoch( boost::gregorian::date( 1970, 1, 1 ) ) ; 00408 // Subtract time_at_epoch from current time to get the required value. 00409 boost::posix_time::time_duration time_diff = ( pt - time_at_epoch ) ; 00410 long long last_date_ll = time_diff.total_microseconds(); 00411 time_curr.push_back(last_date_ll); 00412 //std::cout << "microsecond since Epoch (UTC) : " << last_date_ll <<std::endl; 00413 00414 00415 } 00416 00417 00418 delete queryVI; 00419 00420 size_t size= temp_sum.m_current.size(); 00421 //std::cout<< "size of currents " <<size<< std::endl; 00422 size_t tsize= time_curr.size(); 00423 //std::cout<< "size of time " << tsize<< std::endl; 00424 if (size !=tsize ) { std::cout<< "current and time not filled correctely " << std::endl;} 00425 00426 if ( tsize > 1 ) { temp_sum.m_run_intervall_micros = time_curr[0] - time_curr[tsize-1];} else { temp_sum.m_run_intervall_micros=0;} 00427 00428 std::cout<< "run intervall in microseconds " << temp_sum.m_run_intervall_micros << std::endl; 00429 00430 double wi=0; 00431 std::vector<double> v_wi; 00432 double sumwixi=0; 00433 double sumwi=0; 00434 float min=-1; 00435 float max=-1; 00436 00437 if (size!=0 ){ 00438 min=temp_sum.m_current[0]; 00439 max=temp_sum.m_current[0]; 00440 for(size_t i=0; i< temp_sum.m_current.size(); i++){ 00441 std::cout<< "--> " << temp_sum.m_current[i] << std::endl; 00442 if (tsize >1 && ( i < temp_sum.m_current.size()-1 )) { wi = (time_curr[i] - time_curr[i+1]) ; 00443 v_wi.push_back(wi); 00444 sumwixi+= wi * temp_sum.m_current[i] ; 00445 sumwi += wi; 00446 } 00447 min= std::min(min, temp_sum.m_current[i]); 00448 max= std::max(max, temp_sum.m_current[i]); 00449 } 00450 00451 for (size_t i =0; i<v_wi.size(); i++){ 00452 std::cout<<"wi "<<v_wi[i]<<std::endl; 00453 } 00454 temp_sum.m_start_current=(temp_sum.m_current[0]) ; 00455 std::cout<< "--> " << "start cur "<< temp_sum.m_start_current << std::endl; 00456 00457 temp_sum.m_stop_current=temp_sum.m_current[size-1]; 00458 std::cout<< "--> " << "stop cur "<< temp_sum.m_stop_current << std::endl; 00459 if (tsize>1 ) {temp_sum.m_avg_current=sumwixi/sumwi ;} 00460 else { temp_sum.m_avg_current= temp_sum.m_start_current; } 00461 std::cout<< "--> " << "avg cur "<< temp_sum.m_avg_current << std::endl; 00462 temp_sum.m_max_current= max; 00463 std::cout<< "--> " << "max cur "<< temp_sum.m_max_current << std::endl; 00464 temp_sum.m_min_current= min; 00465 std::cout<< "--> " << "min cur "<< temp_sum.m_min_current << std::endl; 00466 }else{ 00467 temp_sum.m_avg_current=-1; 00468 temp_sum.m_min_current=-1; 00469 temp_sum.m_max_current=-1; 00470 temp_sum.m_stop_current=-1; 00471 temp_sum.m_start_current=-1; 00472 } 00473 00474 00475 00476 00477 00478 00479 session->transaction().commit(); 00480 delete session; 00481 00482 00483 sum= temp_sum; 00484 return sum; 00485 }
void RunInfoRead::run | ( | ) | [virtual] |
std::string RunInfoRead::m_columnToRead [private] |
std::string RunInfoRead::m_connectionString [private] |
std::string RunInfoRead::m_pass [private] |
std::string RunInfoRead::m_tableToRead [private] |
std::string RunInfoRead::m_user [private] |