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 "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 MyTestData d0(17);
0027 MyTestData d1(999);
0028 std::cout << "> Storing payload ptr=" << &d0 << std::endl;
0029 cond::Hash p0 = session.storePayload(d0, boost::posix_time::microsec_clock::universal_time());
0030 cond::Hash p1 = session.storePayload(d1, boost::posix_time::microsec_clock::universal_time());
0031 std::string d("abcd1234");
0032 cond::Hash p3 = session.storePayload(d, boost::posix_time::microsec_clock::universal_time());
0033
0034 IOVEditor editor;
0035 if (!session.existsIov("MyNewIOV")) {
0036 editor = session.createIov<MyTestData>("MyNewIOV", cond::runnumber, cond::SYNCH_OFFLINE);
0037 editor.setDescription("Test with MyTestData class");
0038 editor.insert(1, p0);
0039 editor.insert(100, p1);
0040 std::cout << "> inserted 2 iovs..." << std::endl;
0041 editor.flush();
0042 std::cout << "> iov changes flushed..." << std::endl;
0043 }
0044
0045 if (!session.existsIov("StringData")) {
0046 editor = session.createIov<std::string>("StringData", cond::timestamp);
0047 editor.setDescription("Test with std::string class");
0048 editor.insert(1000000, p3);
0049 editor.insert(2000000, p3);
0050 editor.flush();
0051 }
0052
0053 session.transaction().commit();
0054 std::cout << "> iov changes committed!..." << std::endl;
0055
0056 session.transaction().start(false);
0057 std::cout << "## now trying to insert in the past..." << std::endl;
0058 try {
0059 editor = session.editIov("MyNewIOV");
0060 editor.insert(200, p1);
0061 editor.insert(300, p1);
0062 editor.insert(50, p1);
0063 editor.flush();
0064 std::cout << "ERROR: forbidden insertion." << std::endl;
0065 session.transaction().commit();
0066 } catch (const cond::persistency::Exception& e) {
0067 std::cout << "Expected error: " << e.what() << std::endl;
0068 session.transaction().rollback();
0069 }
0070 session.transaction().start(false);
0071 editor = session.editIov("StringData");
0072 editor.insert(3000000, p3);
0073 editor.insert(4000000, p3);
0074 editor.insert(1500000, p3);
0075 editor.flush();
0076 std::cout << "Insertion in the past completed." << std::endl;
0077 session.transaction().commit();
0078
0079 ::sleep(2);
0080 session.transaction().start();
0081
0082 IOVProxy proxy = session.readIov("MyNewIOV");
0083 std::cout << "> iov loaded size=" << proxy.loadedSize() << std::endl;
0084 std::cout << "> iov sequence size=" << proxy.sequenceSize() << std::endl;
0085 IOVArray iovs = proxy.selectAll();
0086 IOVArray::Iterator iovIt = iovs.find(57);
0087 if (iovIt == iovs.end()) {
0088 std::cout << ">[0] not found!" << std::endl;
0089 } else {
0090 cond::Iov_t val = *iovIt;
0091 std::cout << "#[0] iov since=" << val.since << " till=" << val.till << " pid=" << val.payloadId << std::endl;
0092 std::shared_ptr<MyTestData> pay0 = session.fetchPayload<MyTestData>(val.payloadId);
0093 pay0->print();
0094 iovIt++;
0095 }
0096 if (iovIt == iovs.end()) {
0097 std::cout << "#[1] not found!" << std::endl;
0098 } else {
0099 cond::Iov_t val = *iovIt;
0100 std::cout << "#[1] iov since=" << val.since << " till=" << val.till << " pid=" << val.payloadId << std::endl;
0101 std::shared_ptr<MyTestData> pay1 = session.fetchPayload<MyTestData>(val.payloadId);
0102 pay1->print();
0103 }
0104 iovIt = iovs.find(176);
0105 if (iovIt == iovs.end()) {
0106 std::cout << "#[2] not found!" << std::endl;
0107 } else {
0108 cond::Iov_t val = *iovIt;
0109 std::cout << "#[2] iov since=" << val.since << " till=" << val.till << " pid=" << val.payloadId << std::endl;
0110 std::shared_ptr<MyTestData> pay2 = session.fetchPayload<MyTestData>(val.payloadId);
0111 pay2->print();
0112 iovIt++;
0113 }
0114 if (iovIt == iovs.end()) {
0115 std::cout << "#[3] not found!" << std::endl;
0116 } else {
0117 cond::Iov_t val = *iovIt;
0118 std::cout << "#[3] iov since=" << val.since << " till=" << val.till << " pid=" << val.payloadId << std::endl;
0119 std::shared_ptr<MyTestData> pay3 = session.fetchPayload<MyTestData>(val.payloadId);
0120 pay3->print();
0121 }
0122
0123 proxy = session.readIov("StringData");
0124 iovs = proxy.selectAll();
0125 auto iov2It = iovs.find(1000022);
0126 if (iov2It == iovs.end()) {
0127 std::cout << "#[4] not found!" << std::endl;
0128 } else {
0129 cond::Iov_t val = *iov2It;
0130 std::cout << "#[4] iov since=" << val.since << " till=" << val.till << " pid=" << val.payloadId << std::endl;
0131 std::shared_ptr<std::string> pay4 = session.fetchPayload<std::string>(val.payloadId);
0132 std::cout << "#pay4=" << *pay4 << std::endl;
0133 }
0134 session.transaction().commit();
0135 } catch (const std::exception& e) {
0136 std::cout << "ERROR: " << e.what() << std::endl;
0137 return -1;
0138 } catch (...) {
0139 std::cout << "UNEXPECTED FAILURE." << std::endl;
0140 return -1;
0141 }
0142 std::cout << "## Run successfully completed." << std::endl;
0143 return 0;
0144 }
0145
0146 int main(int argc, char** argv) {
0147 int ret = 0;
0148 edmplugin::PluginManager::Config config;
0149 edmplugin::PluginManager::configure(edmplugin::standard::config());
0150 std::string connectionString0("sqlite_file:cms_conditions_0.db");
0151 ret = run(connectionString0);
0152 return ret;
0153 }