ATLAS Offline Software
SimpleView.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include <stdexcept>
6 #include "AthViews/SimpleView.h"
7 #include "AthViews/View.h"
8 #include "SGTools/transientKey.h"
9 
10 SimpleView::SimpleView( std::string const& Name, bool AllowFallThrough, std::string const& storeName ) :
11  m_store( storeName, Name ),
12  m_roi(),
13  m_name( Name ),
14  m_allowFallThrough( AllowFallThrough )
15 {
16 }
17 
19 {
20 }
21 
22 
27 std::string SimpleView::viewKey (const std::string& key) const
28 {
29  return SG::transientKey (m_name + "_" + key);
30 }
31 
32 
34  auto castParent = dynamic_cast< const SG::View* >( parent );
35  if ( castParent ) {
36  m_parents.insert( castParent );
37  }
38  else {
39  throw std::runtime_error( "Unable to link parent view that cannot be cast to SG::View" );
40  }
41 }
42 
43 
52 {
53  return nullptr;
54 }
55 
56 
70 SG::DataProxy * SimpleView::proxy( const CLID& id, const std::string& key ) const
71 {
72  return findProxy( id, key, m_allowFallThrough );
73 }
74 
75 SG::DataProxy * SimpleView::findProxy( const CLID& id, const std::string& key, const bool allowFallThrough ) const
76 {
77  auto isValid = [](const SG::DataProxy* p) { return p != nullptr and p->isValid(); };
78  auto localProxy = m_store->proxy( id, viewKey(key) );
79  if ( isValid( localProxy ) ) {
80  return localProxy;
81  }
82 
83  for ( auto parent: m_parents ) {
84  // Don't allow parents to access whole-event store independently of this view
85  auto inParentProxy = parent->impl()->findProxy( id, key, false );
86  if ( isValid( inParentProxy ) ) {
87  return inParentProxy;
88  }
89  }
90 
91  //Look in the default store if cound not find in any view - for instance for event-wise IDCs
92  if ( (not isValid( localProxy )) and allowFallThrough ) {
93 
94  //Apply filtering
95  if ( m_fallFilter.size() ) {
96  bool filterPass = false;
97 
98  //Filter passes if the key contains one of the possible values
99  for ( auto& entry : m_fallFilter ) {
100  if ( key.find( entry ) != std::string::npos ) {
101  filterPass = true;
102  break;
103  }
104  }
105 
106  if ( !filterPass ) return nullptr;
107  }
108 
109  return m_store->proxy( id, key );
110  }
111  return nullptr;
112 }
113 
114 
121 SG::DataProxy * SimpleView::proxy( const void* const pTransient ) const
122 {
123  return m_store->proxy( pTransient );
124 }
125 
126 
130 std::vector< const SG::DataProxy* > SimpleView::proxies() const
131 {
132  return m_store->proxies();
133 }
134 
135 
147 {
148  return m_store->addToStore( id, proxy );
149 }
150 
151 
162 bool SimpleView::tryELRemap( sgkey_t sgkey_in, size_t index_in, sgkey_t & sgkey_out, size_t & index_out )
163 {
164  throw std::runtime_error( "Not implemented: SimpleView::tryELRemap" );
165  return m_store->tryELRemap( sgkey_in, index_in, sgkey_out, index_out );
166 }
167 
179 SG::DataProxy * SimpleView::recordObject( SG::DataObjectSharedPtr<DataObject> obj, const std::string& key, bool allowMods, bool returnExisting )
180 {
181  return m_store->recordObject( obj, viewKey(key), allowMods, returnExisting );
182 }
183 
190 {
191  return m_store->boundHandle( handle );
192 }
193 
200 {
201  return m_store->unboundHandle( handle );
202 }
203 
204 unsigned long SimpleView::addRef()
205 {
206  throw std::runtime_error( "Not implemented: SimpleView::addRef" );
207  return 0;
208 }
209 unsigned long SimpleView::release()
210 {
211  throw std::runtime_error( "Not implemented: SimpleView::release" );
212  return 0;
213 }
214 StatusCode SimpleView::queryInterface( const InterfaceID &/*ti*/, void** /*pp*/ )
215 {
216  throw std::runtime_error( "Not implemented: SimpleView::queryInterface" );
217  return StatusCode::FAILURE;
218 }
219 const std::string& SimpleView::name() const
220 {
221  return m_name;
222 }
223 
224 //IStringPool
226 {
227  return m_store->stringToKey( viewKey(str), clid );
228 }
230 {
231  throw std::runtime_error( "Not implemented: SimpleView::keyToString" );
232  return m_store->keyToString( key );
233 }
234 const std::string* SimpleView::keyToString( IStringPool::sgkey_t key, CLID& clid ) const
235 {
236  throw std::runtime_error( "Not implemented: SimpleView::keyToString" );
237  return m_store->keyToString( key, clid );
238 }
239 void SimpleView::registerKey( IStringPool::sgkey_t key, const std::string& str, CLID clid )
240 {
241  m_store->registerKey( key, viewKey(str), clid );
242 }
243 
245  m_roi = roi;
246 }
247 
249  return m_roi;
250 }
251 
252 std::string SimpleView::dump( const std::string& indent ) const {
253 
254  // Dump view contents
255  std::string ret = indent + "Dump " + name() + "\n";
256  ret += indent + "[";
257  for ( const SG::DataProxy* dp: proxies() ) {
258  if ( dp->name().find( name() ) == 0 )
259  ret += " " + dp->name();
260  }
261  ret += " ]\n";
262 
263  // Dump parent views
264  if ( m_parents.size() ) ret += indent + "Parents:\n";
265  for ( auto p : m_parents ) {
266  ret += p->dump( indent + " " );
267  }
268 
269  // Fallthrough
270  if ( indent == "" ) {
271  if ( m_allowFallThrough ) {
272  ret += indent + "May access main store: " + m_store->name();
273  } else {
274  ret += indent + "May not access main store";
275  }
276  }
277  return ret;
278 }
SimpleView::release
virtual unsigned long release()
Definition: SimpleView.cxx:209
TileDCSDataPlotter.dp
dp
Definition: TileDCSDataPlotter.py:840
SimpleView.h
SimpleView::m_fallFilter
std::vector< std::string > m_fallFilter
Definition: SimpleView.h:200
SimpleView::addToStore
virtual StatusCode addToStore(CLID id, SG::DataProxy *proxy)
Add a new proxy to the store.
Definition: SimpleView.cxx:146
StateLessPT_NewConfig.proxy
proxy
Definition: StateLessPT_NewConfig.py:392
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
SimpleView::tryELRemap
virtual bool tryELRemap(sgkey_t sgkey_in, size_t index_in, sgkey_t &sgkey_out, size_t &index_out)
Test to see if the target of an ElementLink has moved.
Definition: SimpleView.cxx:162
SimpleView::stringToKey
virtual IStringPool::sgkey_t stringToKey(const std::string &str, CLID clid)
Find the key for a string/CLID pair.
Definition: SimpleView.cxx:225
SimpleView::m_allowFallThrough
bool m_allowFallThrough
Definition: SimpleView.h:201
SimpleView::m_name
std::string m_name
Definition: SimpleView.h:198
isValid
bool isValid(const T &p)
Definition: AtlasPID.h:214
SimpleView::unboundHandle
virtual void unboundHandle(IResetable *handle)
Tell the store that a handle has been unbound from a proxy.
Definition: SimpleView.cxx:199
IStringPool::sgkey_t
SG::sgkey_t sgkey_t
Type of the keys.
Definition: IStringPool.h:34
SimpleView::dump
std::string dump(const std::string &indent="") const
Definition: SimpleView.cxx:252
IProxyDict
A proxy dictionary.
Definition: AthenaKernel/AthenaKernel/IProxyDict.h:51
transientKey.h
SimpleView::addRef
virtual unsigned long addRef()
Definition: SimpleView.cxx:204
SimpleView::boundHandle
virtual void boundHandle(IResetable *handle)
Tell the store that a handle has been bound to a proxy.
Definition: SimpleView.cxx:189
SimpleView::m_parents
std::set< const SG::View * > m_parents
Definition: SimpleView.h:199
IResetable
a resetable object (e.g. a SG DataHandle)
Definition: IResetable.h:15
geometry_dat_to_json.indent
indent
Definition: geometry_dat_to_json.py:18
SimpleView::proxies
virtual std::vector< const SG::DataProxy * > proxies() const
Return the list of all current proxies in store.
Definition: SimpleView.cxx:130
SimpleView::registerKey
virtual void registerKey(IStringPool::sgkey_t key, const std::string &str, CLID clid)
Remember an additional mapping from key to string/CLID.
Definition: SimpleView.cxx:239
SimpleView::proxy
virtual SG::DataProxy * proxy(const CLID &id, const std::string &key) const
Get proxy with given id and key.
Definition: SimpleView.cxx:70
ret
T ret(T t)
Definition: rootspy.cxx:260
SimpleView::~SimpleView
virtual ~SimpleView()
Definition: SimpleView.cxx:18
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
test_pyathena.parent
parent
Definition: test_pyathena.py:15
SimpleView::getROI
const ElementLink< TrigRoiDescriptorCollection > & getROI() const
Definition: SimpleView.cxx:248
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
SimpleView::proxy_exact
virtual SG::DataProxy * proxy_exact(SG::sgkey_t sgkey) const
Get proxy given a hashed key+clid.
Definition: SimpleView.cxx:51
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
SimpleView::viewKey
std::string viewKey(const std::string &key) const
Construct a key as used in the parent store.
Definition: SimpleView.cxx:27
SimpleView::recordObject
virtual SG::DataProxy * recordObject(SG::DataObjectSharedPtr< DataObject > obj, const std::string &key, bool allowMods, bool returnExisting)
Record an object in the store.
Definition: SimpleView.cxx:179
SimpleView::keyToString
virtual const std::string * keyToString(IStringPool::sgkey_t key) const
Find the string corresponding to a given key.
Definition: SimpleView.cxx:229
SG::sgkey_t
uint32_t sgkey_t
Type used for hashed StoreGate key+CLID pairs.
Definition: CxxUtils/CxxUtils/sgkey_t.h:32
SimpleView::name
virtual const std::string & name() const
Definition: SimpleView.cxx:219
SimpleView::queryInterface
virtual StatusCode queryInterface(const InterfaceID &ti, void **pp)
Definition: SimpleView.cxx:214
Name
JetDumper::Name Name
Definition: JetDumper.cxx:19
SimpleView::setROI
void setROI(const ElementLink< TrigRoiDescriptorCollection > &roi)
Definition: SimpleView.cxx:244
SimpleView::SimpleView
SimpleView()=delete
SG::transientKey
std::string transientKey(const std::string &key)
Make a key transient.
Definition: transientKey.h:51
SimpleView::linkParent
virtual void linkParent(const IProxyDict *parent)
links to the previously used views through these parent views additional data objects become availabl...
Definition: SimpleView.cxx:33
str
Definition: BTagTrackIpAccessor.cxx:11
SimpleView::m_roi
ElementLink< TrigRoiDescriptorCollection > m_roi
Definition: SimpleView.h:197
SG::DataObjectSharedPtr
Smart pointer to manage DataObject reference counts.
Definition: DataObjectSharedPtr.h:46
View.h
SG::View
Definition: View.h:25
python.PyAthena.obj
obj
Definition: PyAthena.py:135
SG::DataProxy
Definition: DataProxy.h:44
SimpleView::m_store
ServiceHandle< StoreGateSvc > m_store
Definition: SimpleView.h:194
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
SimpleView::findProxy
virtual SG::DataProxy * findProxy(const CLID &id, const std::string &key, const bool allowFallThrough) const
Definition: SimpleView.cxx:75