Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:50:26

0001 #include "FWCore/PluginManager/interface/PluginManager.h"
0002 #include "FWCore/PluginManager/interface/standard.h"
0003 #include "FWCore/PluginManager/interface/SharedLibrary.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0005 #include "FWCore/ServiceRegistry/interface/ServiceRegistry.h"
0006 //
0007 #include "CondCore/CondDB/interface/ConnectionPool.h"
0008 //
0009 #include "MyTestData.h"
0010 //
0011 #include <fstream>
0012 #include <iomanip>
0013 #include <cstdlib>
0014 #include <iostream>
0015 
0016 using namespace cond::persistency;
0017 
0018 int run(const std::string& csWrite, const std::string& csRead) {
0019   try {
0020     //*************
0021     std::cout << "> Connecting with db in " << csWrite << std::endl;
0022     ConnectionPool connPool;
0023     connPool.setMessageVerbosity(coral::Debug);
0024     connPool.setAuthenticationPath("/build/gg");
0025     Session session = connPool.createSession(csWrite, true);
0026     session.transaction().start(false);
0027     MyTestData d0(1000);
0028     cond::Hash p0 = session.storePayload(d0);
0029     MyTestData d1(1001);
0030     cond::Hash p1 = session.storePayload(d1);
0031     MyTestData d2(1002);
0032     cond::Hash p2 = session.storePayload(d2);
0033     MyTestData d3(1003);
0034     cond::Hash p3 = session.storePayload(d3);
0035     MyTestData d4(1004);
0036     cond::Hash p4 = session.storePayload(d4);
0037     MyTestData d5(1005);
0038     cond::Hash p5 = session.storePayload(d5);
0039     MyTestData d6(1006);
0040     cond::Hash p6 = session.storePayload(d6);
0041     MyTestData d7(1007);
0042     cond::Hash p7 = session.storePayload(d7);
0043     MyTestData d8(1008);
0044     cond::Hash p8 = session.storePayload(d8);
0045     IOVEditor editor;
0046     std::string tag("MyTestData_ts_v0");
0047     if (!session.existsIov(tag)) {
0048       editor = session.createIov<MyTestData>(tag, cond::timestamp, cond::SYNCH_ANY);
0049       editor.setDescription("Test for group selection");
0050       MyTestData dummy(0);
0051       cond::Hash pd = session.storePayload(dummy);
0052       editor.insert(1, pd);
0053     } else {
0054       editor = session.editIov(tag);
0055     }
0056     boost::posix_time::ptime tb0 = boost::posix_time::second_clock::local_time();
0057     boost::posix_time::ptime tb1 = tb0 + boost::posix_time::seconds(600);
0058     boost::posix_time::ptime tb2 = tb0 + boost::posix_time::seconds(1200);
0059     boost::posix_time::ptime tb3 = tb0 + boost::posix_time::seconds(1800);
0060     boost::posix_time::ptime tb4 = tb0 + boost::posix_time::seconds(2400);
0061     boost::posix_time::ptime tb5 = tb0 + boost::posix_time::seconds(3000);
0062     boost::posix_time::ptime tb6 = tb0 + boost::posix_time::seconds(3600);
0063     boost::posix_time::ptime tb7 = tb0 + boost::posix_time::seconds(4200);
0064     boost::posix_time::ptime tb8 = tb0 + boost::posix_time::seconds(4800);
0065     cond::Time_t t0 = cond::time::from_boost(tb0);
0066     cond::Time_t t1 = cond::time::from_boost(tb1);
0067     cond::Time_t t2 = cond::time::from_boost(tb2);
0068     cond::Time_t t3 = cond::time::from_boost(tb3);
0069     cond::Time_t t4 = cond::time::from_boost(tb4);
0070     cond::Time_t t5 = cond::time::from_boost(tb5);
0071     cond::Time_t t6 = cond::time::from_boost(tb6);
0072     cond::Time_t t7 = cond::time::from_boost(tb7);
0073     cond::Time_t t8 = cond::time::from_boost(tb8);
0074     editor.insert(t0, p0);
0075     editor.insert(t1, p1);
0076     editor.insert(t2, p2);
0077     editor.insert(t3, p3);
0078     editor.insert(t4, p4);
0079     editor.insert(t5, p5);
0080     editor.insert(t6, p6);
0081     editor.insert(t7, p7);
0082     editor.insert(t8, p8);
0083     editor.flush();
0084     session.transaction().commit();
0085     std::cout << "> Connecting with db in " << csRead << std::endl;
0086     session = connPool.createSession(csRead);
0087     session.transaction().start();
0088     IOVProxy reader = session.readIov(tag);
0089     cond::Time_t tg0 = cond::time::from_boost(tb0 + boost::posix_time::seconds(300));
0090     cond::Iov_t iov0 = reader.getInterval(tg0);
0091     std::cout << "tg0: since " << iov0.since << " till " << iov0.till << " nqueries " << reader.numberOfQueries()
0092               << std::endl;
0093     cond::Time_t tg1 = cond::time::from_boost(tb1 + boost::posix_time::seconds(300));
0094     cond::Iov_t iov1 = reader.getInterval(tg1);
0095     std::cout << "tg1: since " << iov1.since << " till " << iov1.till << " nqueries " << reader.numberOfQueries()
0096               << std::endl;
0097     cond::Time_t tg2 = cond::time::from_boost(tb2 + boost::posix_time::seconds(300));
0098     cond::Iov_t iov2 = reader.getInterval(tg2);
0099     std::cout << "tg2: since " << iov2.since << " till " << iov2.till << " nqueries " << reader.numberOfQueries()
0100               << std::endl;
0101     cond::Time_t tg3 = cond::time::from_boost(tb3 + boost::posix_time::seconds(300));
0102     cond::Iov_t iov3 = reader.getInterval(tg3);
0103     std::cout << "tg3: since " << iov3.since << " till " << iov3.till << " nqueries " << reader.numberOfQueries()
0104               << std::endl;
0105     cond::Time_t tg4 = cond::time::from_boost(tb4 + boost::posix_time::seconds(300));
0106     cond::Iov_t iov4 = reader.getInterval(tg4);
0107     std::cout << "tg4: since " << iov4.since << " till " << iov4.till << " nqueries " << reader.numberOfQueries()
0108               << std::endl;
0109     cond::Time_t tg5 = cond::time::from_boost(tb5 + boost::posix_time::seconds(300));
0110     cond::Iov_t iov5 = reader.getInterval(tg5);
0111     std::cout << "tg5: since " << iov5.since << " till " << iov5.till << " nqueries " << reader.numberOfQueries()
0112               << std::endl;
0113     cond::Time_t tg6 = cond::time::from_boost(tb6 + boost::posix_time::seconds(300));
0114     cond::Iov_t iov6 = reader.getInterval(tg6);
0115     std::cout << "tg6: since " << iov6.since << " till " << iov6.till << " nqueries " << reader.numberOfQueries()
0116               << std::endl;
0117     cond::Time_t tg7 = cond::time::from_boost(tb7 + boost::posix_time::seconds(300));
0118     cond::Iov_t iov7 = reader.getInterval(tg7);
0119     std::cout << "tg7: since " << iov7.since << " till " << iov7.till << " nqueries " << reader.numberOfQueries()
0120               << std::endl;
0121     cond::Time_t tg8 = cond::time::from_boost(tb8 + boost::posix_time::seconds(300));
0122     cond::Iov_t iov8 = reader.getInterval(tg8);
0123     std::cout << "tg8: since " << iov8.since << " till " << iov8.till << " nqueries " << reader.numberOfQueries()
0124               << std::endl;
0125     session.transaction().commit();
0126   } catch (const std::exception& e) {
0127     std::cout << "ERROR: " << e.what() << std::endl;
0128     return -1;
0129   } catch (...) {
0130     std::cout << "UNEXPECTED FAILURE." << std::endl;
0131     return -1;
0132   }
0133 
0134   return 0;
0135 }
0136 
0137 int main(int argc, char** argv) {
0138   int ret = 0;
0139   edmplugin::PluginManager::Config config;
0140   edmplugin::PluginManager::configure(edmplugin::standard::config());
0141   std::string connectionString0("sqlite_file:group_selection.db");
0142   std::string connectionString1("sqlite_file:group_selection.db");
0143   ret = run(connectionString0, connectionString1);
0144   return ret;
0145 }