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 ImportUtilities : public cond::Utilities {
0015   public:
0016     ImportUtilities();
0017     ~ImportUtilities() override;
0018     int execute() override;
0019   };
0020 }  // namespace cond
0021 
0022 cond::ImportUtilities::ImportUtilities() : Utilities("conddb_import") {
0023   addConnectOption("fromConnect", "f", "source connection string (optional, default=connect)");
0024   addConnectOption("connect", "c", "target connection string (required)");
0025   addAuthenticationOptions();
0026   addOption<std::string>("inputTag", "i", "source tag (optional - default=tag)");
0027   addOption<std::string>("tag", "t", "destination tag (required)");
0028   addOption<cond::Time_t>("begin", "b", "lower bound of interval to import (optional, default=1)");
0029   addOption<cond::Time_t>("end", "e", "upper bound of interval to import (optional, default=infinity)");
0030   addOption<std::string>("description", "x", "User text ( for new tags, optional )");
0031   addOption<bool>("override",
0032                   "o",
0033                   "Override the existing iovs in the dest tag, for the selected interval ( optional, default=false)");
0034   addOption<bool>("reserialize", "r", "De-serialize in reading and serialize in writing (optional, default=false)");
0035   addOption<bool>("forceInsert", "K", "force the insert for all synchronization types (optional, default=false)");
0036   addOption<std::string>("editingNote", "N", "editing note (required with forceInsert)");
0037 }
0038 
0039 cond::ImportUtilities::~ImportUtilities() {}
0040 
0041 int cond::ImportUtilities::execute() {
0042   bool debug = hasDebug();
0043   std::string destConnect = getOptionValue<std::string>("connect");
0044   std::string sourceConnect = destConnect;
0045   if (hasOptionValue("fromConnect"))
0046     sourceConnect = getOptionValue<std::string>("fromConnect");
0047 
0048   std::string inputTag = getOptionValue<std::string>("inputTag");
0049   ;
0050   std::string tag = inputTag;
0051   if (hasOptionValue("tag")) {
0052     tag = getOptionValue<std::string>("tag");
0053   }
0054 
0055   std::string description("");
0056   if (hasOptionValue("description"))
0057     description = getOptionValue<std::string>("description");
0058   bool override = hasOptionValue("override");
0059   bool reserialize = hasOptionValue("reserialize");
0060   bool forceInsert = hasOptionValue("forceInsert");
0061   std::string editingNote("");
0062   if (hasOptionValue("editingNote"))
0063     editingNote = getOptionValue<std::string>("editingNote");
0064   if (forceInsert && editingNote.empty()) {
0065     std::cout << "ERROR: \'forceInsert\' mode requires an \'editingNote\' to be provided." << std::endl;
0066     return -1;
0067   }
0068 
0069   cond::Time_t begin = 1;
0070   if (hasOptionValue("begin"))
0071     begin = getOptionValue<cond::Time_t>("begin");
0072   cond::Time_t end = cond::time::MAX_VAL;
0073   if (hasOptionValue("end"))
0074     end = getOptionValue<cond::Time_t>("end");
0075   if (begin > end)
0076     throwException("Begin time can't be greater than end time.", "ImportUtilities::execute");
0077 
0078   persistency::ConnectionPool connPool;
0079   if (hasOptionValue("authPath")) {
0080     connPool.setAuthenticationPath(getOptionValue<std::string>("authPath"));
0081   }
0082   connPool.configure();
0083   std::cout << "# Running import tool for conditions on release " << cond::currentCMSSWVersion() << std::endl;
0084   std::cout << "# Connecting to source database on " << sourceConnect << std::endl;
0085   persistency::Session sourceSession = connPool.createSession(sourceConnect);
0086 
0087   std::cout << "# Opening session on destination database..." << std::endl;
0088   persistency::Session destSession = connPool.createSession(destConnect, true);
0089 
0090   std::cout << "# destination tag is " << tag << std::endl;
0091 
0092   size_t nimported = importIovs(inputTag,
0093                                 sourceSession,
0094                                 tag,
0095                                 destSession,
0096                                 begin,
0097                                 end,
0098                                 description,
0099                                 editingNote,
0100                                 override,
0101                                 reserialize,
0102                                 forceInsert);
0103   std::cout << "# " << nimported << " iov(s) imported. " << std::endl;
0104 
0105   return 0;
0106 }
0107 
0108 int main(int argc, char** argv) {
0109   cond::ImportUtilities utilities;
0110   return utilities.run(argc, argv);
0111 }