The Gaudi Framework  master (905e8f18)
Loading...
Searching...
No Matches
StoreSnifferAlg.cpp
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2026 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// ====================================================================
25#include <GaudiKernel/SmartIF.h>
26#include <iomanip>
27#include <map>
28#include <string>
29#include <vector>
30
39class StoreSnifferAlg : public Algorithm {
40public:
43
45
46 struct LeafInfo final {
47 int count;
48 int id;
50 };
51 typedef std::map<std::string, LeafInfo> SniffInfo;
52 typedef std::map<std::string, std::map<int, int>> Correlations;
53
56
57 size_t explore( IRegistry* pObj ) {
58 if ( pObj ) {
59 auto mgr = eventSvc().as<IDataManagerSvc>();
60 if ( mgr ) {
61 std::vector<IRegistry*> leaves;
62 StatusCode sc = m_mgr->objectLeaves( pObj, leaves );
63 if ( sc.isSuccess() ) {
64 for ( auto& pReg : leaves ) {
66 if ( !pReg->address() || !pReg->object() ) continue;
67 const std::string& id = pReg->identifier();
68 auto j = m_info.find( id );
69 if ( j == m_info.end() ) {
70 m_info[id] = LeafInfo();
71 j = m_info.find( id );
72 j->second.count = 0;
73 j->second.id = m_info.size();
74 j->second.clid = pReg->object()->clID();
75 }
76 m_curr[id].id = m_info[id].id;
77 m_curr[id].count = explore( pReg );
78 }
79 return leaves.size();
80 }
81 }
82 }
83 return 0;
84 }
85
88 m_info.clear();
89 m_mgr = eventSvc();
91 }
92
94 StatusCode finalize() override {
95 auto& log = always();
96 log << "== BEGIN ============= Access list content:" << m_info.size() << endmsg;
97 for ( const auto& i : m_info ) {
98 const LeafInfo& info = i.second;
99 log << "== ITEM == " << std::right << std::setw( 4 ) << std::dec << info.id << " clid:" << std::right
100 << std::setw( 8 ) << std::hex << info.clid << " Count:" << std::right << std::setw( 6 ) << std::dec
101 << info.count << " " << i.first + ":" << endmsg;
102 auto c = m_corr.find( i.first );
103 if ( c != m_corr.end() ) {
104 int cnt = 0;
105 log << "== CORRELATIONS:" << ( *c ).second.size() << endmsg;
106 for ( const auto& k : c->second ) {
107 if ( k.second > 0 ) {
108 log << std::dec << k.first << ":" << k.second << " ";
109 if ( ++cnt == 10 ) {
110 cnt = 0;
111 log << endmsg;
112 }
113 }
114 }
115 if ( cnt > 0 ) log << endmsg;
116 }
117 auto l = m_links.find( i.first );
118 if ( l != m_links.end() ) {
119 int cnt = 0;
120 log << "== LINKS:" << l->second.size() << endmsg;
121 for ( const auto& k : l->second ) {
122 if ( k.second > 0 ) {
123 log << std::dec << k.first << ":" << k.second << " ";
124 if ( ++cnt == 10 ) {
125 cnt = 0;
126 log << endmsg;
127 }
128 }
129 }
130 if ( cnt > 0 ) log << endmsg;
131 }
132 }
133 always() << "== END =============== Access list content:" << m_info.size() << endmsg;
134 m_info.clear();
135 m_mgr = nullptr;
136 return StatusCode::SUCCESS;
137 }
138
140 StatusCode execute() override {
141 SmartDataPtr<DataObject> root( eventSvc(), "/Event" );
142 if ( root ) {
143 m_curr.clear();
144 auto& evnt = m_curr["/Event"];
145 evnt.count = explore( root->registry() );
146 evnt.clid = root->clID();
147 evnt.id = m_curr.size();
148 for ( const auto& i : m_curr ) m_info[i.first].count++;
149 for ( const auto& i : m_info ) {
150 const std::string& nam = i.first;
151 // const LeafInfo& leaf = (*i).second;
152 auto c = m_corr.find( nam );
153 if ( c == m_corr.end() ) {
154 m_corr[nam] = {};
155 c = m_corr.find( nam );
156 }
157 for ( const auto& l : m_curr ) {
158 const auto& id = l.second.id;
159 auto k = c->second.find( id );
160 if ( k == c->second.end() ) k = c->second.emplace( id, 0 ).first;
161 ++( k->second );
162 }
163
164 c = m_links.find( nam );
165 if ( c == m_links.end() ) c = m_links.emplace( nam, std::map<int, int>{} ).first;
166 if ( m_curr.find( nam ) == m_curr.end() ) continue;
167
169 if ( !obj ) continue;
170
171 LinkManager* m = obj->linkMgr();
172 for ( long l = 0; l < m->size(); ++l ) {
173 auto* lnk = m->link( l );
174 auto il = m_curr.find( lnk->path() );
175 // cout << "Link:" << lnk->path() << " " << (char*)(il != m_curr.end() ? "Found" : "Not there") << endl;
176 if ( il == m_curr.end() ) continue;
177 if ( !lnk->object() ) continue;
178 const auto& id = il->second.id;
179 auto k = c->second.find( id );
180 if ( k == c->second.end() ) k = c->second.emplace( id, 0 ).first;
181 ++( k->second );
182 }
183 }
184 }
185 return StatusCode::SUCCESS;
186 }
187};
188
unsigned int CLID
Class ID definition.
Definition ClassID.h:16
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
#define DECLARE_COMPONENT(type)
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
MsgStream & always() const
shortcut for the method msgStream(MSG::ALWAYS)
SmartIF< IDataProviderSvc > & eventSvc() const
The standard event data service.
Algorithm(std::string name, ISvcLocator *svcloc, std::string version=PACKAGE_VERSION)
Constructor.
Definition Algorithm.h:98
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition IRegistry.h:29
A small class used to access easily (and efficiently) data items residing in data stores.
Small smart pointer class with automatic reference counting for IInterface.
Definition SmartIF.h:28
SmartIF< IFace > as() const
return a new SmartIF instance to another interface
Definition SmartIF.h:110
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
bool isSuccess() const
Definition StatusCode.h:314
constexpr static const auto SUCCESS
Definition StatusCode.h:99
Small algorithm, which traverses the data store and prints a summary of the leafs accessed during the...
SmartIF< IDataManagerSvc > m_mgr
std::map< std::string, std::map< int, int > > Correlations
Correlations m_links
size_t explore(IRegistry *pObj)
Correlations m_corr
StatusCode execute() override
Execute procedure.
StatusCode initialize() override
Initialize.
StatusCode finalize() override
Finalize.
std::map< std::string, LeafInfo > SniffInfo