The Gaudi Framework  master (2e52acd2)
Loading...
Searching...
No Matches
Transformer.h
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\***********************************************************************************/
11#pragma once
12
13#include "details.h"
14#include "utilities.h"
17#include <tuple>
18#include <utility>
19
20// Adapt an Algorithm (by default, Gaudi::Algorithm) so that derived classes
21// a) do not need to access the event store, and have to explicitly
22// state their data dependencies
23// b) are encouraged not to have state which depends on the events
24// (eg. histograms, counters will have to be mutable)
25
26namespace Gaudi ::Functional {
27
28 namespace details {
29
30 template <typename Signature, typename Traits_, bool isLegacy>
32
33 // general N -> 1 algorithms
34 template <typename Out, typename... In, typename Traits_>
35 struct Transformer<Out( const In&... ), Traits_, true>
36 : DataHandleMixin<std::tuple<Out>, filter_evtcontext<In...>, Traits_> {
37 using DataHandleMixin<std::tuple<Out>, filter_evtcontext<In...>, Traits_>::DataHandleMixin;
38
39 // derived classes can NOT implement execute
40 StatusCode execute() override final {
41 return details::execute( *this, [&] {
42 put( std::get<0>( this->m_outputs ),
43 filter_evtcontext_t<In...>::apply( *this, Gaudi::Hive::currentContext(), this->m_inputs ) );
44 return FilterDecision::PASSED;
45 } );
46 }
47
48 // instead they MUST implement this operator
49 virtual Out operator()( const In&... ) const = 0;
50 };
51
52 template <typename Out, typename... In, typename Traits_>
53 struct Transformer<Out( const In&... ), Traits_, false>
54 : DataHandleMixin<std::tuple<Out>, filter_evtcontext<In...>, Traits_> {
55 using DataHandleMixin<std::tuple<Out>, filter_evtcontext<In...>, Traits_>::DataHandleMixin;
56
57 // derived classes can NOT implement execute
58 StatusCode execute( const EventContext& ctx ) const override final {
59 return details::execute( *this, [&] {
60 put( std::get<0>( this->m_outputs ), filter_evtcontext_t<In...>::apply( *this, ctx, this->m_inputs ) );
61 return FilterDecision::PASSED;
62 } );
63 }
64
65 // instead they MUST implement this operator
66 virtual Out operator()( const In&... ) const = 0;
67 };
68
69 //
70 // general N -> M algorithms
71 //
72 template <typename Signature, typename Traits_, bool isLegacy>
74
75 template <typename... Out, typename... In, typename Traits_>
76 struct MultiTransformer<std::tuple<Out...>( const In&... ), Traits_, true>
77 : DataHandleMixin<std::tuple<Out...>, filter_evtcontext<In...>, Traits_> {
78 using DataHandleMixin<std::tuple<Out...>, filter_evtcontext<In...>, Traits_>::DataHandleMixin;
79
80 // derived classes can NOT implement execute
81 StatusCode execute() override final {
82 return details::execute( *this, [&] {
83 std::apply(
84 [this]( auto&... ohandle ) {
85 std::apply( [&ohandle...](
86 auto&&... data ) { ( put( ohandle, std::forward<decltype( data )>( data ) ), ... ); },
87 filter_evtcontext_t<In...>::apply( *this, Gaudi::Hive::currentContext(), this->m_inputs ) );
88 },
89 this->m_outputs );
90 return FilterDecision::PASSED;
91 } );
92 }
93
94 // instead they MUST implement this operator
95 virtual std::tuple<Out...> operator()( const In&... ) const = 0;
96 };
97
98 template <typename... Out, typename... In, typename Traits_>
99 struct MultiTransformer<std::tuple<Out...>( const In&... ), Traits_, false>
100 : DataHandleMixin<std::tuple<Out...>, filter_evtcontext<In...>, Traits_> {
101 using DataHandleMixin<std::tuple<Out...>, filter_evtcontext<In...>, Traits_>::DataHandleMixin;
102
103 // derived classes can NOT implement execute
104 StatusCode execute( const EventContext& ctx ) const override final {
105 return details::execute( *this, [&] {
106 std::apply(
107 [this, &ctx]( auto&... ohandle ) {
108 std::apply( [&ohandle...](
109 auto&&... data ) { ( put( ohandle, std::forward<decltype( data )>( data ) ), ... ); },
110 filter_evtcontext_t<In...>::apply( *this, ctx, this->m_inputs ) );
111 },
112 this->m_outputs );
113 return FilterDecision::PASSED;
114 } );
115 }
116
117 // instead they MUST implement this operator
118 virtual std::tuple<Out...> operator()( const In&... ) const = 0;
119 };
120
121 //
122 // general N -> M algorithms with filter functionality
123 //
124 template <typename Signature, typename Traits_>
126
127 template <typename... Out, typename... In, typename Traits_>
128 struct MultiTransformerFilter<std::tuple<Out...>( const In&... ), Traits_>
129 : DataHandleMixin<std::tuple<Out...>, filter_evtcontext<In...>, Traits_> {
130 using DataHandleMixin<std::tuple<Out...>, filter_evtcontext<In...>, Traits_>::DataHandleMixin;
131
132 // derived classes can NOT implement execute
133 StatusCode execute( const EventContext& ctx ) const override final {
134 return details::execute( *this, [&] {
135 return std::apply(
136 [&]( auto&... ohandle ) {
137 return std::apply(
138 [&ohandle...]( bool passed, auto&&... data ) {
139 ( put( ohandle, std::forward<decltype( data )>( data ) ), ... );
140 return passed;
141 },
142 filter_evtcontext_t<In...>::apply( *this, ctx, this->m_inputs ) );
143 },
144 this->m_outputs )
145 ? FilterDecision::PASSED
146 : FilterDecision::FAILED;
147 } );
148 }
149
150 // instead they MUST implement this operator
151 virtual std::tuple<bool, Out...> operator()( const In&... ) const = 0;
152 };
153 } // namespace details
154
155 template <typename Signature, typename Traits_ = Traits::useDefaults>
157
158 template <typename Signature, typename Traits_ = Traits::useDefaults>
160
161 template <typename Signature, typename Traits_ = Traits::useDefaults>
163
164} // namespace Gaudi::Functional
This class represents an entry point to all the event specific data.
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
details::MultiTransformer< Signature, Traits_, details::isLegacy< Traits_ > > MultiTransformer
details::Transformer< Signature, Traits_, details::isLegacy< Traits_ > > Transformer
details::MultiTransformerFilter< Signature, Traits_ > MultiTransformerFilter
GAUDI_API const EventContext & currentContext()
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition __init__.py:1
STL namespace.
StatusCode execute(const EventContext &ctx) const override final
Definition Transformer.h:58