ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Trigger
TrigConfiguration
TrigConfIO
src
TrigDBHelper.cxx
Go to the documentation of this file.
1
// Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
2
3
4
#include "
./TrigDBHelper.h
"
5
6
#include "
TrigConfIO/Exceptions.h
"
7
8
#include "RelationalAccess/ISchema.h"
9
#include <iostream>
10
#include <format>
11
12
std::unique_ptr< coral::IQuery >
13
TrigConf::QueryDefinition::createQuery
( coral::ISessionProxy * session )
14
{
15
16
std::unique_ptr< coral::IQuery >
query
( session->nominalSchema().newQuery() );
17
18
// set tables
19
for
(
auto
& table :
m_tables
) {
20
query
->addToTableList( table.first, table.second );
21
}
22
23
// ensure that all the requested variables are bound
24
for
(
auto
& bindVar :
m_bindList
) {
25
const
std::string & fieldName = bindVar.specification().name();
26
if
(
m_bound
.find( fieldName ) ==
m_bound
.end() ) {
27
throw
std::runtime_error(
"Column "
+ fieldName +
" has been bound, but not set to a value"
);
28
}
29
}
30
31
// condition
32
query
->setCondition(
m_condition
,
m_bindList
);
33
34
// output
35
query
->defineOutput(
m_attList
);
36
for
(
const
coral::Attribute & attr :
m_attList
) {
37
query
->addToOutputList(attr.specification().name());
38
}
39
40
return
query
;
41
}
42
43
void
44
TrigConf::QueryDefinition::addToTableList
(
const
std::string & table,
const
std::string & table_short)
45
{
46
m_tables
.emplace_back(table, table_short);
47
}
48
49
void
50
TrigConf::QueryDefinition::extendCondition
(
const
std::string & condext) {
51
if
(
m_condition
.size()>0 && condext.size()>0 &&
m_condition
.back() !=
' '
&& condext[0] !=
' '
) {
52
m_condition
+=
" "
;
53
}
54
m_condition
+= condext;
55
}
56
57
void
58
TrigConf::blobToPtree
(
const
coral::Blob & blob, boost::property_tree::ptree & pt ) {
59
boost::iostreams::stream<boost::iostreams::array_source> stream(
static_cast<
const
char
*
>
( blob.startingAddress()),
60
blob.size());
61
boost::property_tree::read_json(stream, pt);
62
}
63
64
void
65
TrigConf::stringToPtree
(
const
std::string & json_string, boost::property_tree::ptree & pt ) {
66
boost::iostreams::array_source source(json_string.data(), json_string.size());
67
boost::iostreams::stream<boost::iostreams::array_source> stream(source);
68
boost::property_tree::read_json(stream, pt);
69
}
70
71
void
72
TrigConf::writeRawFile
(
const
coral::Blob & data,
const
std::string & outFileName)
73
{
74
try
{
75
std::ofstream outFile(outFileName, std::ofstream::binary);
76
if
(!outFile) {
77
throw
FileWritingException
(std::format(
"Failed to open file {} for writing"
, outFileName));
78
}
79
outFile.write(
static_cast<
const
char
*
>
( data.startingAddress()), data.size() );
80
if
(!outFile) {
81
throw
FileWritingException
(
"Failed to write data to file "
+ outFileName);
82
}
83
outFile.close();
84
}
catch
(
const
std::exception& e) {
85
throw
FileWritingException
(std::format(
"Exception while writing file {} : {}"
, outFileName, e.what()));
86
}
87
}
88
89
void
90
TrigConf::writeRawFile
(
const
std::string & data,
const
std::string & outFileName)
91
{
92
try
{
93
std::ofstream outFile(outFileName, std::ofstream::binary);
94
if
(!outFile) {
95
throw
FileWritingException
(std::format(
"Failed to open file {} for writing"
, outFileName));
96
}
97
outFile.write(data.data(), data.size());
98
if
(!outFile) {
99
throw
FileWritingException
(
"Failed to write data to file "
+ outFileName);
100
}
101
outFile.close();
102
}
catch
(
const
std::exception& e) {
103
throw
FileWritingException
(std::format(
"Exception while writing file {} : {}"
, outFileName, e.what()));
104
}
105
}
106
107
TrigDBHelper.h
Exceptions.h
TrigConf::FileWritingException
Definition
Trigger/TrigConfiguration/TrigConfIO/TrigConfIO/Exceptions.h:68
TrigConf::QueryDefinition::m_tables
std::vector< std::pair< std::string, std::string > > m_tables
Definition
TrigDBHelper.h:58
TrigConf::QueryDefinition::createQuery
std::unique_ptr< coral::IQuery > createQuery(coral::ISessionProxy *session)
Definition
TrigDBHelper.cxx:13
TrigConf::QueryDefinition::m_bindList
coral::AttributeList m_bindList
Definition
TrigDBHelper.h:61
TrigConf::QueryDefinition::extendCondition
void extendCondition(const std::string &condext)
Definition
TrigDBHelper.cxx:50
TrigConf::QueryDefinition::m_condition
std::string m_condition
Definition
TrigDBHelper.h:59
TrigConf::QueryDefinition::m_bound
std::set< std::string > m_bound
Definition
TrigDBHelper.h:63
TrigConf::QueryDefinition::addToTableList
void addToTableList(const std::string &table, const std::string &table_short="")
Definition
TrigDBHelper.cxx:44
TrigConf::QueryDefinition::m_attList
coral::AttributeList m_attList
Definition
TrigDBHelper.h:60
TrigConf::stringToPtree
void stringToPtree(const std::string &json_string, boost::property_tree::ptree &pt)
Definition
TrigDBHelper.cxx:65
TrigConf::writeRawFile
void writeRawFile(const coral::Blob &data, const std::string &outFileName)
write coral data blob to file
Definition
TrigDBHelper.cxx:72
TrigConf::blobToPtree
void blobToPtree(const coral::Blob &blob, boost::property_tree::ptree &pt)
Definition
TrigDBHelper.cxx:58
query
Definition
query.py:1
Generated on
for ATLAS Offline Software by
1.17.0