ATLAS Offline Software
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 
18 SG::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 += '_';
28  }
29 }
30 
31 
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 
112 SG::DataProxy * SG::View::proxy( const CLID& id, const std::string& key ) const
113 {
114  return findProxy( id, key, m_allowFallThrough );
115 }
116 
117 
121 SG::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 
164 std::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 
193 bool SG::View::tryELRemap( sgkey_t, size_t, sgkey_t&, size_t& )
194 {
195  throw std::runtime_error( "Not implemented: SG::View::tryELRemap" );
196 }
197 
198 const std::string* SG::View::keyToString( IStringPool::sgkey_t, CLID& ) const
199 {
200  throw std::runtime_error( "Not implemented: SG::View::keyToString" );
201 }
202 
203 const std::string* SG::View::keyToString( IStringPool::sgkey_t ) const
204 {
205  throw std::runtime_error( "Not implemented: SG::View::keyToString" );
206 }
207 
common.sgkey
def sgkey(tool)
Definition: common.py:1027
TileDCSDataPlotter.dp
dp
Definition: TileDCSDataPlotter.py:842
StateLessPT_NewConfig.proxy
proxy
Definition: StateLessPT_NewConfig.py:407
SG::View::m_name
std::string m_name
Definition: View.h:280
index
Definition: index.py:1
SG::View::recordObject
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
isValid
bool isValid(const T &p)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
Definition: AtlasPID.h:872
m_name
std::string m_name
Definition: ColumnarPhysliteTest.cxx:63
IStringPool::sgkey_t
SG::sgkey_t sgkey_t
Type of the keys.
Definition: IStringPool.h:34
IProxyDict
A proxy dictionary.
Definition: AthenaKernel/AthenaKernel/IProxyDict.h:47
SG::View::linkParent
void linkParent(const IProxyDict *parent)
Link to the previously used views.
Definition: View.cxx:35
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
SG::View::View
View()=delete
geometry_dat_to_json.indent
indent
Definition: geometry_dat_to_json.py:37
SG::View::tryELRemap
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
test_pyathena.parent
parent
Definition: test_pyathena.py:15
SG::View::keyToString
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
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
SG::View::proxy
virtual SG::DataProxy * proxy(const CLID &id, const std::string &key) const override
Get proxy with given id and key.
Definition: View.cxx:112
SG::View::proxy_exact
virtual SG::DataProxy * proxy_exact(SG::sgkey_t sgkey) const override
Get proxy given a hashed key+clid.
Definition: View.cxx:90
SG::View::dump
std::string dump(const std::string &indent="") const
Print content of the view.
Definition: View.cxx:164
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
SG::sgkey_t
uint32_t sgkey_t
Type used for hashed StoreGate key+CLID pairs.
Definition: CxxUtils/CxxUtils/sgkey_t.h:32
DeMoScan.index
string index
Definition: DeMoScan.py:362
SG::View::KeyMap_t
SG::ConcurrentSGKeyMap< sgkey_t > KeyMap_t
Definition: View.h:274
SG::View::findProxy
SG::DataProxy * findProxy(const CLID &id, const std::string &key, bool allowFallThrough) const
Internal implementation of proxy()
Definition: View.cxx:121
SG::DataObjectSharedPtr
Smart pointer to manage DataObject reference counts.
Definition: DataObjectSharedPtr.h:45
View.h
SG::View
A "view" of the event store (IProxyDict).
Definition: View.h:46
python.PyAthena.obj
obj
Definition: PyAthena.py:132
SG::DataProxy
Definition: DataProxy.h:45
TrigRoiDescriptorCollection.h
SG::View::m_index
size_t m_index
Definition: View.h:281
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37