| The Gaudi Framework v27r1

- 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/DataObject.h"
9 #include "GaudiKernel/LinkManager.h"
10 #include "GaudiKernel/IDataProviderSvc.h"
11 #include "GaudiKernel/IDataManagerSvc.h"
12 #include "GaudiKernel/SmartDataPtr.h"
13 #include "GaudiKernel/Algorithm.h"
14 #include "GaudiKernel/IRegistry.h"
15 #include "GaudiKernel/SmartIF.h"
16
17 using namespace std;
18
27 class StoreSnifferAlg : public Algorithm {
28 public:
29
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)
45 { }
47 ~StoreSnifferAlg() override = default;
48
49 size_t explore(IRegistry* pObj) {
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 m_info.clear();
81 m_mgr = eventSvc();
82 return StatusCode::SUCCESS;
83 }
84
86 StatusCode finalize() override {
87 auto& log = always();
88 log << "== BEGIN ============= Access list content:" << m_info.size() << endmsg;
89 for(const auto& i : m_info) {
90 const LeafInfo& info = i.second;
91 log << "== ITEM == " << right << setw(4) << dec << info.id << " clid:"
92 << right << setw(8) << hex << info.clid << " Count:"
93 << right << setw(6) << dec << info.count << " "
94 << i.first+":"
95 << endmsg;
96 auto c=m_corr.find(i.first);
97 if ( c != m_corr.end() ) {
98 int cnt = 0;
99 log << "== CORRELATIONS:" << (*c).second.size() << endmsg;
100 for(const auto& k : c->second) {
101 if ( k.second > 0 ) {
102 log << dec << k.first << ":" << k.second << " ";
103 if ( ++cnt == 10 ) {
104 cnt = 0;
105 log << endmsg;
106 }
107 }
108 }
109 if ( cnt > 0 ) log << endmsg;
110 }
111 auto l=m_links.find(i.first);
112 if ( l != m_links.end() ) {
113 int cnt = 0;
114 log << "== LINKS:" << l->second.size() << endmsg;
115 for(const auto& k : l->second) {
116 if ( k.second > 0 ) {
117 log << dec << k.first << ":" << k.second << " ";
118 if ( ++cnt == 10 ) {
119 cnt = 0;
120 log << endmsg;
121 }
122 }
123 }
124 if ( cnt > 0 ) log << endmsg;
125 }
126 }
127 always() << "== END =============== Access list content:" << m_info.size() << endmsg;
128 m_info.clear();
129 m_mgr = nullptr;
130 return StatusCode::SUCCESS;
131 }
132
134 StatusCode execute() override {
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)
Algorithm.h
SmartIF< IDataManagerSvc >
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
LinkManager.h
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
std::log
T log(T...args)
gaudirun.c
tuple c
Definition: gaudirun.py:391
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)
merge_files.sc
int sc
Definition: merge_files.py:167
std::map< string, LeafInfo >
DataObject::registry
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:74
DataObject::linkMgr
LinkManager * linkMgr() const
Retrieve Link manager.
Definition: DataObject.h:78
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
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
SmartDataPtr.h
DataObject::clID
virtual const CLID & clID() const
Retrieve reference to class definition structure.
Definition: DataObject.cpp:68
StatusCode::SUCCESS
Definition: StatusCode.h:30
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:93
MsgStream::clear
void clear(STATE_TYPE _i=std::ios_base::failbit)
Definition: MsgStream.h:222
SmartIF.h
LinkManager::link
Link * link(long id)
Retrieve symbolic link identified by ID.
Definition: LinkManager.cpp:33
StoreSnifferAlg::finalize
StatusCode finalize() override
Finalize.
Definition: StoreSnifferAlg.cpp:86
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:134
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:421
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 ...
Algorithm
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:74
std::map::find
T find(T...args)
std::map::size
T size(T...args)
std::vector< IRegistry * >
IDataManagerSvc
Definition: IDataManagerSvc.h:45
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:46
std::dec
T dec(T...args)
IOTest.root
tuple root
Definition: IOTest.py:42
StoreSnifferAlg::LeafInfo::count
int count
Definition: StoreSnifferAlg.cpp:33
StoreSnifferAlg::explore
size_t explore(IRegistry *pObj)
Definition: StoreSnifferAlg.cpp:49
StoreSnifferAlg::m_info
SniffInfo m_info
Definition: StoreSnifferAlg.cpp:40
StoreSnifferAlg::Correlations
map< string, map< int, int > > Correlations
Definition: StoreSnifferAlg.cpp:38
StoreSnifferAlg::initialize
StatusCode initialize() override
Initialize.
Definition: StoreSnifferAlg.cpp:79
ana.i
list i
Definition: ana.py:128
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:244
DataObject.h
LinkManager::size
long size() const
Retrieve number of link present.
Definition: LinkManager.h:112