File indexing completed on 2024-04-06 12:01:29
0001
0002 #include "FWCore/PluginManager/interface/PluginManager.h"
0003 #include "FWCore/PluginManager/interface/standard.h"
0004 #include "FWCore/PluginManager/interface/SharedLibrary.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "FWCore/ServiceRegistry/interface/ServiceRegistry.h"
0007
0008 #include "CondCore/CondDB/interface/ConnectionPool.h"
0009 #include "CondCore/CondDB/interface/PayloadProxy.h"
0010
0011 #include "CondFormats/RunInfo/interface/RunInfo.h"
0012
0013 #include "RelationalAccess/ISessionProxy.h"
0014 #include "RelationalAccess/ISchema.h"
0015 #include "RelationalAccess/ITransaction.h"
0016 #include "RelationalAccess/ITable.h"
0017 #include "RelationalAccess/IColumn.h"
0018 #include "RelationalAccess/IQuery.h"
0019 #include "RelationalAccess/ICursor.h"
0020 #include "CoralBase/AttributeSpecification.h"
0021 #include "CoralBase/AttributeList.h"
0022 #include "CoralBase/Attribute.h"
0023
0024
0025 #include <array>
0026 #include <cstdlib>
0027 #include <iostream>
0028 #include <memory>
0029
0030 void testCreateCoralSession(cond::persistency::ConnectionPool& connPool,
0031 std::string const& connectionString,
0032 bool const writeCapable) {
0033 std::shared_ptr<coral::ISessionProxy> session = connPool.createCoralSession(connectionString, writeCapable);
0034 session->transaction().start(true);
0035 coral::ISchema& schema = session->nominalSchema();
0036 std::string tagTable("TAG");
0037 std::string iovTable("IOV");
0038 std::string payloadTable("PAYLOAD");
0039 std::string tag("RunInfo_v1_mc");
0040 std::string object("RunInfo");
0041 std::string hash("cfd8987f899e99de69626e8a91b5c6b1506b82de");
0042 std::unique_ptr<coral::IQuery> query(schema.tableHandle(tagTable).newQuery());
0043 query->addToOutputList("OBJECT_TYPE");
0044 query->defineOutputType("OBJECT_TYPE", "string");
0045 std::string tagWhereClause("NAME=:tag");
0046 coral::AttributeList tagBindVariableList;
0047 tagBindVariableList.extend("tag", typeid(std::string));
0048 tagBindVariableList["tag"].data<std::string>() = tag;
0049 query->setCondition(tagWhereClause, tagBindVariableList);
0050 coral::ICursor& tagCursor = query->execute();
0051 while (tagCursor.next()) {
0052 tagCursor.currentRow().toOutputStream(std::cout) << std::endl;
0053 }
0054 query.reset(schema.tableHandle(iovTable).newQuery());
0055 query->addToOutputList("SINCE");
0056 query->defineOutputType("SINCE", "unsigned long long");
0057 std::string iovWhereClause("TAG_NAME=:tag");
0058 coral::AttributeList iovBindVariableList;
0059 iovBindVariableList.extend("tag", typeid(std::string));
0060 iovBindVariableList["tag"].data<std::string>() = tag;
0061 query->setCondition(iovWhereClause, iovBindVariableList);
0062 coral::ICursor& iovCursor = query->execute();
0063 while (iovCursor.next()) {
0064 iovCursor.currentRow().toOutputStream(std::cout) << std::endl;
0065 }
0066 query.reset(schema.tableHandle(payloadTable).newQuery());
0067 query->addToOutputList("OBJECT_TYPE");
0068 query->defineOutputType("OBJECT_TYPE", "string");
0069 std::string payloadWhereClause("HASH=:hash");
0070 coral::AttributeList payloadBindVariableList;
0071 payloadBindVariableList.extend("hash", typeid(std::string));
0072 payloadBindVariableList["hash"].data<std::string>() = hash;
0073 query->setCondition(payloadWhereClause, payloadBindVariableList);
0074 coral::ICursor& payloadCursor = query->execute();
0075 while (payloadCursor.next()) {
0076 payloadCursor.currentRow().toOutputStream(std::cout) << std::endl;
0077 }
0078 session->transaction().commit();
0079 }
0080
0081 void testCreateSession(cond::persistency::ConnectionPool& connPool,
0082 std::string const& connectionString,
0083 bool const writeCapable) {
0084 cond::Iov_t iov;
0085 cond::persistency::Session session = connPool.createSession(connectionString, writeCapable);
0086 auto requests = std::make_shared<std::vector<cond::Iov_t>>();
0087 cond::persistency::PayloadProxy<RunInfo> pp(&iov, &session, &requests);
0088 session.transaction().start(true);
0089 cond::persistency::IOVProxy iovProxy = session.readIov("RunInfo_v1_mc");
0090 iov = iovProxy.getInterval(1);
0091 session.transaction().commit();
0092 pp.initializeForNewIOV();
0093 pp.make();
0094 std::cout << "# run number: " << pp().m_run << std::endl;
0095 }
0096
0097 void testCreateReadOnlySession(cond::persistency::ConnectionPool& connPool,
0098 std::string const& connectionString,
0099 std::string const& transactionId) {
0100 cond::persistency::Session session = connPool.createReadOnlySession(connectionString, transactionId);
0101 session.transaction().start();
0102 cond::persistency::IOVProxy iov = session.readIov("RunInfo_v1_mc");
0103 std::cout << "Loaded size=" << iov.loadedSize() << std::endl;
0104 cond::Iov_t currentIov = iov.getInterval(1);
0105 std::cout << "run number: " << session.fetchPayload<RunInfo>(currentIov.payloadId)->m_run << std::endl;
0106 session.transaction().commit();
0107 }
0108
0109 int main(int argc, char** argv) {
0110 edmplugin::PluginManager::Config config;
0111 edmplugin::PluginManager::configure(edmplugin::standard::config());
0112
0113 std::vector<edm::ParameterSet> psets;
0114 edm::ParameterSet pSet;
0115 pSet.addParameter("@service_type", std::string("SiteLocalConfigService"));
0116 psets.push_back(pSet);
0117 const edm::ServiceToken services(edm::ServiceRegistry::createSet(psets));
0118 const edm::ServiceRegistry::Operate operate(services);
0119
0120 std::array<std::string, 2> connectionStrings{
0121 {"frontier://FrontierPrep/CMS_CONDITIONS",
0122 "frontier://(proxyconfigurl=http://grid-wpad/wpad.dat)(backupproxyurl=http://"
0123 "cmst0frontier.cern.ch:3128)(backupproxyurl=http://cmst0frontier1.cern.ch:3128)(backupproxyurl=http://"
0124 "cmst0frontier2.cern.ch:3128)(backupproxyurl=http://cmsbpfrontier.cern.ch:3128)(backupproxyurl=http://"
0125 "cmsbpfrontier1.cern.ch:3128)(backupproxyurl=http://cmsbpfrontier2.cern.ch:3128)(backupproxyurl=http://"
0126 "cmsbproxy.fnal.gov:3128)(serverurl=http://cmsfrontier.cern.ch:8000/FrontierPrep)(serverurl=http://"
0127 "cmsfrontier1.cern.ch:8000/FrontierPrep)(serverurl=http://cmsfrontier2.cern.ch:8000/"
0128 "FrontierPrep)(serverurl=http://cmsfrontier3.cern.ch:8000/FrontierPrep)(serverurl=http://"
0129 "cmsfrontier4.cern.ch:8000/FrontierPrep)/CMS_CONDITIONS"}};
0130 try {
0131
0132 for (const auto& connectionString : connectionStrings) {
0133 std::cout << "# Connecting with db in '" << connectionString << "'" << std::endl;
0134 cond::persistency::ConnectionPool connPool;
0135
0136
0137 try {
0138 connPool.createCoralSession(connectionString, true);
0139 } catch (const std::exception& e) {
0140 std::cout << "EXPECTED EXCEPTION: " << e.what() << std::endl;
0141 }
0142 testCreateCoralSession(connPool, connectionString, false);
0143 testCreateSession(connPool, connectionString, false);
0144 testCreateReadOnlySession(connPool, connectionString, "");
0145 testCreateReadOnlySession(connPool, connectionString, "testConnectionPool");
0146 connPool.setFrontierSecurity("foo");
0147 connPool.configure();
0148 try {
0149 connPool.createCoralSession(connectionString, false);
0150 } catch (const cms::Exception& e) {
0151 std::cout << "EXPECTED EXCEPTION: " << e.what() << std::endl;
0152 }
0153 edm::ParameterSet dbParameters;
0154 dbParameters.addUntrackedParameter("authenticationPath", std::string(""));
0155 dbParameters.addUntrackedParameter("authenticationSystem", 0);
0156 dbParameters.addUntrackedParameter("messageLevel", 3);
0157 dbParameters.addUntrackedParameter("security", std::string("sig"));
0158 dbParameters.addUntrackedParameter("logging", false);
0159 connPool.setParameters(dbParameters);
0160 connPool.configure();
0161 testCreateCoralSession(connPool, connectionString, false);
0162 testCreateSession(connPool, connectionString, false);
0163 testCreateReadOnlySession(connPool, connectionString, "");
0164 testCreateReadOnlySession(connPool, connectionString, "testConnectionPool");
0165 }
0166 } catch (const std::exception& e) {
0167 std::cout << "ERROR: " << e.what() << std::endl;
0168 return -1;
0169 } catch (...) {
0170 std::cout << "UNEXPECTED FAILURE." << std::endl;
0171 return -1;
0172 }
0173 }