The Gaudi Framework  master (48d4dc99)
Loading...
Searching...
No Matches
SplittingMergingTransformer.h
Go to the documentation of this file.
1/*****************************************************************************\
2* (c) Copyright 2022-2026 CERN for the benefit of the LHCb Collaboration *
3* *
4* This software is distributed under the terms of the GNU General Public *
5* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". *
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#include "details.h"
13#include "utilities.h"
15#include <optional>
16#include <string>
17#include <vector>
18
19namespace Gaudi::Functional {
20 template <typename Container>
21 using vector_of_ = std::vector<Container>;
22 template <typename Container>
23 using vector_of_optional_ = std::vector<std::optional<Container>>;
25
26 namespace details {
27
28 template <typename Signature, typename Traits_>
30
31 template <typename Out, typename In, typename Traits_>
32 class SplittingMergingTransformer<vector_of_<Out>( const vector_of_const_<In>& ), Traits_>
33 : public BaseClass_t<Traits_> {
35 static_assert( std::is_base_of_v<Algorithm, base_class>, "BaseClass must inherit from Algorithm" );
36
37 // if In is a pointer, it signals optional (as opposed to mandatory) input
38 template <typename T>
41 template <typename T>
44
45 public:
46 using KeyValues = std::pair<std::string, std::vector<std::string>>;
47
48 SplittingMergingTransformer( std::string name, ISvcLocator* locator, const KeyValues& inputs,
49 const KeyValues& outputs )
50 : base_class( std::move( name ), locator ), m_ins{ this, inputs }, m_outs{ this, outputs } {}
51
52 // accessor to output Locations
53 const std::string& outputLocation( unsigned int n ) const { return m_outs.at( n ).key(); }
54 unsigned int outputLocationSize() const { return m_outs.size(); }
55
56 // accessor to input Locations
57 const std::string& inputLocation( unsigned int n ) const { return m_ins.at( n ).key(); }
58 unsigned int inputLocationSize() const { return m_ins.size(); }
59
60 // derived classes can NOT implement execute
61 StatusCode execute( const EventContext& ctx ) const override final {
62 return details::execute( *this, [&] {
63 // TODO:FIXME: how does operator() know the number and order of expected outputs?
64 m_outs.put( ( *this )( m_ins.get( ctx ) ) );
66 } );
67 }
68
69 // TODO/FIXME: how does the callee know in which order to produce the outputs?
70 // (note: 'missing' items can be specified by making Out an std::optional<Out>,
71 // and only those entries which contain an Out are stored)
72 virtual vector_of_<Out> operator()( const vector_of_const_<In>& ) const = 0;
73 };
74
75 } // namespace details
76
77 template <typename Signature, typename Traits_ = Traits::useDefaults>
79
80} // namespace Gaudi::Functional
This class represents an entry point to all the event specific data.
SplittingMergingTransformer(std::string name, ISvcLocator *locator, const KeyValues &inputs, const KeyValues &outputs)
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition ISvcLocator.h:42
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
typename detail2::InputHandle< T, Tr, detail2::DefaultInputHandle >::type InputHandle_t
Definition details.h:494
typename detail2::OutputHandle< T, Tr, DataObjectWriteHandle >::type OutputHandle_t
Definition details.h:491
detail2::BaseClass< Tr, Default >::type BaseClass_t
Definition details.h:485
StatusCode execute(CommonMessagingBase const &alg, F &&f)
Definition details.h:429
std::vector< Container > vector_of_
details::SplittingMergingTransformer< Signature, Traits_ > SplittingMergingTransformer
std::vector< std::optional< Container > > vector_of_optional_
STL namespace.