CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
25  static const std::string POOL_IOV_TABLE_DATA("IOV_DATA");
26  static const std::string ORA_IOV_TABLE_1("ORA_C_COND_IOVSEQUENCE");
27  static const std::string ORA_IOV_TABLE_2("ORA_C_COND_IOVSEQU_A0");
28  static const std::string ORA_IOV_TABLE_3("ORA_C_COND_IOVSEQU_A1");
29 
32  configure();
33  }
34 
36  delete m_pluginManager;
37  }
38 
40  m_authPath = p;
41  }
42 
43  void ConnectionPool::setAuthenticationSystem( int authSysCode ){
44  m_authSys = authSysCode;
45  }
46 
49  }
50 
51  void ConnectionPool::setParameters( const edm::ParameterSet& connectionPset ){
52  setAuthenticationPath( connectionPset.getUntrackedParameter<std::string>("authenticationPath","") );
53  setAuthenticationSystem( connectionPset.getUntrackedParameter<int>("authenticationSystem",0) );
54  int messageLevel = connectionPset.getUntrackedParameter<int>("messageLevel",0);
55  coral::MsgLevel level = coral::Error;
56  switch (messageLevel) {
57  case 0 :
58  level = coral::Error;
59  break;
60  case 1:
61  level = coral::Warning;
62  break;
63  case 2:
64  level = coral::Info;
65  break;
66  case 3:
67  level = coral::Debug;
68  break;
69  default:
70  level = coral::Error;
71  }
72  setMessageVerbosity(level);
73  setLogging( connectionPset.getUntrackedParameter<bool>("logging",false) );
74  }
75 
77  return m_loggingEnabled;
78  }
79 
80  void ConnectionPool::configure( coral::IConnectionServiceConfiguration& coralConfig){
81 
82  coralConfig.disablePoolAutomaticCleanUp();
83  coralConfig.disableConnectionSharing();
84  // message streaming
85  coral::MessageStream::setMsgVerbosity( m_messageLevel );
86  std::string authServiceName("CORAL/Services/EnvironmentAuthenticationService");
88  // authentication
89  if( authPath.empty() ){
90  // first try to check the env...
91  const char* authEnv = ::getenv( cond::Auth::COND_AUTH_PATH );
92  if(authEnv){
93  authPath += authEnv;
94  }
95  }
96  int authSys = m_authSys;
97  // first attempt, look at the env...
98  const char* authSysEnv = ::getenv( cond::Auth::COND_AUTH_SYS );
99  if( authSysEnv ){
100  authSys = ::atoi( authSysEnv );
101  }
102  if( authSys !=CondDbKey && authSys != CoralXMLFile ){
103  // take the default
104  authSys = CondDbKey;
105  }
106  std::string servName("");
107  if( authSys == CondDbKey ){
108  if( authPath.empty() ){
109  const char* authEnv = ::getenv("HOME");
110  if(authEnv){
111  authPath += authEnv;
112  }
113  }
114  servName = "COND/Services/RelationalAuthenticationService";
115  } else if( authSys == CoralXMLFile ){
116  if( authPath.empty() ){
117  authPath = ".";
118  }
119  servName = "COND/Services/XMLAuthenticationService";
120  }
121  if( !authPath.empty() ){
122  authServiceName = servName;
123  coral::Context::instance().PropertyManager().property(cond::Auth::COND_AUTH_PATH_PROPERTY)->set(authPath);
124  coral::Context::instance().loadComponent( authServiceName, m_pluginManager );
125  }
126 
127  std::cout << "==> using " << servName << " for auth, sys " << authSys << std::endl;
128 
129  coralConfig.setAuthenticationService( authServiceName );
130  }
131 
133  coral::ConnectionService connServ;
134  configure( connServ.configuration() );
135  }
136 
138  const std::string& transactionId,
139  bool writeCapable,
140  BackendType backType){
141  coral::ConnectionService connServ;
142  std::pair<std::string,std::string> fullConnectionPars = getConnectionParams( connectionString, transactionId );
143  if( !fullConnectionPars.second.empty() ) {
144  // the olds formats
145  connServ.webCacheControl().refreshTable( fullConnectionPars.second, POOL_IOV_TABLE_DATA );
146  connServ.webCacheControl().refreshTable( fullConnectionPars.second, ORA_IOV_TABLE_1 );
147  connServ.webCacheControl().refreshTable( fullConnectionPars.second, ORA_IOV_TABLE_2 );
148  connServ.webCacheControl().refreshTable( fullConnectionPars.second, ORA_IOV_TABLE_3 );
149  // the new schema...
150  connServ.webCacheControl().setTableTimeToLive( fullConnectionPars.second, TAG::tname, 1 );
151  connServ.webCacheControl().setTableTimeToLive( fullConnectionPars.second, IOV::tname, 1 );
152  connServ.webCacheControl().setTableTimeToLive( fullConnectionPars.second, PAYLOAD::tname, 3 );
153  }
154 
155  boost::shared_ptr<coral::ISessionProxy> coralSession( connServ.connect( fullConnectionPars.first,
157  writeCapable?coral::Update:coral::ReadOnly ) );
158  BackendType bt;
159  auto it = m_dbTypes.find( connectionString);
160  if( it == m_dbTypes.end() ){
161  bt = checkBackendType( coralSession, connectionString );
162  if( bt == UNKNOWN_DB && writeCapable) bt = backType;
163  m_dbTypes.insert( std::make_pair( connectionString, bt ) );
164  } else {
165  bt = (BackendType) it->second;
166  }
167 
168  std::shared_ptr<SessionImpl> impl( new SessionImpl( coralSession, connectionString, bt ) );
169  return Session( impl );
170  }
171 
172  Session ConnectionPool::createSession( const std::string& connectionString, bool writeCapable, BackendType backType ){
173  return createSession( connectionString, "", writeCapable, backType );
174  }
175 
176  Session ConnectionPool::createReadOnlySession( const std::string& connectionString, const std::string& transactionId ){
177  return createSession( connectionString, transactionId );
178  }
181  }
182 
183 
184 
185  }
186 }
static const std::string ORA_IOV_TABLE_1("ORA_C_COND_IOVSEQUENCE")
BackendType checkBackendType(boost::shared_ptr< coral::ISessionProxy > &coralSession, const std::string &connectionString)
Definition: SessionImpl.cc:60
T getUntrackedParameter(std::string const &, T const &) const
static PFTauRenderPlugin instance
static const std::string COND_AUTH_PATH_PROPERTY
Definition: Auth.h:27
static const std::string ORA_IOV_TABLE_3("ORA_C_COND_IOVSEQU_A1")
void setParameters(const edm::ParameterSet &connectionPset)
std::pair< std::string, std::string > getConnectionParams(const std::string &connectionString, const std::string &transactionId)
void setAuthenticationSystem(int authSysCode)
static const char * COND_AUTH_SYS
Definition: Auth.h:13
Session createSession(const std::string &connectionString, bool writeCapable=false, BackendType backType=DEFAULT_DB)
static const std::string COND_WRITER_ROLE
Definition: Auth.h:18
void setMessageVerbosity(coral::MsgLevel level)
BackendType
Definition: Types.h:23
std::map< std::string, int > m_dbTypes
static const std::string COND_READER_ROLE
Definition: Auth.h:19
static const std::string POOL_IOV_TABLE_DATA("IOV_DATA")
static const char * COND_AUTH_PATH
Definition: Auth.h:12
Session createReadOnlySession(const std::string &connectionString, const std::string &transactionId)
tuple cout
Definition: gather_cfg.py:121
tuple level
Definition: testEve_cfg.py:34
cond::CoralServiceManager * m_pluginManager
static const std::string ORA_IOV_TABLE_2("ORA_C_COND_IOVSEQU_A0")
void setAuthenticationPath(const std::string &p)
const bool Debug