Gaudi Framework, version v24r2

Home   Generated: Wed Dec 4 2013
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
StoreSnifferAlg.cpp
Go to the documentation of this file.
1 // $Header: $
2 // ====================================================================
3 // StoreSnifferAlg.cpp
4 // --------------------------------------------------------------------
5 //
6 // Author : Markus Frank
7 //
8 // ====================================================================
14 #include "GaudiKernel/AlgFactory.h"
15 #include "GaudiKernel/Algorithm.h"
16 #include "GaudiKernel/IRegistry.h"
17 #include "GaudiKernel/MsgStream.h"
18 #include "GaudiKernel/SmartIF.h"
19 
20 using namespace std;
21 
30 class StoreSnifferAlg : public Algorithm {
31 public:
32 
34 
35  struct LeafInfo {
36  int count;
37  int id;
39  };
42 
43  SniffInfo m_info, m_curr;
45 
47  StoreSnifferAlg(const string& name, ISvcLocator* pSvc) : Algorithm(name, pSvc) {
48  }
50  virtual ~StoreSnifferAlg() {
51  }
52 
53  size_t explore(IRegistry* pObj) {
54  if ( 0 != pObj ) {
55  SmartIF<IDataManagerSvc> mgr(eventSvc());
56  if ( mgr ) {
57  typedef vector<IRegistry*> Leaves;
58  Leaves leaves;
59  StatusCode sc = m_mgr->objectLeaves(pObj, leaves);
60  if ( sc.isSuccess() ) {
61  for (Leaves::const_iterator i=leaves.begin(); i != leaves.end(); i++ ) {
62  IRegistry* pReg = *i;
63  const string& id = pReg->identifier();
65  if ( pReg->address() && pReg->object() ) {
66  SniffInfo::iterator j=m_info.find(id);
67  if ( j == m_info.end() ) {
68  m_info[id] = LeafInfo();
69  j = m_info.find(id);
70  (*j).second.count = 0;
71  (*j).second.id = m_info.size();
72  (*j).second.clid = pReg->object()->clID();
73  }
74  m_curr[id].id = m_info[id].id;
75  m_curr[id].count = explore(pReg);
76  }
77  }
78  return leaves.size();
79  }
80  }
81  }
82  return 0;
83  }
84 
86  virtual StatusCode initialize() {
87  m_info.clear();
88  m_mgr = eventSvc();
89  return StatusCode::SUCCESS;
90  }
91 
93  virtual StatusCode finalize() {
94  MsgStream log(msgSvc(), name());
95  log << MSG::ALWAYS << "== BEGIN ============= Access list content:" << m_info.size() << endmsg;
96  for(SniffInfo::const_iterator i=m_info.begin(); i!=m_info.end();++i) {
97  const LeafInfo& info = (*i).second;
98  log << "== ITEM == " << right << setw(4) << dec << info.id << " clid:"
99  << right << setw(8) << hex << info.clid << " Count:"
100  << right << setw(6) << dec << info.count << " "
101  << (*i).first+":"
102  << endmsg;
103  Correlations::const_iterator c=m_corr.find((*i).first);
104  if ( c != m_corr.end() ) {
105  int cnt = 0;
106  log << "== CORRELATIONS:" << (*c).second.size() << endmsg;
107  for(map<int,int>::const_iterator k=(*c).second.begin(); k!=(*c).second.end();++k) {
108  if ( (*k).second > 0 ) {
109  log << dec << (*k).first << ":" << (*k).second << " ";
110  if ( ++cnt == 10 ) {
111  cnt = 0;
112  log << endmsg;
113  }
114  }
115  }
116  if ( cnt > 0 ) log << endmsg;
117  }
118  Correlations::const_iterator l=m_links.find((*i).first);
119  if ( l != m_links.end() ) {
120  int cnt = 0;
121  log << "== LINKS:" << (*l).second.size() << endmsg;
122  for(map<int,int>::const_iterator k=(*l).second.begin(); k!=(*l).second.end();++k) {
123  if ( (*k).second > 0 ) {
124  log << dec << (*k).first << ":" << (*k).second << " ";
125  if ( ++cnt == 10 ) {
126  cnt = 0;
127  log << endmsg;
128  }
129  }
130  }
131  if ( cnt > 0 ) log << endmsg;
132  }
133  }
134  log << MSG::ALWAYS << "== END =============== Access list content:" << m_info.size() << endmsg;
135  m_info.clear();
136  m_mgr = 0;
137  return StatusCode::SUCCESS;
138  }
139 
141  virtual StatusCode execute() {
142  SmartDataPtr<DataObject> root(eventSvc(),"/Event");
143  if ( root ) {
144  m_curr.clear();
145  m_curr["/Event"].count = explore(root->registry());
146  m_curr["/Event"].clid = root->clID();
147  m_curr["/Event"].id = m_curr.size();
148  for(SniffInfo::const_iterator i=m_curr.begin(); i!=m_curr.end();++i) {
149  LeafInfo& li = m_info[(*i).first];
150  li.count++;
151  }
152  for(SniffInfo::const_iterator i=m_info.begin(); i!=m_info.end();++i) {
153  const string& nam = (*i).first;
154  // const LeafInfo& leaf = (*i).second;
155  Correlations::iterator c=m_corr.find(nam);
156  if ( c == m_corr.end() ) {
157  m_corr[nam] = map<int,int>();
158  c = m_corr.find(nam);
159  }
160  for(SniffInfo::const_iterator l=m_curr.begin(); l!=m_curr.end();++l) {
161  const LeafInfo& li = (*l).second;
162  map<int,int>::iterator k = (*c).second.find(li.id);
163  if ( k==(*c).second.end() ) (*c).second[li.id] = 0;
164  ++((*c).second[li.id]);
165  }
166 
167  c=m_links.find(nam);
168  if ( c == m_links.end() ) {
169  m_links[nam] = map<int,int>();
170  c = m_links.find(nam);
171  }
172  if ( m_curr.find(nam) != m_curr.end() ) {
173  SmartDataPtr<DataObject> obj(eventSvc(),nam);
174  if ( obj ) {
175  LinkManager* m = obj->linkMgr();
176  for(long l=0; l<m->size(); ++l) {
177  LinkManager::Link* lnk=m->link(l);
178  SniffInfo::const_iterator il=m_curr.find(lnk->path());
179  // cout << "Link:" << lnk->path() << " " << (char*)(il != m_curr.end() ? "Found" : "Not there") << endl;
180  if ( il != m_curr.end() ) {
181  if ( lnk->object() ) {
182  const LeafInfo& li = (*il).second;
183  map<int,int>::iterator k = (*c).second.find(li.id);
184  if ( k==(*c).second.end() ) (*c).second[li.id] = 0;
185  ++((*c).second[li.id]);
186  }
187  }
188  }
189  }
190  }
191  }
192  return StatusCode::SUCCESS;
193  }
194  return StatusCode::SUCCESS;
195  }
196 };
197 

Generated at Wed Dec 4 2013 14:33:07 for Gaudi Framework, version v24r2 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004