The Gaudi Framework  v30r3 (a5ef0a68)
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 {
29 public:
32 
34 
35  struct LeafInfo final {
36  int count;
37  int id;
39  };
42 
43  SniffInfo m_info, m_curr;
44  Correlations m_corr, m_links;
45 
46  size_t explore( IRegistry* pObj )
47  {
48  if ( pObj ) {
49  auto mgr = eventSvc().as<IDataManagerSvc>();
50  if ( mgr ) {
51  vector<IRegistry*> leaves;
52  StatusCode sc = m_mgr->objectLeaves( pObj, leaves );
53  if ( sc.isSuccess() ) {
54  for ( auto& pReg : leaves ) {
56  if ( !pReg->address() || !pReg->object() ) continue;
57  const string& id = pReg->identifier();
58  auto j = m_info.find( id );
59  if ( j == m_info.end() ) {
60  m_info[id] = LeafInfo();
61  j = m_info.find( id );
62  j->second.count = 0;
63  j->second.id = m_info.size();
64  j->second.clid = pReg->object()->clID();
65  }
66  m_curr[id].id = m_info[id].id;
67  m_curr[id].count = explore( pReg );
68  }
69  return leaves.size();
70  }
71  }
72  }
73  return 0;
74  }
75 
78  {
79  m_info.clear();
80  m_mgr = eventSvc();
81  return StatusCode::SUCCESS;
82  }
83 
85  StatusCode finalize() override
86  {
87  auto& log = always();
88  log << "== BEGIN ============= Access list content:" << m_info.size() << endmsg;
89  for ( const auto& i : m_info ) {
90  const LeafInfo& info = i.second;
91  log << "== ITEM == " << right << setw( 4 ) << dec << info.id << " clid:" << right << setw( 8 ) << hex << info.clid
92  << " Count:" << right << setw( 6 ) << dec << info.count << " " << i.first + ":" << endmsg;
93  auto c = m_corr.find( i.first );
94  if ( c != m_corr.end() ) {
95  int cnt = 0;
96  log << "== CORRELATIONS:" << ( *c ).second.size() << endmsg;
97  for ( const auto& k : c->second ) {
98  if ( k.second > 0 ) {
99  log << dec << k.first << ":" << k.second << " ";
100  if ( ++cnt == 10 ) {
101  cnt = 0;
102  log << endmsg;
103  }
104  }
105  }
106  if ( cnt > 0 ) log << endmsg;
107  }
108  auto l = m_links.find( i.first );
109  if ( l != m_links.end() ) {
110  int cnt = 0;
111  log << "== LINKS:" << l->second.size() << endmsg;
112  for ( const auto& k : l->second ) {
113  if ( k.second > 0 ) {
114  log << dec << k.first << ":" << k.second << " ";
115  if ( ++cnt == 10 ) {
116  cnt = 0;
117  log << endmsg;
118  }
119  }
120  }
121  if ( cnt > 0 ) log << endmsg;
122  }
123  }
124  always() << "== END =============== Access list content:" << m_info.size() << endmsg;
125  m_info.clear();
126  m_mgr = nullptr;
127  return StatusCode::SUCCESS;
128  }
129 
131  StatusCode execute() override
132  {
133  SmartDataPtr<DataObject> root( eventSvc(), "/Event" );
134  if ( root ) {
135  m_curr.clear();
136  auto& evnt = m_curr["/Event"];
137  evnt.count = explore( root->registry() );
138  evnt.clid = root->clID();
139  evnt.id = m_curr.size();
140  for ( const auto& i : m_curr ) m_info[i.first].count++;
141  for ( const auto& i : m_info ) {
142  const string& nam = i.first;
143  // const LeafInfo& leaf = (*i).second;
144  auto c = m_corr.find( nam );
145  if ( c == m_corr.end() ) {
146  m_corr[nam] = {};
147  c = m_corr.find( nam );
148  }
149  for ( const auto& l : m_curr ) {
150  const auto& id = l.second.id;
151  auto k = c->second.find( id );
152  if ( k == c->second.end() ) k = c->second.emplace( id, 0 ).first;
153  ++( k->second );
154  }
155 
156  c = m_links.find( nam );
157  if ( c == m_links.end() ) c = m_links.emplace( nam, std::map<int, int>{} ).first;
158  if ( m_curr.find( nam ) == m_curr.end() ) continue;
159 
160  SmartDataPtr<DataObject> obj( eventSvc(), nam );
161  if ( !obj ) continue;
162 
163  LinkManager* m = obj->linkMgr();
164  for ( long l = 0; l < m->size(); ++l ) {
165  auto* lnk = m->link( l );
166  auto il = m_curr.find( lnk->path() );
167  // cout << "Link:" << lnk->path() << " " << (char*)(il != m_curr.end() ? "Found" : "Not there") << endl;
168  if ( il == m_curr.end() ) continue;
169  if ( !lnk->object() ) continue;
170  const auto& id = il->second.id;
171  auto k = c->second.find( id );
172  if ( k == c->second.end() ) k = c->second.emplace( id, 0 ).first;
173  ++( k->second );
174  }
175  }
176  }
177  return StatusCode::SUCCESS;
178  }
179 };
180 
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:287
T log(T...args)
Small algorithm, which traverses the data store and prints a summary of the leafs accessed during the...
T right(T...args)
STL namespace.
T end(T...args)
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:73
LinkManager * linkMgr() const
Retrieve Link manager.
Definition: DataObject.h:75
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:62
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
constexpr double m
Definition: SystemOfUnits.h:94
void clear(STATE_TYPE _i=std::ios_base::failbit)
Definition: MsgStream.h:187
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)
Algorithm(const std::string &name, ISvcLocator *svcloc, const std::string &version=PACKAGE_VERSION)
Constructor.
Definition: Algorithm.cpp:51
map< string, LeafInfo > SniffInfo
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
T count(T...args)
dictionary l
Definition: gaudirun.py:440
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:78
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:209