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 StatusCode initialize(Gaudi::Algorithm* parent,
37 const std::vector<std::string>& froms,
38 const std::string& to) {
39 for (const auto& key: toCopy) {
40 std::string fullto = to + "." + key.second;
41 std::string doc = "Key to move " + key.first + "->" + key.second;
42 for (const auto& from: froms) {
43 std::string fullfrom = from + "." + key.first;
44 m_fromKeys.emplace_back(parent, "read_" + key.first, fullfrom, doc);
45 }
46 m_fromAcc.emplace_back(key.first);
47 m_toKeys.emplace_back(parent, "write_" + key.second, fullto, doc);
48 }
49 ATH_CHECK(m_fromKeys.initialize());
50 ATH_CHECK(m_toKeys.initialize());
51 return StatusCode::SUCCESS;
52 }
53 void copy(const std::vector<MatchedPair<C>>& pairs, const EventContext& cxt)
54 const {
55 std::vector<SG::ReadDecorHandle<C,T>> from;
56 std::vector<SG::WriteDecorHandle<C,T>> to;
57 for (const auto& k: m_fromKeys) {
58 from.emplace_back(k, cxt);
59 }
60 for (const auto& k: m_toKeys) {
61 to.emplace_back(k, cxt);
62 }
63 size_t n_keys = m_fromAcc.size();
64 for (const auto& pair: pairs) {
65 for (size_t iii = 0; iii < n_keys; iii++) {
66 if (pair.from) {
67 to.at(iii)(*pair.to) = m_fromAcc.at(iii)(*pair.from);
68 } else {
69 to.at(iii)(*pair.to) = m_default;
70 }
71 }
72 }
73 }
74};
75
76
77#endif
#define ATH_CHECK
Evaluate an expression and check for errors.
StatusCode initialize(Gaudi::Algorithm *parent, const std::vector< std::string > &froms, const std::string &to)
VariableMule(const T &default_value)
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