void readTag( const std::string& tag, Session& session, const boost::posix_time::ptime& snapshotTime ){ IOVProxy proxy; if( snapshotTime.is_not_a_date_time() ) proxy = session.readIov( tag ); else proxy = session.readIov( tag, snapshotTime ); std::cout <<"> iov loaded size="<<proxy.loadedSize()<<std::endl; std::cout <<"> iov sequence size="<<proxy.sequenceSize()<<std::endl; IOVProxy::Iterator iovIt = proxy.find( 107 ); if( iovIt == proxy.end() ){ std::cout <<">[0] not found!"<<std::endl; } else { cond::Iov_t val = *iovIt; std::cout <<"#[0] iov since="<<val.since<<" till="<<val.till<<" pid="<<val.payloadId<<std::endl; boost::shared_ptr<std::string> pay0 = session.fetchPayload<std::string>( val.payloadId ); std::cout <<"#[0] payload="<<*pay0<<std::endl; } iovIt = proxy.find( 235 ); if( iovIt == proxy.end() ){ std::cout <<">[1] not found!"<<std::endl; } else { cond::Iov_t val = *iovIt; std::cout <<"#[1] iov since="<<val.since<<" till="<<val.till<<" pid="<<val.payloadId<<std::endl; boost::shared_ptr<std::string> pay0 = session.fetchPayload<std::string>( val.payloadId ); std::cout <<"#[1] payload="<<*pay0<<std::endl; } }
int readIov( IOVProxy& proxy, cond::Time_t targetTime, bool expectedOk ){ IOVProxy::Iterator iovIt = proxy.find( targetTime ); if( expectedOk ){ if( iovIt == proxy.end() ){ std::cout <<"#ERROR: no valid iov found for time "<<targetTime<<std::endl; return -1; } else { std::cout <<"#OK: found iov with since "<<(*iovIt).since<<" - till "<<(*iovIt).till<<" for time "<<targetTime<<std::endl; } } else { if( iovIt == proxy.end() ){ std::cout <<"#OK: no valid iov found for time "<<targetTime<<std::endl; } else { std::cout <<"#ERROR: found iov="<<(*iovIt).since<<" for time "<<targetTime<<std::endl; return -1; } } return 0; }
int main (int argc, char** argv) { edmplugin::PluginManager::Config config; edmplugin::PluginManager::configure(edmplugin::standard::config()); //std::string connectionString("oracle://cms_orcoff_prep/CMS_CONDITIONS"); //std::string connectionString("sqlite_file:/build/gg/cms_conditions.db"); //std::string connectionString("sqlite_file:cms_conditions.db"); std::string connectionString("sqlite_file:cms_conditions_ora.db"); std::cout <<"# Connecting with db in "<<connectionString<<std::endl; try{ //************* Session session; session.configuration().setMessageVerbosity( coral::Debug ); session.open( connectionString ); session.transaction().start( false ); MyTestData d0( 17 ); MyTestData d1( 999 ); std::cout <<"# Storing payloads..."<<std::endl; cond::Hash p0 = session.storePayload( d0, boost::posix_time::microsec_clock::universal_time() ); cond::Hash p1 = session.storePayload( d1, boost::posix_time::microsec_clock::universal_time() ); std::string d("abcd1234"); cond::Hash p3 = session.storePayload( d, boost::posix_time::microsec_clock::universal_time() ); IOVEditor editor = session.createIov<MyTestData>( "MyNewIOV", cond::runnumber ); editor.setDescription("Test with MyTestData class"); editor.insert( 1, p0 ); editor.insert( 100, p1 ); std::cout <<"# inserted 2 iovs..."<<std::endl; editor.flush(); std::cout <<"# iov changes flushed..."<<std::endl; editor = session.createIov<std::string>( "StringData", cond::timestamp ); editor.setDescription("Test with std::string class"); editor.insert( 1000000, p3 ); editor.insert( 2000000, p3 ); editor.flush(); session.transaction().commit(); std::cout <<"# iov changes committed!..."<<std::endl; ::sleep(2); session.transaction().start(); IOVProxy proxy = session.readIov( "MyNewIOV" ); IOVProxy::Iterator iovIt = proxy.find( 57 ); if( iovIt == proxy.end() ){ std::cout <<"#0 not found!"<<std::endl; } else { cond::Iov_t val = *iovIt; std::cout <<"#0 iov since="<<val.since<<" till="<<val.till<<" pid="<<val.payloadId<<std::endl; boost::shared_ptr<MyTestData> pay0 = session.fetchPayload<MyTestData>( val.payloadId ); pay0->print(); } iovIt++; if(iovIt == proxy.end() ){ std::cout<<"#1 not found!"<<std::endl; } else { cond::Iov_t val =*iovIt; std::cout <<"#1 iov since="<<val.since<<" till="<<val.till<<" pid="<<val.payloadId<<std::endl; boost::shared_ptr<MyTestData> pay1 = session.fetchPayload<MyTestData>( val.payloadId ); pay1->print(); } iovIt = proxy.find( 176 ); if( iovIt == proxy.end() ){ std::cout <<"#2 not found!"<<std::endl; } else { cond::Iov_t val = *iovIt; std::cout <<"#2 iov since="<<val.since<<" till="<<val.till<<" pid="<<val.payloadId<<std::endl; boost::shared_ptr<MyTestData> pay2 = session.fetchPayload<MyTestData>( val.payloadId ); pay2->print(); } iovIt++; if(iovIt == proxy.end() ){ std::cout<<"#3 not found!"<<std::endl; } else { cond::Iov_t val =*iovIt; std::cout <<"#3 iov since="<<val.since<<" till="<<val.till<<" pid="<<val.payloadId<<std::endl; boost::shared_ptr<MyTestData> pay3 = session.fetchPayload<MyTestData>( val.payloadId ); pay3->print(); } proxy = session.readIov( "StringData" ); auto iov2It = proxy.find( 1000022 ); if(iov2It == proxy.end() ){ std::cout<<"#4 not found!"<<std::endl; } else { cond::Iov_t val =*iov2It; std::cout <<"#4 iov since="<<val.since<<" till="<<val.till<<" pid="<<val.payloadId<<std::endl; boost::shared_ptr<std::string> pay4 = session.fetchPayload<std::string>( val.payloadId ); std::cout <<" ## pay4="<<*pay4<<std::endl; } session.transaction().commit(); } catch (const std::exception& e){ std::cout << "ERROR: " << e.what() << std::endl; return -1; } catch (...){ std::cout << "UNEXPECTED FAILURE." << std::endl; return -1; } }
int run( const std::string& connectionString ){ try{ //************* std::cout <<"> Connecting with db in "<<connectionString<<std::endl; ConnectionPool connPool; connPool.setMessageVerbosity( coral::Debug ); Session session = connPool.createSession( connectionString, true ); session.transaction().start( false ); std::string pay0("Payload #0"); std::string pay1("Payload #1"); auto p0 = session.storePayload( pay0); auto p1 = session.storePayload( pay1); IOVEditor editor; if( !session.existsIov( "MyTag" ) ){ editor = session.createIov<std::string>( "MyTag", cond::runnumber ); editor.setDescription("Test for timestamp selection"); editor.insert( 100, p0 ); editor.insert( 200, p1 ); editor.insert( 1001, p0 ); editor.insert( 1500, p1 ); editor.insert( 2100, p0 ); editor.insert( 2500, p1 ); editor.insert( 10000, p0 ); std::cout <<"> inserted 7 iovs..."<<std::endl; editor.flush(); std::cout <<"> iov changes flushed..."<<std::endl; } if( !session.existsIov( "MyTag2" ) ){ editor = session.createIov<std::string>( "MyTag2", cond::runnumber ); editor.setDescription("Test for timestamp selection"); editor.insert( 100, p0 ); std::cout <<"> inserted 1 iovs..."<<std::endl; editor.flush(); std::cout <<"> iov changes flushed..."<<std::endl; } session.transaction().commit(); std::cout <<"> iov changes committed!..."<<std::endl; ::sleep(2); session.transaction().start(); IOVProxy proxy = session.readIov( "MyTag" ); readIov( proxy, 1, false ); readIov( proxy, 100, true ); readIov( proxy, 1499, true ); readIov( proxy, 1500, true ); readIov( proxy, 20000, true ); proxy.find( 101 ); for( const auto i : proxy ){ std::cout <<"# iov since "<<i.since<<" - till "<<i.till<<std::endl; } proxy = session.readIov( "MyTag2" ); readIov( proxy, 1, false ); readIov( proxy, 100, true ); session.transaction().commit(); } catch (const std::exception& e){ std::cout << "ERROR: " << e.what() << std::endl; return -1; } catch (...){ std::cout << "UNEXPECTED FAILURE." << std::endl; return -1; } std::cout <<"## Run successfully completed."<<std::endl; return 0; }
int doRead( const std::string& connectionString ){ int nFail = 0; try{ //************* std::cout <<"> Connecting for reading with db in "<<connectionString<<std::endl; ConnectionPool connPool; connPool.setMessageVerbosity( coral::Debug ); Session session = connPool.createSession( connectionString, true ); session.transaction().start( false ); session.transaction().start(); IOVProxy proxy = session.readIov( "MyNewIOV" ); std::cout <<"> iov loaded size="<<proxy.loadedSize()<<std::endl; std::cout <<"> iov sequence size="<<proxy.sequenceSize()<<std::endl; IOVProxy::Iterator iovIt = proxy.find( 57 ); if( iovIt == proxy.end() ){ std::cout <<">[0] not found!"<<std::endl; } else { cond::Iov_t val = *iovIt; std::cout <<"#[0] iov since="<<val.since<<" till="<<val.till<<" pid="<<val.payloadId<<std::endl; std::shared_ptr<MyTestData> pay0 = session.fetchPayload<MyTestData>( val.payloadId ); pay0->print(); if ( *pay0 != MyTestData(iVal0) ){ nFail++; std::cout << "ERROR, pay0 found to be wrong, expected : " << iVal0 << " IOV: " << val.since << std::endl; } iovIt++; } if(iovIt == proxy.end() ){ std::cout<<"#[1] not found!"<<std::endl; } else { cond::Iov_t val =*iovIt; std::cout <<"#[1] iov since="<<val.since<<" till="<<val.till<<" pid="<<val.payloadId<<std::endl; std::shared_ptr<MyTestData> pay1 = session.fetchPayload<MyTestData>( val.payloadId ); pay1->print(); if ( *pay1 != MyTestData(iVal1) ){ nFail++; std::cout << "ERROR, pay1 found to be wrong, expected : " << iVal1 << " IOV: " << val.since << std::endl; } } iovIt = proxy.find( 176 ); if( iovIt == proxy.end() ){ std::cout <<"#[2] not found!"<<std::endl; } else { cond::Iov_t val = *iovIt; std::cout <<"#[2] iov since="<<val.since<<" till="<<val.till<<" pid="<<val.payloadId<<std::endl; std::shared_ptr<MyTestData> pay2 = session.fetchPayload<MyTestData>( val.payloadId ); pay2->print(); if ( *pay2 != MyTestData(iVal1) ){ nFail++; std::cout << "ERROR, pay2 found to be wrong, expected : " << iVal1 << " IOV: " << val.since << std::endl; } iovIt++; } if(iovIt == proxy.end() ){ std::cout<<"#[3] not found!"<<std::endl; } else { cond::Iov_t val =*iovIt; std::cout <<"#[3] iov since="<<val.since<<" till="<<val.till<<" pid="<<val.payloadId<<std::endl; std::shared_ptr<MyTestData> pay3 = session.fetchPayload<MyTestData>( val.payloadId ); pay3->print(); if ( *pay3 != MyTestData(iVal1) ){ nFail++; std::cout << "ERROR, pay3 found to be wrong, expected : " << iVal1 << " IOV: " << val.since << std::endl; } } proxy = session.readIov( "StringData" ); auto iov2It = proxy.find( 1000022 ); if(iov2It == proxy.end() ){ std::cout<<"#[4] not found!"<<std::endl; } else { cond::Iov_t val =*iov2It; std::cout <<"#[4] iov since="<<val.since<<" till="<<val.till<<" pid="<<val.payloadId<<std::endl; std::shared_ptr<std::string> pay4 = session.fetchPayload<std::string>( val.payloadId ); std::cout <<"#pay4="<<*pay4<<std::endl; if ( *pay4 != sVal ){ nFail++; std::cout << "ERROR, pay4 found to be " << *pay4 << " expected : " << sVal << " IOV: " << val.since << std::endl; } } session.transaction().commit(); } catch (const std::exception& e){ std::cout << "ERROR: " << e.what() << std::endl; return -1; } catch (...){ std::cout << "UNEXPECTED FAILURE." << std::endl; return -1; } if (nFail == 0) { std::cout << "## Run successfully completed." << std::endl; } else { std::cout << "## Run completed with ERRORS. nFail = " << nFail << std::endl; } return nFail; }
int run( const std::string& connectionString ){ try{ //************* std::cout <<"> Connecting with db in "<<connectionString<<std::endl; ConnectionPool connPool; connPool.setMessageVerbosity( coral::Debug ); Session session = connPool.createSession( connectionString, true ); session.transaction().start( false ); MyTestData d0( 17 ); MyTestData d1( 999 ); std::cout <<"> Storing payload ptr="<<&d0<<std::endl; cond::Hash p0 = session.storePayload( d0, boost::posix_time::microsec_clock::universal_time() ); cond::Hash p1 = session.storePayload( d1, boost::posix_time::microsec_clock::universal_time() ); std::string d("abcd1234"); cond::Hash p3 = session.storePayload( d, boost::posix_time::microsec_clock::universal_time() ); IOVEditor editor; if( !session.existsIov( "MyNewIOV" ) ){ editor = session.createIov<MyTestData>( "MyNewIOV", cond::runnumber, cond::SYNCH_OFFLINE ); editor.setDescription("Test with MyTestData class"); editor.insert( 1, p0 ); editor.insert( 100, p1 ); std::cout <<"> inserted 2 iovs..."<<std::endl; editor.flush(); std::cout <<"> iov changes flushed..."<<std::endl; } if( !session.existsIov( "StringData" ) ){ editor = session.createIov<std::string>( "StringData", cond::timestamp ); editor.setDescription("Test with std::string class"); editor.insert( 1000000, p3 ); editor.insert( 2000000, p3 ); editor.flush(); } session.transaction().commit(); std::cout <<"> iov changes committed!..."<<std::endl; session.transaction().start( false ); std::cout <<"## now trying to insert in the past..."<<std::endl; try{ editor = session.editIov( "MyNewIOV" ); editor.insert( 200, p1 ); editor.insert( 300, p1 ); editor.insert( 50, p1 ); editor.flush(); std::cout <<"ERROR: forbidden insertion."<<std::endl; session.transaction().commit(); } catch ( const cond::persistency::Exception& e ){ std::cout <<"Expected error: "<<e.what()<<std::endl; session.transaction().rollback(); } session.transaction().start( false ); editor = session.editIov( "StringData" ); editor.insert( 3000000, p3 ); editor.insert( 4000000, p3 ); editor.insert( 1500000, p3); editor.flush(); std::cout <<"Insertion in the past completed."<<std::endl; session.transaction().commit(); ::sleep(2); session.transaction().start(); IOVProxy proxy = session.readIov( "MyNewIOV" ); std::cout <<"> iov loaded size="<<proxy.loadedSize()<<std::endl; std::cout <<"> iov sequence size="<<proxy.sequenceSize()<<std::endl; IOVProxy::Iterator iovIt = proxy.find( 57 ); if( iovIt == proxy.end() ){ std::cout <<">[0] not found!"<<std::endl; } else { cond::Iov_t val = *iovIt; std::cout <<"#[0] iov since="<<val.since<<" till="<<val.till<<" pid="<<val.payloadId<<std::endl; std::shared_ptr<MyTestData> pay0 = session.fetchPayload<MyTestData>( val.payloadId ); pay0->print(); iovIt++; } if(iovIt == proxy.end() ){ std::cout<<"#[1] not found!"<<std::endl; } else { cond::Iov_t val =*iovIt; std::cout <<"#[1] iov since="<<val.since<<" till="<<val.till<<" pid="<<val.payloadId<<std::endl; std::shared_ptr<MyTestData> pay1 = session.fetchPayload<MyTestData>( val.payloadId ); pay1->print(); } iovIt = proxy.find( 176 ); if( iovIt == proxy.end() ){ std::cout <<"#[2] not found!"<<std::endl; } else { cond::Iov_t val = *iovIt; std::cout <<"#[2] iov since="<<val.since<<" till="<<val.till<<" pid="<<val.payloadId<<std::endl; std::shared_ptr<MyTestData> pay2 = session.fetchPayload<MyTestData>( val.payloadId ); pay2->print(); iovIt++; } if(iovIt == proxy.end() ){ std::cout<<"#[3] not found!"<<std::endl; } else { cond::Iov_t val =*iovIt; std::cout <<"#[3] iov since="<<val.since<<" till="<<val.till<<" pid="<<val.payloadId<<std::endl; std::shared_ptr<MyTestData> pay3 = session.fetchPayload<MyTestData>( val.payloadId ); pay3->print(); } proxy = session.readIov( "StringData" ); auto iov2It = proxy.find( 1000022 ); if(iov2It == proxy.end() ){ std::cout<<"#[4] not found!"<<std::endl; } else { cond::Iov_t val =*iov2It; std::cout <<"#[4] iov since="<<val.since<<" till="<<val.till<<" pid="<<val.payloadId<<std::endl; std::shared_ptr<std::string> pay4 = session.fetchPayload<std::string>( val.payloadId ); std::cout <<"#pay4="<<*pay4<<std::endl; } session.transaction().commit(); } catch (const std::exception& e){ std::cout << "ERROR: " << e.what() << std::endl; return -1; } catch (...){ std::cout << "UNEXPECTED FAILURE." << std::endl; return -1; } std::cout <<"## Run successfully completed."<<std::endl; return 0; }