diff --git a/Trigger/TrigCost/TrigCostAnalysis/src/CostData.cxx b/Trigger/TrigCost/TrigCostAnalysis/src/CostData.cxx index 5674e10a90145af8a145ecaf7fce3ba52d7f2502..3b6fd10389accb852a97d3001c5ab3814143e7e5 100644 --- a/Trigger/TrigCost/TrigCostAnalysis/src/CostData.cxx +++ b/Trigger/TrigCost/TrigCostAnalysis/src/CostData.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ #include "CostData.h" @@ -131,11 +131,19 @@ void CostData::setTypeMap( const std::unordered_map<uint32_t, std::string>& type m_typeMapPtr = &typeMap; } -void CostData::setAlgToChainsMap( const std::map<std::string, std::vector<TrigConf::Chain>>& algToChains ) { - m_algToChains = &algToChains; +void CostData::setChainToAlgMap( const std::map<std::string, std::set<size_t>>& chainToAlgIdx ) { + m_chainToAlgIdx = &chainToAlgIdx; } -const std::map<std::string, std::vector<TrigConf::Chain>>& CostData::algToChainsMap() const { - return *m_algToChains; +const std::map<std::string, std::set<size_t>>& CostData::chainToAlgMap() const { + return *m_chainToAlgIdx; +} + +const std::set<TrigCompositeUtils::DecisionID>& CostData::seededChains() const { + return *m_seededChains; +} + +void CostData::setSeededChains(const std::set<TrigCompositeUtils::DecisionID>& seededChains) { + m_seededChains = &seededChains; } \ No newline at end of file diff --git a/Trigger/TrigCost/TrigCostAnalysis/src/CostData.h b/Trigger/TrigCost/TrigCostAnalysis/src/CostData.h index ae498afffeb940ff55fe357ee8d123e7fff4ef3d..eb32bcb4f31cd5dbe259a424195b9d5080f43789 100644 --- a/Trigger/TrigCost/TrigCostAnalysis/src/CostData.h +++ b/Trigger/TrigCost/TrigCostAnalysis/src/CostData.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ #ifndef TRIGCOSTANALYSIS_COSTDATA_H @@ -70,12 +70,22 @@ class CostData { /** * @brief Getter of the alg name to chains map. */ - const std::map<std::string, std::vector<TrigConf::Chain>>& algToChainsMap() const; + const std::map<std::string, std::set<size_t>>& chainToAlgMap() const; /** * @brief Set the alg name to chains map. */ - void setAlgToChainsMap( const std::map<std::string, std::vector<TrigConf::Chain>>& algToChains ); + void setChainToAlgMap( const std::map<std::string, std::set<size_t>>& algToChains ); + + /** + * @brief Getter of the seeded chains set. + */ + const std::set<TrigCompositeUtils::DecisionID>& seededChains() const; + + /** + * @brief Set the seeded chains set. + */ + void setSeededChains(const std::set<TrigCompositeUtils::DecisionID>& seededChains); /** * @brief Getter of map between algorithm (index in costCollection) and ROS requests (indicies in rosCollection) @@ -161,7 +171,8 @@ class CostData { const std::unordered_map<uint32_t, std::string>* m_typeMapPtr; //!< Cached non-owning pointer mapping algorithm instance names to types std::map<size_t, std::vector<size_t>> m_algToRos; //!< Mapping of indexes from m_costCollection to corresponding ROS requests made by algorithm const std::map<std::string, std::vector<uint32_t>>* m_rosToRob; //!< Mapping of ROS corresponding to ROB requests - const std::map<std::string, std::vector<TrigConf::Chain>>* m_algToChains; //!<Mapping of algorithm name to chains + const std::map<std::string, std::set<size_t>>* m_chainToAlgIdx; //!<Mapping of algorithm name to chains + const std::set<TrigCompositeUtils::DecisionID>* m_seededChains; //!<Set of seeded chains to monitor }; diff --git a/Trigger/TrigCost/TrigCostAnalysis/src/TrigCostAnalysis.cxx b/Trigger/TrigCost/TrigCostAnalysis/src/TrigCostAnalysis.cxx index 90498f30f9eff4fd67a6e353972f14cb16c911f1..05a50502263340ae1ed607d0dc1b0defe304b42e 100644 --- a/Trigger/TrigCost/TrigCostAnalysis/src/TrigCostAnalysis.cxx +++ b/Trigger/TrigCost/TrigCostAnalysis/src/TrigCostAnalysis.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ #include "GaudiKernel/ThreadLocalContext.h" @@ -15,6 +15,7 @@ #include "monitors/MonitorGlobal.h" #include "monitors/MonitorThreadOccupancy.h" #include "monitors/MonitorROS.h" +#include "monitors/MonitorChain.h" TrigCostAnalysis::TrigCostAnalysis( const std::string& name, ISvcLocator* pSvcLocator ) : @@ -85,6 +86,13 @@ StatusCode TrigCostAnalysis::start() { } } + // Call TrigConf::HLTUtils::string2hash(chain.name()) for all the chains to cache the hash to name mapping + std::vector<std::string> chainNames; + ATH_CHECK( m_algToChainTool->getAllChainNames(chainNames)); + for (const std::string& chainName : chainNames){ + TrigConf::HLTUtils::string2hash(chainName); + } + // As an initial guess, 25 should be a good uper maximum for the number of expected View instances. ATH_CHECK( checkUpdateMaxView(60) ); return StatusCode::SUCCESS; @@ -150,11 +158,26 @@ StatusCode TrigCostAnalysis::execute() { SG::ReadHandle<xAOD::TrigCompositeContainer> rosDataHandle(m_rosDataKey, context); ATH_CHECK( rosDataHandle.isValid() ); + // Save indexes of algorithm in costDataHandle + std::map<std::string, std::set<size_t>> chainToAlgIdx; + std::map<std::string, std::vector<TrigConf::Chain>> algToChain = m_algToChainTool->getChainsForAllAlgs(context); + for (const xAOD::TrigComposite* tc : *costDataHandle) { + const uint32_t nameHash = tc->getDetail<TrigConf::HLTHash>("alg"); + const std::string name = TrigConf::HLTUtils::hash2string(nameHash, "ALG"); + + for (const TrigConf::Chain& chain : algToChain[name]){ + chainToAlgIdx[chain.name()].insert(tc->index()); + } + } + + const std::set<TrigCompositeUtils::DecisionID> seededChains = m_algToChainTool->retrieveActiveChains(context, "L1"); + const uint32_t onlineSlot = getOnlineSlot( costDataHandle.get() ); CostData costData; ATH_CHECK( costData.set(costDataHandle.get(), rosDataHandle.get(), onlineSlot) ); costData.setRosToRobMap(m_rosToRob); - costData.setAlgToChainsMap(m_algToChainTool->getChainsForAllAlgs()); + costData.setChainToAlgMap(chainToAlgIdx); + costData.setSeededChains(seededChains); costData.setLb( context.eventID().lumi_block() ); costData.setTypeMap( m_algTypeMap ); if (!m_enhancedBiasTool.name().empty() && !m_enhancedBiasTool->isMC()) { @@ -211,6 +234,10 @@ StatusCode TrigCostAnalysis::registerMonitors(MonitoredRange* range) { ATH_CHECK( range->addMonitor(std::make_unique<MonitorROS>("ROS_HLT", range)) ); ATH_MSG_DEBUG("Registering ROS_HLT Monitor for range " << range->getName() << ". Size:" << range->getMonitors().size()); } + if (m_doMonitorChain) { + ATH_CHECK( range->addMonitor(std::make_unique<MonitorChain>("Chain_HLT", range)) ); + ATH_MSG_INFO("Registering Chain_HLT Monitor for range " << range->getName() << ". Size:" << range->getMonitors().size()); + } // if (m_do...) {} return StatusCode::SUCCESS; } diff --git a/Trigger/TrigCost/TrigCostAnalysis/src/TrigCostAnalysis.h b/Trigger/TrigCost/TrigCostAnalysis/src/TrigCostAnalysis.h index 13dfda05de5180fc8e926b19be943625abf537ce..bdfa3790be5de5a4ddaf8ee67974226bc02bb8fe 100644 --- a/Trigger/TrigCost/TrigCostAnalysis/src/TrigCostAnalysis.h +++ b/Trigger/TrigCost/TrigCostAnalysis/src/TrigCostAnalysis.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ #ifndef TRIGCOSTANALYSIS_TRIGCOSTALYSIS_H @@ -102,6 +102,9 @@ class TrigCostAnalysis: public ::AthHistogramAlgorithm { Gaudi::Property<bool> m_doMonitorROS { this, "DoMonitorROS", true, "Monitor Read-Out System" }; + Gaudi::Property<bool> m_doMonitorChain { this, "DoMonitorChain", true, + "Monitor individual chains by instance name" }; + Gaudi::Property<bool> m_useEBWeights { this, "UseEBWeights", true, "Apply Enhanced Bias weights" }; diff --git a/Trigger/TrigCost/TrigCostAnalysis/src/counters/CounterChain.cxx b/Trigger/TrigCost/TrigCostAnalysis/src/counters/CounterChain.cxx new file mode 100644 index 0000000000000000000000000000000000000000..6a2e3e6f9e8627c5ffa1cfc431dc1c3eb16966fb --- /dev/null +++ b/Trigger/TrigCost/TrigCostAnalysis/src/counters/CounterChain.cxx @@ -0,0 +1,20 @@ +/* + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration +*/ + +#include "xAODTrigger/TrigCompositeContainer.h" +#include "TrigDataAccessMonitoring/ROBDataMonitor.h" + +#include "CounterChain.h" + +CounterChain::CounterChain(const std::string& name, const MonitorBase* parent) + : CounterBase(name, parent) +{ + +} + + +StatusCode CounterChain::newEvent(const CostData& /*data*/, size_t /*index*/, const float /*weight*/) { + + return StatusCode::SUCCESS; +} diff --git a/Trigger/TrigCost/TrigCostAnalysis/src/counters/CounterChain.h b/Trigger/TrigCost/TrigCostAnalysis/src/counters/CounterChain.h new file mode 100644 index 0000000000000000000000000000000000000000..23df2764602d06c0a6738b9840bb3e405b4b63e3 --- /dev/null +++ b/Trigger/TrigCost/TrigCostAnalysis/src/counters/CounterChain.h @@ -0,0 +1,52 @@ +/* + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef TRIGCOSTANALYSIS_COUNTERCHAIN_H +#define TRIGCOSTANALYSIS_COUNTERCHAIN_H 1 + +#include "../CounterBase.h" + +/** + * @class CounterAlgorithm + * @brief Concrete implimentation of Counter to monitor all properties of a given Algorithm instance. + */ +class CounterChain : public CounterBase { + public: + /** + * @brief Forbid default constructor. + */ + CounterChain() = delete; + + /** + * @brief Construct counter. + * @param[in] name Counter's name + * @param[in] parent Counter's parent monitor, cached non-owning pointer. + */ + CounterChain(const std::string& name, const MonitorBase* parent); + + /** + * @brief Default destructor. + */ + virtual ~CounterChain() = default; + + /** + * @brief Forbid assignment. + */ + CounterChain& operator=(const CounterChain&) = delete; + + /** + * @brief Forbid copy. + */ + CounterChain(const CounterChain&) = delete; + + /** + * @brief Concrete implimentation. Monitores chain's algorithm at specified index. Expected to match this instances name(). + * @param[in] data Access to event data + * @param[in] index Index within appropriate event data container which is to be analysed by this Counter + * @param[in] weight Global event weight + */ + virtual StatusCode newEvent(const CostData& data, size_t index, const float weight = 1.) override; +}; + +#endif // TRIGCOSTANALYSIS_COUNTERALGORITHM_H diff --git a/Trigger/TrigCost/TrigCostAnalysis/src/monitors/MonitorChain.cxx b/Trigger/TrigCost/TrigCostAnalysis/src/monitors/MonitorChain.cxx new file mode 100644 index 0000000000000000000000000000000000000000..53a90f4b57bda8f4536641386914a034c37d7186 --- /dev/null +++ b/Trigger/TrigCost/TrigCostAnalysis/src/monitors/MonitorChain.cxx @@ -0,0 +1,28 @@ +/* + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration +*/ + +#include "MonitorChain.h" +#include "../counters/CounterChain.h" + +MonitorChain::MonitorChain(const std::string& name, const MonitoredRange* parent) + : MonitorBase(name, parent) { +} + +StatusCode MonitorChain::newEvent(const CostData& data, const float weight) { + + const std::set<TrigCompositeUtils::DecisionID> seededChains = data.seededChains(); + int i = 0; + for (const TrigCompositeUtils::DecisionID& chain : seededChains){ + const std::string chainName = TrigConf::HLTUtils::hash2string(chain); + ATH_CHECK( getCounter(chainName)->newEvent(data, i, weight) ); + ++i; + } + + return StatusCode::SUCCESS; +} + + +std::unique_ptr<CounterBase> MonitorChain::newCounter(const std::string& name) { + return std::make_unique<CounterChain>(name, this); +} diff --git a/Trigger/TrigCost/TrigCostAnalysis/src/monitors/MonitorChain.h b/Trigger/TrigCost/TrigCostAnalysis/src/monitors/MonitorChain.h new file mode 100644 index 0000000000000000000000000000000000000000..3fe9643a8718f63525fa2746ba9d765cd4a8bf9a --- /dev/null +++ b/Trigger/TrigCost/TrigCostAnalysis/src/monitors/MonitorChain.h @@ -0,0 +1,59 @@ +/* + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef TRIGCOSTANALYSIS_MONITORCHAIN_H +#define TRIGCOSTANALYSIS_MONITORCHAIN_H 1 + + +#include "../MonitorBase.h" + +/** + * @class MonitorAlgorithm + * @brief Concrete implementation of Monitor to monitor all Chain instances in an event. + */ +class MonitorChain : public MonitorBase { + public: + /** + * @brief Forbid default constructor. + */ + MonitorChain() = delete; + + /** + * @brief Construct monitor. + * @param[in] name Monitor's name + * @param[in] parent Monitor's parent Range, cached non-owning pointer. + */ + MonitorChain(const std::string& name, const MonitoredRange* parent); + + /** + * @brief Default destructor. + */ + virtual ~MonitorChain() = default; + + /** + * @brief Forbid assignment. + */ + MonitorChain& operator=(const MonitorChain&) = delete; + + /** + * @brief Forbid copy. + */ + MonitorChain(const MonitorChain&) = delete; + + /** + * @brief Concrete dispatch method. Iterate over all Algorithms in event data and dispatch to owned Counters + * @param[in] data Access to event data + * @param[in] weight Global event weight + */ + virtual StatusCode newEvent(const CostData& data, const float weight = 1.) override; + + /** + * @brief Concrete counter instantiation. Mints named counter of CounterAlgorith type. + * @param[in] name Name of Counter to mint. + * @return Owning unique ptr object typed on the CounterBase base class which points to concrete Counter of specialised type. + */ + virtual std::unique_ptr<CounterBase> newCounter(const std::string& name) override; +}; + +#endif // TRIGCOSTANALYSIS_MONITORCHAIN_H diff --git a/Trigger/TrigSteer/TrigCompositeUtils/Root/AlgToChainTool.cxx b/Trigger/TrigSteer/TrigCompositeUtils/Root/AlgToChainTool.cxx index 134d6fe98f7cb3edf38a312779f6341b7b8b2462..5e090921a4d09ec57bf5cd8312ca76c59d37820b 100644 --- a/Trigger/TrigSteer/TrigCompositeUtils/Root/AlgToChainTool.cxx +++ b/Trigger/TrigSteer/TrigCompositeUtils/Root/AlgToChainTool.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ #include "TrigCompositeUtils/AlgToChainTool.h" @@ -45,6 +45,16 @@ StatusCode TrigCompositeUtils::AlgToChainTool::start() { return StatusCode::SUCCESS; } +StatusCode TrigCompositeUtils::AlgToChainTool::getAllChainNames(std::vector<std::string>& chainNames) const { + SG::ReadHandle<TrigConf::HLTMenu> hltMenuHandle = SG::makeHandle( m_HLTMenuKey ); + ATH_CHECK( hltMenuHandle.isValid() ); + + for ( const TrigConf::Chain& chain : *hltMenuHandle ) { + chainNames.push_back(chain.name()); + } + return StatusCode::SUCCESS; +} + std::set<std::string> TrigCompositeUtils::AlgToChainTool::getChainsNamesForAlg(const std::string& algorithmName) const { std::set<std::string> result; @@ -80,7 +90,14 @@ std::vector<TrigConf::Chain> TrigCompositeUtils::AlgToChainTool::getChainsForAlg std::set<std::string> TrigCompositeUtils::AlgToChainTool::getActiveChainsForAlg(const std::string& algorithmName, const EventContext& context) const { std::set<std::string> result; - std::set<std::string> allActiveChains = retrieveActiveChains(context); + std::set<TrigCompositeUtils::DecisionID> allActiveChainsID = retrieveActiveChains(context); + + // Convert DecisionID to names + std::set<std::string> allActiveChains; + for ( const TrigCompositeUtils::DecisionID& id : allActiveChainsID ) { + allActiveChains.insert( HLT::Identifier(id).name() ); + } + std::set<std::string> allAlgChains = getChainsNamesForAlg(algorithmName); // Save the chains that are used by selected algorithm and active @@ -91,7 +108,7 @@ std::set<std::string> TrigCompositeUtils::AlgToChainTool::getActiveChainsForAlg( return result; } -std::set<std::string> TrigCompositeUtils::AlgToChainTool::retrieveActiveChains(const EventContext& context) const { +std::set<TrigCompositeUtils::DecisionID> TrigCompositeUtils::AlgToChainTool::retrieveActiveChains(const EventContext& context, const std::string& collectionName) const { std::set<TrigCompositeUtils::DecisionID> activeChainsID; // Retrieve EventStore and keys @@ -101,11 +118,14 @@ std::set<std::string> TrigCompositeUtils::AlgToChainTool::retrieveActiveChains(c std::vector<std::string> keys; eventStore->keys(static_cast<CLID>( ClassID_traits<TrigCompositeUtils::DecisionContainer>::ID() ), keys); - // Retrieve active chains - std::set<std::string> activeChains; - + // Retrieve active chains name hashes for ( const std::string& key : keys ) { - if( key.find("HLTNav") != 0 || key == "HLTNav_Summary" ) { + // Look for given collection + if ( !collectionName.empty() && key.find("HLTNav_" + collectionName) != 0 ){ + continue; + } + + if( collectionName.empty() && (key.find("HLTNav") != 0 || key == "HLTNav_Summary") ) { continue; } @@ -127,21 +147,35 @@ std::set<std::string> TrigCompositeUtils::AlgToChainTool::retrieveActiveChains(c } } - // Convert DecisionID to names - std::set<std::string> activeChainsNames; - - for ( const TrigCompositeUtils::DecisionID& id : activeChainsID ) { - activeChainsNames.insert( HLT::Identifier(id).name() ); - } - - return activeChainsNames; + return activeChainsID; } -std::map<std::string, std::vector<TrigConf::Chain>> TrigCompositeUtils::AlgToChainTool::getChainsForAllAlgs() const{ +std::map<std::string, std::vector<TrigConf::Chain>> TrigCompositeUtils::AlgToChainTool::getChainsForAllAlgs(const EventContext& context) const{ std::map<std::string, std::vector<TrigConf::Chain>> algToChain; + // Look for chains which were active for any of the algorithms of the sequence + // Name of collection for given sequencer consist sequence's filter's name + std::map<std::string, std::set<TrigCompositeUtils::DecisionID>> seqToActiveChains; + for (const auto& sequence : m_sequencerToChainMap) { + seqToActiveChains[sequence.first] = retrieveActiveChains(context, "F" + sequence.first); + } + for (const auto& algSeqPair : m_algToSequencersMap){ - algToChain[algSeqPair.first] = getChainsForAlg(algSeqPair.first); + std::set<TrigCompositeUtils::DecisionID> activeChains; + for (const std::string& seq : algSeqPair.second){ + // Save all active chains per sequences that algorithm was executed + activeChains.insert(seqToActiveChains[seq].begin(), seqToActiveChains[seq].end()); + } + std::vector<TrigConf::Chain> chainsPerAlg = getChainsForAlg(algSeqPair.first); + + // Remove not active chains + chainsPerAlg.erase( + std::remove_if(chainsPerAlg.begin(), chainsPerAlg.end(), + [&](const TrigConf::Chain& c) { return activeChains.find(c.namehash()) == activeChains.end(); }), + chainsPerAlg.end() + ); + + algToChain[algSeqPair.first] = chainsPerAlg; } return algToChain; } diff --git a/Trigger/TrigSteer/TrigCompositeUtils/TrigCompositeUtils/AlgToChainTool.h b/Trigger/TrigSteer/TrigCompositeUtils/TrigCompositeUtils/AlgToChainTool.h index a81a1afe57671d83f8a5752142825f59a7873188..5543bf80264ca78c4a574a5ecacbcc2ad1b3c62a 100644 --- a/Trigger/TrigSteer/TrigCompositeUtils/TrigCompositeUtils/AlgToChainTool.h +++ b/Trigger/TrigSteer/TrigCompositeUtils/TrigCompositeUtils/AlgToChainTool.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ #ifndef TrigCompositeUtils_AlgToChainTool_h @@ -42,11 +42,14 @@ namespace TrigCompositeUtils { std::set<std::string> getActiveChainsForAlg(const std::string& algorithmName, const EventContext& context) const; /// Request set of chains for all algorithms in the menu - std::map<std::string, std::vector<TrigConf::Chain>> getChainsForAllAlgs() const; + std::map<std::string, std::vector<TrigConf::Chain>> getChainsForAllAlgs(const EventContext& context) const; - private: - std::set<std::string> retrieveActiveChains(const EventContext& context) const; + /// Request set of chains from given navigation collection + std::set<TrigCompositeUtils::DecisionID> retrieveActiveChains(const EventContext& context, const std::string& collectionName = "") const; + + StatusCode getAllChainNames(std::vector<std::string>&) const; + private: SG::ReadHandleKey<TrigConf::HLTMenu> m_HLTMenuKey{ this, "HLTTriggerMenu", "DetectorStore+HLTTriggerMenu", "HLT Menu" }; std::map<std::string, std::vector<TrigConf::Chain>> m_sequencerToChainMap;