ATLAS Offline Software
Loading...
Searching...
No Matches
View.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "AthViews/View.h"
7
8#include <stdexcept>
9
10
18SG::View::View( std::string const& name, int index, bool allowFallThrough, std::string const& storeName ) :
19 m_store( storeName, name ),
20 m_keyMap(KeyMap_t::Updater_t()),
21 m_name( name ),
22 m_allowFallThrough( allowFallThrough )
23{
24 if ( index >= 0 ) {
25 m_index = index;
26 m_name += '_';
27 m_name += std::to_string( index );
28 }
29}
30
31
35void SG::View::linkParent( const IProxyDict* parent ) {
36 auto castParent = dynamic_cast< const SG::View* >( parent );
37 if ( castParent ) {
38 m_parents.insert( castParent );
39 }
40 else {
41 throw std::runtime_error( "Unable to link parent view that cannot be cast to SG::View" );
42 }
43}
44
45
58 const std::string& key,
59 bool allowMods,
60 bool returnExisting)
61{
62 // Record the object under the view name
63 SG::DataProxy* proxy = m_store->recordObject( obj, viewKey(key), allowMods, returnExisting );
64
65 // Remember the hashed rawKey -> viewKey mapping for use in proxy_exact
66 if (proxy) {
67 const IStringPool::sgkey_t keyNoView = m_store->stringToKey( key, obj->clID() );
68 m_keyMap.emplace(keyNoView, proxy->sgkey());
69 }
70
71 return proxy;
72}
73
74
91 auto itr = m_keyMap.find(sgkey);
92 if (itr != m_keyMap.end()) {
93 return m_store->proxy_exact( itr->second );
94 }
95 else return nullptr;
96}
97
98
112SG::DataProxy * SG::View::proxy( const CLID& id, const std::string& key ) const
113{
114 return findProxy( id, key, m_allowFallThrough );
115}
116
117
121SG::DataProxy * SG::View::findProxy( const CLID& id, const std::string& key, bool allowFallThrough ) const
122{
123 auto isValid = [](const SG::DataProxy* p) { return p != nullptr and p->isValid(); };
124 auto localProxy = m_store->proxy( id, viewKey(key) );
125 if ( isValid( localProxy ) ) {
126 return localProxy;
127 }
128
129 for ( auto parent: m_parents ) {
130 // Don't allow parents to access whole-event store independently of this view
131 auto inParentProxy = parent->findProxy( id, key, false );
132 if ( isValid( inParentProxy ) ) {
133 return inParentProxy;
134 }
135 }
136
137 //Look in the default store if could not find in any view - for instance for event-wise IDCs
138 if ( (not isValid( localProxy )) and allowFallThrough ) {
139
140 //Apply filtering
141 if ( !m_fallFilter.empty() ) {
142 bool filterPass = false;
143
144 //Filter passes if the key contains one of the possible values
145 for ( auto& entry : m_fallFilter ) {
146 if ( key.find( entry ) != std::string::npos ) {
147 filterPass = true;
148 break;
149 }
150 }
151
152 if ( !filterPass ) return nullptr;
153 }
154
155 return m_store->proxy( id, key );
156 }
157 return nullptr;
158}
159
160
164std::string SG::View::dump( const std::string& indent ) const
165{
166 // Dump view contents
167 std::string ret = indent + "Dump " + name() + "\n";
168 ret += indent + "[";
169 for ( const SG::DataProxy* dp: proxies() ) {
170 if ( dp->name().find( name() ) == 0 )
171 ret += " " + dp->name();
172 }
173 ret += " ]\n";
174
175 // Dump parent views
176 if ( m_parents.size() ) ret += indent + "Parents:\n";
177 for ( auto p : m_parents ) {
178 ret += p->dump( indent + " " );
179 }
180
181 // Fallthrough
182 if ( indent == "" ) {
183 if ( m_allowFallThrough ) {
184 ret += indent + "May access main store: " + m_store->name();
185 } else {
186 ret += indent + "May not access main store";
187 }
188 }
189 return ret;
190}
191
192
193bool SG::View::tryELRemap( sgkey_t, size_t, sgkey_t&, size_t& )
194{
195 throw std::runtime_error( "Not implemented: SG::View::tryELRemap" );
196}
197
199{
200 throw std::runtime_error( "Not implemented: SG::View::keyToString" );
201}
202
204{
205 throw std::runtime_error( "Not implemented: SG::View::keyToString" );
206}
207
bool isValid(const T &p)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
Definition AtlasPID.h:878
uint32_t CLID
The Class ID type.
SG::sgkey_t sgkey_t
Type of the keys.
Definition IStringPool.h:34
A "view" of the event store (IProxyDict).
Definition View.h:46
size_t m_index
Definition View.h:281
std::string m_name
Definition View.h:280
virtual bool tryELRemap(sgkey_t sgkey_in, size_t index_in, sgkey_t &sgkey_out, size_t &index_out) override
Test to see if the target of an ElementLink has moved.
Definition View.cxx:193
virtual const std::string * keyToString(IStringPool::sgkey_t key) const override
Find the string and CLID corresponding to a given key.
Definition View.cxx:203
virtual SG::DataProxy * proxy(const CLID &id, const std::string &key) const override
Get proxy with given id and key.
Definition View.cxx:112
KeyMap_t m_keyMap
Definition View.h:275
SG::DataProxy * findProxy(const CLID &id, const std::string &key, bool allowFallThrough) const
Internal implementation of proxy()
Definition View.cxx:121
std::string dump(const std::string &indent="") const
Print content of the view.
Definition View.cxx:164
void linkParent(const IProxyDict *parent)
Link to the previously used views.
Definition View.cxx:35
virtual const std::string & name() const override
Name of the view.
Definition View.h:117
ServiceHandle< StoreGateSvc > m_store
Definition View.h:271
std::vector< std::string > m_fallFilter
Definition View.h:278
View()=delete
virtual SG::DataProxy * recordObject(SG::DataObjectSharedPtr< DataObject > obj, const std::string &key, bool allowMods, bool returnExisting) override
Record an object in the store.
Definition View.cxx:57
std::set< const SG::View * > m_parents
Definition View.h:277
virtual std::vector< const SG::DataProxy * > proxies() const override
Return the list of all current proxies in store.
Definition View.h:158
std::string viewKey(const std::string &key) const
Construct a key as used in the parent store.
Definition View.h:267
bool m_allowFallThrough
Definition View.h:282
virtual SG::DataProxy * proxy_exact(SG::sgkey_t sgkey) const override
Get proxy given a hashed key+clid.
Definition View.cxx:90
SG::ConcurrentSGKeyMap< sgkey_t > KeyMap_t
Definition View.h:274
CxxUtils::RefCountedPtr< T > DataObjectSharedPtr
uint32_t sgkey_t
Type used for hashed StoreGate key+CLID pairs.
Definition sgkey_t.h:32
Definition index.py:1