| The Gaudi Framework v32r1 (f65d50dc)

FunctionalUtilities.h
Go to the documentation of this file.
1 #ifndef FUNCTIONAL_UTILITIES_H
2 #define FUNCTIONAL_UTILITIES_H
3
4 #include "boost/algorithm/string/join.hpp"
5 #include <initializer_list>
6 #include <string>
7
8 // TODO: fwd declare instead?
9 #include "GaudiAlg/GaudiAlgorithm.h"
10 #include "GaudiAlg/GaudiHistoAlg.h"
11 #include "GaudiKernel/DataObjectHandle.h"
12 #include "GaudiKernel/SerializeSTL.h"
13
14 namespace Gaudi::Functional {
15
16 // This utility is needed when the inputs of a functional algorithm may be stored in several locations
17 inline std::string concat_alternatives( std::initializer_list<std::string> c ) {
18 return boost::algorithm::join( c, ":" );
19 }
20
21 template <typename... Strings>
22 std::string concat_alternatives( const Strings&... s ) {
23 return concat_alternatives( std::initializer_list<std::string>{s...} );
24 }
25
26 [[deprecated( "please use `updateHandleLocation` instead of `Gaudi::Functional::updateHandleLocation`" )]] inline void
27 updateHandleLocation( IProperty& parent, const std::string& prop, const std::string& newLoc ) {
28 auto sc = parent.setProperty( prop, newLoc );
29 if ( sc.isFailure() ) throw GaudiException( "Could not set Property", prop + " -> " + newLoc, sc );
30 }
31
32 [[deprecated(
33 "please use `updateHandleLocations` instead of `Gaudi::Functional::updateHandleLocations`" )]] inline void
34 updateHandleLocations( IProperty& parent, const std::string& prop, const std::vector<std::string>& newLocs ) {
35 std::ostringstream ss;
36 GaudiUtils::details::ostream_joiner(
37 ss << '[', newLocs, ", ", []( std::ostream & os, const auto& i ) -> auto& { return os << "'" << i << "'"; } )
38 << ']';
39 auto sc = parent.setProperty( prop, ss.str() );
40 if ( sc.isFailure() ) throw GaudiException( "Could not set Property", prop + " -> " + ss.str(), sc );
41 }
42
43 namespace Traits {
44
45 // traits classes used to customize Transformer and FilterPredicate
46 // Define the types to to be used as baseclass, and as in- resp. output hanldes.
47 // In case a type is not specified in the traits struct, a default is used.
48 //
49 // The defaults are:
50 //
51 // using BaseClass = GaudiAlgorithm
52 // template <typename T> using InputHandle = DataObjectHandle<T>;
53 // template <typename T> using OutputHandle = DataObjectHandle<T>;
54 //
55
56 // the best way to 'compose' traits is by inheriting them one-by-one...
57 template <typename... Base>
58 struct use_ : Base... {};
59
60 // helper classes one can inherit from to specify a specific trait
61 template <typename Base>
62 struct BaseClass_t {
63 using BaseClass = Base;
64 };
65
66 template <template <typename> class Handle>
67 struct InputHandle_t {
68 template <typename T>
69 using InputHandle = Handle<T>;
70 };
71
72 template <template <typename> class Handle>
73 struct OutputHandle_t {
74 template <typename T>
75 using OutputHandle = Handle<T>;
76 };
77
78 // this uses the defaults -- and it itself is the default ;-)
79 using useDefaults = use_<>;
80
81 // this example uses GaudiHistoAlg as baseclass, and the default handle types for
82 // input and output
83 using useGaudiHistoAlg = use_<BaseClass_t<GaudiHistoAlg>>;
84
85 // use Gaudi::Algorithm as base class -- this should be the base class!
86 using useAlgorithm = use_<BaseClass_t<Gaudi::Algorithm>>;
87
88 // use the legacy GaudiAlgorithm as base class -- this is (annoyingly) the current default
89 using useLegacyGaudiAlgorithm = use_<BaseClass_t<GaudiAlgorithm>>;
90
91 } // namespace Traits
92 } // namespace Gaudi::Functional
93
94 #endif
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:21
gaudirun.c
c
Definition: gaudirun.py:487
Gaudi::Functional::Traits::OutputHandle_t
Definition: FunctionalUtilities.h:73
Gaudi::Functional::concat_alternatives
std::string concat_alternatives(std::initializer_list< std::string > c)
Definition: FunctionalUtilities.h:17
GaudiAlgorithm.h
Header file for class GaudiAlgorithm.
Gaudi::Functional::Traits::use_
Definition: FunctionalUtilities.h:58
Gaudi::Functional
Definition: Consumer.h:8
Gaudi::Functional::updateHandleLocation
void updateHandleLocation(IProperty &parent, const std::string &prop, const std::string &newLoc)
Definition: FunctionalUtilities.h:27
SerializeSTL.h
Provide serialization function (output only) for some common STL classes (vectors,...
std::string
STL class.
IProperty::setProperty
virtual StatusCode setProperty(const Gaudi::Details::PropertyBase &p)=0
Set the property by property.
std::ostringstream
STL class.
std::ostringstream::str
T str(T... args)
Gaudi::Functional::updateHandleLocations
void updateHandleLocations(IProperty &parent, const std::string &prop, const std::vector< std::string > &newLocs)
Definition: FunctionalUtilities.h:34
GaudiUtils::details::ostream_joiner
Stream & ostream_joiner(Stream &os, Iterator first, Iterator last, Separator sep, OutputElement output=OutputElement{})
Definition: SerializeSTL.h:37
Gaudi::Functional::Traits::InputHandle_t::InputHandle
Handle< T > InputHandle
Definition: FunctionalUtilities.h:69
Gaudi::Functional::Traits::OutputHandle_t::OutputHandle
Handle< T > OutputHandle
Definition: FunctionalUtilities.h:75
std::vector< std::string >
gaudirun.s
string s
Definition: gaudirun.py:316
GaudiHistoAlg.h
Gaudi::Functional::Traits::BaseClass_t
Definition: FunctionalUtilities.h:62
Gaudi::Functional::Traits::InputHandle_t
Definition: FunctionalUtilities.h:67
IProperty
The IProperty is the basic interface for all components which have properties that can be set or get.
Definition: IProperty.h:20
std::ostream
STL class.
std::initializer_list
DataObjectHandle.h
Gaudi::Functional::Traits::BaseClass_t::BaseClass
Base BaseClass
Definition: FunctionalUtilities.h:63