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& connectionString) {
0019   try {
0020     //*************
0021     std::cout << "> Connecting with db in " << connectionString << std::endl;
0022     ConnectionPool connPool;
0023     connPool.setMessageVerbosity(coral::Debug);
0024     Session session = connPool.createSession(connectionString, true);
0025     session.transaction().start(false);
0026     std::string d0("abcd1234");
0027     std::string d1("abcdefghil");
0028     cond::Hash p0 = session.storePayload(d0, boost::posix_time::microsec_clock::universal_time());
0029     cond::Hash p1 = session.storePayload(d0, boost::posix_time::microsec_clock::universal_time());
0030 
0031     IOVEditor editor;
0032 
0033     if (!session.existsIov("StringData")) {
0034       editor = session.createIov<std::string>("StringData", cond::timestamp);
0035       editor.setDescription("Test with std::string class");
0036       editor.insert(1000000, p0);
0037       editor.insert(2000000, p1);
0038       editor.flush();
0039     }
0040     session.transaction().commit();
0041     std::cout << "> iov changes committed!..." << std::endl;
0042 
0043     session.transaction().start();
0044     IOVProxy proxy = session.readIov("StringData");
0045     auto iovs = proxy.selectAll();
0046     session.transaction().commit();
0047     std::cout << "(0) Found " << iovs.size() << " iovs." << std::endl;
0048     for (auto iov : iovs) {
0049       std::cout << "Iov since " << iov.since << " hash " << iov.payloadId << std::endl;
0050     }
0051 
0052     session.transaction().start(false);
0053     cond::Hash p3 = session.storePayload(std::string("013456789"), boost::posix_time::microsec_clock::universal_time());
0054     editor = session.editIov("StringData");
0055     editor.insert(3000000, p3);
0056     editor.erase(2000000, p1);
0057     editor.flush();
0058     std::cout << "2nd iovs changes completed." << std::endl;
0059     session.transaction().commit();
0060 
0061     ::sleep(2);
0062     session.transaction().start();
0063     proxy = session.readIov("StringData");
0064     iovs = proxy.selectAll();
0065     session.transaction().commit();
0066     std::cout << "(1) Found " << iovs.size() << " iovs." << std::endl;
0067     for (auto iov : iovs) {
0068       std::cout << "Iov since " << iov.since << " hash " << iov.payloadId << std::endl;
0069     }
0070   } catch (const std::exception& e) {
0071     std::cout << "ERROR: " << e.what() << std::endl;
0072     return -1;
0073   } catch (...) {
0074     std::cout << "UNEXPECTED FAILURE." << std::endl;
0075     return -1;
0076   }
0077   std::cout << "## Run successfully completed." << std::endl;
0078   return 0;
0079 }
0080 
0081 int main(int argc, char** argv) {
0082   int ret = 0;
0083   edmplugin::PluginManager::Config config;
0084   edmplugin::PluginManager::configure(edmplugin::standard::config());
0085   std::string connectionString0("sqlite_file:cms_conditions_4.db");
0086   ret = run(connectionString0);
0087   return ret;
0088 }