The Gaudi Framework  v30r2 (9eca68f7)
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 // ============================================================================
27 // ============================================================================
28 /* get the tool from GaudiAlgorithm
29  * @param alg GaudiAlgorithm
30  * @param type tool type
31  * @param name tool name
32  * @param parent tool parent
33  * @param create flag to create
34  * @return the tool
35  */
36 // ============================================================================
38  const IInterface* parent, const bool create )
39 {
40  return alg ? alg->tool<IAlgTool>( type, name, parent, create ) : nullptr;
41 }
42 // ============================================================================
43 /* get the tool from GaudiAlgorithm
44  * @param alg GaudiAlgorithm
45  * @param typeAndName tool type/name
46  * @param parent tool parent
47  * @param create flag to create
48  * @return the tool
49  */
50 // ============================================================================
52  const IInterface* parent, const bool create )
53 {
54  return alg ? alg->tool<IAlgTool>( typeAndName, parent, create ) : nullptr;
55 }
56 // ============================================================================
57 /* get the service from GaudiAlgorithm
58  * @param alg GaudiAlgorithm
59  * @param name service name
60  * @param create flag to create
61  * @return the tool
62  */
63 // ============================================================================
65 {
66  return alg ? alg->svc<IInterface>( name, create ) : nullptr;
67 }
68 // ============================================================================
69 // get all counters form the algorithm
70 // ============================================================================
73 {
74  names.clear();
75  out.clear();
76  if ( !alg ) {
77  return 0;
78  } // RETURN
79  //
80  std::map<std::string, StatEntity> ordered_counters{begin( alg->counters() ), end( alg->counters() )};
81  for ( const auto& cnt : ordered_counters ) {
82  names.push_back( cnt.first );
83  out.push_back( &cnt.second );
84  }
85  return out.size();
86 }
87 // ============================================================================
88 // get all counters form the tool
89 // ============================================================================
92 {
93  names.clear();
94  out.clear();
95  if ( !alg ) {
96  return 0;
97  } // RETURN
98  //
99  std::map<std::string, StatEntity> ordered_counters{begin( alg->counters() ), end( alg->counters() )};
100  for ( const auto& cnt : ordered_counters ) {
101  names.push_back( cnt.first );
102  out.push_back( &cnt.second );
103  }
104  return out.size();
105 }
106 // ============================================================================
107 // get all counters form the algorithm
108 // ============================================================================
111 {
112  names.clear();
113  out.clear();
114  return alg ? _counters_a_( dynamic_cast<const GaudiAlgorithm*>( alg ), names, out ) : 0;
115 }
116 // ============================================================================
117 // get all counters form the tool
118 // ============================================================================
121 {
122  names.clear();
123  out.clear();
124  return alg ? _counters_t_( dynamic_cast<const GaudiTool*>( alg ), names, out ) : 0;
125 }
126 // ============================================================================
127 // get the counter by name
128 // ============================================================================
130 {
131  return cmp ? &( cmp->counter( name ) ) : nullptr; // RETURN
132 }
133 // ============================================================================
134 // get the counter by name
135 // ============================================================================
137 {
138  return cmp ? &( cmp->counter( name ) ) : nullptr; // RETURN
139 }
140 // ============================================================================
141 // get the counter by name
142 // ============================================================================
144 {
145  return cmp ? _counter_a_( dynamic_cast<const GaudiAlgorithm*>( cmp ), name ) : nullptr;
146 }
147 // ============================================================================
148 // get the counter by name
149 // ============================================================================
151 {
152  return cmp ? _counter_t_( dynamic_cast<const GaudiTool*>( cmp ), name ) : nullptr;
153 }
154 // ============================================================================
155 // get all tools
156 // ============================================================================
158 {
159  tools.clear();
160  if ( cmp ) tools = cmp->tools();
161  return tools.size(); // RETURN
162 }
163 // ============================================================================
164 // get all tools
165 // ============================================================================
167 {
168  tools.clear();
169  if ( cmp ) tools = cmp->tools();
170  return tools.size(); // RETURN
171 }
172 // ============================================================================
173 // get all tools
174 // ============================================================================
176 {
177  tools.clear();
178  return cmp ? _tools_a_( dynamic_cast<const GaudiAlgorithm*>( cmp ), tools ) : 0;
179 }
180 // ============================================================================
181 // get all tools
182 // ============================================================================
184 {
185  tools.clear();
186  return cmp ? _tools_t_( dynamic_cast<const GaudiTool*>( cmp ), tools ) : 0;
187 }
188 // ============================================================================
189 /* check the data in Transient Event Store
190  * @param alg GaudiAlgorithm
191  * @param location data location in TES
192  * @param useRoonInTes flag to respect RootInTes
193  * @return the data
194  */
195 // ============================================================================
196 bool GaudiPython::AlgDecorator::exist( const GaudiAlgorithm* alg, const std::string& location, const bool useRootInTes )
197 {
198  return alg ? alg->exist<DataObject>( alg->evtSvc(), location, useRootInTes ) : false;
199 }
200 // ============================================================================
201 /* get the data from Transient Event Store
202  * @param alg GaudiAlgorithm
203  * @param location data location in TES
204  * @param useRoonInTes flag to respect RootInTes
205  * @return the data
206  */
207 // ============================================================================
209  const bool useRootInTes )
210 {
211  return alg ? alg->get<DataObject>( alg->evtSvc(), location, useRootInTes ) : nullptr;
212 }
213 
214 // ============================================================================
215 // The END
216 // ============================================================================
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
static const StatEntity * _counter_t_(const GaudiTool *alg, const std::string &name)
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.
const Statistics & counters() const
accessor to all counters
Definition: GaudiCommon.h:496
STL class.
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:515
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:281
static const StatEntity * _counter_a_(const GaudiAlgorithm *alg, const std::string &name)
The interface implemented by the AlgTool base class.
Definition: IAlgTool.h:23
The useful base class for tools.
Definition: GaudiTool.h:101
AttribStringParser::Iterator begin(const AttribStringParser &parser)
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:924
The basic counter used for Monitoring purposes.
Definition: StatEntity.h:65
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.
SmartIF< SERVICE > svc(const std::string &name, const bool create=true) const
A useful method for the easy location of services.