2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
6#include "CxxUtils/checker_macros.h"
12 * @brief forward the initialization to the member VarHandleKeys
13 * @param used If false, then this handle is not to be used.
14 * Instead of normal initialization, the key will be cleared.
18 StatusCode VarHandleKeyArrayCommon<Base>::initialize (bool used /*= true*/) {
19 StatusCode sc(StatusCode::SUCCESS);
21 IDataHandleHolder* const owner = this->owner();
22 for (Base& b : *this) {
23 if (owner != nullptr) {
26 if ( b.initialize().isFailure() ) {
27 sc = StatusCode::FAILURE;
38 // Set the VarHandleKey from a string
42 StatusCode VarHandleKeyArrayCommon<Base>::assign(const std::vector<std::string>& vs) {
43 StatusCode sc(StatusCode::SUCCESS);
46 Base b = this->keyFromString (s);
48 sc = StatusCode::FAILURE;
52 std::vector<Base>::emplace_back(std::move(b));
60 // string representation of VarHandleKeyArray
64 std::string VarHandleKeyArrayCommon<Base>::toString() const {
65 std::ostringstream ost;
66 typename std::vector<Base>::const_iterator itr;
68 size_t sz = this->size();
69 for ( size_t i=0; i < sz; ++i, ++itr) {
70 std::print (ost, "'{}'", itr->objKey());
72 std::print (ost, ",");
79 // create array of all base VarHandleKeys in the Array
83 std::vector<SG::VarHandleKey*> VarHandleKeyArrayCommon<Base>::keys() const {
84 std::vector<SG::VarHandleKey*> keys;
85 for (const SG::VarHandleKey& k : *this) {
86 // FIXME: This is a rule violation, but we can't really fix it without
87 // changing the IDataHandleHolder base class from Gaudi.
88 SG::VarHandleKey* k_nc ATLAS_THREAD_SAFE = const_cast<SG::VarHandleKey*>(&k);
89 keys.push_back (k_nc);
96 void VarHandleKeyArrayCommon<Base>::declare(IDataHandleHolder* owner) {
100 for (auto k: keys() ) {
101 owner->declare ( *k );
102 k->setOwner( owner );
108 * Create a HandleKey from a string.
109 * @param s String from which to create the HandleKey.
111 * This is for decoration handle keys. If this array was initialized
112 * with a container key, then that will be used to for the handle keys.
114 template <class Base>
115 template <class T /*= Base*/>
116 requires T::isDecorHandleKey
118 Base VarHandleKeyArrayCommon<Base>::keyFromString (const std::string& s) const
121 return Base (*m_contKey, s);
127 * Create a HandleKey from a string.
128 * @param s String from which to create the HandleKey.
130 * This is for non-decoration handle keys.
132 template <class Base>
133 template <class T /*= Base*/>
134 requires (!T::isDecorHandleKey)
136 Base VarHandleKeyArrayCommon<Base>::keyFromString (const std::string& s) const
145template <std::derived_from<SG::VarHandleKeyArray> T>
146template <class FmtContext>
148formatter<T>::format(const T& k, FmtContext& ctx) const
150 return std::format_to (ctx.out(), "[{}]", k.toString());