| The Gaudi Framework v27r1

- 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/ObjectContainerBase.h"
9 #include "GaudiKernel/ObjectList.h"
10 #include "GaudiKernel/ObjectVector.h"
11 #include "GaudiKernel/KeyedContainer.h"
12 #include "GaudiKernel/IDataProviderSvc.h"
13 #include "GaudiKernel/IDataManagerSvc.h"
14 #include "GaudiKernel/IOpaqueAddress.h"
15 #include "GaudiKernel/SmartDataPtr.h"
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;
36 bool m_exploreRelations;
38 long m_printMissing;
40 long m_total = 0;
42 long m_frqPrint = 0;
44 bool m_load;
46 bool m_testAccess;
48 bool m_accessForeign;
50 SmartIF<IDataProviderSvc> m_dataSvc;
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)
60 {
61 declareProperty("Load", m_load = false);
62 declareProperty("PrintEvt", m_print = 1);
63 declareProperty("PrintMissing", m_printMissing = 0);
64 declareProperty("PrintFreq", m_frequency = 0.0);
65 declareProperty("ExploreRelations", m_exploreRelations = false);
66 declareProperty("DataSvc", m_dataSvcName="EventDataSvc");
67 declareProperty("TestAccess", m_testAccess = false);
68 declareProperty("AccessForeign", m_accessForeign = false);
69 }
71 ~StoreExplorerAlg() override = default;
72
73 template <class T>
74 std::string access(T* p) {
75 if ( !p ) return "Access FAILED.";
76 std::string result = std::accumulate(std::begin(*p),std::end(*p),std::string{},
77 [&](std::string s,typename T::const_reference i) {
78 return s+std::to_string(p->index(i)) + ":" + std::to_string(i->clID()) + ",";
79 });
80 return result.substr(0, result.length()-2);
81 }
82
83
85 void printObj(IRegistry* pReg, std::vector<bool>& flg) {
86 auto& log = info();
87 for (size_t j = 1; j < flg.size(); j++ ) {
88 if ( !flg[j-1] && flg[j] ) log << "| ";
89 else if ( flg[j] ) log << " ";
90 else log << "| ";
91 }
92 log << "+--> " << pReg->name();
93 if ( pReg->address() ) {
94 log << " [Address: CLID="
95 << std::showbase << std::hex << pReg->address()->clID()
96 << " Type=" << (void*)pReg->address()->svcType() << "]";
97 }
98 else {
99 log << " [No Address]";
100 }
101 DataObject* p = pReg->object();
102 if ( p ) {
103 try {
104 std::string typ = System::typeinfoName(typeid(*p));
105 if ( m_testAccess ) p->clID();
106 log << " " << typ.substr(0,32);
107 }
108 catch (...) {
109 log << "Access test FAILED";
110 }
111 }
112 else {
113 log << " (Unloaded) ";
114 }
115 ObjectContainerBase* base = dynamic_cast<ObjectContainerBase*>(p);
116 if ( base ) {
117 try {
118 int numObj = base->numberOfObjects();
119 const CLID id = p->clID();
120 log << " [" << numObj << "]";
121 if ( m_testAccess ) {
122 CLID idd = id>>16;
123 switch(idd) {
124 case CLID_ObjectList>>16: /* ObjectList */
125 access((ObjectList<ContainedObject>*)base);
126 break;
127 case CLID_ObjectVector>>16: /* ObjectVector */
128 access((ObjectVector<ContainedObject>*)base);
129 break;
130 case (CLID_ObjectVector+0x00030000)>>16: /* Keyed Map */
131 access((KeyedContainer<KeyedObject<int>,Containers::Map>*)base);
132 break;
133 case (CLID_ObjectVector+0x00040000)>>16: /* Keyed Hashmap */
134 access((KeyedContainer<KeyedObject<int>,Containers::HashMap>*)base);
135 break;
136 case (CLID_ObjectVector+0x00050000)>>16: /* Keyed array */
137 access((KeyedContainer<KeyedObject<int>,Containers::Array>*)base);
138 break;
139 }
140 }
141 }
142 catch (...) {
143 log << "Access test FAILED";
144 }
145 }
146 log << endmsg;
147 }
148
149 void explore(IRegistry* pObj, std::vector<bool>& flg) {
150 printObj(pObj, flg);
151 if ( pObj ) {
152 auto mgr = eventSvc().as<IDataManagerSvc>();
153 if ( mgr ) {
154 std::vector<IRegistry*> leaves;
155 StatusCode sc = mgr->objectLeaves(pObj, leaves);
156 const std::string* par0 = nullptr;
157 if ( pObj->address() ) par0 = pObj->address()->par();
158 if ( sc.isSuccess() ) {
159 for ( auto i=leaves.begin(); i != leaves.end(); i++ ) {
160 const std::string& id = (*i)->identifier();
161 DataObject* p = nullptr;
162 if ( !m_accessForeign && (*i)->address() ) {
163 if ( par0 ) {
164 const std::string* par1 = (*i)->address()->par();
165 if ( par1 && par0[0] != par1[0] ) continue;
166 }
167 }
168 if ( m_load ) {
169 sc = eventSvc()->retrieveObject(id, p);
170 } else {
171 sc = eventSvc()->findObject(id, p);
172 }
173 if ( sc.isSuccess() ) {
174 if ( id != "/Event/Rec/Relations" || m_exploreRelations ) {
175 flg.push_back(i+1 == leaves.end());
176 explore(*i, flg);
177 flg.pop_back();
178 }
179 } else {
180 flg.push_back(i+1 == leaves.end());
181 printObj(*i, flg);
182 flg.pop_back();
183 }
184 }
185 }
186 }
187 }
188 }
189
191 StatusCode initialize() override {
192 m_rootName.clear();
193 m_dataSvc = service(m_dataSvcName,true);
194 if ( !m_dataSvc ) {
195 error() << "Failed to access service \""
196 << m_dataSvcName << "\"." << endmsg;
197 return StatusCode::FAILURE;
198 }
199 auto mgr = m_dataSvc.as<IDataManagerSvc>();
200 if ( !mgr ) {
201 error() << "Failed to retrieve IDataManagerSvc interface." << endmsg;
202 return StatusCode::FAILURE;
203 }
204 m_rootName = mgr->rootName();
205 return StatusCode::SUCCESS;
206 }
207
209 StatusCode finalize() override {
210 m_dataSvc.reset();
211 return StatusCode::SUCCESS;
212 }
213
215 StatusCode execute() override {
216 SmartDataPtr<DataObject> root(m_dataSvc.get(),m_rootName);
217 if ( ((m_print > m_total++) || (m_frequency*m_total > m_frqPrint)) && root ) {
218 if ( m_frequency*m_total > m_frqPrint ) m_frqPrint++;
219 std::string store_name = "Unknown";
220 IRegistry* pReg = root->registry();
221 if ( pReg ) {
222 auto isvc = SmartIF<IService>{pReg->dataSvc()};
223 if ( isvc ) store_name = isvc->name();
224 }
225 info() << "========= " << m_rootName << "["
226 << std::showbase << std::hex << (unsigned long) root.ptr() << std::dec
227 << "@" << store_name << "]:" << endmsg;
228 std::vector<bool> flg(1,true);
229 explore(root->registry(), flg);
230 return StatusCode::SUCCESS;
231 } else if ( root ) {
232 return StatusCode::SUCCESS;
233 }
234 error() << "Cannot retrieve \"/Event\"!" << endmsg;
235 return StatusCode::FAILURE;
236 }
237 };
238
239 DECLARE_COMPONENT(StoreExplorerAlg)
IOpaqueAddress::par
virtual const std::string * par() const =0
Retrieve String parameters.
StoreExplorerAlg::initialize
StatusCode initialize() override
Initialize.
Definition: StoreExplorerAlg.cpp:191
Algorithm.h
SmartIF< IDataProviderSvc >
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
StoreExplorerAlg::m_printMissing
long m_printMissing
Flag to indicate if missing entities should be printed.
Definition: StoreExplorerAlg.cpp:38
MsgStream.h
KeyedObject< int >
CommonMessagingBase::info
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:124
StoreExplorerAlg::m_dataSvc
SmartIF< IDataProviderSvc > m_dataSvc
Reference to data provider service.
Definition: StoreExplorerAlg.cpp:50
StoreExplorerAlg::m_accessForeign
bool m_accessForeign
Flag to indicate if foreign files should be opened.
Definition: StoreExplorerAlg.cpp:48
System::typeinfoName
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:297
Gaudi.Configuration.log
tuple log
Definition: Configuration.py:13
ObjectVector.h
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
ObjectContainerBase::numberOfObjects
virtual size_type numberOfObjects() const =0
Number of objects in the container.
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
Algorithm::declareProperty
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: Algorithm.h:426
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:215
std::showbase
T showbase(T...args)
StoreExplorerAlg::m_load
bool m_load
Flag to load non existing items.
Definition: StoreExplorerAlg.cpp:44
std::end
T end(T...args)
merge_files.sc
int sc
Definition: merge_files.py:167
IOpaqueAddress::svcType
virtual long svcType() const =0
Retrieve service type.
StoreExplorerAlg::m_total
long m_total
Internal counter to trigger printouts.
Definition: StoreExplorerAlg.cpp:40
StoreExplorerAlg::m_frequency
double m_frequency
Job option to set the printout frequency.
Definition: StoreExplorerAlg.cpp:34
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
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_print
long m_print
Job option to limit printout to first nnn events.
Definition: StoreExplorerAlg.cpp:32
Algorithm::name
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:820
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:118
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.
IOpaqueAddress::clID
virtual const CLID & clID() const =0
Retrieve class information from link.
StatusCode::FAILURE
Definition: StatusCode.h:29
StatusCode::SUCCESS
Definition: StatusCode.h:30
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:54
SmartIF.h
StoreExplorerAlg::StoreExplorerAlg
StoreExplorerAlg(const std::string &name, ISvcLocator *pSvcLocator)
Standard algorithm constructor.
Definition: StoreExplorerAlg.cpp:58
std::vector::pop_back
T pop_back(T...args)
IRegistry.h
IRegistry
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition: IRegistry.h:22
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:85
IRegistry::address
virtual IOpaqueAddress * address() const =0
Retrieve opaque storage address.
IRegistry::object
virtual DataObject * object() const =0
Retrieve object behind the link.
StoreExplorerAlg::m_dataSvcName
std::string m_dataSvcName
Name of the data provider service.
Definition: StoreExplorerAlg.cpp:52
IOpaqueAddress.h
StoreExplorerAlg::explore
void explore(IRegistry *pObj, std::vector< bool > &flg)
Definition: StoreExplorerAlg.cpp:149
Algorithm
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:74
std::string::length
T length(T...args)
ObjectList.h
std::vector< bool >
Algorithm::eventSvc
SmartIF< IDataProviderSvc > & eventSvc() const
The standard event data service.
IDataManagerSvc
Definition: IDataManagerSvc.h:45
std::begin
T begin(T...args)
StoreExplorerAlg::finalize
StatusCode finalize() override
Finalize.
Definition: StoreExplorerAlg.cpp:209
StoreExplorerAlg::m_exploreRelations
bool m_exploreRelations
Flag to check if relations should be followed.
Definition: StoreExplorerAlg.cpp:36
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
std::hex
T hex(T...args)
IOTest.root
tuple root
Definition: IOTest.py:42
IRegistry::dataSvc
virtual IDataProviderSvc * dataSvc() const =0
Retrieve pointer to Transient Store.
std::string::substr
T substr(T...args)
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:30
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
Algorithm::service
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:232
std::accumulate
T accumulate(T...args)
StoreExplorerAlg::m_frqPrint
long m_frqPrint
Internal counter to adjust printout frequency.
Definition: StoreExplorerAlg.cpp:42
DataObject
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
ana.i
list i
Definition: ana.py:128
KeyedContainer.h
StoreExplorerAlg::m_testAccess
bool m_testAccess
Flag to test access to objects (DataObject and ContainedObject)
Definition: StoreExplorerAlg.cpp:46
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:74
IDataProviderSvc::retrieveObject
virtual StatusCode retrieveObject(IRegistry *pDirectory, const std::string &path, DataObject *&pObject)=0
Retrieve object identified by its directory entry.