ATLAS Offline Software
Loading...
Searching...
No Matches
AthenaMon.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5// ********************************************************************
6//
7// NAME: AthenaMon.cxx
8//
9// AUTHOR: Rob McPherson & Manuel Diaz
10// Manuel Diaz 01.04.2004 Changed interface access from
11// IAlgTool to IMonitorToolBase
12//
13// ********************************************************************
14
15#include "GaudiKernel/MsgStream.h"
16#include "GaudiKernel/IToolSvc.h"
17#include "GaudiKernel/StatusCode.h"
18#include "GaudiKernel/TypeNameString.h"
19
20#include "AthenaMon.h"
21
22class ISvcLocator;
23// class AlgFactory;
24
25/*---------------------------------------------------------------*/
26AthenaMon::AthenaMon(const std::string& name, ISvcLocator* pSvcLocator) :
27 AthAlgorithm(name, pSvcLocator)
28{
29 MsgStream log(msgSvc(), "AthenaMon");
30
31 declareProperty("AthenaMonTools",m_monToolNames);
32 declareProperty("CheckEveryNoEvents",m_everyNevents=-1);
33 declareProperty("BookHistsinInitialize",m_bookHistsinInitialize=true);
35 declareProperty("THistSvc_OutPutStreamMapping",m_THistSvc_streamnameMapping);
36}
37
38/*---------------------------------------------------------------*/
42
43/*---------------------------------------------------------------*/
45/*---------------------------------------------------------------*/
46{
47 MsgStream log(msgSvc(), name());
48 log << MSG::INFO << "initialize AthenaMon algorithm" << endmsg;
49
50 std::vector<std::string>::iterator it = m_monToolNames.begin();
51 SmartIF<IToolSvc> p_toolSvc{service("ToolSvc")};
52 ATH_CHECK( p_toolSvc.isValid() );
53
54 for (; it < m_monToolNames.end(); ++it) {
55
56 std::string toolname(*it);
57 IMonitorToolBase* p_tool;
58
59 Gaudi::Utils::TypeNameString mytool(toolname);
60
61 StatusCode sc = p_toolSvc->retrieveTool(mytool.type(), mytool.name(), p_tool);
62 if(sc.isFailure()) {
63 log << MSG::FATAL << "Unable to create " << toolname
64 << " AlgTool" << endmsg;
65 return StatusCode::FAILURE;
66 } else {
67
68 log << MSG::INFO
69 << "Tool Name = " << toolname
70 << endmsg;
71
73 if(sc.isFailure()) {
74 log << MSG::WARNING << "Unable to setup the OutPutStreams in "
75 << toolname << endmsg;
76 }
77
78 // shall I book histograms now ?
80 {
81 // Try to book the histograms now. If the tool uses
82 // dynamic booking, it should define bookHists as empty.
83 sc = p_tool->bookHists();
84 if(sc.isFailure()) {
85 log << MSG::WARNING << "Unable to book in " << toolname << endmsg;
86 }
87 }
88 m_monTools.push_back(p_tool);
89 }
90 }
92 return StatusCode::SUCCESS;
93}
94
95/*---------------------------------------------------------------*/
96StatusCode AthenaMon::execute(const EventContext& ctx)
97{
98
99 MsgStream log(msgSvc(), name());
100
101 log << MSG::DEBUG << "executing AthenaMon algorithm" << endmsg;
102
103 //Invoke all declared alg monitoring tools to fill their histograms
104 std::vector<IMonitorToolBase*>::iterator it = m_monTools.begin();
105
106 for (; it < m_monTools.end(); ++it) {
107 if((*it)->preSelector())
108 if((*it)->fillHists(ctx).isFailure()) {
109 log << MSG::WARNING << "Error Filling Histograms" << endmsg;
110 // return StatusCode::FAILURE;
111 }
112 }
113 if(m_eventCounter==0) {
114 //Invoke periodically all declared alg monitoring tools to check their histograms
115 it = m_monTools.begin();
116
117 for (; it < m_monTools.end(); ++it) {
118 log << MSG::INFO << "calling checkHists of tool " << endmsg;
119 StatusCode sc = (*it)->checkHists(false);
120 if(sc.isFailure()) {
121 log << MSG::WARNING << "Can\'t call checkHists of tool." << endmsg;
122 // return StatusCode::FAILURE;
123 }
124 }
126 }
128 return StatusCode::SUCCESS;
129}
130
131/*---------------------------------------------------------------*/
133{
134 MsgStream log(msgSvc(), name());
135
136 log << MSG::INFO << "finalizing AthenaMon algorithm" << endmsg;
137
138 //Invoke all declared alg monitoring tools to finalize their histograms
139 std::vector<IMonitorToolBase*>::iterator it = m_monTools.begin();
140
141 for (; it < m_monTools.end(); ++it) {
142 log << MSG::INFO << "finalizing tool " << endmsg;
143 StatusCode sc = (*it)->finalHists();
144 if(sc.isFailure()) {
145 log << MSG::WARNING << "Can\'t finalize a tool." << endmsg;
146 // return StatusCode::FAILURE;
147 }
148 }
149 //Invoke all declared alg monitoring tools to check their histograms
150 it = m_monTools.begin();
151
152 for (; it < m_monTools.end(); ++it) {
153 log << MSG::INFO << "calling checkHists of tool " << endmsg;
154 StatusCode sc = (*it)->checkHists(true);
155 if(sc.isFailure()) {
156 log << MSG::WARNING << "Can\'t call checkHists of tool." << endmsg;
157 // return StatusCode::FAILURE;
158 }
159 }
160
161 return StatusCode::SUCCESS;
162}
163
164/*---------------------------------------------------------------*/
166{
167 MsgStream log(msgSvc(), name());
168 log << MSG::INFO << "start()" << endmsg;
169
170 // histograms already booked
172 return StatusCode::SUCCESS;
173
174 std::vector<IMonitorToolBase*>::iterator it = m_monTools.begin();
175 for (; it < m_monTools.end(); ++it)
176 if((*it)->bookHists().isFailure())
177 log << MSG::WARNING << "Error Filling Histograms" << endmsg;
178
179 return StatusCode::SUCCESS;
180}
181
182/*---------------------------------------------------------------*/
183StatusCode AthenaMon::stop()
184{
185 MsgStream log(msgSvc(), name());
186 log << MSG::INFO << "stop()" << endmsg;
187
188 std::vector<IMonitorToolBase*>::iterator it = m_monTools.begin();
189 for (; it < m_monTools.end(); ++it)
190 if((*it)->runStat().isFailure())
191 log << MSG::WARNING << "Error calling runStat" << endmsg;
192
193 return StatusCode::SUCCESS;
194}
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
static Double_t sc
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
long m_eventCounter
Definition AthenaMon.h:37
long m_everyNevents
Definition AthenaMon.h:36
virtual StatusCode finalize()
AthenaMon(const std::string &name, ISvcLocator *pSvcLocator)
Definition AthenaMon.cxx:26
std::vector< IMonitorToolBase * > m_monTools
Definition AthenaMon.h:28
virtual StatusCode initialize()
Definition AthenaMon.cxx:44
std::vector< std::string > m_THistSvc_streamnameMapping
Definition AthenaMon.h:34
virtual StatusCode stop()
virtual ~AthenaMon()
Definition AthenaMon.cxx:39
std::vector< std::string > m_monToolNames
Definition AthenaMon.h:32
bool m_bookHistsinInitialize
Definition AthenaMon.h:39
virtual StatusCode execute(const EventContext &ctx)
Execute method.
Definition AthenaMon.cxx:96
virtual StatusCode start()
virtual StatusCode setupOutputStreams(std::vector< std::string > Mapping=std::vector< std::string >())=0
virtual StatusCode bookHists()=0