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"
21 #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 ) { return nullptr ; } // RETURN
37  const auto& algs = svc->algorithms() ;
38  auto it = std::find_if( algs.rbegin(), algs.rend(),
40  if ( algs.rend() == it ) { return nullptr ; } // RETURN
41  IAlgorithm* alg = *it ;
42  return dynamic_cast<TYPE*>( alg ) ; // RETURN
43  }
44 }
45 // ============================================================================
46 /* simple function to extract the last active
47  * GaudiAlgorithm from the context
48  *
49  * @code
50  *
51  * // get the context service:
52  * const IAlgContextSvc* svc = ... ;
53  *
54  * GaudiAlgorithm* ga = getGaudiAlg ( svc ) ;
55  *
56  * @endcode
57  *
58  * @author Vanya BELYAEV ibelyaev@physics.syr.edu
59  * @date 2007-09-07
60  */
61 // ============================================================================
64 { return getAlg<GaudiAlgorithm> ( svc ) ; }
65 // ============================================================================
66 /* simple function to extract the last active
67  * GaudiHistoAlg from the context
68  *
69  * @code
70  *
71  * // get the context service:
72  * const IAlgContextSvc* svc = ... ;
73  *
74  * GaudiHistoAlg* ha = getHistoAlg ( svc ) ;
75  *
76  * @endcode
77  *
78  * @author Vanya BELYAEV ibelyaev@physics.syr.edu
79  * @date 2007-09-07
80  */
81 // ============================================================================
84 { return getAlg<GaudiHistoAlg> ( svc ) ; }
85 // ============================================================================
86 /* simple function to extract the last active
87  * GaudiTupleAlg from the context
88  *
89  * @code
90  *
91  * // get the context service:
92  * const IAlgContextSvc* svc = ... ;
93  *
94  * GaudiTupleAlg* ta = getTupleAlg ( svc ) ;
95  *
96  * @endcode
97  *
98  * @author Vanya BELYAEV ibelyaev@physics.syr.edu
99  * @date 2007-09-07
100  */
101 // ============================================================================
104 { return getAlg<GaudiTupleAlg> ( svc ) ; }
105 // ============================================================================
106 /* simple function to extract the last active
107  * GaudiSequencer from the context
108  *
109  * @code
110  *
111  * // get the context service:
112  * const IAlgContextSvc* svc = ... ;
113  *
114  * GaudiSequencer* sa = getGaudiSequencer ( svc ) ;
115  *
116  * @endcode
117  *
118  * @author Vanya BELYAEV ibelyaev@physics.syr.edu
119  * @date 2007-09-07
120  */
121 // ============================================================================
124 { return getAlg<GaudiSequencer> ( svc ) ; }
125 // ============================================================================
126 /* simple function to extract the last active
127  * Sequencer from the context
128  *
129  * @code
130  *
131  * // get the context service:
132  * const IAlgContextSvc* svc = ... ;
133  *
134  * Sequencer* sa = getSequencerAlg ( svc ) ;
135  *
136  * @endcode
137  *
138  * @author Vanya BELYAEV ibelyaev@physics.syr.edu
139  * @date 2007-09-07
140  */
141 Sequencer*
143 { return getAlg<Sequencer> ( svc ) ; }
144 // ========================================================================
145 /* simple function to extract the last active
146  * "Sequencer" () GaudiSequencer or Sequencer)
147  * from the context
148  *
149  * @code
150  *
151  * // get the context service:
152  * const IAlgContextSvc* svc = ... ;
153  *
154  * IAlgorithm* a = getSequencer ( svc ) ;
155  *
156  * @endcode
157  *
158  * @author Vanya BELYAEV ibelyaev@physics.syr.edu
159  * @date 2007-09-07
160  */
161 // ========================================================================
162 IAlgorithm*
164 {
165  if ( !svc ) { return nullptr ; } // RETURN
166  //
169 
170  const auto& algs = svc->algorithms();
171  auto a = std::find_if( algs.rbegin(), algs.rend(),
172  [&](IAlgorithm* alg) { return sel1(alg) || sel2(alg); } );
173  return a!=algs.rend() ? *a : nullptr;
174 }
175 // ========================================================================
176 
177 
178 // ============================================================================
179 // The END
180 // ============================================================================
GAUDI_API GaudiHistoAlg * getHistoAlg(const IAlgContextSvc *svc)
simple function to extract the last active GaudiHistoAlg from the context
Definition: GetAlgs.cpp:83
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:103
GAUDI_API IAlgorithm * getSequencer(const IAlgContextSvc *svc)
simple function to extract the last active "Sequencer" () GaudiSequencer or simple Sequencer) from th...
Definition: GetAlgs.cpp:163
GAUDI_API Sequencer * getSequencerAlg(const IAlgContextSvc *svc)
simple function to extract the last active Sequencer from the context
Definition: GetAlgs.cpp:142
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:63
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:27
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.
Simple class to extend the functionality of class GaudiAlgorithm.
Definition: GaudiHistoAlg.h:37
ClassName: Sequencer.
Definition: Sequencer.h:23
Simple class to extend the functionality of class GaudiHistoAlg.
Definition: GaudiTupleAlg.h:41
GAUDI_API GaudiSequencer * getGaudiSequencer(const IAlgContextSvc *svc)
simple function to extract the last active GaudiSequencer from the context
Definition: GetAlgs.cpp:123