The Gaudi Framework  v33r0 (d5ea422b)
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>
32  std::string concat_alternatives( const Strings&... s ) {
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  // this uses the defaults -- and it itself is the default ;-)
90 
91  // this example uses GaudiHistoAlg as baseclass, and the default handle types for
92  // input and output
94 
95  // use Gaudi::Algorithm as base class -- this should be the base class!
97 
98  // use the legacy GaudiAlgorithm as base class -- this is (annoyingly) the current default
100 
101  } // namespace Traits
102 } // namespace Gaudi::Functional
103 
104 #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,...
STL class.
virtual StatusCode setProperty(const Gaudi::Details::PropertyBase &p)=0
Set the property by property.
T str(T... args)
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:47
string s
Definition: gaudirun.py:328
The IProperty is the basic interface for all components which have properties that can be set or get.
Definition: IProperty.h:30
STL class.