The Gaudi Framework  v30r0 (c919700c)
StoreSnifferAlg.cpp
Go to the documentation of this file.
1 // ====================================================================
2 // StoreSnifferAlg.cpp
3 // --------------------------------------------------------------------
4 //
5 // Author : Markus Frank
6 //
7 // ====================================================================
12 #include "GaudiKernel/IRegistry.h"
15 #include "GaudiKernel/SmartIF.h"
16 
17 using namespace std;
18 
27 class StoreSnifferAlg : public Algorithm
28 {
29 public:
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 ) {}
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 
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 
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 ...
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:50
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:73
LinkManager * linkMgr() const
Retrieve Link manager.
Definition: DataObject.h:75
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:33
T setw(T...args)
SmartIF< IDataManagerSvc > m_mgr
Correlations m_links
map< string, map< int, int > > Correlations
virtual const CLID & clID() const
Retrieve reference to class definition structure.
Definition: DataObject.cpp:62
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
constexpr double m
Definition: SystemOfUnits.h:94
void clear(STATE_TYPE _i=std::ios_base::failbit)
Definition: MsgStream.h:187
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:440
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:79
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:47
T dec(T...args)
size_t explore(IRegistry *pObj)
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:209