ATLAS Offline Software
Loading...
Searching...
No Matches
TrigConf::TrigDBHLTPrescalesSetLoader Class Reference

Loader of trigger configurations from Json files. More...

#include <TrigDBHLTPrescalesSetLoader.h>

Inheritance diagram for TrigConf::TrigDBHLTPrescalesSetLoader:
Collaboration diagram for TrigConf::TrigDBHLTPrescalesSetLoader:

Public Member Functions

 TrigDBHLTPrescalesSetLoader (const std::string &connection)
 Constructor.
virtual ~TrigDBHLTPrescalesSetLoader () override
 Destructor - cannot be defined here because QueryDefinition is an incomplete type.
bool loadHLTPrescales (unsigned int hltpsk, HLTPrescalesSet &hltpss, const std::string &outFileName="") const
 Load content from the Trigger DB into an HLTPrescalesSet for a given HLTPrescaleKey (HLTPSK)
void setCrestConnection (const std::string &server, const std::string &version="")
 declare CREST as the source of the configuration An empty crest server makes it use Oracle
void setCrestTrigDB (const std::string &crestTrigDB)
 set trigger db for the crest connection
size_t schemaVersion (coral::ISessionProxy *session) const
 access to TriggerDB schema version
void setLevel (MSGTC::Level lvl)
MSGTC::Level outputLevel () const
bool msgLvl (const MSGTC::Level lvl) const
 Test the output level.
MsgStreamTCmsg () const
 The standard message stream.
MsgStreamTCmsg (const MSGTC::Level lvl) const
 The standard message stream.
const std::string & getName () const
 name accessor

Protected Member Functions

bool useCrest () const
std::string getTrigDataCrest (const std::string &type, int key) const
 Get trigger configuration from the TriggerDB through Crest.
std::unique_ptr< coral::ISessionProxy > createDBSession () const
 create (if needed) DB session and return the session proxy
QueryDefinition getQueryDefinition (size_t schemaVersion, const std::map< size_t, QueryDefinition > &queries) const
 return query for given schemaVersion from possible queries
void loadFromCrest (unsigned int key, boost::property_tree::ptree &pt, const std::string &outFileName, const std::string &description, const std::string &query_type) const
void loadFromOracle (unsigned int key, boost::property_tree::ptree &pt, const std::string &outFileName, const std::string &description, const std::map< size_t, QueryDefinition > &queries) const

Private Attributes

std::map< size_t, QueryDefinitionm_queries
bool m_useCrest {false}
std::string m_connection {""}
std::string m_crestServer {""}
std::string m_crestVersion {""}
std::string m_crestTrigDb {""}
int m_retrialPeriod {0}
int m_retrialTimeout {0}
int m_connectionTimeout {0}
boost::thread_specific_ptr< MsgStreamTCm_msg_tls
 MsgStreamTC instance (a std::cout like with print-out levels)
std::string m_name

Detailed Description

Loader of trigger configurations from Json files.

Definition at line 23 of file TrigDBHLTPrescalesSetLoader.h.

Constructor & Destructor Documentation

◆ TrigDBHLTPrescalesSetLoader()

TrigConf::TrigDBHLTPrescalesSetLoader::TrigDBHLTPrescalesSetLoader ( const std::string & connection)

Constructor.

Definition at line 6 of file TrigDBHLTPrescalesSetLoader.cxx.

6 :
7 TrigDBLoader("TrigDBHLTPrescalesSetLoader", connection)
8{
9 { // query for all schema versions
10 auto & q = m_queries[1];
11 // tables
12 q.addToTableList ( "HLT_PRESCALE_SET" );
13 // bind vars
14 q.extendBinding<int>("key");
15 // conditions
16 q.extendCondition("HPS_ID = :key");
17 // attributes
18 q.extendOutput<coral::Blob>( "HPS_DATA" );
19 // the field with the data
20 q.setDataName("HPS_DATA");
21 }
22}
std::map< size_t, QueryDefinition > m_queries
TrigDBLoader(const std::string &loaderName, const std::string &connection)
Constructor.

◆ ~TrigDBHLTPrescalesSetLoader()

TrigConf::TrigDBHLTPrescalesSetLoader::~TrigDBHLTPrescalesSetLoader ( )
overridevirtualdefault

Destructor - cannot be defined here because QueryDefinition is an incomplete type.

Member Function Documentation

◆ createDBSession()

std::unique_ptr< coral::ISessionProxy > TrigConf::TrigDBLoader::createDBSession ( ) const
protectedinherited

create (if needed) DB session and return the session proxy

Definition at line 107 of file TrigDBLoader.cxx.

107 {
108
109 coral::ConnectionService connSvc;
110 coral::IConnectionServiceConfiguration& csc = connSvc.configuration();
111 csc.setConnectionRetrialPeriod( m_retrialPeriod );
112 csc.setConnectionRetrialTimeOut( m_retrialTimeout );
113 csc.setConnectionTimeOut( m_connectionTimeout );
114
115 /* TODO
116 if(csc.replicaSortingAlgorithm() == nullptr) { // likely to be standalone, create our own
117 TRG_MSG_INFO("Create own ReplicaSortingAlgorithm");
118 m_replicaSorter = new TrigConf::ReplicaSorter();
119 csc.setReplicaSortingAlgorithm(*m_replicaSorter);
120 }
121 */
122
123 TRG_MSG_INFO("Connecting to " << m_connection);
124
125 auto proxy = std::unique_ptr<coral::ISessionProxy>( connSvc.connect(m_connection, coral::AccessMode::ReadOnly) );
126
127 TRG_MSG_INFO("Opened session " << m_connection << " with retrialPeriod/retrialTimeout/connectionTimeout: "
129
130 return proxy;
131}

◆ getName()

const std::string & TrigConf::TrigConfMessaging::getName ( ) const
inlineinherited

name accessor

Returns
the name

Definition at line 101 of file TrigConfMessaging.h.

101 {
102 return m_name;
103 }

◆ getQueryDefinition()

TrigConf::QueryDefinition TrigConf::TrigDBLoader::getQueryDefinition ( size_t schemaVersion,
const std::map< size_t, QueryDefinition > & queries ) const
protectedinherited

return query for given schemaVersion from possible queries

Definition at line 174 of file TrigDBLoader.cxx.

176{
177 // find the largest version key in the map of defined queries that is <= the schemaVersion
178 size_t maxDefVersion = 0;
179 for(auto & entry : queries) {
180 size_t vkey = entry.first;
181 if(vkey>maxDefVersion and vkey<=schemaVersion) {
182 maxDefVersion = vkey;
183 }
184 }
185 // if nothing found, throw an error
186 if( maxDefVersion==0 ) {
187 TRG_MSG_ERROR("No query for schema version " << schemaVersion << " defined" );
188 throw TrigConf::NoQueryException(std::format("No query available for schema version {}", schemaVersion));
189 }
190 return queries.at(maxDefVersion);
191}
size_t schemaVersion(coral::ISessionProxy *session) const
access to TriggerDB schema version

◆ getTrigDataCrest()

std::string TrigConf::TrigDBLoader::getTrigDataCrest ( const std::string & type,
int key ) const
protectedinherited

Get trigger configuration from the TriggerDB through Crest.

Parameters
typeThe type of trigger configuration data to access
  • L1PS => L1 prescale (with L1PS key)
  • HLTPS => HLT prescale (with HLTPS key)
  • L1M => L1 menu (with SMK)
  • HLTM => HLT menu (with SMK)
  • JO => Job options (with SMK)
  • BGS => bunch group set (with BGS key)
  • MGS => monitoring group (with SMK)
keyThe trigger key

Definition at line 134 of file TrigDBLoader.cxx.

134 {
135 /*
136 To get the trigger data from the TriggerDB using CrestApi, it has been agreed to
137 use the API's payload query with a special specifier
138
139 triggerdb://<TrigDBSpec>/<TypeSpec>/<DBKey>
140
141 Possible TrigDBSpec: CONF_DATA_RUN3, CONF_MC_RUN3, CONF_REPR_RUN3
142 Possible TypeSpec: L1PS, HLTM, L1M, HLTPS, BGS, MGS, JO
143 */
144
145 std::string url = m_crestServer + m_crestVersion;
146 std::string query = std::format("triggerdb://{}/{}/{}", m_crestTrigDb, type, key);
147
148#if 0
149 /*
150 the final implementation should be the code below
151 however, in the version used by 24.0 the function CrestApi.getPayload(hash) does not work
152 for the trigger: it includes a hash validation that is not applicable for the trigger
153 but only for conditions payload queries by hash
154 */
155 Crest::CrestApi capi = Crest::CrestApi(url);
156 std::string payload = capi.getPayload(query);
157#else
158 /*
159 so for release 24.0 and until the access to the trigger payload is implemented in CrestApi
160 the CrestRequest is build manually. Luckily all needed functionality is accessible
161 (this code is a copy of CrestApi::getPayload() without the checkHash())
162 */
163 Crest::CrestRequest request = Crest::CrestRequest();
164 request.setUrl(url);
165 std::string current_path = "payloads/data?format=BLOB&hash=" + query;
166 nlohmann::json js = nullptr;
167 std::string payload = request.performRequest(current_path, Crest::Action::GET, js, "TrigDbLoader");
168#endif
169
170 return payload;
171}
query
Definition index.py:72

◆ loadFromCrest()

void TrigConf::TrigDBLoader::loadFromCrest ( unsigned int key,
boost::property_tree::ptree & pt,
const std::string & outFileName,
const std::string & description,
const std::string & query_type ) const
protectedinherited

Definition at line 194 of file TrigDBLoader.cxx.

197{
198 std::string payload;
199 try {
200 payload = getTrigDataCrest(query_type, key);
201 }
202 catch(Crest::CrestException & ex) {
203 TRG_MSG_ERROR("When reading " << description << " for key " << key << " from crest a CrestException was caught ( " << ex.what() <<" )" );
204 throw TrigConf::CrestLoadingException(std::format("{}: {}", getName(), ex.what()));
205 }
206 if(!outFileName.empty()) {
207 writeRawFile(payload, outFileName);
208 TRG_MSG_INFO("Wrote file " << outFileName);
209 }
210 try {
211 stringToPtree(payload, pt);
212 }
213 catch(boost::property_tree::json_parser_error & ex) {
214 TRG_MSG_ERROR("When reading " << description << " for key " << key << " from crest a ptree json parser error was caught ( " << ex.what() <<" )" );
215 throw TrigConf::JsonParsingException(std::format("{}: {}", getName(), ex.what()));
216 }
217}
const std::string & getName() const
name accessor
std::string getTrigDataCrest(const std::string &type, int key) const
Get trigger configuration from the TriggerDB through Crest.
std::string description
glabal timer - how long have I taken so far?
Definition hcg.cxx:91
void stringToPtree(const std::string &json_string, boost::property_tree::ptree &pt)
void writeRawFile(const coral::Blob &data, const std::string &outFileName)
write coral data blob to file

◆ loadFromOracle()

void TrigConf::TrigDBLoader::loadFromOracle ( unsigned int key,
boost::property_tree::ptree & pt,
const std::string & outFileName,
const std::string & description,
const std::map< size_t, QueryDefinition > & queries ) const
protectedinherited

Definition at line 220 of file TrigDBLoader.cxx.

223{
224 auto session = createDBSession();
225 session->transaction().start( /*bool readonly=*/ true);
226 const size_t sv = schemaVersion(session.get());
227 QueryDefinition qdef = getQueryDefinition(sv, queries);
228 try {
229 qdef.setBoundValue<int>("key", key);
230 auto q = qdef.createQuery( session.get() );
231 auto & cursor = q->execute();
232 if ( ! cursor.next() ) {
233 TRG_MSG_ERROR("Tried reading " << description << ", but key " << key << " is not available" );
234 throw TrigConf::NoKeyException(std::format("{}: key {} not available", getName(), key));
235 }
236 const coral::AttributeList& row = cursor.currentRow();
237 const coral::Blob& dataBlob = row[qdef.dataName()].data<coral::Blob>();
238
239 if(!outFileName.empty()) {
240 writeRawFile( dataBlob, outFileName );
241 TRG_MSG_INFO("Wrote file " << outFileName);
242 }
243 blobToPtree( dataBlob, pt );
244 }
245 catch(coral::QueryException & ex) {
246 TRG_MSG_ERROR("When reading " << description << " for key " << key << " a coral::QueryException was caught ( " << ex.what() <<" )" );
247 throw TrigConf::QueryException(std::format("{}: {}", getName(), ex.what()));
248 }
249 catch(boost::property_tree::json_parser_error & ex) {
250 TRG_MSG_ERROR("When reading " << description << " for key " << key << " a ptree json parser error was caught ( " << ex.what() <<" )" );
251 throw TrigConf::JsonParsingException(std::format("{}: {}", getName(), ex.what()));
252 }
253}
std::unique_ptr< coral::ISessionProxy > createDBSession() const
create (if needed) DB session and return the session proxy
QueryDefinition getQueryDefinition(size_t schemaVersion, const std::map< size_t, QueryDefinition > &queries) const
return query for given schemaVersion from possible queries
row
Appending html table to final .html summary file.
void blobToPtree(const coral::Blob &blob, boost::property_tree::ptree &pt)

◆ loadHLTPrescales()

bool TrigConf::TrigDBHLTPrescalesSetLoader::loadHLTPrescales ( unsigned int hltpsk,
TrigConf::HLTPrescalesSet & pss,
const std::string & outFileName = "" ) const

Load content from the Trigger DB into an HLTPrescalesSet for a given HLTPrescaleKey (HLTPSK)

Parameters
hltpsk[in] the HLTPSK that should be loaded
hltpss[out] the loaded HLTPrescalesSet
outFileName[in] name of file to write out the loaded data (optional, by default no file will be written)
Returns
true if loading (and optional writing) was successfull

Definition at line 28 of file TrigDBHLTPrescalesSetLoader.cxx.

30{
31 // load data into ptree
32 boost::property_tree::ptree pt;
33 if(useCrest()) {
34 loadFromCrest(psk, pt, outFileName, "HLT prescales", "HLTPS");
35 } else {
36 loadFromOracle(psk, pt, outFileName, "HLT prescales", m_queries);
37 }
38
39 // fill HLTPrescaleSet with data
40 try {
41 pss.setData(std::move(pt));
42 pss.setPSK(psk);
43 }
44 catch(std::exception & ex) {
45 pss.clear();
46 TRG_MSG_ERROR("When reading HLT prescales for HLT PSK " << psk << " a parsing error occured ( " << ex.what() <<" )" );
47 throw TrigConf::ParsingException("TrigDBHLTPrescalesSetLoader: parsing error " + std::string(ex.what()));
48 }
49 return true;
50}
void setData(const ptree &data)
Setting the configuration data.
void setPSK(unsigned int psk)
virtual void clear() override
Clearing the configuration data.
void loadFromOracle(unsigned int key, boost::property_tree::ptree &pt, const std::string &outFileName, const std::string &description, const std::map< size_t, QueryDefinition > &queries) const
void loadFromCrest(unsigned int key, boost::property_tree::ptree &pt, const std::string &outFileName, const std::string &description, const std::string &query_type) const

◆ msg() [1/2]

MsgStreamTC & TrigConf::TrigConfMessaging::msg ( ) const
inlineinherited

The standard message stream.

Returns a reference to the message stream May not be invoked before sysInitialize() has been invoked.

Definition at line 86 of file TrigConfMessaging.h.

87 {
88 MsgStreamTC* ms = m_msg_tls.get();
89 if (!ms) {
90 ms = new MsgStreamTC(m_name);
91 m_msg_tls.reset(ms);
92 }
93 return *ms;
94 }
boost::thread_specific_ptr< MsgStreamTC > m_msg_tls
MsgStreamTC instance (a std::cout like with print-out levels)

◆ msg() [2/2]

MsgStreamTC & TrigConf::TrigConfMessaging::msg ( const MSGTC::Level lvl) const
inlineinherited

The standard message stream.

Returns a reference to the default message stream May not be invoked before sysInitialize() has been invoked.

Definition at line 96 of file TrigConfMessaging.h.

97 {
98 return msg() << lvl;
99 }
MsgStreamTC & msg() const
The standard message stream.

◆ msgLvl()

bool TrigConf::TrigConfMessaging::msgLvl ( const MSGTC::Level lvl) const
inlineinherited

Test the output level.

Parameters
lvlThe message level to test against
Returns
boolean Indicting if messages at given level will be printed
Return values
trueMessages at level "lvl" will be printed

Definition at line 75 of file TrigConfMessaging.h.

76 {
77 if (msg().level() <= lvl) {
78 msg() << lvl;
79 return true;
80 }
81 else {
82 return false;
83 }
84 }

◆ outputLevel()

MSGTC::Level TrigConf::TrigDBLoader::outputLevel ( ) const
inlineinherited

Definition at line 70 of file TrigDBLoader.h.

70{ return msg().level(); }

◆ schemaVersion()

size_t TrigConf::TrigDBLoader::schemaVersion ( coral::ISessionProxy * session) const
inherited

access to TriggerDB schema version

Returns
version of the DB schema (0 - no version, >0 - schema version)

Definition at line 38 of file TrigDBLoader.cxx.

38 {
39
40 static const std::string versionTagPrefix("Trigger-Run3-Schema-v");
41
42 // if database has no schema version, then we return 0
43 if(! session->nominalSchema().existsTable("TRIGGER_SCHEMA") ) {
44 throw std::runtime_error( "Trigger schema has no schema version table" );
45 }
46
47 TrigConf::QueryDefinition qdef;
48 // tables
49 qdef.addToTableList ( "TRIGGER_SCHEMA" );
50 // attributes
51 qdef.extendOutput<std::string>( "TS_TAG" );
52
53 auto query = qdef.createQuery( session );
54 auto & cursor = query->execute();
55 if ( ! cursor.next() ) {
56 throw std::runtime_error( "Trigger schema has schema version table but it is empty" );
57 }
58
59 const coral::AttributeList& row = cursor.currentRow();
60 std::string versionTag = row["TS_TAG"].data<std::string>();
61 if( ! versionTag.starts_with(versionTagPrefix)) {
62 throw std::runtime_error(std::format("Tag format error: Trigger schema version tag {} does not start with {}", versionTag, versionTagPrefix));
63 }
64
65 std::string vstr = versionTag.substr(versionTagPrefix.size()); // the part of the string containing the version
66 size_t schemaVersion{0};
67 try {
68 schemaVersion = std::stoi(vstr);
69 }
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());
72 throw;
73 }
74
75 TRG_MSG_INFO("TriggerDB schema version: " << schemaVersion);
76 return schemaVersion;
77}
std::unique_ptr< coral::IQuery > createQuery(coral::ISessionProxy *session)
void extendOutput(const std::string &fieldName)
void addToTableList(const std::string &table, const std::string &table_short="")

◆ setCrestConnection()

void TrigConf::TrigDBLoader::setCrestConnection ( const std::string & server,
const std::string & version = "" )
inherited

declare CREST as the source of the configuration An empty crest server makes it use Oracle

Parameters
serverThe crest server. An empty string disables Crest and enables Oracle (the default)
versionThe version of the crest api. Usually not needed. If not given, it defaults to the default API version (see CrestApi/CrestApiBase.h)

Definition at line 80 of file TrigDBLoader.cxx.

80 {
81 // server
83 if(m_crestServer.ends_with('/')) { // remove trailing '/'
84 m_crestServer.pop_back();
85 }
86
87 // use crest flag
88 m_useCrest = ! m_crestServer.empty();
89
90 // version
91 if(version.empty()) {
92 m_crestVersion = DEFAULT_CREST_API_VERSION; // defined in CrestApi/CrestApiBase.h
93 } else {
95 }
96 if(!m_crestVersion.starts_with('/')) { // prepend '/' if not existent
98 }
99}

◆ setCrestTrigDB()

void TrigConf::TrigDBLoader::setCrestTrigDB ( const std::string & crestTrigDB)
inherited

set trigger db for the crest connection

Parameters
crestTrigDBthe source trigger DB. Possible values currently
  • CONF_DATA_RUN3 => ATLAS_CONF_TRIGGER_RUN3
  • CONF_MC_RUN3 => ATLAS_CONF_TRIGGER_MC_RUN3
  • CONF_REPR_RUN3 => ATLAS_CONF_TRIGGER_REPR_RUN3

Definition at line 102 of file TrigDBLoader.cxx.

102 {
103 m_crestTrigDb = crestTrigDB;
104}

◆ setLevel()

void TrigConf::TrigDBLoader::setLevel ( MSGTC::Level lvl)
inlineinherited

Definition at line 68 of file TrigDBLoader.h.

68{ msg().setLevel(lvl); }
void setLevel(MSGTC::Level lvl)
Set message level of stream.

◆ useCrest()

bool TrigConf::TrigDBLoader::useCrest ( ) const
inlineprotectedinherited

Definition at line 74 of file TrigDBLoader.h.

74 {
75 return m_useCrest;
76 }

Member Data Documentation

◆ m_connection

std::string TrigConf::TrigDBLoader::m_connection {""}
privateinherited

Definition at line 110 of file TrigDBLoader.h.

110{""};

◆ m_connectionTimeout

int TrigConf::TrigDBLoader::m_connectionTimeout {0}
privateinherited

Definition at line 116 of file TrigDBLoader.h.

116{0};

◆ m_crestServer

std::string TrigConf::TrigDBLoader::m_crestServer {""}
privateinherited

Definition at line 111 of file TrigDBLoader.h.

111{""};

◆ m_crestTrigDb

std::string TrigConf::TrigDBLoader::m_crestTrigDb {""}
privateinherited

Definition at line 113 of file TrigDBLoader.h.

113{""};

◆ m_crestVersion

std::string TrigConf::TrigDBLoader::m_crestVersion {""}
privateinherited

Definition at line 112 of file TrigDBLoader.h.

112{""};

◆ m_msg_tls

boost::thread_specific_ptr<MsgStreamTC> TrigConf::TrigConfMessaging::m_msg_tls
mutableprivateinherited

MsgStreamTC instance (a std::cout like with print-out levels)

Definition at line 71 of file TrigConfMessaging.h.

◆ m_name

std::string TrigConf::TrigConfMessaging::m_name
privateinherited

Definition at line 72 of file TrigConfMessaging.h.

◆ m_queries

std::map<size_t, QueryDefinition> TrigConf::TrigDBHLTPrescalesSetLoader::m_queries
private

Definition at line 43 of file TrigDBHLTPrescalesSetLoader.h.

◆ m_retrialPeriod

int TrigConf::TrigDBLoader::m_retrialPeriod {0}
privateinherited

Definition at line 114 of file TrigDBLoader.h.

114{0};

◆ m_retrialTimeout

int TrigConf::TrigDBLoader::m_retrialTimeout {0}
privateinherited

Definition at line 115 of file TrigDBLoader.h.

115{0};

◆ m_useCrest

bool TrigConf::TrigDBLoader::m_useCrest {false}
privateinherited

Definition at line 109 of file TrigDBLoader.h.

109{false};

The documentation for this class was generated from the following files: