The Gaudi Framework
master (2e57474e)
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
#include <
GaudiKernel/Algorithm.h
>
19
#include <
GaudiKernel/DataObject.h
>
20
#include <
GaudiKernel/IDataManagerSvc.h
>
21
#include <
GaudiKernel/IDataProviderSvc.h
>
22
#include <
GaudiKernel/IRegistry.h
>
23
#include <
GaudiKernel/LinkManager.h
>
24
#include <
GaudiKernel/SmartDataPtr.h
>
25
#include <
GaudiKernel/SmartIF.h
>
26
#include <iomanip>
27
#include <map>
28
#include <string>
29
#include <vector>
30
39
class
StoreSnifferAlg
:
public
Algorithm
{
40
public
:
42
using
Algorithm::Algorithm
;
43
44
SmartIF<IDataManagerSvc>
m_mgr
;
45
46
struct
LeafInfo
final {
47
int
count
;
48
int
id
;
49
CLID
clid
;
50
};
51
typedef
std::map<std::string, LeafInfo>
SniffInfo
;
52
typedef
std::map<std::string, std::map<int, int>>
Correlations
;
53
54
SniffInfo
m_info
,
m_curr
;
55
Correlations
m_corr
,
m_links
;
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
87
StatusCode
initialize
()
override
{
88
m_info
.clear();
89
m_mgr
=
eventSvc
();
90
return
StatusCode::SUCCESS
;
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
168
SmartDataPtr<DataObject>
obj(
eventSvc
(), nam );
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
189
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:39
StoreSnifferAlg::m_mgr
SmartIF< IDataManagerSvc > m_mgr
Definition
StoreSnifferAlg.cpp:44
StoreSnifferAlg::Correlations
std::map< std::string, std::map< int, int > > Correlations
Definition
StoreSnifferAlg.cpp:52
StoreSnifferAlg::m_links
Correlations m_links
Definition
StoreSnifferAlg.cpp:55
StoreSnifferAlg::explore
size_t explore(IRegistry *pObj)
Definition
StoreSnifferAlg.cpp:57
StoreSnifferAlg::m_curr
SniffInfo m_curr
Definition
StoreSnifferAlg.cpp:54
StoreSnifferAlg::m_corr
Correlations m_corr
Definition
StoreSnifferAlg.cpp:55
StoreSnifferAlg::m_info
SniffInfo m_info
Definition
StoreSnifferAlg.cpp:54
StoreSnifferAlg::execute
StatusCode execute() override
Execute procedure.
Definition
StoreSnifferAlg.cpp:140
StoreSnifferAlg::initialize
StatusCode initialize() override
Initialize.
Definition
StoreSnifferAlg.cpp:87
StoreSnifferAlg::finalize
StatusCode finalize() override
Finalize.
Definition
StoreSnifferAlg.cpp:94
StoreSnifferAlg::SniffInfo
std::map< std::string, LeafInfo > SniffInfo
Definition
StoreSnifferAlg.cpp:51
IDataManagerSvc
Definition
IDataManagerSvc.h:47
StoreSnifferAlg::LeafInfo
Definition
StoreSnifferAlg.cpp:46
StoreSnifferAlg::LeafInfo::count
int count
Definition
StoreSnifferAlg.cpp:47
StoreSnifferAlg::LeafInfo::id
int id
Definition
StoreSnifferAlg.cpp:48
StoreSnifferAlg::LeafInfo::clid
CLID clid
Definition
StoreSnifferAlg.cpp:49
GaudiCommonSvc
src
DataSvc
StoreSnifferAlg.cpp
Generated on
for The Gaudi Framework by
1.17.0