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

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

#include <TrigDBCTPFilesLoader.h>

Inheritance diagram for TrigConf::TrigDBCTPFilesLoader:
Collaboration diagram for TrigConf::TrigDBCTPFilesLoader:

Public Member Functions

 TrigDBCTPFilesLoader (const std::string &connection)
 Constructor.
virtual ~TrigDBCTPFilesLoader () override
 Destructor - cannot be defined here because QueryDefinition is an incomplete type.
bool loadHardwareFiles (unsigned int smk, L1CTPFiles &ctpfiles, uint8_t loadMask=0x0F, const std::string &outFileName="") const
 Load content from the Trigger DB into an L1CTPFiles object for a given super master key (SMK)
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 Member Functions

void loadCTPFiles (L1CTPFiles &ctpfiles, std::unique_ptr< coral::IQuery > query, size_t schemaVersion) const
void loadCTPSMX (L1CTPFiles &ctpfiles, std::unique_ptr< coral::IQuery > query, size_t schemaVersion) const
void loadTMC (L1CTPFiles &ctpfiles, std::unique_ptr< coral::IQuery > query, size_t schemaVersion) const
void loadMUCTPI (L1CTPFiles &ctpfiles, std::unique_ptr< coral::IQuery > query, size_t schemaVersion) const
std::vector< uint32_t > loadDBFieldIntoVector (const coral::AttributeList &row, const std::string &field, size_t size) const
std::string loadDBFieldIntoString (const coral::AttributeList &row, const std::string &field) const

Private Attributes

std::map< size_t, QueryDefinitionm_link_queries
std::map< size_t, QueryDefinitionm_ctpfiles_queries
std::map< size_t, QueryDefinitionm_ctpsmx_queries
std::map< size_t, QueryDefinitionm_muctpi_queries
std::map< size_t, QueryDefinitionm_tmcsig_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 30 of file TrigDBCTPFilesLoader.h.

Constructor & Destructor Documentation

◆ TrigDBCTPFilesLoader()

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

Constructor.

Definition at line 9 of file TrigDBCTPFilesLoader.cxx.

9 :
10 TrigDBLoader("TrigDBCTPFilesLoader", connection)
11{
12 // CTP and MUCTPI hardware files only exist for schema versions >= 3
13
14 { // links to file tables
15 auto & q = m_link_queries[3];
16 // tables
17 q.addToTableList ( "SUPER_MASTER_TABLE", "SMT" );
18 q.addToTableList ( "L1_MENU", "L1TM" );
19 // bind vars
20 q.extendBinding<unsigned int>("smk");
21 // conditions
22 q.extendCondition("SMT.SMT_ID = :smk AND SMT.SMT_L1_MENU_ID = L1TM.L1TM_ID");
23 // attributes
24 q.extendOutput<unsigned int>( "L1TM.L1TM_CTP_FILES_ID");
25 q.extendOutput<unsigned int>( "L1TM.L1TM_CTP_SMX_ID");
26 q.extendOutput<unsigned int>( "L1TM.L1TM_MUCTPI_FILES_ID");
27 q.extendOutput<unsigned int>( "L1TM.L1TM_TMC_SIGNALS_ID");
28 }
29
30 { // ctp files
31 auto & q = m_ctpfiles_queries[3];
32 // tables
33 q.addToTableList ( "L1_CTP_FILES" );
34 // bind vars
35 q.extendBinding<unsigned int>("id");
36 // conditions
37 q.extendCondition("L1CF_ID = :id");
38 // attributes
39 q.extendOutput<coral::Blob>( "L1CF_LUT" );
40 q.extendOutput<coral::Blob>( "L1CF_CAM" );
41 q.extendOutput<coral::Blob>( "L1CF_MON_SEL_SLOT7" );
42 q.extendOutput<coral::Blob>( "L1CF_MON_SEL_SLOT8" );
43 q.extendOutput<coral::Blob>( "L1CF_MON_SEL_SLOT9" );
44 q.extendOutput<coral::Blob>( "L1CF_MON_SEL_CTPMON" );
45 q.extendOutput<coral::Blob>( "L1CF_MON_DEC_SLOT7" );
46 q.extendOutput<coral::Blob>( "L1CF_MON_DEC_SLOT8" );
47 q.extendOutput<coral::Blob>( "L1CF_MON_DEC_SLOT9" );
48 q.extendOutput<coral::Blob>( "L1CF_MON_DEC_CTPMON" );
49 q.extendOutput<coral::Blob>( "L1CF_MON_DMX" );
50 }
51
52 {
53 // ctp files >= v6
54 // in version 6 this field (ctp core switchmatrix) was added
55 auto q = m_ctpfiles_queries[3];
56 q.extendOutput<coral::Blob>( "L1CF_SMX" );
57 m_ctpfiles_queries[6] = std::move(q);
58 }
59
60 { // ctp smx
61 auto & q = m_ctpsmx_queries[3];
62 // tables
63 q.addToTableList ( "L1_CTP_SMX" );
64 // bind vars
65 q.extendBinding<unsigned int>("id");
66 // conditions
67 q.extendCondition("L1SMX_ID = :id");
68 // attributes
69 q.extendOutput<coral::Blob>( "L1SMX_OUTPUT" );
70 q.extendOutput<coral::Blob>( "L1SMX_VHDL_SLOT7" );
71 q.extendOutput<coral::Blob>( "L1SMX_VHDL_SLOT8" );
72 q.extendOutput<coral::Blob>( "L1SMX_VHDL_SLOT9" );
73 q.extendOutput<coral::Blob>( "L1SMX_SVFI_SLOT7" );
74 q.extendOutput<coral::Blob>( "L1SMX_SVFI_SLOT8" );
75 q.extendOutput<coral::Blob>( "L1SMX_SVFI_SLOT9" );
76 }
77
78 { // muctpi
79 auto & q = m_muctpi_queries[3];
80 // tables
81 q.addToTableList ( "L1_MUCTPI_FILES" );
82 // bind vars
83 q.extendBinding<unsigned int>("id");
84 // conditions
85 q.extendCondition("L1MF_ID = :id");
86 // attributes
87 q.extendOutput<coral::Blob>( "L1MF_DATA" );
88 }
89
90 { // tmc
91 auto & q = m_tmcsig_queries[3];
92 // tables
93 q.addToTableList ( "L1_TMC_SIGNALS" );
94 // bind vars
95 q.extendBinding<unsigned int>("id");
96 // conditions
97 q.extendCondition("L1TMC_ID = :id");
98 // attributes
99 q.extendOutput<coral::Blob>( "L1TMC_DATA" );
100 }
101}
std::map< size_t, QueryDefinition > m_tmcsig_queries
std::map< size_t, QueryDefinition > m_ctpfiles_queries
std::map< size_t, QueryDefinition > m_muctpi_queries
std::map< size_t, QueryDefinition > m_ctpsmx_queries
std::map< size_t, QueryDefinition > m_link_queries
TrigDBLoader(const std::string &loaderName, const std::string &connection)
Constructor.

◆ ~TrigDBCTPFilesLoader()

TrigConf::TrigDBCTPFilesLoader::~TrigDBCTPFilesLoader ( )
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

◆ loadCTPFiles()

void TrigConf::TrigDBCTPFilesLoader::loadCTPFiles ( L1CTPFiles & ctpfiles,
std::unique_ptr< coral::IQuery > query,
size_t schemaVersion ) const
private

Definition at line 189 of file TrigDBCTPFilesLoader.cxx.

190{
191 TRG_MSG_INFO("Loading data from table L1_CTP_FILES.");
192 try
193 {
194 auto & cursor = query->execute();
195 std::ignore = cursor.next();
196 const coral::AttributeList& row = cursor.currentRow();
197 {
198 ctpfiles.set_Ctpcore_LUT(
200 );
201 }
202 {
203 ctpfiles.set_Ctpcore_CAM(
205 );
206 }
207 if(schemaVersion>=6) {
208 ctpfiles.set_Ctpcore_SMX(
210 );
211 }
212
213 {
214 ctpfiles.set_Ctpin_MonSelector_Slot7(
215 loadDBFieldIntoVector(row, "L1CF_MON_SEL_SLOT7", L1CTPFiles::CTPIN_MONSEL_SIZE)
216 );
217 }
218 {
219 ctpfiles.set_Ctpin_MonSelector_Slot8(
220 loadDBFieldIntoVector(row, "L1CF_MON_SEL_SLOT8", L1CTPFiles::CTPIN_MONSEL_SIZE)
221 );
222 }
223 {
224 ctpfiles.set_Ctpin_MonSelector_Slot9(
225 loadDBFieldIntoVector(row, "L1CF_MON_SEL_SLOT9", L1CTPFiles::CTPIN_MONSEL_SIZE)
226 );
227 }
228 {
229 ctpfiles.set_Ctpin_MonDecoder_Slot7(
230 loadDBFieldIntoVector(row, "L1CF_MON_DEC_SLOT7", L1CTPFiles::CTPIN_MONDEC_SIZE)
231 );
232 }
233 {
234 ctpfiles.set_Ctpin_MonDecoder_Slot8(
235 loadDBFieldIntoVector(row, "L1CF_MON_DEC_SLOT8", L1CTPFiles::CTPIN_MONDEC_SIZE)
236 );
237 }
238 {
239 ctpfiles.set_Ctpin_MonDecoder_Slot9(
240 loadDBFieldIntoVector(row, "L1CF_MON_DEC_SLOT9", L1CTPFiles::CTPIN_MONDEC_SIZE)
241 );
242 }
243 {
244 ctpfiles.set_Ctpmon_MonSelector(
246 );
247 }
248 {
249 ctpfiles.set_Ctpmon_MonDecoder(
250 loadDBFieldIntoVector(row, "L1CF_MON_DEC_CTPMON", L1CTPFiles::CTPMON_DECODER_SIZE)
251 );
252 }
253 {
254 ctpfiles.set_Ctpmon_DMX(
256 );
257 }
258 ctpfiles.set_HasCompleteCtpData(true);
259 }
260 catch(coral::QueryException & ex) {
261 TRG_MSG_ERROR("When reading the L1CTPFiles a coral::QueryException was caught ( " << ex.what() <<" )" );
262 throw TrigConf::QueryException("TrigDBCTPFilesLoader: " + std::string(ex.what()));
263 }
264}
static const size_t CTPIN_MONDEC_SIZE
Definition L1CTPFiles.h:39
static const size_t CTPCORE_SMX_SIZE
Definition L1CTPFiles.h:36
static const size_t CTPMON_SELECTOR_SIZE
Definition L1CTPFiles.h:43
static const size_t CTPMON_DMX_SIZE
Definition L1CTPFiles.h:45
static const size_t CTPIN_MONSEL_SIZE
Definition L1CTPFiles.h:38
static const size_t CTPMON_DECODER_SIZE
Definition L1CTPFiles.h:44
static const size_t CTPCORE_CAM_SIZE
Definition L1CTPFiles.h:35
static const size_t CTPCORE_LUT_SIZE
Definition L1CTPFiles.h:34
std::vector< uint32_t > loadDBFieldIntoVector(const coral::AttributeList &row, const std::string &field, size_t size) const
row
Appending html table to final .html summary file.

◆ loadCTPSMX()

void TrigConf::TrigDBCTPFilesLoader::loadCTPSMX ( L1CTPFiles & ctpfiles,
std::unique_ptr< coral::IQuery > query,
size_t schemaVersion ) const
private

Definition at line 267 of file TrigDBCTPFilesLoader.cxx.

267 {
268 TRG_MSG_INFO("Loading data from table L1_CTP_SMX");
269 try
270 {
271 auto & cursor = query->execute();
272 std::ignore = cursor.next();
273 const coral::AttributeList& row = cursor.currentRow();
274
275 ctpfiles.set_Smx_Output( loadDBFieldIntoString(row, "L1SMX_OUTPUT") );
276 ctpfiles.set_Smx_Vhdl_Slot7( loadDBFieldIntoString(row, "L1SMX_VHDL_SLOT7") );
277 ctpfiles.set_Smx_Vhdl_Slot8( loadDBFieldIntoString(row, "L1SMX_VHDL_SLOT8") );
278 ctpfiles.set_Smx_Vhdl_Slot9( loadDBFieldIntoString(row, "L1SMX_VHDL_SLOT9") );
279 ctpfiles.set_Smx_Svfi_Slot7( loadDBFieldIntoString(row, "L1SMX_SVFI_SLOT7") );
280 ctpfiles.set_Smx_Svfi_Slot8( loadDBFieldIntoString(row, "L1SMX_SVFI_SLOT8") );
281 ctpfiles.set_Smx_Svfi_Slot9( loadDBFieldIntoString(row, "L1SMX_SVFI_SLOT9") );
282 ctpfiles.set_HasCompleteSmxData(true);
283 }
284 catch(coral::QueryException & ex) {
285 TRG_MSG_ERROR("When reading the L1CTPFiles a coral::QueryException was caught ( " << ex.what() <<" )" );
286 throw TrigConf::QueryException("TrigDBCTPFilesLoader: " + std::string(ex.what()));
287 }
288}
std::string loadDBFieldIntoString(const coral::AttributeList &row, const std::string &field) const

◆ loadDBFieldIntoString()

std::string TrigConf::TrigDBCTPFilesLoader::loadDBFieldIntoString ( const coral::AttributeList & row,
const std::string & field ) const
private

Definition at line 505 of file TrigDBCTPFilesLoader.cxx.

505 {
506 std::string result;
507 try {
508 const coral::Blob& blob = row[field].data<coral::Blob>();
509 boost::iostreams::stream<boost::iostreams::array_source> stream(
510 static_cast<const char*> (blob.startingAddress()),
511 blob.size()
512 );
513 result = std::string (
514 std::istreambuf_iterator<char>(stream.rdbuf()),
515 std::istreambuf_iterator<char>()
516 );
517 TRG_MSG_INFO("Loading " << field << " of size " << result.size());
518 }
519 catch(const coral::AttributeException & e) {} // NULL content
520 if(result.empty()) {
521 TRG_MSG_ERROR("Field " << field << " in DB is empty");
522 throw std::runtime_error( "CTPFilesLoader: field " + field + " in DB is empty" );
523 }
524 return result;
525}

◆ loadDBFieldIntoVector()

std::vector< uint32_t > TrigConf::TrigDBCTPFilesLoader::loadDBFieldIntoVector ( const coral::AttributeList & row,
const std::string & field,
size_t size ) const
private

Definition at line 477 of file TrigDBCTPFilesLoader.cxx.

477 {
478 std::vector<uint32_t> vec;
479 if(size>0) {
480 vec.reserve(size);
481 }
482 try {
483 TRG_MSG_INFO("Loading " << field << " of size (#words) " << size);
484 const coral::Blob& blob = row[field].data<coral::Blob>();
485 boost::iostreams::stream<boost::iostreams::array_source> stream(
486 static_cast<const char*> (blob.startingAddress()),
487 blob.size()
488 );
489 std::string word{""};
490 while(stream >> word) {
491 vec.push_back(std::stoul(word,nullptr, 0));
492 }
493 }
494 catch(const coral::AttributeException & e) {} // NULL content
495 // check the size if a positive size was requested
496 if(size > 0 && size != vec.size()) {
497 TRG_MSG_ERROR("File content from DB of size " << vec.size() << ", but expect " << size);
498 throw std::runtime_error( "CTPFilesLoader: file of unexpected size" );
499 }
500
501 return vec;
502}
std::vector< size_t > vec

◆ 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
void blobToPtree(const coral::Blob &blob, boost::property_tree::ptree &pt)

◆ loadHardwareFiles()

bool TrigConf::TrigDBCTPFilesLoader::loadHardwareFiles ( unsigned int smk,
TrigConf::L1CTPFiles & ctpfiles,
uint8_t loadMask = 0x0F,
const std::string & outFileName = "" ) const

Load content from the Trigger DB into an L1CTPFiles object for a given super master key (SMK)

Parameters
smk[in] the SMK that should be loaded
ctpfiles[out] the loaded L1CTPFiles
loadMask[in] bit mask which specifies which content should be loaded (default is 0x0F which loads all content) 0x01 - CTPFiles, 0x02 - SMX files, 0x04 - TMC, 0x08 - MUCTPI
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 107 of file TrigDBCTPFilesLoader.cxx.

111{
112 unsigned int ctpFilesID{0};
113 unsigned int ctpSmxID{0};
114 unsigned int muctpiID{0};
115 unsigned int tmcSignalsID{0};
116
117 auto session = createDBSession();
118 session->transaction().start( /*bool readonly=*/ true);
119 const size_t sv = schemaVersion(session.get());
120 try {
121 QueryDefinition qdef = getQueryDefinition(sv, m_link_queries);
122 qdef.setBoundValue<unsigned int>("smk", smk);
123 auto q = qdef.createQuery( session.get() );
124 auto & cursor = q->execute();
125 if ( ! cursor.next() ) {
126 TRG_MSG_ERROR("Tried reading L1 CTPFiles, but super master key " << smk << " is not available" );
127 throw TrigConf::NoSMKException("TrigDBCTPFilesLoader: super master key " + std::to_string(smk) + " not available");
128 }
129 const coral::AttributeList& row = cursor.currentRow();
130 try {
131 ctpFilesID = row["L1TM.L1TM_CTP_FILES_ID"].data<unsigned int>();
132 }
133 catch(const coral::AttributeException & e) // NULL content
134 {}
135 try {
136 ctpSmxID = row["L1TM.L1TM_CTP_SMX_ID"].data<unsigned int>();
137 }
138 catch(const coral::AttributeException & e) // NULL content
139 {}
140 try {
141 muctpiID = row["L1TM.L1TM_MUCTPI_FILES_ID"].data<unsigned int>();
142 }
143 catch(const coral::AttributeException & e) // NULL content
144 {}
145 try {
146 tmcSignalsID = row["L1TM.L1TM_TMC_SIGNALS_ID"].data<unsigned int>();
147 }
148 catch(const coral::AttributeException & e) // NULL content
149 {}
150
151 TRG_MSG_INFO("ID of table L1_CTP_FILES : " << ctpFilesID);
152 TRG_MSG_INFO("ID of table L1_CTP_SMX : " << ctpSmxID);
153 TRG_MSG_INFO("ID of table L1_MUCTPI_FILES : " << muctpiID);
154 TRG_MSG_INFO("ID of table L1_TMC_SIGNALS : " << tmcSignalsID);
155 }
156 catch(coral::QueryException & ex) {
157 TRG_MSG_ERROR("When reading the files table links for super master key " << smk << " a coral::QueryException was caught ( " << ex.what() <<" )" );
158 throw TrigConf::QueryException("TrigDBCTPFilesLoader: " + std::string(ex.what()));
159 }
160
161 if(ctpFilesID>0 && (loadMask & 0x01)!=0 ) {
162 QueryDefinition qdef = getQueryDefinition(sv, m_ctpfiles_queries);
163 qdef.setBoundValue<unsigned int>("id", ctpFilesID);
164 loadCTPFiles(ctpfiles, qdef.createQuery( session.get() ), sv );
165 }
166
167 if(ctpSmxID>0 && (loadMask & 0x02)!=0) {
168 QueryDefinition qdef = getQueryDefinition(sv, m_ctpsmx_queries);
169 qdef.setBoundValue<unsigned int>("id", ctpSmxID);
170 loadCTPSMX(ctpfiles, qdef.createQuery( session.get() ), sv );
171 }
172
173 if(tmcSignalsID>0 && (loadMask & 0x04)!=0) {
174 QueryDefinition qdef = getQueryDefinition(sv, m_tmcsig_queries);
175 qdef.setBoundValue<unsigned int>("id", tmcSignalsID);
176 loadTMC(ctpfiles, qdef.createQuery( session.get() ), sv );
177 }
178
179 if(muctpiID>0 && (loadMask & 0x08)!=0) {
180 QueryDefinition qdef = getQueryDefinition(sv, m_muctpi_queries);
181 qdef.setBoundValue<unsigned int>("id", muctpiID);
182 loadMUCTPI(ctpfiles, qdef.createQuery( session.get() ), sv );
183 }
184 return true;
185}
void loadMUCTPI(L1CTPFiles &ctpfiles, std::unique_ptr< coral::IQuery > query, size_t schemaVersion) const
void loadCTPSMX(L1CTPFiles &ctpfiles, std::unique_ptr< coral::IQuery > query, size_t schemaVersion) const
void loadCTPFiles(L1CTPFiles &ctpfiles, std::unique_ptr< coral::IQuery > query, size_t schemaVersion) const
void loadTMC(L1CTPFiles &ctpfiles, std::unique_ptr< coral::IQuery > query, size_t schemaVersion) const

◆ loadMUCTPI()

void TrigConf::TrigDBCTPFilesLoader::loadMUCTPI ( L1CTPFiles & ctpfiles,
std::unique_ptr< coral::IQuery > query,
size_t schemaVersion ) const
private

Definition at line 291 of file TrigDBCTPFilesLoader.cxx.

291 {
292 TRG_MSG_INFO("Loading data from table L1_MUCTPI_FILES");
293
294 bool incomplete = false;
295 boost::property_tree::ptree pt;
296 try
297 {
298 auto & cursor = query->execute();
299 std::ignore = cursor.next();
300 const coral::AttributeList& row = cursor.currentRow();
301 const coral::Blob & blob = row["L1MF_DATA"].data<coral::Blob>();
302 blobToPtree(blob, pt);
303 }
304 catch(coral::QueryException & ex) {
305 TRG_MSG_ERROR("When reading the L1CTPFiles a coral::QueryException was caught ( " << ex.what() <<" )" );
306 throw TrigConf::QueryException("TrigDBCTPFilesLoader: " + std::string(ex.what()));
307 }
308 DataStructure ds("L1_MUCTPI_FILES", std::move(pt));
309 std::vector<std::string> keys = ds.getKeys();
311 if( auto dv = ds.getList_optional(L1CTPFiles::s_keyMap.at(k)) ) {
312 keys.erase( std::find(keys.begin(), keys.end(), L1CTPFiles::s_keyMap.at(k)) );
313 std::vector<uint32_t> v;
314 v.reserve(200);
315 for( const auto & x : *dv ) {
316 v.push_back(std::stoul(x.getValue<std::string>(), nullptr, 0));
317 }
318 ctpfiles.set_Muctpi(k, std::move(v));
319 } else {
320 incomplete = true;
321 }
322 }
323 for(const std::string & k : keys) {
324 if(ds.isNull(k)) {
325 TRG_MSG_INFO("Attribute " << k << " has null-content");
326 incomplete = true;
327 continue;
328 }
329 auto sopt = ds.getAttribute_optional<std::string>(k);
330 if(k.compare(0, 6, "pt_lut") == 0) {
331 auto dv = ds.getList(k);
332 std::vector<uint32_t> v;
333 v.reserve(200);
334 for( const auto & x : dv ) {
335 v.push_back(std::stoul(x.getValue<std::string>(), nullptr, 0));
336 }
337 ctpfiles.set_Muctpi_Extra_Ptlut(k, std::move(v));
338 } else if(k=="multiplicities_nbits") {
339 auto dv = ds.getList(k);
340 std::vector<uint32_t> v;
341 for( const auto & x : dv ) {
342 v.push_back(std::stoul(x.getValue<std::string>(), nullptr, 0));
343 }
344 ctpfiles.set_Muctpi_Nbits(std::move(v));
345 }
346 }
347 ctpfiles.set_HasCompleteMuctpiData(!incomplete);
348}
#define x
static const std::map< MuctpiAccess, std::string > s_keyMap
Definition L1CTPFiles.h:7

◆ loadTMC()

void TrigConf::TrigDBCTPFilesLoader::loadTMC ( L1CTPFiles & ctpfiles,
std::unique_ptr< coral::IQuery > query,
size_t schemaVersion ) const
private

Definition at line 351 of file TrigDBCTPFilesLoader.cxx.

351 {
352 TRG_MSG_INFO("Loading data from table L1_TMC_SIGNALS");
353 boost::property_tree::ptree pt;
354 try
355 {
356 auto & cursor = query->execute();
357 std::ignore = cursor.next();
358 const coral::AttributeList& row = cursor.currentRow();
359 const coral::Blob & blob = row["L1TMC_DATA"].data<coral::Blob>();
360 blobToPtree(blob, pt);
361 }
362 catch(coral::QueryException & ex) {
363 TRG_MSG_ERROR("When reading the L1CTPFiles a coral::QueryException was caught ( " << ex.what() <<" )" );
364 throw TrigConf::QueryException("TrigDBCTPFilesLoader: " + std::string(ex.what()));
365 }
366
367 DataStructure ds("L1_TMC", std::move(pt));
368
369 // should always be the correct type
370 if( auto ft = ds.getAttribute<std::string>("filetype"); ft != "tmcresult" ) {
371 throw TrigConf::ParsingException("TrigDBCTPFilesLoader::loadTMC: json structure of unexpected file type found. Expected 'tmcresult', but found " + ft);
372 }
373
374 // read the ctpcore inputs
375 if (auto dv = ds.getObject_optional("CTPCORE.TriggerInputs"))
376 {
377 std::vector<TrigConf::L1CTPFiles::CTPCoreInput> ctpcoreInputs;
378 for (const std::string &k : dv->getKeys())
379 {
380 const TrigConf::DataStructure &inp = dv->getObject(k);
381 const std::string &inputType = inp["type"];
383 if (inputType == "PIT")
384 {
386 }
387 else if (inputType == "DIR")
388 {
390 }
391 else if (inputType == "CTPX")
392 continue;
393 else
394 continue;
395 ctpcoreInputs.push_back(
396 TrigConf::L1CTPFiles::CTPCoreInput(
397 inp.getAttribute<size_t>("number"), inp.getAttribute<std::string>("name"),
398 inp.getAttribute<size_t>("bit"), inp.getAttribute<size_t>("phase"),
399 inpEnum));
400 }
401 TRG_MSG_INFO("Loading ctpcore inputs " << ctpcoreInputs.size());
402 ctpfiles.set_Tmc_CtpcoreInputs(std::move(ctpcoreInputs));
403 }
404
405 // read the ctpcore CTPX inputs
406 if (auto dv = ds.getObject_optional("CTPCORE.TriggerInputs"))
407 {
408 std::vector<TrigConf::L1CTPFiles::CTPCoreCTPXInput> ctpcoreCTPXInputs;
409 for (const std::string &k : dv->getKeys())
410 {
411 const TrigConf::DataStructure &inp = dv->getObject(k);
412 const std::string &inputType = inp["type"];
414 if (inputType == "CTPX")
415 {
417 }
418 else if (inputType == "PIT" || inputType == "DIR")
419 continue;
420 else
421 continue;
422 ctpcoreCTPXInputs.push_back(
423 TrigConf::L1CTPFiles::CTPCoreCTPXInput(
424 inp.getAttribute<size_t>("number"), inp.getAttribute<std::string>("name"),
425 inp.getAttribute<size_t>("bit"),
426 inpEnum));
427 }
428 TRG_MSG_INFO("Loading ctpcore CTPX inputs " << ctpcoreCTPXInputs.size());
429 ctpfiles.set_Tmc_CtpcoreCTPXInputs(std::move(ctpcoreCTPXInputs));
430 }
431
432 // read the ctpin map
433 std::vector<TrigConf::L1CTPFiles::CTPInCounter> ctpinCounters;
434 for (size_t slot : {7, 8, 9})
435 {
436 for (size_t conn : {0, 1, 2, 3})
437 {
438 std::string path = "CTPINs.SLOT" + std::to_string(slot) + ".Monitoring.Cables.CON" + std::to_string(conn);
439 if (auto dv = ds.getObject_optional(path))
440 {
441 if (auto ov = dv->getList_optional("outputs"))
442 {
443 for (const DataStructure &output : *ov)
444 {
445 ctpinCounters.push_back(
446 TrigConf::L1CTPFiles::CTPInCounter(
447 output.getAttribute<std::string>("TriggerCounter"), slot, conn, output.getAttribute<size_t>("number")));
448 }
449 }
450 }
451 }
452 }
453 TRG_MSG_INFO("Loading ctpin counters " << ctpinCounters.size());
454 ctpfiles.set_Tmc_CtpinCounters(std::move(ctpinCounters));
455
456 // read the ctpmon map
457 std::vector<TrigConf::L1CTPFiles::CTPMonCounter> ctpmonCounters;
458 if( auto dv = ds.getObject_optional("CTPMON.Monitoring") ) {
459 if (auto ov = dv->getList_optional("outputs"))
460 {
461 for (const DataStructure &output : *ov)
462 {
463 ctpmonCounters.push_back(
464 TrigConf::L1CTPFiles::CTPMonCounter(
465 output.getAttribute<std::string>("TriggerCounter"), output.getAttribute<size_t>("number")));
466 }
467 }
468 }
469 TRG_MSG_INFO("Loading ctpmon counters " << ctpmonCounters.size());
470 ctpfiles.set_Tmc_CtpmonCounters(std::move(ctpmonCounters));
471
472 ctpfiles.set_Tmc_Data(std::move(ds));
473 ctpfiles.set_HasCompleteTmcData(true);
474}
T getAttribute(const std::string &key, bool ignoreIfMissing=false, const T &def=T()) const
Access to simple attribute.
path
python interpreter configuration --------------------------------------—
Definition athena.py:128
output
Definition merge.py:16

◆ 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_ctpfiles_queries

std::map<size_t, QueryDefinition> TrigConf::TrigDBCTPFilesLoader::m_ctpfiles_queries
private

Definition at line 68 of file TrigDBCTPFilesLoader.h.

◆ m_ctpsmx_queries

std::map<size_t, QueryDefinition> TrigConf::TrigDBCTPFilesLoader::m_ctpsmx_queries
private

Definition at line 69 of file TrigDBCTPFilesLoader.h.

◆ m_link_queries

std::map<size_t, QueryDefinition> TrigConf::TrigDBCTPFilesLoader::m_link_queries
private

Definition at line 67 of file TrigDBCTPFilesLoader.h.

◆ 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_muctpi_queries

std::map<size_t, QueryDefinition> TrigConf::TrigDBCTPFilesLoader::m_muctpi_queries
private

Definition at line 70 of file TrigDBCTPFilesLoader.h.

◆ m_name

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

Definition at line 72 of file TrigConfMessaging.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_tmcsig_queries

std::map<size_t, QueryDefinition> TrigConf::TrigDBCTPFilesLoader::m_tmcsig_queries
private

Definition at line 71 of file TrigDBCTPFilesLoader.h.

◆ 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: