Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
StoreExplorerAlg.cpp
Go to the documentation of this file.
1 // ====================================================================
2 // StoreExplorerAlg.cpp
3 // --------------------------------------------------------------------
4 //
5 // Author : Markus Frank
6 //
7 // ====================================================================
12 #include "GaudiKernel/IRegistry.h"
14 #include "GaudiKernel/MsgStream.h"
16 #include "GaudiKernel/ObjectList.h"
19 #include "GaudiKernel/SmartIF.h"
20 
21 #include <numeric>
22 
32 class StoreExplorerAlg : public Algorithm {
33 
34  Gaudi::Property<bool> m_load{this, "Load", false, "load non existing items"};
35  Gaudi::Property<long> m_print{this, "PrintEvt", 1, "limit printout to first N events"};
36  Gaudi::Property<long> m_printMissing{this, "PrintMissing", 0, "indicate if missing entities should be printed"};
37  Gaudi::Property<double> m_frequency{this, "PrintFreq", 0.0, "printout frequency"};
38  Gaudi::Property<bool> m_exploreRelations{this, "ExploreRelations", false, "if relations should be followed"};
39  Gaudi::Property<std::string> m_dataSvcName{this, "DataSvc", "EventDataSvc", "name of the data provider service"};
40  Gaudi::Property<bool> m_testAccess{this, "TestAccess", false,
41  "test access to objects (DataObject and ContainedObject)"};
42  Gaudi::Property<bool> m_accessForeign{this, "AccessForeign", false, "indicate if foreign files should be opened"};
43 
45  long m_total = 0;
47  long m_frqPrint = 0;
52 
53 public:
56 
57  template <class T>
58  std::string access( T* p ) {
59  if ( !p ) return "Access FAILED.";
61  std::begin( *p ), std::end( *p ), std::string{}, [&]( std::string s, typename T::const_reference i ) {
62  return s + std::to_string( p->index( i ) ) + ":" + std::to_string( i->clID() ) + ",";
63  } );
64  return result.substr( 0, result.length() - 2 );
65  }
66 
68  void printObj( IRegistry* pReg, std::vector<bool>& flg ) {
69  auto& log = info();
70  for ( size_t j = 1; j < flg.size(); j++ ) {
71  if ( !flg[j - 1] && flg[j] )
72  log << "| ";
73  else if ( flg[j] )
74  log << " ";
75  else
76  log << "| ";
77  }
78  log << "+--> " << pReg->name();
79  if ( pReg->address() ) {
80  log << " [Address: CLID=" << std::showbase << std::hex << pReg->address()->clID()
81  << " Type=" << (void*)pReg->address()->svcType() << "]";
82  } else {
83  log << " [No Address]";
84  }
85  DataObject* p = pReg->object();
86  if ( p ) {
87  try {
88  std::string typ = System::typeinfoName( typeid( *p ) );
89  if ( m_testAccess ) p->clID();
90  log << " " << typ.substr( 0, 32 );
91  } catch ( ... ) { log << "Access test FAILED"; }
92  } else {
93  log << " (Unloaded) ";
94  }
95  ObjectContainerBase* base = dynamic_cast<ObjectContainerBase*>( p );
96  if ( base ) {
97  try {
98  int numObj = base->numberOfObjects();
99  const CLID id = p->clID();
100  log << " [" << numObj << "]";
101  if ( m_testAccess ) {
102  CLID idd = id >> 16;
103  switch ( idd ) {
104  case CLID_ObjectList >> 16: /* ObjectList */
106  break;
107  case CLID_ObjectVector >> 16: /* ObjectVector */
109  break;
110  case ( CLID_ObjectVector + 0x00030000 ) >> 16: /* Keyed Map */
112  break;
113  case ( CLID_ObjectVector + 0x00040000 ) >> 16: /* Keyed Hashmap */
115  break;
116  case ( CLID_ObjectVector + 0x00050000 ) >> 16: /* Keyed array */
118  break;
119  }
120  }
121  } catch ( ... ) { log << "Access test FAILED"; }
122  }
123  log << endmsg;
124  }
125 
126  void explore( IRegistry* pObj, std::vector<bool>& flg ) {
127  printObj( pObj, flg );
128  if ( pObj ) {
129  auto mgr = eventSvc().as<IDataManagerSvc>();
130  if ( mgr ) {
132  StatusCode sc = mgr->objectLeaves( pObj, leaves );
133  const std::string* par0 = nullptr;
134  if ( pObj->address() ) par0 = pObj->address()->par();
135  if ( sc.isSuccess() ) {
136  for ( auto i = leaves.begin(); i != leaves.end(); i++ ) {
137  const std::string& id = ( *i )->identifier();
138  DataObject* p = nullptr;
139  if ( !m_accessForeign && ( *i )->address() ) {
140  if ( par0 ) {
141  const std::string* par1 = ( *i )->address()->par();
142  if ( par1 && par0[0] != par1[0] ) continue;
143  }
144  }
145  if ( m_load ) {
146  sc = eventSvc()->retrieveObject( id, p );
147  } else {
148  sc = eventSvc()->findObject( id, p );
149  }
150  if ( sc.isSuccess() ) {
151  if ( id != "/Event/Rec/Relations" || m_exploreRelations ) {
152  flg.push_back( i + 1 == leaves.end() );
153  explore( *i, flg );
154  flg.pop_back();
155  }
156  } else {
157  flg.push_back( i + 1 == leaves.end() );
158  printObj( *i, flg );
159  flg.pop_back();
160  }
161  }
162  }
163  }
164  }
165  }
166 
168  StatusCode initialize() override {
169  m_rootName.clear();
170  m_dataSvc = service( m_dataSvcName, true );
171  if ( !m_dataSvc ) {
172  error() << "Failed to access service \"" << m_dataSvcName << "\"." << endmsg;
173  return StatusCode::FAILURE;
174  }
175  auto mgr = m_dataSvc.as<IDataManagerSvc>();
176  if ( !mgr ) {
177  error() << "Failed to retrieve IDataManagerSvc interface." << endmsg;
178  return StatusCode::FAILURE;
179  }
180  m_rootName = mgr->rootName();
181  return StatusCode::SUCCESS;
182  }
183 
185  StatusCode finalize() override {
186  m_dataSvc.reset();
187  return StatusCode::SUCCESS;
188  }
189 
191  StatusCode execute() override {
193  if ( ( ( m_print > m_total++ ) || ( m_frequency * m_total > m_frqPrint ) ) && root ) {
194  if ( m_frequency * m_total > m_frqPrint ) m_frqPrint++;
195  std::string store_name = "Unknown";
196  IRegistry* pReg = root->registry();
197  if ( pReg ) {
198  auto isvc = SmartIF<IService>{pReg->dataSvc()};
199  if ( isvc ) store_name = isvc->name();
200  }
201  info() << "========= " << m_rootName << "[" << std::showbase << std::hex << (unsigned long)root.ptr() << std::dec
202  << "@" << store_name << "]:" << endmsg;
203  std::vector<bool> flg( 1, true );
204  explore( root->registry(), flg );
205  return StatusCode::SUCCESS;
206  } else if ( root ) {
207  return StatusCode::SUCCESS;
208  }
209  error() << "Cannot retrieve \"/Event\"!" << endmsg;
210  return StatusCode::FAILURE;
211  }
212 };
213 
StatusCode initialize() override
Initialize.
Gaudi::Property< bool > m_exploreRelations
virtual const CLID & clID() const =0
Retrieve class information from link.
Implementation of property with value of concrete type.
Definition: Property.h:352
Definition of the templated KeyedObject class.
Definition: KeyedObject.h:29
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
SmartIF< IDataProviderSvc > m_dataSvc
Reference to data provider service.
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:309
virtual StatusCode findObject(IRegistry *pDirectory, boost::string_ref path, DataObject *&pObject)=0
Find object identified by its directory entry.
bool isSuccess() const
Definition: StatusCode.h:267
Gaudi::Property< bool > m_accessForeign
Algorithm(const std::string &name, ISvcLocator *svcloc, const std::string &version=PACKAGE_VERSION)
Constructor.
Definition: Algorithm.cpp:48
T to_string(T...args)
ObjectVector is one of the basic Gaudi container classes capable of being registered in Data Stores...
StatusCode service(const std::string &name, T *&psvc, bool createIf=true) const
Access a service by name, creating it if it doesn&#39;t already exist.
Definition: Algorithm.h:215
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
template class KeyedContainer, KeyedContainer.h
virtual const name_type & name() const =0
Name of the directory (or key)
StatusCode execute() override
Execute procedure.
T showbase(T...args)
T end(T...args)
Gaudi::Property< std::string > m_dataSvcName
SmartIF< IDataProviderSvc > & eventSvc() const
The standard event data service.
Definition: Algorithm.cpp:668
virtual const std::string * par() const =0
Retrieve String parameters.
long m_total
Internal counter to trigger printouts.
Gaudi::Property< double > m_frequency
ObjectList is one of the basic Gaudi container classes capable of being registered in Data Stores...
STL class.
Gaudi::Property< bool > m_testAccess
#define DECLARE_COMPONENT(type)
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:76
T push_back(T...args)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
SmartIF< IFace > as() const
return a new SmartIF instance to another interface
Definition: SmartIF.h:107
virtual const CLID & clID() const
Retrieve reference to class definition structure.
Definition: DataObject.cpp:56
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
std::string m_rootName
Name of the root leaf (obtained at initialize)
T pop_back(T...args)
virtual IDataProviderSvc * dataSvc() const =0
Retrieve pointer to Transient Store.
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition: IRegistry.h:22
virtual long svcType() const =0
Retrieve service type.
virtual StatusCode retrieveObject(IRegistry *pDirectory, boost::string_ref path, DataObject *&pObject)=0
Retrieve object identified by its directory entry.
unsigned int CLID
Class ID definition.
Definition: ClassID.h:8
T clear(T...args)
void printObj(IRegistry *pReg, std::vector< bool > &flg)
Print datastore leaf.
Gaudi::Property< long > m_print
virtual DataObject * object() const =0
Retrieve object behind the link.
void explore(IRegistry *pObj, std::vector< bool > &flg)
Alias for backward compatibility.
Definition: Algorithm.h:56
T length(T...args)
T begin(T...args)
StatusCode finalize() override
Finalize.
KeyedObjectManager Class to manage keyed objects.
string s
Definition: gaudirun.py:312
A small class used to access easily (and efficiently) data items residing in data stores...
Definition: SmartDataPtr.h:47
constexpr static const auto FAILURE
Definition: StatusCode.h:86
Gaudi::Property< long > m_printMissing
T hex(T...args)
T substr(T...args)
Small algorith, which traverses the data store and prints generic information about all leaves...
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:86
ObjectContainerBase is the base class for Gaudi container classes.
virtual size_type numberOfObjects() const =0
Number of objects in the container.
T accumulate(T...args)
long m_frqPrint
Internal counter to adjust printout frequency.
virtual IOpaqueAddress * address() const =0
Retrieve opaque storage address.
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
Gaudi::Property< bool > m_load
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
std::string access(T *p)