The Gaudi Framework  v37r1 (a7f61348)
utilities.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2023 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 #pragma once
12 
15 #include <boost/algorithm/string/join.hpp>
16 #include <initializer_list>
17 #include <string>
18 
19 namespace Gaudi::Functional {
20 
21  // This utility is needed when the inputs of a functional algorithm may be stored in several locations
23  return boost::algorithm::join( c, ":" );
24  }
25 
26  template <typename... Strings>
29  }
30 
31  [[deprecated( "please use `updateHandleLocation` instead of `Gaudi::Functional::updateHandleLocation`" )]] inline void
32  updateHandleLocation( IProperty& parent, const std::string& prop, const std::string& newLoc ) {
33  auto sc = parent.setProperty( prop, newLoc );
34  if ( sc.isFailure() ) throw GaudiException( "Could not set Property", prop + " -> " + newLoc, sc );
35  }
36 
37  [[deprecated(
38  "please use `updateHandleLocations` instead of `Gaudi::Functional::updateHandleLocations`" )]] inline void
39  updateHandleLocations( IProperty& parent, const std::string& prop, const std::vector<std::string>& newLocs ) {
41  GaudiUtils::details::ostream_joiner( ss << '[', newLocs, ", ", []( std::ostream& os, const auto& i ) -> auto& {
42  return os << "'" << i << "'";
43  } ) << ']';
44  auto sc = parent.setProperty( prop, ss.str() );
45  if ( sc.isFailure() ) throw GaudiException( "Could not set Property", prop + " -> " + ss.str(), sc );
46  }
47 
48  namespace Traits {
49 
50  // traits classes used to customize Transformer and FilterPredicate
51  // Define the types to to be used as baseclass, and as in- resp. output hanldes.
52  // In case a type is not specified in the traits struct, a default is used.
53  //
54  // The defaults are:
55  //
56  // using BaseClass = GaudiAlgorithm
57  // template <typename T> using InputHandle = DataObjectHandle<T>;
58  // template <typename T> using OutputHandle = DataObjectHandle<T>;
59  //
60 
61  // the best way to 'compose' traits is by inheriting them one-by-one...
62  template <typename... Base>
63  struct use_ : Base... {};
64 
65  // helper classes one can inherit from to specify a specific trait
66  template <typename Base>
67  struct BaseClass_t {
68  using BaseClass = Base;
69  };
70 
71  template <template <typename> class Handle>
72  struct InputHandle_t {
73  template <typename T>
74  using InputHandle = Handle<T>;
75  };
76 
77  template <template <typename> class Handle>
78  struct OutputHandle_t {
79  template <typename T>
80  using OutputHandle = Handle<T>;
81  };
82 
83  template <typename Data, typename View>
84  struct writeViewFor {
85  template <typename T>
86  using OutputHandle = std::enable_if_t<std::is_same_v<T, Data>, DataObjectWriteHandle<View, Data>>;
87  };
88 
89  // add support for objects that should reside in the TES for lifetime management, but should not
90  // be used explicitly and/or directly by downstream code.
91  template <typename Data>
92  struct WriteOpaqueFor {
93  struct OpaqueView {
94  OpaqueView() = default;
95  template <typename T>
96  OpaqueView( T const& ) {}
97  };
98 
99  template <typename T>
100  using OutputHandle = std::enable_if_t<std::is_same_v<T, Data>, DataObjectWriteHandle<OpaqueView, Data>>;
101  };
102 
103  // this uses the defaults -- and it itself is the default ;-)
105  } // namespace Traits
106 } // namespace Gaudi::Functional
Gaudi::Functional::updateHandleLocations
void updateHandleLocations(IProperty &parent, const std::string &prop, const std::vector< std::string > &newLocs)
Definition: utilities.h:39
DataObjectWriteHandle
Definition: DataObjectHandle.h:427
Gaudi::Functional::Traits::OutputHandle_t::OutputHandle
Handle< T > OutputHandle
Definition: utilities.h:80
std::string
STL class.
Gaudi::Functional::Traits::WriteOpaqueFor
Definition: utilities.h:92
gaudirun.s
string s
Definition: gaudirun.py:348
std::vector< std::string >
GaudiException
Definition: GaudiException.h:31
Gaudi::Functional::Traits::WriteOpaqueFor::OpaqueView
Definition: utilities.h:93
gaudirun.c
c
Definition: gaudirun.py:527
IProperty
Definition: IProperty.h:33
std::ostream
STL class.
Gaudi::Functional::Traits::OutputHandle_t
Definition: utilities.h:78
Gaudi::Functional::Traits::use_
Definition: utilities.h:63
Gaudi::Functional
Definition: FunctionalUtilities.h:18
Gaudi::Functional::Traits::WriteOpaqueFor::OpaqueView::OpaqueView
OpaqueView(T const &)
Definition: utilities.h:96
BoostArrayProperties.Strings
Strings
Definition: BoostArrayProperties.py:35
std::ostringstream
STL class.
Gaudi::Functional::Traits::InputHandle_t::InputHandle
Handle< T > InputHandle
Definition: utilities.h:74
Gaudi::Functional::Traits::writeViewFor::OutputHandle
std::enable_if_t< std::is_same_v< T, Data >, DataObjectWriteHandle< View, Data > > OutputHandle
Definition: utilities.h:86
Gaudi::Functional::Traits::BaseClass_t
Definition: utilities.h:67
Gaudi::Functional::Traits::WriteOpaqueFor::OutputHandle
std::enable_if_t< std::is_same_v< T, Data >, DataObjectWriteHandle< OpaqueView, Data > > OutputHandle
Definition: utilities.h:100
Gaudi::Functional::Traits::writeViewFor
Definition: utilities.h:84
Gaudi::Functional::updateHandleLocation
void updateHandleLocation(IProperty &parent, const std::string &prop, const std::string &newLoc)
Definition: utilities.h:32
std::ostringstream::str
T str(T... args)
SerializeSTL.h
Gaudi::Functional::concat_alternatives
std::string concat_alternatives(std::initializer_list< std::string > c)
Definition: utilities.h:22
Gaudi::Functional::Traits::BaseClass_t::BaseClass
Base BaseClass
Definition: utilities.h:68
DataObjectHandle.h
Gaudi::Functional::Traits::InputHandle_t
Definition: utilities.h:72
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