The Gaudi Framework  master (b9786168)
Loading...
Searching...
No Matches
StoreSnifferAlg.cpp
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2024 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
27using namespace std;
28
37class StoreSnifferAlg : public Algorithm {
38public:
41
43
44 struct LeafInfo final {
45 int count;
46 int id;
48 };
49 typedef map<string, LeafInfo> SniffInfo;
50 typedef map<string, map<int, int>> Correlations;
51
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
86 m_info.clear();
87 m_mgr = eventSvc();
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
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
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
map< string, LeafInfo > SniffInfo
Correlations m_links
size_t explore(IRegistry *pObj)
Correlations m_corr
StatusCode execute() override
Execute procedure.
StatusCode initialize() override
Initialize.
StatusCode finalize() override
Finalize.
map< string, map< int, int > > Correlations
STL namespace.