| The Gaudi Framework v30r0 (c919700c)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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