8 #include "CoralBase/Exception.h"
9 #include "CoralBase/Blob.h"
11 #include "RelationalAccess/ConnectionService.h"
12 #include "RelationalAccess/IConnectionServiceConfiguration.h"
13 #include "RelationalAccess/ISessionProxy.h"
14 #include "RelationalAccess/ISchema.h"
16 #include "boost/property_tree/ptree.hpp"
23 m_connection(connection)
30 bool startswith(
const std::string&
str,
const std::string& sub) {
31 if(
str.size()<sub.size())
33 return (
str.compare(0,sub.size(),sub) == 0);
40 static const std::string versionTagPrefix(
"Trigger-Run3-Schema-v");
43 if(! session->nominalSchema().existsTable(
"TRIGGER_SCHEMA") ) {
44 throw std::runtime_error(
"Trigger schema has no schema version table" );
56 throw std::runtime_error(
"Trigger schema has schema version table but it is empty" );
60 std::string versionTag =
row[
"TS_TAG"].data<std::string>();
61 if( ! startswith(versionTag, versionTagPrefix)) {
62 throw std::runtime_error(
"Tag format error: Trigger schema version tag " + versionTag +
"does not start with " + versionTagPrefix);
65 std::string vstr = versionTag.substr(versionTagPrefix.size());
66 size_t schemaVersion{0};
68 schemaVersion = std::stoi(vstr);
70 catch (
const std::invalid_argument& ia) {
71 TRG_MSG_ERROR(
"Invalid argument when interpreting the version part " << vstr <<
" of schema tag " << versionTag <<
". " << ia.what());
75 TRG_MSG_INFO(
"TriggerDB schema version: " << schemaVersion);
87 outFile.write(
static_cast<const char*
> (
data.startingAddress()),
data.size() );
93 std::unique_ptr<coral::ISessionProxy>
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 );
112 auto proxy = std::unique_ptr<coral::ISessionProxy>( connSvc.connect(m_connection, coral::AccessMode::ReadOnly) );
114 TRG_MSG_INFO(
"Opened session " << m_connection <<
" with retrialPeriod/retrialTimeout/connectionTimeout: "
115 << m_retrialPeriod <<
"/" << m_retrialTimeout <<
"/" << m_connectionTimeout);
123 const std::map<size_t, TrigConf::QueryDefinition> & queries)
const
126 size_t maxDefVersion = 0;
127 for(
auto &
entry : queries) {
128 size_t vkey =
entry.first;
129 if(vkey>maxDefVersion and vkey<=schemaVersion) {
130 maxDefVersion = vkey;
134 if( maxDefVersion==0 ) {
135 TRG_MSG_ERROR(
"No query for schema version " << schemaVersion <<
" defined" );
138 return queries.at(maxDefVersion);