Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v36r16 (ea80daf8)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
FunctionalUtilities.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 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 \***********************************************************************************/
11 #ifndef FUNCTIONAL_UTILITIES_H
12 #define FUNCTIONAL_UTILITIES_H
13 
14 #include "boost/algorithm/string/join.hpp"
15 #include <initializer_list>
16 #include <string>
17 
18 // TODO: fwd declare instead?
20 #include "GaudiAlg/GaudiHistoAlg.h"
23 
24 namespace Gaudi::Functional {
25 
26  // This utility is needed when the inputs of a functional algorithm may be stored in several locations
28  return boost::algorithm::join( c, ":" );
29  }
30 
31  template <typename... Strings>
34  }
35 
36  [[deprecated( "please use `updateHandleLocation` instead of `Gaudi::Functional::updateHandleLocation`" )]] inline void
37  updateHandleLocation( IProperty& parent, const std::string& prop, const std::string& newLoc ) {
38  auto sc = parent.setProperty( prop, newLoc );
39  if ( sc.isFailure() ) throw GaudiException( "Could not set Property", prop + " -> " + newLoc, sc );
40  }
41 
42  [[deprecated(
43  "please use `updateHandleLocations` instead of `Gaudi::Functional::updateHandleLocations`" )]] inline void
44  updateHandleLocations( IProperty& parent, const std::string& prop, const std::vector<std::string>& newLocs ) {
47  ss << '[', newLocs, ", ", []( std::ostream & os, const auto& i ) -> auto& { return os << "'" << i << "'"; } )
48  << ']';
49  auto sc = parent.setProperty( prop, ss.str() );
50  if ( sc.isFailure() ) throw GaudiException( "Could not set Property", prop + " -> " + ss.str(), sc );
51  }
52 
53  namespace Traits {
54 
55  // traits classes used to customize Transformer and FilterPredicate
56  // Define the types to to be used as baseclass, and as in- resp. output hanldes.
57  // In case a type is not specified in the traits struct, a default is used.
58  //
59  // The defaults are:
60  //
61  // using BaseClass = GaudiAlgorithm
62  // template <typename T> using InputHandle = DataObjectHandle<T>;
63  // template <typename T> using OutputHandle = DataObjectHandle<T>;
64  //
65 
66  // the best way to 'compose' traits is by inheriting them one-by-one...
67  template <typename... Base>
68  struct use_ : Base... {};
69 
70  // helper classes one can inherit from to specify a specific trait
71  template <typename Base>
72  struct BaseClass_t {
73  using BaseClass = Base;
74  };
75 
76  template <template <typename> class Handle>
77  struct InputHandle_t {
78  template <typename T>
79  using InputHandle = Handle<T>;
80  };
81 
82  template <template <typename> class Handle>
83  struct OutputHandle_t {
84  template <typename T>
85  using OutputHandle = Handle<T>;
86  };
87 
88  template <typename Data, typename View>
89  struct writeViewFor {
90  template <typename T>
91  using OutputHandle = std::enable_if_t<std::is_same_v<T, Data>, DataObjectWriteHandle<View, Data>>;
92  };
93 
94  // add support for objects that should reside in the TES for lifetime management, but should not
95  // be used explicitly and/or directly by downstream code.
96  template <typename Data>
97  struct WriteOpaqueFor {
98  struct OpaqueView {
99  OpaqueView() = default;
100  template <typename T>
101  OpaqueView( T const& ) {}
102  };
103 
104  template <typename T>
105  using OutputHandle = std::enable_if_t<std::is_same_v<T, Data>, DataObjectWriteHandle<OpaqueView, Data>>;
106  };
107 
108  // this uses the defaults -- and it itself is the default ;-)
110 
111  // this example uses GaudiHistoAlg as baseclass, and the default handle types for
112  // input and output
114 
115  // use Gaudi::Algorithm as base class -- this should be the base class!
117 
118  // use the legacy GaudiAlgorithm as base class -- this is (annoyingly) the current default
120 
121  } // namespace Traits
122 } // namespace Gaudi::Functional
123 
124 #endif
Gaudi::Functional::updateHandleLocations
void updateHandleLocations(IProperty &parent, const std::string &prop, const std::vector< std::string > &newLocs)
Definition: FunctionalUtilities.h:44
DataObjectWriteHandle
Definition: DataObjectHandle.h:427
Gaudi::Functional::Traits::OutputHandle_t::OutputHandle
Handle< T > OutputHandle
Definition: FunctionalUtilities.h:85
std::string
STL class.
Gaudi::Functional::Traits::WriteOpaqueFor
Definition: FunctionalUtilities.h:97
gaudirun.s
string s
Definition: gaudirun.py:348
std::vector< std::string >
GaudiException
Definition: GaudiException.h:31
Gaudi::Functional::Traits::WriteOpaqueFor::OpaqueView
Definition: FunctionalUtilities.h:98
gaudirun.c
c
Definition: gaudirun.py:527
GaudiHistoAlg.h
IProperty
Definition: IProperty.h:33
std::ostream
STL class.
Gaudi::Functional::Traits::OutputHandle_t
Definition: FunctionalUtilities.h:83
Gaudi::Functional::Traits::use_
Definition: FunctionalUtilities.h:68
Gaudi::Functional
Definition: Consumer.h:19
Gaudi::Functional::Traits::WriteOpaqueFor::OpaqueView::OpaqueView
OpaqueView(T const &)
Definition: FunctionalUtilities.h:101
BoostArrayProperties.Strings
Strings
Definition: BoostArrayProperties.py:35
std::ostringstream
STL class.
Gaudi::Functional::Traits::InputHandle_t::InputHandle
Handle< T > InputHandle
Definition: FunctionalUtilities.h:79
GaudiAlgorithm.h
Gaudi::Functional::Traits::writeViewFor::OutputHandle
std::enable_if_t< std::is_same_v< T, Data >, DataObjectWriteHandle< View, Data > > OutputHandle
Definition: FunctionalUtilities.h:91
Gaudi::Functional::Traits::BaseClass_t
Definition: FunctionalUtilities.h:72
Gaudi::Functional::Traits::WriteOpaqueFor::OutputHandle
std::enable_if_t< std::is_same_v< T, Data >, DataObjectWriteHandle< OpaqueView, Data > > OutputHandle
Definition: FunctionalUtilities.h:105
Gaudi::Functional::Traits::writeViewFor
Definition: FunctionalUtilities.h:89
Gaudi::Functional::updateHandleLocation
void updateHandleLocation(IProperty &parent, const std::string &prop, const std::string &newLoc)
Definition: FunctionalUtilities.h:37
std::ostringstream::str
T str(T... args)
SerializeSTL.h
Gaudi::Functional::concat_alternatives
std::string concat_alternatives(std::initializer_list< std::string > c)
Definition: FunctionalUtilities.h:27
Gaudi::Functional::Traits::BaseClass_t::BaseClass
Base BaseClass
Definition: FunctionalUtilities.h:73
DataObjectHandle.h
Gaudi::Functional::Traits::InputHandle_t
Definition: FunctionalUtilities.h:77
Gaudi::Functional::Traits::WriteOpaqueFor::OpaqueView::OpaqueView
OpaqueView()=default
GaudiUtils::details::ostream_joiner
Stream & ostream_joiner(Stream &os, Iterator first, Iterator last, Separator sep, OutputElement output=OutputElement{})
Definition: SerializeSTL.h:73
std::initializer_list
IProperty::setProperty
StatusCode setProperty(const Gaudi::Details::PropertyBase &p)
Set the property from a property.
Definition: IProperty.h:39