| The Gaudi Framework v28r2p1 (f1a77ff4)

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

- File List
- File Members

MergingTransformer.h
Go to the documentation of this file.
1 #ifndef MERGING_TRANSFORMER_H
2 #define MERGING_TRANSFORMER_H
3
4 #include <vector>
5 #include <string>
6 #include <functional>
7
8 #include "GaudiAlg/FunctionalDetails.h"
9 #include "GaudiAlg/FunctionalUtilities.h"
10
11 namespace Gaudi { namespace Functional {
12
13 template <typename Signature, typename Traits_=Traits::useDefaults> class MergingTransformer;
14
15 using details::vector_of_const_;
16
18 template <typename Out, typename In, typename Traits_>
19 class MergingTransformer<Out(const vector_of_const_<In>&),Traits_>
20 : public details::DataHandleMixin<std::tuple<Out>,void,Traits_>
21 {
22 using base_class = details::DataHandleMixin<std::tuple<Out>,void,Traits_>;
23 public:
24 using KeyValue = std::pair<std::string, std::string>;
25 using KeyValues = std::pair<std::string, std::vector<std::string>>;
26
27 MergingTransformer(const std::string& name, ISvcLocator* locator,
28 const KeyValues& inputs, const KeyValue& output);
29
30 // derived classes can NOT implement execute
31 StatusCode execute() override final;
32
33 virtual Out operator()(const vector_of_const_<In>& inputs) const = 0;
34
35 private:
36 // if In is a pointer, it signals optional (as opposed to mandatory) input
37 template <typename T> using InputHandle_t = details::InputHandle_t<Traits_,typename std::remove_pointer<T>::type>;
38 std::vector<std::string> m_inputLocations; // TODO/FIXME: remove this duplication...
39 std::vector<InputHandle_t<In>> m_inputs; // and make the handles properties instead...
40 };
41
42 template <typename Out, typename In, typename Traits_>
43 MergingTransformer<Out(const vector_of_const_<In>&),Traits_>
44 ::MergingTransformer( const std::string& name, ISvcLocator* pSvcLocator,
45 const KeyValues& inputs, const KeyValue& output )
46 : base_class( name , pSvcLocator, output )
47 , m_inputLocations( inputs.second )
48 {
49 // TODO/FIXME: replace vector of string property + call-back with a
50 // vector<handle> property ... as soon as declareProperty can deal with that.
51 auto p = this->declareProperty( inputs.first, m_inputLocations );
52 p->declareUpdateHandler( [=](Gaudi::Details::PropertyBase&) {
53 this->m_inputs = details::make_vector_of_handles<decltype(this->m_inputs)>
54 (this, m_inputLocations, Gaudi::DataHandle::Reader);
55 if (std::is_pointer<In>::value) { // handle constructor does not (yet) allow to set optional flag... so do it explicitly here...
56 std::for_each( this->m_inputs.begin(), this->m_inputs.end(), [](auto& h) { h.setOptional(true); } );
57 }
58 } );
59 p->useUpdateHandler(); // invoke call-back now, to be sure the input handles are synced with the property...
60 }
61
62 template <typename Out, typename In, typename Traits_>
63 StatusCode
64 MergingTransformer<Out(const vector_of_const_<In>&),Traits_>::execute()
65 {
66 vector_of_const_<In> ins; ins.reserve(m_inputs.size());
67 std::transform(m_inputs.begin(),m_inputs.end(),
68 std::back_inserter(ins),
69 details::details2::get_from_handle<In>{} );
70 try {
71 using details::as_const;
72 details::put( std::get<0>(this->m_outputs), as_const(*this)( as_const(ins) ) );
73 } catch ( GaudiException& e ) {
74 (e.code() ? this->warning() : this->error() ) << e.message() << endmsg;
75 return e.code();
76 }
77 return StatusCode::SUCCESS;
78 }
79
80 }}
81
82 #endif
GaudiException::message
virtual const std::string & message() const
error message to be printed
Definition: GaudiException.h:111
StatusCode::SUCCESS
Definition: StatusCode.h:30
Gaudi::Functional::details::as_const
constexpr std::add_const< T >::type & as_const(T &t) noexcept
Definition: FunctionalDetails.h:77
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:23
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
Gaudi::Functional::details::make_vector_of_handles
Handles make_vector_of_handles(IDataHandleHolder *owner, const std::vector< std::string > &init, Gaudi::DataHandle::Mode mode)
Definition: FunctionalDetails.h:306
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
std::is_pointer
gaudirun.output
output
Definition: gaudirun.py:388
Gaudi::Functional::execute
StatusCode execute() override final
Containers::vector
struct GAUDI_API vector
Parametrisation class for vector-like implementation.
Definition: KeyedObjectManager.h:29
std
STL namespace.
Gaudi::Functional::void
class MergingTransformer< Out(const vector_of_const_< In > void
Definition: MergingTransformer.h:19
Gaudi::Functional::details::details2::get_from_handle
Definition: FunctionalDetails.h:159
Gaudi::DataHandle::Reader
Definition: DataHandle.h:31
Gaudi::Functional::details::vector_of_const_
Definition: FunctionalDetails.h:171
GaudiException::code
virtual const StatusCode & code() const
StatusCode for Exception.
Definition: GaudiException.h:127
Gaudi::Units::second
constexpr double second
Definition: SystemOfUnits.h:122
std::string
STL class.
BrunelScenarioForwardScheduler.inputs
inputs
Definition: BrunelScenarioForwardScheduler.py:123
Gaudi::Functional::details::DataHandleMixin
Definition: FunctionalDetails.h:317
Gaudi::Functional::MergingTransformer
Definition: MergingTransformer.h:13
HiveAlgSequencer.h
h
Definition: HiveAlgSequencer.py:24
Gaudi::Functional::Traits_
class MergingTransformer< Out(const vector_of_const_< In > Traits_
Definition: MergingTransformer.h:19
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
declareProperty
Gaudi::Details::PropertyBase * declareProperty(const std::string &name, TYPE &value, const std::string &doc="none")
Declare a property (templated)
gaudirun.type
type
Definition: gaudirun.py:125
FunctionalUtilities.h
Gaudi::Details::PropertyBase
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
Gaudi::Functional::m_inputLocations
std::vector< std::string > m_inputLocations
Definition: MergingTransformer.h:38
Gaudi::Functional::InputHandle_t
details::InputHandle_t< Traits_, typename std::remove_pointer< T >::type > InputHandle_t
Definition: MergingTransformer.h:37
std::tuple
std::pair< std::string, std::string >
Gaudi::Functional::m_inputs
std::vector< InputHandle_t< In > > m_inputs
Definition: MergingTransformer.h:39
std::back_inserter
T back_inserter(T...args)
Gaudi::Functional::MergingTransformer
MergingTransformer(const std::string &name, ISvcLocator *locator, const KeyValues &inputs, const KeyValue &output)
Definition: MergingTransformer.h:44
std::transform
T transform(T...args)
std::for_each
T for_each(T...args)
Gaudi
Helper functions to set/get the application return code.
Definition: __init__.py:1
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
Gaudi::Functional::details::put
Out1 * put(DataObjectHandle< Out1 > &out_handle, Out2 &&out)
Definition: FunctionalDetails.h:87
FunctionalDetails.h