The Gaudi Framework  master (181af51f)
Loading...
Searching...
No Matches
AnyViewAlgorithm.cpp
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2023 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\***********************************************************************************/
15#include <gsl/span>
16#include <string>
17#include <string_view>
18#include <vector>
19
21
22template <typename Data, typename View>
24
25struct ProduceStringView : Gaudi::Functional::Producer<std::string(), writeViewFor<std::string, std::string_view>> {
26 ProduceStringView( const std::string& name, ISvcLocator* svcLoc )
27 : Producer{ name, svcLoc, { "Output", "/Event/Test/StringView" } } {}
28
29 std::string operator()() const override { return "Hello World"; }
30};
32
34 : Gaudi::Functional::Producer<std::vector<int>(), writeViewFor<std::vector<int>, gsl::span<const int>>> {
35 ProduceIntView( const std::string& name, ISvcLocator* svcLoc )
36 : Producer{ name, svcLoc, { "Output", "/Event/Test/IntView" } } {}
37
38 std::vector<int> operator()() const override {
39 std::vector<int> vi{ 1, 2, 3, 5, 8, 13, 21, 34 };
40 info() << "made vector with data at : " << vi.data() << endmsg;
41 return vi;
42 }
43};
45
46struct GetStringView : Gaudi::Functional::Consumer<void( std::string_view const& ), BaseClass_t> {
47 GetStringView( const std::string& name, ISvcLocator* svcLoc )
48 : Consumer{ name, svcLoc, { "Input", "/Event/Test/StringView" } } {}
49
50 void operator()( const std::string_view& sv ) const override { info() << sv << endmsg; }
51};
53
54struct GetIntView : Gaudi::Functional::Consumer<void( gsl::span<const int> const& ), BaseClass_t> {
55 GetIntView( const std::string& name, ISvcLocator* svcLoc )
56 : Consumer{ name, svcLoc, { "Input", "/Event/Test/IntView" } } {}
57
58 void operator()( const gsl::span<const int>& view ) const override {
59 info() << "got a span with data at : " << view.data() << endmsg;
60 auto& out = info();
61 for ( int i : view ) out << i << " ";
62 out << endmsg;
63 }
64};
Gaudi::Functional::Traits::use_< Gaudi::Functional::Traits::writeViewFor< Data, View >, BaseClass_t > writeViewFor
Gaudi::Functional::Traits::BaseClass_t< Gaudi::Algorithm > BaseClass_t
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
STL class.
details::Producer< Signature, Traits_, details::isLegacy< Traits_ > > Producer
Definition Producer.h:37
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.
GetIntView(const std::string &name, ISvcLocator *svcLoc)
void operator()(const gsl::span< const int > &view) const override
void operator()(const std::string_view &sv) const override
GetStringView(const std::string &name, ISvcLocator *svcLoc)
ProduceIntView(const std::string &name, ISvcLocator *svcLoc)
std::vector< int > operator()() const override
ProduceStringView(const std::string &name, ISvcLocator *svcLoc)
std::string operator()() const override