5 #include "RelationalAccess/ISession.h"
6 #include "RelationalAccess/ITransaction.h"
7 #include "RelationalAccess/ISchema.h"
8 #include "RelationalAccess/ITable.h"
9 #include "RelationalAccess/ITableDataEditor.h"
10 #include "RelationalAccess/TableDescription.h"
11 #include "RelationalAccess/IQuery.h"
12 #include "RelationalAccess/ICursor.h"
13 #include "CoralBase/AttributeList.h"
14 #include "CoralBase/Attribute.h"
15 #include "CoralBase/AttributeSpecification.h"
20 #include "CoralBase/TimeStamp.h"
22 #include "boost/date_time/posix_time/posix_time.hpp"
23 #include "boost/date_time.hpp"
41 m_connectionString( connectionString ),
104 temp_sum.
m_run = r_number;
106 std::cout<<
"entering readData" << std::endl;
109 session->transaction().start( );
110 std::cout<<
"starting session " << std::endl;
111 coral::ISchema&
schema = session->nominalSchema();
112 std::cout<<
" accessing schema " << std::endl;
115 coral::IQuery* queryI = schema.tableHandle(
m_tableToRead).newQuery();
120 coral::AttributeList conditionData;
121 conditionData.extend<
int>(
"n_run" );
122 conditionData[0].data<
int>() = r_number;
127 queryI->setCondition( condition1, conditionData );
128 coral::ICursor& cursorI = queryI->execute();
130 if ( cursorI.next()!=0 ) {
131 const coral::AttributeList& row = cursorI.currentRow();
143 long long id_start=0;
145 coral::IQuery* queryII = schema.tableHandle( m_tableToRead).newQuery();
148 queryII->addToOutputList( m_tableToRead +
"." + m_columnToRead_id, m_columnToRead_id );
150 std::string condition2 = m_tableToRead +
".runnumber=:n_run AND " + m_tableToRead +
".name='CMS.LVL0:START_TIME_T'";
151 queryII->setCondition( condition2, conditionData );
152 coral::ICursor& cursorII = queryII->execute();
154 if ( cursorII.next()!=0 ) {
155 const coral::AttributeList& row = cursorII.currentRow();
156 id_start= row[m_columnToRead_id].data<
long long>();
157 std::cout<<
" id for start time time extracted == " <<id_start << std::endl;
161 std::cout<<
" id for start time time extracted == " <<id_start << std::endl;
170 coral::IQuery* queryIII = schema.tableHandle( m_tableToRead_date).newQuery();
173 queryIII->addToOutputList( m_tableToRead_date +
"." + m_columnToRead_val, m_columnToRead_val );
175 coral::AttributeList conditionData3;
176 conditionData3.extend<
long long>(
"n_id" );
177 conditionData3[0].data<
long long>() = id_start;
178 std::string condition3 = m_tableToRead_date +
".runsession_parameter_id=:n_id";
179 queryIII->setCondition( condition3, conditionData3 );
180 coral::ICursor& cursorIII = queryIII->execute();
182 if ( cursorIII.next()!=0 ) {
183 const coral::AttributeList& row = cursorIII.currentRow();
184 coral::TimeStamp ts = row[m_columnToRead_val].data<coral::TimeStamp>();
186 int month= ts.month();
189 int minute= ts.minute();
191 long nanosecond = ts.nanosecond();
197 std::cout<<
" start time time extracted == " <<
"-->year " << year
198 <<
"-- month " << month
200 <<
"-- hour " << hour
201 <<
"-- minute " << minute
202 <<
"-- second " << second
203 <<
"-- nanosecond " << nanosecond<<std::endl;
204 boost::gregorian::date
dt(year,month,day);
206 boost::posix_time::time_duration td(hour-1,minute,second,nanosecond/1000);
208 boost::posix_time::ptime
pt( dt, td);
218 boost::posix_time::ptime time_at_epoch( boost::gregorian::date( 1970, 1, 1 ) ) ;
220 boost::posix_time::time_duration time_diff = ( pt - time_at_epoch ) ;
233 coral::IQuery* queryIV = schema.tableHandle( m_tableToRead).newQuery();
236 queryIV->addToOutputList( m_tableToRead +
"." + m_columnToRead_id, m_columnToRead_id );
238 std::string condition4 = m_tableToRead +
".runnumber=:n_run AND " + m_tableToRead +
".name='CMS.LVL0:STOP_TIME_T'";
240 queryIV->setCondition( condition4, conditionData );
242 coral::ICursor& cursorIV = queryIV->execute();
246 if ( cursorIV.next()!=0 ) {
247 const coral::AttributeList& row = cursorIV.currentRow();
249 id_stop= row[m_columnToRead_id].data<
long long>();
250 std::cout<<
" id for stop time time extracted == " <<id_stop << std::endl;
259 coral::IQuery* queryIVbis = schema.tableHandle( m_tableToRead_date).newQuery();
262 queryIVbis->addToOutputList( m_tableToRead_date +
"." + m_columnToRead_val, m_columnToRead_val );
264 coral::AttributeList conditionData4bis;
265 conditionData4bis.extend<
long long>(
"n_id" );
266 conditionData4bis[0].data<
long long>() = id_stop;
267 std::string condition4bis = m_tableToRead_date +
".runsession_parameter_id=:n_id";
268 queryIVbis->setCondition( condition4bis, conditionData4bis );
269 coral::ICursor& cursorIVbis = queryIVbis->execute();
270 if ( cursorIVbis.next()!=0 ) {
271 const coral::AttributeList& row = cursorIVbis.currentRow();
272 coral::TimeStamp ts = row[m_columnToRead_val].data<coral::TimeStamp>();
274 int month= ts.month();
277 int minute= ts.minute();
279 long nanosecond = ts.nanosecond();
280 std::cout<<
" stop time time extracted == " <<
"-->year " << year
281 <<
"-- month " << month
283 <<
"-- hour " << hour
284 <<
"-- minute " << minute
285 <<
"-- second " << second
286 <<
"-- nanosecond " << nanosecond<<std::endl;
287 boost::gregorian::date
dt(year,month,day);
289 boost::posix_time::time_duration td(hour-1,minute,second,nanosecond/1000);
290 boost::posix_time::ptime
pt( dt, td);
292 temp_sum.
m_stop_time_str = boost::posix_time::to_iso_extended_string(pt);
294 boost::posix_time::ptime time_at_epoch( boost::gregorian::date( 1970, 1, 1 ) ) ;
296 boost::posix_time::time_duration time_diff = ( pt - time_at_epoch ) ;
307 const std::string m_tableToRead_ls=
"HLT_SUPERVISOR_LUMISECTIONS_V2";
310 coral::IQuery* queryV = schema.tableHandle( m_tableToRead_ls ).newQuery();
311 queryV->addToOutputList(
"MAX(" + m_tableToRead_ls +
"." + m_columnToRead_ls +
")", m_columnToRead_ls );
312 std::string condition5 = m_tableToRead_ls +
".runnr=:n_run " ;
315 queryV->setCondition( condition5, conditionData );
318 coral::ICursor& cursorV = queryV->execute();
319 if ( cursorV.next()!=0 ) {
320 const coral::AttributeList& row = cursorV.currentRow();
321 double lumisections = row[m_columnToRead_ls].data<
double>();
328 std::cout<<
" leaving the query "<< std::endl;
338 coral::IQuery* queryVIPIXEL = schema.tableHandle( m_tableToRead).newQuery();
341 std::string condition6PIXEL = m_tableToRead +
".runnumber=:n_run AND " + m_tableToRead +
".name='CMS.LVL0:PIXEL'";
342 queryVIPIXEL->setCondition( condition6PIXEL, conditionData );
343 coral::ICursor& cursorVIPIXEL = queryVIPIXEL->execute();
345 if ( cursorVIPIXEL.next()!=0 ) {
346 const coral::AttributeList& row = cursorVIPIXEL.currentRow();
356 coral::IQuery* queryVITRACKER = schema.tableHandle( m_tableToRead).newQuery();
359 std::string condition6TRACKER = m_tableToRead +
".runnumber=:n_run AND " + m_tableToRead +
".name='CMS.LVL0:TRACKER'";
360 queryVITRACKER->setCondition( condition6TRACKER, conditionData );
361 coral::ICursor& cursorVITRACKER = queryVITRACKER->execute();
363 if ( cursorVITRACKER.next()!=0 ) {
364 const coral::AttributeList& row = cursorVITRACKER.currentRow();
373 delete queryVITRACKER;
375 coral::IQuery* queryVIECAL = schema.tableHandle( m_tableToRead).newQuery();
378 std::string condition6ECAL = m_tableToRead +
".runnumber=:n_run AND " + m_tableToRead +
".name='CMS.LVL0:ECAL'";
379 queryVIECAL->setCondition( condition6ECAL, conditionData );
380 coral::ICursor& cursorVIECAL = queryVIECAL->execute();
382 if ( cursorVIECAL.next()!=0 ) {
383 const coral::AttributeList& row = cursorVIECAL.currentRow();
394 coral::IQuery* queryVIHCAL = schema.tableHandle( m_tableToRead).newQuery();
397 std::string condition6HCAL = m_tableToRead +
".runnumber=:n_run AND " + m_tableToRead +
".name='CMS.LVL0:HCAL'";
398 queryVIHCAL->setCondition( condition6HCAL, conditionData );
399 coral::ICursor& cursorVIHCAL = queryVIHCAL->execute();
401 if ( cursorVIHCAL.next()!=0 ) {
402 const coral::AttributeList& row = cursorVIHCAL.currentRow();
414 coral::IQuery* queryVIDT = schema.tableHandle( m_tableToRead).newQuery();
417 std::string condition6DT = m_tableToRead +
".runnumber=:n_run AND " + m_tableToRead +
".name='CMS.LVL0:DT'";
418 queryVIDT->setCondition( condition6DT, conditionData );
419 coral::ICursor& cursorVIDT = queryVIDT->execute();
421 if ( cursorVIDT.next()!=0 ) {
422 const coral::AttributeList& row = cursorVIDT.currentRow();
433 coral::IQuery* queryVICSC = schema.tableHandle( m_tableToRead).newQuery();
436 std::string condition6CSC = m_tableToRead +
".runnumber=:n_run AND " + m_tableToRead +
".name='CMS.LVL0:CSC'";
437 queryVICSC->setCondition( condition6CSC, conditionData );
438 coral::ICursor& cursorVICSC = queryVICSC->execute();
440 if ( cursorVICSC.next()!=0 ) {
441 const coral::AttributeList& row = cursorVICSC.currentRow();
452 coral::IQuery* queryVIRPC = schema.tableHandle( m_tableToRead).newQuery();
455 std::string condition6RPC = m_tableToRead +
".runnumber=:n_run AND " + m_tableToRead +
".name='CMS.LVL0:RPC'";
456 queryVIRPC->setCondition( condition6RPC, conditionData );
457 coral::ICursor& cursorVIRPC = queryVIRPC->execute();
459 if ( cursorVIRPC.next()!=0 ) {
460 const coral::AttributeList& row = cursorVIRPC.currentRow();
477 coral::IQuery* queryVII = schema.tableHandle( m_tableToRead).newQuery();
482 coral::AttributeList conditionData7;
483 conditionData7.extend<
int>(
"n_run" );
484 conditionData7[0].data<
int>() = r_number;
488 std::string condition7 = m_tableToRead +
".runnumber=:n_run AND " + m_tableToRead +
".name='CMS.LVL0:HLT_KEY_DESCRIPTION'";
489 queryVII->setCondition( condition7, conditionData7 );
490 coral::ICursor& cursorVII = queryVII->execute();
492 if ( cursorVII.next()!=0 ) {
493 const coral::AttributeList& row = cursorVII.currentRow();
504 coral::IQuery* queryVIII = schema.tableHandle( m_tableToRead).newQuery();
509 coral::AttributeList conditionData8;
510 conditionData8.extend<
int>(
"n_run" );
511 conditionData8[0].data<
int>() = r_number;
515 std::string condition8 = m_tableToRead +
".runnumber=:n_run AND " + m_tableToRead +
".name='CMS.TRG:EVNR' ORDER BY TIME DESC";
516 queryVIII->setCondition( condition8, conditionData8 );
517 coral::ICursor& cursorVIII = queryVIII->execute();
519 if ( cursorVIII.next()!=0 ) {
520 const coral::AttributeList& row = cursorVIII.currentRow();
534 coral::IQuery* queryIX = schema.tableHandle( m_tableToRead).newQuery();
540 coral::AttributeList conditionData9;
541 conditionData9.extend<
int>(
"n_run" );
542 conditionData9[0].data<
int>() = r_number;
546 std::string condition9 = m_tableToRead +
".runnumber=:n_run AND " + m_tableToRead +
".name='CMS.TRG:Rate' ORDER BY TIME";
548 queryIX->setCondition( condition9, conditionData9 );
549 coral::ICursor& cursorIX = queryIX->execute();
551 if ( cursorIX.next()!=0 ) {
552 const coral::AttributeList& row = cursorIX.currentRow();
568 session->transaction().commit();
std::vector< int > m_subdt_in
RunSummary readData(const std::string &table, const std::string &column, const int r_number)
std::string m_tableToRead
std::string m_stop_time_str
virtual ~RunSummaryRead()
U second(std::pair< T, U > const &p)
std::string m_columnToRead
std::string m_connectionString
RunSummaryRead(const std::string &connectionString, const std::string &user, const std::string &pass)
long long m_start_time_ll
std::string m_start_time_str
coral::ISession * connect(const std::string &connectionString, const std::string &user, const std::string &password)