ATLAS Offline Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
TrigConf::SessionMgr Class Reference

Manager of the database session. More...

#include <SessionMgr.h>

Inheritance diagram for TrigConf::SessionMgr:
Collaboration diagram for TrigConf::SessionMgr:

Public Member Functions

 SessionMgr ()
 constructor More...
 
virtual ~SessionMgr () override
 destructor More...
 
void closeSession ()
 close open sessions More...
 
coral::ISessionProxy & createSession ()
 instantiates the session More...
 
void setTypeConversionRules ()
 SQL -> C++ type conversion mapping for Oracle database to match MySQL. More...
 
void setConnectionString (const std::string &connStr)
 
void setUseFrontier (bool useFrontier)
 
void setRetrialPeriod (int retrialPeriod)
 
void setRetrialTimeout (int retrialTimeout)
 
void setConnectionTimeout (int connectionTimeout)
 
void setDbType (const std::string &s)
 
void setDbServer (const std::string &s)
 
void setDbName (const std::string &s)
 
void setDbUser (const std::string &s)
 
void setDbPassword (const std::string &s)
 
const std::string & connection () const
 
bool useFrontier () const
 
int retrialPeriod () const
 
int retrialTimeout () const
 
int connectionTimeout () const
 
const std::string & dbType () const
 
const std::string & dbServer () const
 
const std::string & dbName () const
 
const std::string & dbUser () const
 
const std::string & dbPassword () const
 
bool msgLvl (const MSGTC::Level lvl) const
 Test the output level. More...
 
MsgStreamTCmsg () const
 The standard message stream. More...
 
MsgStreamTCmsg (const MSGTC::Level lvl) const
 The standard message stream. More...
 

Private Member Functions

void buildConnectionString ()
 
void setCppTypeForSqlType (const std::string &cpp_type, const std::string &sql_type)
 SQL -> C++ type conversion interface to CORAL. More...
 

Private Attributes

coral::ISessionProxy * m_sessionproxy { nullptr }
 the coral database session More...
 
std::string m_connectionString { "" }
 connection string More...
 
std::string m_dbtype { "" }
 db type More...
 
std::string m_dbserver { "" }
 db server More...
 
std::string m_dbname { "" }
 db name More...
 
std::string m_user { "" }
 user name More...
 
std::string m_password { "" }
 password More...
 
bool m_useFrontier { false }
 uses frontier instead of oracle More...
 
int m_retrialPeriod {0}
 
int m_retrialTimeout {0}
 
int m_connectionTimeout {0}
 
ReplicaSorterm_replicaSorter { nullptr }
 
boost::thread_specific_ptr< MsgStreamTCm_msg_tls
 MsgStreamTC instance (a std::cout like with print-out levels) More...
 
std::string m_name
 

Detailed Description

Manager of the database session.

it uses CORAL to connect to the different DB technologies

Definition at line 29 of file SessionMgr.h.

Constructor & Destructor Documentation

◆ SessionMgr()

SessionMgr::SessionMgr ( )

constructor

Definition at line 37 of file SessionMgr.cxx.

37  :
38  TrigConfMessaging("SessionMgr")
39 {}

◆ ~SessionMgr()

SessionMgr::~SessionMgr ( )
overridevirtual

destructor

Definition at line 41 of file SessionMgr.cxx.

41  {
42  // Dtors are noexcept by default, so if closeSession() throws,
43  // std::terminate will be called. However, cppcheck warns here
44  // about the uncaught exception, so do the std::terminate call
45  // explicitly.
46  try {
47  closeSession();
48  } catch (...) {
49  std::terminate();
50  }
51  // never delete the m_replicaSorter, we will have to live with that
52  // one-time memory leak. The problem is the CORAL interface that
53  // does keeps a reference to the replicaSorter and keeps using it
54  // but doesn't clean it up. And if we delete it too early, then
55  // later access leads to a crash
56 }

Member Function Documentation

◆ buildConnectionString()

void TrigConf::SessionMgr::buildConnectionString ( )
private

Definition at line 76 of file SessionMgr.cxx.

76  {
77 
78  if(m_connectionString!="")
79  return;
80 
81  if(m_dbserver=="") {
83  } else if(m_dbtype == "dblookup") {
85  } else {
86  m_connectionString = m_dbtype + "://" + m_dbserver + "/" + m_dbname;
87  }
88 }

◆ closeSession()

void SessionMgr::closeSession ( )

close open sessions

Definition at line 59 of file SessionMgr.cxx.

59  {
60 
61  if(m_sessionproxy) {
62  try{
63  delete m_sessionproxy;
64  m_sessionproxy = nullptr;
65  TRG_MSG_INFO("Closing session " << m_connectionString);
66  }
67  catch ( coral::Exception& e ) {
68  TRG_MSG_WARNING("CORAL exception " << e.what());
69  throw;
70  }
71  }
72 
73 }

◆ connection()

const std::string& TrigConf::SessionMgr::connection ( ) const
inline

Definition at line 62 of file SessionMgr.h.

62 { return m_connectionString; }

◆ connectionTimeout()

int TrigConf::SessionMgr::connectionTimeout ( ) const
inline

Definition at line 66 of file SessionMgr.h.

66 { return m_connectionTimeout; }

◆ createSession()

coral::ISessionProxy & TrigConf::SessionMgr::createSession ( )

instantiates the session

Definition at line 92 of file SessionMgr.cxx.

92  {
93 
94  if( m_sessionproxy ) return *m_sessionproxy;
95 
96  coral::ConnectionService connSvc;
97  coral::IConnectionServiceConfiguration& csc = connSvc.configuration();
98  csc.setConnectionRetrialPeriod( m_retrialPeriod );
99  csc.setConnectionRetrialTimeOut( m_retrialTimeout );
100  csc.setConnectionTimeOut( m_connectionTimeout );
101 
102 
103  if(csc.replicaSortingAlgorithm() == nullptr) { // likely to be standalone, create our own
104  TRG_MSG_INFO("Create own ReplicaSortingAlgorithm");
106  csc.setReplicaSortingAlgorithm(*m_replicaSorter);
107  }
108 
110  TRG_MSG_INFO("Connecting to " << m_connectionString);
111  m_sessionproxy = connSvc.connect(m_connectionString, coral::AccessMode::ReadOnly);
112  TRG_MSG_INFO("Opening session " << m_connectionString << " with " << m_retrialPeriod << "/" << m_retrialTimeout << "/" << m_connectionTimeout);
113 
114  return *m_sessionproxy;
115 }

◆ dbName()

const std::string& TrigConf::SessionMgr::dbName ( ) const
inline

Definition at line 69 of file SessionMgr.h.

69 { return m_dbname; }

◆ dbPassword()

const std::string& TrigConf::SessionMgr::dbPassword ( ) const
inline

Definition at line 71 of file SessionMgr.h.

71 { return m_password; }

◆ dbServer()

const std::string& TrigConf::SessionMgr::dbServer ( ) const
inline

Definition at line 68 of file SessionMgr.h.

68 { return m_dbserver; }

◆ dbType()

const std::string& TrigConf::SessionMgr::dbType ( ) const
inline

Definition at line 67 of file SessionMgr.h.

67 { return m_dbtype; }

◆ dbUser()

const std::string& TrigConf::SessionMgr::dbUser ( ) const
inline

Definition at line 70 of file SessionMgr.h.

70 { return m_user; }

◆ msg() [1/2]

MsgStreamTC & TrigConf::TrigConfMessaging::msg ( ) const
inlineinherited

The standard message stream.

Returns a reference to the message stream May not be invoked before sysInitialize() has been invoked.

Definition at line 81 of file TrigConfMessaging.h.

82  {
83  MsgStreamTC* ms = m_msg_tls.get();
84  if (!ms) {
85  ms = new MsgStreamTC(m_name);
86  m_msg_tls.reset(ms);
87  }
88  return *ms;
89  }

◆ msg() [2/2]

MsgStreamTC & TrigConf::TrigConfMessaging::msg ( const MSGTC::Level  lvl) const
inlineinherited

The standard message stream.

Returns a reference to the default message stream May not be invoked before sysInitialize() has been invoked.

Definition at line 91 of file TrigConfMessaging.h.

92  {
93  return msg() << lvl;
94  }

◆ msgLvl()

bool TrigConf::TrigConfMessaging::msgLvl ( const MSGTC::Level  lvl) const
inlineinherited

Test the output level.

Parameters
lvlThe message level to test against
Returns
boolean Indicting if messages at given level will be printed
Return values
trueMessages at level "lvl" will be printed

Definition at line 70 of file TrigConfMessaging.h.

71  {
72  if (msg().level() <= lvl) {
73  msg() << lvl;
74  return true;
75  }
76  else {
77  return false;
78  }
79  }

◆ retrialPeriod()

int TrigConf::SessionMgr::retrialPeriod ( ) const
inline

Definition at line 64 of file SessionMgr.h.

64 { return m_retrialPeriod; }

◆ retrialTimeout()

int TrigConf::SessionMgr::retrialTimeout ( ) const
inline

Definition at line 65 of file SessionMgr.h.

65 { return m_retrialTimeout; }

◆ setConnectionString()

void TrigConf::SessionMgr::setConnectionString ( const std::string &  connStr)
inline

Definition at line 49 of file SessionMgr.h.

◆ setConnectionTimeout()

void TrigConf::SessionMgr::setConnectionTimeout ( int  connectionTimeout)
inline

Definition at line 53 of file SessionMgr.h.

◆ setCppTypeForSqlType()

void TrigConf::SessionMgr::setCppTypeForSqlType ( const std::string &  cpp_type,
const std::string &  sql_type 
)
private

SQL -> C++ type conversion interface to CORAL.

◆ setDbName()

void TrigConf::SessionMgr::setDbName ( const std::string &  s)

Definition at line 131 of file SessionMgr.cxx.

131  {
132  m_dbname = s;
133  m_connectionString = "";
134 }

◆ setDbPassword()

void TrigConf::SessionMgr::setDbPassword ( const std::string &  s)

Definition at line 143 of file SessionMgr.cxx.

143  {
144  m_password = s;
145  m_connectionString = "";
146 }

◆ setDbServer()

void TrigConf::SessionMgr::setDbServer ( const std::string &  s)

Definition at line 125 of file SessionMgr.cxx.

125  {
126  m_dbserver = s;
127  m_connectionString = "";
128 }

◆ setDbType()

void TrigConf::SessionMgr::setDbType ( const std::string &  s)

Definition at line 119 of file SessionMgr.cxx.

119  {
120  m_dbtype = boost::to_lower_copy(s);
121  m_connectionString = "";
122 }

◆ setDbUser()

void TrigConf::SessionMgr::setDbUser ( const std::string &  s)

Definition at line 137 of file SessionMgr.cxx.

137  {
138  m_user = s;
139  m_connectionString = "";
140 }

◆ setRetrialPeriod()

void TrigConf::SessionMgr::setRetrialPeriod ( int  retrialPeriod)
inline

Definition at line 51 of file SessionMgr.h.

◆ setRetrialTimeout()

void TrigConf::SessionMgr::setRetrialTimeout ( int  retrialTimeout)
inline

Definition at line 52 of file SessionMgr.h.

◆ setTypeConversionRules()

void TrigConf::SessionMgr::setTypeConversionRules ( )

SQL -> C++ type conversion mapping for Oracle database to match MySQL.

◆ setUseFrontier()

void TrigConf::SessionMgr::setUseFrontier ( bool  useFrontier)
inline

Definition at line 50 of file SessionMgr.h.

◆ useFrontier()

bool TrigConf::SessionMgr::useFrontier ( ) const
inline

Definition at line 63 of file SessionMgr.h.

63 { return m_useFrontier; }

Member Data Documentation

◆ m_connectionString

std::string TrigConf::SessionMgr::m_connectionString { "" }
private

connection string

Definition at line 83 of file SessionMgr.h.

◆ m_connectionTimeout

int TrigConf::SessionMgr::m_connectionTimeout {0}
private

Definition at line 92 of file SessionMgr.h.

◆ m_dbname

std::string TrigConf::SessionMgr::m_dbname { "" }
private

db name

Definition at line 86 of file SessionMgr.h.

◆ m_dbserver

std::string TrigConf::SessionMgr::m_dbserver { "" }
private

db server

Definition at line 85 of file SessionMgr.h.

◆ m_dbtype

std::string TrigConf::SessionMgr::m_dbtype { "" }
private

db type

Definition at line 84 of file SessionMgr.h.

◆ m_msg_tls

boost::thread_specific_ptr<MsgStreamTC> TrigConf::TrigConfMessaging::m_msg_tls
mutableprivateinherited

MsgStreamTC instance (a std::cout like with print-out levels)

Definition at line 66 of file TrigConfMessaging.h.

◆ m_name

std::string TrigConf::TrigConfMessaging::m_name
privateinherited

Definition at line 67 of file TrigConfMessaging.h.

◆ m_password

std::string TrigConf::SessionMgr::m_password { "" }
private

password

Definition at line 88 of file SessionMgr.h.

◆ m_replicaSorter

ReplicaSorter* TrigConf::SessionMgr::m_replicaSorter { nullptr }
private

Definition at line 94 of file SessionMgr.h.

◆ m_retrialPeriod

int TrigConf::SessionMgr::m_retrialPeriod {0}
private

Definition at line 90 of file SessionMgr.h.

◆ m_retrialTimeout

int TrigConf::SessionMgr::m_retrialTimeout {0}
private

Definition at line 91 of file SessionMgr.h.

◆ m_sessionproxy

coral::ISessionProxy* TrigConf::SessionMgr::m_sessionproxy { nullptr }
private

the coral database session

Definition at line 81 of file SessionMgr.h.

◆ m_useFrontier

bool TrigConf::SessionMgr::m_useFrontier { false }
private

uses frontier instead of oracle

Definition at line 89 of file SessionMgr.h.

◆ m_user

std::string TrigConf::SessionMgr::m_user { "" }
private

user name

Definition at line 87 of file SessionMgr.h.


The documentation for this class was generated from the following files:
TrigConf::SessionMgr::m_connectionString
std::string m_connectionString
connection string
Definition: SessionMgr.h:83
TrigConf::SessionMgr::m_connectionTimeout
int m_connectionTimeout
Definition: SessionMgr.h:92
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
TrigConf::SessionMgr::retrialTimeout
int retrialTimeout() const
Definition: SessionMgr.h:65
TrigConf::SessionMgr::m_password
std::string m_password
password
Definition: SessionMgr.h:88
TrigConf::SessionMgr::useFrontier
bool useFrontier() const
Definition: SessionMgr.h:63
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
TrigConf::SessionMgr::m_retrialTimeout
int m_retrialTimeout
Definition: SessionMgr.h:91
TrigConf::TrigConfMessaging::m_msg_tls
boost::thread_specific_ptr< MsgStreamTC > m_msg_tls
MsgStreamTC instance (a std::cout like with print-out levels)
Definition: TrigConfMessaging.h:66
TrigConf::SessionMgr::m_dbname
std::string m_dbname
db name
Definition: SessionMgr.h:86
TrigConf::SessionMgr::m_dbserver
std::string m_dbserver
db server
Definition: SessionMgr.h:85
TrigConf::ReplicaSorter
Definition: Trigger/TrigConfiguration/TrigConfStorage/src/ReplicaSorter.h:14
TrigConf::SessionMgr::m_sessionproxy
coral::ISessionProxy * m_sessionproxy
the coral database session
Definition: SessionMgr.h:81
CheckTagAssociation.connStr
connStr
Definition: CheckTagAssociation.py:85
TrigConf::SessionMgr::m_replicaSorter
ReplicaSorter * m_replicaSorter
Definition: SessionMgr.h:94
python.SystemOfUnits.ms
int ms
Definition: SystemOfUnits.py:132
python.iconfTool.models.loaders.level
level
Definition: loaders.py:20
TrigConf::SessionMgr::m_useFrontier
bool m_useFrontier
uses frontier instead of oracle
Definition: SessionMgr.h:89
TrigConf::TrigConfMessaging::m_name
std::string m_name
Definition: TrigConfMessaging.h:67
TrigConf::TrigConfMessaging::msg
MsgStreamTC & msg() const
The standard message stream.
Definition: TrigConfMessaging.h:81
TrigConf::TrigConfMessaging::TrigConfMessaging
TrigConfMessaging()=delete
TrigConf::SessionMgr::m_retrialPeriod
int m_retrialPeriod
Definition: SessionMgr.h:90
TrigConf::SessionMgr::m_user
std::string m_user
user name
Definition: SessionMgr.h:87
TrigConf::SessionMgr::retrialPeriod
int retrialPeriod() const
Definition: SessionMgr.h:64
TRG_MSG_INFO
#define TRG_MSG_INFO(x)
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStreamMacros.h:27
TRG_MSG_WARNING
#define TRG_MSG_WARNING(x)
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStreamMacros.h:28
TrigConf::SessionMgr::m_dbtype
std::string m_dbtype
db type
Definition: SessionMgr.h:84
TrigConf::SessionMgr::closeSession
void closeSession()
close open sessions
Definition: SessionMgr.cxx:59
TrigConf::SessionMgr::buildConnectionString
void buildConnectionString()
Definition: SessionMgr.cxx:76
TrigConf::SessionMgr::connectionTimeout
int connectionTimeout() const
Definition: SessionMgr.h:66