ATLAS Offline Software
DebugView.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 "AthViews/DebugView.h"
6 #include "AthViews/View.h"
7 
8 
9 DebugView::DebugView( std::string const& Name, bool AllowFallThrough, std::string const& storeName ) :
10  SimpleView( Name, AllowFallThrough, storeName ),
12 {
13 }
14 
16 {
17  // Debugging info
18  ATH_MSG_INFO( "Loaded via fallthrough from view " << m_name << ": " );
19  for ( auto const& key : m_fallList ) ATH_MSG_INFO( key );
20 
21  ATH_MSG_INFO( "View " << m_name << " has " << m_parents.size() << " parents" );
22 }
23 
25 
26  // Check the parent is a view
27  auto castParent = dynamic_cast< const SG::View* >( parent );
28  if ( castParent ) {
29 
30  // Check for uniqueness
31  auto result = m_parents.insert( castParent );
32  if ( std::get<1>( result ) ) {
33  ATH_MSG_INFO( "Adding parent view " << parent->name() << " to view " << name() << " with " << m_parents.size() - 1 << " existing parents" );
34  }
35  else {
36  ATH_MSG_WARNING( "Attempted to add duplicate parent " << parent->name() << " to view " << name() );
37  }
38  }
39  else {
40  ATH_MSG_ERROR( "Unable to link parent view that cannot be cast to SG::View" );
41  }
42 }
43 
44 // Calling proxy locally can have allowFallThrough true
45 SG::DataProxy * DebugView::proxy( const CLID& id, const std::string& key ) const
46 {
47  return findProxy( id, key, m_allowFallThrough );
48 }
49 
50 SG::DataProxy * DebugView::findProxy( const CLID& id, const std::string& key, const bool allowFallThrough ) const
51 {
52  auto isValid = [](const SG::DataProxy* p) { return p != nullptr and p->isValid(); };
53  auto localProxy = m_store->proxy( id, viewKey(key) );
54  if ( isValid( localProxy ) ) {
55  return localProxy;
56  }
57 
58  // Locate any parent views containing the data
59  SG::DataProxy* parentProxy = nullptr;
60  std::vector< const SG::View* > validParents;
61  for ( auto& parent: m_parents ) {
62 
63  // Don't allow parents to access whole-event store independently of this view
64  auto inParentProxy = parent->impl()->findProxy( id, key, false );
65 
66  // Record parents that contain the data
67  if ( isValid( inParentProxy ) ) {
68 
69  // Warn if two different data objects conflict
70  if ( parentProxy && ( parentProxy->object() != inParentProxy->object() ) ) {
71  ATH_MSG_WARNING( "Parent view " << parent->name() << " contains conflicting data (" << inParentProxy->object() << ") vs " << parentProxy->object() << " found first" );
72  }
73 
74  // Retrive the first data found
75  if ( !parentProxy ) parentProxy = inParentProxy;
76 
77  // Make list of all parents returning data
78  validParents.push_back( parent );
79  }
80  }
81 
82  // Return results from parent view search
83  if ( parentProxy ) {
84 
85  // Warn if multiple parents returned result
86  if ( validParents.size() > 1 ) {
87 
88  std::string validNames = "";
89  for ( auto& parent : validParents ) validNames += parent->name() + " ";
90 
91  ATH_MSG_WARNING( "Key " << key << " in multiple parents (" << validParents.size() << "): " << validNames );
92  }
93  return parentProxy;
94  }
95 
96  // Look in the default store if cound not find in any view - for instance for event-wise IDCs
97  if ( (not isValid( localProxy )) and allowFallThrough ) {
98 
99  // Apply filtering
100  if ( m_fallFilter.size() ) {
101  bool filterPass = false;
102 
103  // Filter passes if the key contains one of the possible values
104  for ( auto& entry : m_fallFilter ) {
105  if ( key.find( entry ) != std::string::npos ) {
106  filterPass = true;
107  break;
108  }
109  }
110 
111  if ( !filterPass ) {
112  ATH_MSG_INFO( "Key " << key << " not found in filter for view " << m_name << ": returning 0" );
113  return nullptr;
114  }
115  }
116 
117  auto mainStoreProxy = m_store->proxy( id, key );
118  if ( mainStoreProxy ) {
119  ATH_MSG_INFO( "Key " << key << " fell through to main store from view " << m_name << ": returning " << mainStoreProxy );
120  m_fallList.insert( key );
121  }
122  return mainStoreProxy;
123  }
124  return nullptr;
125 }
126 
127 SG::DataProxy * DebugView::proxy( const void* const pTransient ) const
128 {
129  throw std::runtime_error( "Not implemented: SimpleView::proxy" );
130  return m_store->proxy( pTransient );
131 }
132 
133 SG::DataProxy * DebugView::recordObject( SG::DataObjectSharedPtr<DataObject> obj, const std::string& key, bool allowMods, bool returnExisting )
134 {
135  // Warn if fallthrough already happened for the object
136  if ( m_fallList.find( key ) != m_fallList.end() ) {
137  ATH_MSG_WARNING( "Key " << key << " was recorded to view " << m_name << " but was previously retrieved via fallthrough" );
138  }
139 
140  return m_store->recordObject( obj, viewKey(key), allowMods, returnExisting );
141 }
SimpleView::m_fallFilter
std::vector< std::string > m_fallFilter
Definition: SimpleView.h:196
get_generator_info.result
result
Definition: get_generator_info.py:21
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
DebugView::proxy
virtual SG::DataProxy * proxy(const CLID &id, const std::string &key) const
Definition: DebugView.cxx:45
SimpleView::m_allowFallThrough
bool m_allowFallThrough
Definition: SimpleView.h:197
SimpleView::m_name
std::string m_name
Definition: SimpleView.h:194
isValid
bool isValid(const T &p)
Definition: AtlasPID.h:225
IProxyDict
A proxy dictionary.
Definition: AthenaKernel/AthenaKernel/IProxyDict.h:47
SimpleView::m_parents
std::set< const SG::View * > m_parents
Definition: SimpleView.h:195
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SimpleView
Very simple pass-through implementation of IProxyDict.
Definition: SimpleView.h:35
DebugView::DebugView
DebugView()=delete
test_pyathena.parent
parent
Definition: test_pyathena.py:15
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
DebugView::~DebugView
virtual ~DebugView()
Definition: DebugView.cxx:15
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::name
virtual const std::string & name() const
Definition: SimpleView.cxx:204
DebugView.h
Name
JetDumper::Name Name
Definition: JetDumper.cxx:19
DebugView::linkParent
virtual void linkParent(const IProxyDict *parent)
Definition: DebugView.cxx:24
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
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:132
SG::DataProxy
Definition: DataProxy.h:44
DebugView::findProxy
virtual SG::DataProxy * findProxy(const CLID &id, const std::string &key, const bool allowFallThrough) const
Definition: DebugView.cxx:50
DebugView::recordObject
virtual SG::DataProxy * recordObject(SG::DataObjectSharedPtr< DataObject > obj, const std::string &key, bool allowMods, bool returnExisting)
Definition: DebugView.cxx:133
SimpleView::m_store
ServiceHandle< StoreGateSvc > m_store
Definition: SimpleView.h:190
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37