17 q.addToTableList (
"SUPER_MASTER_TABLE",
"SMT" );
18 q.addToTableList (
"L1_MENU",
"L1TM" );
20 q.extendBinding<
unsigned int>(
"smk");
22 q.extendCondition(
"SMT.SMT_ID = :smk AND SMT.SMT_L1_MENU_ID = L1TM.L1TM_ID");
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");
33 q.addToTableList (
"L1_CTP_FILES" );
35 q.extendBinding<
unsigned int>(
"id");
37 q.extendCondition(
"L1CF_ID = :id");
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" );
56 q.extendOutput<coral::Blob>(
"L1CF_SMX" );
63 q.addToTableList (
"L1_CTP_SMX" );
65 q.extendBinding<
unsigned int>(
"id");
67 q.extendCondition(
"L1SMX_ID = :id");
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" );
81 q.addToTableList (
"L1_MUCTPI_FILES" );
83 q.extendBinding<
unsigned int>(
"id");
85 q.extendCondition(
"L1MF_ID = :id");
87 q.extendOutput<coral::Blob>(
"L1MF_DATA" );
93 q.addToTableList (
"L1_TMC_SIGNALS" );
95 q.extendBinding<
unsigned int>(
"id");
97 q.extendCondition(
"L1TMC_ID = :id");
99 q.extendOutput<coral::Blob>(
"L1TMC_DATA" );
110 const std::string & )
const
112 unsigned int ctpFilesID{0};
113 unsigned int ctpSmxID{0};
114 unsigned int muctpiID{0};
115 unsigned int tmcSignalsID{0};
118 session->transaction().start(
true);
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" );
129 const coral::AttributeList& row = cursor.currentRow();
131 ctpFilesID = row[
"L1TM.L1TM_CTP_FILES_ID"].data<
unsigned int>();
133 catch(
const coral::AttributeException & e)
136 ctpSmxID = row[
"L1TM.L1TM_CTP_SMX_ID"].data<
unsigned int>();
138 catch(
const coral::AttributeException & e)
141 muctpiID = row[
"L1TM.L1TM_MUCTPI_FILES_ID"].data<
unsigned int>();
143 catch(
const coral::AttributeException & e)
146 tmcSignalsID = row[
"L1TM.L1TM_TMC_SIGNALS_ID"].data<
unsigned int>();
148 catch(
const coral::AttributeException & e)
151 TRG_MSG_INFO(
"ID of table L1_CTP_FILES : " << ctpFilesID);
153 TRG_MSG_INFO(
"ID of table L1_MUCTPI_FILES : " << muctpiID);
154 TRG_MSG_INFO(
"ID of table L1_TMC_SIGNALS : " << tmcSignalsID);
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() <<
" )" );
161 if(ctpFilesID>0 && (loadMask & 0x01)!=0 ) {
167 if(ctpSmxID>0 && (loadMask & 0x02)!=0) {
173 if(tmcSignalsID>0 && (loadMask & 0x04)!=0) {
179 if(muctpiID>0 && (loadMask & 0x08)!=0) {
194 auto & cursor =
query->execute();
195 std::ignore = cursor.next();
196 const coral::AttributeList& row = cursor.currentRow();
260 catch(coral::QueryException & ex) {
261 TRG_MSG_ERROR(
"When reading the L1CTPFiles a coral::QueryException was caught ( " << ex.what() <<
" )" );
271 auto & cursor =
query->execute();
272 std::ignore = cursor.next();
273 const coral::AttributeList& row = cursor.currentRow();
284 catch(coral::QueryException & ex) {
285 TRG_MSG_ERROR(
"When reading the L1CTPFiles a coral::QueryException was caught ( " << ex.what() <<
" )" );
292 TRG_MSG_INFO(
"Loading data from table L1_MUCTPI_FILES");
294 bool incomplete =
false;
295 boost::property_tree::ptree pt;
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>();
304 catch(coral::QueryException & ex) {
305 TRG_MSG_ERROR(
"When reading the L1CTPFiles a coral::QueryException was caught ( " << ex.what() <<
" )" );
309 std::vector<std::string> keys = ds.getKeys();
313 std::vector<uint32_t> v;
315 for(
const auto &
x : *dv ) {
316 v.push_back(std::stoul(
x.getValue<std::string>(),
nullptr, 0));
323 for(
const std::string & k : keys) {
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;
334 for(
const auto &
x : dv ) {
335 v.push_back(std::stoul(
x.getValue<std::string>(),
nullptr, 0));
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));
353 boost::property_tree::ptree pt;
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>();
362 catch(coral::QueryException & ex) {
363 TRG_MSG_ERROR(
"When reading the L1CTPFiles a coral::QueryException was caught ( " << ex.what() <<
" )" );
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);
375 if (
auto dv = ds.getObject_optional(
"CTPCORE.TriggerInputs"))
377 std::vector<TrigConf::L1CTPFiles::CTPCoreInput> ctpcoreInputs;
378 for (
const std::string &k : dv->getKeys())
381 const std::string &inputType = inp[
"type"];
383 if (inputType ==
"PIT")
387 else if (inputType ==
"DIR")
391 else if (inputType ==
"CTPX")
395 ctpcoreInputs.push_back(
401 TRG_MSG_INFO(
"Loading ctpcore inputs " << ctpcoreInputs.size());
406 if (
auto dv = ds.getObject_optional(
"CTPCORE.TriggerInputs"))
408 std::vector<TrigConf::L1CTPFiles::CTPCoreCTPXInput> ctpcoreCTPXInputs;
409 for (
const std::string &k : dv->getKeys())
412 const std::string &inputType = inp[
"type"];
414 if (inputType ==
"CTPX")
418 else if (inputType ==
"PIT" || inputType ==
"DIR")
422 ctpcoreCTPXInputs.push_back(
428 TRG_MSG_INFO(
"Loading ctpcore CTPX inputs " << ctpcoreCTPXInputs.size());
433 std::vector<TrigConf::L1CTPFiles::CTPInCounter> ctpinCounters;
434 for (
size_t slot : {7, 8, 9})
436 for (
size_t conn : {0, 1, 2, 3})
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))
441 if (
auto ov = dv->getList_optional(
"outputs"))
445 ctpinCounters.push_back(
447 output.getAttribute<std::string>(
"TriggerCounter"), slot, conn, output.getAttribute<
size_t>(
"number")));
453 TRG_MSG_INFO(
"Loading ctpin counters " << ctpinCounters.size());
457 std::vector<TrigConf::L1CTPFiles::CTPMonCounter> ctpmonCounters;
458 if(
auto dv = ds.getObject_optional(
"CTPMON.Monitoring") ) {
459 if (
auto ov = dv->getList_optional(
"outputs"))
463 ctpmonCounters.push_back(
465 output.getAttribute<std::string>(
"TriggerCounter"), output.getAttribute<
size_t>(
"number")));
469 TRG_MSG_INFO(
"Loading ctpmon counters " << ctpmonCounters.size());
478 std::vector<uint32_t>
vec;
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()),
489 std::string word{
""};
490 while(stream >> word) {
491 vec.push_back(std::stoul(word,
nullptr, 0));
494 catch(
const coral::AttributeException & e) {}
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" );
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()),
514 std::istreambuf_iterator<char>(stream.rdbuf()),
515 std::istreambuf_iterator<char>()
519 catch(
const coral::AttributeException & e) {}
522 throw std::runtime_error(
"CTPFilesLoader: field " + field +
" in DB is empty" );
std::vector< size_t > vec
Loader class for Trigger configuration (L1 hardware files) from the Trigger DB.
Base class for Trigger configuration data and wrapper around underlying representation.
T getAttribute(const std::string &key, bool ignoreIfMissing=false, const T &def=T()) const
Access to simple attribute.
void set_Muctpi(MuctpiAccess key, std::vector< uint32_t > data)
void set_Ctpmon_MonSelector(std::vector< uint32_t > data)
void set_Tmc_CtpmonCounters(std::vector< TrigConf::L1CTPFiles::CTPMonCounter > data)
void set_Ctpin_MonSelector_Slot9(std::vector< uint32_t > data)
void set_HasCompleteCtpData(bool flag)
Setters of the various CTP data.
void set_HasCompleteSmxData(bool flag)
static const size_t CTPIN_MONDEC_SIZE
void set_Tmc_Data(DataStructure data)
void set_Ctpin_MonDecoder_Slot8(std::vector< uint32_t > data)
static const std::map< MuctpiAccess, std::string > s_keyMap
void set_Ctpin_MonSelector_Slot8(std::vector< uint32_t > data)
void set_Tmc_CtpcoreInputs(std::vector< TrigConf::L1CTPFiles::CTPCoreInput > data)
void set_Smx_Svfi_Slot8(const std::string &data)
void set_Ctpmon_MonDecoder(std::vector< uint32_t > data)
void set_Smx_Svfi_Slot9(const std::string &data)
void set_Tmc_CtpinCounters(std::vector< TrigConf::L1CTPFiles::CTPInCounter > data)
void set_Muctpi_Nbits(std::vector< uint32_t > data)
static const size_t CTPCORE_SMX_SIZE
static const size_t CTPMON_SELECTOR_SIZE
void set_Ctpcore_LUT(std::vector< uint32_t > data)
void set_Ctpmon_DMX(std::vector< uint32_t > data)
static const size_t CTPMON_DMX_SIZE
void set_Smx_Vhdl_Slot7(const std::string &data)
void set_Ctpin_MonDecoder_Slot7(std::vector< uint32_t > data)
void set_Muctpi_Extra_Ptlut(const std::string &key, std::vector< uint32_t > data)
void set_HasCompleteMuctpiData(bool flag)
static const size_t CTPIN_MONSEL_SIZE
void set_Ctpcore_SMX(std::vector< uint32_t > data)
void set_Smx_Output(const std::string &data)
void set_Smx_Vhdl_Slot9(const std::string &data)
void set_Tmc_CtpcoreCTPXInputs(std::vector< TrigConf::L1CTPFiles::CTPCoreCTPXInput > data)
void set_Ctpin_MonSelector_Slot7(std::vector< uint32_t > data)
void set_Smx_Svfi_Slot7(const std::string &data)
void set_Ctpin_MonDecoder_Slot9(std::vector< uint32_t > data)
static const size_t CTPMON_DECODER_SIZE
void set_Ctpcore_CAM(std::vector< uint32_t > data)
static const size_t CTPCORE_CAM_SIZE
void set_Smx_Vhdl_Slot8(const std::string &data)
void set_HasCompleteTmcData(bool flag)
static const size_t CTPCORE_LUT_SIZE
std::unique_ptr< coral::IQuery > createQuery(coral::ISessionProxy *session)
void setBoundValue(const std::string &fieldName, const T &value)
void loadMUCTPI(L1CTPFiles &ctpfiles, std::unique_ptr< coral::IQuery > query, size_t schemaVersion) const
TrigDBCTPFilesLoader(const std::string &connection)
Constructor.
std::vector< uint32_t > loadDBFieldIntoVector(const coral::AttributeList &row, const std::string &field, size_t size) const
virtual ~TrigDBCTPFilesLoader() override
Destructor - cannot be defined here because QueryDefinition is an incomplete type.
void loadCTPSMX(L1CTPFiles &ctpfiles, std::unique_ptr< coral::IQuery > query, size_t schemaVersion) const
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
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
std::map< size_t, QueryDefinition > m_link_queries
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)
std::string loadDBFieldIntoString(const coral::AttributeList &row, const std::string &field) const
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
TrigDBLoader(const std::string &loaderName, const std::string &connection)
Constructor.
size_t schemaVersion(coral::ISessionProxy *session) const
access to TriggerDB schema version
void blobToPtree(const coral::Blob &blob, boost::property_tree::ptree &pt)