The Gaudi Framework
master (68c8ac5a)
Toggle main menu visibility
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
20
#include <
GaudiKernel/Algorithm.h
>
21
#include <
GaudiKernel/DataObject.h
>
22
#include <
GaudiKernel/IDataManagerSvc.h
>
23
#include <
GaudiKernel/IDataProviderSvc.h
>
24
#include <
GaudiKernel/IRegistry.h
>
25
#include <
GaudiKernel/LinkManager.h
>
26
#include <
GaudiKernel/SmartDataPtr.h
>
27
#include <
GaudiKernel/SmartIF.h
>
28
29
// STL includes
30
#include <iomanip>
31
#include <map>
32
#include <string>
33
#include <vector>
34
43
class
StoreSnifferAlg
:
public
Algorithm
{
44
public
:
46
using
Algorithm::Algorithm
;
47
48
SmartIF<IDataManagerSvc>
m_mgr
;
49
50
struct
LeafInfo
final {
51
int
count
;
52
int
id
;
53
CLID
clid
;
54
};
55
using
SniffInfo
= std::map<std::string, LeafInfo>;
56
using
Correlations
= std::map<std::string, std::map<int, int>>;
57
58
SniffInfo
m_info
,
m_curr
;
59
Correlations
m_corr
,
m_links
;
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
91
StatusCode
initialize
()
override
{
92
m_info
.clear();
93
m_mgr
=
eventSvc
();
94
return
StatusCode::SUCCESS
;
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
172
SmartDataPtr<DataObject>
obj(
eventSvc
(), nam );
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
193
DECLARE_COMPONENT
(
StoreSnifferAlg
)
CLID
unsigned int CLID
Class ID definition.
Definition
ClassID.h:16
DataObject.h
Algorithm.h
IDataManagerSvc.h
IDataProviderSvc.h
IRegistry.h
LinkManager.h
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition
MsgStream.h:198
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition
PluginServiceV1.h:45
SmartDataPtr.h
SmartIF.h
CommonMessagingBase::info
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Definition
CommonMessaging.h:115
CommonMessagingBase::always
MsgStream & always() const
shortcut for the method msgStream(MSG::ALWAYS)
Definition
CommonMessaging.h:100
Gaudi::Algorithm::eventSvc
SmartIF< IDataProviderSvc > & eventSvc() const
The standard event data service.
Definition
Algorithm.cpp:551
Gaudi::Algorithm::Algorithm
Algorithm(std::string name, ISvcLocator *svcloc, std::string version=PACKAGE_VERSION)
Constructor.
Definition
Algorithm.h:98
IRegistry
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition
IRegistry.h:29
LinkManager
A LinkManager is the object aggregated into a DataObject, which is responsible for the handling of no...
Definition
LinkManager.h:28
SmartDataPtr
A small class used to access easily (and efficiently) data items residing in data stores.
Definition
SmartDataPtr.h:44
SmartIF
Small smart pointer class with automatic reference counting for IInterface.
Definition
SmartIF.h:28
SmartIF::as
SmartIF< IFace > as() const
return a new SmartIF instance to another interface
Definition
SmartIF.h:110
StatusCode
This class is used for returning status codes from appropriate routines.
Definition
StatusCode.h:64
StatusCode::isSuccess
bool isSuccess() const
Definition
StatusCode.h:302
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition
StatusCode.h:99
StoreSnifferAlg
Small algorithm, which traverses the data store and prints a summary of the leafs accessed during the...
Definition
StoreSnifferAlg.cpp:43
StoreSnifferAlg::m_mgr
SmartIF< IDataManagerSvc > m_mgr
Definition
StoreSnifferAlg.cpp:48
StoreSnifferAlg::m_links
Correlations m_links
Definition
StoreSnifferAlg.cpp:59
StoreSnifferAlg::explore
size_t explore(IRegistry *pObj)
Definition
StoreSnifferAlg.cpp:61
StoreSnifferAlg::SniffInfo
std::map< std::string, LeafInfo > SniffInfo
Definition
StoreSnifferAlg.cpp:55
StoreSnifferAlg::m_curr
SniffInfo m_curr
Definition
StoreSnifferAlg.cpp:58
StoreSnifferAlg::m_corr
Correlations m_corr
Definition
StoreSnifferAlg.cpp:59
StoreSnifferAlg::m_info
SniffInfo m_info
Definition
StoreSnifferAlg.cpp:58
StoreSnifferAlg::execute
StatusCode execute() override
Execute procedure.
Definition
StoreSnifferAlg.cpp:144
StoreSnifferAlg::initialize
StatusCode initialize() override
Initialize.
Definition
StoreSnifferAlg.cpp:91
StoreSnifferAlg::Correlations
std::map< std::string, std::map< int, int > > Correlations
Definition
StoreSnifferAlg.cpp:56
StoreSnifferAlg::finalize
StatusCode finalize() override
Finalize.
Definition
StoreSnifferAlg.cpp:98
IDataManagerSvc
Definition
IDataManagerSvc.h:47
StoreSnifferAlg::LeafInfo
Definition
StoreSnifferAlg.cpp:50
StoreSnifferAlg::LeafInfo::count
int count
Definition
StoreSnifferAlg.cpp:51
StoreSnifferAlg::LeafInfo::id
int id
Definition
StoreSnifferAlg.cpp:52
StoreSnifferAlg::LeafInfo::clid
CLID clid
Definition
StoreSnifferAlg.cpp:53
GaudiCommonSvc
src
DataSvc
StoreSnifferAlg.cpp
Generated on
for The Gaudi Framework by
1.17.0