| The Gaudi Framework v28r2p1 (f1a77ff4)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

GaudiTool.cpp
Go to the documentation of this file.
1 // ============================================================================
2 // Include files
3 // ============================================================================
4 // GaudiKernel
5 // ============================================================================
6 #include "GaudiKernel/IChronoStatSvc.h"
7 #include "GaudiKernel/IIncidentSvc.h"
8 #include "GaudiKernel/IDataProviderSvc.h"
9 #include "GaudiKernel/IHistogramSvc.h"
10 #include "GaudiKernel/INTupleSvc.h"
11 #include "GaudiKernel/IAlgContextSvc.h"
12 #include "GaudiKernel/Bootstrap.h"
13 // ============================================================================
14 // GaudiAlg
15 // ============================================================================
16 #include "GaudiAlg/GaudiTool.h"
17 #include "GaudiAlg/GaudiAlgorithm.h"
18 // ============================================================================
26 // ============================================================================
27 // templated methods
28 // ============================================================================
29 #include "GaudiCommon.icpp"
30 // ============================================================================
31 template class GaudiCommon<AlgTool>;
32 // ============================================================================
39 // ============================================================================
40 namespace GaudiToolServices
41 {
43 const std::string s_EventDataSvc = "EventDataSvc" ;
45 const std::string s_DetectorDataSvc = "DetectorDataSvc" ;
47 const std::string s_ChronoStatSvc = "ChronoStatSvc" ;
49 const std::string s_IncidentSvc = "IncidentSvc" ;
51 const std::string s_HistoSvc = "HistogramDataSvc" ;
52 }
53 // ============================================================================
54 namespace GaudiToolLocal
55 {
56 // ==========================================================================
60 class Counter final
61 {
62 public:
63 // ========================================================================
64 // constructor
65 Counter ( std::string msg = " Misbalance ")
66 : m_message ( std::move(msg) )
67 {};
68 // destructor
69 ~Counter() { report(); }
70 // ========================================================================
71 public:
72 // ========================================================================
74 long increment ( const std::string& object ) { return ++m_map[object] ; }
76 long decrement ( const std::string& object ) { return --m_map[object] ; }
78 long counts ( const std::string& object ) { return m_map[object] ; }
80 void report() const
81 {
83 if ( !GaudiTool::summaryEnabled() ) { return ; } // RETURN
84 //
85 for ( const auto& entry : m_map )
86 {
87 if( entry.second ) {
88 std::cout << "GaudiTool WARNING " << m_message
89 << "'" << entry.first << "' Counts = " << entry.second
90 << std::endl ;
91 }
92 }
93 }
94 // ========================================================================
95 private:
96 // ========================================================================
97 typedef std::map<std::string,long> Map;
98 Map m_map ;
99 std::string m_message ;
100 // ========================================================================
101 };
102 // ==========================================================================
108 static Counter s_InstanceCounter ( " Create/Destroy (mis)balance " ) ;
109 // ==========================================================================
115 static Counter s_FinalizeCounter ( " Initialize/Finalize (mis)balance " ) ;
116 // ==========================================================================
117 }
118 // ============================================================================
120 // ============================================================================
121 bool GaudiTool::s_enableSummary = true ; // summary is enabled
122 // ============================================================================
123 // enable/disable summary
124 // ============================================================================
125 bool GaudiTool::enableSummary ( bool value ) // enable/disable summary
126 {
127 s_enableSummary = value ;
128 return summaryEnabled () ;
129 }
130 // ============================================================================
131 // is summary enabled?
132 // ============================================================================
133 bool GaudiTool::summaryEnabled () // is summary enabled?
134 { return s_enableSummary ; }
135 // ============================================================================
136 // Standard constructor
137 // ============================================================================
138 GaudiTool::GaudiTool ( const std::string& this_type ,
139 const std::string& this_name ,
140 const IInterface* parent )
141 : GaudiCommon<AlgTool> ( this_type , this_name , parent )
142 , m_local ( this_type + "/" + this_name )
143 {
144 // make instance counts
145 GaudiToolLocal::s_InstanceCounter.increment ( m_local ) ;
146 }
147 // ============================================================================
148 // destructor
149 // ============================================================================
150 GaudiTool::~GaudiTool()
151 {
152 GaudiToolLocal::s_InstanceCounter.decrement ( m_local ) ;
153 }
154 // ============================================================================
155 // standard initialization method
156 // ============================================================================
157 StatusCode GaudiTool::initialize ()
158 {
159 // initialize the base class
160 const StatusCode sc = GaudiCommon<AlgTool>::initialize() ;
161 if ( sc.isFailure() ) { return sc; }
162
163 // increment the counter
164 GaudiToolLocal::s_FinalizeCounter.increment( m_local ) ;
165
166 // are we a public tool ?
167 m_isPublic = isPublic();
168
169 // return
170 return sc;
171 }
172 // ============================================================================
173 // standard finalization method
174 // ============================================================================
175 StatusCode GaudiTool::finalize ()
176 {
177 if ( msgLevel(MSG::DEBUG) )
178 debug() << " ==> Finalize the base class GaudiTool " << endmsg;
179
180 // clear "explicit services"
181 m_detSvc.reset();
182 m_chronoSvc.reset();
183 m_incSvc.reset();
184 m_histoSvc.reset();
185
186 // finalize the base class
187 const StatusCode sc = GaudiCommon<AlgTool>::finalize() ;
188 if ( sc.isFailure() ) { return sc; }
189
190 // Decrement the counter
191 GaudiToolLocal::s_FinalizeCounter.decrement( m_local ) ;
192
193 // return
194 return sc;
195 }
196 // ============================================================================
197 // Determines if this tool is public or not (i.e. owned by the ToolSvc).
198 // ============================================================================
199 bool GaudiTool::isPublic() const
200 {
201 const IAlgTool * tool = this;
202 // Recurse down the ownership tree, to see with we ever end up at the ToolSvc
203 bool ownedByToolSvc = false;
204 unsigned int sanityCheck(0);
205 while ( tool && ++sanityCheck < 99999 )
206 {
207 ownedByToolSvc = ( nullptr != dynamic_cast<const IToolSvc*>(tool->parent()) );
208 if ( ownedByToolSvc ) { break; }
209 // if parent is also a tool, try again
210 tool = dynamic_cast<const IAlgTool*>(tool->parent());
211 }
212 return ownedByToolSvc;
213 }
214 // ============================================================================
215 // accessor to detector service
216 // ============================================================================
217 IDataProviderSvc* GaudiTool::detSvc () const
218 {
219 if ( UNLIKELY(!m_detSvc) ) m_detSvc = service( GaudiToolServices::s_DetectorDataSvc , true ) ;
220 return m_detSvc ;
221 }
222 // ============================================================================
223 // The standard N-Tuple
224 // ============================================================================
225 INTupleSvc* GaudiTool::ntupleSvc () const
226 {
227 if ( UNLIKELY(!m_ntupleSvc) ) m_ntupleSvc = service( "NTupleSvc" , true ) ;
228 return m_ntupleSvc ;
229 }
230 // ============================================================================
231 // The standard event collection service
232 // ============================================================================
233 INTupleSvc* GaudiTool::evtColSvc () const
234 {
235 if (UNLIKELY(!m_evtColSvc)) m_evtColSvc = service( "EvtTupleSvc" , true ) ;
236 return m_evtColSvc ;
237 }
238 // ============================================================================
239 // accessor to Incident Service
240 // ============================================================================
241 IIncidentSvc* GaudiTool::incSvc () const
242 {
243 if (UNLIKELY(!m_incSvc)) m_incSvc = service( GaudiToolServices::s_IncidentSvc , true ) ;
244 return m_incSvc ;
245 }
246 // ============================================================================
247 // accessor to Chrono & Stat Service
248 // ============================================================================
249 IChronoStatSvc* GaudiTool::chronoSvc () const
250 {
251 if (UNLIKELY( !m_chronoSvc)) m_chronoSvc = service( GaudiToolServices::s_ChronoStatSvc , true ) ;
252 return m_chronoSvc ;
253 }
254 // ============================================================================
255 // accessor to histogram Service
256 // ============================================================================
257 IHistogramSvc* GaudiTool::histoSvc () const
258 {
259 if (UNLIKELY(!m_histoSvc)) m_histoSvc = service ( GaudiToolServices::s_HistoSvc, true ) ;
260 return m_histoSvc;
261 }
262 // ============================================================================
263 // accessor to Algorithm Context Service
264 // ============================================================================
265 IAlgContextSvc* GaudiTool::contextSvc () const
266 {
267 if (UNLIKELY(!m_contextSvc)) m_contextSvc = service( m_contextSvcName , true ) ;
268 return m_contextSvc;
269 }
270 // ============================================================================
271 // The END
272 // ============================================================================
GaudiTool::chronoSvc
IChronoStatSvc * chronoSvc() const
accessor to Chrono & Stat Service
Definition: GaudiTool.cpp:249
GaudiTool::incSvc
IIncidentSvc * incSvc() const
accessor to Incident Service
Definition: GaudiTool.cpp:241
IToolSvc
The interface implemented by the IToolSvc base class.
Definition: IToolSvc.h:19
GaudiTool::contextSvc
IAlgContextSvc * contextSvc() const
acessor to the Algorithm Context Service
Definition: GaudiTool.cpp:265
GaudiTool.h
Header file for class GaudiAlgorithm.
GaudiTool::m_isPublic
bool m_isPublic
Flag to say if the tool is a public or private tool.
Definition: GaudiTool.h:786
GaudiTool::m_ntupleSvc
SmartIF< INTupleSvc > m_ntupleSvc
pointer to the N-Tuple service
Definition: GaudiTool.h:766
GaudiToolLocal::Counter::counts
long counts(const std::string &object)
current count
Definition: GaudiTool.cpp:78
GaudiToolLocal::Counter::report
void report() const
make a report
Definition: GaudiTool.cpp:80
GaudiTool::histoSvc
IHistogramSvc * histoSvc() const
acessor to the histogram service
Definition: GaudiTool.cpp:257
GaudiToolLocal::Counter::Counter
Counter(std::string msg=" Misbalance ")
Definition: GaudiTool.cpp:65
GaudiAlgorithm.h
Header file for class GaudiAlgorithm.
MSG::DEBUG
Definition: IMessageSvc.h:18
std::endl
T endl(T...args)
UNLIKELY
#define UNLIKELY(x)
Definition: Kernel.h:126
GaudiToolServices::s_ChronoStatSvc
const std::string s_ChronoStatSvc
the default name for Chrono & Stat Service
Definition: GaudiTool.cpp:47
Bootstrap.h
GaudiTool::m_contextSvc
SmartIF< IAlgContextSvc > m_contextSvc
Algorithm Context Service.
Definition: GaudiTool.h:778
std
STL namespace.
GaudiTool::enableSummary
static bool enableSummary(bool)
enable/disable summary
Definition: GaudiTool.cpp:125
GaudiCommon::finalize
StatusCode finalize() override
standard finalization method
Definition: GaudiCommon.icpp:207
GaudiTool::m_incSvc
SmartIF< IIncidentSvc > m_incSvc
pointer to Incident Service
Definition: GaudiTool.h:774
IDataProviderSvc
Data provider interface definition.
Definition: IDataProviderSvc.h:45
GaudiTool::ntupleSvc
INTupleSvc * ntupleSvc() const
Access the standard N-Tuple.
Definition: GaudiTool.cpp:225
std::map< std::string, long >
StatusCode::isFailure
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:84
GaudiToolServices::s_IncidentSvc
const std::string s_IncidentSvc
the default name for Incident Service
Definition: GaudiTool.cpp:49
GaudiToolServices
Collection of default services names to be used for class GaudiTool.
std::string
STL class.
INTupleSvc
Definition: INTupleSvc.h:37
IChronoStatSvc
The IChronoStatSvc is the interface implemented by the ChronoStatService.
Definition: IChronoStatSvc.h:33
GaudiToolLocal::Counter::m_map
Map m_map
Definition: GaudiTool.cpp:98
GaudiTool::evtColSvc
INTupleSvc * evtColSvc() const
Access the standard event collection service.
Definition: GaudiTool.cpp:233
GaudiToolLocal::Counter::m_message
std::string m_message
Definition: GaudiTool.cpp:99
IDataProviderSvc.h
GaudiToolServices::s_HistoSvc
const std::string s_HistoSvc
the default name for Histogram Service
Definition: GaudiTool.cpp:51
IIncidentSvc.h
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
IInterface
Definition of the basic interface.
Definition: IInterface.h:234
AlgTool::service
StatusCode service(const std::string &name, T *&svc, bool createIf=true) const
Access a service by name, creating it if it doesn&#39;t already exist.
Definition: AlgTool.h:131
GaudiTool::GaudiTool
GaudiTool()=delete
no default/copy constructor, no assignment
GaudiTool::~GaudiTool
~GaudiTool() override
destructor, virtual and protected
Definition: GaudiTool.cpp:150
IHistogramSvc
Definition of the IHistogramSvc interface class.
Definition: IHistogramSvc.h:47
GaudiTool::isPublic
bool isPublic() const
Determines if this tool is public or not (i.e. owned by the ToolSvc).
Definition: GaudiTool.cpp:199
GaudiToolLocal::Counter::increment
long increment(const std::string &object)
make the increment
Definition: GaudiTool.cpp:74
GaudiToolServices::s_DetectorDataSvc
const std::string s_DetectorDataSvc
the default name for Detector Data Service
Definition: GaudiTool.cpp:45
GaudiCommon.icpp
GaudiCommon::initialize
StatusCode initialize() override
standard initialization method
Definition: GaudiCommon.icpp:114
GaudiToolLocal::Counter::Map
std::map< std::string, long > Map
Definition: GaudiTool.cpp:97
IAlgContextSvc.h
GaudiTool::s_enableSummary
static bool s_enableSummary
enable printout of summary?
Definition: GaudiTool.h:796
CommonMessagingBase::debug
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Definition: CommonMessaging.h:126
GaudiTool::m_chronoSvc
SmartIF< IChronoStatSvc > m_chronoSvc
pointer to Chrono & Stat Service
Definition: GaudiTool.h:772
GaudiTool::m_histoSvc
SmartIF< IHistogramSvc > m_histoSvc
pointer for histogram service
Definition: GaudiTool.h:776
GaudiToolLocal::Counter
simple local counter
Definition: GaudiTool.cpp:60
AlgTool
Base class from which all the concrete tool classes should be derived.
Definition: AlgTool.h:48
IAlgTool
The interface implemented by the AlgTool base class.
Definition: IAlgTool.h:23
GaudiTool::m_contextSvcName
Gaudi::Property< std::string > m_contextSvcName
Definition: GaudiTool.h:780
AlgTool::parent
const IInterface * parent() const override
Retrieve parent of the sub-algtool.
Definition: AlgTool.cpp:77
GaudiTool::finalize
StatusCode finalize() override
standard finalization method
Definition: GaudiTool.cpp:175
GaudiToolLocal
Definition: GaudiTool.cpp:54
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:8
GaudiTool::m_detSvc
SmartIF< IDataProviderSvc > m_detSvc
pointer to Detector Data Service
Definition: GaudiTool.h:770
GaudiCommon< AlgTool >
GaudiToolServices::s_EventDataSvc
const std::string s_EventDataSvc
the default name for Event Data Service
Definition: GaudiTool.cpp:43
IAlgContextSvc
An abstract interface for Algorithm Context Service.
Definition: IAlgContextSvc.h:23
IChronoStatSvc.h
SmartIF::reset
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:88
GaudiTool::m_local
const std::string m_local
full tool name "type/name"
Definition: GaudiTool.h:791
GaudiTool::m_evtColSvc
SmartIF< INTupleSvc > m_evtColSvc
pointer to the event tag collection service
Definition: GaudiTool.h:768
CommonMessagingBase::msgLevel
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
Definition: CommonMessaging.h:135
GaudiToolLocal::Counter::decrement
long decrement(const std::string &object)
make the decrement
Definition: GaudiTool.cpp:76
GaudiCommon< AlgTool >::tool
TOOL * tool(const std::string &type, const std::string &name, const IInterface *parent=0, bool create=true) const
Useful method for the easy location of tools.
std::cout
IAlgTool::parent
virtual const IInterface * parent() const =0
The parent of the concrete AlgTool.
GaudiTool::summaryEnabled
static bool summaryEnabled()
is summary enabled?
Definition: GaudiTool.cpp:133
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
IIncidentSvc
The interface implemented by the IncidentSvc service.
Definition: IIncidentSvc.h:23
GaudiTool::initialize
StatusCode initialize() override
standard initialization method
Definition: GaudiTool.cpp:157
GaudiTool::detSvc
IDataProviderSvc * detSvc() const
accessor to detector service
Definition: GaudiTool.cpp:217
GaudiToolLocal::Counter::~Counter
~Counter()
Definition: GaudiTool.cpp:69
INTupleSvc.h
IHistogramSvc.h