The Gaudi Framework  v33r0 (d5ea422b)
StoreSnifferAlg.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 // ====================================================================
12 // StoreSnifferAlg.cpp
13 // --------------------------------------------------------------------
14 //
15 // Author : Markus Frank
16 //
17 // ====================================================================
18 #include "GaudiKernel/Algorithm.h"
19 #include "GaudiKernel/DataObject.h"
22 #include "GaudiKernel/IRegistry.h"
25 #include "GaudiKernel/SmartIF.h"
26 
27 using namespace std;
28 
37 class StoreSnifferAlg : public Algorithm {
38 public:
41 
43 
44  struct LeafInfo final {
45  int count;
46  int id;
48  };
51 
52  SniffInfo m_info, m_curr;
54 
55  size_t explore( IRegistry* pObj ) {
56  if ( pObj ) {
57  auto mgr = eventSvc().as<IDataManagerSvc>();
58  if ( mgr ) {
59  vector<IRegistry*> leaves;
60  StatusCode sc = m_mgr->objectLeaves( pObj, leaves );
61  if ( sc.isSuccess() ) {
62  for ( auto& pReg : leaves ) {
64  if ( !pReg->address() || !pReg->object() ) continue;
65  const string& id = pReg->identifier();
66  auto j = m_info.find( id );
67  if ( j == m_info.end() ) {
68  m_info[id] = LeafInfo();
69  j = m_info.find( id );
70  j->second.count = 0;
71  j->second.id = m_info.size();
72  j->second.clid = pReg->object()->clID();
73  }
74  m_curr[id].id = m_info[id].id;
75  m_curr[id].count = explore( pReg );
76  }
77  return leaves.size();
78  }
79  }
80  }
81  return 0;
82  }
83 
85  StatusCode initialize() override {
86  m_info.clear();
87  m_mgr = eventSvc();
88  return StatusCode::SUCCESS;
89  }
90 
92  StatusCode finalize() override {
93  auto& log = always();
94  log << "== BEGIN ============= Access list content:" << m_info.size() << endmsg;
95  for ( const auto& i : m_info ) {
96  const LeafInfo& info = i.second;
97  log << "== ITEM == " << right << setw( 4 ) << dec << info.id << " clid:" << right << setw( 8 ) << hex << info.clid
98  << " Count:" << right << setw( 6 ) << dec << info.count << " " << i.first + ":" << endmsg;
99  auto c = m_corr.find( i.first );
100  if ( c != m_corr.end() ) {
101  int cnt = 0;
102  log << "== CORRELATIONS:" << ( *c ).second.size() << endmsg;
103  for ( const auto& k : c->second ) {
104  if ( k.second > 0 ) {
105  log << dec << k.first << ":" << k.second << " ";
106  if ( ++cnt == 10 ) {
107  cnt = 0;
108  log << endmsg;
109  }
110  }
111  }
112  if ( cnt > 0 ) log << endmsg;
113  }
114  auto l = m_links.find( i.first );
115  if ( l != m_links.end() ) {
116  int cnt = 0;
117  log << "== LINKS:" << l->second.size() << endmsg;
118  for ( const auto& k : l->second ) {
119  if ( k.second > 0 ) {
120  log << dec << k.first << ":" << k.second << " ";
121  if ( ++cnt == 10 ) {
122  cnt = 0;
123  log << endmsg;
124  }
125  }
126  }
127  if ( cnt > 0 ) log << endmsg;
128  }
129  }
130  always() << "== END =============== Access list content:" << m_info.size() << endmsg;
131  m_info.clear();
132  m_mgr = nullptr;
133  return StatusCode::SUCCESS;
134  }
135 
137  StatusCode execute() override {
138  SmartDataPtr<DataObject> root( eventSvc(), "/Event" );
139  if ( root ) {
140  m_curr.clear();
141  auto& evnt = m_curr["/Event"];
142  evnt.count = explore( root->registry() );
143  evnt.clid = root->clID();
144  evnt.id = m_curr.size();
145  for ( const auto& i : m_curr ) m_info[i.first].count++;
146  for ( const auto& i : m_info ) {
147  const string& nam = i.first;
148  // const LeafInfo& leaf = (*i).second;
149  auto c = m_corr.find( nam );
150  if ( c == m_corr.end() ) {
151  m_corr[nam] = {};
152  c = m_corr.find( nam );
153  }
154  for ( const auto& l : m_curr ) {
155  const auto& id = l.second.id;
156  auto k = c->second.find( id );
157  if ( k == c->second.end() ) k = c->second.emplace( id, 0 ).first;
158  ++( k->second );
159  }
160 
161  c = m_links.find( nam );
162  if ( c == m_links.end() ) c = m_links.emplace( nam, std::map<int, int>{} ).first;
163  if ( m_curr.find( nam ) == m_curr.end() ) continue;
164 
165  SmartDataPtr<DataObject> obj( eventSvc(), nam );
166  if ( !obj ) continue;
167 
168  LinkManager* m = obj->linkMgr();
169  for ( long l = 0; l < m->size(); ++l ) {
170  auto* lnk = m->link( l );
171  auto il = m_curr.find( lnk->path() );
172  // cout << "Link:" << lnk->path() << " " << (char*)(il != m_curr.end() ? "Found" : "Not there") << endl;
173  if ( il == m_curr.end() ) continue;
174  if ( !lnk->object() ) continue;
175  const auto& id = il->second.id;
176  auto k = c->second.find( id );
177  if ( k == c->second.end() ) k = c->second.emplace( id, 0 ).first;
178  ++( k->second );
179  }
180  }
181  }
182  return StatusCode::SUCCESS;
183  }
184 };
185 
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 ...
LinkManager * linkMgr() const
Retrieve Link manager.
Definition: DataObject.h:84
T log(T... args)
Algorithm(const std::string &name, ISvcLocator *svcloc, const std::string &version=PACKAGE_VERSION)
Constructor.
Definition: Algorithm.cpp:59
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:96
STL namespace.
T end(T... args)
T setw(T... args)
#define DECLARE_COMPONENT(type)
SmartIF< IDataManagerSvc > m_mgr
Correlations m_links
map< string, map< int, int > > Correlations
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
constexpr double m
void clear(STATE_TYPE _i=std::ios_base::failbit)
Definition: MsgStream.h:181
StatusCode finalize() override
Finalize.
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition: IRegistry.h:32
StatusCode execute() override
Execute procedure.
unsigned int CLID
Class ID definition.
Definition: ClassID.h:18
T clear(T... args)
bool isSuccess() const
Definition: StatusCode.h:361
map< string, LeafInfo > SniffInfo
T count(T... args)
dictionary l
Definition: gaudirun.py:543
Alias for backward compatibility.
Definition: Algorithm.h:66
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:57
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:202