ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Trigger
TrigConfiguration
TrigConfStorage
src
DBLoader.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
./DBHelper.h
"
6
#include "
TrigConfStorage/DBLoader.h
"
7
8
#include "RelationalAccess/ITransaction.h"
9
#include "RelationalAccess/ICursor.h"
10
#include "RelationalAccess/IQuery.h"
11
#include "RelationalAccess/ITable.h"
12
#include "RelationalAccess/ISchema.h"
13
#include "RelationalAccess/SchemaException.h"
14
15
#include <CoralBase/Attribute.h>
16
#include <CoralBase/AttributeList.h>
17
18
#include <stdexcept>
19
#include <memory>
20
21
using namespace
std
;
22
using namespace
TrigConf
;
23
24
DBLoader::DBLoader
(
const
std::string&
name
,
StorageMgr
& sm, coral::ISessionProxy& session ) :
25
TrigConfMessaging
(
name
),
26
m_storageMgr
( sm ),
27
m_session
( session )
28
{}
29
30
31
DBLoader::DBLoader
(
StorageMgr
& sm, coral::ISessionProxy& session ) :
32
DBLoader
(
"DBLoader"
, sm, session)
33
{}
34
35
36
void
TrigConf::DBLoader::startSession
()
37
{
38
if
( !
m_session
.transaction().isActive() ) {
39
bool
readOnly =
true
;
40
m_session
.transaction().start(readOnly);
41
m_sessionOwner
=
true
;
42
}
43
}
44
45
void
TrigConf::DBLoader::commitSession
()
46
{
47
if
(
m_session
.transaction().isActive() &&
m_sessionOwner
) {
48
m_session
.transaction().commit();
49
}
50
}
51
52
53
bool
54
DBLoader::isRun2
() {
55
const
static
unsigned
int
run
= std::get<1>(
loadSchemaVersion
());
56
return
run
== 2;
57
}
58
59
void
60
DBLoader::setLevel
(
MSGTC::Level
lvl) {
61
msg
().
setLevel
(lvl);
62
63
switch
(lvl) {
64
case
MSGTC::ALWAYS
:
m_verbose
= 5;
break
;
65
case
MSGTC::VERBOSE
:
m_verbose
= 4;
break
;
66
case
MSGTC::DEBUG
:
m_verbose
= 3;
break
;
67
case
MSGTC::INFO
:
m_verbose
= 2;
break
;
68
case
MSGTC::WARNING
:
69
case
MSGTC::ERROR
:
70
case
MSGTC::FATAL
:
m_verbose
= 0;
break
;
71
default
:
m_verbose
= 0;
72
}
73
}
74
75
unsigned
int
76
DBLoader::triggerDBSchemaVersion
() {
77
return
std::get<0>(
loadSchemaVersion
());
78
}
79
80
std::tuple<unsigned int,unsigned int>
81
DBLoader::loadSchemaVersion
()
const
82
{
83
const
static
auto
versions = [&]() -> std::tuple<unsigned int,unsigned int> {
84
bool
mySession =
false
;
85
if
( !
m_session
.transaction().isActive() ) {
86
m_session
.transaction().start(
true
);
87
mySession =
true
;
88
}
89
90
std::unique_ptr< coral::IQuery > q(
m_session
.nominalSchema().tableHandle(
"TRIGGER_SCHEMA"
).newQuery() );
91
q->setRowCacheSize( 1 );
92
93
//Output data and types
94
coral::AttributeList attList;
95
attList.extend<
int
>(
"TS_ID"
);
96
q->defineOutput(attList);
97
q->addToOutputList(
"TS_ID"
);
98
99
q->addToOrderList(
"TS_ID desc"
);
100
coral::ICursor& cursor = q->execute();
101
102
if
( ! cursor.next() ) {
103
TRG_MSG_ERROR
(
"Table TRIGGER_SCHEMA is not filled"
);
104
if
( mySession )
m_session
.transaction().commit();
105
throw
std::runtime_error(
"DBLoader::loadSchemaVersion() >> Table TRIGGER_SCHEMA is not filled"
);
106
}
107
108
const
coral::AttributeList& row = cursor.currentRow();
109
const
unsigned
int
triggerDBSchemaVersion
= row[
"TS_ID"
].data<
int
>();
110
111
TRG_MSG_INFO
(
"TriggerDB schema version: "
<<
triggerDBSchemaVersion
);
112
113
const
unsigned
int
run
=
m_session
.nominalSchema().existsTable(
"ACTIVE_MASTERS"
) ? 2 : 1;
114
115
TRG_MSG_INFO
(
"Database has Run "
<<
run
<<
" schema"
);
116
TRG_MSG_INFO
(
"Total number of tables : "
<<
m_session
.nominalSchema().listTables().size());
117
118
//commitSession();
119
if
( mySession )
m_session
.transaction().commit();
120
121
return
{
triggerDBSchemaVersion
,
run
};
122
}();
123
124
return
versions;
125
}
126
127
bool
128
TrigConf::DBLoader::loadL1MasterKey
(
int
smk,
int
& Lvl1MasterKey) {
129
try
{
130
startSession
();
131
132
unique_ptr< coral::IQuery > q(
m_session
.nominalSchema().tableHandle(
"SUPER_MASTER_TABLE"
).newQuery() );
133
q->setRowCacheSize( 5 );
134
135
//Bind list
136
coral::AttributeList bindings;
137
bindings.extend<
int
>(
"smtid"
);
138
bindings[0].data<
int
>() = smk;
139
q->setCondition(
"SMT_ID = :smtid"
, bindings );
140
141
//Output data and types
142
coral::AttributeList attList;
143
attList.extend<
int
>(
"SMT_L1_MASTER_TABLE_ID"
);
144
fillQuery
(q.get(), attList);
145
146
coral::ICursor& cursor = q->execute();
147
if
( ! cursor.next() ) {
148
msg
() <<
"DBLoader: No such SuperMaster key exists "
<< smk << endl;
149
throw
runtime_error(
"DBLoader: SuperMasterKey not available"
);
150
}
151
152
const
coral::AttributeList& row = cursor.currentRow();
153
Lvl1MasterKey = row[
"SMT_L1_MASTER_TABLE_ID"
].data<
int
>();
154
}
155
catch
(
const
std::exception& e ) {
156
commitSession
();
157
msg
() <<
"DBLoader: C++ exception: "
<< e.what() << std::endl;
158
throw
;
159
}
160
commitSession
();
161
return
true
;
162
}
163
164
165
166
bool
167
TrigConf::DBLoader::loadL1MenuKey
(
int
SuperMasterKey,
int
& Lvl1MenuKey) {
168
try
{
169
170
int
l1Master = 0;
171
loadL1MasterKey
(SuperMasterKey, l1Master);
172
173
startSession
();
174
175
unique_ptr< coral::IQuery > q(
m_session
.nominalSchema().tableHandle(
"L1_MASTER_TABLE"
).newQuery() );
176
q->setRowCacheSize( 5 );
177
178
//Bind list
179
coral::AttributeList bindings;
180
bindings.extend<
int
>(
"l1mtid"
);
181
bindings[0].data<
int
>() = l1Master;
182
q->setCondition(
"L1MT_ID = :l1mtid"
, bindings );
183
184
//Output data and types
185
coral::AttributeList attList;
186
attList.extend<
int
>(
"L1MT_TRIGGER_MENU_ID"
);
187
q->defineOutput(attList);
188
q->addToOutputList(
"L1MT_TRIGGER_MENU_ID"
);
189
190
coral::ICursor& cursor = q->execute();
191
if
( ! cursor.next() ) {
192
msg
() <<
"DBLoader >> No such L1 Master key exists "
<< l1Master << std::endl;
193
throw
std::runtime_error(
"DBLoader >> L1MasterKey not available"
);
194
}
195
196
const
coral::AttributeList& row = cursor.currentRow();
197
Lvl1MenuKey = row[
"L1MT_TRIGGER_MENU_ID"
].data<
int
>();
198
199
commitSession
();
200
201
}
202
catch
(
const
std::exception& e ) {
203
msg
() <<
"DBLoader >> Standard C++ exception: "
<< e.what() << std::endl;
204
m_session
.transaction().rollback();
205
throw
;
206
}
207
return
true
;
208
}
DBHelper.h
DBLoader.h
TRG_MSG_INFO
#define TRG_MSG_INFO(x)
Definition
Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStreamMacros.h:27
TRG_MSG_ERROR
#define TRG_MSG_ERROR(x)
Definition
Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStreamMacros.h:29
TrigConf::DBLoader::loadL1MasterKey
bool loadL1MasterKey(int SuperMasterKey, int &Lvl1MasterKey)
get l1 master from super master
Definition
DBLoader.cxx:128
TrigConf::DBLoader::m_storageMgr
StorageMgr & m_storageMgr
reference to the storage manager
Definition
DBLoader.h:66
TrigConf::DBLoader::DBLoader
DBLoader(StorageMgr &sm, coral::ISessionProxy &session)
constructor
Definition
DBLoader.cxx:31
TrigConf::DBLoader::m_verbose
int m_verbose
Definition
DBLoader.h:63
TrigConf::DBLoader::commitSession
void commitSession()
commit session if not already done
Definition
DBLoader.cxx:45
TrigConf::DBLoader::m_sessionOwner
bool m_sessionOwner
remember if the loader started the session in the first place
Definition
DBLoader.h:68
TrigConf::DBLoader::setLevel
virtual void setLevel(MSGTC::Level lvl) override
Load the configuration data from the configuration source.
Definition
DBLoader.cxx:60
TrigConf::DBLoader::m_session
coral::ISessionProxy & m_session
CORAL interface to database session.
Definition
DBLoader.h:67
TrigConf::DBLoader::triggerDBSchemaVersion
unsigned int triggerDBSchemaVersion()
Definition
DBLoader.cxx:76
TrigConf::DBLoader::loadSchemaVersion
std::tuple< unsigned int, unsigned int > loadSchemaVersion() const
get DB schema version and run number
Definition
DBLoader.cxx:81
TrigConf::DBLoader::isRun2
bool isRun2()
Definition
DBLoader.cxx:54
TrigConf::DBLoader::startSession
void startSession()
start session if not already active
Definition
DBLoader.cxx:36
TrigConf::DBLoader::loadL1MenuKey
bool loadL1MenuKey(int SuperMasterKey, int &Lvl1MenuKey)
get l1 menu id from super master
Definition
DBLoader.cxx:167
TrigConf::MsgStreamTC::setLevel
void setLevel(MSGTC::Level lvl)
Set message level of stream.
Definition
Trigger/TrigConfiguration/TrigConfBase/Root/MsgStream.cxx:52
TrigConf::StorageMgr
Database Storage Manager, controls the database session and the different loader classes for DB acces...
Definition
StorageMgr.h:23
TrigConf::TrigConfMessaging::msg
MsgStreamTC & msg() const
The standard message stream.
Definition
TrigConfMessaging.h:86
TrigConf::TrigConfMessaging::TrigConfMessaging
TrigConfMessaging(const std::string &name)
Constructor with parameters.
Definition
TrigConfMessaging.h:34
TrigConf::MSGTC::Level
Level
Definition
Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:21
TrigConf::MSGTC::DEBUG
@ DEBUG
Definition
Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:24
TrigConf::MSGTC::ERROR
@ ERROR
Definition
Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:27
TrigConf::MSGTC::VERBOSE
@ VERBOSE
Definition
Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:23
TrigConf::MSGTC::FATAL
@ FATAL
Definition
Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:28
TrigConf::MSGTC::WARNING
@ WARNING
Definition
Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:26
TrigConf::MSGTC::INFO
@ INFO
Definition
Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:25
TrigConf::MSGTC::ALWAYS
@ ALWAYS
Definition
Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:29
TrigConf
Forward iterator to traverse the main components of the trigger configuration.
Definition
Config.h:22
TrigConf::fillQuery
void fillQuery(coral::IQuery *q, coral::AttributeList &attList)
Definition
DBHelper.cxx:13
std
STL namespace.
TrigConf::name
Definition
HLTChainList.h:35
msg
MsgStream & msg
Definition
testRead.cxx:32
run
int run(int argc, char *argv[])
Definition
ttree2hdf5.cxx:28
Generated on
for ATLAS Offline Software by
1.17.0