ATLAS Offline Software
Loading...
Searching...
No Matches
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
11#include "Gaudi/Algorithm.h"
13
14
15template <typename T>
17{
18 typename T::const_value_type from;
19 typename T::const_value_type to;
20};
21
22template <typename T, typename C>
24{
25public:
26 std::map<std::string,std::string> toCopy;
27private:
33 std::vector<SG::AuxElement::ConstAccessor<T>> m_fromAcc;
34public:
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
#define ATH_CHECK
Evaluate an expression and check for errors.
VariableMule(const T &default_value)
StatusCode initialize(OWNER *parent, const std::vector< std::string > &froms, const std::string &to)
std::map< std::string, std::string > toCopy
std::vector< SG::AuxElement::ConstAccessor< T > > m_fromAcc
SG::ReadDecorHandleKeyArray< C > RC
SG::WriteDecorHandleKeyArray< C > WC
void copy(const std::vector< MatchedPair< C > > &pairs, const EventContext &cxt) const
STL class.
DecorHandleKeyArray< ReadDecorHandle< T, S >, ReadDecorHandleKey< T >, Gaudi::DataHandle::Reader > ReadDecorHandleKeyArray
DecorHandleKeyArray< WriteDecorHandle< T, S >, WriteDecorHandleKey< T >, Gaudi::DataHandle::Writer > WriteDecorHandleKeyArray
T::const_value_type from
T::const_value_type to