00001 #include "CondTools/RunInfo/interface/L1TriggerScalerRead.h"
00002
00003
00004
00005 #include "RelationalAccess/ISession.h"
00006 #include "RelationalAccess/ITransaction.h"
00007 #include "RelationalAccess/ISchema.h"
00008 #include "RelationalAccess/ITable.h"
00009 #include "RelationalAccess/ITableDataEditor.h"
00010 #include "RelationalAccess/TableDescription.h"
00011 #include "RelationalAccess/IQuery.h"
00012 #include "RelationalAccess/ICursor.h"
00013 #include "CoralBase/AttributeList.h"
00014 #include "CoralBase/Attribute.h"
00015 #include "CoralBase/AttributeSpecification.h"
00016
00017
00018 #include "CondCore/DBCommon/interface/Time.h"
00019
00020 #include "CoralBase/TimeStamp.h"
00021
00022 #include "boost/date_time/posix_time/posix_time.hpp"
00023 #include "boost/date_time.hpp"
00024
00025 #include <iostream>
00026 #include <stdexcept>
00027 #include <vector>
00028 #include <math.h>
00029
00030
00031
00032
00033
00034 L1TriggerScalerRead::L1TriggerScalerRead(
00035
00036 const std::string& connectionString,
00037 const std::string& user,
00038 const std::string& pass):
00039 TestBase(),
00040
00041 m_connectionString( connectionString ),
00042 m_user( user ),
00043 m_pass( pass )
00044 {
00045 m_tableToDrop="";
00046
00047
00048
00049 }
00050
00051
00052 L1TriggerScalerRead::~L1TriggerScalerRead()
00053 {}
00054
00055
00056
00057 void
00058 L1TriggerScalerRead::run()
00059 {
00060
00061 }
00062
00063 void L1TriggerScalerRead::dropTable(const std::string & table){
00064 m_tableToDrop = table;
00065 coral::ISession* session = this->connect( m_connectionString,m_user, m_pass );
00066 session->transaction().start( );
00067 std::cout << "connected succesfully to omds" <<std::endl;
00068 coral::ISchema& schema = session->nominalSchema();
00069 schema.dropIfExistsTable( m_tableToDrop );
00070
00071 }
00072
00073
00074
00075
00076 std::vector<L1TriggerScaler::Lumi>
00077 L1TriggerScalerRead::readData(const int r_number)
00078 {
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113 std::cout<< "entering readData" << std::endl;
00114 coral::ISession* session = this->connect( m_connectionString,
00115 m_user, m_pass );
00116 session->transaction().start( );
00117 std::cout<< "starting session " << std::endl;
00118 coral::ISchema& schema = session->nominalSchema();
00119 std::cout<< " accessing schema " << std::endl;
00120
00121
00122 coral::IQuery* query0 = schema.tableHandle("RUNSESSION_PARAMETER").newQuery();
00123 std::cout<< "table handling " << std::endl;
00124 query0->addToOutputList("RUNSESSION_PARAMETER.STRING_VALUE" , "STRING_VALUE");
00125
00126 std::string condition0 = "RUNSESSION_PARAMETER.RUNNUMBER=:n_run AND RUNSESSION_PARAMETER.NAME='CMS.TRG:GTLumiSegInfo_format'";
00127 coral::AttributeList conditionData0;
00128 conditionData0.extend<int>( "n_run" );
00129 query0->setCondition( condition0, conditionData0 );
00130 conditionData0[0].data<int>() = r_number;
00131 coral::ICursor& cursor0 = query0->execute();
00132
00133 std::vector<L1TriggerScaler::Lumi> l1triggerscaler_array;
00134
00135 std::string string_format;
00136 while ( cursor0.next()!=0 )
00137 {
00138
00139 const coral::AttributeList& row = cursor0.currentRow();
00140 std::cout<< " entering the query == " << std::endl;
00141 string_format= row["STRING_VALUE"].data<std::string>();
00142
00143 std::cout<< " string value extracted == " << string_format << std::endl;
00144 }
00145
00146
00147
00148
00149
00150
00151
00152
00153 coral::IQuery* queryI = schema.tableHandle("RUNSESSION_PARAMETER").newQuery();
00154
00155
00156 std::cout<< "table handling " << std::endl;
00157
00158
00159 queryI->addToOutputList("RUNSESSION_PARAMETER.ID" , "ID");
00160
00161 queryI->addToOutputList("RUNSESSION_PARAMETER.TIME" , "TIME");
00162
00163
00164 std::string condition = "RUNSESSION_PARAMETER.RUNNUMBER=:n_run AND RUNSESSION_PARAMETER.NAME LIKE 'CMS.TRG:GTLumiSegInfo%' ORDER BY TIME ";
00165
00166 coral::AttributeList conditionData;
00167 conditionData.extend<int>( "n_run" );
00168 queryI->setCondition( condition, conditionData );
00169 conditionData[0].data<int>() = r_number;
00170 coral::ICursor& cursorI = queryI->execute();
00171
00172 std::vector<std::pair<int, long long> > v_vid;
00173
00174 if (cursorI.next()==0)
00175 {
00176
00177 std::cout<< " run " <<r_number <<" not full " << std::endl;
00178 }
00179 while ( cursorI.next()!=0 )
00180 {
00181
00182 L1TriggerScaler::Lumi Itemp;
00183
00184 Itemp.m_runnumber = r_number;
00185
00186 Itemp.m_date="0";
00187 Itemp.m_string_format= string_format;
00188 const coral::AttributeList& row = cursorI.currentRow();
00189 std::cout<< " entering the query == " << std::endl;
00190
00191
00192
00193 Itemp.m_lumi_id=row["ID"].data<long long>();
00194 std::cout<< " id value extracted == " << Itemp.m_lumi_id << std::endl;
00195
00196
00197 coral::TimeStamp st=row["TIME"].data<coral::TimeStamp>();
00198 int year= st.year();
00199 int month= st.month();
00200 int day= st.day();
00201 int hour= st.hour();
00202
00203 int minute= st.minute();
00204 int second = st.second();
00205 long nanosecond = st.nanosecond();
00206 std::cout<< " start time time extracted == " << "-->year " << year
00207 << "-- month " << month
00208 << "-- day " << day
00209 << "-- hour " << hour
00210 << "-- minute " << minute
00211 << "-- second " << second <<std::endl;
00212 boost::gregorian::date dt(year,month,day);
00213 boost::posix_time::time_duration td(hour,minute,second,nanosecond/1000);
00214 boost::posix_time::ptime pt( dt, td);
00215 Itemp.m_start_time = boost::posix_time::to_iso_extended_string(pt);
00216 std::cout<< " time extracted == " << Itemp.m_start_time << std::endl;
00217
00218
00219
00220 coral::IQuery* queryII = schema.newQuery();
00221 queryII->addToOutputList("RUNSESSION_VECTOR.VALUE_ID" , "VALUE_ID");
00222 queryII->addToOutputList("RUNSESSION_VECTOR.VALUE_INDEX" , "VALUE_INDEX");
00223
00224 queryII->addToTableList("RUNSESSION_VECTOR");
00225 std::string condition2 = "RUNSESSION_VECTOR.PARENT_ID=:n_vid";
00226 coral::AttributeList conditionData2;
00227 conditionData2.extend<long>( "n_vid" );
00228 queryII->setCondition( condition2, conditionData2 );
00229 conditionData2[0].data<long>() =Itemp.m_lumi_id +1 ;
00230 coral::ICursor& cursorII = queryII->execute();
00231 while ( cursorII.next()!=0 )
00232 {
00233 const coral::AttributeList& row = cursorII.currentRow();
00234 std::cout<< " entering the queryII == " << std::endl;
00235 long long vid_val = row["VALUE_ID"].data<long long>();
00236 int vid_id = (int)row["VALUE_INDEX"].data<long long>();
00237 v_vid.push_back(std::make_pair(vid_id, vid_val));
00238 std::cout<< " value_id index extracted == " << v_vid.back().first << std::endl;
00239 std::cout<< " value_id value extracted == " << v_vid.back().second << std::endl;
00240
00241
00242 coral::AttributeList conditionData3;
00243 conditionData3.extend<int>( "n_vid_val" );
00244 conditionData3[0].data<int>() =vid_val ;
00245 switch (vid_id){
00246 case 0: {
00247 std::cout<<" caso 0" << std::endl;
00248 coral::IQuery* queryIII = schema.newQuery();
00249 queryIII->addToOutputList("RUNSESSION_INTEGER.VALUE" , "VALUE");
00250 queryIII->addToTableList("RUNSESSION_INTEGER");
00251 std::string condition3 = "RUNSESSION_INTEGER.PARENT_ID=:n_vid_val";
00252 queryIII->setCondition( condition3, conditionData3 );
00253 coral::ICursor& cursorIII = queryIII->execute();
00254
00255
00256 while ( cursorIII.next()!=0 ) {
00257 const coral::AttributeList& row = cursorIII.currentRow();
00258
00259 Itemp.m_rn = row["VALUE"].data<long long>();
00260 std::cout<< " run extracted == " << Itemp.m_rn << std::endl;
00261 }
00262 delete queryIII;
00263 }
00264 break;
00265 case 1:{
00266 std::cout<<" caso 1" << std::endl;
00267 coral::IQuery* queryIII = schema.newQuery();
00268 queryIII->addToOutputList("RUNSESSION_INTEGER.VALUE" , "VALUE");
00269 queryIII->addToTableList("RUNSESSION_INTEGER");
00270 std::string condition3 = "RUNSESSION_INTEGER.PARENT_ID=:n_vid_val";
00271 queryIII->setCondition( condition3, conditionData3 );
00272 coral::ICursor& cursorIII = queryIII->execute();
00273 while ( cursorIII.next()!=0 ) {
00274 const coral::AttributeList& row = cursorIII.currentRow();
00275 std::cout<< " entering the queryIII " << std::endl;
00276 Itemp.m_lumisegment = row["VALUE"].data<long long>();
00277 std::cout<< " lumisegment extracted == " << Itemp.m_lumisegment << std::endl;
00278 }
00279 delete queryIII;
00280 }
00281 break;
00282 case 2:{
00283 std::cout<<" caso 2" << std::endl;
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300 }
00301 break;
00302 case 3:{
00303 std::cout<<" caso 3" << std::endl;
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320 }
00321 break;
00322 case 4:{
00323 std::cout<<" caso 4" << std::endl;
00324 coral::IQuery* queryIII = schema.newQuery();
00325 queryIII->addToOutputList("RUNSESSION_DATE.VALUE" , "VALUE");
00326 queryIII->addToTableList("RUNSESSION_DATE");
00327 std::string condition3 = "RUNSESSION_DATE.PARENT_ID=:n_vid_val";
00328 queryIII->setCondition( condition3, conditionData3 );
00329 coral::ICursor& cursorIII = queryIII->execute();
00330 if ( cursorIII.next()!=0 ) {
00331 const coral::AttributeList& row = cursorIII.currentRow();
00332 std::cout<< " entering the queryIII " << std::endl;
00333 coral::TimeStamp ts = row["VALUE"].data<coral::TimeStamp>();
00334 int year= ts.year();
00335 int month= ts.month();
00336 int day= ts.day();
00337 int hour= ts.hour();
00338
00339 int minute= ts.minute();
00340 int second = ts.second();
00341 long nanosecond = ts.nanosecond();
00342 std::cout<< " start time time extracted == " << "-->year " << year
00343 << "-- month " << month
00344 << "-- day " << day
00345 << "-- hour " << hour
00346 << "-- minute " << minute
00347 << "-- second " << second <<std::endl;
00348 boost::gregorian::date dt(year,month,day);
00349 boost::posix_time::time_duration td(hour,minute,second,nanosecond/1000);
00350 boost::posix_time::ptime pt( dt, td);
00351 Itemp.m_date = boost::posix_time::to_iso_extended_string(pt);
00352 std::cout<< " date extracted == " << Itemp.m_date << std::endl;
00353 } else {
00354 Itemp.m_date=="NULL";
00355 std::cout<< "date extracted == " << Itemp.m_date<<std::endl;
00356 }
00357 delete queryIII;
00358 }
00359 break;
00360 case 5:{
00361
00362 std::cout<<" caso 5" << std::endl;
00363 coral::IQuery* queryIII = schema.newQuery();
00364 queryIII->addToOutputList("RUNSESSION_INTEGER.VALUE" , "VALUE");
00365 queryIII->addToTableList("RUNSESSION_INTEGER");
00366 std::string condition3 = "RUNSESSION_INTEGER.PARENT_ID=:n_vid_val";
00367 queryIII->setCondition( condition3, conditionData3 );
00368 coral::ICursor& cursorIII = queryIII->execute();
00369 int i=0;
00370 while ( cursorIII.next()!=0 ) {
00371 const coral::AttributeList& row = cursorIII.currentRow();
00372 std::cout<< " entering the queryIII " << std::endl;
00373 int v = (int)row["VALUE"].data<long long>();
00374 Itemp.m_GTAlgoCounts.push_back(v);
00375
00376 i++;
00377 }
00378
00379 delete queryIII;
00380
00381 }
00382
00383 break;
00384 case 6:{
00385
00386 std::cout<<" caso 6" << std::endl;
00387 coral::IQuery* queryIII = schema.newQuery();
00388 queryIII->addToOutputList("RUNSESSION_FLOAT.VALUE" , "VALUE");
00389 queryIII->addToTableList("RUNSESSION_FLOAT");
00390 std::string condition3 = "RUNSESSION_FLOAT.PARENT_ID=:n_vid_val";
00391 queryIII->setCondition( condition3, conditionData3 );
00392 coral::ICursor& cursorIII = queryIII->execute();
00393 int i=0;
00394 while ( cursorIII.next()!=0 ) {
00395 const coral::AttributeList& row = cursorIII.currentRow();
00396 std::cout<< " entering the queryIII " << std::endl;
00397 float v = (float)row["VALUE"].data<double>();
00398 Itemp.m_GTAlgoRates.push_back(v);
00399
00400 i++;
00401 }
00402
00403 delete queryIII;
00404
00405 }
00406
00407 break;
00408
00409 case 7:{
00410
00411 std::cout<<" caso 7" << std::endl;
00412 coral::IQuery* queryIII = schema.newQuery();
00413 queryIII->addToOutputList("RUNSESSION_INTEGER.VALUE" , "VALUE");
00414 queryIII->addToTableList("RUNSESSION_INTEGER");
00415 std::string condition3 = "RUNSESSION_INTEGER.PARENT_ID=:n_vid_val";
00416 queryIII->setCondition( condition3, conditionData3 );
00417 coral::ICursor& cursorIII = queryIII->execute();
00418 int i=0;
00419 while ( cursorIII.next()!=0 ) {
00420 const coral::AttributeList& row = cursorIII.currentRow();
00421 std::cout<< " entering the queryIII " << std::endl;
00422 int v = (int)row["VALUE"].data<long long>();
00423 Itemp.m_GTAlgoPrescaling.push_back(v);
00424
00425 i++;
00426 }
00427
00428 delete queryIII;
00429
00430 }
00431
00432 break;
00433 case 8:{
00434
00435 std::cout<<" caso 8" << std::endl;
00436 coral::IQuery* queryIII = schema.newQuery();
00437 queryIII->addToOutputList("RUNSESSION_INTEGER.VALUE" , "VALUE");
00438 queryIII->addToTableList("RUNSESSION_INTEGER");
00439 std::string condition3 = "RUNSESSION_INTEGER.PARENT_ID=:n_vid_val";
00440 queryIII->setCondition( condition3, conditionData3 );
00441 coral::ICursor& cursorIII = queryIII->execute();
00442 int i=0;
00443 while ( cursorIII.next()!=0 ) {
00444 const coral::AttributeList& row = cursorIII.currentRow();
00445 std::cout<< " entering the queryIII " << std::endl;
00446 int v = (int)row["VALUE"].data<long long>();
00447 Itemp.m_GTTechCounts.push_back(v);
00448
00449 i++;
00450 }
00451
00452 delete queryIII;
00453
00454 }
00455
00456 break;
00457 case 9:{
00458
00459 std::cout<<" caso 9" << std::endl;
00460 coral::IQuery* queryIII = schema.newQuery();
00461 queryIII->addToOutputList("RUNSESSION_FLOAT.VALUE" , "VALUE");
00462 queryIII->addToTableList("RUNSESSION_FLOAT");
00463 std::string condition3 = "RUNSESSION_FLOAT.PARENT_ID=:n_vid_val";
00464 queryIII->setCondition( condition3, conditionData3 );
00465 coral::ICursor& cursorIII = queryIII->execute();
00466 int i=0;
00467 while ( cursorIII.next()!=0 ) {
00468 const coral::AttributeList& row = cursorIII.currentRow();
00469 std::cout<< " entering the queryIII " << std::endl;
00470 float v = (float)row["VALUE"].data<double>();
00471 Itemp.m_GTTechRates.push_back(v);
00472
00473 i++;
00474 }
00475
00476 delete queryIII;
00477
00478 }
00479
00480 break;
00481 case 10:{
00482
00483 std::cout<<" caso 10" << std::endl;
00484 coral::IQuery* queryIII = schema.newQuery();
00485 queryIII->addToOutputList("RUNSESSION_INTEGER.VALUE" , "VALUE");
00486 queryIII->addToTableList("RUNSESSION_INTEGER");
00487 std::string condition3 = "RUNSESSION_INTEGER.PARENT_ID=:n_vid_val";
00488 queryIII->setCondition( condition3, conditionData3 );
00489 coral::ICursor& cursorIII = queryIII->execute();
00490 int i=0;
00491 while ( cursorIII.next()!=0 ) {
00492 const coral::AttributeList& row = cursorIII.currentRow();
00493 std::cout<< " entering the queryIII " << std::endl;
00494 int v = (int)row["VALUE"].data<long long>();
00495 Itemp.m_GTTechPrescaling.push_back(v);
00496
00497 i++;
00498 }
00499
00500 delete queryIII;
00501
00502 }
00503
00504 break;
00505 case 11:{
00506
00507 std::cout<<" caso 11" << std::endl;
00508 coral::IQuery* queryIII = schema.newQuery();
00509 queryIII->addToOutputList("RUNSESSION_INTEGER.VALUE" , "VALUE");
00510 queryIII->addToTableList("RUNSESSION_INTEGER");
00511 std::string condition3 = "RUNSESSION_INTEGER.PARENT_ID=:n_vid_val";
00512 queryIII->setCondition( condition3, conditionData3 );
00513 coral::ICursor& cursorIII = queryIII->execute();
00514 int i=0;
00515 while ( cursorIII.next()!=0 ) {
00516 const coral::AttributeList& row = cursorIII.currentRow();
00517 std::cout<< " entering the queryIII " << std::endl;
00518 int v = (int)row["VALUE"].data<long long>();
00519 Itemp.m_GTPartition0TriggerCounts.push_back(v);
00520
00521 i++;
00522 }
00523
00524 delete queryIII;
00525
00526 }
00527
00528 break;
00529 case 12:{
00530
00531 std::cout<<" caso 12" << std::endl;
00532 coral::IQuery* queryIII = schema.newQuery();
00533 queryIII->addToOutputList("RUNSESSION_FLOAT.VALUE" , "VALUE");
00534 queryIII->addToTableList("RUNSESSION_FLOAT");
00535 std::string condition3 = "RUNSESSION_FLOAT.PARENT_ID=:n_vid_val";
00536 queryIII->setCondition( condition3, conditionData3 );
00537 coral::ICursor& cursorIII = queryIII->execute();
00538 int i=0;
00539 while ( cursorIII.next()!=0 ) {
00540 const coral::AttributeList& row = cursorIII.currentRow();
00541 std::cout<< " entering the queryIII " << std::endl;
00542 float v = (float)row["VALUE"].data<double>();
00543 Itemp.m_GTPartition0TriggerRates.push_back(v);
00544
00545 i++;
00546 }
00547
00548 delete queryIII;
00549
00550 }
00551
00552 break;
00553 case 13:{
00554
00555 std::cout<<" caso 13" << std::endl;
00556 coral::IQuery* queryIII = schema.newQuery();
00557 queryIII->addToOutputList("RUNSESSION_INTEGER.VALUE" , "VALUE");
00558 queryIII->addToTableList("RUNSESSION_INTEGER");
00559 std::string condition3 = "RUNSESSION_INTEGER.PARENT_ID=:n_vid_val";
00560 queryIII->setCondition( condition3, conditionData3 );
00561 coral::ICursor& cursorIII = queryIII->execute();
00562 int i=0;
00563 while ( cursorIII.next()!=0 ) {
00564 const coral::AttributeList& row = cursorIII.currentRow();
00565 std::cout<< " entering the queryIII " << std::endl;
00566 int v = (int)row["VALUE"].data<long long>();
00567 Itemp.m_GTPartition0DeadTime.push_back(v);
00568
00569 i++;
00570 }
00571
00572 delete queryIII;
00573
00574 }
00575
00576 break;
00577 case 14:{
00578
00579 std::cout<<" caso 14" << std::endl;
00580 coral::IQuery* queryIII = schema.newQuery();
00581 queryIII->addToOutputList("RUNSESSION_FLOAT.VALUE" , "VALUE");
00582 queryIII->addToTableList("RUNSESSION_FLOAT");
00583 std::string condition3 = "RUNSESSION_FLOAT.PARENT_ID=:n_vid_val";
00584 queryIII->setCondition( condition3, conditionData3 );
00585 coral::ICursor& cursorIII = queryIII->execute();
00586 int i=0;
00587 while ( cursorIII.next()!=0 ) {
00588 const coral::AttributeList& row = cursorIII.currentRow();
00589 std::cout<< " entering the queryIII " << std::endl;
00590 float v = (float)row["VALUE"].data<double>();
00591 Itemp.m_GTPartition0DeadTimeRatio.push_back(v);
00592
00593 i++;
00594 }
00595
00596 delete queryIII;
00597
00598 }
00599
00600 break;
00601
00602 default:
00603 std::cout<< "index out of range" << std::endl;
00604 break;
00605
00606 }
00607
00608
00609
00610 }
00611 delete queryII;
00612
00613
00614
00615 l1triggerscaler_array.push_back(Itemp);
00616
00617 }
00618
00619 delete queryI;
00620
00621
00622 session->transaction().commit();
00623 delete session;
00624
00625
00626
00627
00628 return l1triggerscaler_array;
00629 }
00630
00631
00632