Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:01:30

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 <fstream>
0010 #include <iomanip>
0011 #include <cstdlib>
0012 #include <iostream>
0013 
0014 using namespace cond::persistency;
0015 
0016 int run(const std::string& connectionString) {
0017   try {
0018     //*************
0019     std::cout << "> Connecting with db in " << connectionString << std::endl;
0020     ConnectionPool connPool;
0021     connPool.setMessageVerbosity(coral::Debug);
0022     connPool.configure();
0023     Session session = connPool.createSession(connectionString, true);
0024     session.transaction().start(false);
0025     RunInfoEditor runInfoWriter = session.editRunInfo();
0026     runInfoWriter.insert(1000,
0027                          boost::posix_time::time_from_string("2017-01-01 00:00:00.000"),
0028                          boost::posix_time::time_from_string("2017-01-01 01:00:00.000"));
0029     runInfoWriter.insert(1010,
0030                          boost::posix_time::time_from_string("2017-01-01 01:00:10.000"),
0031                          boost::posix_time::time_from_string("2017-01-01 02:00:00.000"));
0032     runInfoWriter.insert(1020,
0033                          boost::posix_time::time_from_string("2017-01-01 02:00:10.000"),
0034                          boost::posix_time::time_from_string("2017-01-01 03:00:00.000"));
0035     runInfoWriter.insert(1030,
0036                          boost::posix_time::time_from_string("2017-01-01 03:00:10.000"),
0037                          boost::posix_time::time_from_string("2017-01-01 04:00:00.000"));
0038     runInfoWriter.flush();
0039     session.transaction().commit();
0040     session.transaction().start(false);
0041     std::cout << "Last inserted: " << runInfoWriter.getLastInserted() << std::endl;
0042     session.transaction().commit();
0043     session.transaction().start(false);
0044     runInfoWriter.insertNew(1040,
0045                             boost::posix_time::time_from_string("2017-01-01 04:00:10.000"),
0046                             boost::posix_time::time_from_string("2017-01-01 04:00:10.000"));
0047     runInfoWriter.flush();
0048     session.transaction().commit();
0049     session.transaction().start();
0050     RunInfoProxy reader = session.getRunInfo(900, 1031);
0051     auto it = reader.find(1015);
0052     if (it != reader.end()) {
0053       auto rdata = *it;
0054       std::cout << "For target=1015 Found run=" << rdata.run << " start=" << rdata.start << " end=" << rdata.end
0055                 << std::endl;
0056     } else
0057       std::cout << " Can't find run 1015 in the selected range" << std::endl;
0058     it = reader.find(1030);
0059     if (it != reader.end()) {
0060       auto rdata = *it;
0061       std::cout << "For target=1030 Found run=" << rdata.run << " start=" << rdata.start << " end=" << rdata.end
0062                 << std::endl;
0063     } else
0064       std::cout << " Can't find run 1030 in the selected range" << std::endl;
0065     it = reader.find(1035);
0066     if (it != reader.end()) {
0067       auto rdata = *it;
0068       std::cout << "For target=1035 Found run=" << rdata.run << " start=" << rdata.start << " end=" << rdata.end
0069                 << std::endl;
0070     } else
0071       std::cout << " Can't find run 1035 in the selected range" << std::endl;
0072     session.transaction().commit();
0073     session.transaction().start(false);
0074     runInfoWriter.insertNew(1040,
0075                             boost::posix_time::time_from_string("2017-01-01 04:00:10.000"),
0076                             boost::posix_time::time_from_string("2017-01-01 05:00:00.000"));
0077     runInfoWriter.flush();
0078     session.transaction().commit();
0079     session.transaction().start();
0080     reader = session.getRunInfo(1036, 1036);
0081     auto run = reader.get(1036);
0082     std::cout << "For target=1036 Found run=" << run.run << " start=" << run.start << " end=" << run.end << std::endl;
0083     run = reader.get(1037);
0084     std::cout << "For target=1037 Found run=" << run.run << " start=" << run.start << " end=" << run.end << std::endl;
0085     try {
0086       run = reader.get(1041);
0087       std::cout << "For target=1041 Found run=" << run.run << " start=" << run.start << " end=" << run.end << std::endl;
0088     } catch (const std::exception& e) {
0089       std::cout << "Expected error:" << e.what() << std::endl;
0090     }
0091     session.transaction().commit();
0092     session.transaction().start();
0093     std::cout << "Last inserted: " << runInfoWriter.getLastInserted() << std::endl;
0094     session.transaction().commit();
0095   } catch (const std::exception& e) {
0096     std::cout << "ERROR: " << e.what() << std::endl;
0097     return -1;
0098   } catch (...) {
0099     std::cout << "UNEXPECTED FAILURE." << std::endl;
0100     return -1;
0101   }
0102   std::cout << "## Run successfully completed." << std::endl;
0103   return 0;
0104 }
0105 
0106 int main(int argc, char** argv) {
0107   int ret = 0;
0108   edmplugin::PluginManager::Config config;
0109   edmplugin::PluginManager::configure(edmplugin::standard::config());
0110   std::string connectionString0("sqlite_file:run_info_0.db");
0111   ret = run(connectionString0);
0112   return ret;
0113 }