The Gaudi Framework  master (37c0b60a)
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 \***********************************************************************************/
13 #include <GaudiKernel/Algorithm.h>
15 #include <gsl/span>
16 #include <string>
17 #include <string_view>
18 #include <vector>
19 
21 
22 template <typename Data, typename View>
24 
25 struct ProduceStringView : Gaudi::Functional::Producer<std::string(), writeViewFor<std::string, std::string_view>> {
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>>> {
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 
46 struct GetStringView : Gaudi::Functional::Consumer<void( std::string_view const& ), BaseClass_t> {
48  : Consumer{ name, svcLoc, { "Input", "/Event/Test/StringView" } } {}
49 
50  void operator()( const std::string_view& sv ) const override { info() << sv << endmsg; }
51 };
53 
54 struct GetIntView : Gaudi::Functional::Consumer<void( gsl::span<const int> const& ), BaseClass_t> {
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 };
GetStringView::operator()
void operator()(const std::string_view &sv) const override
Definition: AnyViewAlgorithm.cpp:50
ProduceIntView::ProduceIntView
ProduceIntView(const std::string &name, ISvcLocator *svcLoc)
Definition: AnyViewAlgorithm.cpp:35
GetIntView::operator()
void operator()(const gsl::span< const int > &view) const override
Definition: AnyViewAlgorithm.cpp:58
Gaudi::Functional::Consumer
details::Consumer< Signature, Traits_, details::isLegacy< Traits_ > > Consumer
Definition: Consumer.h:69
std::string
STL class.
GetStringView::GetStringView
GetStringView(const std::string &name, ISvcLocator *svcLoc)
Definition: AnyViewAlgorithm.cpp:47
std::vector< int >
ISvcLocator
Definition: ISvcLocator.h:46
GetIntView
Definition: AnyViewAlgorithm.cpp:54
Algorithm.h
ProduceStringView::ProduceStringView
ProduceStringView(const std::string &name, ISvcLocator *svcLoc)
Definition: AnyViewAlgorithm.cpp:26
Consumer.h
Gaudi::Functional::Producer
details::Producer< Signature, Traits_, details::isLegacy< Traits_ > > Producer
Definition: Producer.h:37
Producer.h
Gaudi::Functional::Traits::use_
Definition: utilities.h:34
Gaudi::Functional::details::Producer
Definition: Producer.h:22
ProduceIntView::operator()
std::vector< int > operator()() const override
Definition: AnyViewAlgorithm.cpp:38
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
ProduceStringView
Definition: AnyViewAlgorithm.cpp:25
ProduceIntView
Definition: AnyViewAlgorithm.cpp:34
Gaudi
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition: __init__.py:1
Containers::vector
struct GAUDI_API vector
Parametrisation class for vector-like implementation.
Definition: KeyedObjectManager.h:39
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
std
STL namespace.
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
Gaudi::Functional::Traits::BaseClass_t
Definition: utilities.h:38
ProduceStringView::operator()
std::string operator()() const override
Definition: AnyViewAlgorithm.cpp:29
GetStringView
Definition: AnyViewAlgorithm.cpp:46
DataObjectHandle.h
std::vector::data
T data(T... args)
GetIntView::GetIntView
GetIntView(const std::string &name, ISvcLocator *svcLoc)
Definition: AnyViewAlgorithm.cpp:55
PrepareBase.out
out
Definition: PrepareBase.py:20