File indexing completed on 2023-03-17 10:45:55
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 readIov(IOVProxy& proxy, cond::Time_t targetTime, bool expectedOk) {
0017 bool found = false;
0018 cond::Iov_t iov;
0019 std::cout << "#Testing tag " << proxy.tagInfo().name << std::endl;
0020 try {
0021 iov = proxy.getInterval(targetTime);
0022 if (iov.since < cond::time::MAX_VAL)
0023 found = true;
0024 } catch (const Exception& e) {
0025 std::cout << "# IOV " << targetTime << " not found: " << e.what() << std::endl;
0026 }
0027 if (expectedOk) {
0028 if (found) {
0029 std::cout << "#OK: found iov with since " << iov.since << " - till " << iov.till << " for time " << targetTime
0030 << std::endl;
0031 return 0;
0032 } else {
0033 std::cout << "#OK: no valid iov found for time " << targetTime << std::endl;
0034 return -1;
0035 }
0036 } else {
0037 if (found) {
0038 std::cout << "#ERROR: found iov=" << iov.since << " for time " << targetTime << std::endl;
0039 return -1;
0040 } else {
0041 std::cout << "#OK: no valid iov found for time " << targetTime << std::endl;
0042 return 0;
0043 }
0044 }
0045 }
0046
0047 int run(const std::string& connectionString) {
0048 try {
0049
0050 std::cout << "> Connecting with db in " << connectionString << std::endl;
0051 ConnectionPool connPool;
0052 connPool.setMessageVerbosity(coral::Debug);
0053 Session session = connPool.createSession(connectionString, true);
0054 session.transaction().start(false);
0055 std::string pay0("Payload #0");
0056 std::string pay1("Payload #1");
0057 auto p0 = session.storePayload(pay0);
0058 auto p1 = session.storePayload(pay1);
0059 IOVEditor editor;
0060 std::string tag0("MyTag0");
0061 if (!session.existsIov(tag0)) {
0062 editor = session.createIov<std::string>(tag0, cond::runnumber);
0063 editor.setDescription(tag0 + " Test for timestamp selection");
0064 editor.insert(100, p0);
0065 editor.insert(200, p1);
0066 editor.insert(1001, p0);
0067 editor.insert(1500, p1);
0068 editor.insert(2100, p0);
0069 editor.insert(2500, p1);
0070 editor.insert(10000, p0);
0071 std::cout << "> inserted 7 iovs..." << std::endl;
0072 editor.flush();
0073 std::cout << "> iov changes flushed..." << std::endl;
0074 }
0075 std::string tag1("MyTag1");
0076 if (!session.existsIov(tag1)) {
0077 editor = session.createIov<std::string>(tag1, cond::runnumber);
0078 editor.setDescription(tag1 + " Test for timestamp selection");
0079 editor.insert(100, p0);
0080 std::cout << "> inserted 1 iovs..." << std::endl;
0081 editor.flush();
0082 std::cout << "> iov changes flushed..." << std::endl;
0083 }
0084 session.transaction().commit();
0085 std::cout << "> iov changes committed!..." << std::endl;
0086 ::sleep(2);
0087 session.transaction().start();
0088 IOVProxy proxy = session.readIov(tag0);
0089 auto md = proxy.getMetadata();
0090 std::cout << tag0 << " description is \"" << std::get<0>(md) << "\"" << std::endl;
0091 readIov(proxy, 1, false);
0092 readIov(proxy, 100, true);
0093 readIov(proxy, 1499, true);
0094 readIov(proxy, 1500, true);
0095 readIov(proxy, 20000, true);
0096 IOVArray iovs = proxy.selectAll();
0097 iovs.find(101);
0098 for (const auto i : iovs) {
0099 std::cout << "# iov since " << i.since << " - till " << i.till << std::endl;
0100 }
0101 proxy = session.readIov(tag1);
0102 md = proxy.getMetadata();
0103 std::cout << tag1 << " description is \"" << std::get<0>(md) << "\"" << std::endl;
0104 readIov(proxy, 1, false);
0105 readIov(proxy, 100, true);
0106 session.transaction().commit();
0107
0108 session.transaction().start(false);
0109 auto ed = session.editIov(tag1);
0110 ed.setDescription("Changed description for tag " + tag1);
0111 ed.flush();
0112 session.transaction().commit();
0113
0114 session.transaction().start();
0115 md = session.readIov(tag1).getMetadata();
0116 std::cout << tag1 << " description is \"" << std::get<0>(md) << "\"" << std::endl;
0117 session.transaction().commit();
0118
0119 } catch (const std::exception& e) {
0120 std::cout << "ERROR: " << e.what() << std::endl;
0121 return -1;
0122 } catch (...) {
0123 std::cout << "UNEXPECTED FAILURE." << std::endl;
0124 return -1;
0125 }
0126 std::cout << "## Run successfully completed." << std::endl;
0127 return 0;
0128 }
0129
0130 int main(int argc, char** argv) {
0131 int ret = 0;
0132 edmplugin::PluginManager::Config config;
0133 edmplugin::PluginManager::configure(edmplugin::standard::config());
0134 std::string connectionString0("sqlite_file:cms_conditions_2.db");
0135 ret = run(connectionString0);
0136 return ret;
0137 }