Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:01:51

0001 #include "CondCore/CondDB/interface/ConnectionPool.h"
0002 #include "CondCore/CondDB/interface/Utils.h"
0003 #include "CondCore/CondDB/interface/IOVEditor.h"
0004 #include "CondCore/CondDB/interface/IOVProxy.h"
0005 
0006 #include "CondCore/Utilities/interface/Utilities.h"
0007 #include "CondCore/Utilities/interface/CondDBTools.h"
0008 #include <iostream>
0009 
0010 #include <sstream>
0011 
0012 namespace cond {
0013 
0014   class CopyIovUtilities : public cond::Utilities {
0015   public:
0016     CopyIovUtilities();
0017     ~CopyIovUtilities() override;
0018     int execute() override;
0019   };
0020 }  // namespace cond
0021 
0022 cond::CopyIovUtilities::CopyIovUtilities() : Utilities("conddb_copy_iov") {
0023   addConnectOption("connect", "c", "target connection string (required)");
0024   addAuthenticationOptions();
0025   addOption<std::string>("inputTag", "i", "source tag (optional)");
0026   addOption<std::string>("tag", "t", "destination tag (optional)");
0027   addOption<cond::Time_t>("sourceSince", "s", "since time of the iov to copy (required)");
0028   addOption<cond::Time_t>("destSince", "d", "since time of the destination iov (optional, default=sourceSince)");
0029   addOption<std::string>("description", "x", "user text (for new tags, optional)");
0030 }
0031 
0032 cond::CopyIovUtilities::~CopyIovUtilities() {}
0033 
0034 int cond::CopyIovUtilities::execute() {
0035   bool debug = hasDebug();
0036   std::string connect = getOptionValue<std::string>("connect");
0037 
0038   // this is mandatory
0039   std::string inputTag = getOptionValue<std::string>("inputTag");
0040   std::string tag = inputTag;
0041   if (hasOptionValue("tag"))
0042     tag = getOptionValue<std::string>("tag");
0043 
0044   cond::Time_t sourceSince = getOptionValue<cond::Time_t>("sourceSince");
0045   cond::Time_t destSince = sourceSince;
0046   if (hasOptionValue("destSince"))
0047     destSince = getOptionValue<cond::Time_t>("destSince");
0048 
0049   std::string description("");
0050   if (hasOptionValue("description"))
0051     description = getOptionValue<std::string>("description");
0052 
0053   persistency::ConnectionPool connPool;
0054   if (hasOptionValue("authPath")) {
0055     connPool.setAuthenticationPath(getOptionValue<std::string>("authPath"));
0056   }
0057   connPool.configure();
0058 
0059   std::cout << "# Connecting to source database on " << connect << std::endl;
0060   persistency::Session session = connPool.createSession(connect, true);
0061 
0062   std::cout << "# input tag is " << inputTag << std::endl;
0063   std::cout << "# destination tag is " << tag << std::endl;
0064 
0065   bool imported = copyIov(session, inputTag, tag, sourceSince, destSince, description);
0066 
0067   if (imported) {
0068     std::cout << "# 1 iov copied. " << std::endl;
0069   }
0070   return 0;
0071 }
0072 
0073 int main(int argc, char** argv) {
0074   cond::CopyIovUtilities utilities;
0075   return utilities.run(argc, argv);
0076 }