File indexing completed on 2024-04-06 12:01:38
0001
0002 #include "FWCore/PluginManager/interface/PluginManager.h"
0003 #include "FWCore/PluginManager/interface/standard.h"
0004 #include "FWCore/ServiceRegistry/interface/ServiceRegistry.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006
0007 #include "CondCore/Utilities/interface/CondPyInterface.h"
0008
0009 #include "CondCore/DBCommon/interface/Exception.h"
0010
0011 #include "CondCore/DBCommon/interface/DbConnection.h"
0012 #include "CondCore/DBCommon/interface/DbTransaction.h"
0013 #include "CondCore/DBCommon/interface/Exception.h"
0014 #include "CondCore/DBCommon/interface/FipProtocolParser.h"
0015 #include "CondCore/MetaDataService/interface/MetaData.h"
0016
0017 #include "CondCore/DBCommon/interface/Time.h"
0018
0019 #include "CondCore/IOVService/interface/IOVProxy.h"
0020
0021 #include "CondCore/ESSources/interface/DataProxy.h"
0022 #include "CondCore/ESSources/interface/ProxyFactory.h"
0023 #include "CondCore/IOVService/interface/PayloadProxy.h"
0024
0025 #include "CondCore/Utilities/interface/Utilities.h"
0026
0027 #include "CondCore/DBCommon/interface/ClassID.h"
0028
0029 #include "CondCore/IOVService/interface/KeyList.h"
0030 #include "CondCore/IOVService/interface/KeyListProxy.h"
0031
0032 #include <boost/program_options.hpp>
0033 #include <iterator>
0034 #include <iostream>
0035
0036 #include <typeinfo>
0037
0038
0039
0040 namespace {
0041 std::string buildName(const std::string& iRecordName) { return iRecordName + "@NewProxy"; }
0042
0043 class CondGetterFromTag : public cond::CondGetter {
0044 public:
0045 CondGetterFromTag(const cond::CondDB& db, std::string tag) : m_db(db), m_tag(tag) {}
0046 virtual ~CondGetterFromTag() {}
0047
0048 cond::IOVProxy get(std::string name) const override {
0049
0050 std::cout << "keyed record name " << name << std::endl;
0051 return m_db.iov(m_tag);
0052 }
0053
0054 cond::CondDB m_db;
0055 std::string m_tag;
0056 };
0057
0058
0059
0060
0061 }
0062
0063 namespace cond {
0064 class CondDataProxyUtilities : public Utilities {
0065 public:
0066 CondDataProxyUtilities();
0067 ~CondDataProxyUtilities();
0068 int execute() override;
0069 };
0070 }
0071
0072 cond::CondDataProxyUtilities::CondDataProxyUtilities() : Utilities("CondDataProxy_t") {
0073 this->addConnectOption();
0074 this->addAuthenticationOptions();
0075 addOption<bool>("verbose", "v", "verbose");
0076 addOption<std::string>("tag", "t", "tag");
0077 addOption<std::string>("keyed", "k", "tag of keyed container");
0078 addOption<std::string>("record", "r", "record");
0079 addOption<cond::Time_t>("atTime", "a", "time of event");
0080 }
0081
0082 cond::CondDataProxyUtilities::~CondDataProxyUtilities() {}
0083
0084 int cond::CondDataProxyUtilities::execute() {
0085 this->initializePluginManager();
0086 std::string authpath(".");
0087 if (this->hasOptionValue("authPath"))
0088 authpath = this->getAuthenticationPathValue();
0089 std::string connect = this->getConnectValue();
0090 std::string tag = this->getOptionValue<std::string>("tag");
0091 std::string keyed = this->getOptionValue<std::string>("keyed");
0092 std::string record = this->getOptionValue<std::string>("record");
0093
0094 cond::Time_t time = 0;
0095 if (this->hasOptionValue("atTime"))
0096 time = this->getOptionValue<cond::Time_t>("atTime");
0097 cond::RDBMS rdbms(authpath, this->hasDebug());
0098 cond::CondDB db = rdbms.getDB(connect);
0099 cond::DbSession mysession = db.session();
0100
0101
0102 cond::DataProxyWrapperBase* pb = cond::ProxyFactory::get()->create(buildName(record));
0103 pb->lateInit(mysession, db.iovToken(tag), "", connect, tag);
0104
0105 cond::DataProxyWrapperBase::ProxyP payloadProxy = pb->proxy();
0106
0107 std::cout << cond::className(typeid(*payloadProxy)) << std::endl;
0108
0109 CondGetterFromTag getter(db, keyed);
0110 payloadProxy->loadMore(getter);
0111
0112 cond::ValidityInterval iov = payloadProxy->setIntervalFor(time);
0113 payloadProxy->make();
0114 std::cout << "for " << time << ": since " << iov.first << ", till " << iov.second;
0115 if (payloadProxy->isValid()) {
0116 } else
0117 std::cout << ". No data";
0118 std::cout << std::endl;
0119
0120 {
0121 cond::PayloadProxy<cond::KeyList> const* pp = dynamic_cast<cond::PayloadProxy<cond::KeyList>*>(payloadProxy.get());
0122 if (pp) {
0123 const cond::KeyList& keys = (*pp)();
0124 int n = 0;
0125 for (int i = 0; i < keys.size(); i++)
0126 if (keys.elem(i))
0127 n++;
0128 std::cout << "found " << n << " valid keyed confs" << std::endl;
0129 }
0130 }
0131 return 0;
0132 }
0133
0134 int main(int argc, char** argv) {
0135 cond::CondDataProxyUtilities utilities;
0136 return utilities.run(argc, argv);
0137 }