ATLAS Offline Software
Loading...
Searching...
No Matches
SessionMgr.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7#include "RelationalAccess/AccessMode.h"
8#include "RelationalAccess/IDatabaseServiceDescription.h"
9#include "RelationalAccess/IDatabaseServiceSet.h"
10#include "RelationalAccess/ILookupService.h"
11#include "RelationalAccess/IAuthenticationService.h"
12#include "RelationalAccess/IAuthenticationCredentials.h"
13#include "RelationalAccess/ITypeConverter.h"
14#include "RelationalAccess/IRelationalDomain.h"
15#include "RelationalAccess/ConnectionService.h"
16#include "RelationalAccess/IConnectionService.h"
17#include "RelationalAccess/IConnectionServiceConfiguration.h"
18
19#include "RelationalAccess/ISessionProxy.h"
20
21
22#include "./ReplicaSorter.h"
23
24#include "CoralKernel/Context.h"
25#include "CoralBase/Exception.h"
26
27#include <boost/algorithm/string/case_conv.hpp>
28
29#include <iostream>
30#include <stdlib.h>
31#include <string.h>
32
33
34using namespace std;
35using namespace TrigConf;
36
38 TrigConfMessaging("SessionMgr")
39{}
40
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 {
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}
57
58void
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}
74
75void
77
78 if(m_connectionString!="")
79 return;
80
81 if(m_dbserver=="") {
83 } else if(m_dbtype == "dblookup") {
85 } else {
87 }
88}
89
90
91coral::ISessionProxy&
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}
116
117
118void
119TrigConf::SessionMgr::setDbType(const std::string & s) {
120 m_dbtype = boost::to_lower_copy(s);
122}
123
124void
125TrigConf::SessionMgr::setDbServer(const std::string & s) {
126 m_dbserver = s;
128}
129
130void
131TrigConf::SessionMgr::setDbName(const std::string & s) {
132 m_dbname = s;
134}
135
136void
137TrigConf::SessionMgr::setDbUser(const std::string & s) {
138 m_user = s;
140}
141
142void
144 m_password = s;
146}
147
std::string m_dbtype
db type
Definition SessionMgr.h:84
coral::ISessionProxy & createSession()
instantiates the session
std::string m_dbname
db name
Definition SessionMgr.h:86
void closeSession()
close open sessions
void setDbPassword(const std::string &s)
void setDbName(const std::string &s)
ReplicaSorter * m_replicaSorter
Definition SessionMgr.h:94
std::string m_dbserver
db server
Definition SessionMgr.h:85
coral::ISessionProxy * m_sessionproxy
the coral database session
Definition SessionMgr.h:81
std::string m_password
password
Definition SessionMgr.h:88
std::string m_connectionString
connection string
Definition SessionMgr.h:83
std::string m_user
user name
Definition SessionMgr.h:87
void setDbType(const std::string &s)
void setDbServer(const std::string &s)
virtual ~SessionMgr() override
destructor
void setDbUser(const std::string &s)
SessionMgr()
constructor
TrigConfMessaging(const std::string &name)
Constructor with parameters.
Forward iterator to traverse the main components of the trigger configuration.
Definition Config.h:22
STL namespace.