Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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 #include "CondCore/CondDB/interface/PayloadProxy.h"
0009 //
0010 #include "MyTestData.h"
0011 //
0012 #include <fstream>
0013 #include <iomanip>
0014 #include <cstdlib>
0015 #include <iostream>
0016 
0017 using namespace cond::persistency;
0018 
0019 int run(const std::string& connectionString) {
0020   try {
0021     //*************
0022     std::cout << "> Connecting with db in " << connectionString << std::endl;
0023     ConnectionPool connPool;
0024     connPool.setMessageVerbosity(coral::Debug);
0025     Session session = connPool.createSession(connectionString, true);
0026     session.transaction().start(false);
0027     MyTestData d0(17);
0028     MyTestData d1(999);
0029     std::cout << "> Storing payload ptr=" << &d0 << std::endl;
0030     cond::Hash p0 = session.storePayload(d0, boost::posix_time::microsec_clock::universal_time());
0031     cond::Hash p1 = session.storePayload(d1, boost::posix_time::microsec_clock::universal_time());
0032 
0033     IOVEditor editor;
0034     if (!session.existsIov("MyNewIOV")) {
0035       editor = session.createIov<MyTestData>("MyNewIOV", cond::lumiid, cond::SYNCH_HLT);
0036       editor.setDescription("Test with MyTestData class");
0037       editor.insert(1, p0);
0038       editor.insert(cond::time::lumiTime(100, 11), p1);
0039       editor.insert(cond::time::lumiTime(100, 21), p0);
0040       editor.insert(cond::time::lumiTime(100, 31), p1);
0041       editor.insert(cond::time::lumiTime(200, 11), p1);
0042       editor.insert(cond::time::lumiTime(200, 21), p0);
0043       editor.insert(cond::time::lumiTime(200, 31), p1);
0044       editor.insert(cond::time::lumiTime(300, 11), p1);
0045       editor.insert(cond::time::lumiTime(300, 21), p0);
0046       editor.insert(cond::time::lumiTime(300, 31), p1);
0047       editor.insert(cond::time::lumiTime(400, 11), p0);
0048       editor.insert(cond::time::lumiTime(400, 12), p1);
0049       editor.insert(cond::time::lumiTime(400, 13), p0);
0050       std::cout << "> inserted iovs..." << std::endl;
0051       editor.flush();
0052       std::cout << "> iov changes flushed..." << std::endl;
0053     }
0054 
0055     session.transaction().commit();
0056     std::cout << "> iov changes committed!..." << std::endl;
0057 
0058     ::sleep(2);
0059     session.transaction().start();
0060 
0061     auto arr0 = session.readIov("MyNewIOV").selectAll();
0062     std::cout << "# Selecting all iovs..." << std::endl;
0063     for (auto iiov : arr0) {
0064       std::cout << "# since=" << iiov.since << " till:" << iiov.till << std::endl;
0065     }
0066     auto arr1 = session.readIov("MyNewIOV").selectRange(cond::time::lumiTime(100, 15), cond::time::lumiTime(300, 15));
0067     std::cout << "# Selecting range (" << cond::time::lumiTime(100, 15) << "," << cond::time::lumiTime(300, 15) << ")"
0068               << std::endl;
0069     for (auto iiov : arr1) {
0070       std::cout << "# since=" << iiov.since << " till:" << iiov.till << std::endl;
0071     }
0072     auto pxn = session.readIov("MyNewIOV");
0073     std::vector<cond::Time_t> inputTimes{10,
0074                                          cond::time::lumiTime(100, 15),
0075                                          cond::time::lumiTime(100, 25),
0076                                          cond::time::lumiTime(100, 35),
0077                                          cond::time::lumiTime(200, 15),
0078                                          cond::time::lumiTime(200, 25),
0079                                          cond::time::lumiTime(200, 35),
0080                                          cond::time::lumiTime(300, 15),
0081                                          cond::time::lumiTime(300, 25),
0082                                          cond::time::lumiTime(300, 35),
0083                                          cond::time::lumiTime(400, 11),
0084                                          cond::time::lumiTime(400, 12),
0085                                          cond::time::lumiTime(400, 13)};
0086     for (auto t : inputTimes) {
0087       cond::Iov_t iiov = pxn.getInterval(t);
0088       std::cout << "#Target=" << t << " since=" << iiov.since << " till:" << iiov.till << std::endl;
0089     }
0090 
0091     std::cout << "#Nqueries:" << pxn.numberOfQueries() << std::endl;
0092 
0093     session.transaction().commit();
0094 
0095     cond::Iov_t iov;
0096     auto requests = std::make_shared<std::vector<cond::Iov_t>>();
0097     PayloadProxy<MyTestData> ppn(&iov, &session, &requests);
0098     session.transaction().start(true);
0099     auto iovP = session.readIov("MyNewIOV");
0100     for (auto t : inputTimes) {
0101       iov = iovP.getInterval(t);
0102       ppn.initializeForNewIOV();
0103       ppn.make();
0104       std::cout << "PP: target=" << t << " since=" << iov.since << " till:" << iov.till << std::endl;
0105     }
0106     session.transaction().commit();
0107 
0108     std::cout << "#PP: nqueries:" << iovP.numberOfQueries() << std::endl;
0109 
0110   } catch (const std::exception& e) {
0111     std::cout << "ERROR: " << e.what() << std::endl;
0112     return -1;
0113   } catch (...) {
0114     std::cout << "UNEXPECTED FAILURE." << std::endl;
0115     return -1;
0116   }
0117   std::cout << "## Run successfully completed." << std::endl;
0118   return 0;
0119 }
0120 
0121 int main(int argc, char** argv) {
0122   int ret = 0;
0123   edmplugin::PluginManager::Config config;
0124   edmplugin::PluginManager::configure(edmplugin::standard::config());
0125   std::string connectionString0("sqlite_file:cms_conditions_3.db");
0126   ret = run(connectionString0);
0127   return ret;
0128 }