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 //
6 // CMSSW includes
8 // coral includes
9 #include "RelationalAccess/ConnectionService.h"
10 #include "RelationalAccess/IWebCacheControl.h"
11 #include "RelationalAccess/ISessionProxy.h"
12 #include "RelationalAccess/IConnectionServiceConfiguration.h"
13 #include "CoralKernel/Context.h"
14 #include "CoralKernel/IProperty.h"
15 #include "CoralKernel/IPropertyManager.h"
16 // externals
17 #include <boost/filesystem/operations.hpp>
18 
19 namespace cond {
20 
21  namespace persistency {
22 
24  m_authPath(),
25  m_authSys(0),
26  m_messageLevel( coral::Error ),
27  m_loggingEnabled( false ),
28  m_pluginManager( new cond::CoralServiceManager ),
29  m_refreshtablelist(){
30  m_refreshtablelist.reserve(6);
31  //table names for IOVSequence in the old POOL mapping
32  m_refreshtablelist.push_back("IOV");
33  m_refreshtablelist.push_back("IOV_DATA");
34  //table names for IOVSequence in ORA
35  m_refreshtablelist.push_back("ORA_C_COND_IOVSEQUENCE");
36  m_refreshtablelist.push_back("ORA_C_COND_IOVSEQU_A0");
37  m_refreshtablelist.push_back("ORA_C_COND_IOVSEQU_A1");
38  //table names for IOVSequence in CONDDB
39  m_refreshtablelist.push_back("TAG");
40  configure();
41  }
42 
44  delete m_pluginManager;
45  }
46 
48  m_authPath = p;
49  }
50 
51  void ConnectionPool::setAuthenticationSystem( int authSysCode ){
52  m_authSys = authSysCode;
53  }
54 
55  void ConnectionPool::setLogging( bool flag ){
56  m_loggingEnabled = flag;
57  }
58 
59  void ConnectionPool::setParameters( const edm::ParameterSet& connectionPset ){
60  setAuthenticationPath( connectionPset.getUntrackedParameter<std::string>("authenticationPath","") );
61  setAuthenticationSystem( connectionPset.getUntrackedParameter<int>("authenticationSystem",0) );
62  int messageLevel = connectionPset.getUntrackedParameter<int>("messageLevel",0);
63  coral::MsgLevel level = coral::Error;
64  switch (messageLevel) {
65  case 0 :
66  level = coral::Error;
67  break;
68  case 1:
69  level = coral::Warning;
70  break;
71  case 2:
72  level = coral::Info;
73  break;
74  case 3:
75  level = coral::Debug;
76  break;
77  default:
78  level = coral::Error;
79  }
80  setMessageVerbosity(level);
81  setLogging( connectionPset.getUntrackedParameter<bool>("logging",false) );
82  }
83 
85  return m_loggingEnabled;
86  }
87 
88  void ConnectionPool::configure( coral::IConnectionServiceConfiguration& coralConfig){
89 
90  coralConfig.disablePoolAutomaticCleanUp();
91  coralConfig.disableConnectionSharing();
92  // message streaming
93  coral::MessageStream::setMsgVerbosity( m_messageLevel );
94  std::string authServiceName("CORAL/Services/EnvironmentAuthenticationService");
96  // authentication
97  if( authPath.empty() ){
98  // first try to check the env...
99  const char* authEnv = ::getenv( cond::Auth::COND_AUTH_PATH );
100  if(authEnv){
101  authPath += authEnv;
102  }
103  }
104  int authSys = m_authSys;
105  // first attempt, look at the env...
106  const char* authSysEnv = ::getenv( cond::Auth::COND_AUTH_SYS );
107  if( authSysEnv ){
108  authSys = ::atoi( authSysEnv );
109  }
110  if( authSys !=CondDbKey && authSys != CoralXMLFile ){
111  // take the default
112  authSys = CondDbKey;
113  }
114  std::string servName("");
115  if( authSys == CondDbKey ){
116  if( authPath.empty() ){
117  const char* authEnv = ::getenv("HOME");
118  if(authEnv){
119  authPath += authEnv;
120  }
121  }
122  servName = "COND/Services/RelationalAuthenticationService";
123  } else if( authSys == CoralXMLFile ){
124  if( authPath.empty() ){
125  authPath = ".";
126  }
127  servName = "COND/Services/XMLAuthenticationService";
128  }
129  if( !authPath.empty() ){
130  authServiceName = servName;
131  coral::Context::instance().PropertyManager().property(cond::Auth::COND_AUTH_PATH_PROPERTY)->set(authPath);
132  coral::Context::instance().loadComponent( authServiceName, m_pluginManager );
133  }
134  coralConfig.setAuthenticationService( authServiceName );
135  }
136 
138  coral::ConnectionService connServ;
139  configure( connServ.configuration() );
140  }
141 
142  Session ConnectionPool::createSession( const std::string& connectionString, const std::string& transactionId, bool writeCapable ){
143  coral::ConnectionService connServ;
144  std::pair<std::string,std::string> fullConnectionPars = getRealConnectionString( connectionString, transactionId );
145  if( !fullConnectionPars.second.empty() )
146  for( auto tableName : m_refreshtablelist ) connServ.webCacheControl().refreshTable( fullConnectionPars.second, tableName );
147 
148  boost::shared_ptr<coral::ISessionProxy> coralSession( connServ.connect( fullConnectionPars.first,
149  writeCapable?coral::Update:coral::ReadOnly ) );
150  return Session( coralSession, connectionString );
151  }
152 
153  Session ConnectionPool::createSession( const std::string& connectionString, bool writeCapable ){
154  return createSession( connectionString, "", writeCapable );
155  }
156 
157  Session ConnectionPool::createReadOnlySession( const std::string& connectionString, const std::string& transactionId ){
158  return createSession( connectionString, transactionId );
159  }
162  }
163 
164 
165 
166  }
167 }
T getUntrackedParameter(std::string const &, T const &) const
static PFTauRenderPlugin instance
static const std::string COND_AUTH_PATH_PROPERTY
Definition: Auth.h:27
std::pair< std::string, std::string > getRealConnectionString(const std::string &initialConnection)
void setParameters(const edm::ParameterSet &connectionPset)
void setAuthenticationSystem(int authSysCode)
static const char * COND_AUTH_SYS
Definition: Auth.h:13
Session createSession(const std::string &connectionString, bool writeCapable=false)
void setMessageVerbosity(coral::MsgLevel level)
static const char * COND_AUTH_PATH
Definition: Auth.h:12
Session createReadOnlySession(const std::string &connectionString, const std::string &transactionId)
tuple level
Definition: testEve_cfg.py:34
volatile std::atomic< bool > shutdown_flag false
cond::CoralServiceManager * m_pluginManager
void setAuthenticationPath(const std::string &p)
const bool Debug
std::vector< std::string > m_refreshtablelist