| The Gaudi Framework v29r1 (5cd95fa2)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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/AnyDataHandle.h"
12 #include "GaudiKernel/DataObjectHandle.h"
13 #include "GaudiKernel/SerializeSTL.h"
14
15 namespace Gaudi
16 {
17 namespace Functional
18 {
19
20 // This utility is needed when the inputs of a functional algorithm may be stored in several locations
21 inline std::string concat_alternatives( std::initializer_list<std::string> c )
22 {
23 return boost::algorithm::join( c, ":" );
24 }
25
26 template <typename... Strings>
27 std::string concat_alternatives( const Strings&... s )
28 {
29 return concat_alternatives( std::initializer_list<std::string>{s...} );
30 }
31
32 inline void updateHandleLocation( IProperty& parent, const std::string& prop, const std::string& newLoc )
33 {
34 auto sc = parent.setProperty( prop, newLoc );
35 if ( sc.isFailure() ) throw GaudiException( "Could not set Property", prop + " -> " + newLoc, sc );
36 }
37
38 inline void updateHandleLocations( IProperty& parent, const std::string& prop,
39 const std::vector<std::string>& newLocs )
40 {
41 std::ostringstream ss;
42 GaudiUtils::details::ostream_joiner( ss << '[', newLocs, ", ", []( std::ostream & os, const auto& i ) -> auto& {
43 return os << "'" << i << "'";
44 } ) << ']';
45 auto sc = parent.setProperty( prop, ss.str() );
46 if ( sc.isFailure() ) throw GaudiException( "Could not set Property", prop + " -> " + ss.str(), sc );
47 }
48
49 [[deprecated( "please use updateHandleLocation instead" )]] inline void
50 updateReadHandleLocation( IProperty& parent, const std::string& prop, const std::string& newLoc )
51 {
52 return updateHandleLocation( parent, prop, newLoc );
53 }
54
55 namespace Traits
56 {
57
58 // traits classes used to customize Transformer and FilterPredicate
59 // Define the types to to be used as baseclass, and as in- resp. output hanldes.
60 // In case a type is not specified in the traits struct, a default is used.
61 //
62 // The defaults are:
63 //
64 // using BaseClass = GaudiAlgorithm
65 // template <typename T> using InputHandle = DataObjectHandle<T>;
66 // template <typename T> using OutputHandle = DataObjectHandle<T>;
67 //
68
69 // the best way to 'compose' traits is by inheriting them one-by-one...
70 template <typename... Base>
71 struct use_ : Base... {
72 };
73
74 // helper classes one can inherit from to specify a specific trait
75 template <typename Base>
76 struct BaseClass_t {
77 using BaseClass = Base;
78 };
79
80 template <template <typename> class Handle>
81 struct InputHandle_t {
82 template <typename T>
83 using InputHandle = Handle<T>;
84 };
85
86 template <template <typename> class Handle>
87 struct OutputHandle_t {
88 template <typename T>
89 using OutputHandle = Handle<T>;
90 };
91
92 // this uses the defaults -- and it itself is the default ;-)
93 using useDefaults = use_<>;
94
95 // example: use AnyDataHandle as input and output, and the default BaseClass
96 using useAnyDataHandle = use_<InputHandle_t<AnyDataHandle>, OutputHandle_t<AnyDataHandle>>;
97
98 // this example uses GaudiHistoAlg as baseclass, and the default handle types for
99 // input and output
100 using useGaudiHistoAlg = use_<BaseClass_t<GaudiHistoAlg>>;
101 }
102 }
103 }
104
105 #endif
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:22
gaudirun.c
c
Definition: gaudirun.py:407
Gaudi::Functional::Traits::OutputHandle_t
Definition: FunctionalUtilities.h:87
Gaudi::Functional::concat_alternatives
std::string concat_alternatives(std::initializer_list< std::string > c)
Definition: FunctionalUtilities.h:21
GaudiAlgorithm.h
Header file for class GaudiAlgorithm.
Gaudi::Functional::Traits::use_
Definition: FunctionalUtilities.h:71
Gaudi::Functional::updateHandleLocation
void updateHandleLocation(IProperty &parent, const std::string &prop, const std::string &newLoc)
Definition: FunctionalUtilities.h:32
SerializeSTL.h
Provide serialization function (output only) for some common STL classes (vectors, lists, pairs, maps) plus GaudiUtils::Map and GaudiUtils::HashMap.
Gaudi::Functional::updateReadHandleLocation
void updateReadHandleLocation(IProperty &parent, const std::string &prop, const std::string &newLoc)
Definition: FunctionalUtilities.h:50
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:38
AnyDataHandle.h
GaudiUtils::details::ostream_joiner
Stream & ostream_joiner(Stream &os, Iterator first, Iterator last, Separator sep, OutputElement output=OutputElement{})
Definition: SerializeSTL.h:40
Gaudi::Functional::Traits::InputHandle_t::InputHandle
Handle< T > InputHandle
Definition: FunctionalUtilities.h:83
Gaudi::Functional::Traits::OutputHandle_t::OutputHandle
Handle< T > OutputHandle
Definition: FunctionalUtilities.h:89
std::vector< std::string >
gaudirun.s
string s
Definition: gaudirun.py:253
GaudiHistoAlg.h
Gaudi::Functional::Traits::BaseClass_t
Definition: FunctionalUtilities.h:76
Gaudi::Functional::Traits::InputHandle_t
Definition: FunctionalUtilities.h:81
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.
Gaudi
Helper functions to set/get the application return code.
Definition: __init__.py:1
std::initializer_list
DataObjectHandle.h
Gaudi::Functional::Traits::BaseClass_t::BaseClass
Base BaseClass
Definition: FunctionalUtilities.h:77