ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
JetTagging
JetTagDerivationUtils
JetTagDerivationUtils
VariableMule.h
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
6
#ifndef VARIABLE_MULE_H
7
#define VARIABLE_MULE_H
8
9
#include "
StoreGate/WriteDecorHandleKeyArray.h
"
10
#include "
StoreGate/ReadDecorHandleKeyArray.h
"
11
#include "Gaudi/Algorithm.h"
12
#include "
AthenaBaseComps/AthCheckMacros.h
"
13
14
15
template
<
typename
T>
16
struct
MatchedPair
17
{
18
typename
T::const_value_type
from
;
19
typename
T::const_value_type
to
;
20
};
21
22
template
<
typename
T,
typename
C>
23
class
VariableMule
24
{
25
public
:
26
std::map<std::string,std::string>
toCopy
;
27
private
:
28
using
RC
=
SG::ReadDecorHandleKeyArray<C>
;
29
using
WC
=
SG::WriteDecorHandleKeyArray<C>
;
30
RC
m_fromKeys
;
31
WC
m_toKeys
;
32
T
m_default
;
33
std::vector<SG::AuxElement::ConstAccessor<T>>
m_fromAcc
;
34
public
:
35
VariableMule
(
const
T& default_value):
m_default
(default_value) {}
36
// the owner is templated so that the keys are declared through the
37
// AthCommonDataStore overload: a Gaudi::Algorithm declares them as plain
38
// properties, and the scheduler never sees them as data dependencies
39
template
<
typename
OWNER>
40
StatusCode
initialize
(OWNER* parent,
41
const
std::vector<std::string>& froms,
42
const
std::string& to) {
43
// the owner keeps pointers to the keys, so the storage must not move
44
m_fromKeys
.reserve(
toCopy
.size() * froms.size());
45
m_toKeys
.reserve(
toCopy
.size());
46
m_fromAcc
.reserve(
toCopy
.size());
47
for
(
const
auto
& key:
toCopy
) {
48
std::string fullto = to +
"."
+ key.second;
49
std::string doc =
"Key to move "
+ key.first +
"->"
+ key.second;
50
for
(
const
auto
& from: froms) {
51
std::string fullfrom = from +
"."
+ key.first;
52
m_fromKeys
.emplace_back(parent,
"read_"
+ key.first, fullfrom, doc);
53
}
54
m_fromAcc
.emplace_back(key.first);
55
m_toKeys
.emplace_back(parent,
"write_"
+ key.second, fullto, doc);
56
}
57
ATH_CHECK
(
m_fromKeys
.initialize());
58
ATH_CHECK
(
m_toKeys
.initialize());
59
return
StatusCode::SUCCESS;
60
}
61
void
copy
(
const
std::vector<
MatchedPair<C>
>& pairs,
const
EventContext& cxt)
62
const
{
63
std::vector<SG::ReadDecorHandle<C,T>> from;
64
std::vector<SG::WriteDecorHandle<C,T>> to;
65
for
(
const
auto
& k:
m_fromKeys
) {
66
from.emplace_back(k, cxt);
67
}
68
for
(
const
auto
& k:
m_toKeys
) {
69
to.emplace_back(k, cxt);
70
}
71
size_t
n_keys =
m_fromAcc
.size();
72
for
(
const
auto
&
pair
: pairs) {
73
for
(
size_t
iii = 0; iii < n_keys; iii++) {
74
if
(
pair
.from) {
75
to.at(iii)(*
pair
.to) =
m_fromAcc
.at(iii)(*
pair
.from);
76
}
else
{
77
to.at(iii)(*
pair
.to) =
m_default
;
78
}
79
}
80
}
81
}
82
};
83
84
85
#endif
AthCheckMacros.h
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ReadDecorHandleKeyArray.h
WriteDecorHandleKeyArray.h
VariableMule::VariableMule
VariableMule(const T &default_value)
Definition
VariableMule.h:35
VariableMule::m_default
T m_default
Definition
VariableMule.h:32
VariableMule::m_toKeys
WC m_toKeys
Definition
VariableMule.h:31
VariableMule::initialize
StatusCode initialize(OWNER *parent, const std::vector< std::string > &froms, const std::string &to)
Definition
VariableMule.h:40
VariableMule::m_fromKeys
RC m_fromKeys
Definition
VariableMule.h:30
VariableMule::toCopy
std::map< std::string, std::string > toCopy
Definition
VariableMule.h:26
VariableMule::m_fromAcc
std::vector< SG::AuxElement::ConstAccessor< T > > m_fromAcc
Definition
VariableMule.h:33
VariableMule::RC
SG::ReadDecorHandleKeyArray< C > RC
Definition
VariableMule.h:28
VariableMule::WC
SG::WriteDecorHandleKeyArray< C > WC
Definition
VariableMule.h:29
VariableMule::copy
void copy(const std::vector< MatchedPair< C > > &pairs, const EventContext &cxt) const
Definition
VariableMule.h:61
pair
STL class.
SG::ReadDecorHandleKeyArray
DecorHandleKeyArray< ReadDecorHandle< T, S >, ReadDecorHandleKey< T >, Gaudi::DataHandle::Reader > ReadDecorHandleKeyArray
Definition
StoreGate/StoreGate/ReadDecorHandleKeyArray.h:35
SG::WriteDecorHandleKeyArray
DecorHandleKeyArray< WriteDecorHandle< T, S >, WriteDecorHandleKey< T >, Gaudi::DataHandle::Writer > WriteDecorHandleKeyArray
Definition
StoreGate/StoreGate/WriteDecorHandleKeyArray.h:35
MatchedPair
Definition
VariableMule.h:17
MatchedPair::from
T::const_value_type from
Definition
VariableMule.h:18
MatchedPair::to
T::const_value_type to
Definition
VariableMule.h:19
Generated on
for ATLAS Offline Software by
1.17.0