The Gaudi Framework  v30r3 (a5ef0a68)
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 {
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 // ========================================================================
156 {
157  if ( !svc ) {
158  return nullptr;
159  } // RETURN
160  //
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 // ============================================================================
GAUDI_API GaudiHistoAlg * getHistoAlg(const IAlgContextSvc *svc)
simple function to extract the last active GaudiHistoAlg from the context
Definition: GetAlgs.cpp:83
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:101
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:155
GAUDI_API Sequencer * getSequencerAlg(const IAlgContextSvc *svc)
simple function to extract the last active Sequencer from the context
Definition: GetAlgs.cpp:136
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:65
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:42
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:23
GAUDI_API GaudiSequencer * getGaudiSequencer(const IAlgContextSvc *svc)
simple function to extract the last active GaudiSequencer from the context
Definition: GetAlgs.cpp:119