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 #include "CoralMsgReporter.h"
6 //
9 // CMSSW includes
11 // coral includes
12 #include "RelationalAccess/ConnectionService.h"
13 #include "RelationalAccess/IWebCacheControl.h"
14 #include "RelationalAccess/ISessionProxy.h"
15 #include "RelationalAccess/IConnectionServiceConfiguration.h"
16 #include "CoralKernel/Context.h"
17 #include "CoralKernel/IProperty.h"
18 #include "CoralKernel/IPropertyManager.h"
19 
20 namespace cond {
21 
22  namespace persistency {
23 
27  coral::MessageStream::installMsgReporter(m_msgReporter);
28  configure();
29  }
30 
32 
34 
35  void ConnectionPool::setAuthenticationSystem(int authSysCode) { m_authSys = authSysCode; }
36 
38 
40 
41  void ConnectionPool::setParameters(const edm::ParameterSet& connectionPset) {
42  //set the connection parameters from a ParameterSet
43  //if a parameter is not defined, keep the values already set in the data members
44  //(i.e. default if no other setters called, or the ones currently available)
45  setAuthenticationPath(connectionPset.getUntrackedParameter<std::string>("authenticationPath", m_authPath));
46  setAuthenticationSystem(connectionPset.getUntrackedParameter<int>("authenticationSystem", m_authSys));
48  int messageLevel =
49  connectionPset.getUntrackedParameter<int>("messageLevel", 0); //0 corresponds to Error level, current default
50  coral::MsgLevel level = m_messageLevel;
51  switch (messageLevel) {
52  case 0:
54  break;
55  case 1:
56  level = coral::Warning;
57  break;
58  case 2:
59  level = coral::Info;
60  break;
61  case 3:
63  break;
64  default:
66  }
68  setLogging(connectionPset.getUntrackedParameter<bool>("logging", m_loggingEnabled));
69  }
70 
72 
73  void ConnectionPool::configure(coral::IConnectionServiceConfiguration& coralConfig) {
74  coralConfig.disablePoolAutomaticCleanUp();
75  coralConfig.disableConnectionSharing();
76  // message streaming
77  coral::MessageStream::setMsgVerbosity(m_messageLevel);
79 
80  // authentication
81  std::string authServiceName("CORAL/Services/EnvironmentAuthenticationService");
83  // authentication
84  if (authPath.empty()) {
85  // first try to check the env...
86  const char* authEnv = std::getenv(cond::auth::COND_AUTH_PATH);
87  if (authEnv) {
88  authPath += authEnv;
89  }
90  }
91  int authSys = m_authSys;
92  // first attempt, look at the env...
93  const char* authSysEnv = std::getenv(cond::auth::COND_AUTH_SYS);
94  if (authSysEnv) {
95  authSys = ::atoi(authSysEnv);
96  }
97  if (authSys != CondDbKey && authSys != CoralXMLFile) {
98  // take the default
99  authSys = CondDbKey;
100  }
101  std::string servName("");
102  if (authSys == CondDbKey) {
103  if (authPath.empty()) {
104  const char* authEnv = std::getenv("HOME");
105  if (authEnv) {
106  authPath += authEnv;
107  }
108  }
109  servName = "COND/Services/RelationalAuthenticationService";
110  } else if (authSys == CoralXMLFile) {
111  if (authPath.empty()) {
112  authPath = ".";
113  }
114  servName = "COND/Services/XMLAuthenticationService";
115  }
116  if (!authPath.empty()) {
117  authServiceName = servName;
118  coral::Context::instance().PropertyManager().property(cond::auth::COND_AUTH_PATH_PROPERTY)->set(authPath);
119  coral::Context::instance().loadComponent(authServiceName, m_pluginManager);
120  }
121 
122  coralConfig.setAuthenticationService(authServiceName);
123  }
124 
126  coral::ConnectionService connServ;
127  configure(connServ.configuration());
128  }
129 
130  std::shared_ptr<coral::ISessionProxy> ConnectionPool::createCoralSession(const std::string& connectionString,
131  const std::string& transactionId,
132  bool writeCapable) {
133  coral::ConnectionService connServ;
134  //all sessions opened with this connection service will share the same frontier security option.
135  std::pair<std::string, std::string> fullConnectionPars =
137  if (!fullConnectionPars.second.empty()) {
138  //all sessions opened with this connection service will share the same TTL settings for TAG, IOV, and PAYLOAD tables.
139  connServ.webCacheControl().setTableTimeToLive(fullConnectionPars.second, TAG::tname, 1);
140  connServ.webCacheControl().setTableTimeToLive(fullConnectionPars.second, IOV::tname, 1);
141  connServ.webCacheControl().setTableTimeToLive(fullConnectionPars.second, PAYLOAD::tname, 3);
142  }
143 
144  return std::shared_ptr<coral::ISessionProxy>(
145  connServ.connect(fullConnectionPars.first,
147  writeCapable ? coral::Update : coral::ReadOnly));
148  }
149 
151  const std::string& transactionId,
152  bool writeCapable) {
153  std::shared_ptr<coral::ISessionProxy> coralSession =
154  createCoralSession(connectionString, transactionId, writeCapable);
155  return Session(std::make_shared<SessionImpl>(coralSession, connectionString));
156  }
157 
159  return createSession(connectionString, "", writeCapable);
160  }
161 
163  const std::string& transactionId) {
164  return createSession(connectionString, transactionId);
165  }
166 
167  std::shared_ptr<coral::ISessionProxy> ConnectionPool::createCoralSession(const std::string& connectionString,
168  bool writeCapable) {
169  return createCoralSession(connectionString, "", writeCapable);
170  }
171 
173 
175 
176  } // namespace persistency
177 } // namespace cond
personalPlayback.level
level
Definition: personalPlayback.py:22
lumi_dqm_sourceclient-live_cfg.authPath
authPath
Definition: lumi_dqm_sourceclient-live_cfg.py:33
cond::persistency::ConnectionPool::m_pluginManager
cond::CoralServiceManager * m_pluginManager
Definition: ConnectionPool.h:73
cond::auth::COND_READER_ROLE
static constexpr const char *const COND_READER_ROLE
Definition: Auth.h:18
cond::persistency::ConnectionPool::~ConnectionPool
~ConnectionPool()
Definition: ConnectionPool.cc:31
cond::persistency::ConnectionPool::setFrontierSecurity
void setFrontierSecurity(const std::string &signature)
Definition: ConnectionPool.cc:37
cond::persistency::CoralMsgReporter
Definition: CoralMsgReporter.h:31
ConnectionPool.h
IOVSchema.h
logger
Definition: logger.py:1
cond::persistency::ConnectionPool::createCoralSession
std::shared_ptr< coral::ISessionProxy > createCoralSession(const std::string &connectionString, bool writeCapable=false)
Definition: ConnectionPool.cc:167
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
cond::persistency::ConnectionPool::isLoggingEnabled
bool isLoggingEnabled() const
Definition: ConnectionPool.cc:71
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:158
cond::persistency::ConnectionPool::setLogDestination
void setLogDestination(Logger &logger)
Definition: ConnectionPool.cc:174
cond::persistency::Logger
Definition: Logger.h:85
cond::auth::COND_WRITER_ROLE
static constexpr const char *const COND_WRITER_ROLE
Definition: Auth.h:17
cond::auth::COND_AUTH_SYS
static constexpr const char *const COND_AUTH_SYS
Definition: Auth.h:12
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:32
cond::persistency::ConnectionPool::m_messageLevel
coral::MsgLevel m_messageLevel
Definition: ConnectionPool.h:66
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:35
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:71
beam_dqm_sourceclient-live_cfg.messageLevel
messageLevel
Definition: beam_dqm_sourceclient-live_cfg.py:362
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:172
edm::ParameterSet
Definition: ParameterSet.h:47
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
CoralMsgReporter.h
cond::persistency::ConnectionPool::m_msgReporter
CoralMsgReporter * m_msgReporter
Definition: ConnectionPool.h:67
cond::persistency::CondDbKey
Definition: ConnectionPool.h:32
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:33
cond::persistency::CoralMsgReporter::subscribe
void subscribe(Logger &logger)
Definition: CoralMsgReporter.cc:143
cond::persistency::ConnectionPool::setParameters
void setParameters(const edm::ParameterSet &connectionPset)
Definition: ConnectionPool.cc:41
cond::persistency::ConnectionPool::configure
void configure()
Definition: ConnectionPool.cc:125
instance
static PFTauRenderPlugin instance
Definition: PFTauRenderPlugin.cc:70
cond::auth::COND_AUTH_PATH
static constexpr const char *const COND_AUTH_PATH
Definition: Auth.h:11
cond::persistency::ConnectionPool::m_authPath
std::string m_authPath
Definition: ConnectionPool.h:64
cond::persistency::ConnectionPool::m_loggingEnabled
bool m_loggingEnabled
Definition: ConnectionPool.h:68
cond::auth::COND_AUTH_PATH_PROPERTY
static constexpr const char *const COND_AUTH_PATH_PROPERTY
Definition: Auth.h:33
cond::persistency::ConnectionPool::setLogging
void setLogging(bool flag)
Definition: ConnectionPool.cc:39
cond::persistency::CoralMsgReporter::setOutputLevel
void setOutputLevel(coral::MsgLevel lvl) override
Modify output level.
Definition: CoralMsgReporter.cc:88
cond::persistency::ConnectionPool::ConnectionPool
ConnectionPool()
Definition: ConnectionPool.cc:24
Auth.h
cond::persistency::ConnectionPool::createReadOnlySession
Session createReadOnlySession(const std::string &connectionString, const std::string &transactionId)
Definition: ConnectionPool.cc:162
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:65
RemoveAddSevLevel.flag
flag
Definition: RemoveAddSevLevel.py:116