ATLAS Offline Software
AthenaMon.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 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/ListItem.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  IToolSvc* p_toolSvc;
52  StatusCode sc = service("ToolSvc",p_toolSvc);
53 
54  if (sc.isFailure()) {
55  log << MSG::FATAL << " Tool Service not found " << endmsg;
56  return StatusCode::FAILURE;
57  }
58 
59  for (; it < m_monToolNames.end(); ++it) {
60 
61  std::string toolname(*it);
62  IMonitorToolBase* p_tool;
63 
64  ListItem mytool(toolname);
65 
66  sc = p_toolSvc->retrieveTool(mytool.type(), mytool.name(), p_tool);
67  if(sc.isFailure()) {
68  log << MSG::FATAL << "Unable to create " << toolname
69  << " AlgTool" << endmsg;
70  return StatusCode::FAILURE;
71  } else {
72 
73  log << MSG::INFO
74  << "Tool Name = " << toolname
75  << endmsg;
76 
78  if(sc.isFailure()) {
79  log << MSG::WARNING << "Unable to setup the OutPutStreams in "
80  << toolname << endmsg;
81  }
82 
83  // shall I book histograms now ?
85  {
86  // Try to book the histograms now. If the tool uses
87  // dynamic booking, it should define bookHists as empty.
88  sc = p_tool->bookHists();
89  if(sc.isFailure()) {
90  log << MSG::WARNING << "Unable to book in " << toolname << endmsg;
91  }
92  }
93  m_monTools.push_back(p_tool);
94  }
95  }
97  return StatusCode::SUCCESS;
98 }
99 
100 /*---------------------------------------------------------------*/
102 {
103  MsgStream log(msgSvc(), name());
104 
105  log << MSG::DEBUG << "executing AthenaMon algorithm" << endmsg;
106 
107  //Invoke all declared alg monitoring tools to fill their histograms
109 
110  for (; it < m_monTools.end(); ++it) {
111  if((*it)->preSelector())
112  if((*it)->fillHists().isFailure()) {
113  log << MSG::WARNING << "Error Filling Histograms" << endmsg;
114  // return StatusCode::FAILURE;
115  }
116  }
117  if(m_eventCounter==0) {
118  //Invoke periodically all declared alg monitoring tools to check their histograms
119  it = m_monTools.begin();
120 
121  for (; it < m_monTools.end(); ++it) {
122  log << MSG::INFO << "calling checkHists of tool " << endmsg;
123  StatusCode sc = (*it)->checkHists(false);
124  if(sc.isFailure()) {
125  log << MSG::WARNING << "Can\'t call checkHists of tool." << endmsg;
126  // return StatusCode::FAILURE;
127  }
128  }
130  }
132  return StatusCode::SUCCESS;
133 }
134 
135 /*---------------------------------------------------------------*/
137 {
138  MsgStream log(msgSvc(), name());
139 
140  log << MSG::INFO << "finalizing AthenaMon algorithm" << endmsg;
141 
142  //Invoke all declared alg monitoring tools to finalize their histograms
144 
145  for (; it < m_monTools.end(); ++it) {
146  log << MSG::INFO << "finalizing tool " << endmsg;
147  StatusCode sc = (*it)->finalHists();
148  if(sc.isFailure()) {
149  log << MSG::WARNING << "Can\'t finalize a tool." << endmsg;
150  // return StatusCode::FAILURE;
151  }
152  }
153  //Invoke all declared alg monitoring tools to check their histograms
154  it = m_monTools.begin();
155 
156  for (; it < m_monTools.end(); ++it) {
157  log << MSG::INFO << "calling checkHists of tool " << endmsg;
158  StatusCode sc = (*it)->checkHists(true);
159  if(sc.isFailure()) {
160  log << MSG::WARNING << "Can\'t call checkHists of tool." << endmsg;
161  // return StatusCode::FAILURE;
162  }
163  }
164 
165  return StatusCode::SUCCESS;
166 }
167 
168 /*---------------------------------------------------------------*/
170 {
171  MsgStream log(msgSvc(), name());
172  log << MSG::INFO << "start()" << endmsg;
173 
174  // histograms already booked
176  return StatusCode::SUCCESS;
177 
179  for (; it < m_monTools.end(); ++it)
180  if((*it)->bookHists().isFailure())
181  log << MSG::WARNING << "Error Filling Histograms" << endmsg;
182 
183  return StatusCode::SUCCESS;
184 }
185 
186 /*---------------------------------------------------------------*/
188 {
189  MsgStream log(msgSvc(), name());
190  log << MSG::INFO << "stop()" << endmsg;
191 
193  for (; it < m_monTools.end(); ++it)
194  if((*it)->runStat().isFailure())
195  log << MSG::WARNING << "Error calling runStat" << endmsg;
196 
197  return StatusCode::SUCCESS;
198 }
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:19
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:423
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:136
AthenaMon::initialize
virtual StatusCode initialize()
Definition: AthenaMon.cxx:44
AthenaMon::stop
virtual StatusCode stop()
Definition: AthenaMon.cxx:187
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:195
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:169
DEBUG
#define DEBUG
Definition: page_access.h:11
AthenaMon::execute
virtual StatusCode execute()
Definition: AthenaMon.cxx:101
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