5#define BOOST_BIND_GLOBAL_PLACEHOLDERS
6#include <boost/property_tree/json_parser.hpp>
8#include "GaudiKernel/ThreadLocalContext.h"
48 ATH_MSG_DEBUG(
"No EnhancedBiasTool. Not doing additional weighting.");
50 ATH_MSG_FATAL(
"Configured to use Enhanced Bias weights. Must supply weighting tool.");
51 return StatusCode::FAILURE;
59 if (hashFile.empty()) {
68 ATH_CHECK(
m_histSvc->regTree(
"/COSTSTREAM/metadata", std::make_unique<TTree>(
"metadata",
"metadata")) );
71 return StatusCode::SUCCESS;
78 using boost::property_tree::ptree;
83 const ptree& menuData = hltMenuHandle->data();
84 for (
const auto& sequencer : menuData.get_child(
"sequencers")) {
86 for (
const auto& alg : sequencer.second) {
88 size_t breakPoint = alg.second.data().find(
'/');
89 std::string algType = alg.second.data().substr(0, breakPoint);
90 std::string algName = alg.second.data().substr(breakPoint+1, alg.second.data().size());
91 std::replace(algType.begin(), algType.end(),
':',
'_');
92 std::replace(algName.begin(), algName.end(),
':',
'_');
95 if (algType.find(
"EventViewCreatorAlgorithm") != std::string::npos) {
103 std::vector<TrigConf::Chain> chains;
110 const size_t legsSize {chain.legMultiplicities().size()};
111 for (
size_t counter = 0; legsSize > 1 && counter < legsSize; ++counter){
120 size_t breakPoint = entry.find(
'/');
121 if (breakPoint != std::string::npos){
122 std::string algType = entry.substr(0, breakPoint);
123 const std::string algName = entry.substr(breakPoint+1, entry.size());
124 std::replace(algType.begin(), algType.end(),
':',
'_');
134 return StatusCode::SUCCESS;
140 return StatusCode::SUCCESS;
144 ATH_MSG_DEBUG(
"Extending maximum View instances from " << current <<
" to " <<
max);
148 std::stringstream
ss;
149 ss << store <<
"_view_" << viewID;
153 std::stringstream
ss;
154 ss << viewID <<
"_StoreGateSvc_Impl";
157 return StatusCode::SUCCESS;
162 double ebWeight = 1.0;
172 std::string histName(hist->GetName());
173 std::string bookingString =
"/COSTSTREAM/" + tDir +
"/" + histName;
175 if (!((
m_histSvc->regHist(bookingString, hist)).isSuccess())) {
176 ATH_MSG_WARNING(
"Problem registering histogram with name " << histName);
185 const EventContext& context = Gaudi::Hive::currentContext();
193 return StatusCode::SUCCESS;
197 ATH_MSG_DEBUG(
"Monitoring event " << context.eventID().event_number() <<
" in LB " << context.eventID().lumi_block() <<
" in range " << range->getName());
208 if (metadataDataHandle.
isValid()){
212 m_hostnames.insert(
tc->getDetail<std::string>(
"hostname"));
213 }
catch (
const std::exception& ) {
214 ATH_MSG_WARNING(
"Missing HLT_RuntimeMetadata EDM hostname for event " << context.eventID().event_number());
220 ATH_MSG_DEBUG(
"Not valid HLT_RuntimeMetadata handle for the event " << context.eventID().event_number());
225 std::map<std::string, std::set<size_t>> chainToAlgIdx;
226 std::map<std::string, std::set<size_t>> chainToUniqAlgs;
227 std::map<std::string, std::map<int16_t, std::set<size_t>>> seqToAlgIdx;
228 std::map<std::string, std::set<std::string>> algToChain;
233 std::map<std::string, std::string> algToSeq;
243 for (
const std::string& chain : algToChain[algName]){
244 chainToAlgIdx[chain].insert(
tc->index());
249 ATH_MSG_DEBUG(
"Algorithm " << algName <<
" executed uniquely for " << *algToChain[algName].begin() <<
" chain");
250 chainToUniqAlgs[*algToChain[algName].begin()].insert(
tc->index());
253 if (algToSeq.count(algName)){
254 const int16_t view =
tc->getDetail<int16_t>(
"view");
255 seqToAlgIdx[algToSeq[algName]][view].insert(
tc->index());
259 const std::set<TrigCompositeUtils::DecisionID> seededChains =
m_algToChainTool->retrieveActiveChains(context,
"HLTNav_L1");
260 std::vector<TrigCompositeUtils::AlgToChainTool::ChainInfo> seededChainsInfo;
263 bool skipMonitoringThisEvent =
false;
266 skipMonitoringThisEvent =
true;
269 for (
auto id : seededChains){
272 seededChainsInfo.push_back(std::move(chainInfo));
283 costData.
setLb( context.eventID().lumi_block() );
287 bool liveTimeIsPerEvent =
true;
288 if (liveTime == 0.0) {
290 liveTimeIsPerEvent =
false;
292 costData.
setLivetime( liveTime, liveTimeIsPerEvent );
295 ATH_CHECK( range->newEvent( costData,
getWeight(context), skipMonitoringThisEvent ) );
301 return StatusCode::SUCCESS;
320 ATH_CHECK( range->addMonitor(std::make_unique<MonitorAlgorithm>(
"Algorithm_HLT", range)) );
321 ATH_MSG_DEBUG(
"Registering Algorithm_HLT Monitor for range " << range->getName() <<
". Size:" << range->getMonitors().size());
324 ATH_CHECK( range->addMonitor(std::make_unique<MonitorAlgorithmClass>(
"Algorithm_Class_HLT", range)) );
325 ATH_MSG_DEBUG(
"Registering Algorithm_Class_HLT Monitor for range " << range->getName() <<
". Size:" << range->getMonitors().size());
328 ATH_CHECK( range->addMonitor(std::make_unique<MonitorGlobal>(
"Global_HLT", range)) );
329 ATH_MSG_DEBUG(
"Registering Global_HLT Monitor for range " << range->getName() <<
". Size:" << range->getMonitors().size());
332 ATH_CHECK( range->addMonitor(std::make_unique<MonitorThreadOccupancy>(
"Thread_Occupancy_HLT", range)) );
333 ATH_MSG_DEBUG(
"Registering Thread_Occupancy_HLT Monitor for range " << range->getName() <<
". Size:" << range->getMonitors().size());
336 ATH_CHECK( range->addMonitor(std::make_unique<MonitorROS>(
"ROS_HLT", range)) );
337 ATH_MSG_DEBUG(
"Registering ROS_HLT Monitor for range " << range->getName() <<
". Size:" << range->getMonitors().size());
340 ATH_CHECK( range->addMonitor(std::make_unique<MonitorChain>(
"Chain_HLT", range)) );
341 ATH_MSG_DEBUG(
"Registering Chain_HLT Monitor for range " << range->getName() <<
". Size:" << range->getMonitors().size());
344 ATH_CHECK( range->addMonitor(std::make_unique<MonitorChainAlgorithm>(
"Chain_Algorithm_HLT", range)) );
345 ATH_MSG_DEBUG(
"Registering Chain_Algorihtm_HLT Monitor for range " << range->getName() <<
". Size:" << range->getMonitors().size());
348 ATH_CHECK( range->addMonitor(std::make_unique<MonitorSequence>(
"Sequence_HLT", range)) );
349 ATH_MSG_DEBUG(
"Registering Sequence_HLT Monitor for range " << range->getName() <<
". Size:" << range->getMonitors().size());
354 for (
const std::unique_ptr<MonitorBase>& monitor : range->getMonitors()){
355 monitor->msg().setLevel(
msg().level());
358 return StatusCode::SUCCESS;
363 std::string rangeName;
365 constexpr bool includeEndOfLB =
false;
370 const EventIDBase::number_type lumiBlock = context.eventID().lumi_block();
373 std::stringstream
ss;
374 ss <<
"LumiBlock_" << std::setfill(
'0') << std::setw(5) << lumiBlockRangeStart;
375 if (includeEndOfLB && lumiBlockRangeStop != lumiBlockRangeStart) {
376 ss <<
"_" << lumiBlockRangeStop;
378 rangeName =
ss.str();
381 std::unordered_map<std::string, std::unique_ptr<MonitoredRange>>
::iterator it;
388 std::make_pair(rangeName, std::make_unique<MonitoredRange>(rangeName,
this))
394 return StatusCode::SUCCESS;
398 range = it->second.get();
399 return StatusCode::SUCCESS;
407 if (costCollection->
size() == 0) {
410 const uint32_t initialSlot = costCollection->
at(0)->getDetail<uint32_t>(
"slot");
412 const uint32_t algSlot =
tc->getDetail<uint32_t>(
"slot");
413 if (algSlot == 0 or algSlot != initialSlot) {
426 std::stringstream
ss;
430 const uint64_t
start =
tc->getDetail<uint64_t>(
"start");
431 const uint64_t stop =
tc->getDetail<uint64_t>(
"stop");
432 const uint32_t slot =
tc->getDetail<uint32_t>(
"slot");
433 const uint64_t start_ms_round = std::llround(
start * 1e-3 );
434 const uint64_t stop_ms_round = std::llround( stop * 1e-3 );
435 const uint32_t threadID =
tc->getDetail<uint32_t>(
"thread");
437 ss <<
"{id:" << algID++;
438 ss <<
", group:" << threadID;
439 ss <<
", className:'slot" << slot <<
"'";
442 ss <<
", duration:" << (stop -
start);
443 ss <<
", start:" << start_ms_round;
444 if (stop_ms_round > start_ms_round) {
445 ss <<
", end:" << stop_ms_round;
447 ss <<
", type:'point'";
449 ss <<
"}," << std::endl;
452 ATH_MSG_DEBUG(
"Full Event Summary for event " << context.eventID().event_number());
456 return StatusCode::SUCCESS;
464 return StatusCode::SUCCESS;
476 std::string hostnamesList =
"";
477 if (m_hostnames.size() > 1){
479 for (
const auto& name : m_hostnames) hostnamesList += name +
",";
480 hostnamesList.pop_back();
481 }
else if (m_hostnames.size() == 1) {
482 hostnamesList = *m_hostnames.begin();
488 if ( hltMenuHandle.
isValid() ){
489 std::stringstream
ss;
490 boost::property_tree::json_parser::write_json(
ss, hltMenuHandle->data());
504 m_metadataTree->Branch(
"ChainAlgorithmMonitor", &ChainAlgorithmMonitor);
506 m_metadataTree->Branch(
"AlgorithmClassMonitor", &AlgorithmClassMonitor);
519 std::string atlasProject = std::getenv(
"AtlasProject");
520 std::string atlasVersion = std::getenv(
"AtlasVersion");
525 std::string processedRanges;
530 std::stringstream
ss;
532 ss << rangePair.first <<
": ";
533 std::string lbrange = rangePair.first.substr(strlen(
"LumiBlock_"));
534 ss <<
" Lumiblocks " << std::stoi(lbrange) <<
" to " << std::stoi(lbrange) +
m_TimeRangeLengthLB <<
", ";
536 processedRanges =
ss.str();
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
boost::property_tree::ptree ptree
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Caches and propagates event data to be used by monitoring algorithms.
bool isMasterSlot() const
void setLb(uint32_t lb)
Setter of effective P1 walltime represented by the current event.
void setSequencersMap(const std::map< std::string, std::map< int16_t, std::set< size_t > > > &seqToAlg)
Set the sequence to alg idx map.
void setCostROSData(const CostROSData &costROSData)
Set ROS to ROB map.
void setTypeMap(const std::unordered_map< uint32_t, std::string > &typeMap)
Set internal type map pointer.
void setChainToAlgMap(const std::map< std::string, std::set< size_t > > &algToChains)
Set the alg name to chains map.
void setSeededChains(const std::vector< TrigCompositeUtils::AlgToChainTool::ChainInfo > &seededChains)
Set the seeded chains set.
void setLivetime(float time, bool liveTimeIsPerEvent)
Setter of effective P1 walltime represented by the current event, or the current lumi block.
void setChainToUniqAlgMap(const std::map< std::string, std::set< size_t > > &algToChains)
Set the chain to its unique alg names map.
StatusCode set(const xAOD::TrigCompositeContainer *costCollection, const xAOD::TrigCompositeContainer *rosCollection, uint32_t onlineSlot)
Cache the cost and ros collections, after formally requesting it from storegate.
const T * at(size_type n) const
Access an element, as an rvalue.
size_type size() const noexcept
Returns the number of elements in the collection.
Container which represents a time range and holds a collection of Monitors which monitor this range.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type get() const
Dereference the pointer, but don't cache anything.
static const std::string hash2string(HLTHash, const std::string &category="TE")
hash function translating identifiers into names (via internal dictionary)
static HLTHash string2hash(const std::string &, const std::string &category="TE")
hash function translating TE names into identifiers
static void file2hashes(const std::string &fileName="hashes2string.txt")
debugging output of internal dictionary
Gaudi::Property< bool > m_useEBWeights
uint32_t getOnlineSlot(const xAOD::TrigCompositeContainer *costCollection) const
Return the slot used to process the event online.
std::unordered_map< std::string, std::unique_ptr< MonitoredRange > > m_monitoredRanges
Owned storage of Ranges.
Gaudi::Property< bool > m_singleTimeRange
Gaudi::Property< std::set< std::string > > m_excludeAlgsFromChain
Gaudi::Property< std::vector< std::string > > m_additionalHashList
SG::ReadHandleKey< xAOD::TrigCompositeContainer > m_metadataDataKey
Gaudi::Property< bool > m_doMonitorAlgorithm
Gaudi::Property< bool > m_doMonitorChainAlgorithm
Gaudi::Property< bool > m_doMonitorROS
virtual StatusCode finalize() final
Currently a noop for this algorithm.
Gaudi::Property< float > m_baseEventWeight
TH1 * bookGetPointer(TH1 *hist, const std::string &tDir="") const
Public method forwarded to this class' AthHistogramAlgorithm::bookGetPointer base.
ServiceHandle< ITHistSvc > m_histSvc
Gaudi::Property< bool > m_doMonitorSequence
std::atomic< size_t > m_maxViewsNumber
What is the maximum number of View instances we've so far cached string hashes to cover?
virtual StatusCode start()
Retrieve menu handle.
void writeMetadata()
Write to outpute tree (if any) the metadata needed downstream.
ToolHandle< IEnhancedBiasWeighter > m_enhancedBiasTool
Gaudi::Property< size_t > m_maxFullEventDumps
Gaudi::Property< std::string > m_additionalHashMap
Gaudi::Property< std::map< std::string, std::vector< uint32_t > > > m_rosToRob
std::mutex m_addHostnameMutex
Mutex to update set below.
StatusCode getRange(const EventContext &context, MonitoredRange *&range)
Return or construct and return a Range for the Context.
std::unordered_map< uint32_t, std::string > m_algTypeMap
Cache of algorithm's type, read from configuration data.
Gaudi::Property< size_t > m_maxTimeRange
Gaudi::Property< bool > m_doMonitorThreadOccupancy
SG::ReadHandleKey< xAOD::TrigCompositeContainer > m_rosDataKey
virtual StatusCode execute() final
Monitor event, unless max range limit reached and event outside of all ranges.
StatusCode registerMonitors(MonitoredRange *range)
Populate a newly minted Range object with all configured Monitors.
Gaudi::Property< bool > m_doMonitorGlobal
Gaudi::Property< size_t > m_TimeRangeLengthLB
StatusCode checkUpdateMaxView(const size_t max)
High watermark for pre-cached string hashes for the SLOT category.
virtual StatusCode initialize() final
Retrieve tools and initialise read handles.
CostROSData m_costROSData
Cached CostROSData class with details needed for ROS monitoring.
SG::ReadHandleKey< xAOD::TrigCompositeContainer > m_costDataKey
TTree * m_metadataTree
Used to write out some metadata needed by post-processing (e.g.
TrigCostAnalysis(const std::string &name, ISvcLocator *pSvcLocator)
Construct TrigCostAnalysis.
SG::ReadHandleKey< TrigConf::HLTMenu > m_HLTMenuKey
ToolHandle< TrigCompositeUtils::AlgToChainTool > m_algToChainTool
std::set< std::string > m_storeIdentifiers
Identifiers of object stores, needed to cache STORE string-hash values.
Gaudi::Property< bool > m_doMonitorChain
StatusCode dumpEvent(const EventContext &context) const
Dump event algorithm execution data in ASCII format.
Gaudi::Property< bool > m_doMonitorAlgorithmClass
Gaudi::Property< uint64_t > m_fullEventDumpProbability
std::atomic< size_t > m_fullEventDumps
Counter to keep track of how many events have been full-dumped.
Gaudi::Property< std::string > m_singleTimeRangeName
float getWeight(const EventContext &context)
Compute global event weight to correct for online prescales.
bool checkDoFullEventDump(const EventContext &context, const CostData &costData)
Check if event dumping should be performed for the current event.
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
HLT::Identifier createLegName(const HLT::Identifier &chainIdentifier, size_t counter)
Generate the HLT::Identifier which corresponds to a specific leg of a given chain.
TrigCompositeContainer_v1 TrigCompositeContainer
Declare the latest version of the container.
TrigComposite_v1 TrigComposite
Declare the latest version of the class.