Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
StoreSnifferAlg.cpp
Go to the documentation of this file.
1 // ====================================================================
2 // StoreSnifferAlg.cpp
3 // --------------------------------------------------------------------
4 //
5 // Author : Markus Frank
6 //
7 // ====================================================================
12 #include "GaudiKernel/IRegistry.h"
15 #include "GaudiKernel/SmartIF.h"
16 
17 using namespace std;
18 
27 class StoreSnifferAlg : public Algorithm {
28 public:
31 
33 
34  struct LeafInfo final {
35  int count;
36  int id;
38  };
41 
42  SniffInfo m_info, m_curr;
43  Correlations m_corr, m_links;
44 
45  size_t explore( IRegistry* pObj ) {
46  if ( pObj ) {
47  auto mgr = eventSvc().as<IDataManagerSvc>();
48  if ( mgr ) {
49  vector<IRegistry*> leaves;
50  StatusCode sc = m_mgr->objectLeaves( pObj, leaves );
51  if ( sc.isSuccess() ) {
52  for ( auto& pReg : leaves ) {
54  if ( !pReg->address() || !pReg->object() ) continue;
55  const string& id = pReg->identifier();
56  auto j = m_info.find( id );
57  if ( j == m_info.end() ) {
58  m_info[id] = LeafInfo();
59  j = m_info.find( id );
60  j->second.count = 0;
61  j->second.id = m_info.size();
62  j->second.clid = pReg->object()->clID();
63  }
64  m_curr[id].id = m_info[id].id;
65  m_curr[id].count = explore( pReg );
66  }
67  return leaves.size();
68  }
69  }
70  }
71  return 0;
72  }
73 
75  StatusCode initialize() override {
76  m_info.clear();
77  m_mgr = eventSvc();
78  return StatusCode::SUCCESS;
79  }
80 
82  StatusCode finalize() override {
83  auto& log = always();
84  log << "== BEGIN ============= Access list content:" << m_info.size() << endmsg;
85  for ( const auto& i : m_info ) {
86  const LeafInfo& info = i.second;
87  log << "== ITEM == " << right << setw( 4 ) << dec << info.id << " clid:" << right << setw( 8 ) << hex << info.clid
88  << " Count:" << right << setw( 6 ) << dec << info.count << " " << i.first + ":" << endmsg;
89  auto c = m_corr.find( i.first );
90  if ( c != m_corr.end() ) {
91  int cnt = 0;
92  log << "== CORRELATIONS:" << ( *c ).second.size() << endmsg;
93  for ( const auto& k : c->second ) {
94  if ( k.second > 0 ) {
95  log << dec << k.first << ":" << k.second << " ";
96  if ( ++cnt == 10 ) {
97  cnt = 0;
98  log << endmsg;
99  }
100  }
101  }
102  if ( cnt > 0 ) log << endmsg;
103  }
104  auto l = m_links.find( i.first );
105  if ( l != m_links.end() ) {
106  int cnt = 0;
107  log << "== LINKS:" << l->second.size() << endmsg;
108  for ( const auto& k : l->second ) {
109  if ( k.second > 0 ) {
110  log << dec << k.first << ":" << k.second << " ";
111  if ( ++cnt == 10 ) {
112  cnt = 0;
113  log << endmsg;
114  }
115  }
116  }
117  if ( cnt > 0 ) log << endmsg;
118  }
119  }
120  always() << "== END =============== Access list content:" << m_info.size() << endmsg;
121  m_info.clear();
122  m_mgr = nullptr;
123  return StatusCode::SUCCESS;
124  }
125 
127  StatusCode execute() override {
128  SmartDataPtr<DataObject> root( eventSvc(), "/Event" );
129  if ( root ) {
130  m_curr.clear();
131  auto& evnt = m_curr["/Event"];
132  evnt.count = explore( root->registry() );
133  evnt.clid = root->clID();
134  evnt.id = m_curr.size();
135  for ( const auto& i : m_curr ) m_info[i.first].count++;
136  for ( const auto& i : m_info ) {
137  const string& nam = i.first;
138  // const LeafInfo& leaf = (*i).second;
139  auto c = m_corr.find( nam );
140  if ( c == m_corr.end() ) {
141  m_corr[nam] = {};
142  c = m_corr.find( nam );
143  }
144  for ( const auto& l : m_curr ) {
145  const auto& id = l.second.id;
146  auto k = c->second.find( id );
147  if ( k == c->second.end() ) k = c->second.emplace( id, 0 ).first;
148  ++( k->second );
149  }
150 
151  c = m_links.find( nam );
152  if ( c == m_links.end() ) c = m_links.emplace( nam, std::map<int, int>{} ).first;
153  if ( m_curr.find( nam ) == m_curr.end() ) continue;
154 
155  SmartDataPtr<DataObject> obj( eventSvc(), nam );
156  if ( !obj ) continue;
157 
158  LinkManager* m = obj->linkMgr();
159  for ( long l = 0; l < m->size(); ++l ) {
160  auto* lnk = m->link( l );
161  auto il = m_curr.find( lnk->path() );
162  // cout << "Link:" << lnk->path() << " " << (char*)(il != m_curr.end() ? "Found" : "Not there") << endl;
163  if ( il == m_curr.end() ) continue;
164  if ( !lnk->object() ) continue;
165  const auto& id = il->second.id;
166  auto k = c->second.find( id );
167  if ( k == c->second.end() ) k = c->second.emplace( id, 0 ).first;
168  ++( k->second );
169  }
170  }
171  }
172  return StatusCode::SUCCESS;
173  }
174 };
175 
virtual StatusCode objectLeaves(const DataObject *pObject, std::vector< IRegistry * > &refLeaves)=0
Explore the object store: retrieve all leaves attached to the object The object is identified by its ...
bool isSuccess() const
Definition: StatusCode.h:267
T log(T...args)
Algorithm(const std::string &name, ISvcLocator *svcloc, const std::string &version=PACKAGE_VERSION)
Constructor.
Definition: Algorithm.cpp:48
Small algorithm, which traverses the data store and prints a summary of the leafs accessed during the...
T right(T...args)
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
STL namespace.
T end(T...args)
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:72
LinkManager * linkMgr() const
Retrieve Link manager.
Definition: DataObject.h:74
T setw(T...args)
#define DECLARE_COMPONENT(type)
SmartIF< IDataManagerSvc > m_mgr
Correlations m_links
map< string, map< int, int > > Correlations
virtual const CLID & clID() const
Retrieve reference to class definition structure.
Definition: DataObject.cpp:56
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
constexpr double m
Definition: SystemOfUnits.h:92
void clear(STATE_TYPE _i=std::ios_base::failbit)
Definition: MsgStream.h:171
StatusCode finalize() override
Finalize.
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition: IRegistry.h:22
StatusCode execute() override
Execute procedure.
unsigned int CLID
Class ID definition.
Definition: ClassID.h:8
T clear(T...args)
map< string, LeafInfo > SniffInfo
T count(T...args)
dictionary l
Definition: gaudirun.py:517
Alias for backward compatibility.
Definition: Algorithm.h:56
T find(T...args)
T size(T...args)
T emplace(T...args)
A small class used to access easily (and efficiently) data items residing in data stores...
Definition: SmartDataPtr.h:47
T dec(T...args)
size_t explore(IRegistry *pObj)
StatusCode initialize() override
Initialize.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192