Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-09-07 22:41:41

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 }  // namespace cond
0020 
0021 cond::TestReadUtilities::TestReadUtilities() : Utilities("conddb_copy_iov") {
0022   addConnectOption("connect", "c", "target connection string (required)");
0023   addAuthenticationOptions();
0024   //addOption<bool>("deserialize","d","de-serialize the specified payload");
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   bool debug = hasDebug();
0035   std::string connect = getOptionValue<std::string>("connect");
0036 
0037   typedef boost::tokenizer<boost::char_separator<char>> tokenizer;
0038   std::vector<std::string> hashes;
0039   std::string tag("");
0040   std::vector<cond::Time_t> iovs;
0041   if (hasOptionValue("hashes")) {
0042     std::string hs = getOptionValue<std::string>("hashes");
0043     tokenizer tok(hs);
0044     for (auto &t : tok) {
0045       hashes.push_back(t);
0046     }
0047   } else if (hasOptionValue("tag")) {
0048     tag = getOptionValue<std::string>("tag");
0049     if (!hasOptionValue("iovs")) {
0050       std::cout << "ERROR: no iovs provided for tag " << tag << std::endl;
0051       return 1;
0052     }
0053     std::string siovs = getOptionValue<std::string>("iovs");
0054     tokenizer tok(siovs);
0055     for (auto &t : tok) {
0056       iovs.push_back(std::stoull(t));
0057     }
0058   }
0059 
0060   if (hashes.empty() and iovs.empty()) {
0061     std::cout << "ERROR: no hashes or tag/iovs provided." << std::endl;
0062     return 1;
0063   }
0064 
0065   persistency::ConnectionPool connPool;
0066   if (hasOptionValue("authPath")) {
0067     connPool.setAuthenticationPath(getOptionValue<std::string>("authPath"));
0068   }
0069   connPool.configure();
0070 
0071   std::cout << "# Connecting to source database on " << connect << std::endl;
0072   persistency::Session session;
0073   bool runTransaction = hasOptionValue("run");
0074   session = connPool.createSession(connect, false);
0075   if (hashes.empty()) {
0076     for (auto &i : iovs) {
0077       auto startt = std::chrono::steady_clock::now();
0078       persistency::Session iovSession = session;
0079       if (runTransaction) {
0080         std::cout << "INFO: using run-labeled transactions." << std::endl;
0081         iovSession = connPool.createReadOnlySession(connect, std::to_string(i));
0082       }
0083       iovSession.transaction().start(true);
0084       cond::persistency::IOVProxy iovp = iovSession.readIov(tag);
0085       auto iov = iovp.getInterval(i);
0086       hashes.push_back(iov.payloadId);
0087       iovSession.transaction().commit();
0088       auto stopt = std::chrono::steady_clock::now();
0089       auto deltat = std::chrono::duration_cast<std::chrono::milliseconds>(stopt - startt);
0090       std::cout << "INFO: Resolved iov " << iov.since << " for target " << i << " in tag " << tag
0091                 << " (time ms:" << deltat.count() << ")" << std::endl;
0092     }
0093   }
0094 
0095   cond::Binary data;
0096   cond::Binary info;
0097   std::string typeName("");
0098   for (auto &h : hashes) {
0099     auto startt = std::chrono::steady_clock::now();
0100     session.transaction().start(true);
0101     bool found = session.fetchPayloadData(h, typeName, data, info);
0102     session.transaction().commit();
0103     auto stopt = std::chrono::steady_clock::now();
0104     auto deltat = std::chrono::duration_cast<std::chrono::milliseconds>(stopt - startt);
0105     if (!found) {
0106       std::cout << "ERROR: payload for hash " << h << " has not been found." << std::endl;
0107       return 2;
0108     } else {
0109       std::cout << "INFO: Loaded payload data for hash " << h << " size: " << data.size()
0110                 << " (time ms:" << deltat.count() << ")" << std::endl;
0111     }
0112   }
0113   return 0;
0114 }
0115 
0116 int main(int argc, char **argv) {
0117   cond::TestReadUtilities utilities;
0118   return utilities.run(argc, argv);
0119 }