| The Gaudi Framework v28r2p1 (f1a77ff4)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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