ATLAS Offline Software
Loading...
Searching...
No Matches
SG::View Class Referencefinal

A "view" of the event store (IProxyDict). More...

#include <View.h>

Inheritance diagram for SG::View:
Collaboration diagram for SG::View:

Public Member Functions

 View (const std::string &name, int index, bool allowFallThrough=true, const std::string &storeName="StoreGateSvc")
 Create a new View instance.
 View ()=delete
virtual ~View ()=default
 View (const View &)=delete
Viewoperator= (const View &)=delete
size_t viewID () const
 Return view index.
void linkParent (const IProxyDict *parent)
 Link to the previously used views.
const std::set< const SG::View * > & getParentLinks () const
 Returns the links to the previously used views.
void setFilter (std::vector< std::string > const &inputFilter)
 Set a filtering rule for anything loaded via fall-through.
void setROI (const ElementLink< TrigRoiDescriptorCollection > &roi)
 Associated RoI with this view.
const ElementLink< TrigRoiDescriptorCollection > & getROI () const
 Return associated RoI.
std::string dump (const std::string &indent="") const
 Print content of the view.
IProxyDict interface
virtual const std::string & name () const override
 Name of the view.
virtual SG::DataProxyproxy_exact (SG::sgkey_t sgkey) const override
 Get proxy given a hashed key+clid.
virtual SG::DataProxyproxy (const CLID &id, const std::string &key) const override
 Get proxy with given id and key.
virtual SG::DataProxyproxy (const void *const pTransient) const override
 Get a proxy referencing a given transient object.
virtual std::vector< const SG::DataProxy * > proxies () const override
 Return the list of all current proxies in store.
virtual StatusCode addToStore (CLID id, SG::DataProxy *proxy) override
 Add a new proxy to the store.
virtual SG::DataProxyrecordObject (SG::DataObjectSharedPtr< DataObject > obj, const std::string &key, bool allowMods, bool returnExisting) override
 Record an object in the store.
virtual void boundHandle (IResetable *handle) override
 Tell the store that a handle has been bound to a proxy.
virtual void unboundHandle (IResetable *handle) override
 Tell the store that a handle has been unbound from a proxy.
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.
IStringPool interface
virtual const std::string * keyToString (IStringPool::sgkey_t key) const override
 Find the string and CLID corresponding to a given key.
virtual const std::string * keyToString (IStringPool::sgkey_t key, CLID &clid) const override
 Find the string corresponding to a given key.
virtual IStringPool::sgkey_t stringToKey (const std::string &str, CLID clid) override
 Find the key for a string/CLID pair.
virtual void registerKey (IStringPool::sgkey_t key, const std::string &str, CLID clid) override
 Remember an additional mapping from key to string/CLID.

Private Types

using KeyMap_t = SG::ConcurrentSGKeyMap<sgkey_t>

Private Member Functions

SG::DataProxyfindProxy (const CLID &id, const std::string &key, bool allowFallThrough) const
 Internal implementation of proxy()
std::string viewKey (const std::string &key) const
 Construct a key as used in the parent store.

Private Attributes

ServiceHandle< StoreGateSvcm_store
ElementLink< TrigRoiDescriptorCollectionm_roi
KeyMap_t m_keyMap
std::set< const SG::View * > m_parents
std::vector< std::string > m_fallFilter
std::string m_name
size_t m_index {0}
bool m_allowFallThrough {true}

Detailed Description

A "view" of the event store (IProxyDict).

This class provides a view of the event store by mangling (prefixing) the key name with a fixed string (see viewKey()). Usually the view is carried by the (extended) EventContext and automatically applied for algorithms running within a view. For creating/accessing objects from outside the view, the view needs to be explicitly set via VarHandleBase::setProxyDict() on the handle (see AthViews/ViewHelper.h).

The lookup of an object proceeds in the following order:

  1. the current view
  2. the parent view if linked
  3. the full store if allowFallThrough is set

Definition at line 46 of file View.h.

Member Typedef Documentation

◆ KeyMap_t

Definition at line 274 of file View.h.

Constructor & Destructor Documentation

◆ View() [1/3]

SG::View::View ( const std::string & name,
int index,
bool allowFallThrough = true,
const std::string & storeName = "StoreGateSvc" )

Create a new View instance.

Parameters
nameName of the view
indexIndex of the view (gets appended to the name if index >= 0)
allowFallThroughAllow fall-back to default store if object not found within the view
storeNameStore name

Definition at line 18 of file View.cxx.

18 :
19 m_store( storeName, name ),
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}
size_t m_index
Definition View.h:281
std::string m_name
Definition View.h:280
KeyMap_t m_keyMap
Definition View.h:275
virtual const std::string & name() const override
Name of the view.
Definition View.h:117
ServiceHandle< StoreGateSvc > m_store
Definition View.h:271
bool m_allowFallThrough
Definition View.h:282
str index
Definition DeMoScan.py:362

◆ View() [2/3]

SG::View::View ( )
delete

◆ ~View()

virtual SG::View::~View ( )
virtualdefault

◆ View() [3/3]

SG::View::View ( const View & )
delete

Member Function Documentation

◆ addToStore()

virtual StatusCode SG::View::addToStore ( CLID id,
SG::DataProxy * proxy )
inlineoverridevirtual

Add a new proxy to the store.

Parameters
idCLID as which the proxy should be added.
proxyThe proxy to add.

Simple addition of a proxy to the store. The key is taken as the primary key of the proxy. Does not handle things like overwrite, history, symlinks, etc. Should return failure if there is already an entry for this clid/key.

Definition at line 172 of file View.h.

172 {
173 return m_store->addToStore( id, proxy );
174 }
virtual SG::DataProxy * proxy(const CLID &id, const std::string &key) const override
Get proxy with given id and key.
Definition View.cxx:112

◆ boundHandle()

virtual void SG::View::boundHandle ( IResetable * handle)
inlineoverridevirtual

Tell the store that a handle has been bound to a proxy.

Parameters
handleThe handle that was bound.

Definition at line 196 of file View.h.

196 {
197 return m_store->boundHandle( handle );
198 }

◆ dump()

std::string SG::View::dump ( const std::string & indent = "") const

Print content of the view.

Definition at line 164 of file View.cxx.

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}
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

◆ findProxy()

SG::DataProxy * SG::View::findProxy ( const CLID & id,
const std::string & key,
bool allowFallThrough ) const
private

Internal implementation of proxy()

Definition at line 121 of file View.cxx.

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}
bool isValid(const T &p)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
Definition AtlasPID.h:878
std::vector< std::string > m_fallFilter
Definition View.h:278
std::string viewKey(const std::string &key) const
Construct a key as used in the parent store.
Definition View.h:267

◆ getParentLinks()

const std::set< const SG::View * > & SG::View::getParentLinks ( ) const
inline

Returns the links to the previously used views.

Definition at line 78 of file View.h.

78 {
79 return m_parents;
80 }

◆ getROI()

const ElementLink< TrigRoiDescriptorCollection > & SG::View::getROI ( ) const
inline

Return associated RoI.

Definition at line 100 of file View.h.

100 {
101 return m_roi;
102 }
ElementLink< TrigRoiDescriptorCollection > m_roi
Definition View.h:272

◆ keyToString() [1/2]

const std::string * SG::View::keyToString ( IStringPool::sgkey_t key) const
overridevirtual

Find the string and CLID corresponding to a given key.

Not supported. Will throw std::runtime_error.

Definition at line 203 of file View.cxx.

204{
205 throw std::runtime_error( "Not implemented: SG::View::keyToString" );
206}

◆ keyToString() [2/2]

const std::string * SG::View::keyToString ( IStringPool::sgkey_t key,
CLID & clid ) const
overridevirtual

Find the string corresponding to a given key.

Not supported. Will throw std::runtime_error.

Definition at line 198 of file View.cxx.

199{
200 throw std::runtime_error( "Not implemented: SG::View::keyToString" );
201}

◆ linkParent()

void SG::View::linkParent ( const IProxyDict * parent)

Link to the previously used views.

Definition at line 35 of file View.cxx.

35 {
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}

◆ name()

virtual const std::string & SG::View::name ( ) const
inlineoverridevirtual

Name of the view.

Definition at line 117 of file View.h.

117 {
118 return m_name;
119 }

◆ operator=()

View & SG::View::operator= ( const View & )
delete

◆ proxies()

virtual std::vector< const SG::DataProxy * > SG::View::proxies ( ) const
inlineoverridevirtual

Return the list of all current proxies in store.

Definition at line 158 of file View.h.

158 {
159 return m_store->proxies();
160 }

◆ proxy() [1/2]

SG::DataProxy * SG::View::proxy ( const CLID & id,
const std::string & key ) const
overridevirtual

Get proxy with given id and key.

Parameters
idThe CLID of the desired object.
keyThe key of the desired object.

If the key is a null string, then it is a default key. Finding a proxy via the default key should succeed only if there is exactly one object with the given CLID in the store. Finding a proxy via a default key is considered deprecated for the case of the event store.

Returns 0 to flag failure

Definition at line 112 of file View.cxx.

113{
114 return findProxy( id, key, m_allowFallThrough );
115}
SG::DataProxy * findProxy(const CLID &id, const std::string &key, bool allowFallThrough) const
Internal implementation of proxy()
Definition View.cxx:121

◆ proxy() [2/2]

virtual SG::DataProxy * SG::View::proxy ( const void *const pTransient) const
inlineoverridevirtual

Get a proxy referencing a given transient object.

Parameters
pTransientThe object to find.

Returns 0 to flag failure

Definition at line 151 of file View.h.

151 {
152 return m_store->proxy( pTransient );
153 }

◆ proxy_exact()

SG::DataProxy * SG::View::proxy_exact ( SG::sgkey_t sgkey) const
overridevirtual

Get proxy given a hashed key+clid.

Parameters
sgkeyHashed key to look up.

Find an exact match; no handling of aliases, etc. Returns 0 to flag failure.

Parameters
sgkeyHashed key to look up.

Find an exact match; no handling of aliases, etc. Returns 0 to flag failure.

Note
The implementation of proxy_exact is a bit special for the view case. This method is called by the Read/WriteHandle to avoid lengthy lookups via the string key. However, the sgkey that is passed is the hashed key of the original HandleKey (without the view prefix). So whenever we store an object in a view, we calculate the raw hashed key in recordObject() and store a mapping to the hashed view key to be able to retrieve the correct proxy here.

Definition at line 90 of file View.cxx.

90 {
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}

◆ recordObject()

SG::DataProxy * SG::View::recordObject ( SG::DataObjectSharedPtr< DataObject > obj,
const std::string & key,
bool allowMods,
bool returnExisting )
overridevirtual

Record an object in the store.

Parameters
objThe data object to store.
keyThe key as which it should be stored.
allowModsIf false, the object will be recorded as const.

Full-blown record. obj should usually be something deriving from SG::DataBucket.

Returns the proxy for the recorded object; nullptr on failure.

Definition at line 57 of file View.cxx.

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}
SG::sgkey_t sgkey_t
Type of the keys.
Definition IStringPool.h:34

◆ registerKey()

virtual void SG::View::registerKey ( IStringPool::sgkey_t key,
const std::string & str,
CLID clid )
inlineoverridevirtual

Remember an additional mapping from key to string/CLID.

Definition at line 251 of file View.h.

251 {
252 m_store->registerKey( key, viewKey(str), clid );
253 }

◆ setFilter()

void SG::View::setFilter ( std::vector< std::string > const & inputFilter)
inline

Set a filtering rule for anything loaded via fall-through.

Parameters
inputFilterOnly allow keys containing one these strings to fall-through.

Definition at line 86 of file View.h.

86 {
87 m_fallFilter = inputFilter;
88 }

◆ setROI()

void SG::View::setROI ( const ElementLink< TrigRoiDescriptorCollection > & roi)
inline

Associated RoI with this view.

Definition at line 93 of file View.h.

93 {
94 m_roi = roi;
95 }

◆ stringToKey()

virtual IStringPool::sgkey_t SG::View::stringToKey ( const std::string & str,
CLID clid )
inlineoverridevirtual

Find the key for a string/CLID pair.

Definition at line 244 of file View.h.

244 {
245 return m_store->stringToKey( viewKey(str), clid );
246 }

◆ tryELRemap()

bool SG::View::tryELRemap ( sgkey_t sgkey_in,
size_t index_in,
sgkey_t & sgkey_out,
size_t & index_out )
overridevirtual

Test to see if the target of an ElementLink has moved.

Parameters
sgkey_inOriginal hashed key of the EL.
index_inOriginal index of the EL.
sgkey_out[out]New hashed key for the EL.
index_out[out]New index for the EL.
Returns
True if there is a remapping; false otherwise.

Not supported. Will throw std::runtime_error.

Definition at line 193 of file View.cxx.

194{
195 throw std::runtime_error( "Not implemented: SG::View::tryELRemap" );
196}

◆ unboundHandle()

virtual void SG::View::unboundHandle ( IResetable * handle)
inlineoverridevirtual

Tell the store that a handle has been unbound from a proxy.

Parameters
handleThe handle that was unbound.

Definition at line 204 of file View.h.

204 {
205 return m_store->unboundHandle( handle );
206 }

◆ viewID()

size_t SG::View::viewID ( ) const
inline

Return view index.

Definition at line 66 of file View.h.

66 {
67 return m_index;
68 }

◆ viewKey()

std::string SG::View::viewKey ( const std::string & key) const
inlineprivate

Construct a key as used in the parent store.

Parameters
keyThe key as used in the view.

Definition at line 267 of file View.h.

267 {
268 return SG::transientKey (m_name + "_" + key);
269 }
std::string transientKey(const std::string &key)
Make a key transient.

Member Data Documentation

◆ m_allowFallThrough

bool SG::View::m_allowFallThrough {true}
private

Definition at line 282 of file View.h.

282{true};

◆ m_fallFilter

std::vector< std::string > SG::View::m_fallFilter
private

Definition at line 278 of file View.h.

◆ m_index

size_t SG::View::m_index {0}
private

Definition at line 281 of file View.h.

281{0};

◆ m_keyMap

KeyMap_t SG::View::m_keyMap
private

Definition at line 275 of file View.h.

◆ m_name

std::string SG::View::m_name
private

Definition at line 280 of file View.h.

◆ m_parents

std::set< const SG::View* > SG::View::m_parents
private

Definition at line 277 of file View.h.

◆ m_roi

ElementLink<TrigRoiDescriptorCollection> SG::View::m_roi
private

Definition at line 272 of file View.h.

◆ m_store

ServiceHandle< StoreGateSvc > SG::View::m_store
private

Definition at line 271 of file View.h.


The documentation for this class was generated from the following files: