| The Gaudi Framework v30r0 (c919700c)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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 {
29 public:
30 SmartIF<IDataManagerSvc> m_mgr;
31
32 struct LeafInfo final {
33 int count;
34 int id;
35 CLID clid;
36 };
37 typedef map<string, LeafInfo> SniffInfo;
38 typedef map<string, map<int, int>> Correlations;
39
40 SniffInfo m_info, m_curr;
41 Correlations m_corr, m_links;
42
44 StoreSnifferAlg( const string& name, ISvcLocator* pSvc ) : Algorithm( name, pSvc ) {}
46 ~StoreSnifferAlg() override = default;
47
48 size_t explore( IRegistry* pObj )
49 {
50 if ( pObj ) {
51 auto mgr = eventSvc().as<IDataManagerSvc>();
52 if ( mgr ) {
53 vector<IRegistry*> leaves;
54 StatusCode sc = m_mgr->objectLeaves( pObj, leaves );
55 if ( sc.isSuccess() ) {
56 for ( auto& pReg : leaves ) {
58 if ( !pReg->address() || !pReg->object() ) continue;
59 const string& id = pReg->identifier();
60 auto j = m_info.find( id );
61 if ( j == m_info.end() ) {
62 m_info[id] = LeafInfo();
63 j = m_info.find( id );
64 j->second.count = 0;
65 j->second.id = m_info.size();
66 j->second.clid = pReg->object()->clID();
67 }
68 m_curr[id].id = m_info[id].id;
69 m_curr[id].count = explore( pReg );
70 }
71 return leaves.size();
72 }
73 }
74 }
75 return 0;
76 }
77
79 StatusCode initialize() override
80 {
81 m_info.clear();
82 m_mgr = eventSvc();
83 return StatusCode::SUCCESS;
84 }
85
87 StatusCode finalize() override
88 {
89 auto& log = always();
90 log << "== BEGIN ============= Access list content:" << m_info.size() << endmsg;
91 for ( const auto& i : m_info ) {
92 const LeafInfo& info = i.second;
93 log << "== ITEM == " << right << setw( 4 ) << dec << info.id << " clid:" << right << setw( 8 ) << hex << info.clid
94 << " Count:" << right << setw( 6 ) << dec << info.count << " " << i.first + ":" << endmsg;
95 auto c = m_corr.find( i.first );
96 if ( c != m_corr.end() ) {
97 int cnt = 0;
98 log << "== CORRELATIONS:" << ( *c ).second.size() << endmsg;
99 for ( const auto& k : c->second ) {
100 if ( k.second > 0 ) {
101 log << dec << k.first << ":" << k.second << " ";
102 if ( ++cnt == 10 ) {
103 cnt = 0;
104 log << endmsg;
105 }
106 }
107 }
108 if ( cnt > 0 ) log << endmsg;
109 }
110 auto l = m_links.find( i.first );
111 if ( l != m_links.end() ) {
112 int cnt = 0;
113 log << "== LINKS:" << l->second.size() << endmsg;
114 for ( const auto& k : l->second ) {
115 if ( k.second > 0 ) {
116 log << dec << k.first << ":" << k.second << " ";
117 if ( ++cnt == 10 ) {
118 cnt = 0;
119 log << endmsg;
120 }
121 }
122 }
123 if ( cnt > 0 ) log << endmsg;
124 }
125 }
126 always() << "== END =============== Access list content:" << m_info.size() << endmsg;
127 m_info.clear();
128 m_mgr = nullptr;
129 return StatusCode::SUCCESS;
130 }
131
133 StatusCode execute() override
134 {
135 SmartDataPtr<DataObject> root( eventSvc(), "/Event" );
136 if ( root ) {
137 m_curr.clear();
138 auto& evnt = m_curr["/Event"];
139 evnt.count = explore( root->registry() );
140 evnt.clid = root->clID();
141 evnt.id = m_curr.size();
142 for ( const auto& i : m_curr ) m_info[i.first].count++;
143 for ( const auto& i : m_info ) {
144 const string& nam = i.first;
145 // const LeafInfo& leaf = (*i).second;
146 auto c = m_corr.find( nam );
147 if ( c == m_corr.end() ) {
148 m_corr[nam] = {};
149 c = m_corr.find( nam );
150 }
151 for ( const auto& l : m_curr ) {
152 const auto& id = l.second.id;
153 auto k = c->second.find( id );
154 if ( k == c->second.end() ) k = c->second.emplace( id, 0 ).first;
155 ++( k->second );
156 }
157
158 c = m_links.find( nam );
159 if ( c == m_links.end() ) c = m_links.emplace( nam, std::map<int, int>{} ).first;
160 if ( m_curr.find( nam ) == m_curr.end() ) continue;
161
162 SmartDataPtr<DataObject> obj( eventSvc(), nam );
163 if ( !obj ) continue;
164
165 LinkManager* m = obj->linkMgr();
166 for ( long l = 0; l < m->size(); ++l ) {
167 auto* lnk = m->link( l );
168 auto il = m_curr.find( lnk->path() );
169 // cout << "Link:" << lnk->path() << " " << (char*)(il != m_curr.end() ? "Found" : "Not there") << endl;
170 if ( il == m_curr.end() ) continue;
171 if ( !lnk->object() ) continue;
172 const auto& id = il->second.id;
173 auto k = c->second.find( id );
174 if ( k == c->second.end() ) k = c->second.emplace( id, 0 ).first;
175 ++( k->second );
176 }
177 }
178 }
179 return StatusCode::SUCCESS;
180 }
181 };
182
183 DECLARE_COMPONENT( StoreSnifferAlg )
StatusCode::SUCCESS
Definition: StatusCode.h:29
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 ...
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
gaudirun.c
c
Definition: gaudirun.py:407
LinkManager.h
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:32
IDataManagerSvc
Definition: IDataManagerSvc.h:46
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:50
std::log
T log(T...args)
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)
std
STL namespace.
StoreSnifferAlg::LeafInfo
Definition: StoreSnifferAlg.cpp:32
std::map::end
T end(T...args)
std::map< string, LeafInfo >
DataObject::registry
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:73
DataObject::linkMgr
LinkManager * linkMgr() const
Retrieve Link manager.
Definition: DataObject.h:75
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:33
std::setw
T setw(T...args)
StoreSnifferAlg::m_mgr
SmartIF< IDataManagerSvc > m_mgr
Definition: StoreSnifferAlg.cpp:30
StoreSnifferAlg::m_links
Correlations m_links
Definition: StoreSnifferAlg.cpp:41
StoreSnifferAlg::LeafInfo::id
int id
Definition: StoreSnifferAlg.cpp:34
IDataManagerSvc.h
IDataProviderSvc.h
StoreSnifferAlg::Correlations
map< string, map< int, int > > Correlations
Definition: StoreSnifferAlg.cpp:38
SmartDataPtr.h
DataObject::clID
virtual const CLID & clID() const
Retrieve reference to class definition structure.
Definition: DataObject.cpp:62
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
Gaudi::Units::m
constexpr double m
Definition: SystemOfUnits.h:94
MsgStream::clear
void clear(STATE_TYPE _i=std::ios_base::failbit)
Definition: MsgStream.h:187
SmartIF.h
LinkManager::link
Link * link(long id)
Retrieve symbolic link identified by ID.
Definition: LinkManager.cpp:31
StoreSnifferAlg::finalize
StatusCode finalize() override
Finalize.
Definition: StoreSnifferAlg.cpp:87
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:133
CLID
unsigned int CLID
Class ID definition.
Definition: ClassID.h:8
std::map::clear
T clear(T...args)
StoreSnifferAlg::SniffInfo
map< string, LeafInfo > SniffInfo
Definition: StoreSnifferAlg.cpp:37
std::map::count
T count(T...args)
gaudirun.l
dictionary l
Definition: gaudirun.py:440
Algorithm
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:79
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:18
StoreSnifferAlg::LeafInfo::count
int count
Definition: StoreSnifferAlg.cpp:33
StoreSnifferAlg::explore
size_t explore(IRegistry *pObj)
Definition: StoreSnifferAlg.cpp:48
StoreSnifferAlg::m_info
SniffInfo m_info
Definition: StoreSnifferAlg.cpp:40
StoreSnifferAlg::initialize
StatusCode initialize() override
Initialize.
Definition: StoreSnifferAlg.cpp:79
LinkManager
A LinkManager is the object aggregated into a DataObject, which is responsible for the handling of no...
Definition: LinkManager.h:21
StoreSnifferAlg::StoreSnifferAlg
StoreSnifferAlg(const string &name, ISvcLocator *pSvc)
Standard algorithm constructor.
Definition: StoreSnifferAlg.cpp:44
StoreSnifferAlg::LeafInfo::clid
CLID clid
Definition: StoreSnifferAlg.cpp:35
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
DataObject.h
LinkManager::size
long size() const
Retrieve number of link present.
Definition: LinkManager.h:105