All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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/MsgStream.h"
16 #include "GaudiKernel/SmartIF.h"
17 
18 using namespace std;
19 
28 class StoreSnifferAlg : public Algorithm {
29 public:
30 
32 
33  struct LeafInfo {
34  int count;
35  int id;
37  };
38  typedef map<string, LeafInfo> SniffInfo;
39  typedef map<string,map<int,int> > Correlations;
40 
41  SniffInfo m_info, m_curr;
43 
45  StoreSnifferAlg(const string& name, ISvcLocator* pSvc) : Algorithm(name, pSvc) {
46  }
48  virtual ~StoreSnifferAlg() {
49  }
50 
51  size_t explore(IRegistry* pObj) {
52  if ( 0 != pObj ) {
53  SmartIF<IDataManagerSvc> mgr(eventSvc());
54  if ( mgr ) {
55  typedef vector<IRegistry*> Leaves;
56  Leaves leaves;
57  StatusCode sc = m_mgr->objectLeaves(pObj, leaves);
58  if ( sc.isSuccess() ) {
59  for (Leaves::const_iterator i=leaves.begin(); i != leaves.end(); i++ ) {
60  IRegistry* pReg = *i;
61  const string& id = pReg->identifier();
63  if ( pReg->address() && pReg->object() ) {
64  SniffInfo::iterator j=m_info.find(id);
65  if ( j == m_info.end() ) {
66  m_info[id] = LeafInfo();
67  j = m_info.find(id);
68  (*j).second.count = 0;
69  (*j).second.id = m_info.size();
70  (*j).second.clid = pReg->object()->clID();
71  }
72  m_curr[id].id = m_info[id].id;
73  m_curr[id].count = explore(pReg);
74  }
75  }
76  return leaves.size();
77  }
78  }
79  }
80  return 0;
81  }
82 
84  virtual StatusCode initialize() {
85  m_info.clear();
86  m_mgr = eventSvc();
87  return StatusCode::SUCCESS;
88  }
89 
91  virtual StatusCode finalize() {
92  MsgStream log(msgSvc(), name());
93  log << MSG::ALWAYS << "== BEGIN ============= Access list content:" << m_info.size() << endmsg;
94  for(SniffInfo::const_iterator i=m_info.begin(); i!=m_info.end();++i) {
95  const LeafInfo& info = (*i).second;
96  log << "== ITEM == " << right << setw(4) << dec << info.id << " clid:"
97  << right << setw(8) << hex << info.clid << " Count:"
98  << right << setw(6) << dec << info.count << " "
99  << (*i).first+":"
100  << endmsg;
101  Correlations::const_iterator c=m_corr.find((*i).first);
102  if ( c != m_corr.end() ) {
103  int cnt = 0;
104  log << "== CORRELATIONS:" << (*c).second.size() << endmsg;
105  for(map<int,int>::const_iterator k=(*c).second.begin(); k!=(*c).second.end();++k) {
106  if ( (*k).second > 0 ) {
107  log << dec << (*k).first << ":" << (*k).second << " ";
108  if ( ++cnt == 10 ) {
109  cnt = 0;
110  log << endmsg;
111  }
112  }
113  }
114  if ( cnt > 0 ) log << endmsg;
115  }
116  Correlations::const_iterator l=m_links.find((*i).first);
117  if ( l != m_links.end() ) {
118  int cnt = 0;
119  log << "== LINKS:" << (*l).second.size() << endmsg;
120  for(map<int,int>::const_iterator k=(*l).second.begin(); k!=(*l).second.end();++k) {
121  if ( (*k).second > 0 ) {
122  log << dec << (*k).first << ":" << (*k).second << " ";
123  if ( ++cnt == 10 ) {
124  cnt = 0;
125  log << endmsg;
126  }
127  }
128  }
129  if ( cnt > 0 ) log << endmsg;
130  }
131  }
132  log << MSG::ALWAYS << "== END =============== Access list content:" << m_info.size() << endmsg;
133  m_info.clear();
134  m_mgr = 0;
135  return StatusCode::SUCCESS;
136  }
137 
139  virtual StatusCode execute() {
140  SmartDataPtr<DataObject> root(eventSvc(),"/Event");
141  if ( root ) {
142  m_curr.clear();
143  m_curr["/Event"].count = explore(root->registry());
144  m_curr["/Event"].clid = root->clID();
145  m_curr["/Event"].id = m_curr.size();
146  for(SniffInfo::const_iterator i=m_curr.begin(); i!=m_curr.end();++i) {
147  LeafInfo& li = m_info[(*i).first];
148  li.count++;
149  }
150  for(SniffInfo::const_iterator i=m_info.begin(); i!=m_info.end();++i) {
151  const string& nam = (*i).first;
152  // const LeafInfo& leaf = (*i).second;
153  Correlations::iterator c=m_corr.find(nam);
154  if ( c == m_corr.end() ) {
155  m_corr[nam] = map<int,int>();
156  c = m_corr.find(nam);
157  }
158  for(SniffInfo::const_iterator l=m_curr.begin(); l!=m_curr.end();++l) {
159  const LeafInfo& li = (*l).second;
160  map<int,int>::iterator k = (*c).second.find(li.id);
161  if ( k==(*c).second.end() ) (*c).second[li.id] = 0;
162  ++((*c).second[li.id]);
163  }
164 
165  c=m_links.find(nam);
166  if ( c == m_links.end() ) {
167  m_links[nam] = map<int,int>();
168  c = m_links.find(nam);
169  }
170  if ( m_curr.find(nam) != m_curr.end() ) {
171  SmartDataPtr<DataObject> obj(eventSvc(),nam);
172  if ( obj ) {
173  LinkManager* m = obj->linkMgr();
174  for(long l=0; l<m->size(); ++l) {
175  LinkManager::Link* lnk=m->link(l);
176  SniffInfo::const_iterator il=m_curr.find(lnk->path());
177  // cout << "Link:" << lnk->path() << " " << (char*)(il != m_curr.end() ? "Found" : "Not there") << endl;
178  if ( il != m_curr.end() ) {
179  if ( lnk->object() ) {
180  const LeafInfo& li = (*il).second;
181  map<int,int>::iterator k = (*c).second.find(li.id);
182  if ( k==(*c).second.end() ) (*c).second[li.id] = 0;
183  ++((*c).second[li.id]);
184  }
185  }
186  }
187  }
188  }
189  }
190  return StatusCode::SUCCESS;
191  }
192  return StatusCode::SUCCESS;
193  }
194 };
195 
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:26
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:62
tuple c
Definition: gaudirun.py:341
Small algorithm, which traverses the data store and prints a summary of the leafs accessed during the...
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:69
LinkManager * linkMgr() const
Retrieve Link manager.
Definition: DataObject.h:73
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
SmartIF< IDataManagerSvc > m_mgr
Correlations m_links
virtual StatusCode initialize()
Initialize.
virtual const CLID & clID() const
Retrieve reference to class definition structure.
Definition: DataObject.cpp:58
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
void clear(STATE_TYPE _i=std::ios_base::failbit)
Definition: MsgStream.h:222
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition: IRegistry.h:22
unsigned int CLID
Class ID definition.
Definition: ClassID.h:9
virtual IOpaqueAddress * address() const =0
Retrieve opaque storage address.
virtual DataObject * object() const =0
Retrieve object behind the link.
map< string, LeafInfo > SniffInfo
dictionary l
Definition: gaudirun.py:365
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:61
virtual ~StoreSnifferAlg()
Standard Destructor.
virtual StatusCode execute()
Execute procedure.
A small class used to access easily (and efficiently) data items residing in data stores...
Definition: SmartDataPtr.h:46
tuple root
Definition: IOTest.py:42
virtual StatusCode finalize()
Finalize.
size_t explore(IRegistry *pObj)
virtual const id_type & identifier() const =0
Full identifier (or key)
map< string, map< int, int > > Correlations
list i
Definition: ana.py:128
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