ATLAS Offline Software
SGIterator.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
3 */
4 /*
5  */
12 #include "StoreGate/SGIterator.h"
13 
14 
19 {
20 }
21 
22 
33  bool isConst)
34 {
35  // Save all valid proxies in reverse order. Also take out a refcount on each.
36  while (itr != itrEnd) {
37  --itrEnd;
38  DataProxy* dp = itrEnd->second;
39  if (dp->isValid() && (isConst || !dp->isConst())) {
40  m_proxies.push_back (dp);
41  dp->addRef();
42  }
43  }
44 }
45 
46 
51  : m_proxies (other.m_proxies)
52 {
53  // Maintain shared ownership of elements in our range.
54  this->addRef();
55 }
56 
57 
62 {
63  // Release ownership of everything in our range.
64  this->release();
65 }
66 
67 
73 {
74  if (this != &other) {
75  // Assign, maintaining refcounts.
76  this->release();
77  m_proxies = other.m_proxies;
78  this->addRef();
79  }
80  return *this;
81 }
82 
83 
96  bool isConst)
97 {
98  this->release();
99  m_proxies.clear();
100 
101  while (itr != itrEnd) {
102  --itrEnd;
103  DataProxy* dp = itrEnd->second;
104  if (dp->isValid() && (isConst || !dp->isConst())) {
105  m_proxies.push_back (dp);
106  dp->addRef();
107  }
108  }
109 
110  if (m_proxies.empty()) {
111  return StatusCode::FAILURE;
112  }
113 
114  return StatusCode::SUCCESS;
115 }
116 
117 
124 {
125  if (!m_proxies.empty()) {
126  m_proxies.back()->release();
127  m_proxies.pop_back();
128  }
129 }
130 
131 
138 {
139  // This should usually not be needed, since we check for constness
140  // when initializing the iterator. However, it is possible for a proxy
141  // to be marked as const after the iterator has been formed, so keep the check.
142  const SG::DataProxy* dp = this->proxy();
143  if (dp->isConst()) {
144  const IProxyDict* store = dp->store();
145  throw SG::ExcConstObject (dp->clID(),
146  dp->name(),
147  store ? store->name() : "(unknown)");
148  }
149 }
150 
151 
155 const std::string& SG::detail::IteratorBase::key() const
156 {
157  return m_proxies.back()->name();
158 }
store
StoreGateSvc * store
Definition: fbtTestBasics.cxx:71
TileDCSDataPlotter.dp
dp
Definition: TileDCSDataPlotter.py:840
StateLessPT_NewConfig.proxy
proxy
Definition: StateLessPT_NewConfig.py:392
SG::DataProxy::isConst
bool isConst() const
Check if it is a const object.
SG::detail::IteratorBase::key
const std::string & key() const
Get the key string with which the current object was stored.
Definition: SGIterator.cxx:155
SGIterator.h
A standard conforming forward iterator over items in StoreGate.
IProxyDict
A proxy dictionary.
Definition: AthenaKernel/AthenaKernel/IProxyDict.h:47
SG::detail::IteratorBase::setState
StatusCode setState(SG::ConstProxyIterator itr, SG::ConstProxyIterator itrEnd, bool isConst)
Reset state of the iterator.
Definition: SGIterator.cxx:94
SG::detail::IteratorBase::operator=
IteratorBase & operator=(const IteratorBase &other)
Assignment.
Definition: SGIterator.cxx:72
SG::detail::IteratorBase::increment
void increment()
Move to the next valid proxy.
Definition: SGIterator.cxx:123
SG::detail::IteratorBase::~IteratorBase
~IteratorBase()
Destructor.
Definition: SGIterator.cxx:61
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::detail::IteratorBase::IteratorBase
IteratorBase()
Default constructor.
Definition: SGIterator.cxx:18
SG::ExcConstObject
Exception — Tried to retrieve non-const pointer to const object.
Definition: Control/StoreGate/StoreGate/exceptions.h:134
python.EventInfoMgtInit.release
release
Definition: EventInfoMgtInit.py:24
SG::detail::IteratorBase::const_check
void const_check() const
Const check: throw an exception if we're pointing at a const proxy.
Definition: SGIterator.cxx:137
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
SG::detail::IteratorBase
Definition: SGIterator.h:36
SG::DataProxy
Definition: DataProxy.h:44
SG::ConstProxyIterator
ProxyMap::const_iterator ConstProxyIterator
Definition: ProxyMap.h:28
SG::detail::IteratorBase::addRef
void addRef()
Add a reference count to all proxies in our range.