| The Gaudi Framework v28r2p1 (f1a77ff4)

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