The Gaudi Framework  v32r0 (3325bb39)
MergingTransformer.h
Go to the documentation of this file.
1 #ifndef MERGING_TRANSFORMER_H
2 #define MERGING_TRANSFORMER_H
3 
4 #include <functional>
5 #include <string>
6 #include <vector>
7 
10 
11 namespace Gaudi::Functional {
12 
13  using details::vector_of_const_;
14 
15  namespace details {
16 
17  template <typename Signature, typename Traits_, bool isLegacy>
19 
21  template <typename Out, typename In, typename Traits_>
22  class MergingTransformer<Out( const vector_of_const_<In>& ), Traits_, true>
25 
26  public:
27  using KeyValue = typename base_class::KeyValue;
28  using KeyValues = typename base_class::KeyValues;
29 
30  MergingTransformer( const std::string& name, ISvcLocator* locator, const KeyValues& inputs,
31  const KeyValue& output )
32  : base_class( name, locator, output )
33  , m_inputLocations{this, inputs.first, inputs.second,
35  this->m_inputs = details::make_vector_of_handles<decltype( this->m_inputs )>(
36  this, m_inputLocations );
37  if ( std::is_pointer_v<In> ) { // handle constructor does not (yet) allow to set
38  // optional flag... so do it
39  // explicitly here...
40  std::for_each( this->m_inputs.begin(), this->m_inputs.end(),
41  []( auto& h ) { h.setOptional( true ); } );
42  }
43  },
45 
46  // accessor to input Locations
47  const std::string& inputLocation( unsigned int n ) const { return m_inputLocations.value()[n]; }
48  unsigned int inputLocationSize() const { return m_inputLocations.value().size(); }
49 
50  // derived classes can NOT implement execute
51  StatusCode execute() override final {
53  ins.reserve( m_inputs.size() );
54  std::transform( m_inputs.begin(), m_inputs.end(), std::back_inserter( ins ),
56  try {
57  details::put( std::get<0>( this->m_outputs ), std::as_const( *this )( std::as_const( ins ) ) );
58  return StatusCode::SUCCESS;
59  } catch ( GaudiException& e ) {
60  ( e.code() ? this->warning() : this->error() ) << e.message() << endmsg;
61  return e.code();
62  }
63  }
64 
65  virtual Out operator()( const vector_of_const_<In>& inputs ) const = 0;
66 
67  private:
68  // if In is a pointer, it signals optional (as opposed to mandatory) input
69  template <typename T>
71  std::vector<InputHandle_t<In>> m_inputs; // and make the handles properties instead...
72  Gaudi::Property<std::vector<std::string>> m_inputLocations; // TODO/FIXME: remove this duplication...
73  // TODO/FIXME: replace vector of string property + call-back with a
74  // vector<handle> property ... as soon as declareProperty can deal with that.
75  };
76 
77  template <typename Out, typename In, typename Traits_>
78  class MergingTransformer<Out( const vector_of_const_<In>& ), Traits_, false>
81 
82  public:
83  using KeyValue = typename base_class::KeyValue;
84  using KeyValues = typename base_class::KeyValues;
85 
86  MergingTransformer( const std::string& name, ISvcLocator* locator, const KeyValues& inputs,
87  const KeyValue& output )
88  : base_class( name, locator, output )
89  , m_inputLocations{this, inputs.first, inputs.second,
91  this->m_inputs = details::make_vector_of_handles<decltype( this->m_inputs )>(
92  this, m_inputLocations );
93  if ( std::is_pointer_v<In> ) { // handle constructor does not (yet) allow to set
94  // optional flag... so do it
95  // explicitly here...
96  std::for_each( this->m_inputs.begin(), this->m_inputs.end(),
97  []( auto& h ) { h.setOptional( true ); } );
98  }
99  },
101 
102  // accessor to input Locations
103  const std::string& inputLocation( unsigned int n ) const { return m_inputLocations.value()[n]; }
104  unsigned int inputLocationSize() const { return m_inputLocations.value().size(); }
105 
106  // derived classes can NOT implement execute
107  StatusCode execute( const EventContext& ) const override final {
109  ins.reserve( m_inputs.size() );
110  std::transform( m_inputs.begin(), m_inputs.end(), std::back_inserter( ins ),
112  try {
113  details::put( std::get<0>( this->m_outputs ), ( *this )( std::as_const( ins ) ) );
114  return StatusCode::SUCCESS;
115  } catch ( GaudiException& e ) {
116  ( e.code() ? this->warning() : this->error() ) << e.message() << endmsg;
117  return e.code();
118  }
119  }
120 
121  virtual Out operator()( const vector_of_const_<In>& inputs ) const = 0;
122 
123  private:
124  // if In is a pointer, it signals optional (as opposed to mandatory) input
125  template <typename T>
127  std::vector<InputHandle_t<In>> m_inputs; // and make the handles properties instead...
128  Gaudi::Property<std::vector<std::string>> m_inputLocations; // TODO/FIXME: remove this duplication...
129  // TODO/FIXME: replace vector of string property + call-back with a
130  // vector<handle> property ... as soon as declareProperty can deal with that.
131  };
132 
133  } // namespace details
134 
135  template <typename Signature, typename Traits_ = Traits::useDefaults>
137 
138 } // namespace Gaudi::Functional
139 
140 #endif
virtual const std::string & message() const
error message to be printed
Define general base for Gaudi exception.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
virtual Out operator()(const vector_of_const_< In > &inputs) const =0
Implementation of property with value of concrete type.
Definition: Property.h:352
typename base_class::KeyValue KeyValue
unsigned int inputLocationSize() const
typename base_class::KeyValues KeyValues
Gaudi::tagged_bool< class ImmediatelyInvokeHandler_tag > ImmediatelyInvokeHandler
Definition: Property.h:141
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
This class represents an entry point to all the event specific data.
Definition: EventContext.h:24
virtual const StatusCode & code() const
StatusCode for Exception.
std::vector< InputHandle_t< In > > m_inputs
STL class.
class MergingTransformer< Out(const vector_of_const_< In > Traits_
StatusCode execute() override final
Gaudi::cpp17::detected_or_t< DataObjectReadHandle< T >, detail2::InputHandle_t, Tr, T > InputHandle_t
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
STL class.
MergingTransformer(const std::string &name, ISvcLocator *locator, const KeyValues &inputs, const KeyValue &output)
T back_inserter(T...args)
Out1 * put(const DataObjectHandle< Out1 > &out_handle, Out2 &&out)
Gaudi::Property< std::vector< std::string > > m_inputLocations
class MergingTransformer< Out(const vector_of_const_< In > void
T transform(T...args)
const std::string & inputLocation(unsigned int n) const
T for_each(T...args)
Handles make_vector_of_handles(IDataHandleHolder *owner, const std::vector< std::string > &init)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192