The Gaudi Framework
v36r1 (3e2fb5a8)
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?
19
#include "
GaudiAlg/GaudiAlgorithm.h
"
20
#include "
GaudiAlg/GaudiHistoAlg.h
"
21
#include "
GaudiKernel/DataObjectHandle.h
"
22
#include "
GaudiKernel/SerializeSTL.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
27
inline
std::string
concat_alternatives
(
std::initializer_list<std::string>
c
) {
28
return
boost::algorithm::join(
c
,
":"
);
29
}
30
31
template
<
typename
...
Strings
>
32
std::string
concat_alternatives
(
const
Strings
&...
s
) {
33
return
concat_alternatives
(
std::initializer_list<std::string>
{
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 ) {
45
std::ostringstream
ss;
46
GaudiUtils::details::ostream_joiner
(
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
// this uses the defaults -- and it itself is the default ;-)
95
using
useDefaults
=
use_<>
;
96
97
// this example uses GaudiHistoAlg as baseclass, and the default handle types for
98
// input and output
99
using
useGaudiHistoAlg
=
use_<BaseClass_t<GaudiHistoAlg>
>;
100
101
// use Gaudi::Algorithm as base class -- this should be the base class!
102
using
useAlgorithm
=
use_<BaseClass_t<Gaudi::Algorithm>
>;
103
104
// use the legacy GaudiAlgorithm as base class -- this is (annoyingly) the current default
105
using
useLegacyGaudiAlgorithm
=
use_<BaseClass_t<GaudiAlgorithm>
>;
106
107
}
// namespace Traits
108
}
// namespace Gaudi::Functional
109
110
#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:420
Gaudi::Functional::Traits::OutputHandle_t::OutputHandle
Handle< T > OutputHandle
Definition:
FunctionalUtilities.h:85
std::string
STL class.
gaudirun.s
string s
Definition:
gaudirun.py:328
std::vector< std::string >
GaudiException
Definition:
GaudiException.h:31
gaudirun.c
c
Definition:
gaudirun.py:509
GaudiHistoAlg.h
IProperty
Definition:
IProperty.h:33
ArrayProperties.Strings
Strings
Definition:
ArrayProperties.py:68
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
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::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
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
GaudiAlg
include
GaudiAlg
FunctionalUtilities.h
Generated on Tue Sep 21 2021 12:27:37 for The Gaudi Framework by
1.8.18