| The Gaudi Framework v32r1 (f65d50dc)

StoreSnifferAlg.cpp
Go to the documentation of this file.
1 // ====================================================================
2 // StoreSnifferAlg.cpp
3 // --------------------------------------------------------------------
4 //
5 // Author : Markus Frank
6 //
7 // ====================================================================
8 #include "GaudiKernel/Algorithm.h"
9 #include "GaudiKernel/DataObject.h"
10 #include "GaudiKernel/IDataManagerSvc.h"
11 #include "GaudiKernel/IDataProviderSvc.h"
12 #include "GaudiKernel/IRegistry.h"
13 #include "GaudiKernel/LinkManager.h"
14 #include "GaudiKernel/SmartDataPtr.h"
15 #include "GaudiKernel/SmartIF.h"
16
17 using namespace std;
18
27 class StoreSnifferAlg : public Algorithm {
28 public:
30 using Algorithm::Algorithm;
31
32 SmartIF<IDataManagerSvc> m_mgr;
33
34 struct LeafInfo final {
35 int count;
36 int id;
37 CLID clid;
38 };
39 typedef map<string, LeafInfo> SniffInfo;
40 typedef map<string, map<int, int>> Correlations;
41
42 SniffInfo m_info, m_curr;
43 Correlations m_corr, m_links;
44
45 size_t explore( IRegistry* pObj ) {
46 if ( pObj ) {
47 auto mgr = eventSvc().as<IDataManagerSvc>();
48 if ( mgr ) {
49 vector<IRegistry*> leaves;
50 StatusCode sc = m_mgr->objectLeaves( pObj, leaves );
51 if ( sc.isSuccess() ) {
52 for ( auto& pReg : leaves ) {
54 if ( !pReg->address() || !pReg->object() ) continue;
55 const string& id = pReg->identifier();
56 auto j = m_info.find( id );
57 if ( j == m_info.end() ) {
58 m_info[id] = LeafInfo();
59 j = m_info.find( id );
60 j->second.count = 0;
61 j->second.id = m_info.size();
62 j->second.clid = pReg->object()->clID();
63 }
64 m_curr[id].id = m_info[id].id;
65 m_curr[id].count = explore( pReg );
66 }
67 return leaves.size();
68 }
69 }
70 }
71 return 0;
72 }
73
75 StatusCode initialize() override {
76 m_info.clear();
77 m_mgr = eventSvc();
78 return StatusCode::SUCCESS;
79 }
80
82 StatusCode finalize() override {
83 auto& log = always();
84 log << "== BEGIN ============= Access list content:" << m_info.size() << endmsg;
85 for ( const auto& i : m_info ) {
86 const LeafInfo& info = i.second;
87 log << "== ITEM == " << right << setw( 4 ) << dec << info.id << " clid:" << right << setw( 8 ) << hex << info.clid
88 << " Count:" << right << setw( 6 ) << dec << info.count << " " << i.first + ":" << endmsg;
89 auto c = m_corr.find( i.first );
90 if ( c != m_corr.end() ) {
91 int cnt = 0;
92 log << "== CORRELATIONS:" << ( *c ).second.size() << endmsg;
93 for ( const auto& k : c->second ) {
94 if ( k.second > 0 ) {
95 log << dec << k.first << ":" << k.second << " ";
96 if ( ++cnt == 10 ) {
97 cnt = 0;
98 log << endmsg;
99 }
100 }
101 }
102 if ( cnt > 0 ) log << endmsg;
103 }
104 auto l = m_links.find( i.first );
105 if ( l != m_links.end() ) {
106 int cnt = 0;
107 log << "== LINKS:" << l->second.size() << endmsg;
108 for ( const auto& k : l->second ) {
109 if ( k.second > 0 ) {
110 log << dec << k.first << ":" << k.second << " ";
111 if ( ++cnt == 10 ) {
112 cnt = 0;
113 log << endmsg;
114 }
115 }
116 }
117 if ( cnt > 0 ) log << endmsg;
118 }
119 }
120 always() << "== END =============== Access list content:" << m_info.size() << endmsg;
121 m_info.clear();
122 m_mgr = nullptr;
123 return StatusCode::SUCCESS;
124 }
125
127 StatusCode execute() override {
128 SmartDataPtr<DataObject> root( eventSvc(), "/Event" );
129 if ( root ) {
130 m_curr.clear();
131 auto& evnt = m_curr["/Event"];
132 evnt.count = explore( root->registry() );
133 evnt.clid = root->clID();
134 evnt.id = m_curr.size();
135 for ( const auto& i : m_curr ) m_info[i.first].count++;
136 for ( const auto& i : m_info ) {
137 const string& nam = i.first;
138 // const LeafInfo& leaf = (*i).second;
139 auto c = m_corr.find( nam );
140 if ( c == m_corr.end() ) {
141 m_corr[nam] = {};
142 c = m_corr.find( nam );
143 }
144 for ( const auto& l : m_curr ) {
145 const auto& id = l.second.id;
146 auto k = c->second.find( id );
147 if ( k == c->second.end() ) k = c->second.emplace( id, 0 ).first;
148 ++( k->second );
149 }
150
151 c = m_links.find( nam );
152 if ( c == m_links.end() ) c = m_links.emplace( nam, std::map<int, int>{} ).first;
153 if ( m_curr.find( nam ) == m_curr.end() ) continue;
154
155 SmartDataPtr<DataObject> obj( eventSvc(), nam );
156 if ( !obj ) continue;
157
158 LinkManager* m = obj->linkMgr();
159 for ( long l = 0; l < m->size(); ++l ) {
160 auto* lnk = m->link( l );
161 auto il = m_curr.find( lnk->path() );
162 // cout << "Link:" << lnk->path() << " " << (char*)(il != m_curr.end() ? "Found" : "Not there") << endl;
163 if ( il == m_curr.end() ) continue;
164 if ( !lnk->object() ) continue;
165 const auto& id = il->second.id;
166 auto k = c->second.find( id );
167 if ( k == c->second.end() ) k = c->second.emplace( id, 0 ).first;
168 ++( k->second );
169 }
170 }
171 }
172 return StatusCode::SUCCESS;
173 }
174 };
175
176 DECLARE_COMPONENT( StoreSnifferAlg )
Algorithm.h
SmartIF< IDataManagerSvc >
IDataManagerSvc::objectLeaves
virtual StatusCode objectLeaves(const DataObject *pObject, std::vector< IRegistry * > &refLeaves)=0
Explore the object store: retrieve all leaves attached to the object The object is identified by its ...
gaudirun.c
c
Definition: gaudirun.py:487
LinkManager.h
IDataManagerSvc
Definition: IDataManagerSvc.h:45
DataObject::linkMgr
LinkManager * linkMgr() const
Retrieve Link manager.
Definition: DataObject.h:74
std::log
T log(T... args)
Gaudi::Algorithm::Algorithm
Algorithm(const std::string &name, ISvcLocator *svcloc, const std::string &version=PACKAGE_VERSION)
Constructor.
Definition: Algorithm.cpp:48
StoreSnifferAlg
Small algorithm, which traverses the data store and prints a summary of the leafs accessed during the...
Definition: StoreSnifferAlg.cpp:27
std::right
T right(T... args)
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
std
STL namespace.
StoreSnifferAlg::LeafInfo
Definition: StoreSnifferAlg.cpp:34
std::map::end
T end(T... args)
std::map< string, LeafInfo >
std::setw
T setw(T... args)
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
StoreSnifferAlg::m_mgr
SmartIF< IDataManagerSvc > m_mgr
Definition: StoreSnifferAlg.cpp:32
StoreSnifferAlg::m_links
Correlations m_links
Definition: StoreSnifferAlg.cpp:43
StoreSnifferAlg::LeafInfo::id
int id
Definition: StoreSnifferAlg.cpp:36
IDataManagerSvc.h
IDataProviderSvc.h
StoreSnifferAlg::Correlations
map< string, map< int, int > > Correlations
Definition: StoreSnifferAlg.cpp:40
SmartDataPtr.h
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
Gaudi::Units::m
constexpr double m
Definition: SystemOfUnits.h:92
MsgStream::clear
void clear(STATE_TYPE _i=std::ios_base::failbit)
Definition: MsgStream.h:171
SmartIF.h
StoreSnifferAlg::finalize
StatusCode finalize() override
Finalize.
Definition: StoreSnifferAlg.cpp:82
IRegistry.h
IRegistry
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition: IRegistry.h:22
StoreSnifferAlg::execute
StatusCode execute() override
Execute procedure.
Definition: StoreSnifferAlg.cpp:127
CLID
unsigned int CLID
Class ID definition.
Definition: ClassID.h:8
std::map::clear
T clear(T... args)
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:267
StoreSnifferAlg::SniffInfo
map< string, LeafInfo > SniffInfo
Definition: StoreSnifferAlg.cpp:39
std::map::count
T count(T... args)
gaudirun.l
dictionary l
Definition: gaudirun.py:521
Algorithm
Alias for backward compatibility.
Definition: Algorithm.h:56
std::map::find
T find(T... args)
std::map::size
T size(T... args)
std::vector< IRegistry * >
std::map::emplace
T emplace(T... args)
SmartDataPtr
A small class used to access easily (and efficiently) data items residing in data stores.
Definition: SmartDataPtr.h:47
std::dec
T dec(T... args)
gaudiComponentHelp.root
root
Definition: gaudiComponentHelp.py:27
StoreSnifferAlg::LeafInfo::count
int count
Definition: StoreSnifferAlg.cpp:35
StoreSnifferAlg::explore
size_t explore(IRegistry *pObj)
Definition: StoreSnifferAlg.cpp:45
StoreSnifferAlg::m_info
SniffInfo m_info
Definition: StoreSnifferAlg.cpp:42
StoreSnifferAlg::initialize
StatusCode initialize() override
Initialize.
Definition: StoreSnifferAlg.cpp:75
LinkManager
A LinkManager is the object aggregated into a DataObject, which is responsible for the handling of no...
Definition: LinkManager.h:21
StoreSnifferAlg::LeafInfo::clid
CLID clid
Definition: StoreSnifferAlg.cpp:37
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
DataObject.h