ATLAS Offline Software
Loading...
Searching...
No Matches
AthenaMon.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 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/*---------------------------------------------------------------*/
97{
98 MsgStream log(msgSvc(), name());
99
100 log << MSG::DEBUG << "executing AthenaMon algorithm" << endmsg;
101
102 //Invoke all declared alg monitoring tools to fill their histograms
103 std::vector<IMonitorToolBase*>::iterator it = m_monTools.begin();
104
105 for (; it < m_monTools.end(); ++it) {
106 if((*it)->preSelector())
107 if((*it)->fillHists().isFailure()) {
108 log << MSG::WARNING << "Error Filling Histograms" << endmsg;
109 // return StatusCode::FAILURE;
110 }
111 }
112 if(m_eventCounter==0) {
113 //Invoke periodically all declared alg monitoring tools to check their histograms
114 it = m_monTools.begin();
115
116 for (; it < m_monTools.end(); ++it) {
117 log << MSG::INFO << "calling checkHists of tool " << endmsg;
118 StatusCode sc = (*it)->checkHists(false);
119 if(sc.isFailure()) {
120 log << MSG::WARNING << "Can\'t call checkHists of tool." << endmsg;
121 // return StatusCode::FAILURE;
122 }
123 }
125 }
127 return StatusCode::SUCCESS;
128}
129
130/*---------------------------------------------------------------*/
132{
133 MsgStream log(msgSvc(), name());
134
135 log << MSG::INFO << "finalizing AthenaMon algorithm" << endmsg;
136
137 //Invoke all declared alg monitoring tools to finalize their histograms
138 std::vector<IMonitorToolBase*>::iterator it = m_monTools.begin();
139
140 for (; it < m_monTools.end(); ++it) {
141 log << MSG::INFO << "finalizing tool " << endmsg;
142 StatusCode sc = (*it)->finalHists();
143 if(sc.isFailure()) {
144 log << MSG::WARNING << "Can\'t finalize a tool." << endmsg;
145 // return StatusCode::FAILURE;
146 }
147 }
148 //Invoke all declared alg monitoring tools to check their histograms
149 it = m_monTools.begin();
150
151 for (; it < m_monTools.end(); ++it) {
152 log << MSG::INFO << "calling checkHists of tool " << endmsg;
153 StatusCode sc = (*it)->checkHists(true);
154 if(sc.isFailure()) {
155 log << MSG::WARNING << "Can\'t call checkHists of tool." << endmsg;
156 // return StatusCode::FAILURE;
157 }
158 }
159
160 return StatusCode::SUCCESS;
161}
162
163/*---------------------------------------------------------------*/
165{
166 MsgStream log(msgSvc(), name());
167 log << MSG::INFO << "start()" << endmsg;
168
169 // histograms already booked
171 return StatusCode::SUCCESS;
172
173 std::vector<IMonitorToolBase*>::iterator it = m_monTools.begin();
174 for (; it < m_monTools.end(); ++it)
175 if((*it)->bookHists().isFailure())
176 log << MSG::WARNING << "Error Filling Histograms" << endmsg;
177
178 return StatusCode::SUCCESS;
179}
180
181/*---------------------------------------------------------------*/
182StatusCode AthenaMon::stop()
183{
184 MsgStream log(msgSvc(), name());
185 log << MSG::INFO << "stop()" << endmsg;
186
187 std::vector<IMonitorToolBase*>::iterator it = m_monTools.begin();
188 for (; it < m_monTools.end(); ++it)
189 if((*it)->runStat().isFailure())
190 log << MSG::WARNING << "Error calling runStat" << endmsg;
191
192 return StatusCode::SUCCESS;
193}
#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 execute()
Definition AthenaMon.cxx:96
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 start()
virtual StatusCode setupOutputStreams(std::vector< std::string > Mapping=std::vector< std::string >())=0
virtual StatusCode bookHists()=0