Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:50:47

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 
0009 namespace cond {
0010 
0011   class TestIovUtilities : public cond::Utilities {
0012   public:
0013     TestIovUtilities();
0014     ~TestIovUtilities() override;
0015     int execute() override;
0016   };
0017 }  // namespace cond
0018 
0019 cond::TestIovUtilities::TestIovUtilities() : Utilities("conddb_copy_iov") {
0020   addConnectOption("connect", "c", "target connection string (required)");
0021   addAuthenticationOptions();
0022   addOption<bool>("read", "r", "de-serialize the specified payload");
0023   addOption<std::string>("hash", "x", "hash of the payload");
0024 }
0025 
0026 cond::TestIovUtilities::~TestIovUtilities() {}
0027 
0028 int cond::TestIovUtilities::execute() {
0029   bool debug = hasDebug();
0030   std::string connect = getOptionValue<std::string>("connect");
0031 
0032   std::string hash("");
0033   bool read = hasOptionValue("read");
0034   if (read) {
0035     hash = getOptionValue<std::string>("hash");
0036   }
0037 
0038   persistency::ConnectionPool connPool;
0039   if (hasOptionValue("authPath")) {
0040     connPool.setAuthenticationPath(getOptionValue<std::string>("authPath"));
0041   }
0042   connPool.configure();
0043 
0044   std::cout << "# Connecting to source database on " << connect << std::endl;
0045   persistency::Session session = connPool.createSession(connect);
0046 
0047   session.transaction().start(true);
0048   try {
0049     persistency::fetch(hash, session);
0050     std::cout << "De-serialization of payload " << hash << " performed correctly." << std::endl;
0051   } catch (const persistency::Exception& e) {
0052     std::cout << "De-serialization of payload " << hash << " failed: " << e.what() << std::endl;
0053   }
0054   session.transaction().commit();
0055   return 0;
0056 }
0057 
0058 int main(int argc, char** argv) {
0059   cond::TestIovUtilities utilities;
0060   return utilities.run(argc, argv);
0061 }