| The Gaudi Framework v32r1 (f65d50dc)

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 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 // ========================================================================
149 IAlgorithm* Gaudi::Utils::getSequencer( const IAlgContextSvc* svc ) {
150 if ( !svc ) { return nullptr; } // RETURN
151 //
152 AlgTypeSelector<GaudiSequencer> sel1;
153 AlgTypeSelector<Sequencer> sel2;
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 // ============================================================================
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:77
ManySmallAlgs.alg
alg
Definition: ManySmallAlgs.py:69
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:28
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:95
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:149
Sequencer.h
IAlgContextSvc::algorithms
virtual const Algorithms & algorithms() const =0
get the stack of executed algorithms
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:130
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:59
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:39
GetAlg.h
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:25
Gaudi::Utils::getGaudiSequencer
GAUDI_API GaudiSequencer * getGaudiSequencer(const IAlgContextSvc *svc)
simple function to extract the last active GaudiSequencer from the context
Definition: GetAlgs.cpp:113