StoreSnifferAlg.cpp
Go to the documentation of this file.
1 // ====================================================================
2 // StoreSnifferAlg.cpp
3 // --------------------------------------------------------------------
4 //
5 // Author : Markus Frank
6 //
7 // ====================================================================
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 
31 
32  struct LeafInfo final {
33  int count;
34  int id;
36  };
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 
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:74
T log(T...args)
Small algorithm, which traverses the data store and prints a summary of the leafs accessed during the...
T right(T...args)
STL namespace.
T end(T...args)
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:74
LinkManager * linkMgr() const
Retrieve Link manager.
Definition: DataObject.h:78
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
T setw(T...args)
SmartIF< IDataManagerSvc > m_mgr
Correlations m_links
virtual const CLID & clID() const
Retrieve reference to class definition structure.
Definition: DataObject.cpp:68
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
constexpr double m
Definition: SystemOfUnits.h:93
void clear(STATE_TYPE _i=std::ios_base::failbit)
Definition: MsgStream.h:222
StatusCode finalize() override
Finalize.
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition: IRegistry.h:22
StatusCode execute() override
Execute procedure.
unsigned int CLID
Class ID definition.
Definition: ClassID.h:8
T clear(T...args)
map< string, LeafInfo > SniffInfo
T count(T...args)
dictionary l
Definition: gaudirun.py:421
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 ...
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:78
T find(T...args)
T size(T...args)
T emplace(T...args)
A small class used to access easily (and efficiently) data items residing in data stores...
Definition: SmartDataPtr.h:46
T dec(T...args)
size_t explore(IRegistry *pObj)
map< string, map< int, int > > Correlations
StatusCode initialize() override
Initialize.
StoreSnifferAlg(const string &name, ISvcLocator *pSvc)
Standard algorithm constructor.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244