Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:52:23

0001 #include "CondCore/CondDB/interface/ConnectionPool.h"
0002 #include "CondCore/CondDB/interface/RunInfoEditor.h"
0003 #include "CondCore/Utilities/interface/Utilities.h"
0004 #include "CondTools/RunInfo/interface/RunInfoUpdate.h"
0005 #include "CondFormats/RunInfo/interface/RunInfo.h"
0006 #include <iostream>
0007 
0008 #include <sstream>
0009 
0010 namespace cond {
0011 
0012   class RunInfoUtils : public cond::Utilities {
0013   public:
0014     RunInfoUtils();
0015     ~RunInfoUtils() override;
0016     int execute() override;
0017   };
0018 }  // namespace cond
0019 
0020 cond::RunInfoUtils::RunInfoUtils() : Utilities("conddb_import_runInfo") {
0021   addConnectOption("fromConnect", "f", "source connection string (optional, default=connect)");
0022   addConnectOption("connect", "c", "target connection string (required)");
0023   addAuthenticationOptions();
0024   addOption<std::string>("tag", "t", "source tag (required)");
0025   addOption<size_t>("max_entries", "m", "max entries to migrate (default=1000)");
0026 }
0027 
0028 cond::RunInfoUtils::~RunInfoUtils() {}
0029 
0030 boost::posix_time::ptime parseTimeFromIsoString(const std::string& isoString) {
0031   boost::posix_time::time_input_facet* tif = new boost::posix_time::time_input_facet;
0032   tif->set_iso_extended_format();
0033   std::istringstream iss(isoString);
0034   iss.imbue(std::locale(std::locale::classic(), tif));
0035   boost::posix_time::ptime ret;
0036   iss >> ret;
0037   return ret;
0038 }
0039 
0040 int cond::RunInfoUtils::execute() {
0041   std::string connect = getOptionValue<std::string>("connect");
0042   std::string fromConnect = getOptionValue<std::string>("fromConnect");
0043 
0044   // this is mandatory
0045   std::string tag = getOptionValue<std::string>("tag");
0046   std::cout << "# Source tag is " << tag << std::endl;
0047 
0048   size_t max_entries = 1000;
0049   if (hasOptionValue("max_entries"))
0050     max_entries = getOptionValue<size_t>("max_entries");
0051 
0052   persistency::ConnectionPool connPool;
0053   if (hasOptionValue("authPath")) {
0054     connPool.setAuthenticationPath(getOptionValue<std::string>("authPath"));
0055   }
0056   if (hasDebug())
0057     connPool.setMessageVerbosity(coral::Debug);
0058   connPool.configure();
0059 
0060   persistency::Session session = connPool.createSession(connect, true);
0061   std::cout << "# Connecting to target database on " << connect << std::endl;
0062   persistency::Session sourceSession = connPool.createSession(fromConnect);
0063   std::cout << "# Connecting to source database on " << fromConnect << std::endl;
0064   RunInfoUpdate updater(session);
0065   persistency::TransactionScope tsc(session.transaction());
0066   tsc.start(false);
0067   sourceSession.transaction().start();
0068   updater.import(max_entries, tag, sourceSession);
0069   sourceSession.transaction().commit();
0070   tsc.commit();
0071   return 0;
0072 }
0073 
0074 int main(int argc, char** argv) {
0075   cond::RunInfoUtils utilities;
0076   return utilities.run(argc, argv);
0077 }