The Gaudi Framework  v30r3 (a5ef0a68)
AlgDecorators.cpp
Go to the documentation of this file.
1 // ============================================================================
2 // Include files
3 // ============================================================================
4 // GaudiKernel
5 // ============================================================================
7 #include "GaudiKernel/IAlgTool.h"
10 #include "GaudiKernel/IProperty.h"
11 #include "GaudiKernel/SmartIF.h"
12 // ============================================================================
13 // GaudiAlg
14 // ============================================================================
16 #include "GaudiAlg/GaudiTool.h"
17 // ============================================================================
18 // GaudiPython
19 // ============================================================================
21 // ============================================================================
22 // Disable warnings on gcc
23 // ============================================================================
24 #if defined( __GNUC__ )
25 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
26 #endif
27 // ============================================================================
33 // ============================================================================
34 /* get the tool from GaudiAlgorithm
35  * @param alg GaudiAlgorithm
36  * @param type tool type
37  * @param name tool name
38  * @param parent tool parent
39  * @param create flag to create
40  * @return the tool
41  */
42 // ============================================================================
44  const IInterface* parent, const bool create )
45 {
46  return alg ? alg->tool<IAlgTool>( type, name, parent, create ) : nullptr;
47 }
48 // ============================================================================
49 /* get the tool from GaudiAlgorithm
50  * @param alg GaudiAlgorithm
51  * @param typeAndName tool type/name
52  * @param parent tool parent
53  * @param create flag to create
54  * @return the tool
55  */
56 // ============================================================================
58  const IInterface* parent, const bool create )
59 {
60  return alg ? alg->tool<IAlgTool>( typeAndName, parent, create ) : nullptr;
61 }
62 // ============================================================================
63 /* get the service from GaudiAlgorithm
64  * @param alg GaudiAlgorithm
65  * @param name service name
66  * @param create flag to create
67  * @return the tool
68  */
69 // ============================================================================
71 {
72  return alg ? alg->svc<IInterface>( name, create ) : nullptr;
73 }
74 // ============================================================================
75 // get all counters form the algorithm
76 // ============================================================================
79 {
80  names.clear();
81  out.clear();
82  if ( !alg ) {
83  return 0;
84  } // RETURN
85  //
86  for ( auto& cnt : alg->counters() ) {
87  names.push_back( cnt.first );
88  out.push_back( &( cnt.second.get() ) );
89  }
90  return out.size();
91 }
92 // ============================================================================
93 // get all counters form the tool
94 // ============================================================================
97 {
98  names.clear();
99  out.clear();
100  if ( !alg ) {
101  return 0;
102  } // RETURN
103  //
104  for ( auto& cnt : alg->counters() ) {
105  names.push_back( cnt.first );
106  out.push_back( &( cnt.second.get() ) );
107  }
108  return out.size();
109 }
110 // ============================================================================
111 // get all counters form the algorithm
112 // ============================================================================
115 {
116  names.clear();
117  out.clear();
118  return alg ? _counters_a_( dynamic_cast<const GaudiAlgorithm*>( alg ), names, out ) : 0;
119 }
120 // ============================================================================
121 // get all counters form the tool
122 // ============================================================================
125 {
126  names.clear();
127  out.clear();
128  return alg ? _counters_t_( dynamic_cast<const GaudiTool*>( alg ), names, out ) : 0;
129 }
130 // ============================================================================
131 // get the counter by name
132 // ============================================================================
134 {
135  return cmp ? &( cmp->counter( name ) ) : nullptr; // RETURN
136 }
137 // ============================================================================
138 // get the counter by name
139 // ============================================================================
141 {
142  return cmp ? &( cmp->counter( name ) ) : nullptr; // RETURN
143 }
144 // ============================================================================
145 // get the counter by name
146 // ============================================================================
148 {
149  return cmp ? _counter_a_( dynamic_cast<const GaudiAlgorithm*>( cmp ), name ) : nullptr;
150 }
151 // ============================================================================
152 // get the counter by name
153 // ============================================================================
155 {
156  return cmp ? _counter_t_( dynamic_cast<const GaudiTool*>( cmp ), name ) : nullptr;
157 }
158 // ============================================================================
159 // get all tools
160 // ============================================================================
162 {
163  tools.clear();
164  if ( cmp ) tools = cmp->tools();
165  return tools.size(); // RETURN
166 }
167 // ============================================================================
168 // get all tools
169 // ============================================================================
171 {
172  tools.clear();
173  if ( cmp ) tools = cmp->tools();
174  return tools.size(); // RETURN
175 }
176 // ============================================================================
177 // get all tools
178 // ============================================================================
180 {
181  tools.clear();
182  return cmp ? _tools_a_( dynamic_cast<const GaudiAlgorithm*>( cmp ), tools ) : 0;
183 }
184 // ============================================================================
185 // get all tools
186 // ============================================================================
188 {
189  tools.clear();
190  return cmp ? _tools_t_( dynamic_cast<const GaudiTool*>( cmp ), tools ) : 0;
191 }
192 // ============================================================================
193 /* check the data in Transient Event Store
194  * @param alg GaudiAlgorithm
195  * @param location data location in TES
196  * @param useRoonInTes flag to respect RootInTes
197  * @return the data
198  */
199 // ============================================================================
200 bool GaudiPython::AlgDecorator::exist( const GaudiAlgorithm* alg, const std::string& location, const bool useRootInTes )
201 {
202  return alg ? alg->exist<DataObject>( alg->evtSvc(), location, useRootInTes ) : false;
203 }
204 // ============================================================================
205 /* get the data from Transient Event Store
206  * @param alg GaudiAlgorithm
207  * @param location data location in TES
208  * @param useRoonInTes flag to respect RootInTes
209  * @return the data
210  */
211 // ============================================================================
213  const bool useRootInTes )
214 {
215  return alg ? alg->get<DataObject>( alg->evtSvc(), location, useRootInTes ) : nullptr;
216 }
217 // ============================================================================
218 // Re-enable warnings on gcc
219 // ============================================================================
220 #if defined( __GNUC__ )
221 #pragma GCC diagnostic pop
222 #endif
223 
224 // ============================================================================
225 // The END
226 // ============================================================================
static size_t _counters_a_(const GaudiAlgorithm *alg, std::vector< std::string > &names, Counters &out)
Header file for class GaudiAlgorithm.
static bool exist(const GaudiAlgorithm *alg, const std::string &location, const bool useRootInTes)
get the data from TES
Header file for class GaudiAlgorithm.
static IInterface * svc_(const GaudiAlgorithm *alg, const std::string &name, const bool create=false)
get the service from GaudiAlgorithm
bool exist(IDataProviderSvc *svc, const std::string &location, const bool useRootInTES=true) const
Check the existence of a data object or container in the Gaudi Transient Event Store.
Collection of "decorators" for python algorithms.
static size_t _counters_t_(const GaudiTool *alg, std::vector< std::string > &names, Counters &out)
static IAlgTool * tool_(const GaudiAlgorithm *alg, const std::string &type, const std::string &name, const IInterface *parent=0, const bool create=true)
get the tool from GaudiAlgorithm
STL class.
T push_back(T...args)
StatEntity & counter(const std::string &tag) const
accessor to certain counter by name
Definition: GaudiCommon.h:512
Definition of the basic interface.
Definition: IInterface.h:277
static size_t _tools_t_(const GaudiTool *, Tools &tools)
The useful base class for data processing algorithms.
Gaudi::Utils::GetData< TYPE >::return_type get(IDataProviderSvc *svc, const std::string &location, const bool useRootInTES=true) const
Templated access to the data in Gaudi Transient Store.
T clear(T...args)
static size_t _tools_a_(const GaudiAlgorithm *, Tools &tools)
const std::vector< IAlgTool * > & tools() const
Definition: AlgTool.cpp:460
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:28
T size(T...args)
SmartIF< IDataProviderSvc > & evtSvc() const
shortcut for method eventSvc
Definition: Algorithm.h:280
The interface implemented by the AlgTool base class.
Definition: IAlgTool.h:23
The useful base class for tools.
Definition: GaudiTool.h:101
static StatEntity * _counter_t_(const GaudiTool *alg, const std::string &name)
static DataObject * get_(const GaudiAlgorithm *alg, const std::string &location, const bool useRootInTes)
get the data from TES
const std::vector< IAlgTool * > & tools() const
Definition: Algorithm.cpp:943
backward compatible StatEntity class.
Definition: Counters.h:777
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
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.
static StatEntity * _counter_a_(const GaudiAlgorithm *alg, const std::string &name)
SmartIF< SERVICE > svc(const std::string &name, const bool create=true) const
A useful method for the easy location of services.
const Statistics counters() const
accessor to all counters
Definition: GaudiCommon.h:492