ATLAS Offline Software
Loading...
Searching...
No Matches
AthToolSupport/AsgDataHandles/AsgDataHandles/VarHandleKeyArray.icc
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3*/
4
5
6#include <sstream>
7
8
9namespace SG {
10 /**
11 * @brief forward the initialization to the member VarHandleKeys
12 * @param used If false, then this handle is not to be used.
13 * Instead of normal initialization, the key will be cleared.
14 */
15 template <class Base>
16 inline
17 StatusCode VarHandleKeyArrayCommon<Base>::initialize (bool used /*= true*/) {
18 StatusCode sc(StatusCode::SUCCESS);
19 if (used) {
20 // IDataHandleHolder* const owner = this->owner();
21 for (Base& b : *this) {
22 // if (owner != nullptr) {
23 // b.setOwner(owner);
24 // }
25 if ( b.initialize().isFailure() ) {
26 sc = StatusCode::FAILURE;
27 }
28 }
29 }
30 else {
31 this->clear();
32 }
33 return sc;
34 }
35
36 // //
37 // // Set the VarHandleKey from a string
38 // //
39 // template <class Base>
40 // inline
41 // StatusCode VarHandleKeyArrayCommon<Base>::assign(const std::vector<std::string>& vs) {
42 // StatusCode sc(StatusCode::SUCCESS);
43 // this->clear();
44 // for (auto & s : vs) {
45 // Base b;
46 // if (!b.assign(s)) {
47 // sc = StatusCode::FAILURE;
48 // } else {
49 // // Skip blank keys
50 // if (b.key() != "") {
51 // this->push_back(b);
52 // }
53 // }
54 // }
55 // return sc;
56 // }
57
58 //
59 // string representation of VarHandleKeyArray
60 //
61 template <class Base>
62 inline
63 std::string VarHandleKeyArrayCommon<Base>::toString() const {
64 std::ostringstream ost;
65 typename std::vector<Base>::const_iterator itr;
66 itr = this->begin();
67 size_t sz = this->size();
68 for ( size_t i=0; i < sz; ++i, ++itr) {
69 // ost << "'" << itr->objKey() << "'";
70 ost << "'" << itr->key() << "'";
71 if (i != sz-1) {
72 ost << ",";
73 }
74 }
75 return ost.str();
76 }
77
78 // //
79 // // create array of all base VarHandleKeys in the Array
80 // //
81 // template <class Base>
82 // inline
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);
90 // }
91 // return keys;
92 // }
93
94 // template <class Base>
95 // inline
96 // void VarHandleKeyArrayCommon<Base>::declare(IDataHandleHolder* owner) {
97 // if ( renounced() ) {
98 // return;
99 // }
100 // for (auto k: keys() ) {
101 // owner->declare ( *k );
102 // k->setOwner( owner );
103 // }
104 // }
105}