All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GetAlgs.cpp
Go to the documentation of this file.
1 // $Id: GetAlgs.cpp,v 1.1 2007/09/25 16:12:41 marcocle Exp $
2 // ============================================================================
3 // Include files
4 // ============================================================================
5 // STD&STL
6 // ============================================================================
7 #include <algorithm>
8 #include <functional>
9 // ============================================================================
10 // GaudiKernel
11 // ============================================================================
13 #include "GaudiKernel/IAlgorithm.h"
14 // ============================================================================
15 // GaudiAlg
16 // ============================================================================
17 #include "GaudiAlg/GetAlg.h"
18 #include "GaudiAlg/GetAlgs.h"
19 // ============================================================================
21 #include "GaudiAlg/GaudiHistoAlg.h"
22 #include "GaudiAlg/GaudiTupleAlg.h"
24 #include "GaudiAlg/Sequencer.h"
25 // ============================================================================
31 // ============================================================================
32 namespace
33 {
34  template <class TYPE>
35  TYPE* getAlg ( const IAlgContextSvc* svc )
36  {
37  if ( 0 == svc ) { return 0 ; } // RETURN
38  typedef IAlgContextSvc::Algorithms ALGS ;
39  const ALGS& algs = svc->algorithms() ;
40  ALGS::const_reverse_iterator it = std::find_if
41  ( algs.rbegin () ,
42  algs.rend () ,
44  if ( algs.rend() == it ) { return 0 ; } // RETURN
45  IAlgorithm* alg = *it ;
46  return dynamic_cast<TYPE*>( alg ) ; // RETURN
47  }
48 }
49 // ============================================================================
50 /* simple function to extract the last active
51  * GaudiAlgorithm from the context
52  *
53  * @code
54  *
55  * // get the context service:
56  * const IAlgContextSvc* svc = ... ;
57  *
58  * GaudiAlgorithm* ga = getGaudiAlg ( svc ) ;
59  *
60  * @endcode
61  *
62  * @author Vanya BELYAEV ibelyaev@physics.syr.edu
63  * @date 2007-09-07
64  */
65 // ============================================================================
68 { return getAlg<GaudiAlgorithm> ( svc ) ; }
69 // ============================================================================
70 /* simple function to extract the last active
71  * GaudiHistoAlg from the context
72  *
73  * @code
74  *
75  * // get the context service:
76  * const IAlgContextSvc* svc = ... ;
77  *
78  * GaudiHistoAlg* ha = getHistoAlg ( svc ) ;
79  *
80  * @endcode
81  *
82  * @author Vanya BELYAEV ibelyaev@physics.syr.edu
83  * @date 2007-09-07
84  */
85 // ============================================================================
88 { return getAlg<GaudiHistoAlg> ( svc ) ; }
89 // ============================================================================
90 /* simple function to extract the last active
91  * GaudiTupleAlg from the context
92  *
93  * @code
94  *
95  * // get the context service:
96  * const IAlgContextSvc* svc = ... ;
97  *
98  * GaudiTupleAlg* ta = getTupleAlg ( svc ) ;
99  *
100  * @endcode
101  *
102  * @author Vanya BELYAEV ibelyaev@physics.syr.edu
103  * @date 2007-09-07
104  */
105 // ============================================================================
108 { return getAlg<GaudiTupleAlg> ( svc ) ; }
109 // ============================================================================
110 /* simple function to extract the last active
111  * GaudiSequencer from the context
112  *
113  * @code
114  *
115  * // get the context service:
116  * const IAlgContextSvc* svc = ... ;
117  *
118  * GaudiSequencer* sa = getGaudiSequencer ( svc ) ;
119  *
120  * @endcode
121  *
122  * @author Vanya BELYAEV ibelyaev@physics.syr.edu
123  * @date 2007-09-07
124  */
125 // ============================================================================
128 { return getAlg<GaudiSequencer> ( svc ) ; }
129 // ============================================================================
130 /* simple function to extract the last active
131  * Sequencer from the context
132  *
133  * @code
134  *
135  * // get the context service:
136  * const IAlgContextSvc* svc = ... ;
137  *
138  * Sequencer* sa = getSequencerAlg ( svc ) ;
139  *
140  * @endcode
141  *
142  * @author Vanya BELYAEV ibelyaev@physics.syr.edu
143  * @date 2007-09-07
144  */
145 Sequencer*
147 { return getAlg<Sequencer> ( svc ) ; }
148 // ========================================================================
149 /* simple function to extract the last active
150  * "Sequencer" () GaudiSequencer or Sequencer)
151  * from the context
152  *
153  * @code
154  *
155  * // get the context service:
156  * const IAlgContextSvc* svc = ... ;
157  *
158  * IAlgorithm* a = getSequencer ( svc ) ;
159  *
160  * @endcode
161  *
162  * @author Vanya BELYAEV ibelyaev@physics.syr.edu
163  * @date 2007-09-07
164  */
165 // ========================================================================
166 IAlgorithm*
168 {
169  if ( 0 == svc ) { return 0 ; } // RETURN
170  //
171  typedef IAlgContextSvc::Algorithms ALGS ;
172  const ALGS& algs = svc->algorithms() ;
175  for ( ALGS::const_reverse_iterator it = algs.rbegin() ;
176  algs.rend() != it ; ++it )
177  {
178  if ( sel1 ( *it ) ) { return *it ; }
179  if ( sel2 ( *it ) ) { return *it ; }
180  }
181  return 0 ; // RETURN ;
182 }
183 // ========================================================================
184 
185 
186 // ============================================================================
187 // The END
188 // ============================================================================
GAUDI_API GaudiHistoAlg * getHistoAlg(const IAlgContextSvc *svc)
simple function to extract the last active GaudiHistoAlg from the context
Definition: GetAlgs.cpp:87
Sequencer for executing several algorithms, stopping when one is faulty.
GAUDI_API GaudiTupleAlg * getTupleAlg(const IAlgContextSvc *svc)
simple function to extract the last active GaudiTupleAlg from the context
Definition: GetAlgs.cpp:107
GAUDI_API IAlgorithm * getSequencer(const IAlgContextSvc *svc)
simple function to extract the last active "Sequencer" () GaudiSequencer or simple Sequencer) from th...
Definition: GetAlgs.cpp:167
virtual const Algorithms & algorithms() const =0
get the stack of executed algorithms
std::vector< IAlgorithm * > Algorithms
the actual type of algorithm' stack
GAUDI_API Sequencer * getSequencerAlg(const IAlgContextSvc *svc)
simple function to extract the last active Sequencer from the context
Definition: GetAlgs.cpp:146
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:67
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:20
The trivial selector of algorithm by type.
Definition: GetAlg.h:42
An abstract interface for Algorithm Context Service.
Simple class to extend the functionality of class GaudiAlgorithm.
Definition: GaudiHistoAlg.h:38
ClassName: Sequencer.
Definition: Sequencer.h:24
Simple class to extend the functionality of class GaudiHistoAlg.
Definition: GaudiTupleAlg.h:42
GAUDI_API GaudiSequencer * getGaudiSequencer(const IAlgContextSvc *svc)
simple function to extract the last active GaudiSequencer from the context
Definition: GetAlgs.cpp:127