All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
StoreExplorerAlg.cpp
Go to the documentation of this file.
1 // ====================================================================
2 // StoreExplorerAlg.cpp
3 // --------------------------------------------------------------------
4 //
5 // Author : Markus Frank
6 //
7 // ====================================================================
16 #include "GaudiKernel/Algorithm.h"
17 #include "GaudiKernel/IRegistry.h"
18 #include "GaudiKernel/MsgStream.h"
19 #include "GaudiKernel/SmartIF.h"
20 
30 class StoreExplorerAlg : public Algorithm {
32  long m_print;
34  double m_frequency;
40  long m_total;
42  long m_frqPrint;
44  bool m_load;
52  std::string m_dataSvcName;
54  std::string m_rootName;
55 public:
56 
58  StoreExplorerAlg(const std::string& name, ISvcLocator* pSvcLocator)
59  : Algorithm(name, pSvcLocator), m_dataSvc(0)
60  {
61  m_total = m_frqPrint = 0;
62  declareProperty("Load", m_load = false);
63  declareProperty("PrintEvt", m_print = 1);
64  declareProperty("PrintMissing", m_printMissing = 0);
65  declareProperty("PrintFreq", m_frequency = 0.0);
66  declareProperty("ExploreRelations", m_exploreRelations = false);
67  declareProperty("DataSvc", m_dataSvcName="EventDataSvc");
68  declareProperty("TestAccess", m_testAccess = false);
69  declareProperty("AccessForeign", m_accessForeign = false);
70  }
72  virtual ~StoreExplorerAlg() {
73  }
74 
75  template <class T>
76  std::string access(T* p) {
77  if ( p ) {
78  std::stringstream s;
79  for (typename T::const_iterator i = p->begin(); i != p->end(); ++i ) {
80  int idx = p->index(*i);
81  s << idx << ":" << (*i)->clID() << ",";
82  }
83  std::string result = s.str();
84  return result.substr(0, result.length()-2);
85  }
86  return "Access FAILED.";
87  }
88 
89 
91  void printObj(IRegistry* pReg, std::vector<bool>& flg) {
92  MsgStream log(msgSvc(), name());
93  log << MSG::INFO;
94  for (size_t j = 1; j < flg.size(); j++ ) {
95  if ( !flg[j-1] && flg[j] ) log << "| ";
96  else if ( flg[j] ) log << " ";
97  else log << "| ";
98  }
99  log << "+--> " << pReg->name();
100  if ( pReg->address() ) {
101  log << " [Address: CLID="
102  << std::showbase << std::hex << pReg->address()->clID();
103  log << " Type=" << (void*)pReg->address()->svcType() << "]";
104  }
105  else {
106  log << " [No Address]";
107  }
108  DataObject* p = pReg->object();
109  if ( p ) {
110  try {
111  std::string typ = System::typeinfoName(typeid(*p));
112  if ( m_testAccess ) {
113  p->clID();
114  }
115  log << " " << typ.substr(0,32);
116  }
117  catch (...) {
118  log << "Access test FAILED";
119  }
120  }
121  else {
122  log << " (Unloaded) ";
123  }
124  ObjectContainerBase* base = dynamic_cast<ObjectContainerBase*>(p);
125  if ( base ) {
126  try {
127  int numObj = base->numberOfObjects();
128  const CLID id = p->clID();
129  log << " [" << numObj << "]";
130  if ( m_testAccess ) {
131  CLID idd = id>>16;
132  switch(idd) {
133  case CLID_ObjectList>>16: /* ObjectList */
135  break;
136  case CLID_ObjectVector>>16: /* ObjectVector */
138  break;
139  case (CLID_ObjectVector+0x00030000)>>16: /* Keyed Map */
141  break;
142  case (CLID_ObjectVector+0x00040000)>>16: /* Keyed Hashmap */
144  break;
145  case (CLID_ObjectVector+0x00050000)>>16: /* Keyed array */
147  break;
148  }
149  }
150  }
151  catch (...) {
152  log << "Access test FAILED";
153  }
154  }
155  log << endmsg;
156  }
157 
158  void explore(IRegistry* pObj, std::vector<bool>& flg) {
159  printObj(pObj, flg);
160  if ( 0 != pObj ) {
162  if ( mgr ) {
163  typedef std::vector<IRegistry*> Leaves;
164  Leaves leaves;
165  StatusCode sc = mgr->objectLeaves(pObj, leaves);
166  const std::string* par0 = 0;
167  if ( pObj->address() ) {
168  par0 = pObj->address()->par();
169  }
170  if ( sc.isSuccess() ) {
171  for ( Leaves::const_iterator i=leaves.begin(); i != leaves.end(); i++ ) {
172  const std::string& id = (*i)->identifier();
173  DataObject* p = 0;
174  if ( !m_accessForeign && (*i)->address() ) {
175  if ( par0 ) {
176  const std::string* par1 = (*i)->address()->par();
177  if ( par1 ) {
178  if ( par0[0] != par1[0] ) {
179  continue;
180  }
181  }
182  }
183  }
184  if ( m_load ) {
185  sc = eventSvc()->retrieveObject(id, p);
186  }
187  else {
188  sc = eventSvc()->findObject(id, p);
189  }
190  if ( sc.isSuccess() ) {
191  if ( id != "/Event/Rec/Relations" || m_exploreRelations ) {
192  flg.push_back(i+1 == leaves.end());
193  explore(*i, flg);
194  flg.pop_back();
195  }
196  }
197  else {
198  flg.push_back(i+1 == leaves.end());
199  printObj(*i, flg);
200  flg.pop_back();
201  }
202  }
203  }
204  }
205  }
206  }
207 
209  virtual StatusCode initialize() {
210  MsgStream log(msgSvc(), name());
211  m_rootName = "";
213  if ( sc.isSuccess() ) {
215  if ( mgr ) {
216  m_rootName = mgr->rootName();
217  return sc;
218  }
219  log << MSG::ERROR << "Failed to retrieve IDataManagerSvc interface." << endmsg;
220  return StatusCode::FAILURE;
221  }
222  log << MSG::ERROR << "Failed to access service \""
223  << m_dataSvcName << "\"." << endmsg;
224  return StatusCode::FAILURE;
225  }
226 
228  virtual StatusCode finalize() {
229  if ( m_dataSvc ) m_dataSvc->release();
230  m_dataSvc = 0;
231  return StatusCode::SUCCESS;
232  }
233 
235  virtual StatusCode execute() {
236  MsgStream log(msgSvc(), name());
238  if ( ((m_print > m_total++) || (m_frequency*m_total > m_frqPrint)) && root ) {
239  if ( m_frequency*m_total > m_frqPrint ) {
240  m_frqPrint++;
241  }
242  std::string store_name = "Unknown";
243  IRegistry* pReg = root->registry();
244  if ( pReg ) {
245  SmartIF<IService> isvc(pReg->dataSvc());
246  if ( isvc ) {
247  store_name = isvc->name();
248  }
249  }
250  log << MSG::INFO << "========= " << m_rootName << "["
251  << "0x" << std::hex << (unsigned long) root.ptr() << std::dec
252  << "@" << store_name << "]:" << endmsg;
253  std::vector<bool> flg;
254  flg.push_back(true);
255  explore(root->registry(), flg);
256  return StatusCode::SUCCESS;
257  }
258  else if ( root ) {
259  return StatusCode::SUCCESS;
260  }
261  log << MSG::ERROR << "Cannot retrieve \"/Event\"!" << endmsg;
262  return StatusCode::FAILURE;
263  }
264 };
265 
virtual const std::string * par() const =0
Retrieve String parameters.
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
long m_printMissing
Flag to indicate if missing entities should be printed.
bool m_accessForeign
Flag to indicate if foreign files should be opened.
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:298
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:62
virtual size_type numberOfObjects() const =0
Number of objects in the container.
ObjectVector is one of the basic Gaudi container classes capable of being registered in Data Stores...
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: Algorithm.h:395
template class KeyedContainer, KeyedContainer.h
virtual const name_type & name() const =0
Name of the directory (or key)
bool m_load
Flag to load non existing items.
virtual StatusCode execute()
Execute procedure.
virtual StatusCode initialize()
Initialize.
Data provider interface definition.
virtual long svcType() const =0
Retrieve service type.
long m_total
Internal counter to trigger printouts.
virtual StatusCode finalize()
Finalize.
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:69
double m_frequency
Job option to set the printout frequency.
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:35
ObjectList is one of the basic Gaudi container classes capable of being registered in Data Stores...
TYPE * ptr()
Automatic conversion to data type.
long m_print
Job option to limit printout to first nnn events.
virtual const CLID & clID() const
Retrieve reference to class definition structure.
Definition: DataObject.cpp:58
virtual const CLID & clID() const =0
Retrieve class information from link.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
std::string m_rootName
Name of the root leaf (obtained at initialize)
StoreExplorerAlg(const std::string &name, ISvcLocator *pSvcLocator)
Standard algorithm constructor.
virtual const std::string & name() const
The identifying name of the algorithm object.
Definition: Algorithm.cpp:837
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
Definition: Algorithm.cpp:896
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
void printObj(IRegistry *pReg, std::vector< bool > &flg)
Print datastore leaf.
virtual IOpaqueAddress * address() const =0
Retrieve opaque storage address.
virtual DataObject * object() const =0
Retrieve object behind the link.
std::string m_dataSvcName
Name of the data provider service.
void explore(IRegistry *pObj, std::vector< bool > &flg)
IDataProviderSvc * m_dataSvc
Reference to data provider service.
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:61
SmartIF< IDataProviderSvc > & eventSvc() const
The standard event data service.
virtual unsigned long release()=0
Release Interface instance.
bool m_exploreRelations
Flag to check if relations should be followed.
KeyedObjectManager Class to manage keyed objects.
string s
Definition: gaudirun.py:210
A small class used to access easily (and efficiently) data items residing in data stores...
Definition: SmartDataPtr.h:46
virtual ~StoreExplorerAlg()
Standard Destructor.
tuple root
Definition: IOTest.py:42
virtual IDataProviderSvc * dataSvc() const =0
Retrieve pointer to Transient Store.
Small algorith, which traverses the data store and prints generic information about all leaves...
ObjectContainerBase is the base class for Gaudi container classes.
StatusCode service(const std::string &name, T *&psvc, bool createIf=true) const
Access a service by name, creating it if it doesn't already exist.
Definition: Algorithm.h:205
long m_frqPrint
Internal counter to adjust printout frequency.
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:31
list i
Definition: ana.py:128
bool m_testAccess
Flag to test access to objects (DataObject and ContainedObject)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:243
std::string access(T *p)