| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

- 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
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;
42 long m_frqPrint;
44 bool m_load;
46 bool m_testAccess;
48 bool m_accessForeign;
50 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), 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 */
134 access((ObjectList<ContainedObject>*)base);
135 break;
136 case CLID_ObjectVector>>16: /* ObjectVector */
137 access((ObjectVector<ContainedObject>*)base);
138 break;
139 case (CLID_ObjectVector+0x00030000)>>16: /* Keyed Map */
140 access((KeyedContainer<KeyedObject<int>,Containers::Map>*)base);
141 break;
142 case (CLID_ObjectVector+0x00040000)>>16: /* Keyed Hashmap */
143 access((KeyedContainer<KeyedObject<int>,Containers::HashMap>*)base);
144 break;
145 case (CLID_ObjectVector+0x00050000)>>16: /* Keyed array */
146 access((KeyedContainer<KeyedObject<int>,Containers::Array>*)base);
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 ) {
161 SmartIF<IDataManagerSvc> mgr(eventSvc());
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 = "";
212 StatusCode sc = service(m_dataSvcName, m_dataSvc, true);
213 if ( sc.isSuccess() ) {
214 SmartIF<IDataManagerSvc> mgr(m_dataSvc);
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());
237 SmartDataPtr<DataObject> root(m_dataSvc,m_rootName);
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
266 DECLARE_COMPONENT(StoreExplorerAlg)