File indexing completed on 2025-03-23 15:57:27
0001 #include "CondCore/CondDB/interface/ConnectionPool.h"
0002
0003 #include "CondCore/Utilities/interface/Utilities.h"
0004 #include "CondCore/Utilities/interface/CondDBImport.h"
0005 #include <iostream>
0006
0007 #include <sstream>
0008 #include <boost/tokenizer.hpp>
0009 #include <chrono>
0010
0011 namespace cond {
0012
0013 class TestReadUtilities : public cond::Utilities {
0014 public:
0015 TestReadUtilities();
0016 ~TestReadUtilities() override;
0017 int execute() override;
0018 };
0019 }
0020
0021 cond::TestReadUtilities::TestReadUtilities() : Utilities("conddb_copy_iov") {
0022 addConnectOption("connect", "c", "target connection string (required)");
0023 addAuthenticationOptions();
0024
0025 addOption<std::string>("hashes", "x", "space-separated list of hashes of the payloads");
0026 addOption<std::string>("tag", "t", "tag for the iov-based search");
0027 addOption<std::string>("iovs", "i", "space-separated list of target times ( run, lumi or timestamp)");
0028 addOption<bool>("run", "r", "run-labeled transaction");
0029 }
0030
0031 cond::TestReadUtilities::~TestReadUtilities() {}
0032
0033 int cond::TestReadUtilities::execute() {
0034 std::string connect = getOptionValue<std::string>("connect");
0035
0036 typedef boost::tokenizer<boost::char_separator<char>> tokenizer;
0037 std::vector<std::string> hashes;
0038 std::string tag("");
0039 std::vector<cond::Time_t> iovs;
0040 if (hasOptionValue("hashes")) {
0041 std::string hs = getOptionValue<std::string>("hashes");
0042 tokenizer tok(hs);
0043 for (auto &t : tok) {
0044 hashes.push_back(t);
0045 }
0046 } else if (hasOptionValue("tag")) {
0047 tag = getOptionValue<std::string>("tag");
0048 if (!hasOptionValue("iovs")) {
0049 std::cout << "ERROR: no iovs provided for tag " << tag << std::endl;
0050 return 1;
0051 }
0052 std::string siovs = getOptionValue<std::string>("iovs");
0053 tokenizer tok(siovs);
0054 for (auto &t : tok) {
0055 iovs.push_back(std::stoull(t));
0056 }
0057 }
0058
0059 if (hashes.empty() and iovs.empty()) {
0060 std::cout << "ERROR: no hashes or tag/iovs provided." << std::endl;
0061 return 1;
0062 }
0063
0064 persistency::ConnectionPool connPool;
0065 if (hasOptionValue("authPath")) {
0066 connPool.setAuthenticationPath(getOptionValue<std::string>("authPath"));
0067 }
0068 connPool.configure();
0069
0070 std::cout << "# Connecting to source database on " << connect << std::endl;
0071 persistency::Session session;
0072 bool runTransaction = hasOptionValue("run");
0073 session = connPool.createSession(connect, false);
0074 if (hashes.empty()) {
0075 for (auto &i : iovs) {
0076 auto startt = std::chrono::steady_clock::now();
0077 persistency::Session iovSession = session;
0078 if (runTransaction) {
0079 std::cout << "INFO: using run-labeled transactions." << std::endl;
0080 iovSession = connPool.createReadOnlySession(connect, std::to_string(i));
0081 }
0082 iovSession.transaction().start(true);
0083 cond::persistency::IOVProxy iovp = iovSession.readIov(tag);
0084 auto iov = iovp.getInterval(i);
0085 hashes.push_back(iov.payloadId);
0086 iovSession.transaction().commit();
0087 auto stopt = std::chrono::steady_clock::now();
0088 auto deltat = std::chrono::duration_cast<std::chrono::milliseconds>(stopt - startt);
0089 std::cout << "INFO: Resolved iov " << iov.since << " for target " << i << " in tag " << tag
0090 << " (time ms:" << deltat.count() << ")" << std::endl;
0091 }
0092 }
0093
0094 cond::Binary data;
0095 cond::Binary info;
0096 std::string typeName("");
0097 for (auto &h : hashes) {
0098 auto startt = std::chrono::steady_clock::now();
0099 session.transaction().start(true);
0100 bool found = session.fetchPayloadData(h, typeName, data, info);
0101 session.transaction().commit();
0102 auto stopt = std::chrono::steady_clock::now();
0103 auto deltat = std::chrono::duration_cast<std::chrono::milliseconds>(stopt - startt);
0104 if (!found) {
0105 std::cout << "ERROR: payload for hash " << h << " has not been found." << std::endl;
0106 return 2;
0107 } else {
0108 std::cout << "INFO: Loaded payload data for hash " << h << " size: " << data.size()
0109 << " (time ms:" << deltat.count() << ")" << std::endl;
0110 }
0111 }
0112 return 0;
0113 }
0114
0115 int main(int argc, char **argv) {
0116 cond::TestReadUtilities utilities;
0117 return utilities.run(argc, argv);
0118 }