The Gaudi Framework  v29r0 (ff2e7097)
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?
10 #include "GaudiAlg/GaudiHistoAlg.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
22  {
23  return boost::algorithm::join( c, ":" );
24  }
25 
26  template <typename... Strings>
27  std::string concat_alternatives( const Strings&... s )
28  {
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  {
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 ;-)
94 
95  // example: use AnyDataHandle as input and output, and the default BaseClass
97 
98  // this example uses GaudiHistoAlg as baseclass, and the default handle types for
99  // input and output
101  }
102  }
103 }
104 
105 #endif
Define general base for Gaudi exception.
std::string concat_alternatives(std::initializer_list< std::string > c)
Header file for class GaudiAlgorithm.
void updateHandleLocation(IProperty &parent, const std::string &prop, const std::string &newLoc)
Provide serialization function (output only) for some common STL classes (vectors, lists, pairs, maps) plus GaudiUtils::Map and GaudiUtils::HashMap.
void updateReadHandleLocation(IProperty &parent, const std::string &prop, const std::string &newLoc)
STL class.
virtual StatusCode setProperty(const Gaudi::Details::PropertyBase &p)=0
Set the property by property.
void updateHandleLocations(IProperty &parent, const std::string &prop, const std::vector< std::string > &newLocs)
Stream & ostream_joiner(Stream &os, Iterator first, Iterator last, Separator sep, OutputElement output=OutputElement{})
Definition: SerializeSTL.h:40
string s
Definition: gaudirun.py:253
The IProperty is the basic interface for all components which have properties that can be set or get...
Definition: IProperty.h:20
STL class.
Helper functions to set/get the application return code.
Definition: __init__.py:1