Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:03:17

0001 #include "CondCore/Utilities/interface/Utilities.h"
0002 #include "CondCore/CondDB/interface/ConnectionPool.h"
0003 #include "CondFormats/RunInfo/interface/LHCInfo.h"
0004 
0005 //#include <boost/program_options.hpp>
0006 #include <fstream>
0007 #include <iostream>
0008 #include <stdexcept>
0009 
0010 namespace cond {
0011   class Dump_LHCInfo : public Utilities {
0012   public:
0013     Dump_LHCInfo();
0014     ~Dump_LHCInfo() override;
0015     int execute() override;
0016   };
0017 }  // namespace cond
0018 
0019 cond::Dump_LHCInfo::Dump_LHCInfo() : Utilities("conddb_dump_LHCInfo") {
0020   addConnectOption("connect", "c", "source connection string (optional, default=connect)");
0021   addOption<std::string>("tag", "t", "the source tag");
0022   addOption<std::string>("hash", "i", "the hash (id) of the payload to dump");
0023   addOption<cond::Time_t>("since", "s", "since time of the iov");
0024 }
0025 
0026 cond::Dump_LHCInfo::~Dump_LHCInfo() {}
0027 
0028 namespace Dump_LHCInfo_impl {
0029   void dump(const LHCInfo& payload, std::ostream& out) {
0030     std::stringstream ss;
0031     payload.print(ss);
0032     out << ss.str();
0033     out << std::endl;
0034   }
0035 }  // namespace Dump_LHCInfo_impl
0036 
0037 int cond::Dump_LHCInfo::execute() {
0038   std::string connect = getOptionValue<std::string>("connect");
0039   std::string tag("");
0040 
0041   cond::persistency::ConnectionPool connection;
0042   connection.setMessageVerbosity(coral::Error);
0043   connection.configure();
0044 
0045   cond::Hash payloadHash("");
0046   cond::Time_t since = 0;
0047   if (hasOptionValue("hash")) {
0048     payloadHash = getOptionValue<std::string>("hash");
0049   } else {
0050     if (hasOptionValue("tag")) {
0051       tag = getOptionValue<std::string>("tag");
0052     } else {
0053       std::cout << "Error: no tag provided to identify the payload." << std::endl;
0054       return 1;
0055     }
0056     if (hasOptionValue("since")) {
0057       since = getOptionValue<cond::Time_t>("since");
0058     } else {
0059       std::cout << "Error: no IOV since provided to identify the payload." << std::endl;
0060       return 1;
0061     }
0062   }
0063 
0064   cond::persistency::Session session = connection.createSession(connect, false);
0065   session.transaction().start(true);
0066 
0067   if (payloadHash.empty()) {
0068     cond::persistency::IOVProxy iovSeq = session.readIov(tag);
0069     auto iov = iovSeq.getInterval(since);
0070     payloadHash = iov.payloadId;
0071   }
0072 
0073   std::shared_ptr<LHCInfo> payload = session.fetchPayload<LHCInfo>(payloadHash);
0074   session.transaction().commit();
0075 
0076   std::cout << "# *********************************************************** " << std::endl;
0077   std::cout << "# Dumping payload id " << payloadHash << std::endl;
0078   std::cout << "# *********************************************************** " << std::endl;
0079 
0080   Dump_LHCInfo_impl::dump(*payload, std::cout);
0081 
0082   std::cout << "# *********************************************************** " << std::endl;
0083   return 0;
0084 }
0085 
0086 int main(int argc, char** argv) {
0087   cond::Dump_LHCInfo utilities;
0088   return utilities.run(argc, argv);
0089 }