The Gaudi Framework  master (37c0b60a)
StoreSnifferAlg.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 // ====================================================================
12 // StoreSnifferAlg.cpp
13 // --------------------------------------------------------------------
14 //
15 // Author : Markus Frank
16 //
17 // ====================================================================
18 #include <GaudiKernel/Algorithm.h>
19 #include <GaudiKernel/DataObject.h>
22 #include <GaudiKernel/IRegistry.h>
25 #include <GaudiKernel/SmartIF.h>
26 
27 using namespace std;
28 
37 class StoreSnifferAlg : public Algorithm {
38 public:
41 
43 
44  struct LeafInfo final {
45  int count;
46  int id;
48  };
51 
52  SniffInfo m_info, m_curr;
54 
55  size_t explore( IRegistry* pObj ) {
56  if ( pObj ) {
57  auto mgr = eventSvc().as<IDataManagerSvc>();
58  if ( mgr ) {
59  vector<IRegistry*> leaves;
60  StatusCode sc = m_mgr->objectLeaves( pObj, leaves );
61  if ( sc.isSuccess() ) {
62  for ( auto& pReg : leaves ) {
64  if ( !pReg->address() || !pReg->object() ) continue;
65  const string& id = pReg->identifier();
66  auto 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  return leaves.size();
78  }
79  }
80  }
81  return 0;
82  }
83 
85  StatusCode initialize() override {
86  m_info.clear();
87  m_mgr = eventSvc();
88  return StatusCode::SUCCESS;
89  }
90 
92  StatusCode finalize() override {
93  auto& log = always();
94  log << "== BEGIN ============= Access list content:" << m_info.size() << endmsg;
95  for ( const auto& i : m_info ) {
96  const LeafInfo& info = i.second;
97  log << "== ITEM == " << right << setw( 4 ) << dec << info.id << " clid:" << right << setw( 8 ) << hex << info.clid
98  << " Count:" << right << setw( 6 ) << dec << info.count << " " << i.first + ":" << endmsg;
99  auto c = m_corr.find( i.first );
100  if ( c != m_corr.end() ) {
101  int cnt = 0;
102  log << "== CORRELATIONS:" << ( *c ).second.size() << endmsg;
103  for ( const auto& k : c->second ) {
104  if ( k.second > 0 ) {
105  log << dec << k.first << ":" << k.second << " ";
106  if ( ++cnt == 10 ) {
107  cnt = 0;
108  log << endmsg;
109  }
110  }
111  }
112  if ( cnt > 0 ) log << endmsg;
113  }
114  auto l = m_links.find( i.first );
115  if ( l != m_links.end() ) {
116  int cnt = 0;
117  log << "== LINKS:" << l->second.size() << endmsg;
118  for ( const auto& k : l->second ) {
119  if ( k.second > 0 ) {
120  log << dec << k.first << ":" << k.second << " ";
121  if ( ++cnt == 10 ) {
122  cnt = 0;
123  log << endmsg;
124  }
125  }
126  }
127  if ( cnt > 0 ) log << endmsg;
128  }
129  }
130  always() << "== END =============== Access list content:" << m_info.size() << endmsg;
131  m_info.clear();
132  m_mgr = nullptr;
133  return StatusCode::SUCCESS;
134  }
135 
137  StatusCode execute() override {
138  SmartDataPtr<DataObject> root( eventSvc(), "/Event" );
139  if ( root ) {
140  m_curr.clear();
141  auto& evnt = m_curr["/Event"];
142  evnt.count = explore( root->registry() );
143  evnt.clid = root->clID();
144  evnt.id = m_curr.size();
145  for ( const auto& i : m_curr ) m_info[i.first].count++;
146  for ( const auto& i : m_info ) {
147  const string& nam = i.first;
148  // const LeafInfo& leaf = (*i).second;
149  auto c = m_corr.find( nam );
150  if ( c == m_corr.end() ) {
151  m_corr[nam] = {};
152  c = m_corr.find( nam );
153  }
154  for ( const auto& l : m_curr ) {
155  const auto& id = l.second.id;
156  auto k = c->second.find( id );
157  if ( k == c->second.end() ) k = c->second.emplace( id, 0 ).first;
158  ++( k->second );
159  }
160 
161  c = m_links.find( nam );
162  if ( c == m_links.end() ) c = m_links.emplace( nam, std::map<int, int>{} ).first;
163  if ( m_curr.find( nam ) == m_curr.end() ) continue;
164 
165  SmartDataPtr<DataObject> obj( eventSvc(), nam );
166  if ( !obj ) continue;
167 
168  LinkManager* m = obj->linkMgr();
169  for ( long l = 0; l < m->size(); ++l ) {
170  auto* lnk = m->link( l );
171  auto il = m_curr.find( lnk->path() );
172  // cout << "Link:" << lnk->path() << " " << (char*)(il != m_curr.end() ? "Found" : "Not there") << endl;
173  if ( il == m_curr.end() ) continue;
174  if ( !lnk->object() ) continue;
175  const auto& id = il->second.id;
176  auto k = c->second.find( id );
177  if ( k == c->second.end() ) k = c->second.emplace( id, 0 ).first;
178  ++( k->second );
179  }
180  }
181  }
182  return StatusCode::SUCCESS;
183  }
184 };
185 
186 DECLARE_COMPONENT( StoreSnifferAlg )
StoreSnifferAlg::initialize
StatusCode initialize() override
Initialize.
Definition: StoreSnifferAlg.cpp:85
StoreSnifferAlg::m_info
SniffInfo m_info
Definition: StoreSnifferAlg.cpp:52
IDataManagerSvc
Definition: IDataManagerSvc.h:55
StoreSnifferAlg::LeafInfo::clid
CLID clid
Definition: StoreSnifferAlg.cpp:47
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:314
std::vector< IRegistry * >
std::map::find
T find(T... args)
std::map::size
T size(T... args)
Algorithm
Alias for backward compatibility.
Definition: Algorithm.h:58
StoreSnifferAlg::m_mgr
SmartIF< IDataManagerSvc > m_mgr
Definition: StoreSnifferAlg.cpp:42
Algorithm.h
std::map::emplace
T emplace(T... args)
gaudiComponentHelp.root
root
Definition: gaudiComponentHelp.py:42
gaudirun.c
c
Definition: gaudirun.py:525
IRegistry
Definition: IRegistry.h:32
StoreSnifferAlg::Correlations
map< string, map< int, int > > Correlations
Definition: StoreSnifferAlg.cpp:50
GaudiPartProp.tests.id
id
Definition: tests.py:111
IDataProviderSvc.h
std::map::clear
T clear(T... args)
std::dec
T dec(T... args)
StoreSnifferAlg::execute
StatusCode execute() override
Execute procedure.
Definition: StoreSnifferAlg.cpp:137
SmartIF.h
StatusCode
Definition: StatusCode.h:65
std::log
T log(T... args)
Gaudi::Units::m
constexpr double m
Definition: SystemOfUnits.h:108
ProduceConsume.j
j
Definition: ProduceConsume.py:104
StoreSnifferAlg::LeafInfo::count
int count
Definition: StoreSnifferAlg.cpp:45
SmartDataPtr.h
SmartIF< IDataManagerSvc >
MsgStream::clear
void clear(STATE_TYPE _i=std::ios_base::failbit)
Definition: MsgStream.h:181
CLID
unsigned int CLID
Class ID definition.
Definition: ClassID.h:18
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
std::map< string, LeafInfo >
StoreSnifferAlg::LeafInfo::id
int id
Definition: StoreSnifferAlg.cpp:46
StoreSnifferAlg::LeafInfo
Definition: StoreSnifferAlg.cpp:44
IRegistry.h
StoreSnifferAlg::m_links
Correlations m_links
Definition: StoreSnifferAlg.cpp:53
StoreSnifferAlg::explore
size_t explore(IRegistry *pObj)
Definition: StoreSnifferAlg.cpp:55
StoreSnifferAlg::finalize
StatusCode finalize() override
Finalize.
Definition: StoreSnifferAlg.cpp:92
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
DataObject.h
std::right
T right(T... args)
gaudirun.l
dictionary l
Definition: gaudirun.py:583
SmartDataPtr
A small class used to access easily (and efficiently) data items residing in data stores.
Definition: SmartDataPtr.h:57
std
STL namespace.
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
std::map::count
T count(T... args)
StoreSnifferAlg::SniffInfo
map< string, LeafInfo > SniffInfo
Definition: StoreSnifferAlg.cpp:49
std::map::end
T end(T... args)
Gaudi::Algorithm::Algorithm
Algorithm(std::string name, ISvcLocator *svcloc, std::string version=PACKAGE_VERSION)
Constructor.
Definition: Algorithm.h:101
std::setw
T setw(T... args)
DataObject::linkMgr
LinkManager * linkMgr()
Retrieve Link manager.
Definition: DataObject.h:80
IDataManagerSvc.h