The Gaudi Framework  master (5e4eb178)
Loading...
Searching...
No Matches
merging_transformer.cpp
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2026 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\***********************************************************************************/
12#include <string>
13
15using is2f_merger_base = Gaudi::Functional::MergingTransformer<float( ints const&, int const& )>;
17using out_t = std::tuple<float, float>;
23using filter_out_t = std::tuple<bool, float, float>;
24
26 is2f_merger_with_scalar( std::string const& name, ISvcLocator* pSvcLocator )
27 : is2f_merger_base( name, pSvcLocator, { { "InputInts", { "firstInt", "secondInt" } }, { "Scale", "scale" } },
28 { "Output", "scaledSum" } ) {}
29
30 float operator()( ints const& is, int const& scale ) const override {
31 auto sum = 0.f;
32 info() << "input locations: " << inputLocation( 0 ) << ", " << inputLocation<1>() << endmsg;
33 info() << "input location sizes: " << inputLocationSize( 0 ) << ", " << inputLocationSize( 1 ) << endmsg;
34 for ( auto i : is ) {
35 info() << "i: " << i << " ";
36 sum += i;
37 }
38 info() << "scale: " << scale << endmsg;
39 return sum * scale;
40 }
41};
42
44
46 is_merger_consumer_with_scalar( std::string const& name, ISvcLocator* pSvcLocator )
47 : is_merger_consumer_base( name, pSvcLocator,
48 { { "InputInts", { "firstInt", "secondInt" } }, { "Scale", "scale" } } ) {}
49
50 void operator()( ints const& is, int const& scale ) const override {
51 auto sum = 0;
52 for ( auto i : is ) { sum += i; }
53 info() << "consumed scaled sum: " << sum * scale << " from " << inputLocation( 0 ) << " and " << inputLocation<1>()
54 << endmsg;
55 }
56};
57
59
61 is2ff_merger( std::string const& name, ISvcLocator* pSvcLocator )
62 : is2ff_merger_base( name, pSvcLocator, { "InputInts", { "firstInt", "secondInt" } },
63 { { "O1", "firstFloat" }, { "O2", "secondFloat" } } ) {}
64
65 out_t operator()( ints const& is ) const override {
66 float f1 = 1, f2 = 1;
67
68 for ( auto i : is ) {
69 info() << "i: " << i << " ";
70 f1 *= i;
71 f2 *= 1.f / i;
72 }
73 info() << endmsg;
74 return { f1, f2 };
75 }
76};
77
79
81 is2ff_merger_with_scalar( std::string const& name, ISvcLocator* pSvcLocator )
82 : is2ff_merger_scalar_base( name, pSvcLocator,
83 { { "InputInts", { "firstInt", "secondInt" } }, { "Scale", "scale" } },
84 { { "O1", "firstFloat" }, { "O2", "secondFloat" } } ) {}
85
86 out_t operator()( ints const& is, int const& scale ) const override {
87 float sum = 0, product = 1;
88
89 for ( auto i : is ) {
90 info() << "i: " << i << " ";
91 sum += i;
92 product *= i;
93 }
94 info() << "scale: " << scale << endmsg;
95 return { sum * scale, product * scale };
96 }
97};
98
100
102 is2ff_merger_filter( std::string const& name, ISvcLocator* pSvcLocator )
103 : is2ff_merger_filter_base( name, pSvcLocator, { "InputInts", { "firstInt", "secondInt" } },
104 { { "O1", "firstFloat" }, { "O2", "secondFloat" } } ) {}
105
106 filter_out_t operator()( ints const& is ) const override {
107 float f1 = 1, f2 = 1;
108
109 for ( auto i : is ) {
110 info() << "i: " << i << " ";
111 f1 *= i;
112 f2 *= 1.f / i;
113 }
114 info() << endmsg;
115 auto filter_passed = f1 > 10;
116 info() << "Filter " << ( filter_passed ? "passed" : "failed" ) << endmsg;
117 return { filter_passed, f1, f2 };
118 }
119};
120
122
124 is2ff_merger_filter_with_scalar( std::string const& name, ISvcLocator* pSvcLocator )
125 : is2ff_merger_filter_scalar_base( name, pSvcLocator,
126 { { "InputInts", { "firstInt", "secondInt" } }, { "Scale", "scale" } },
127 { { "O1", "firstFloat" }, { "O2", "secondFloat" } } ) {}
128
129 filter_out_t operator()( ints const& is, int const& scale ) const override {
130 float product = 1, inverse = 1;
131
132 for ( auto i : is ) {
133 info() << "i: " << i << " ";
134 product *= i;
135 inverse *= 1.f / i;
136 }
137 info() << "scale: " << scale << endmsg;
138 product *= scale;
139 inverse *= scale;
140 auto filter_passed = product > 10;
141 info() << "Filter " << ( filter_passed ? "passed" : "failed" ) << endmsg;
142 return { filter_passed, product, inverse };
143 }
144};
145
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
#define DECLARE_COMPONENT(type)
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition ISvcLocator.h:42
std::tuple< float, float > out_t
Gaudi::Functional::MergingMultiTransformerFilter< out_t(ints const &, int const &)> is2ff_merger_filter_scalar_base
std::tuple< bool, float, float > filter_out_t
Gaudi::Functional::MergingMultiTransformerFilter< out_t(ints const &)> is2ff_merger_filter_base
Gaudi::Functional::MergingTransformer< float(ints const &, int const &)> is2f_merger_base
Gaudi::Functional::MergingMultiTransformer< out_t(ints const &)> is2ff_merger_base
Gaudi::Functional::vector_of_const_< int > ints
Gaudi::Functional::MergingMultiTransformer< out_t(ints const &, int const &)> is2ff_merger_scalar_base
Gaudi::Functional::MergingConsumer< void(ints const &, int const &)> is_merger_consumer_base
details::MergingTransformer< Signature, Traits_, details::isLegacy< Traits_ > > MergingTransformer
details::MergingTransformer< Signature, Traits_, details::isLegacy< Traits_ > > MergingConsumer
is2f_merger_with_scalar(std::string const &name, ISvcLocator *pSvcLocator)
float operator()(ints const &is, int const &scale) const override
is2ff_merger_filter_with_scalar(std::string const &name, ISvcLocator *pSvcLocator)
filter_out_t operator()(ints const &is, int const &scale) const override
filter_out_t operator()(ints const &is) const override
is2ff_merger_filter(std::string const &name, ISvcLocator *pSvcLocator)
out_t operator()(ints const &is, int const &scale) const override
is2ff_merger_with_scalar(std::string const &name, ISvcLocator *pSvcLocator)
out_t operator()(ints const &is) const override
is2ff_merger(std::string const &name, ISvcLocator *pSvcLocator)
void operator()(ints const &is, int const &scale) const override
is_merger_consumer_with_scalar(std::string const &name, ISvcLocator *pSvcLocator)