CMS 3D CMS Logo

ConnectionPool.cc
Go to the documentation of this file.
2 #include "DbConnectionString.h"
3 #include "SessionImpl.h"
4 #include "IOVSchema.h"
5 //
8 // CMSSW includes
10 // coral includes
11 #include "RelationalAccess/ConnectionService.h"
12 #include "RelationalAccess/IWebCacheControl.h"
13 #include "RelationalAccess/ISessionProxy.h"
14 #include "RelationalAccess/IConnectionServiceConfiguration.h"
15 #include "CoralKernel/Context.h"
16 #include "CoralKernel/IProperty.h"
17 #include "CoralKernel/IPropertyManager.h"
18 // externals
19 #include <boost/filesystem/operations.hpp>
20 
21 namespace cond {
22 
23  namespace persistency {
24 
27  configure();
28  }
29 
31 
33 
34  void ConnectionPool::setAuthenticationSystem(int authSysCode) { m_authSys = authSysCode; }
35 
37 
39 
40  void ConnectionPool::setParameters(const edm::ParameterSet& connectionPset) {
41  //set the connection parameters from a ParameterSet
42  //if a parameter is not defined, keep the values already set in the data members
43  //(i.e. default if no other setters called, or the ones currently available)
44  setAuthenticationPath(connectionPset.getUntrackedParameter<std::string>("authenticationPath", m_authPath));
45  setAuthenticationSystem(connectionPset.getUntrackedParameter<int>("authenticationSystem", m_authSys));
47  int messageLevel =
48  connectionPset.getUntrackedParameter<int>("messageLevel", 0); //0 corresponds to Error level, current default
49  coral::MsgLevel level = m_messageLevel;
50  switch (messageLevel) {
51  case 0:
53  break;
54  case 1:
55  level = coral::Warning;
56  break;
57  case 2:
58  level = coral::Info;
59  break;
60  case 3:
62  break;
63  default:
65  }
67  setLogging(connectionPset.getUntrackedParameter<bool>("logging", m_loggingEnabled));
68  }
69 
71 
72  void ConnectionPool::configure(coral::IConnectionServiceConfiguration& coralConfig) {
73  coralConfig.disablePoolAutomaticCleanUp();
74  coralConfig.disableConnectionSharing();
75  // message streaming
76  coral::MessageStream::setMsgVerbosity(m_messageLevel);
77  std::string authServiceName("CORAL/Services/EnvironmentAuthenticationService");
79  // authentication
80  if (authPath.empty()) {
81  // first try to check the env...
82  const char* authEnv = std::getenv(cond::auth::COND_AUTH_PATH);
83  if (authEnv) {
84  authPath += authEnv;
85  }
86  }
87  int authSys = m_authSys;
88  // first attempt, look at the env...
89  const char* authSysEnv = std::getenv(cond::auth::COND_AUTH_SYS);
90  if (authSysEnv) {
91  authSys = ::atoi(authSysEnv);
92  }
93  if (authSys != CondDbKey && authSys != CoralXMLFile) {
94  // take the default
95  authSys = CondDbKey;
96  }
97  std::string servName("");
98  if (authSys == CondDbKey) {
99  if (authPath.empty()) {
100  const char* authEnv = std::getenv("HOME");
101  if (authEnv) {
102  authPath += authEnv;
103  }
104  }
105  servName = "COND/Services/RelationalAuthenticationService";
106  } else if (authSys == CoralXMLFile) {
107  if (authPath.empty()) {
108  authPath = ".";
109  }
110  servName = "COND/Services/XMLAuthenticationService";
111  }
112  if (!authPath.empty()) {
113  authServiceName = servName;
114  coral::Context::instance().PropertyManager().property(cond::auth::COND_AUTH_PATH_PROPERTY)->set(authPath);
115  coral::Context::instance().loadComponent(authServiceName, m_pluginManager);
116  }
117 
118  coralConfig.setAuthenticationService(authServiceName);
119  }
120 
122  coral::ConnectionService connServ;
123  configure(connServ.configuration());
124  }
125 
126  std::shared_ptr<coral::ISessionProxy> ConnectionPool::createCoralSession(const std::string& connectionString,
127  const std::string& transactionId,
128  bool writeCapable) {
129  coral::ConnectionService connServ;
130  //all sessions opened with this connection service will share the same frontier security option.
131  std::pair<std::string, std::string> fullConnectionPars =
133  if (!fullConnectionPars.second.empty()) {
134  //all sessions opened with this connection service will share the same TTL settings for TAG, IOV, and PAYLOAD tables.
135  connServ.webCacheControl().setTableTimeToLive(fullConnectionPars.second, TAG::tname, 1);
136  connServ.webCacheControl().setTableTimeToLive(fullConnectionPars.second, IOV::tname, 1);
137  connServ.webCacheControl().setTableTimeToLive(fullConnectionPars.second, PAYLOAD::tname, 3);
138  }
139 
140  return std::shared_ptr<coral::ISessionProxy>(
141  connServ.connect(fullConnectionPars.first,
143  writeCapable ? coral::Update : coral::ReadOnly));
144  }
145 
147  const std::string& transactionId,
148  bool writeCapable) {
149  std::shared_ptr<coral::ISessionProxy> coralSession =
150  createCoralSession(connectionString, transactionId, writeCapable);
151  return Session(std::make_shared<SessionImpl>(coralSession, connectionString));
152  }
153 
155  return createSession(connectionString, "", writeCapable);
156  }
157 
159  const std::string& transactionId) {
160  return createSession(connectionString, transactionId);
161  }
162 
163  std::shared_ptr<coral::ISessionProxy> ConnectionPool::createCoralSession(const std::string& connectionString,
164  bool writeCapable) {
165  return createCoralSession(connectionString, "", writeCapable);
166  }
167 
169 
170  } // namespace persistency
171 } // namespace cond
personalPlayback.level
level
Definition: personalPlayback.py:22
lumi_dqm_sourceclient-live_cfg.authPath
authPath
Definition: lumi_dqm_sourceclient-live_cfg.py:29
cond::persistency::ConnectionPool::m_pluginManager
cond::CoralServiceManager * m_pluginManager
Definition: ConnectionPool.h:67
cond::auth::COND_READER_ROLE
static constexpr const char *const COND_READER_ROLE
Definition: Auth.h:17
cond::persistency::ConnectionPool::~ConnectionPool
~ConnectionPool()
Definition: ConnectionPool.cc:30
cond::persistency::ConnectionPool::setFrontierSecurity
void setFrontierSecurity(const std::string &signature)
Definition: ConnectionPool.cc:36
ConnectionPool.h
IOVSchema.h
cond::persistency::ConnectionPool::createCoralSession
std::shared_ptr< coral::ISessionProxy > createCoralSession(const std::string &connectionString, bool writeCapable=false)
Definition: ConnectionPool.cc:163
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
cond::persistency::ConnectionPool::isLoggingEnabled
bool isLoggingEnabled() const
Definition: ConnectionPool.cc:70
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
CoralServiceManager.h
cond::persistency::ConnectionPool::createSession
Session createSession(const std::string &connectionString, bool writeCapable=false)
Definition: ConnectionPool.cc:154
cond::auth::COND_WRITER_ROLE
static constexpr const char *const COND_WRITER_ROLE
Definition: Auth.h:16
cond::auth::COND_AUTH_SYS
static constexpr const char *const COND_AUTH_SYS
Definition: Auth.h:11
cond::CoralServiceManager
Definition: CoralServiceManager.h:25
Debug
const bool Debug
Definition: CosmicMuonParameters.h:12
DbConnectionString.h
cond::persistency::TAG::tname
static constexpr char const * tname
Definition: IOVSchema.h:13
SessionImpl.h
cond::persistency::CoralXMLFile
Definition: ConnectionPool.h:28
cond::persistency::ConnectionPool::m_messageLevel
coral::MsgLevel m_messageLevel
Definition: ConnectionPool.h:61
cond::persistency::getConnectionParams
std::pair< std::string, std::string > getConnectionParams(const std::string &connectionString, const std::string &transactionId, const std::string &signature)
Definition: DbConnectionString.cc:39
cond::persistency::ConnectionPool::setAuthenticationSystem
void setAuthenticationSystem(int authSysCode)
Definition: ConnectionPool.cc:34
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
cond
Definition: plugin.cc:23
cond::persistency::ConnectionPool::m_frontierSecurity
std::string m_frontierSecurity
Definition: ConnectionPool.h:65
beam_dqm_sourceclient-live_cfg.messageLevel
messageLevel
Definition: beam_dqm_sourceclient-live_cfg.py:355
cond::persistency::IOV::tname
static constexpr char const * tname
Definition: IOVSchema.h:104
cond::persistency::ConnectionPool::setMessageVerbosity
void setMessageVerbosity(coral::MsgLevel level)
Definition: ConnectionPool.cc:168
edm::ParameterSet
Definition: ParameterSet.h:36
signature
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined signature
Definition: Activities.doc:4
cond::persistency::CondDbKey
Definition: ConnectionPool.h:28
cond::persistency::Session
Definition: Session.h:63
leef::Error
edm::ErrorSummaryEntry Error
Definition: LogErrorEventFilter.cc:29
cond::persistency::ConnectionPool::setAuthenticationPath
void setAuthenticationPath(const std::string &p)
Definition: ConnectionPool.cc:32
cond::persistency::ConnectionPool::setParameters
void setParameters(const edm::ParameterSet &connectionPset)
Definition: ConnectionPool.cc:40
cond::persistency::ConnectionPool::configure
void configure()
Definition: ConnectionPool.cc:121
instance
static PFTauRenderPlugin instance
Definition: PFTauRenderPlugin.cc:70
cond::auth::COND_AUTH_PATH
static constexpr const char *const COND_AUTH_PATH
Definition: Auth.h:10
cond::persistency::ConnectionPool::m_authPath
std::string m_authPath
Definition: ConnectionPool.h:59
cond::persistency::ConnectionPool::m_loggingEnabled
bool m_loggingEnabled
Definition: ConnectionPool.h:62
cond::auth::COND_AUTH_PATH_PROPERTY
static constexpr const char *const COND_AUTH_PATH_PROPERTY
Definition: Auth.h:27
cond::persistency::ConnectionPool::setLogging
void setLogging(bool flag)
Definition: ConnectionPool.cc:38
cond::persistency::ConnectionPool::ConnectionPool
ConnectionPool()
Definition: ConnectionPool.cc:25
Auth.h
cond::persistency::ConnectionPool::createReadOnlySession
Session createReadOnlySession(const std::string &connectionString, const std::string &transactionId)
Definition: ConnectionPool.cc:158
ParameterSet.h
cond::persistency::PAYLOAD::tname
static constexpr char const * tname
Definition: IOVSchema.h:67
l1RCTOmdsFedVectorProducer_cfi.connectionString
connectionString
Definition: l1RCTOmdsFedVectorProducer_cfi.py:4
cond::persistency::ConnectionPool::m_authSys
int m_authSys
Definition: ConnectionPool.h:60
RemoveAddSevLevel.flag
flag
Definition: RemoveAddSevLevel.py:116