Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
GetAlgs.cpp
Go to the documentation of this file.
1 // ============================================================================
2 // Include files
3 // ============================================================================
4 // STD&STL
5 // ============================================================================
6 #include <algorithm>
7 #include <functional>
8 // ============================================================================
9 // GaudiKernel
10 // ============================================================================
12 #include "GaudiKernel/IAlgorithm.h"
13 // ============================================================================
14 // GaudiAlg
15 // ============================================================================
16 #include "GaudiAlg/GetAlg.h"
17 #include "GaudiAlg/GetAlgs.h"
18 // ============================================================================
20 #include "GaudiAlg/GaudiHistoAlg.h"
22 #include "GaudiAlg/GaudiTupleAlg.h"
23 #include "GaudiAlg/Sequencer.h"
24 // ============================================================================
30 // ============================================================================
31 namespace {
32  template <class TYPE>
33  TYPE* getAlg( const IAlgContextSvc* svc ) {
34  if ( !svc ) { return nullptr; } // RETURN
35  const auto& algs = svc->algorithms();
36  auto it = std::find_if( algs.rbegin(), algs.rend(), Gaudi::Utils::AlgTypeSelector<TYPE>{} );
37  if ( algs.rend() == it ) { return nullptr; } // RETURN
38  IAlgorithm* alg = *it;
39  return dynamic_cast<TYPE*>( alg ); // RETURN
40  }
41 } // namespace
42 // ============================================================================
43 /* simple function to extract the last active
44  * GaudiAlgorithm from the context
45  *
46  * @code
47  *
48  * // get the context service:
49  * const IAlgContextSvc* svc = ... ;
50  *
51  * GaudiAlgorithm* ga = getGaudiAlg ( svc ) ;
52  *
53  * @endcode
54  *
55  * @author Vanya BELYAEV ibelyaev@physics.syr.edu
56  * @date 2007-09-07
57  */
58 // ============================================================================
59 GaudiAlgorithm* Gaudi::Utils::getGaudiAlg( const IAlgContextSvc* svc ) { return getAlg<GaudiAlgorithm>( svc ); }
60 // ============================================================================
61 /* simple function to extract the last active
62  * GaudiHistoAlg from the context
63  *
64  * @code
65  *
66  * // get the context service:
67  * const IAlgContextSvc* svc = ... ;
68  *
69  * GaudiHistoAlg* ha = getHistoAlg ( svc ) ;
70  *
71  * @endcode
72  *
73  * @author Vanya BELYAEV ibelyaev@physics.syr.edu
74  * @date 2007-09-07
75  */
76 // ============================================================================
77 GaudiHistoAlg* Gaudi::Utils::getHistoAlg( const IAlgContextSvc* svc ) { return getAlg<GaudiHistoAlg>( svc ); }
78 // ============================================================================
79 /* simple function to extract the last active
80  * GaudiTupleAlg from the context
81  *
82  * @code
83  *
84  * // get the context service:
85  * const IAlgContextSvc* svc = ... ;
86  *
87  * GaudiTupleAlg* ta = getTupleAlg ( svc ) ;
88  *
89  * @endcode
90  *
91  * @author Vanya BELYAEV ibelyaev@physics.syr.edu
92  * @date 2007-09-07
93  */
94 // ============================================================================
95 GaudiTupleAlg* Gaudi::Utils::getTupleAlg( const IAlgContextSvc* svc ) { return getAlg<GaudiTupleAlg>( svc ); }
96 // ============================================================================
97 /* simple function to extract the last active
98  * GaudiSequencer from the context
99  *
100  * @code
101  *
102  * // get the context service:
103  * const IAlgContextSvc* svc = ... ;
104  *
105  * GaudiSequencer* sa = getGaudiSequencer ( svc ) ;
106  *
107  * @endcode
108  *
109  * @author Vanya BELYAEV ibelyaev@physics.syr.edu
110  * @date 2007-09-07
111  */
112 // ============================================================================
113 GaudiSequencer* Gaudi::Utils::getGaudiSequencer( const IAlgContextSvc* svc ) { return getAlg<GaudiSequencer>( svc ); }
114 // ============================================================================
115 /* simple function to extract the last active
116  * Sequencer from the context
117  *
118  * @code
119  *
120  * // get the context service:
121  * const IAlgContextSvc* svc = ... ;
122  *
123  * Sequencer* sa = getSequencerAlg ( svc ) ;
124  *
125  * @endcode
126  *
127  * @author Vanya BELYAEV ibelyaev@physics.syr.edu
128  * @date 2007-09-07
129  */
130 Sequencer* Gaudi::Utils::getSequencerAlg( const IAlgContextSvc* svc ) { return getAlg<Sequencer>( svc ); }
131 // ========================================================================
132 /* simple function to extract the last active
133  * "Sequencer" () GaudiSequencer or Sequencer)
134  * from the context
135  *
136  * @code
137  *
138  * // get the context service:
139  * const IAlgContextSvc* svc = ... ;
140  *
141  * IAlgorithm* a = getSequencer ( svc ) ;
142  *
143  * @endcode
144  *
145  * @author Vanya BELYAEV ibelyaev@physics.syr.edu
146  * @date 2007-09-07
147  */
148 // ========================================================================
150  if ( !svc ) { return nullptr; } // RETURN
151  //
154 
155  const auto& algs = svc->algorithms();
156  auto a = std::find_if( algs.rbegin(), algs.rend(), [&]( IAlgorithm* alg ) { return sel1( alg ) || sel2( alg ); } );
157  return a != algs.rend() ? *a : nullptr;
158 }
159 // ========================================================================
160 
161 // ============================================================================
162 // The END
163 // ============================================================================
GAUDI_API GaudiHistoAlg * getHistoAlg(const IAlgContextSvc *svc)
simple function to extract the last active GaudiHistoAlg from the context
Definition: GetAlgs.cpp:77
Simple class to extend the functionality of class GaudiHistoAlg.
Definition: GaudiTupleAlg.h:41
Sequencer for executing several algorithms, stopping when one is faulty.
Header file for class GaudiAlgorithm.
GAUDI_API GaudiTupleAlg * getTupleAlg(const IAlgContextSvc *svc)
simple function to extract the last active GaudiTupleAlg from the context
Definition: GetAlgs.cpp:95
Simple class to extend the functionality of class GaudiAlgorithm.
Definition: GaudiHistoAlg.h:37
GAUDI_API IAlgorithm * getSequencer(const IAlgContextSvc *svc)
simple function to extract the last active "Sequencer" () GaudiSequencer or simple Sequencer) from th...
Definition: GetAlgs.cpp:149
GAUDI_API Sequencer * getSequencerAlg(const IAlgContextSvc *svc)
simple function to extract the last active Sequencer from the context
Definition: GetAlgs.cpp:130
The useful base class for data processing algorithms.
GAUDI_API GaudiAlgorithm * getGaudiAlg(const IAlgContextSvc *svc)
simple function to extract the last active GaudiAlgorithm from the context
Definition: GetAlgs.cpp:59
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:28
The trivial selector of algorithm by type.
Definition: GetAlg.h:39
virtual const Algorithms & algorithms() const =0
get the stack of executed algorithms
T find_if(T...args)
An abstract interface for Algorithm Context Service.
ClassName: Sequencer.
Definition: Sequencer.h:25
GAUDI_API GaudiSequencer * getGaudiSequencer(const IAlgContextSvc *svc)
simple function to extract the last active GaudiSequencer from the context
Definition: GetAlgs.cpp:113