The Gaudi Framework  v33r0 (d5ea422b)
AlgDecorators.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 // ============================================================================
12 // Include files
13 // ============================================================================
14 // GaudiKernel
15 // ============================================================================
16 #include "GaudiKernel/DataObject.h"
17 #include "GaudiKernel/IAlgTool.h"
18 #include "GaudiKernel/IAlgorithm.h"
19 #include "GaudiKernel/IInterface.h"
20 #include "GaudiKernel/IProperty.h"
21 #include "GaudiKernel/SmartIF.h"
22 // ============================================================================
23 // GaudiAlg
24 // ============================================================================
26 #include "GaudiAlg/GaudiTool.h"
27 // ============================================================================
28 // GaudiPython
29 // ============================================================================
31 // ============================================================================
32 // Disable warnings on gcc
33 // ============================================================================
34 #if defined( __GNUC__ )
35 # pragma GCC diagnostic push ignored "-Wdeprecated-declarations"
36 #endif
37 // ============================================================================
43 // ============================================================================
44 /* get the tool from GaudiAlgorithm
45  * @param alg GaudiAlgorithm
46  * @param type tool type
47  * @param name tool name
48  * @param parent tool parent
49  * @param create flag to create
50  * @return the tool
51  */
52 // ============================================================================
54  const IInterface* parent, const bool create ) {
55  return alg ? alg->tool<IAlgTool>( type, name, parent, create ) : nullptr;
56 }
57 // ============================================================================
58 /* get the tool from GaudiAlgorithm
59  * @param alg GaudiAlgorithm
60  * @param typeAndName tool type/name
61  * @param parent tool parent
62  * @param create flag to create
63  * @return the tool
64  */
65 // ============================================================================
67  const IInterface* parent, const bool create ) {
68  return alg ? alg->tool<IAlgTool>( typeAndName, parent, create ) : nullptr;
69 }
70 // ============================================================================
71 /* get the service from GaudiAlgorithm
72  * @param alg GaudiAlgorithm
73  * @param name service name
74  * @param create flag to create
75  * @return the tool
76  */
77 // ============================================================================
79  return alg ? alg->svc<IInterface>( name, create ) : nullptr;
80 }
81 // ============================================================================
82 // get all counters form the algorithm
83 // ============================================================================
86  names.clear();
87  out.clear();
88  if ( !alg ) return 0;
89  alg->forEachCounter( [&]( const std::string& name, auto& counter ) {
90  names.push_back( name );
91  out.push_back( &counter );
92  } );
93  return out.size();
94 }
95 // ============================================================================
96 // get all counters form the tool
97 // ============================================================================
100  names.clear();
101  out.clear();
102  if ( !alg ) return 0;
103  alg->forEachCounter( [&]( const std::string& name, auto& counter ) {
104  names.push_back( name );
105  out.push_back( &counter );
106  } );
107  return out.size();
108 }
109 // ============================================================================
110 // get all counters form the algorithm
111 // ============================================================================
114  names.clear();
115  out.clear();
116  return alg ? _counters_a_( dynamic_cast<const GaudiAlgorithm*>( alg ), names, out ) : 0;
117 }
118 // ============================================================================
119 // get all counters form the tool
120 // ============================================================================
123  names.clear();
124  out.clear();
125  return alg ? _counters_t_( dynamic_cast<const GaudiTool*>( alg ), names, out ) : 0;
126 }
127 // ============================================================================
128 // get the counter by name
129 // ============================================================================
131  return cmp ? &( cmp->counter( name ) ) : nullptr; // RETURN
132 }
133 // ============================================================================
134 // get the counter by name
135 // ============================================================================
137  return cmp ? &( cmp->counter( name ) ) : nullptr; // RETURN
138 }
139 // ============================================================================
140 // get the counter by name
141 // ============================================================================
143  return cmp ? _counter_a_( dynamic_cast<const GaudiAlgorithm*>( cmp ), name ) : nullptr;
144 }
145 // ============================================================================
146 // get the counter by name
147 // ============================================================================
149  return cmp ? _counter_t_( dynamic_cast<const GaudiTool*>( cmp ), name ) : nullptr;
150 }
151 // ============================================================================
152 // get all tools
153 // ============================================================================
155  tools.clear();
156  if ( cmp ) tools = cmp->tools();
157  return tools.size(); // RETURN
158 }
159 // ============================================================================
160 // get all tools
161 // ============================================================================
163  tools.clear();
164  if ( cmp ) tools = cmp->tools();
165  return tools.size(); // RETURN
166 }
167 // ============================================================================
168 // get all tools
169 // ============================================================================
171  tools.clear();
172  return cmp ? _tools_a_( dynamic_cast<const GaudiAlgorithm*>( cmp ), tools ) : 0;
173 }
174 // ============================================================================
175 // get all tools
176 // ============================================================================
178  tools.clear();
179  return cmp ? _tools_t_( dynamic_cast<const GaudiTool*>( cmp ), tools ) : 0;
180 }
181 // ============================================================================
182 /* check the data in Transient Event Store
183  * @param alg GaudiAlgorithm
184  * @param location data location in TES
185  * @param useRoonInTes flag to respect RootInTes
186  * @return the data
187  */
188 // ============================================================================
190  const bool useRootInTes ) {
191  return alg ? alg->exist<DataObject>( alg->evtSvc(), location, useRootInTes ) : false;
192 }
193 // ============================================================================
194 /* get the data from Transient Event Store
195  * @param alg GaudiAlgorithm
196  * @param location data location in TES
197  * @param useRoonInTes flag to respect RootInTes
198  * @return the data
199  */
200 // ============================================================================
202  const bool useRootInTes ) {
203  return alg ? alg->get<DataObject>( alg->evtSvc(), location, useRootInTes ) : nullptr;
204 }
205 // ============================================================================
206 // Re-enable warnings on gcc
207 // ============================================================================
208 #if defined( __GNUC__ )
209 # pragma GCC diagnostic pop
210 #endif
211 
212 // ============================================================================
213 // The END
214 // ============================================================================
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
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)
Definition of the basic interface.
Definition: IInterface.h:254
static size_t _tools_t_(const GaudiTool *, Tools &tools)
The useful base class for data processing algorithms.
T clear(T... args)
static size_t _tools_a_(const GaudiAlgorithm *, Tools &tools)
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:38
StatEntity & counter(const std::string &tag) const
accessor to certain counter by name
Definition: GaudiCommon.h:516
T size(T... args)
The interface implemented by the AlgTool base class.
Definition: IAlgTool.h:33
The useful base class for tools.
Definition: GaudiTool.h:111
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
backward compatible StatEntity class.
Definition: StatEntity.h:18
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:40
static StatEntity * _counter_a_(const GaudiAlgorithm *alg, const std::string &name)