diff --git a/Trigger/TrigConfiguration/TrigConfData/TrigConfData/DataStructure.h b/Trigger/TrigConfiguration/TrigConfData/TrigConfData/DataStructure.h index 4d8827ce7e5f11a9762752258f812c6972833578..2944dc2efc09cec016bfb93b6661ca68b299b1fb 100644 --- a/Trigger/TrigConfiguration/TrigConfData/TrigConfData/DataStructure.h +++ b/Trigger/TrigConfiguration/TrigConfData/TrigConfData/DataStructure.h @@ -120,6 +120,15 @@ namespace TrigConf { */ bool hasAttribute(const std::string & key) const; + /** Check if an attribute is null + * @param key The path to the attribute name, relative to the current one in form "path.to.child" + * @return true if path @c key exists and is null + * + * If the attribute doesn't exist, the function returns false. To check if an attribute exists and + * is null, use it together with @c hasAttribute. + */ + bool isNull(const std::string & key) const; + /** Check if child exists * @param path The path to the child, relative to the current one in form "path.to.child" * @return true if path exists diff --git a/Trigger/TrigConfiguration/TrigConfData/TrigConfData/L1CTPFiles.h b/Trigger/TrigConfiguration/TrigConfData/TrigConfData/L1CTPFiles.h new file mode 100644 index 0000000000000000000000000000000000000000..4738a4c646d1845be453d0f5cdc87af6111a620f --- /dev/null +++ b/Trigger/TrigConfiguration/TrigConfData/TrigConfData/L1CTPFiles.h @@ -0,0 +1,200 @@ +/* + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef TRIGCONFDATA_L1CTPFiles_H +#define TRIGCONFDATA_L1CTPFiles_H + +#include "TrigConfData/ConstIter.h" +#include "TrigConfData/DataStructure.h" +#include "TrigConfData/L1Item.h" +#include "TrigConfData/L1Connector.h" +#include "TrigConfData/L1Board.h" +#include "TrigConfData/L1TopoAlgorithm.h" +#include "TrigConfData/L1Threshold.h" +#include "TrigConfData/L1ThrExtraInfo.h" +#include "TrigConfData/L1CTP.h" + +#include <vector> +#include <map> + +namespace TrigConf { + + /** + * @brief L1 menu configuration + * + * Provides access to menu name and ctpVersion and to the L1 items and thresholds + */ + class L1CTPFiles final { + public: + + static const size_t CTPCORE_LUT_SIZE {725248}; + static const size_t CTPCORE_CAM_SIZE {55296}; + + static const size_t CTPIN_MONSEL_SIZE {124}; + static const size_t CTPIN_MONDEC_SIZE {4096}; + + static const size_t CTPMON_MUX_OUTPUT_NUMBER {9}; + static const size_t CTPMON_ADDRESS_SELECTOR_NUMBER {24}; + static const size_t CTPMON_SELECTOR_SIZE = CTPMON_MUX_OUTPUT_NUMBER * CTPMON_ADDRESS_SELECTOR_NUMBER; + static const size_t CTPMON_DECODER_SIZE {6656}; + static const size_t CTPMON_DMX_SIZE {160}; + + enum MuctpiAccess { RoiMaskA, RoiMaskC, PtLutBarrel, PtLutEndcap }; + static const std::map<MuctpiAccess, std::string> s_keyMap; + + class CTPCoreInput { + public: + CTPCoreInput(size_t inputNumber, std::string name, size_t bit, size_t phase) : + m_inputNumber(inputNumber), m_name(name), m_bit(bit), m_phase(phase) {} + size_t inputNumber() const { return m_inputNumber; } + std::string name() const { return m_name; } + size_t bit() const { return m_bit; } + size_t phase() const { return m_phase; } + private: + size_t m_inputNumber; + std::string m_name; + size_t m_bit; + size_t m_phase; + }; + + /** Constructor */ + L1CTPFiles(); + + /** Destructor */ + virtual ~L1CTPFiles(); + + /** + * Accessors to the various CTP data + **/ + bool hasCompleteCtpData() const; + bool hasCompleteSmxData() const; + bool hasCompleteMuctpiData() const; + bool hasCompleteTmcData() const; + + const std::vector<uint32_t> & ctpcore_LUT() const; + const std::vector<uint32_t> & ctpcore_CAM() const; + + const std::vector<uint32_t> & ctpin_MonSelector_Slot7() const; + const std::vector<uint32_t> & ctpin_MonSelector_Slot8() const; + const std::vector<uint32_t> & ctpin_MonSelector_Slot9() const; + const std::vector<uint32_t> & ctpin_MonDecoder_Slot7() const; + const std::vector<uint32_t> & ctpin_MonDecoder_Slot8() const; + const std::vector<uint32_t> & ctpin_MonDecoder_Slot9() const; + + const std::vector<uint32_t> & ctpmon_MonSelector() const; + const std::vector<uint32_t> & ctpmon_MonDecoder() const; + const std::vector<uint32_t> & ctpmon_DMX() const; + + const std::string & smx_Output() const; + const std::string & smx_Vhdl_Slot7() const; + const std::string & smx_Vhdl_Slot8() const; + const std::string & smx_Vhdl_Slot9() const; + const std::string & smx_Svfi_Slot7() const; + const std::string & smx_Svfi_Slot8() const; + const std::string & smx_Svfi_Slot9() const; + + const std::vector<uint32_t> & muctpiRoi(MuctpiAccess key) const; + const std::vector<uint32_t> & muctpi_Extra_Ptlut(const std::string & sector) const; + const std::vector<uint32_t> & muctpi_Nbits() const; + + const std::vector<TrigConf::L1CTPFiles::CTPCoreInput> & tmc_CtpcoreInputs() const; + const std::map<std::string, size_t> & tmc_CtpinCounters() const; + const std::map<std::string, size_t> & tmc_CtpmonCounters() const; + + /** + * Setters of the various CTP data + */ + + void set_HasCompleteCtpData(bool flag); + void set_HasCompleteSmxData(bool flag); + void set_HasCompleteMuctpiData(bool flag); + void set_HasCompleteTmcData(bool flag); + + void set_Ctpcore_LUT(std::vector<uint32_t> data); + void set_Ctpcore_CAM(std::vector<uint32_t> data); + + void set_Ctpin_MonSelector_Slot7(std::vector<uint32_t> data); + void set_Ctpin_MonSelector_Slot8(std::vector<uint32_t> data); + void set_Ctpin_MonSelector_Slot9(std::vector<uint32_t> data); + void set_Ctpin_MonDecoder_Slot7(std::vector<uint32_t> data); + void set_Ctpin_MonDecoder_Slot8(std::vector<uint32_t> data); + void set_Ctpin_MonDecoder_Slot9(std::vector<uint32_t> data); + + void set_Ctpmon_MonSelector(std::vector<uint32_t> data); + void set_Ctpmon_MonDecoder(std::vector<uint32_t> data); + void set_Ctpmon_DMX(std::vector<uint32_t> data); + + void set_Smx_Output(const std::string & data); + void set_Smx_Vhdl_Slot7(const std::string & data); + void set_Smx_Vhdl_Slot8(const std::string & data); + void set_Smx_Vhdl_Slot9(const std::string & data); + void set_Smx_Svfi_Slot7(const std::string & data); + void set_Smx_Svfi_Slot8(const std::string & data); + void set_Smx_Svfi_Slot9(const std::string & data); + + void set_Muctpi(MuctpiAccess key, std::vector<uint32_t> data); + void set_Muctpi_Extra_Ptlut(const std::string & key, std::vector<uint32_t> data); + void set_Muctpi_Nbits(std::vector<uint32_t> data); + + void set_Tmc_CtpcoreInputs(std::vector<TrigConf::L1CTPFiles::CTPCoreInput> data); + void set_Tmc_CtpinCounters(std::map<std::string, size_t> data); + void set_Tmc_CtpmonCounters(std::map<std::string, size_t> data); + + void print() const; + + private: + + bool m_hasCompleteCtpData {false}; + bool m_hasCompleteSmxData {false}; + bool m_hasCompleteMuctpiData {false}; + bool m_hasCompleteTmcData {false}; + + + /** + * L1_CTP_FILES + */ + std::vector<uint32_t> m_Ctpcore_LUT; + std::vector<uint32_t> m_Ctpcore_CAM; + + std::vector<uint32_t> m_Ctpin_MonSelector_Slot7; + std::vector<uint32_t> m_Ctpin_MonSelector_Slot8; + std::vector<uint32_t> m_Ctpin_MonSelector_Slot9; + std::vector<uint32_t> m_Ctpin_MonDecoder_Slot7; + std::vector<uint32_t> m_Ctpin_MonDecoder_Slot8; + std::vector<uint32_t> m_Ctpin_MonDecoder_Slot9; + + std::vector<uint32_t> m_Ctpmon_MonSelector; + std::vector<uint32_t> m_Ctpmon_MonDecoder; + std::vector<uint32_t> m_Ctpmon_DMX; + + /** + * L1_SMX files + */ + std::string m_Smx_Output {}; + std::string m_Smx_Vhdl_Slot7 {}; + std::string m_Smx_Vhdl_Slot8 {}; + std::string m_Smx_Vhdl_Slot9 {}; + std::string m_Smx_Svfi_Slot7 {}; + std::string m_Smx_Svfi_Slot8 {}; + std::string m_Smx_Svfi_Slot9 {}; + + /** + * L1 Muon files + */ + std::map<std::string, std::vector<uint32_t>> m_muctpi; + std::map<std::string, std::vector<uint32_t>> m_muctpi_Extra_Ptlut; + std::vector<uint32_t> m_muctpi_Nbits; + + + /** + * L1 TMC output informaion + */ + std::vector<TrigConf::L1CTPFiles::CTPCoreInput> m_Tmc_CtpcoreInputs; + std::map<std::string, size_t> m_Tmc_CtpinCounters; + std::map<std::string, size_t> m_Tmc_CtpmonCounters; + + }; +} + +#endif diff --git a/Trigger/TrigConfiguration/TrigConfData/src/DataStructure.cxx b/Trigger/TrigConfiguration/TrigConfData/src/DataStructure.cxx index 14235454fc1cba346d78f8e90890de03b87e69f9..6696fdd7e3b0276b1a7e367c7aaff9f1079d45e1 100644 --- a/Trigger/TrigConfiguration/TrigConfData/src/DataStructure.cxx +++ b/Trigger/TrigConfiguration/TrigConfData/src/DataStructure.cxx @@ -24,9 +24,16 @@ TrigConf::DataStructure::DataStructure(const std::string & name, const ptree & d TrigConf::DataStructure::DataStructure(ptree && data) : + m_initialized(true), m_dataSPtr(std::make_shared<ptree>(move(data))) {} +TrigConf::DataStructure::DataStructure(const std::string & name, ptree && data) : + m_initialized(true), + m_dataSPtr(std::make_shared<ptree>(move(data))), + m_name(name) +{} + TrigConf::DataStructure::~DataStructure() {} @@ -54,7 +61,7 @@ TrigConf::DataStructure::setData(ptree&& data) } void TrigConf::DataStructure::setName(const std::string& n) { - m_name = n; + m_name = n; } @@ -87,6 +94,16 @@ TrigConf::DataStructure::hasAttribute(const std::string & key) const { return child.get().empty(); // if empty then it is an attribute, otherwise a child note } +bool +TrigConf::DataStructure::isNull(const std::string & key) const { + auto child = data().get_child_optional( key ); + if( ! child ) { + return false; + } + return child->get_value<std::string>() == "null"; +} + + std::string TrigConf::DataStructure::className() const { return "DataStructure"; @@ -201,10 +218,12 @@ TrigConf::DataStructure::getObject(const std::string & pathToChild, bool ignoreI throw std::runtime_error(className() + "#" + name() + ": structure '" + pathToChild + "' does not exist."); } } - // check if the pathToChild points to an object - if ( obj.get().empty() ) { + // check if the pathToChild is an attribute + if( obj.get().get_value<std::string>() != "" ) { throw std::runtime_error(className() + "#" + name() + ": structure '" + pathToChild + "' is not an object {} but a simple attribute, it needs to be accessed via [\"" + pathToChild + "\"] -> string"); - } else if ( obj.get().front().first.empty() ) { + } + // check if the pathToChild points to a list + if ( obj.get().front().first.empty() ) { throw std::runtime_error(className() + "#" + name() + ": structure '" + pathToChild + "' is not an object {} but a list [], it needs to be accessed via getList(\"" + pathToChild + "\") -> vector<DataStructure>"); } return { obj.get() }; diff --git a/Trigger/TrigConfiguration/TrigConfData/src/L1CTPFiles.cxx b/Trigger/TrigConfiguration/TrigConfData/src/L1CTPFiles.cxx new file mode 100644 index 0000000000000000000000000000000000000000..da1c52970df7ed36271e54f386f097f42362ca2f --- /dev/null +++ b/Trigger/TrigConfiguration/TrigConfData/src/L1CTPFiles.cxx @@ -0,0 +1,352 @@ +/* + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration +*/ + +#include "TrigConfData/L1CTPFiles.h" + +const std::map<TrigConf::L1CTPFiles::MuctpiAccess, std::string> TrigConf::L1CTPFiles::s_keyMap = { + { RoiMaskA, "roimasking_lut_A" }, + { RoiMaskC, "roimasking_lut_C" }, + { PtLutBarrel, "pt_lut_BA" }, + { PtLutEndcap, "pt_lut_EF" } +}; + +TrigConf::L1CTPFiles::L1CTPFiles() { + for(auto x : s_keyMap) { + m_muctpi[x.second]; + } + m_muctpi[s_keyMap.at(RoiMaskA)]; + m_muctpi[s_keyMap.at(RoiMaskC)]; + m_muctpi[s_keyMap.at(PtLutBarrel)]; + m_muctpi[s_keyMap.at(PtLutEndcap)]; +} + +TrigConf::L1CTPFiles::~L1CTPFiles() = default; + +void +TrigConf::L1CTPFiles::print() const +{ + std::cout << "CTP Files (" << (m_hasCompleteCtpData? "complete" : "incomplete") << ")" << std::endl; + std::cout << " LUT: " << m_Ctpcore_LUT.size() << std::endl; + std::cout << " CAM: " << m_Ctpcore_CAM.size() << std::endl; + std::cout << " CTPIN Mon Sel 7: " << m_Ctpin_MonSelector_Slot7.size() << std::endl; + std::cout << " CTPIN Mon Sel 8: " << m_Ctpin_MonSelector_Slot8.size() << std::endl; + std::cout << " CTPIN Mon Sel 9: " << m_Ctpin_MonSelector_Slot9.size() << std::endl; + std::cout << " CTPIN Mon Dec 7: " << m_Ctpin_MonDecoder_Slot7.size() << std::endl; + std::cout << " CTPIN Mon Dec 8: " << m_Ctpin_MonDecoder_Slot8.size() << std::endl; + std::cout << " CTPIN Mon Dec 9: " << m_Ctpin_MonDecoder_Slot9.size() << std::endl; + std::cout << " CTPMON Mon Sel: " << m_Ctpmon_MonSelector.size() << std::endl; + std::cout << " CTPMON Mon Dec: " << m_Ctpmon_MonDecoder.size() << std::endl; + std::cout << " CTPMON DMX: " << m_Ctpmon_DMX.size() << std::endl; + std::cout << "CTP SMX (" << (m_hasCompleteSmxData? "complete" : "incomplete") << ")" << std::endl; + std::cout << " Output: " << m_Smx_Output.size() << std::endl; + std::cout << " VHDL 7: " << m_Smx_Vhdl_Slot7.size() << std::endl; + std::cout << " VHDL 8: " << m_Smx_Vhdl_Slot8.size() << std::endl; + std::cout << " VHDL 9: " << m_Smx_Vhdl_Slot9.size() << std::endl; + std::cout << " SVFI 7: " << m_Smx_Svfi_Slot7.size() << std::endl; + std::cout << " SVFI 8: " << m_Smx_Svfi_Slot8.size() << std::endl; + std::cout << " SVFI 9: " << m_Smx_Svfi_Slot9.size() << std::endl; + std::cout << "MUCTPI Files (" << (m_hasCompleteMuctpiData? "complete" : "incomplete") << ")" << std::endl; + std::cout << " required:" << std::endl; + std::cout << " RoiMask A: " << m_muctpi.at("roimasking_lut_A").size() << std::endl; + std::cout << " RoiMask C: " << m_muctpi.at("roimasking_lut_C").size() << std::endl; + std::cout << " pt Barrel: " << m_muctpi.at("pt_lut_BA").size() << std::endl; + std::cout << " pt EC/FW : " << m_muctpi.at("pt_lut_EF").size() << std::endl; + std::cout << " extra pt lut:" << std::endl; + for(auto x: m_muctpi_Extra_Ptlut) { + std::cout << " " << x.first << ": " << x.second.size() << std::endl; + } + std::cout << " nbits: " << m_muctpi_Nbits.size() << std::endl; + std::cout << "TMC information (" << (m_hasCompleteTmcData? "complete" : "incomplete") << ")" << std::endl; + std::cout << " CTPCore inputs : " << m_Tmc_CtpcoreInputs.size() << std::endl; + std::cout << " CTPIN map entries : " << m_Tmc_CtpinCounters.size() << std::endl; + std::cout << " CTPMON map entries: " << m_Tmc_CtpmonCounters.size() << std::endl; +} + +/** + * Accessors + **/ +bool +TrigConf::L1CTPFiles::hasCompleteCtpData() const { + return m_hasCompleteCtpData; +} + +bool +TrigConf::L1CTPFiles::hasCompleteSmxData() const { + return m_hasCompleteSmxData; +} + +bool +TrigConf::L1CTPFiles::hasCompleteMuctpiData() const { + return m_hasCompleteMuctpiData; +} + +bool +TrigConf::L1CTPFiles::hasCompleteTmcData() const { + return m_hasCompleteTmcData; +} + +const std::vector<uint32_t> & +TrigConf::L1CTPFiles::ctpcore_LUT() const { + return m_Ctpcore_LUT; +} + +const std::vector<uint32_t> & +TrigConf::L1CTPFiles::ctpcore_CAM() const { + return m_Ctpcore_CAM; +} + +const std::vector<uint32_t> & +TrigConf::L1CTPFiles::ctpin_MonSelector_Slot7() const { + return m_Ctpin_MonSelector_Slot7; + +} + +const std::vector<uint32_t> & +TrigConf::L1CTPFiles::ctpin_MonSelector_Slot8() const { + return m_Ctpin_MonSelector_Slot8; +} + +const std::vector<uint32_t> & +TrigConf::L1CTPFiles::ctpin_MonSelector_Slot9() const { + return m_Ctpin_MonSelector_Slot9; +} + +const std::vector<uint32_t> & +TrigConf::L1CTPFiles::ctpin_MonDecoder_Slot7() const { + return m_Ctpin_MonDecoder_Slot7; +} + +const std::vector<uint32_t> & +TrigConf::L1CTPFiles::ctpin_MonDecoder_Slot8() const { + return m_Ctpin_MonDecoder_Slot8; +} + +const std::vector<uint32_t> & +TrigConf::L1CTPFiles::ctpin_MonDecoder_Slot9() const { + return m_Ctpin_MonDecoder_Slot9; +} + +const std::vector<uint32_t> & +TrigConf::L1CTPFiles::ctpmon_MonSelector() const { + return m_Ctpmon_MonSelector; +} + +const std::vector<uint32_t> & +TrigConf::L1CTPFiles::ctpmon_MonDecoder() const { + return m_Ctpmon_MonDecoder; +} + +const std::vector<uint32_t> & +TrigConf::L1CTPFiles::ctpmon_DMX() const { + return m_Ctpmon_DMX; +} + +const std::string & +TrigConf::L1CTPFiles::smx_Output() const { + return m_Smx_Output; +} + +const std::string & +TrigConf::L1CTPFiles::smx_Vhdl_Slot7() const { + return m_Smx_Vhdl_Slot7; +} + +const std::string & +TrigConf::L1CTPFiles::smx_Vhdl_Slot8() const { + return m_Smx_Vhdl_Slot8; +} + +const std::string & +TrigConf::L1CTPFiles::smx_Vhdl_Slot9() const { + return m_Smx_Vhdl_Slot9; +} + +const std::string & +TrigConf::L1CTPFiles::smx_Svfi_Slot7() const { + return m_Smx_Svfi_Slot7; +} + +const std::string & +TrigConf::L1CTPFiles::smx_Svfi_Slot8() const { + return m_Smx_Svfi_Slot8; +} + +const std::string & +TrigConf::L1CTPFiles::smx_Svfi_Slot9() const { + return m_Smx_Svfi_Slot9; +} + +const std::vector<uint32_t> & +TrigConf::L1CTPFiles::muctpiRoi(MuctpiAccess key) const { + return m_muctpi.at(s_keyMap.at(key)); +} + +const std::vector<uint32_t> & +TrigConf::L1CTPFiles::muctpi_Extra_Ptlut(const std::string & sector) const { + return m_muctpi_Extra_Ptlut.at(sector); +} + +const std::vector<uint32_t> & +TrigConf::L1CTPFiles::muctpi_Nbits() const { + return m_muctpi_Nbits; +} + +const std::vector<TrigConf::L1CTPFiles::CTPCoreInput> & +TrigConf::L1CTPFiles::tmc_CtpcoreInputs() const { + return m_Tmc_CtpcoreInputs; +} + +const std::map<std::string, size_t> & +TrigConf::L1CTPFiles::tmc_CtpinCounters() const { + return m_Tmc_CtpinCounters; +} + +const std::map<std::string, size_t> & +TrigConf::L1CTPFiles::tmc_CtpmonCounters() const { + return m_Tmc_CtpmonCounters; +} + + +/** + * Setters + **/ +void +TrigConf::L1CTPFiles::set_HasCompleteCtpData(bool flag) { + m_hasCompleteCtpData = flag; +} + +void +TrigConf::L1CTPFiles::set_HasCompleteSmxData(bool flag) { + m_hasCompleteSmxData = flag; +} + +void +TrigConf::L1CTPFiles::set_HasCompleteMuctpiData(bool flag) { + m_hasCompleteMuctpiData = flag; +} + +void +TrigConf::L1CTPFiles::set_HasCompleteTmcData(bool flag) { + m_hasCompleteTmcData = flag; +} + +void +TrigConf::L1CTPFiles::set_Ctpcore_LUT(std::vector<uint32_t> data) { + m_Ctpcore_LUT = std::move(data); +} + +void +TrigConf::L1CTPFiles::set_Ctpcore_CAM(std::vector<uint32_t> data) { + m_Ctpcore_CAM = std::move(data); +} + +void +TrigConf::L1CTPFiles::set_Ctpin_MonSelector_Slot7(std::vector<uint32_t> data) { + m_Ctpin_MonSelector_Slot7 = std::move(data); +} + +void +TrigConf::L1CTPFiles::set_Ctpin_MonSelector_Slot8(std::vector<uint32_t> data) { + m_Ctpin_MonSelector_Slot8 = std::move(data); +} + +void +TrigConf::L1CTPFiles::set_Ctpin_MonSelector_Slot9(std::vector<uint32_t> data) { + m_Ctpin_MonSelector_Slot9 = std::move(data); +} + +void +TrigConf::L1CTPFiles::set_Ctpin_MonDecoder_Slot7(std::vector<uint32_t> data) { + m_Ctpin_MonDecoder_Slot7 = std::move(data); +} + +void +TrigConf::L1CTPFiles::set_Ctpin_MonDecoder_Slot8(std::vector<uint32_t> data) { + m_Ctpin_MonDecoder_Slot8 = std::move(data); +} + +void +TrigConf::L1CTPFiles::set_Ctpin_MonDecoder_Slot9(std::vector<uint32_t> data) { + m_Ctpin_MonDecoder_Slot9 = std::move(data); +} + +void +TrigConf::L1CTPFiles::set_Ctpmon_MonSelector(std::vector<uint32_t> data) { + m_Ctpmon_MonSelector = std::move(data); +} + +void +TrigConf::L1CTPFiles::set_Ctpmon_MonDecoder(std::vector<uint32_t> data) { + m_Ctpmon_MonDecoder = std::move(data); +} + +void +TrigConf::L1CTPFiles::set_Ctpmon_DMX(std::vector<uint32_t> data) { + m_Ctpmon_DMX = std::move(data); +} + +void +TrigConf::L1CTPFiles::set_Smx_Output(const std::string & data) { + m_Smx_Output = data; +} + +void +TrigConf::L1CTPFiles::set_Smx_Vhdl_Slot7(const std::string & data) { + m_Smx_Vhdl_Slot7 = data; +} + +void +TrigConf::L1CTPFiles::set_Smx_Vhdl_Slot8(const std::string & data) { + m_Smx_Vhdl_Slot8 = data; +} + +void +TrigConf::L1CTPFiles::set_Smx_Vhdl_Slot9(const std::string & data) { + m_Smx_Vhdl_Slot9 = data; +} + +void +TrigConf::L1CTPFiles::set_Smx_Svfi_Slot7(const std::string & data) { + m_Smx_Svfi_Slot7 = data; +} + +void +TrigConf::L1CTPFiles::set_Smx_Svfi_Slot8(const std::string & data) { + m_Smx_Svfi_Slot8 = data; +} + +void +TrigConf::L1CTPFiles::set_Smx_Svfi_Slot9(const std::string & data) { + m_Smx_Svfi_Slot9 = data; +} + +void +TrigConf::L1CTPFiles::set_Muctpi(MuctpiAccess key, std::vector<uint32_t> data) { + m_muctpi[s_keyMap.at(key)] = std::move(data); +} + +void +TrigConf::L1CTPFiles::set_Muctpi_Extra_Ptlut(const std::string & key, std::vector<uint32_t> data) { + m_muctpi_Extra_Ptlut[key] = std::move(data); +} + +void +TrigConf::L1CTPFiles::set_Muctpi_Nbits(std::vector<uint32_t> data) { + m_muctpi_Nbits = std::move(data); +} + +void +TrigConf::L1CTPFiles::set_Tmc_CtpcoreInputs(std::vector<TrigConf::L1CTPFiles::CTPCoreInput> data) { + m_Tmc_CtpcoreInputs = std::move(data); +} + +void +TrigConf::L1CTPFiles::set_Tmc_CtpinCounters(std::map<std::string, size_t> data) { + m_Tmc_CtpinCounters = std::move(data); +} + +void +TrigConf::L1CTPFiles::set_Tmc_CtpmonCounters(std::map<std::string, size_t> data) { + m_Tmc_CtpmonCounters = std::move(data); +} diff --git a/Trigger/TrigConfiguration/TrigConfIO/TrigConfIO/TrigDBCTPFilesLoader.h b/Trigger/TrigConfiguration/TrigConfIO/TrigConfIO/TrigDBCTPFilesLoader.h new file mode 100644 index 0000000000000000000000000000000000000000..17a6136be6c7ab67d5d4cd9c87f992f50494ceaa --- /dev/null +++ b/Trigger/TrigConfiguration/TrigConfIO/TrigConfIO/TrigDBCTPFilesLoader.h @@ -0,0 +1,76 @@ +/* + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration +*/ + +/** + * @file TrigConfIO/TrigDBCTPFilesLoader.h + * @brief Loader class for Trigger configuration (L1 hardware files) from the Trigger DB + */ + +#ifndef TRIGCONFIO_TrigDBCTPFilesLoader_H +#define TRIGCONFIO_TrigDBCTPFilesLoader_H + +#include "TrigConfData/L1CTPFiles.h" + +#include "TrigConfIO/TrigDBLoader.h" + +#include <map> +#include <vector> + +namespace coral { + class IQuery; + class AttributeList; +} + +namespace TrigConf { + + /** + * @brief Loader of trigger configurations from Json files + */ + class TrigDBCTPFilesLoader : public TrigDBLoader { + public: + + /** Constructor */ + TrigDBCTPFilesLoader(const std::string & connection); + + /** Destructor */ + virtual ~TrigDBCTPFilesLoader(); + + /** + * @brief Load content from the Trigger DB into an L1CTPFiles object for a given super master key (SMK) + * @param smk [in] the SMK that should be loaded + * @param ctpfiles [out] the loaded L1CTPFiles + * @param 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 + * @param outFileName [in] if set, an outputfile with the raw data blob is written + */ + bool loadHardwareFiles( unsigned int smk, + L1CTPFiles & ctpfiles, + uint8_t loadMask = 0x0F, + const std::string & outFileName = "") const; + + private: + + void loadCTPFiles(L1CTPFiles & ctpfiles, std::unique_ptr<coral::IQuery> query) const; + + void loadCTPSMX(L1CTPFiles & ctpfiles, std::unique_ptr<coral::IQuery> query) const; + + void loadTMC(L1CTPFiles & ctpfiles, std::unique_ptr<coral::IQuery> query) const; + + void loadMUCTPI(L1CTPFiles & ctpfiles, std::unique_ptr<coral::IQuery> query) 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; + + std::map<size_t, QueryDefinition> m_link_queries; + std::map<size_t, QueryDefinition> m_ctpfiles_queries; + std::map<size_t, QueryDefinition> m_ctpsmx_queries; + std::map<size_t, QueryDefinition> m_muctpi_queries; + std::map<size_t, QueryDefinition> m_tmcsig_queries; + }; + +} + +#endif + diff --git a/Trigger/TrigConfiguration/TrigConfIO/src/TrigDBCTPFilesLoader.cxx b/Trigger/TrigConfiguration/TrigConfIO/src/TrigDBCTPFilesLoader.cxx new file mode 100644 index 0000000000000000000000000000000000000000..ebe559049739bc3f1976bcc0d8aff973871690e8 --- /dev/null +++ b/Trigger/TrigConfiguration/TrigConfIO/src/TrigDBCTPFilesLoader.cxx @@ -0,0 +1,439 @@ +// Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration + +#include "./TrigDBHelper.h" +#include "TrigConfIO/TrigDBCTPFilesLoader.h" +#include "TrigConfData/DataStructure.h" +#include <iterator> + +TrigConf::TrigDBCTPFilesLoader::TrigDBCTPFilesLoader(const std::string & connection) : + TrigDBLoader("TrigDBCTPFilesLoader", connection) +{ + // CTP and MUCTPI hardware files only exist for schema versions >= 3 + + { // links to file tables + auto & q = m_link_queries[3]; + // tables + q.addToTableList ( "SUPER_MASTER_TABLE", "SMT" ); + q.addToTableList ( "L1_MENU", "L1TM" ); + // bind vars + q.extendBinding<unsigned int>("smk"); + // conditions + q.extendCondition("SMT.SMT_ID = :smk AND SMT.SMT_L1_MENU_ID = L1TM.L1TM_ID"); + // attributes + q.extendOutput<unsigned int>( "L1TM.L1TM_CTP_FILES_ID"); + q.extendOutput<unsigned int>( "L1TM.L1TM_CTP_SMX_ID"); + q.extendOutput<unsigned int>( "L1TM.L1TM_MUCTPI_FILES_ID"); + q.extendOutput<unsigned int>( "L1TM.L1TM_TMC_SIGNALS_ID"); + } + + { // ctp files + auto & q = m_ctpfiles_queries[3]; + // tables + q.addToTableList ( "L1_CTP_FILES" ); + // bind vars + q.extendBinding<unsigned int>("id"); + // conditions + q.extendCondition("L1CF_ID = :id"); + // attributes + q.extendOutput<coral::Blob>( "L1CF_LUT" ); + q.extendOutput<coral::Blob>( "L1CF_CAM" ); + q.extendOutput<coral::Blob>( "L1CF_MON_SEL_SLOT7" ); + q.extendOutput<coral::Blob>( "L1CF_MON_SEL_SLOT8" ); + q.extendOutput<coral::Blob>( "L1CF_MON_SEL_SLOT9" ); + q.extendOutput<coral::Blob>( "L1CF_MON_SEL_CTPMON" ); + q.extendOutput<coral::Blob>( "L1CF_MON_DEC_SLOT7" ); + q.extendOutput<coral::Blob>( "L1CF_MON_DEC_SLOT8" ); + q.extendOutput<coral::Blob>( "L1CF_MON_DEC_SLOT9" ); + q.extendOutput<coral::Blob>( "L1CF_MON_DEC_CTPMON" ); + q.extendOutput<coral::Blob>( "L1CF_MON_DMX" ); + } + + { // ctp smx + auto & q = m_ctpsmx_queries[3]; + // tables + q.addToTableList ( "L1_CTP_SMX" ); + // bind vars + q.extendBinding<unsigned int>("id"); + // conditions + q.extendCondition("L1SMX_ID = :id"); + // attributes + q.extendOutput<coral::Blob>( "L1SMX_OUTPUT" ); + q.extendOutput<coral::Blob>( "L1SMX_VHDL_SLOT7" ); + q.extendOutput<coral::Blob>( "L1SMX_VHDL_SLOT8" ); + q.extendOutput<coral::Blob>( "L1SMX_VHDL_SLOT9" ); + q.extendOutput<coral::Blob>( "L1SMX_SVFI_SLOT7" ); + q.extendOutput<coral::Blob>( "L1SMX_SVFI_SLOT8" ); + q.extendOutput<coral::Blob>( "L1SMX_SVFI_SLOT9" ); + } + + { // muctpi + auto & q = m_muctpi_queries[3]; + // tables + q.addToTableList ( "L1_MUCTPI_FILES" ); + // bind vars + q.extendBinding<unsigned int>("id"); + // conditions + q.extendCondition("L1MF_ID = :id"); + // attributes + q.extendOutput<coral::Blob>( "L1MF_DATA" ); + } + + { // tmc + auto & q = m_tmcsig_queries[3]; + // tables + q.addToTableList ( "L1_TMC_SIGNALS" ); + // bind vars + q.extendBinding<unsigned int>("id"); + // conditions + q.extendCondition("L1TMC_ID = :id"); + // attributes + q.extendOutput<coral::Blob>( "L1TMC_DATA" ); + } +} + +TrigConf::TrigDBCTPFilesLoader::~TrigDBCTPFilesLoader() = default; + +bool +TrigConf::TrigDBCTPFilesLoader::loadHardwareFiles (unsigned int smk, + TrigConf::L1CTPFiles & ctpfiles, + uint8_t loadMask, + const std::string & /*outFileName*/ ) const +{ + unsigned int ctpFilesID{0}; + unsigned int ctpSmxID{0}; + unsigned int muctpiID{0}; + unsigned int tmcSignalsID{0}; + + auto session = createDBSession(); + session->transaction().start( /*bool readonly=*/ true); + const size_t sv = schemaVersion(session.get()); + try { + QueryDefinition qdef = getQueryDefinition(sv, m_link_queries); + qdef.setBoundValue<unsigned int>("smk", smk); + auto q = qdef.createQuery( session.get() ); + auto & cursor = q->execute(); + if ( ! cursor.next() ) { + TRG_MSG_ERROR("Tried reading L1 CTPFiles, but super master key " << smk << " is not available" ); + throw TrigConf::NoSMKException("TrigDBCTPFilesLoader: super master key " + std::to_string(smk) + " not available"); + } + const coral::AttributeList& row = cursor.currentRow(); + try { + ctpFilesID = row["L1TM.L1TM_CTP_FILES_ID"].data<unsigned int>(); + } + catch(const coral::AttributeException & e) // NULL content + {} + try { + ctpSmxID = row["L1TM.L1TM_CTP_FILES_ID"].data<unsigned int>(); + } + catch(const coral::AttributeException & e) // NULL content + {} + try { + muctpiID = row["L1TM.L1TM_CTP_FILES_ID"].data<unsigned int>(); + } + catch(const coral::AttributeException & e) // NULL content + {} + try { + tmcSignalsID = row["L1TM.L1TM_CTP_FILES_ID"].data<unsigned int>(); + } + catch(const coral::AttributeException & e) // NULL content + {} + + TRG_MSG_INFO("ID of table L1_CTP_FILES : " << ctpFilesID); + TRG_MSG_INFO("ID of table L1_CTP_SMX : " << ctpSmxID); + TRG_MSG_INFO("ID of table L1_MUCTPI_FILES : " << muctpiID); + TRG_MSG_INFO("ID of table L1_TMC_SIGNALS : " << tmcSignalsID); + } + catch(coral::QueryException & ex) { + TRG_MSG_ERROR("When reading the files table links for super master key " << smk << " a coral::QueryException was caught ( " << ex.what() <<" )" ); + throw TrigConf::QueryException("TrigDBCTPFilesLoader: " + std::string(ex.what())); + } + + if(ctpFilesID>0 && (loadMask & 0x01)!=0 ) { + QueryDefinition qdef = getQueryDefinition(sv, m_ctpfiles_queries); + qdef.setBoundValue<unsigned int>("id", ctpFilesID); + loadCTPFiles(ctpfiles, qdef.createQuery( session.get() ) ); + } + + if(ctpSmxID>0 && (loadMask & 0x02)!=0) { + QueryDefinition qdef = getQueryDefinition(sv, m_ctpsmx_queries); + qdef.setBoundValue<unsigned int>("id", ctpSmxID); + loadCTPSMX(ctpfiles, qdef.createQuery( session.get() ) ); + } + + if(tmcSignalsID>0 && (loadMask & 0x04)!=0) { + QueryDefinition qdef = getQueryDefinition(sv, m_tmcsig_queries); + qdef.setBoundValue<unsigned int>("id", tmcSignalsID); + loadTMC(ctpfiles, qdef.createQuery( session.get() ) ); + } + + if(muctpiID>0 && (loadMask & 0x08)!=0) { + QueryDefinition qdef = getQueryDefinition(sv, m_muctpi_queries); + qdef.setBoundValue<unsigned int>("id", muctpiID); + loadMUCTPI(ctpfiles, qdef.createQuery( session.get() ) ); + } + return true; +} + + +void +TrigConf::TrigDBCTPFilesLoader::loadCTPFiles(L1CTPFiles & ctpfiles, std::unique_ptr<coral::IQuery> query) const +{ + TRG_MSG_INFO("Loading data from table L1_CTP_FILES"); + try + { + auto & cursor = query->execute(); + cursor.next(); + const coral::AttributeList& row = cursor.currentRow(); + { + ctpfiles.set_Ctpcore_LUT( + loadDBFieldIntoVector(row, "L1CF_LUT", L1CTPFiles::CTPCORE_LUT_SIZE) + ); + } + { + ctpfiles.set_Ctpcore_CAM( + loadDBFieldIntoVector(row, "L1CF_CAM", L1CTPFiles::CTPCORE_CAM_SIZE) + ); + } + { + ctpfiles.set_Ctpin_MonSelector_Slot7( + loadDBFieldIntoVector(row, "L1CF_MON_SEL_SLOT7", L1CTPFiles::CTPIN_MONSEL_SIZE) + ); + } + { + ctpfiles.set_Ctpin_MonSelector_Slot8( + loadDBFieldIntoVector(row, "L1CF_MON_SEL_SLOT8", L1CTPFiles::CTPIN_MONSEL_SIZE) + ); + } + { + ctpfiles.set_Ctpin_MonSelector_Slot9( + loadDBFieldIntoVector(row, "L1CF_MON_SEL_SLOT9", L1CTPFiles::CTPIN_MONSEL_SIZE) + ); + } + { + ctpfiles.set_Ctpin_MonDecoder_Slot7( + loadDBFieldIntoVector(row, "L1CF_MON_DEC_SLOT7", L1CTPFiles::CTPIN_MONDEC_SIZE) + ); + } + { + ctpfiles.set_Ctpin_MonDecoder_Slot8( + loadDBFieldIntoVector(row, "L1CF_MON_DEC_SLOT8", L1CTPFiles::CTPIN_MONDEC_SIZE) + ); + } + { + ctpfiles.set_Ctpin_MonDecoder_Slot9( + loadDBFieldIntoVector(row, "L1CF_MON_DEC_SLOT9", L1CTPFiles::CTPIN_MONDEC_SIZE) + ); + } + { + ctpfiles.set_Ctpmon_MonSelector( + loadDBFieldIntoVector(row, "L1CF_MON_SEL_CTPMON", L1CTPFiles::CTPMON_SELECTOR_SIZE) + ); + } + { + ctpfiles.set_Ctpmon_MonDecoder( + loadDBFieldIntoVector(row, "L1CF_MON_DEC_CTPMON", L1CTPFiles::CTPMON_DECODER_SIZE) + ); + } + { + ctpfiles.set_Ctpmon_DMX( + loadDBFieldIntoVector(row, "L1CF_MON_DMX", L1CTPFiles::CTPMON_DMX_SIZE) + ); + } + ctpfiles.set_HasCompleteCtpData(true); + } + catch(coral::QueryException & ex) { + TRG_MSG_ERROR("When reading the L1CTPFiles a coral::QueryException was caught ( " << ex.what() <<" )" ); + throw TrigConf::QueryException("TrigDBCTPFilesLoader: " + std::string(ex.what())); + } +} + +void +TrigConf::TrigDBCTPFilesLoader::loadCTPSMX(L1CTPFiles & ctpfiles, std::unique_ptr<coral::IQuery> query) const { + TRG_MSG_INFO("Loading data from table L1_CTP_SMX"); + try + { + auto & cursor = query->execute(); + cursor.next(); + const coral::AttributeList& row = cursor.currentRow(); + + ctpfiles.set_Smx_Output( loadDBFieldIntoString(row, "L1SMX_OUTPUT") ); + ctpfiles.set_Smx_Vhdl_Slot7( loadDBFieldIntoString(row, "L1SMX_VHDL_SLOT7") ); + ctpfiles.set_Smx_Vhdl_Slot8( loadDBFieldIntoString(row, "L1SMX_VHDL_SLOT8") ); + ctpfiles.set_Smx_Vhdl_Slot9( loadDBFieldIntoString(row, "L1SMX_VHDL_SLOT9") ); + ctpfiles.set_Smx_Svfi_Slot7( loadDBFieldIntoString(row, "L1SMX_SVFI_SLOT7") ); + ctpfiles.set_Smx_Svfi_Slot8( loadDBFieldIntoString(row, "L1SMX_SVFI_SLOT8") ); + ctpfiles.set_Smx_Svfi_Slot9( loadDBFieldIntoString(row, "L1SMX_SVFI_SLOT9") ); + ctpfiles.set_HasCompleteSmxData(true); + } + catch(coral::QueryException & ex) { + TRG_MSG_ERROR("When reading the L1CTPFiles a coral::QueryException was caught ( " << ex.what() <<" )" ); + throw TrigConf::QueryException("TrigDBCTPFilesLoader: " + std::string(ex.what())); + } +} + +void +TrigConf::TrigDBCTPFilesLoader::loadMUCTPI(L1CTPFiles & ctpfiles, std::unique_ptr<coral::IQuery> query) const { + TRG_MSG_INFO("Loading data from table L1_MUCTPI_FILES"); + + bool incomplete = false; + boost::property_tree::ptree pt; + try + { + auto & cursor = query->execute(); + cursor.next(); + const coral::AttributeList& row = cursor.currentRow(); + const coral::Blob & blob = row["L1MF_DATA"].data<coral::Blob>(); + blobToPtree(blob, pt); + } + catch(coral::QueryException & ex) { + TRG_MSG_ERROR("When reading the L1CTPFiles a coral::QueryException was caught ( " << ex.what() <<" )" ); + throw TrigConf::QueryException("TrigDBCTPFilesLoader: " + std::string(ex.what())); + } + DataStructure ds("L1_MUCTPI_FILES", std::move(pt)); + std::vector<std::string> keys = ds.getKeys(); + for(auto k : {L1CTPFiles::RoiMaskA, L1CTPFiles::RoiMaskC, L1CTPFiles::PtLutBarrel, L1CTPFiles::PtLutEndcap}) { + if( auto dv = ds.getList_optional(L1CTPFiles::s_keyMap.at(k)) ) { + keys.erase( std::find(keys.begin(), keys.end(), L1CTPFiles::s_keyMap.at(k)) ); + std::vector<uint32_t> v; + v.reserve(200); + for( auto x : *dv ) { + v.push_back(std::stoul(x.getValue<std::string>(), nullptr, 0)); + } + ctpfiles.set_Muctpi(k, std::move(v)); + } else { + incomplete = true; + } + } + for(const std::string & k : keys) { + if(ds.isNull(k)) { + TRG_MSG_INFO("Attribute " << k << " has null-content"); + incomplete = true; + continue; + } + auto sopt = ds.getAttribute_optional<std::string>(k); + if(k.compare(0, 6, "pt_lut") == 0) { + auto dv = ds.getList(k); + std::vector<uint32_t> v; + v.reserve(200); + for( auto x : dv ) { + v.push_back(std::stoul(x.getValue<std::string>(), nullptr, 0)); + } + ctpfiles.set_Muctpi_Extra_Ptlut(k, std::move(v)); + } else if(k=="multiplicities_nbits") { + auto dv = ds.getList(k); + std::vector<uint32_t> v; + for( auto x : dv ) { + v.push_back(std::stoul(x.getValue<std::string>(), nullptr, 0)); + } + ctpfiles.set_Muctpi_Nbits(std::move(v)); + } + } + ctpfiles.set_HasCompleteMuctpiData(!incomplete); +} + +void +TrigConf::TrigDBCTPFilesLoader::loadTMC(L1CTPFiles & ctpfiles, std::unique_ptr<coral::IQuery> query) const { + TRG_MSG_INFO("Loading data from table L1_TMC_SIGNALS"); + boost::property_tree::ptree pt; + try + { + auto & cursor = query->execute(); + cursor.next(); + const coral::AttributeList& row = cursor.currentRow(); + const coral::Blob & blob = row["L1TMC_DATA"].data<coral::Blob>(); + blobToPtree(blob, pt); + } + catch(coral::QueryException & ex) { + TRG_MSG_ERROR("When reading the L1CTPFiles a coral::QueryException was caught ( " << ex.what() <<" )" ); + throw TrigConf::QueryException("TrigDBCTPFilesLoader: " + std::string(ex.what())); + } + + DataStructure ds("L1_TMC", std::move(pt)); + + // should always be the correct type + if( auto ft = ds.getAttribute<std::string>("fileType"); ft != "inputMapping" ) { + throw TrigConf::ParsingException("TrigDBCTPFilesLoader::loadTMC: json structure of unexpected file type found. Expected 'inputMapping', but found " + ft); + } + + // read the ctpcore inputs + if( auto dv = ds.getList_optional("ctpCoreInputs") ) { + std::vector<TrigConf::L1CTPFiles::CTPCoreInput> ctpcoreInputs; + for(const TrigConf::DataStructure & inp : *dv) { + ctpcoreInputs.push_back( + TrigConf::L1CTPFiles::CTPCoreInput(inp.getAttribute<size_t>("inputNumber"), inp.getAttribute<std::string>("name"), inp.getAttribute<size_t>("bit"), inp.getAttribute<size_t>("phase")) + ); + } + TRG_MSG_INFO("Loading ctpcore inputs " << ctpcoreInputs.size()); + ctpfiles.set_Tmc_CtpcoreInputs(std::move(ctpcoreInputs)); + } + + // read the ctpin map + if( auto dv = ds.getObject_optional("ctpinMap") ) { + std::map<std::string, size_t> ctpin; + for(const std::string & k : dv->getKeys()) { + ctpin[k] = dv->getAttribute<size_t>(k); + } + TRG_MSG_INFO("Loading ctpin counters " << ctpin.size()); + ctpfiles.set_Tmc_CtpinCounters(std::move(ctpin)); + } + + // read the ctpmon map + if( auto dv = ds.getObject_optional("ctpmonMap") ) { + std::map<std::string, size_t> ctpmon; + for(const std::string & k : dv->getKeys()) { + ctpmon[k] = dv->getAttribute<size_t>(k); + } + ctpfiles.set_Tmc_CtpmonCounters(std::move(ctpmon)); + TRG_MSG_INFO("Loading ctp mon counters " << ctpmon.size()); + } + + ctpfiles.set_HasCompleteTmcData(true); +} + +std::vector<uint32_t> +TrigConf::TrigDBCTPFilesLoader::loadDBFieldIntoVector(const coral::AttributeList& row, const std::string& field, size_t size) const { + std::vector<uint32_t> vec; + vec.reserve(size); + try { + TRG_MSG_INFO("Loading " << field << " of size (#words) " << size); + const coral::Blob& blob = row[field].data<coral::Blob>(); + boost::iostreams::stream<boost::iostreams::array_source> stream( + static_cast<const char*> (blob.startingAddress()), + blob.size() + ); + std::string word{""}; + while(stream >> word) { + vec.push_back(std::stoul(word,nullptr, 0)); + } + } + catch(const coral::AttributeException & e) {} // NULL content + if(size != vec.size()) { + TRG_MSG_ERROR("File content from DB of size " << vec.size() << ", but expect " << size); + throw std::runtime_error( "CTPFilesLoader: file of unexpected size" ); + } + + return vec; +} + +std::string +TrigConf::TrigDBCTPFilesLoader::loadDBFieldIntoString(const coral::AttributeList& row, const std::string& field) const { + std::string result; + try { + const coral::Blob& blob = row[field].data<coral::Blob>(); + boost::iostreams::stream<boost::iostreams::array_source> stream( + static_cast<const char*> (blob.startingAddress()), + blob.size() + ); + result = std::string ( + std::istreambuf_iterator<char>(stream.rdbuf()), + std::istreambuf_iterator<char>() + ); + TRG_MSG_INFO("Loading " << field << " of size " << result.size()); + } + catch(const coral::AttributeException & e) {} // NULL content + if(result.empty()) { + TRG_MSG_ERROR("Field " << field << " in DB is empty"); + throw std::runtime_error( "CTPFilesLoader: field " + field + " in DB is empty" ); + } + return result; +} diff --git a/Trigger/TrigConfiguration/TrigConfIO/utils/TriggerMenuRW.cxx b/Trigger/TrigConfiguration/TrigConfIO/utils/TriggerMenuRW.cxx index 2189df1e4345b1a72c2315dbb29a9011f0328202..bb72cfef8a5b2db8141b15f2281b47851bf714e5 100644 --- a/Trigger/TrigConfiguration/TrigConfIO/utils/TriggerMenuRW.cxx +++ b/Trigger/TrigConfiguration/TrigConfIO/utils/TriggerMenuRW.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #include <cstdlib> @@ -13,6 +13,7 @@ #include "TrigConfIO/TrigDBL1PrescalesSetLoader.h" #include "TrigConfIO/TrigDBHLTPrescalesSetLoader.h" #include "TrigConfIO/TrigDBL1BunchGroupSetLoader.h" +#include "TrigConfIO/TrigDBCTPFilesLoader.h" #include "TrigConfData/HLTMenu.h" #include "TrigConfData/L1Menu.h" #include "TrigConfData/L1PrescalesSet.h" @@ -26,7 +27,7 @@ public: ~Config(){} Config(){} - std::vector<std::string> knownParameters { "file", "f", "smk", "l1psk", "hltpsk", "bgsk", "db", "write", "w", "Write", "W", "help", "h", "detail", "d" }; + std::vector<std::string> knownParameters { "file", "f", "smk", "l1psk", "hltpsk", "bgsk", "db", "write", "w", "Write", "W", "help", "h", "detail", "d", "ctp", "c" }; // parameters // input @@ -36,6 +37,7 @@ public: unsigned int hltpsk { 0 }; unsigned int bgsk { 0 }; std::string dbalias { "TRIGGERDBDEV1" }; + bool doCtp { false }; // flag to read CTP files // output bool write { false }; // flag to enable writing @@ -59,25 +61,26 @@ public: void Config::usage() { - cout << "The program needs to be run with the following specifications:\n\n"; - cout << "TriggerMenuRW <options>\n"; - cout << "\n"; - cout << "[Input options]\n"; - cout << " -f|--file file1 [file2 [file3 ...]] ... one or multiple json files\n"; - cout << " --smk smk ... smk \n"; - cout << " --l1psk l1psk ... the L1 prescale key \n"; - cout << " --hltpsk hltpsk ... the HLT prescale key \n"; - cout << " --bgsk bgsk ... the bunchgroup key \n"; - cout << " --db dbalias ... dbalias (default " << dbalias << ") \n"; - cout << "[Output options]\n"; - cout << " -w|--write [base] ... to write out json files, e.g. L1menu[_<base>].json. base is optional.\n"; - cout << " -W|--Write [base] ... to write out json files from the internal structure (only for L1Menu), e.g. L1menu[_<base>].json. base is optional.\n"; - cout << "[Other options]\n"; - cout << " -h|--help ... this help\n"; - cout << " -d|--detail ... prints detailed job options\n"; - cout << "\n\n"; - cout << "Examples\n"; - cout << " --file L1menu.json HLTMenu.json ... read L1Menu.json and HLTMenu.json and show some basic statistics\n"; + cout << "The program needs to be run with the following specifications:\n\n"; + cout << "TriggerMenuRW <options>\n"; + cout << "\n"; + cout << "[Input options]\n"; + cout << " -f|--file file1 [file2 [file3 ...]] ... one or multiple json files\n"; + cout << " --smk smk ... smk \n"; + cout << " --l1psk l1psk ... the L1 prescale key \n"; + cout << " --hltpsk hltpsk ... the HLT prescale key \n"; + cout << " --bgsk bgsk ... the bunchgroup key \n"; + cout << " --db dbalias ... dbalias (default " << dbalias << ") \n"; + cout << " -c|--ctp ... if provided together with the SMK and DB then will read only CTP files from the DB and not the rest of the menu\n"; + cout << "[Output options]\n"; + cout << " -w|--write [base] ... to write out json files, e.g. L1menu[_<base>].json. base is optional.\n"; + cout << " -W|--Write [base] ... to write out json files from the internal structure (only for L1Menu), e.g. L1menu[_<base>].json. base is optional.\n"; + cout << "[Other options]\n"; + cout << " -h|--help ... this help\n"; + cout << " -d|--detail ... prints detailed job options\n"; + cout << "\n\n"; + cout << "Examples\n"; + cout << " --file L1menu.json HLTMenu.json ... read L1Menu.json and HLTMenu.json and show some basic statistics\n"; } @@ -109,6 +112,7 @@ Config::parseProgramOptions(int argc, char* argv[]) { if(paramName == "d" || paramName == "detail" ) { detail = true; continue; } if(paramName == "w" || paramName == "write" ) { write = true; } if(paramName == "W" || paramName == "Write" ) { writeFromDataStructure = true; } + if(paramName == "c" || paramName == "ctp" ) { doCtp = true; } currentParameter = paramName; continue; } @@ -273,7 +277,7 @@ int main(int argc, char** argv) { } } - if( cfg.smk != 0 ) { + if( cfg.smk != 0 && !cfg.doCtp ) { // load config from DB // db menu loader @@ -333,6 +337,12 @@ int main(int argc, char** argv) { } } + if( cfg.smk != 0 && cfg.doCtp ) { + TrigConf::TrigDBCTPFilesLoader dbloader(cfg.dbalias); + TrigConf::L1CTPFiles ctpfiles; + dbloader.loadHardwareFiles(cfg.smk, ctpfiles, 0x0F, outputFileName("CTPFiles", cfg)); + ctpfiles.print(); + } if( cfg.l1psk != 0 ) { // load L1 prescales set from DB