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
0009 #include <fstream>
0010 #include <iomanip>
0011 #include <cstdlib>
0012 #include <iostream>
0013
0014 using namespace cond::persistency;
0015
0016 void readTag(const std::string& tag, Session& session, const boost::posix_time::ptime& snapshotTime) {
0017 IOVProxy proxy;
0018 if (snapshotTime.is_not_a_date_time())
0019 proxy = session.readIov(tag);
0020 else
0021 proxy = session.readIov(tag, snapshotTime);
0022 std::cout << "> iov loaded size=" << proxy.loadedSize() << std::endl;
0023 std::cout << "> iov sequence size=" << proxy.sequenceSize() << std::endl;
0024 try {
0025 auto iov = proxy.getInterval(107);
0026 std::cout << "#[0] iov since=" << iov.since << " till=" << iov.till << " pid=" << iov.payloadId << std::endl;
0027 std::shared_ptr<std::string> pay0 = session.fetchPayload<std::string>(iov.payloadId);
0028 std::cout << "#[0] payload=" << *pay0 << std::endl;
0029 } catch (const Exception& e) {
0030 std::cout << ">[0] not found!" << std::endl;
0031 }
0032 try {
0033 auto iov = proxy.getInterval(235);
0034 std::cout << "#[1] iov since=" << iov.since << " till=" << iov.till << " pid=" << iov.payloadId << std::endl;
0035 std::shared_ptr<std::string> pay0 = session.fetchPayload<std::string>(iov.payloadId);
0036 std::cout << "#[1] payload=" << *pay0 << std::endl;
0037 } catch (const Exception& e) {
0038 std::cout << ">[1] not found!" << std::endl;
0039 }
0040 }
0041
0042 int run(const std::string& connectionString) {
0043 try {
0044
0045 std::cout << "> Connecting with db in " << connectionString << std::endl;
0046 ConnectionPool connPool;
0047 connPool.setMessageVerbosity(coral::Debug);
0048 Session session = connPool.createSession(connectionString, true);
0049 session.transaction().start(false);
0050 std::string pay0("Payload #0");
0051 std::string pay1("Payload #1");
0052 std::string pay2("Payload #2");
0053 std::string pay3("Payload #3");
0054 std::string pay4("Payload #4");
0055 std::string pay5("Payload #5");
0056 auto p0 = session.storePayload(pay0);
0057 auto p1 = session.storePayload(pay1);
0058 auto p2 = session.storePayload(pay2);
0059
0060 IOVEditor editor;
0061 if (!session.existsIov("MyTag")) {
0062 editor = session.createIov<std::string>("MyTag", cond::runnumber);
0063 editor.setDescription("Test for timestamp selection");
0064 editor.insert(1, p0);
0065 editor.insert(101, p1);
0066 editor.insert(201, p2);
0067 std::cout << "> inserted 3 iovs..." << std::endl;
0068 editor.flush();
0069 std::cout << "> iov changes flushed..." << std::endl;
0070 }
0071 session.transaction().commit();
0072 boost::posix_time::ptime snap0 = boost::posix_time::microsec_clock::universal_time();
0073 std::cout << "> iov changes committed!..." << std::endl;
0074 ::sleep(2);
0075 boost::posix_time::ptime notime;
0076 session.transaction().start();
0077 readTag("MyTag", session, notime);
0078 session.transaction().commit();
0079 session.transaction().start(false);
0080 auto p3 = session.storePayload(pay3);
0081 auto p4 = session.storePayload(pay4);
0082 auto p5 = session.storePayload(pay5);
0083 editor = session.editIov("MyTag");
0084 editor.insert(101, p3);
0085 editor.insert(222, p4);
0086 editor.flush();
0087 session.transaction().commit();
0088 boost::posix_time::ptime snap1 = boost::posix_time::microsec_clock::universal_time();
0089 ::sleep(2);
0090 session.transaction().start();
0091 readTag("MyTag", session, notime);
0092 session.transaction().commit();
0093 session.transaction().start(false);
0094 editor = session.editIov("MyTag");
0095 editor.insert(102, p5);
0096 editor.flush();
0097 session.transaction().commit();
0098 session.transaction().start();
0099 readTag("MyTag", session, notime);
0100 session.transaction().commit();
0101 session.transaction().start();
0102 readTag("MyTag", session, snap0);
0103 session.transaction().commit();
0104 session.transaction().start();
0105 readTag("MyTag", session, snap1);
0106 session.transaction().commit();
0107
0108 session.transaction().start(false);
0109 GTEditor gtWriter = session.createGlobalTag("MY_TEST_GT_V0");
0110 gtWriter.setDescription("test GT");
0111 gtWriter.setRelease("CMSSW_7_5_X");
0112 gtWriter.setSnapshotTime(snap0);
0113 gtWriter.insert("myrecord", "MyTag");
0114 gtWriter.flush();
0115 session.transaction().commit();
0116 session.transaction().start();
0117 GTProxy gtReader = session.readGlobalTag("MY_TEST_GT_V0");
0118 boost::posix_time::ptime snap2 = gtReader.snapshotTime();
0119 readTag("MyTag", session, snap2);
0120 session.transaction().commit();
0121 } catch (const std::exception& e) {
0122 std::cout << "ERROR: " << e.what() << std::endl;
0123 return -1;
0124 } catch (...) {
0125 std::cout << "UNEXPECTED FAILURE." << std::endl;
0126 return -1;
0127 }
0128 std::cout << "## Run successfully completed." << std::endl;
0129 return 0;
0130 }
0131
0132 int main(int argc, char** argv) {
0133 int ret = 0;
0134 edmplugin::PluginManager::Config config;
0135 edmplugin::PluginManager::configure(edmplugin::standard::config());
0136 std::string connectionString0("sqlite_file:cms_conditions_1.db");
0137 ret = run(connectionString0);
0138 return ret;
0139 }