The Gaudi Framework  master (68c8ac5a)
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// ====================================================================
18
19// Framework includes
27#include <GaudiKernel/SmartIF.h>
28
29// STL includes
30#include <iomanip>
31#include <map>
32#include <string>
33#include <vector>
34
43class StoreSnifferAlg : public Algorithm {
44public:
47
49
50 struct LeafInfo final {
51 int count;
52 int id;
54 };
55 using SniffInfo = std::map<std::string, LeafInfo>;
56 using Correlations = std::map<std::string, std::map<int, int>>;
57
60
61 size_t explore( IRegistry* pObj ) {
62 if ( pObj ) {
63 auto mgr = eventSvc().as<IDataManagerSvc>();
64 if ( mgr ) {
65 std::vector<IRegistry*> leaves;
66 StatusCode sc = m_mgr->objectLeaves( pObj, leaves );
67 if ( sc.isSuccess() ) {
68 for ( auto& pReg : leaves ) {
70 if ( !pReg->address() || !pReg->object() ) continue;
71 const std::string& id = pReg->identifier();
72 auto j = m_info.find( id );
73 if ( j == m_info.end() ) {
74 m_info[id] = LeafInfo();
75 j = m_info.find( id );
76 j->second.count = 0;
77 j->second.id = m_info.size();
78 j->second.clid = pReg->object()->clID();
79 }
80 m_curr[id].id = m_info[id].id;
81 m_curr[id].count = explore( pReg );
82 }
83 return leaves.size();
84 }
85 }
86 }
87 return 0;
88 }
89
92 m_info.clear();
93 m_mgr = eventSvc();
95 }
96
98 StatusCode finalize() override {
99 auto& log = always();
100 log << "== BEGIN ============= Access list content:" << m_info.size() << endmsg;
101 for ( const auto& i : m_info ) {
102 const LeafInfo& info = i.second;
103 log << "== ITEM == " << std::right << std::setw( 4 ) << std::dec << info.id << " clid:" << std::right
104 << std::setw( 8 ) << std::hex << info.clid << " Count:" << std::right << std::setw( 6 ) << std::dec
105 << info.count << " " << i.first + ":" << endmsg;
106 auto c = m_corr.find( i.first );
107 if ( c != m_corr.end() ) {
108 int cnt = 0;
109 log << "== CORRELATIONS:" << ( *c ).second.size() << endmsg;
110 for ( const auto& k : c->second ) {
111 if ( k.second > 0 ) {
112 log << std::dec << k.first << ":" << k.second << " ";
113 if ( ++cnt == 10 ) {
114 cnt = 0;
115 log << endmsg;
116 }
117 }
118 }
119 if ( cnt > 0 ) log << endmsg;
120 }
121 auto l = m_links.find( i.first );
122 if ( l != m_links.end() ) {
123 int cnt = 0;
124 log << "== LINKS:" << l->second.size() << endmsg;
125 for ( const auto& k : l->second ) {
126 if ( k.second > 0 ) {
127 log << std::dec << k.first << ":" << k.second << " ";
128 if ( ++cnt == 10 ) {
129 cnt = 0;
130 log << endmsg;
131 }
132 }
133 }
134 if ( cnt > 0 ) log << endmsg;
135 }
136 }
137 always() << "== END =============== Access list content:" << m_info.size() << endmsg;
138 m_info.clear();
139 m_mgr = nullptr;
140 return StatusCode::SUCCESS;
141 }
142
144 StatusCode execute() override {
145 SmartDataPtr<DataObject> root( eventSvc(), "/Event" );
146 if ( root ) {
147 m_curr.clear();
148 auto& evnt = m_curr["/Event"];
149 evnt.count = explore( root->registry() );
150 evnt.clid = root->clID();
151 evnt.id = m_curr.size();
152 for ( const auto& i : m_curr ) m_info[i.first].count++;
153 for ( const auto& i : m_info ) {
154 const std::string& nam = i.first;
155 // const LeafInfo& leaf = (*i).second;
156 auto c = m_corr.find( nam );
157 if ( c == m_corr.end() ) {
158 m_corr[nam] = {};
159 c = m_corr.find( nam );
160 }
161 for ( const auto& l : m_curr ) {
162 const auto& id = l.second.id;
163 auto k = c->second.find( id );
164 if ( k == c->second.end() ) k = c->second.emplace( id, 0 ).first;
165 ++( k->second );
166 }
167
168 c = m_links.find( nam );
169 if ( c == m_links.end() ) c = m_links.emplace( nam, std::map<int, int>{} ).first;
170 if ( m_curr.find( nam ) == m_curr.end() ) continue;
171
173 if ( !obj ) continue;
174
175 LinkManager* m = obj->linkMgr();
176 for ( long l = 0; l < m->size(); ++l ) {
177 auto* lnk = m->link( l );
178 auto il = m_curr.find( lnk->path() );
179 // cout << "Link:" << lnk->path() << " " << (char*)(il != m_curr.end() ? "Found" : "Not there") << endl;
180 if ( il == m_curr.end() ) continue;
181 if ( !lnk->object() ) continue;
182 const auto& id = il->second.id;
183 auto k = c->second.find( id );
184 if ( k == c->second.end() ) k = c->second.emplace( id, 0 ).first;
185 ++( k->second );
186 }
187 }
188 }
189 return StatusCode::SUCCESS;
190 }
191};
192
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:302
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
Correlations m_links
size_t explore(IRegistry *pObj)
std::map< std::string, LeafInfo > SniffInfo
Correlations m_corr
StatusCode execute() override
Execute procedure.
StatusCode initialize() override
Initialize.
std::map< std::string, std::map< int, int > > Correlations
StatusCode finalize() override
Finalize.