All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
AlgDecorators.cpp
Go to the documentation of this file.
1 // ============================================================================
2 // Include files
3 // ============================================================================
4 // GaudiKernel
5 // ============================================================================
9 #include "GaudiKernel/IAlgTool.h"
10 #include "GaudiKernel/SmartIF.h"
11 #include "GaudiKernel/DataObject.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 GaudiAlgorithm* alg ,
39  const std::string& type ,
40  const std::string& name ,
41  const IInterface* parent ,
42  const bool create )
43 {
44  return alg ? alg -> tool<IAlgTool> ( type , name , parent , create ) : nullptr;
45 }
46 // ============================================================================
47 /* get the tool from GaudiAlgorithm
48  * @param alg GaudiAlgorithm
49  * @param typeAndName tool type/name
50  * @param parent tool parent
51  * @param create flag to create
52  * @return the tool
53  */
54 // ============================================================================
56 ( const GaudiAlgorithm* alg ,
57  const std::string& typeAndName ,
58  const IInterface* parent ,
59  const bool create )
60 {
61  return alg ? alg->tool<IAlgTool>( typeAndName , parent , create ) : nullptr;
62 }
63 // ============================================================================
64 /* get the service from GaudiAlgorithm
65  * @param alg GaudiAlgorithm
66  * @param name service name
67  * @param create flag to create
68  * @return the tool
69  */
70 // ============================================================================
72 ( const GaudiAlgorithm* alg ,
73  const std::string& name ,
74  const bool create )
75 {
76  return alg ? alg -> svc<IInterface> ( name , create ) : nullptr;
77 }
78 // ============================================================================
79 // get all counters form the algorithm
80 // ============================================================================
82 ( const GaudiAlgorithm* alg ,
85 {
86  names.clear () ;
87  out.clear () ;
88  if ( !alg ) { return 0 ; } // RETURN
89  //
90  for ( const auto& cnt : alg->counters() )
91  {
92  names.push_back ( cnt.first ) ;
93  out .push_back ( &cnt.second ) ;
94  }
95  return out.size() ;
96 }
97 // ============================================================================
98 // get all counters form the tool
99 // ============================================================================
101 ( const GaudiTool* alg ,
102  std::vector<std::string>& names ,
104 {
105  names.clear () ;
106  out.clear () ;
107  if ( !alg ) { return 0 ; } // RETURN
108  //
109  for ( const auto& cnt : alg->counters() )
110  {
111  names.push_back ( cnt.first ) ;
112  out .push_back ( &cnt.second ) ;
113  }
114  return out.size() ;
115 }
116 // ============================================================================
117 // get all counters form the algorithm
118 // ============================================================================
120 ( const IAlgorithm* alg ,
121  std::vector<std::string>& names ,
123 {
124  names.clear () ;
125  out.clear () ;
126  return alg ? _counters_a_ ( dynamic_cast<const GaudiAlgorithm*>( alg ) , names , out )
127  : 0;
128 }
129 // ============================================================================
130 // get all counters form the tool
131 // ============================================================================
133 ( const IAlgTool* alg ,
134  std::vector<std::string>& names ,
136 {
137  names.clear () ;
138  out.clear () ;
139  return alg ? _counters_t_ ( dynamic_cast<const GaudiTool*>( alg ) , names , out )
140  : 0;
141 }
142 // ============================================================================
143 // get the counter by name
144 // ============================================================================
146 ( const GaudiAlgorithm* cmp , const std::string& name )
147 {
148  return cmp ? &( cmp -> counter ( name ) ) : nullptr; // RETURN
149 }
150 // ============================================================================
151 // get the counter by name
152 // ============================================================================
154 ( const GaudiTool* cmp , const std::string& name )
155 {
156  return cmp ? &( cmp -> counter ( name ) ) : nullptr; // RETURN
157 }
158 // ============================================================================
159 // get the counter by name
160 // ============================================================================
162 ( const IAlgorithm* cmp , const std::string& name )
163 {
164  return cmp ? _counter_a_ ( dynamic_cast<const GaudiAlgorithm*>( cmp ) , name )
165  : nullptr;
166 }
167 // ============================================================================
168 // get the counter by name
169 // ============================================================================
171 ( const IAlgTool* cmp , const std::string& name )
172 {
173  return cmp ? _counter_t_ ( dynamic_cast<const GaudiTool*>( cmp ) , name )
174  : nullptr;
175 }
176 // ============================================================================
177 // get all tools
178 // ============================================================================
181 {
182  tools.clear() ;
183  if ( cmp ) tools = cmp->tools() ;
184  return tools.size() ; // RETURN
185 }
186 // ============================================================================
187 // get all tools
188 // ============================================================================
191 {
192  tools.clear() ;
193  if ( cmp ) tools = cmp->tools() ;
194  return tools.size() ; // RETURN
195 }
196 // ============================================================================
197 // get all tools
198 // ============================================================================
201 {
202  tools.clear() ;
203  return cmp ? _tools_a_ ( dynamic_cast<const GaudiAlgorithm*> ( cmp ) , tools )
204  : 0;
205 }
206 // ============================================================================
207 // get all tools
208 // ============================================================================
211 {
212  tools.clear() ;
213  return cmp ? _tools_t_ ( dynamic_cast<const GaudiTool*> ( cmp ) , tools ) : 0;
214 }
215 // ============================================================================
216 /* check the data in Transient Event Store
217  * @param alg GaudiAlgorithm
218  * @param location data location in TES
219  * @param useRoonInTes flag to respect RootInTes
220  * @return the data
221  */
222 // ============================================================================
224 ( const GaudiAlgorithm* alg ,
225  const std::string& location ,
226  const bool useRootInTes )
227 {
228  return alg ? alg->exist<DataObject> ( alg->evtSvc() , location , useRootInTes )
229  : false;
230 }
231 // ============================================================================
232 /* get the data from Transient Event Store
233  * @param alg GaudiAlgorithm
234  * @param location data location in TES
235  * @param useRoonInTes flag to respect RootInTes
236  * @return the data
237  */
238 // ============================================================================
240 ( const GaudiAlgorithm* alg ,
241  const std::string& location ,
242  const bool useRootInTes )
243 {
244  return alg ? alg->get<DataObject> ( alg->evtSvc() , location , useRootInTes )
245  : nullptr;
246 }
247 
248 // ============================================================================
249 // The END
250 // ============================================================================
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:465
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:234
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:457
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:27
T size(T...args)
SmartIF< IDataProviderSvc > & evtSvc() const
shortcut for method eventSvc
Definition: Algorithm.h:276
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
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:901
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.