The Gaudi Framework  v36r16 (ea80daf8)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
MakeAndConsume.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #include "GaudiAlg/Consumer.h"
14 #include "GaudiAlg/Producer.h"
17 #include "GaudiAlg/Transformer.h"
18 #include "GaudiKernel/AlgTool.h"
19 #include "GaudiKernel/IAlgTool.h"
20 #include "GaudiKernel/IBinder.h"
23 #include <cmath>
24 #include <numeric>
25 #include <optional>
26 
27 namespace Gaudi::Examples {
28 
29  struct IMyTool : extend_interfaces<IAlgTool> {
31  virtual void operator()() const = 0;
32  };
33 
34  struct MyExampleTool : extends<AlgTool, IMyTool> {
35  using extends::extends;
36  void operator()() const override { always() << m_message.value() << endmsg; }
37  Gaudi::Property<std::string> m_message{ this, "Message", "Boring Default Message" };
38  };
39  DECLARE_COMPONENT( MyExampleTool )
40 
41  struct MyConsumerTool final : Gaudi::Functional::ToolBinder<Gaudi::Interface::Bind::Box<IMyTool>( const int& )> {
43  : ToolBinder{ std::move( type ), std::move( name ), parent, KeyValue{ "MyInt", "/Event/MyInt" },
44  construct<BoundInstance>( this ) } {}
45 
46  class BoundInstance final : public Gaudi::Interface::Bind::Stub<IMyTool> {
48  int i;
49 
50  public:
51  BoundInstance( MyConsumerTool const* parent, const int& i ) : parent{ parent }, i{ i } {}
52  void operator()() const override {
53  parent->always() << "BoundInstance - got: " << i << " from " << parent->inputLocation<int>() << endmsg;
54  }
55  };
56  };
57  DECLARE_COMPONENT( MyConsumerTool )
58 
59  using BaseClass_t = Gaudi::Functional::Traits::BaseClass_t<Gaudi::Algorithm>;
60 
61  struct ToolConsumer final : Gaudi::Functional::Consumer<void( IMyTool const& ), BaseClass_t> {
63  : Consumer( name, svcLoc, KeyValue{ "MyTool", "MyExampleTool" } ) {}
64 
65  void operator()( IMyTool const& tool ) const override { tool(); }
66  };
67  DECLARE_COMPONENT( ToolConsumer )
68 
69  struct CountingConsumer final : Gaudi::Functional::Consumer<void(), BaseClass_t> {
71  mutable Gaudi::Accumulators::MsgCounter<MSG::ERROR> m_err{ this, "This is not an error...", 3 };
72  mutable Gaudi::Accumulators::MsgCounter<MSG::WARNING> m_warn{ this, "This is not a warning...", 2 };
73  mutable Gaudi::Accumulators::MsgCounter<MSG::INFO> m_info{ this, "This is not info...", 1 };
74 
75  void operator()() const override {
76  always() << "CountingConsumer: incrementing \"This is not an error\" twice" << endmsg;
77  ++m_err;
78  m_err += true;
79  m_err += false; // should do nothing...
80  always() << "CountingConsumer: incrementing \"This is not a warning\" twice" << endmsg;
81  ++m_warn;
82  m_warn += true;
83  m_warn += false; // should do nothing...
84  always() << "CountingConsumer: incrementing \"This is not info\" twice" << endmsg;
85  ++m_info;
86  m_info += true;
87  m_info += false; // should do nothing...
88  }
89  };
90  DECLARE_COMPONENT( CountingConsumer )
91 
92  struct IntDataProducer final : Gaudi::Functional::Producer<int(), BaseClass_t> {
93 
95  : Producer( name, svcLoc, KeyValue( "OutputLocation", "/Event/MyInt" ) ) {}
96 
97  int operator()() const override {
98  info() << "executing IntDataProducer, storing " << m_value.value() << " into " << outputLocation() << endmsg;
99  return m_value;
100  }
101 
102  Gaudi::Property<int> m_value{ this, "Value", 7, "The integer value to produce." };
103  };
104 
105  DECLARE_COMPONENT( IntDataProducer )
106 
107  struct VectorDataProducer final : Gaudi::Functional::Producer<std::vector<int>(), BaseClass_t> {
108 
109  Gaudi::Property<std::vector<int>> m_data{ this, "Data", { 3, 3, 3, 3 } };
110 
112  : Producer( name, svcLoc, KeyValue( "OutputLocation", "/Event/MyVector" ) ) {}
113 
114  std::vector<int> operator()() const override {
115  info() << "executing VectorDataProducer, storing " << m_data.value() << " into " << outputLocation() << endmsg;
116  return m_data;
117  }
118  };
119 
120  DECLARE_COMPONENT( VectorDataProducer )
121 
123  struct KeyedDataProducer final : Gaudi::Functional::Producer<int_container(), BaseClass_t> {
124 
126  : Producer( name, svcLoc, KeyValue( "OutputLocation", "/Event/MyKeyed" ) ) {}
127 
128  int_container operator()() const override {
129  int_container container;
130  auto a = new KeyedObject<int>{ 4 };
131  container.add( a );
132  auto b = new KeyedObject<int>{ 5 };
133  container.add( b );
134  info() << "executing KeyedDataProducer, storing [4,5] into " << outputLocation() << endmsg;
135  return container;
136  }
137  };
138 
139  DECLARE_COMPONENT( KeyedDataProducer )
140 
141  struct IntDataConsumer final : Gaudi::Functional::Consumer<void( const int& ), BaseClass_t> {
142 
144  : Consumer( name, svcLoc, KeyValue( "InputLocation", "/Event/MyInt" ) ) {}
145 
146  void operator()( const int& input ) const override {
147  info() << "executing IntDataConsumer, consuming " << input << " from " << inputLocation() << endmsg;
148  }
149  };
150 
151  DECLARE_COMPONENT( IntDataConsumer )
152 
153  struct IntToFloatData final : Gaudi::Functional::Transformer<float( const int& ), BaseClass_t> {
154 
156  : Transformer( name, svcLoc, KeyValue( "InputLocation", "/Event/MyInt" ),
157  KeyValue( "OutputLocation", "/Event/MyFloat" ) ) {}
158 
159  float operator()( const int& input ) const override {
160  info() << "Converting: " << input << " from " << inputLocation() << " and storing it into " << outputLocation()
161  << endmsg;
162  return input;
163  }
164  };
165 
166  DECLARE_COMPONENT( IntToFloatData )
167 
168  struct IntFloatToFloatData final : Gaudi::Functional::Transformer<float( const int&, const float& ), BaseClass_t> {
169 
171  : Transformer( name, svcLoc,
172  { KeyValue( "InputLocation", "/Event/MyInt" ), KeyValue{ "OtherInput", "/Event/MyOtherFloat" } },
173  KeyValue( "OutputLocation", "/Event/OtherFloat" ) ) {}
174 
175  float operator()( const int& in1, const float& in2 ) const override {
176  info() << "Converting: " << in1 << " from " << inputLocation<int>() << " and " << in2 << " from "
177  << inputLocation<float>() << " and storing it into " << outputLocation() << endmsg;
178  return in1 + in2;
179  }
180  };
181 
182  DECLARE_COMPONENT( IntFloatToFloatData )
183 
185  : Gaudi::Functional::MultiTransformer<std::tuple<float, float>( const int&, const int& ), BaseClass_t> {
187  : MultiTransformer( name, svcLoc,
188  { KeyValue( "InputLocation1", { "/Event/MyInt" } ),
189  KeyValue( "InputLocation2", { "/Event/MyOtherInt" } ) },
190  { KeyValue( "OutputLocation1", { "/Event/MyMultiFloat1" } ),
191  KeyValue( "OutputLocation2", { "/Event/MyMultiFloat2" } ) } ) {}
192 
193  std::tuple<float, float> operator()( const int& input1, const int& input2 ) const override {
194  info() << "Number of inputs : " << inputLocationSize() << ", number of outputs : " << outputLocationSize()
195  << endmsg;
196  info() << "Converting " << input1 << " from " << inputLocation<0>() << " and " << input2 << " from "
197  << inputLocation<1>() << endmsg;
198  info() << "Storing results into " << outputLocation<0>() << " and " << outputLocation<1>() << endmsg;
199  return std::tuple<float, float>{ input1, input2 };
200  }
201  };
202 
203  DECLARE_COMPONENT( IntIntToFloatFloatData )
204 
205 
208  : public Gaudi::Functional::MergingTransformer<
209  std::vector<int>( const Gaudi::Functional::vector_of_const_<std::vector<int>>& ), BaseClass_t> {
210 
212  : MergingTransformer( name, svcLoc, { "InputLocations", {} },
213  { "OutputLocation", "/Event/MyConcatenatedIntVector" } ) {}
214 
216  operator()( const Gaudi::Functional::vector_of_const_<std::vector<int>>& intVectors ) const override {
217  // Create a vector and pre-allocate enough space for the number of integers we have
218  auto nelements = std::accumulate( intVectors.begin(), intVectors.end(), 0,
219  []( const auto a, const auto b ) { return a + b.size(); } );
221  out.reserve( nelements );
222  // Concatenate the input vectors to form the output
223  for ( const auto& intVector : intVectors ) {
224  info() << "Concatening vector " << intVector << endmsg;
225  out.insert( out.end(), intVector.begin(), intVector.end() );
226  }
227  info() << "Storing output vector " << out << " to " << outputLocation() << endmsg;
228  return out;
229  }
230  };
231 
232  DECLARE_COMPONENT( IntVectorsToIntVector )
233 
234  struct FloatDataConsumer final : Gaudi::Functional::Consumer<void( const float& ), BaseClass_t> {
235 
237  : Consumer( name, svcLoc, KeyValue( "InputLocation", "/Event/MyFloat" ) ) {}
238 
239  void operator()( const float& input ) const override {
240  info() << "executing FloatDataConsumer: " << input << endmsg;
241  }
242  };
243 
244  DECLARE_COMPONENT( FloatDataConsumer )
245 
246  struct ContextConsumer final : Gaudi::Functional::Consumer<void( const EventContext& ), BaseClass_t> {
247 
249 
250  void operator()( const EventContext& ctx ) const override {
251  info() << "executing ContextConsumer, got " << ctx << endmsg;
252  }
253  };
254 
255  DECLARE_COMPONENT( ContextConsumer )
256 
257  struct ContextTransformer final : Gaudi::Functional::Transformer<int( const EventContext& ), BaseClass_t> {
258 
260  : Transformer( name, svcLoc, KeyValue{ "OutputLoc", "/Event/SomeOtherInt" } ) {}
261 
262  int operator()( const EventContext& ctx ) const override {
263  info() << "executing ContextConsumer, got " << ctx << endmsg;
264  return 9;
265  }
266  };
267 
268  DECLARE_COMPONENT( ContextTransformer )
269 
270  struct ContextIntConsumer final : Gaudi::Functional::Consumer<void( const EventContext&, const int& ), BaseClass_t> {
271 
273  : Consumer( name, svcLoc, KeyValue( "InputLocation", "/Event/MyInt" ) ) {}
274 
275  void operator()( const EventContext& ctx, const int& i ) const override {
276  info() << "executing ContextIntConsumer, got context = " << ctx << ", int = " << i << endmsg;
277  }
278  };
279 
280  DECLARE_COMPONENT( ContextIntConsumer )
281 
282  struct VectorDoubleProducer final : Gaudi::Functional::Producer<std::vector<double>(), BaseClass_t> {
283 
285  : Producer( name, svcLoc, KeyValue( "OutputLocation", "/Event/MyVectorOfDoubles" ) ) {}
286 
287  std::vector<double> operator()() const override {
288  info() << "storing vector<double> into " << outputLocation() << endmsg;
289  return { 12.34, 56.78, 90.12, 34.56, 78.90 };
290  }
291  };
292 
293  DECLARE_COMPONENT( VectorDoubleProducer )
294 
295  struct FrExpTransformer final
296  : Gaudi::Functional::MultiScalarTransformer<
297  FrExpTransformer, std::tuple<std::vector<double>, std::vector<int>>( const std::vector<double>& ),
298  BaseClass_t> {
300  : MultiScalarTransformer( name, svcLoc, KeyValue{ "InputDoubles", { "/Event/MyVectorOfDoubles" } },
301  { KeyValue{ "OutputFractions", { "/Event/MyVectorOfFractions" } },
302  KeyValue{ "OutputIntegers", { "/Event/MyVectorOfIntegers" } } } ) {}
303 
304  using MultiScalarTransformer::operator();
305 
306  std::tuple<double, int> operator()( const double& d ) const {
307  int i;
308  double frac = std::frexp( d, &i );
309  info() << "Converting " << d << " -> " << frac << ", " << i << endmsg;
310  return { frac, i };
311  }
312  };
313  DECLARE_COMPONENT( FrExpTransformer )
314 
315  struct OptFrExpTransformer final
316  : Gaudi::Functional::MultiScalarTransformer<
317  OptFrExpTransformer, std::tuple<std::vector<double>, std::vector<int>>( const std::vector<double>& ),
318  BaseClass_t> {
320  : MultiScalarTransformer( name, svcLoc, KeyValue{ "InputDoubles", { "/Event/MyVectorOfDoubles" } },
321  { KeyValue{ "OutputFractions", { "/Event/OptMyVectorOfFractions" } },
322  KeyValue{ "OutputIntegers", { "/Event/OptMyVectorOfIntegers" } } } ) {}
323 
324  using MultiScalarTransformer::operator();
325 
326  std::optional<std::tuple<double, int>> operator()( const double& d ) const {
327  if ( d < 30. ) {
328  info() << "Skipping " << d << endmsg;
329  return {};
330  }
331  int i;
332  double frac = std::frexp( d, &i );
333  info() << "Converting " << d << " -> " << frac << ", " << i << endmsg;
334  return std::make_tuple( frac, i );
335  }
336  };
337  DECLARE_COMPONENT( OptFrExpTransformer )
338 
339  struct LdExpTransformer final
340  : Gaudi::Functional::ScalarTransformer<
341  LdExpTransformer, std::vector<double>( const std::vector<double>&, const std::vector<int>& ), BaseClass_t> {
343  : ScalarTransformer( name, svcLoc,
344  { KeyValue{ "InputFractions", { "/Event/MyVectorOfFractions" } },
345  KeyValue{ "InputIntegers", { "/Event/MyVectorOfIntegers" } } },
346  { KeyValue{ "OutputDoubles", { "/Event/MyNewVectorOfDoubles" } } } ) {}
347 
348  using ScalarTransformer::operator();
349 
350  double operator()( double frac, int i ) const {
351  double d = std::ldexp( frac, i );
352  info() << "Converting " << i << ", " << frac << " -> " << d << endmsg;
353  return d;
354  }
355  };
356  DECLARE_COMPONENT( LdExpTransformer )
357 
358  struct OptLdExpTransformer final
359  : Gaudi::Functional::ScalarTransformer<OptLdExpTransformer,
360  std::vector<double>( const std::vector<double>&, const std::vector<int>& ),
361  BaseClass_t> {
363  : ScalarTransformer( name, svcLoc,
364  { KeyValue{ "InputFractions", { "/Event/MyVectorOfFractions" } },
365  KeyValue{ "InputIntegers", { "/Event/MyVectorOfIntegers" } } },
366  { KeyValue{ "OutputDoubles", { "/Event/MyOptVectorOfDoubles" } } } ) {}
367 
368  using ScalarTransformer::operator();
369 
370  std::optional<double> operator()( const double& frac, const int& i ) const {
371  double d = std::ldexp( frac, i );
372  if ( i > 6 ) {
373  info() << "Skipping " << d << endmsg;
374  return {};
375  }
376  info() << "Converting " << i << ", " << frac << " -> " << d << endmsg;
377  return d;
378  }
379  };
380  DECLARE_COMPONENT( OptLdExpTransformer )
381 
382  struct VoidConsumer final : Gaudi::Functional::Consumer<void(), BaseClass_t> {
383 
384  using Consumer::Consumer;
385 
386  void operator()() const override { info() << "executing VoidConsumer" << endmsg; }
387  };
388 
389  DECLARE_COMPONENT( VoidConsumer )
390 
391  struct S : public KeyedObject<int> {
393  int a;
397  };
398 
399  struct SDataProducer final : Gaudi::Functional::Producer<S::Container(), BaseClass_t> {
400 
402  : Producer( name, svcLoc, KeyValue( "OutputLocation", "/Event/MyS" ) ) {}
403 
404  S::Container operator()() const override {
405  S::Container out{};
406  for ( int i = 0; i < j; ++i ) out.insert( new S{} );
407  info() << "storing KeyedContainer of size " << out.size() << " into " << outputLocation() << endmsg;
408  return out;
409  }
410  Gaudi::Property<int> j{ this, "j", 5 };
411  };
412 
413  DECLARE_COMPONENT( SDataProducer )
414 
415  struct SRangesToIntVector final
416  : public Gaudi::Functional::MergingTransformer<
417  std::vector<int>( const Gaudi::Functional::vector_of_const_<Gaudi::Range_<std::vector<S const*>>>& ),
418  BaseClass_t> {
419 
421  : MergingTransformer( name, svcLoc, { "InputRanges", {} },
422  { "OutputLocation", "/Event/MyConcatenatedIntFromSVector" } ) {}
423 
425  const Gaudi::Functional::vector_of_const_<Gaudi::Range_<std::vector<S const*>>>& SVectors ) const override {
427  // Concatenate the input vectors to form the output
428  for ( const auto& SVector : SVectors ) {
429  info() << "Concatening range of size " << SVector.size() << endmsg;
430  for ( auto* s : SVector ) { out.push_back( s->a ); }
431  }
432  info() << "Storing output vector " << out << " to " << outputLocation() << endmsg;
433  return out;
434  }
435  };
436  DECLARE_COMPONENT( SRangesToIntVector )
437 
438  struct IntVectorsMerger final
439  : public Gaudi::Functional::MergingTransformer<
440  void( const Gaudi::Functional::vector_of_const_<std::vector<int>>& ), BaseClass_t> {
441 
443  : MergingTransformer( name, svcLoc, { "InputLocations", {} } ) {}
444 
445  void operator()( const Gaudi::Functional::vector_of_const_<std::vector<int>>& intVectors ) const override {
446  // Create a vector and pre-allocate enough space for the number of integers we have
447  auto nelements = std::accumulate( intVectors.begin(), intVectors.end(), 0,
448  []( const auto a, const auto b ) { return a + b.size(); } );
449  info() << "sum of input sizes: " << nelements << endmsg;
450  // Concatenate the input vectors to form the output
451  for ( const auto& intVector : intVectors ) { info() << "Consuming vector " << intVector << endmsg; }
452  }
453  };
454 
455  DECLARE_COMPONENT( IntVectorsMerger )
456 
458  : public Gaudi::Functional::MergingConsumer<void( Gaudi::Functional::vector_of_const_<std::vector<int>> const& ),
459  BaseClass_t> {
460  using Base =
462  BaseClass_t>;
463 
465  : Base( name, svcLoc, { "InputLocations", {} } ) {}
466 
467  void operator()( Gaudi::Functional::vector_of_const_<std::vector<int>> const& intVectors ) const override {
468  // Create a vector and pre-allocate enough space for the number of integers we have
469  auto nelements = std::accumulate( intVectors.begin(), intVectors.end(), 0,
470  []( const auto a, const auto b ) { return a + b.size(); } );
471  info() << "sum of input sizes: " << nelements << endmsg;
472  // Concatenate the input vectors to form the output
473  for ( const auto& intVector : intVectors ) { info() << "Consuming vector " << intVector << endmsg; }
474  }
475  };
476 
477  DECLARE_COMPONENT( IntVectorsMergingConsumer )
478 
479  struct MyData {
481  };
483 
484  struct RangeProducer : Gaudi::Functional::Producer<MyDataRange()> {
485 
486  RangeProducer( const std::string& name, ISvcLocator* pSvcLocator )
487  : Producer( name, pSvcLocator, KeyValue{ "TrackLocation", "" } ){};
488 
489  MyDataRange operator()() const override { return {}; }
490  };
491  DECLARE_COMPONENT( RangeProducer )
492 
493 
495  struct TwoDMerger final : public Gaudi::Functional::MergingMultiTransformer<
496  std::tuple<std::vector<int>, std::vector<double>>(
497  const Gaudi::Functional::vector_of_const_<std::vector<int>>&,
498  const Gaudi::Functional::vector_of_const_<std::vector<double>>& ),
499  BaseClass_t> {
500 
502  : MergingMultiTransformer{ name,
503  svcLoc,
504  { KeyValues{ "InputInts", {} }, KeyValues{ "InputDoubles", {} } },
505  { KeyValue{ "OutputInts", "/Event/MySummedInts" },
506  KeyValue{ "OutputDoubles", "/Event/MySummedDoubles" } } } {}
507 
510  const Gaudi::Functional::vector_of_const_<std::vector<double>>& doubleVectors ) const override {
512  auto& [is, ds] = r;
513  std::transform( begin( intVectors ), end( intVectors ), std::back_inserter( is ),
514  []( const std::vector<int>& vi ) { return std::accumulate( begin( vi ), end( vi ), 0 ); } );
515  always() << " accumulated: " << is << endmsg;
516  std::transform( begin( doubleVectors ), end( doubleVectors ), std::back_inserter( ds ),
517  []( const std::vector<double>& vd ) { return std::accumulate( begin( vd ), end( vd ), 0. ); } );
518  always() << " accumulated: " << ds << endmsg;
519  return r;
520  }
521  };
522 
523  DECLARE_COMPONENT( TwoDMerger )
524 
525  struct Foo {
526  int i;
527 
528  Foo( int i ) : i{ i } {}
529  Foo( Foo&& ) = delete;
530  Foo& operator=( Foo&& ) = delete;
531  Foo( const Foo& ) = delete;
532  Foo& operator=( const Foo& ) = delete;
533  ~Foo(){};
534  };
535 
536  struct ShrdPtrProducer final : Gaudi::Functional::Producer<std::shared_ptr<Foo>(), BaseClass_t> {
537 
539  : Producer( name, svcLoc, KeyValue( "OutputLocation", "/Event/MySharedFoo" ) ) {}
540 
541  std::shared_ptr<Foo> operator()() const override {
542  auto foo = std::make_shared<Foo>( m_value.value() );
543  info() << "executing ShrdPtrProducer, storing shared_ptr<Foo> with payload at " << foo.get() << " and value "
544  << foo->i << " into " << outputLocation() << endmsg;
545  return foo;
546  }
547 
548  Gaudi::Property<int> m_value{ this, "Value", 7, "The integer value to produce." };
549  };
550 
551  DECLARE_COMPONENT( ShrdPtrProducer )
552 
553  struct ShrdPtrConsumer final : Gaudi::Functional::Consumer<void( std::shared_ptr<Foo> const& ), BaseClass_t> {
554 
556  : Consumer( name, svcLoc, KeyValue( "InputLocation", "/Event/MySharedFoo" ) ) {}
557 
558  void operator()( const std::shared_ptr<Foo>& foo ) const override {
559  info() << "executing ShrdPtrConsumer, got shared_ptr<Foo> with payload at " << foo.get() << " with value "
560  << foo->i << " from " << inputLocation() << endmsg;
561  }
562  };
563 
564  DECLARE_COMPONENT( ShrdPtrConsumer )
565 
566 
569  struct IntVectorsToInts final
570  : public Gaudi::Functional::SplittingMergingTransformer<
571  std::vector<int>( const Gaudi::Functional::vector_of_const_<std::vector<int>>& ), BaseClass_t> {
572 
573  Gaudi::Property<std::vector<std::pair<int, int>>> m_mapping{ this, "Mapping", {} };
574 
576  : SplittingMergingTransformer( name, svcLoc, { "InputLocations", {} }, { "OutputLocations", {} } ) {}
577 
579  operator()( const Gaudi::Functional::vector_of_const_<std::vector<int>>& intVectors ) const override {
580  int l = 0;
581  for ( const auto& iv : intVectors ) { info() << "loaded " << iv << " from " << inputLocation( l++ ) << endmsg; }
582  std::vector<int> out( outputLocationSize(), 0 );
583  for ( const auto& [l, r] : m_mapping.value() ) {
584  out[l] = std::accumulate( intVectors.at( r ).begin(), intVectors.at( r ).end(), out[l] );
585  }
586  l = 0;
587  for ( const auto& o : out ) { info() << "storing " << o << " in " << outputLocation( l++ ) << endmsg; }
588  return out;
589  }
590  };
591  DECLARE_COMPONENT( IntVectorsToInts )
592 
593  struct Eventually {
594  Gaudi::Algorithm const* parent = nullptr;
595  void ( *action )( Gaudi::Algorithm const* ) = nullptr;
596  Eventually( Gaudi::Algorithm const* p, void ( *a )( Gaudi::Algorithm const* ) ) : parent{ p }, action{ a } {}
597  Eventually( Eventually const& ) = delete;
598  Eventually& operator=( Eventually const& ) = delete;
600  : parent{ std::exchange( other.parent, nullptr ) }, action{ std::exchange( other.action, nullptr ) } {}
602  parent = std::exchange( other.parent, nullptr );
603  action = std::exchange( other.action, nullptr );
604  return *this;
605  }
607  if ( action ) action( parent );
608  }
609  };
610 
611  struct OpaqueProducer final
613  Eventually(),
614  Gaudi::Functional::Traits::use_<BaseClass_t, Gaudi::Functional::Traits::WriteOpaqueFor<Eventually>>> {
615 
617  : Producer( name, svcLoc, KeyValue( "OutputLocation", "/Event/Eventually" ) ) {}
618 
619  Eventually operator()() const override {
620  always() << "creating Eventually" << endmsg;
621  return Eventually{ this, []( Gaudi::Algorithm const* me ) {
622  me->always() << "My Eventually is about to be destroyed" << endmsg;
623  } };
624  }
625  };
626 
627  DECLARE_COMPONENT( OpaqueProducer )
628 
629 } // namespace Gaudi::Examples
Gaudi::Examples::SRangesToIntVector::operator()
std::vector< int > operator()(const Gaudi::Functional::vector_of_const_< Gaudi::Range_< std::vector< S const * >>> &SVectors) const override
Definition: MakeAndConsume.cpp:424
Gaudi::Examples::IntVectorsMerger::operator()
void operator()(const Gaudi::Functional::vector_of_const_< std::vector< int >> &intVectors) const override
Definition: MakeAndConsume.cpp:445
Gaudi::Examples::SRangesToIntVector::SRangesToIntVector
SRangesToIntVector(const std::string &name, ISvcLocator *svcLoc)
Definition: MakeAndConsume.cpp:420
Gaudi::Examples::OptLdExpTransformer::OptLdExpTransformer
OptLdExpTransformer(const std::string &name, ISvcLocator *svcLoc)
Definition: MakeAndConsume.cpp:362
Gaudi::Examples::ContextTransformer::operator()
int operator()(const EventContext &ctx) const override
Definition: MakeAndConsume.cpp:262
Gaudi::Examples::IntVectorsMergingConsumer::IntVectorsMergingConsumer
IntVectorsMergingConsumer(const std::string &name, ISvcLocator *svcLoc)
Definition: MakeAndConsume.cpp:464
std::make_tuple
T make_tuple(T... args)
Gaudi::Functional::MergingTransformer
details::MergingTransformer< Signature, Traits_, details::isLegacy< Traits_ > > MergingTransformer
Definition: MergingTransformer.h:236
Gaudi::Examples::LdExpTransformer
Definition: MakeAndConsume.cpp:341
Gaudi::Functional::Consumer
details::Consumer< Signature, Traits_, details::isLegacy< Traits_ > > Consumer
Definition: Consumer.h:69
Gaudi::Examples::ToolConsumer
Definition: MakeAndConsume.cpp:61
Gaudi::Examples::IntIntToFloatFloatData
Definition: MakeAndConsume.cpp:185
Gaudi::Examples::MyConsumerTool::BoundInstance::operator()
void operator()() const override
Definition: MakeAndConsume.cpp:52
std::string
STL class.
std::shared_ptr
STL class.
Gaudi::Examples::OpaqueProducer::OpaqueProducer
OpaqueProducer(const std::string &name, ISvcLocator *svcLoc)
Definition: MakeAndConsume.cpp:616
Gaudi::Examples::VoidConsumer
Definition: MakeAndConsume.cpp:382
Gaudi::Examples::OptFrExpTransformer::operator()
std::optional< std::tuple< double, int > > operator()(const double &d) const
Definition: MakeAndConsume.cpp:326
Gaudi::Examples::IntVectorsToIntVector::operator()
std::vector< int > operator()(const Gaudi::Functional::vector_of_const_< std::vector< int >> &intVectors) const override
Definition: MakeAndConsume.cpp:216
Gaudi::Examples::Foo::operator=
Foo & operator=(const Foo &)=delete
std::move
T move(T... args)
Gaudi::Examples::MyExampleTool::m_message
Gaudi::Property< std::string > m_message
Definition: MakeAndConsume.cpp:37
Gaudi::Examples::IntFloatToFloatData::IntFloatToFloatData
IntFloatToFloatData(const std::string &name, ISvcLocator *svcLoc)
Definition: MakeAndConsume.cpp:170
Gaudi::Examples::IntVectorsToIntVector::IntVectorsToIntVector
IntVectorsToIntVector(const std::string &name, ISvcLocator *svcLoc)
Definition: MakeAndConsume.cpp:211
KeyedObject::KeyedObject
KeyedObject()=default
Standard Constructor. The object key is preset to the invalid value.
Gaudi::Examples::ToolConsumer::operator()
void operator()(IMyTool const &tool) const override
Definition: MakeAndConsume.cpp:65
Gaudi::Examples::IntDataProducer
Definition: MakeAndConsume.cpp:92
Gaudi::Examples::MyConsumerTool::BoundInstance::parent
MyConsumerTool const * parent
Definition: MakeAndConsume.cpp:47
Gaudi::Examples::CountingConsumer
Definition: MakeAndConsume.cpp:69
Gaudi::Examples::IMyTool::DeclareInterfaceID
DeclareInterfaceID(IMyTool, 1, 0)
Gaudi::Examples::LdExpTransformer::operator()
double operator()(double frac, int i) const
Definition: MakeAndConsume.cpp:350
gaudirun.s
string s
Definition: gaudirun.py:348
Gaudi::Examples::SDataProducer::j
Gaudi::Property< int > j
Definition: MakeAndConsume.cpp:410
std::vector< int >
Gaudi::Examples::IMyTool::operator()
virtual void operator()() const =0
Gaudi::Examples::IMyTool
Definition: MakeAndConsume.cpp:29
ISvcLocator
Definition: ISvcLocator.h:46
std::back_inserter
T back_inserter(T... args)
Gaudi::Examples::OptFrExpTransformer
Definition: MakeAndConsume.cpp:318
Gaudi::Examples::LdExpTransformer::LdExpTransformer
LdExpTransformer(const std::string &name, ISvcLocator *svcLoc)
Definition: MakeAndConsume.cpp:342
Gaudi::Examples::Eventually::operator=
Eventually & operator=(Eventually const &)=delete
std::shared_ptr::get
T get(T... args)
Gaudi::Examples::SDataProducer::operator()
S::Container operator()() const override
Definition: MakeAndConsume.cpp:404
Gaudi::Examples::IntVectorsMerger
Definition: MakeAndConsume.cpp:440
Gaudi::Examples::ShrdPtrConsumer
Definition: MakeAndConsume.cpp:553
std::tuple
Gaudi::Examples::ShrdPtrProducer::ShrdPtrProducer
ShrdPtrProducer(const std::string &name, ISvcLocator *svcLoc)
Definition: MakeAndConsume.cpp:538
Containers
Containers namespace.
Definition: KeyedObjectManager.h:28
Gaudi::Functional::details::vector_of_const_
Definition: FunctionalDetails.h:294
Gaudi::Examples::VectorDataProducer::VectorDataProducer
VectorDataProducer(const std::string &name, ISvcLocator *svcLoc)
Definition: MakeAndConsume.cpp:111
extend_interfaces
Base class to be used to extend an interface.
Definition: extend_interfaces.h:15
KeyedContainer.h
Gaudi::Examples::MyConsumerTool::MyConsumerTool
MyConsumerTool(std::string type, std::string name, const IInterface *parent)
Definition: MakeAndConsume.cpp:42
Gaudi::Functional::MergingConsumer
details::MergingTransformer< Signature, Traits_, details::isLegacy< Traits_ > > MergingConsumer
Definition: MergingTransformer.h:241
Gaudi::Examples::Eventually::operator=
Eventually & operator=(Eventually &&other)
Definition: MakeAndConsume.cpp:601
Gaudi::Examples::Eventually::Eventually
Eventually(Eventually const &)=delete
Gaudi::Examples::IntVectorsToInts::operator()
std::vector< int > operator()(const Gaudi::Functional::vector_of_const_< std::vector< int >> &intVectors) const override
Definition: MakeAndConsume.cpp:579
Gaudi::Examples::Foo::~Foo
~Foo()
Definition: MakeAndConsume.cpp:533
Gaudi::Functional::details::Consumer
Definition: Consumer.h:24
Gaudi::Functional::ToolBinder
details::ToolBinder< Signature, Traits_ > ToolBinder
Definition: FunctionalTool.h:86
Gaudi::Examples::ToolConsumer::ToolConsumer
ToolConsumer(const std::string &name, ISvcLocator *svcLoc)
Definition: MakeAndConsume.cpp:62
Gaudi::Examples::FloatDataConsumer::FloatDataConsumer
FloatDataConsumer(const std::string &name, ISvcLocator *svcLoc)
Definition: MakeAndConsume.cpp:236
Gaudi::Examples::ContextTransformer
Definition: MakeAndConsume.cpp:257
Gaudi::Examples::SDataProducer::SDataProducer
SDataProducer(const std::string &name, ISvcLocator *svcLoc)
Definition: MakeAndConsume.cpp:401
Gaudi::Examples::VoidConsumer::operator()
void operator()() const override
Definition: MakeAndConsume.cpp:386
Gaudi::Examples::IntDataConsumer::IntDataConsumer
IntDataConsumer(const std::string &name, ISvcLocator *svcLoc)
Definition: MakeAndConsume.cpp:143
std::frexp
T frexp(T... args)
Gaudi::Examples::ShrdPtrProducer::operator()
std::shared_ptr< Foo > operator()() const override
Definition: MakeAndConsume.cpp:541
Gaudi::Examples::ContextIntConsumer
Definition: MakeAndConsume.cpp:270
Gaudi::Examples::Eventually::Eventually
Eventually(Eventually &&other)
Definition: MakeAndConsume.cpp:599
KeyedContainer::add
long add(ContainedObject *pObject) override
ObjectContainerBase overload: Add an object to the container.
Definition: KeyedContainer.h:599
ScalarTransformer.h
Gaudi::Examples::ShrdPtrConsumer::ShrdPtrConsumer
ShrdPtrConsumer(const std::string &name, ISvcLocator *svcLoc)
Definition: MakeAndConsume.cpp:555
Gaudi::Examples::FrExpTransformer::FrExpTransformer
FrExpTransformer(const std::string &name, ISvcLocator *svcLoc)
Definition: MakeAndConsume.cpp:299
Gaudi::Examples::OptLdExpTransformer
Definition: MakeAndConsume.cpp:361
bug_34121.tool
tool
Definition: bug_34121.py:17
Gaudi::Examples::VectorDoubleProducer::operator()
std::vector< double > operator()() const override
Definition: MakeAndConsume.cpp:287
Gaudi::Examples::ShrdPtrProducer
Definition: MakeAndConsume.cpp:536
Gaudi::Examples::SRangesToIntVector
Definition: MakeAndConsume.cpp:418
TimingHistograms.name
name
Definition: TimingHistograms.py:25
GaudiPython.Pythonizations.ctx
ctx
Definition: Pythonizations.py:588
Gaudi::Examples
Definition: ConditionAccessorHolder.h:21
Gaudi::Functional::details::MergingTransformer
Definition: MergingTransformer.h:50
FunctionalTool.h
Gaudi::Examples::ShrdPtrConsumer::operator()
void operator()(const std::shared_ptr< Foo > &foo) const override
Definition: MakeAndConsume.cpp:558
Consumer.h
HistoDumpEx.r
r
Definition: HistoDumpEx.py:20
Gaudi::Examples::MyConsumerTool::BoundInstance
Definition: MakeAndConsume.cpp:46
Gaudi::Functional::Producer
details::Producer< Signature, Traits_, details::isLegacy< Traits_ > > Producer
Definition: Producer.h:37
Gaudi::Examples::ContextConsumer::operator()
void operator()(const EventContext &ctx) const override
Definition: MakeAndConsume.cpp:250
Gaudi::Examples::CountingConsumer::operator()
void operator()() const override
Definition: MakeAndConsume.cpp:75
Gaudi::Examples::TwoDMerger::TwoDMerger
TwoDMerger(const std::string &name, ISvcLocator *svcLoc)
Definition: MakeAndConsume.cpp:501
CLHEP::begin
double * begin(CLHEP::HepVector &v)
Definition: TupleAlg.cpp:45
Gaudi::Examples::KeyedDataProducer::KeyedDataProducer
KeyedDataProducer(const std::string &name, ISvcLocator *svcLoc)
Definition: MakeAndConsume.cpp:125
Gaudi::Examples::IntVectorsToInts::IntVectorsToInts
IntVectorsToInts(const std::string &name, ISvcLocator *svcLoc)
Definition: MakeAndConsume.cpp:575
Gaudi::Examples::IntIntToFloatFloatData::operator()
std::tuple< float, float > operator()(const int &input1, const int &input2) const override
Definition: MakeAndConsume.cpp:193
Gaudi::Examples::KeyedDataProducer
Definition: MakeAndConsume.cpp:123
Gaudi::Examples::VectorDataProducer::operator()
std::vector< int > operator()() const override
Definition: MakeAndConsume.cpp:114
IAlgTool.h
Gaudi::Examples::Foo::Foo
Foo(Foo &&)=delete
Gaudi::Algorithm
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:90
Gaudi::Examples::Foo::i
int i
Definition: MakeAndConsume.cpp:526
Producer.h
Gaudi::Examples::ContextIntConsumer::ContextIntConsumer
ContextIntConsumer(const std::string &name, ISvcLocator *svcLoc)
Definition: MakeAndConsume.cpp:272
Gaudi::Examples::IntVectorsToInts
transform a vector of vector of int to a vector of int, where the output vector of in is scattered in...
Definition: MakeAndConsume.cpp:571
Gaudi::Examples::S::a
int a
Definition: MakeAndConsume.cpp:393
Gaudi::Examples::Eventually::~Eventually
~Eventually()
Definition: MakeAndConsume.cpp:606
Gaudi::Examples::IntToFloatData::operator()
float operator()(const int &input) const override
Definition: MakeAndConsume.cpp:159
Gaudi::Property::value
const ValueType & value() const
Definition: Property.h:239
Gaudi::Examples::RangeProducer::operator()
MyDataRange operator()() const override
Definition: MakeAndConsume.cpp:489
Gaudi::Examples::FloatDataConsumer::operator()
void operator()(const float &input) const override
Definition: MakeAndConsume.cpp:239
Gaudi::Examples::TwoDMerger
Concatenates a list of input vectors into a single output vector.
Definition: MakeAndConsume.cpp:499
SharedObjectsContainer
Definition: SharedObjectsContainer.h:39
Gaudi::Examples::MyExampleTool::operator()
void operator()() const override
Definition: MakeAndConsume.cpp:36
Gaudi::Examples::ContextIntConsumer::operator()
void operator()(const EventContext &ctx, const int &i) const override
Definition: MakeAndConsume.cpp:275
Gaudi::Examples::ContextTransformer::ContextTransformer
ContextTransformer(const std::string &name, ISvcLocator *svcLoc)
Definition: MakeAndConsume.cpp:259
Gaudi::Examples::ContextConsumer
Definition: MakeAndConsume.cpp:246
KeyedContainer
template class KeyedContainer, KeyedContainer.h
Definition: KeyedContainer.h:74
std::accumulate
T accumulate(T... args)
Gaudi::Examples::FrExpTransformer::operator()
std::tuple< double, int > operator()(const double &d) const
Definition: MakeAndConsume.cpp:306
Gaudi::Examples::TwoDMerger::operator()
std::tuple< std::vector< int >, std::vector< double > > operator()(const Gaudi::Functional::vector_of_const_< std::vector< int >> &intVectors, const Gaudi::Functional::vector_of_const_< std::vector< double >> &doubleVectors) const override
Definition: MakeAndConsume.cpp:509
Transformer.h
Gaudi::Examples::S
Definition: MakeAndConsume.cpp:391
Gaudi::Functional::details::Producer
Definition: Producer.h:22
KeyedObject
Definition of the templated KeyedObject class.
Definition: KeyedObject.h:39
Gaudi::Examples::VectorDataProducer
Definition: MakeAndConsume.cpp:107
Gaudi::Examples::OptFrExpTransformer::OptFrExpTransformer
OptFrExpTransformer(const std::string &name, ISvcLocator *svcLoc)
Definition: MakeAndConsume.cpp:319
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:203
Gaudi::Accumulators::MsgCounter< MSG::ERROR >
Gaudi::Examples::IntVectorsMergingConsumer::operator()
void operator()(Gaudi::Functional::vector_of_const_< std::vector< int >> const &intVectors) const override
Definition: MakeAndConsume.cpp:467
Gaudi::Examples::RangeProducer::RangeProducer
RangeProducer(const std::string &name, ISvcLocator *pSvcLocator)
Definition: MakeAndConsume.cpp:486
Gaudi::Examples::VectorDoubleProducer
Definition: MakeAndConsume.cpp:282
extends
Base class used to extend a class implementing other interfaces.
Definition: extends.h:20
std::transform
T transform(T... args)
Gaudi::Interface::Bind::Stub
Definition: IBinder.h:95
Gaudi
Header file for std:chrono::duration-based Counters.
Definition: __init__.py:1
SharedObjectsContainer.h
IBinder.h
Gaudi::Examples::IntToFloatData::IntToFloatData
IntToFloatData(const std::string &name, ISvcLocator *svcLoc)
Definition: MakeAndConsume.cpp:155
Gaudi::Examples::Eventually
Definition: MakeAndConsume.cpp:593
Gaudi ::Functional::MultiTransformer
details::MultiTransformer< Signature, Traits_, details::isLegacy< Traits_ > > MultiTransformer
Definition: Transformer.h:241
Gaudi::Examples::MyData
Definition: MakeAndConsume.cpp:479
Gaudi::Range_
Definition: Range.h:95
Containers::vector
struct GAUDI_API vector
Parametrisation class for vector-like implementation.
Definition: KeyedObjectManager.h:39
Gaudi::Examples::IntVectorsMergingConsumer
Definition: MakeAndConsume.cpp:459
Gaudi::Examples::FloatDataConsumer
Definition: MakeAndConsume.cpp:234
gaudirun.type
type
Definition: gaudirun.py:162
Gaudi::Examples::RangeProducer
Definition: MakeAndConsume.cpp:484
Gaudi::Examples::Foo::Foo
Foo(int i)
Definition: MakeAndConsume.cpp:528
Gaudi::Examples::IntFloatToFloatData
Definition: MakeAndConsume.cpp:168
Gaudi::Examples::IntDataProducer::IntDataProducer
IntDataProducer(const std::string &name, ISvcLocator *svcLoc)
Definition: MakeAndConsume.cpp:94
Gaudi::Examples::OpaqueProducer
Definition: MakeAndConsume.cpp:614
Gaudi::Examples::MyExampleTool
Definition: MakeAndConsume.cpp:34
Gaudi::Examples::ShrdPtrProducer::m_value
Gaudi::Property< int > m_value
Definition: MakeAndConsume.cpp:548
Gaudi::Examples::Foo
Definition: MakeAndConsume.cpp:525
gaudirun.l
dictionary l
Definition: gaudirun.py:582
MergingTransformer.h
std
STL namespace.
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
Gaudi::Examples::Eventually::Eventually
Eventually(Gaudi::Algorithm const *p, void(*a)(Gaudi::Algorithm const *))
Definition: MakeAndConsume.cpp:596
Gaudi::Functional::SplittingMergingTransformer
details::SplittingMergingTransformer< Signature, Traits_, false > SplittingMergingTransformer
Definition: SplittingMergingTransformer.h:126
IInterface
Definition: IInterface.h:237
Gaudi::Examples::MyConsumerTool::BoundInstance::BoundInstance
BoundInstance(MyConsumerTool const *parent, const int &i)
Definition: MakeAndConsume.cpp:51
EventContext
Definition: EventContext.h:34
Gaudi::Functional::Traits::BaseClass_t
Definition: FunctionalUtilities.h:72
Gaudi::Examples::MyConsumerTool
Definition: MakeAndConsume.cpp:41
Gaudi::Examples::IntToFloatData
Definition: MakeAndConsume.cpp:153
Gaudi::Examples::SDataProducer
Definition: MakeAndConsume.cpp:399
Gaudi::Examples::IntVectorsToIntVector
Concatenates a list of input vectors into a single output vector.
Definition: MakeAndConsume.cpp:209
Gaudi ::Functional::Transformer
details::Transformer< Signature, Traits_, details::isLegacy< Traits_ > > Transformer
Definition: Transformer.h:238
Gaudi::Examples::Foo::operator=
Foo & operator=(Foo &&)=delete
Gaudi::Examples::MyConsumerTool::BoundInstance::i
int i
Definition: MakeAndConsume.cpp:48
Gaudi::Examples::IntDataConsumer
Definition: MakeAndConsume.cpp:141
AlgTool.h
SplittingMergingTransformer.h
gaudirun.action
action
Definition: gaudirun.py:155
Gaudi::Examples::IntVectorsMerger::IntVectorsMerger
IntVectorsMerger(const std::string &name, ISvcLocator *svcLoc)
Definition: MakeAndConsume.cpp:442
IOTest.end
end
Definition: IOTest.py:123
std::ldexp
T ldexp(T... args)
Containers::HashMap
KeyedObjectManager< hashmap > HashMap
Forward declaration of specialized std::hashmap-like object manager.
Definition: KeyedObjectManager.h:107
Gaudi::Examples::IntDataProducer::operator()
int operator()() const override
Definition: MakeAndConsume.cpp:97
Gaudi::Examples::IntFloatToFloatData::operator()
float operator()(const int &in1, const float &in2) const override
Definition: MakeAndConsume.cpp:175
Gaudi::Examples::VectorDoubleProducer::VectorDoubleProducer
VectorDoubleProducer(const std::string &name, ISvcLocator *svcLoc)
Definition: MakeAndConsume.cpp:284
Gaudi::Examples::Foo::Foo
Foo(const Foo &)=delete
Gaudi::Examples::FrExpTransformer
Definition: MakeAndConsume.cpp:298
Gaudi::Examples::IntDataConsumer::operator()
void operator()(const int &input) const override
Definition: MakeAndConsume.cpp:146
Gaudi::Examples::IntIntToFloatFloatData::IntIntToFloatFloatData
IntIntToFloatFloatData(const std::string &name, ISvcLocator *svcLoc)
Definition: MakeAndConsume.cpp:186
Gaudi::Examples::OpaqueProducer::operator()
Eventually operator()() const override
Definition: MakeAndConsume.cpp:619
Gaudi::Property< std::string >
PrepareBase.out
out
Definition: PrepareBase.py:20
Gaudi::Examples::OptLdExpTransformer::operator()
std::optional< double > operator()(const double &frac, const int &i) const
Definition: MakeAndConsume.cpp:370
Gaudi::Examples::KeyedDataProducer::operator()
int_container operator()() const override
Definition: MakeAndConsume.cpp:128