ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Trigger
TrigConfiguration
TrigConfStorage
src
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
5
#include "
TrigConfStorage/SessionMgr.h
"
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 <ranges>
28
#include <cctype>
29
#include <iostream>
30
#include <stdlib.h>
31
#include <string.h>
32
33
34
using namespace
std
;
35
using namespace
TrigConf
;
36
37
SessionMgr::SessionMgr
() :
38
TrigConfMessaging
(
"SessionMgr"
)
39
{}
40
41
SessionMgr::~SessionMgr
() {
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
}
57
58
void
59
SessionMgr::closeSession
() {
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
75
void
76
TrigConf::SessionMgr::buildConnectionString
() {
77
78
if
(
m_connectionString
!=
""
)
79
return
;
80
81
if
(
m_dbserver
==
""
) {
82
m_connectionString
=
m_dbname
;
83
}
else
if
(
m_dbtype
==
"dblookup"
) {
84
m_connectionString
=
m_dbserver
;
85
}
else
{
86
m_connectionString
=
m_dbtype
+
"://"
+
m_dbserver
+
"/"
+
m_dbname
;
87
}
88
}
89
90
91
coral::ISessionProxy&
92
TrigConf::SessionMgr::createSession
() {
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"
);
105
m_replicaSorter
=
new
TrigConf::ReplicaSorter
();
106
csc.setReplicaSortingAlgorithm(*
m_replicaSorter
);
107
}
108
109
buildConnectionString
();
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
118
void
119
TrigConf::SessionMgr::setDbType
(
const
std::string & s) {
120
m_dbtype
= s;
121
std::ranges::transform(
m_dbtype
,
m_dbtype
.begin(), [](
unsigned
char
c) { return std::tolower(c); });
122
m_connectionString
=
""
;
123
}
124
125
void
126
TrigConf::SessionMgr::setDbServer
(
const
std::string & s) {
127
m_dbserver
= s;
128
m_connectionString
=
""
;
129
}
130
131
void
132
TrigConf::SessionMgr::setDbName
(
const
std::string & s) {
133
m_dbname
= s;
134
m_connectionString
=
""
;
135
}
136
137
void
138
TrigConf::SessionMgr::setDbUser
(
const
std::string & s) {
139
m_user
= s;
140
m_connectionString
=
""
;
141
}
142
143
void
144
TrigConf::SessionMgr::setDbPassword
(
const
std::string & s) {
145
m_password
= s;
146
m_connectionString
=
""
;
147
}
148
SessionMgr.h
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
ReplicaSorter.h
TrigConf::ReplicaSorter
Definition
Trigger/TrigConfiguration/TrigConfStorage/src/ReplicaSorter.h:14
TrigConf::SessionMgr::m_dbtype
std::string m_dbtype
db type
Definition
SessionMgr.h:84
TrigConf::SessionMgr::createSession
coral::ISessionProxy & createSession()
instantiates the session
Definition
SessionMgr.cxx:92
TrigConf::SessionMgr::m_dbname
std::string m_dbname
db name
Definition
SessionMgr.h:86
TrigConf::SessionMgr::closeSession
void closeSession()
close open sessions
Definition
SessionMgr.cxx:59
TrigConf::SessionMgr::setDbPassword
void setDbPassword(const std::string &s)
Definition
SessionMgr.cxx:144
TrigConf::SessionMgr::setDbName
void setDbName(const std::string &s)
Definition
SessionMgr.cxx:132
TrigConf::SessionMgr::m_retrialTimeout
int m_retrialTimeout
Definition
SessionMgr.h:91
TrigConf::SessionMgr::m_replicaSorter
ReplicaSorter * m_replicaSorter
Definition
SessionMgr.h:94
TrigConf::SessionMgr::m_dbserver
std::string m_dbserver
db server
Definition
SessionMgr.h:85
TrigConf::SessionMgr::m_sessionproxy
coral::ISessionProxy * m_sessionproxy
the coral database session
Definition
SessionMgr.h:81
TrigConf::SessionMgr::m_password
std::string m_password
password
Definition
SessionMgr.h:88
TrigConf::SessionMgr::buildConnectionString
void buildConnectionString()
Definition
SessionMgr.cxx:76
TrigConf::SessionMgr::m_connectionTimeout
int m_connectionTimeout
Definition
SessionMgr.h:92
TrigConf::SessionMgr::m_connectionString
std::string m_connectionString
connection string
Definition
SessionMgr.h:83
TrigConf::SessionMgr::m_user
std::string m_user
user name
Definition
SessionMgr.h:87
TrigConf::SessionMgr::setDbType
void setDbType(const std::string &s)
Definition
SessionMgr.cxx:119
TrigConf::SessionMgr::setDbServer
void setDbServer(const std::string &s)
Definition
SessionMgr.cxx:126
TrigConf::SessionMgr::m_retrialPeriod
int m_retrialPeriod
Definition
SessionMgr.h:90
TrigConf::SessionMgr::~SessionMgr
virtual ~SessionMgr() override
destructor
Definition
SessionMgr.cxx:41
TrigConf::SessionMgr::setDbUser
void setDbUser(const std::string &s)
Definition
SessionMgr.cxx:138
TrigConf::SessionMgr::SessionMgr
SessionMgr()
constructor
Definition
SessionMgr.cxx:37
TrigConf::TrigConfMessaging::TrigConfMessaging
TrigConfMessaging(const std::string &name)
Constructor with parameters.
Definition
TrigConfMessaging.h:34
TrigConf
Forward iterator to traverse the main components of the trigger configuration.
Definition
IDPerfMonZmumu.h:57
std
STL namespace.
Generated on
for ATLAS Offline Software by
1.17.0