Gaudi Framework, version v24r2
Home
Generated: Wed Dec 4 2013
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
GaudiCommonSvc
src
DataSvc
StoreExplorerAlg.cpp
Go to the documentation of this file.
1
// $Header: /tmp/svngaudi/tmp.jEpFh25751/Gaudi/GaudiSvc/src/DataSvc/StoreExplorerAlg.cpp,v 1.8 2007/10/24 19:06:06 marcocle Exp $
2
// ====================================================================
3
// StoreExplorerAlg.cpp
4
// --------------------------------------------------------------------
5
//
6
// Author : Markus Frank
7
//
8
// ====================================================================
9
#include "
GaudiKernel/ObjectContainerBase.h
"
10
#include "
GaudiKernel/ObjectList.h
"
11
#include "
GaudiKernel/ObjectVector.h
"
12
#include "
GaudiKernel/KeyedContainer.h
"
13
#include "
GaudiKernel/IDataProviderSvc.h
"
14
#include "
GaudiKernel/IDataManagerSvc.h
"
15
#include "
GaudiKernel/IOpaqueAddress.h
"
16
#include "
GaudiKernel/SmartDataPtr.h
"
17
#include "
GaudiKernel/AlgFactory.h
"
18
#include "
GaudiKernel/Algorithm.h
"
19
#include "
GaudiKernel/IRegistry.h
"
20
#include "
GaudiKernel/MsgStream.h
"
21
#include "
GaudiKernel/SmartIF.h
"
22
32
class
StoreExplorerAlg
:
public
Algorithm
{
34
long
m_print
;
36
double
m_frequency
;
38
bool
m_exploreRelations
;
40
long
m_printMissing
;
42
long
m_total
;
44
long
m_frqPrint
;
46
bool
m_load
;
48
bool
m_testAccess
;
50
bool
m_accessForeign
;
52
IDataProviderSvc
*
m_dataSvc
;
54
std::string
m_dataSvcName
;
56
std::string
m_rootName
;
57
public
:
58
60
StoreExplorerAlg
(
const
std::string
&
name
,
ISvcLocator
* pSvcLocator)
61
:
Algorithm
(name, pSvcLocator),
m_dataSvc
(0)
62
{
63
m_total
=
m_frqPrint
= 0;
64
declareProperty
(
"Load"
,
m_load
=
false
);
65
declareProperty
(
"PrintEvt"
,
m_print
= 1);
66
declareProperty
(
"PrintMissing"
,
m_printMissing
= 0);
67
declareProperty
(
"PrintFreq"
,
m_frequency
= 0.0);
68
declareProperty
(
"ExploreRelations"
,
m_exploreRelations
=
false
);
69
declareProperty
(
"DataSvc"
,
m_dataSvcName
=
"EventDataSvc"
);
70
declareProperty
(
"TestAccess"
,
m_testAccess
=
false
);
71
declareProperty
(
"AccessForeign"
,
m_accessForeign
=
false
);
72
}
74
virtual
~StoreExplorerAlg
() {
75
}
76
77
template
<
class
T>
78
std::string
access
(T* p) {
79
if
( p ) {
80
std::stringstream
s
;
81
for
(
typename
T::const_iterator
i
= p->begin();
i
!= p->end(); ++
i
) {
82
int
idx = p->index(*
i
);
83
s << idx <<
":"
<< (*i)->clID() <<
","
;
84
}
85
std::string
result = s.str();
86
return
result.
substr
(0, result.length()-2);
87
}
88
return
"Access FAILED."
;
89
}
90
91
93
void
printObj
(
IRegistry
* pReg,
std::vector<bool>
& flg) {
94
MsgStream
log
(
msgSvc
(),
name
());
95
log <<
MSG::INFO
;
96
for
(
size_t
j = 1; j < flg.
size
(); j++ ) {
97
if
( !flg[j-1] && flg[j] ) log <<
"| "
;
98
else
if
( flg[j] ) log <<
" "
;
99
else
log <<
"| "
;
100
}
101
log <<
"+--> "
<< pReg->
name
();
102
if
( pReg->
address
() ) {
103
log <<
" [Address: CLID="
104
<<
std::showbase
<<
std::hex
<< pReg->
address
()->
clID
();
105
log <<
" Type="
<< (
void
*)pReg->
address
()->
svcType
() <<
"]"
;
106
}
107
else
{
108
log <<
" [No Address]"
;
109
}
110
DataObject
* p = pReg->
object
();
111
if
( p ) {
112
try
{
113
std::string
typ =
System::typeinfoName
(
typeid
(*p));
114
if
(
m_testAccess
) {
115
p->
clID
();
116
}
117
log <<
" "
<< typ.substr(0,32);
118
}
119
catch
(...) {
120
log <<
"Access test FAILED"
;
121
}
122
}
123
else
{
124
log <<
" (Unloaded) "
;
125
}
126
ObjectContainerBase
* base =
dynamic_cast<
ObjectContainerBase
*
>
(p);
127
if
( base ) {
128
try
{
129
int
numObj = base->
numberOfObjects
();
130
const
CLID
id
= p->
clID
();
131
log <<
" ["
<< numObj <<
"]"
;
132
if
(
m_testAccess
) {
133
CLID
idd =
id
>>16;
134
switch
(idd) {
135
case
CLID_ObjectList
>>16:
/* ObjectList */
136
access
((
ObjectList<ContainedObject>
*)base);
137
break
;
138
case
CLID_ObjectVector
>>16:
/* ObjectVector */
139
access
((
ObjectVector<ContainedObject>
*)base);
140
break
;
141
case
(
CLID_ObjectVector
+0x00030000)>>16:
/* Keyed Map */
142
access
((
KeyedContainer
<
KeyedObject<int>
,
Containers::Map
>*)base);
143
break
;
144
case
(
CLID_ObjectVector
+0x00040000)>>16:
/* Keyed Hashmap */
145
access
((
KeyedContainer
<
KeyedObject<int>
,
Containers::HashMap
>*)base);
146
break
;
147
case
(
CLID_ObjectVector
+0x00050000)>>16:
/* Keyed array */
148
access
((
KeyedContainer
<
KeyedObject<int>
,
Containers::Array
>*)base);
149
break
;
150
}
151
}
152
}
153
catch
(...) {
154
log <<
"Access test FAILED"
;
155
}
156
}
157
log <<
endmsg
;
158
}
159
160
void
explore
(
IRegistry
* pObj,
std::vector<bool>
& flg) {
161
printObj
(pObj, flg);
162
if
( 0 != pObj ) {
163
SmartIF<IDataManagerSvc>
mgr(
eventSvc
());
164
if
( mgr ) {
165
typedef
std::vector<IRegistry*>
Leaves;
166
Leaves leaves;
167
StatusCode
sc
= mgr->objectLeaves(pObj, leaves);
168
const
std::string
* par0 = 0;
169
if
( pObj->
address
() ) {
170
par0 = pObj->
address
()->
par
();
171
}
172
if
( sc.
isSuccess
() ) {
173
for
( Leaves::const_iterator
i
=leaves.begin();
i
!= leaves.end();
i
++ ) {
174
const
std::string
&
id
= (*i)->identifier();
175
DataObject
* p = 0;
176
if
( !
m_accessForeign
&& (*i)->address() ) {
177
if
( par0 ) {
178
const
std::string
* par1 = (*i)->address()->par();
179
if
( par1 ) {
180
if
( par0[0] != par1[0] ) {
181
continue
;
182
}
183
}
184
}
185
}
186
if
(
m_load
) {
187
sc =
eventSvc
()->retrieveObject(
id
, p);
188
}
189
else
{
190
sc =
eventSvc
()->findObject(
id
, p);
191
}
192
if
( sc.
isSuccess
() ) {
193
if
(
id
!=
"/Event/Rec/Relations"
||
m_exploreRelations
) {
194
flg.
push_back
(
i
+1 == leaves.end());
195
explore
(*
i
, flg);
196
flg.
pop_back
();
197
}
198
}
199
else
{
200
flg.
push_back
(
i
+1 == leaves.end());
201
printObj
(*
i
, flg);
202
flg.
pop_back
();
203
}
204
}
205
}
206
}
207
}
208
}
209
211
virtual
StatusCode
initialize
() {
212
MsgStream
log
(
msgSvc
(),
name
());
213
m_rootName
=
""
;
214
StatusCode
sc
=
service
(
m_dataSvcName
,
m_dataSvc
,
true
);
215
if
( sc.
isSuccess
() ) {
216
SmartIF<IDataManagerSvc>
mgr(
m_dataSvc
);
217
if
( mgr ) {
218
m_rootName
= mgr->rootName();
219
return
sc
;
220
}
221
log <<
MSG::ERROR
<<
"Failed to retrieve IDataManagerSvc interface."
<<
endmsg
;
222
return
StatusCode::FAILURE
;
223
}
224
log <<
MSG::ERROR
<<
"Failed to access service \""
225
<<
m_dataSvcName
<<
"\"."
<<
endmsg
;
226
return
StatusCode::FAILURE
;
227
}
228
230
virtual
StatusCode
finalize
() {
231
if
(
m_dataSvc
)
m_dataSvc
->
release
();
232
m_dataSvc
= 0;
233
return
StatusCode::SUCCESS
;
234
}
235
237
virtual
StatusCode
execute
() {
238
MsgStream
log
(
msgSvc
(),
name
());
239
SmartDataPtr<DataObject>
root
(
m_dataSvc
,
m_rootName
);
240
if
( ((
m_print
>
m_total
++) || (
m_frequency
*
m_total
>
m_frqPrint
)) && root ) {
241
if
(
m_frequency
*
m_total
>
m_frqPrint
) {
242
m_frqPrint
++;
243
}
244
std::string
store_name =
"Unknown"
;
245
IRegistry
* pReg = root->
registry
();
246
if
( pReg ) {
247
SmartIF<IService>
isvc(pReg->
dataSvc
());
248
if
( isvc ) {
249
store_name = isvc->name();
250
}
251
}
252
log <<
MSG::INFO
<<
"========= "
<<
m_rootName
<<
"["
253
<<
"0x"
<<
std::hex
<< (
unsigned
long) root.
ptr
() <<
std::dec
254
<<
"@"
<< store_name <<
"]:"
<<
endmsg
;
255
std::vector<bool>
flg;
256
flg.
push_back
(
true
);
257
explore
(root->
registry
(), flg);
258
return
StatusCode::SUCCESS
;
259
}
260
else
if
( root ) {
261
return
StatusCode::SUCCESS
;
262
}
263
log <<
MSG::ERROR
<<
"Cannot retrieve \"/Event\"!"
<<
endmsg
;
264
return
StatusCode::FAILURE
;
265
}
266
};
267
268
DECLARE_ALGORITHM_FACTORY
(
StoreExplorerAlg
)
Generated at Wed Dec 4 2013 14:33:07 for Gaudi Framework, version v24r2 by
Doxygen
version 1.8.2 written by
Dimitri van Heesch
, © 1997-2004