Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
22 class ISvcLocator;
23 // class AlgFactory;
24 
25 /*---------------------------------------------------------------*/
26 AthenaMon::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 /*---------------------------------------------------------------*/
40 {
41 }
42 
43 /*---------------------------------------------------------------*/
45 /*---------------------------------------------------------------*/
46 {
47  MsgStream log(msgSvc(), name());
48  log << MSG::INFO << "initialize AthenaMon algorithm" << endmsg;
49 
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
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
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 
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 /*---------------------------------------------------------------*/
183 {
184  MsgStream log(msgSvc(), name());
185  log << MSG::INFO << "stop()" << endmsg;
186 
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 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
AthenaMon::m_bookHistsinInitialize
bool m_bookHistsinInitialize
Definition: AthenaMon.h:39
python.Constants.FATAL
int FATAL
Definition: Control/AthenaCommon/python/Constants.py:18
AthenaMon::m_THistSvc_streamnameMapping
std::vector< std::string > m_THistSvc_streamnameMapping
Definition: AthenaMon.h:34
IMonitorToolBase::setupOutputStreams
virtual StatusCode setupOutputStreams(std::vector< std::string > Mapping=std::vector< std::string >())=0
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
skel.it
it
Definition: skel.GENtoEVGEN.py:407
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
AthenaMon::AthenaMon
AthenaMon(const std::string &name, ISvcLocator *pSvcLocator)
Definition: AthenaMon.cxx:26
AthenaMon::m_monToolNames
std::vector< std::string > m_monToolNames
Definition: AthenaMon.h:32
StdJOSetup.msgSvc
msgSvc
Provide convenience handles for various services.
Definition: StdJOSetup.py:36
AthenaMon.h
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
AthenaMon::m_eventCounter
long m_eventCounter
Definition: AthenaMon.h:37
AthenaMon::finalize
virtual StatusCode finalize()
Definition: AthenaMon.cxx:131
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
AthenaMon::initialize
virtual StatusCode initialize()
Definition: AthenaMon.cxx:44
AthenaMon::stop
virtual StatusCode stop()
Definition: AthenaMon.cxx:182
AthAlgorithm
Definition: AthAlgorithm.h:47
python.hypoToolDisplay.toolname
def toolname(tool)
Definition: hypoToolDisplay.py:13
IMonitorToolBase
Definition: IMonitorToolBase.h:25
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
test_pyathena.mytool
mytool
Definition: test_pyathena.py:19
AthenaMon::m_monTools
std::vector< IMonitorToolBase * > m_monTools
Definition: AthenaMon.h:28
AthenaMon::start
virtual StatusCode start()
Definition: AthenaMon.cxx:164
DEBUG
#define DEBUG
Definition: page_access.h:11
AthenaMon::execute
virtual StatusCode execute()
Definition: AthenaMon.cxx:96
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
AthenaMon::~AthenaMon
virtual ~AthenaMon()
Definition: AthenaMon.cxx:39
AthenaMon::m_everyNevents
long m_everyNevents
Definition: AthenaMon.h:36
IMonitorToolBase::bookHists
virtual StatusCode bookHists()=0