ATLAS Offline Software
TrigErrorMonTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 #include "TrigErrorMonTool.h"
6 #include "GaudiKernel/IAlgExecStateSvc.h"
7 
8 // =============================================================================
9 // Standard constructor
10 // =============================================================================
11 TrigErrorMonTool::TrigErrorMonTool(const std::string& type, const std::string& name, const IInterface* parent)
12 : base_class(type, name, parent) {}
13 
14 // =============================================================================
15 // Implementation of IStateful::initialize
16 // =============================================================================
18  ATH_CHECK(m_monTool.retrieve(DisableTool{m_monTool.name().empty()}));
19  ATH_CHECK(m_algToChainTool.retrieve(DisableTool{m_algToChainTool.name().empty()}));
20  ATH_CHECK(m_aess.retrieve());
21 
22  if (!m_trigCostSvcHandle.empty()) ATH_CHECK(m_trigCostSvcHandle.retrieve());
23 
24  return StatusCode::SUCCESS;
25 }
26 
27 // =============================================================================
28 // Implementation of IStateful::finalize
29 // =============================================================================
31  ATH_CHECK(m_monTool.release());
32  ATH_CHECK(m_algToChainTool.release());
33  ATH_CHECK(m_aess.release());
34  return StatusCode::SUCCESS;
35 }
36 
37 // =============================================================================
38 // The main method of the tool, ITrigErrorMonTool::algExecErrors
39 // =============================================================================
40 std::unordered_map<std::string_view, StatusCode> TrigErrorMonTool::algExecErrors(const EventContext& eventContext) const {
41  std::unordered_map<std::string_view, StatusCode> algErrors;
42  bool wasTimeout = false;
43  for (const auto& [key, state] : m_aess->algExecStates(eventContext)) {
44  if (!state.execStatus().isSuccess()) {
45  ATH_MSG_DEBUG("Algorithm " << key << " returned StatusCode " << state.execStatus().message()
46  << " in event " << eventContext.eventID());
47  algErrors[key.str()] = state.execStatus();
48  auto monErrorAlgName = Monitored::Scalar<std::string>("ErrorAlgName", key.str());
49  auto monErrorCode = Monitored::Scalar<std::string>("ErrorCode", state.execStatus().message());
50  auto mon = Monitored::Group(m_monTool, monErrorAlgName, monErrorCode);
51 
52  if (m_algToChainTool.isEnabled()) {
53  std::set<std::string> chainNames = m_algToChainTool->getActiveChainsForAlg(key.str(), eventContext);
54  // Monitored::Collection requires operator[]
55  std::vector<std::string> chainNamesVec(chainNames.begin(), chainNames.end());
56 
57  auto monErrorChainNames= Monitored::Collection<std::vector<std::string>>("ErrorChainName", chainNamesVec);
58  Monitored::Group(m_monTool, monErrorChainNames, monErrorCode);
59  }
60 
61  if (state.execStatus() == Athena::Status::TIMEOUT) {
62  // Print report of most time consuming algorithms
63  wasTimeout = true;
64  }
65  }
66  }
67 
68  if (wasTimeout && !m_trigCostSvcHandle.empty()){
69  std::string timeoutReport;
70  if (m_trigCostSvcHandle->generateTimeoutReport(eventContext, timeoutReport) == StatusCode::FAILURE){
71  ATH_MSG_ERROR("Generating timeout algorithm report failed.");
72  }
73  else if (timeoutReport.empty()){
74  ATH_MSG_INFO("CostMonitoring not active in this event. A list of slow algorithms is not available.");
75  }
76  else {
77  ATH_MSG_ERROR(timeoutReport);
78  }
79  }
80 
81  return algErrors;
82 }
TrigErrorMonTool::m_algToChainTool
ToolHandle< TrigCompositeUtils::AlgToChainTool > m_algToChainTool
Definition: TrigErrorMonTool.h:36
TrigDefs::Group
Group
Properties of a chain group.
Definition: GroupProperties.h:13
TrigErrorMonTool::initialize
virtual StatusCode initialize() override
Definition: TrigErrorMonTool.cxx:17
TrigErrorMonTool::m_trigCostSvcHandle
ServiceHandle< ITrigCostSvc > m_trigCostSvcHandle
Definition: TrigErrorMonTool.h:34
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
TrigErrorMonTool.h
TrigErrorMonTool::TrigErrorMonTool
TrigErrorMonTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: TrigErrorMonTool.cxx:11
TrigErrorMonTool::m_monTool
ToolHandle< GenericMonitoringTool > m_monTool
Definition: TrigErrorMonTool.h:35
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TrigErrorMonTool::finalize
virtual StatusCode finalize() override
Definition: TrigErrorMonTool.cxx:30
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TrigErrorMonTool::m_aess
ServiceHandle< IAlgExecStateSvc > m_aess
Definition: TrigErrorMonTool.h:33
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
Athena::Status::TIMEOUT
@ TIMEOUT
Timeout during event processing.
TrigErrorMonTool::algExecErrors
virtual std::unordered_map< std::string_view, StatusCode > algExecErrors(const EventContext &eventContext) const override
Produce a subset of IAlgExecStateSvc::algExecStates with only non-success StatusCodes and fill releva...
Definition: TrigErrorMonTool.cxx:40
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
plotBeamSpotMon.mon
mon
Definition: plotBeamSpotMon.py:67
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
AthStatusCode.h
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37