ATLAS Offline Software
Loading...
Searching...
No Matches
SGAudSvc Class Reference

This service gives a graphical representation of algorithms accessing StoreGate. More...

#include <SGAudSvc.h>

Inheritance diagram for SGAudSvc:
Collaboration diagram for SGAudSvc:

Public Member Functions

 SGAudSvc (const std::string &name, ISvcLocator *pSvcLocator)
 Constructor with parameters:
virtual StatusCode initialize () override
 Gaudi Service Implementation.
virtual StatusCode finalize () override
virtual void handle (const Incident &incident) override
 incident service handle for EndEvent.
virtual void SGAudit (const std::string &key, const CLID &id, const int &fnc, const int &store_id) override
bool SGGetCurrentAlg ()
 Gets name of curently running algorithm from AlgContextSvc.
virtual void setFakeCurrentAlg (const std::string &) override
 For implementing custom increased granularity auditing of for instance tools.
virtual void clearFakeCurrentAlg () override
 For implementing custom increased granularity auditing of for instance tools.

Private Types

typedef std::map< std::string, std::set< std::string > > DataMap

Private Member Functions

 SGAudSvc ()
 Default constructor:
void SGAudRETRIEVE (std::string SGobject)
void SGAudRECORD (std::string SGobject)
void getNobj (const std::string &name)
void addRead ()
void addWrite ()
void monitor ()
 just counts events. called at EndEvent incident
void writeJSON ()

Private Attributes

Gaudi::Property< std::string > m_outFileName
Gaudi::Property< std::string > m_allFileName
Gaudi::Property< std::string > m_sumFileName
Gaudi::Property< bool > m_ignoreFakeAlgs
Gaudi::Property< int > m_startEvent
Gaudi::Property< bool > m_useCLID
ServiceHandle< IAlgContextSvc > p_algCtxSvc
 Pointer to the AlgContextScv.
ServiceHandle< IClassIDSvc > m_pCID
std::vector< std::string > m_vObj
 Vector of accessed SG objects names.
std::vector< std::string > m_vAlg
 Vector of names of algorithms accessing SG.
std::map< int, int > m_timesRead
 map counting Reads of each object by each algorithm.
std::map< int, int > m_timesWritten
 map counting Writes of each object by each algorithm.
std::string m_currAlg
std::string m_currObj
std::string m_fakeCurrAlg
int m_nCurrAlg {0}
int m_nCurrObj {0}
int m_nEvents {0}
DataMap m_read
DataMap m_write
std::ofstream m_ofa
std::ofstream m_ofs
bool m_inExec {false}

Detailed Description

This service gives a graphical representation of algorithms accessing StoreGate.

SGAudSvc instruments retrieve and record functions of StoreGate and from there gets names of objects accessed. Upon getting an object name it asks AlgContexSvc for the name of the current algorithm. At the end of run, an ASCII file is produced (SGAudSvc.out).

By default data are not collected for the first three events.

Definition at line 42 of file SGAudSvc.h.

Member Typedef Documentation

◆ DataMap

typedef std::map<std::string, std::set<std::string> > SGAudSvc::DataMap
private

Definition at line 138 of file SGAudSvc.h.

Constructor & Destructor Documentation

◆ SGAudSvc() [1/2]

SGAudSvc::SGAudSvc ( const std::string & name,
ISvcLocator * pSvcLocator )

Constructor with parameters:

Definition at line 39 of file SGAudSvc.cxx.

39 :
40 base_class ( name, pSvcLocator ),
41 p_algCtxSvc("AlgContextSvc", name),
42 m_pCID("ClassIDSvc", name)
43{
44}
ServiceHandle< IClassIDSvc > m_pCID
Definition SGAudSvc.h:120
ServiceHandle< IAlgContextSvc > p_algCtxSvc
Pointer to the AlgContextScv.
Definition SGAudSvc.h:119

◆ SGAudSvc() [2/2]

SGAudSvc::SGAudSvc ( )
private

Default constructor:

Member Function Documentation

◆ addRead()

void SGAudSvc::addRead ( )
private

Definition at line 356 of file SGAudSvc.cxx.

356 {
357 int oaHash=m_nCurrObj*1000 + m_nCurrAlg;
358 if (m_timesRead.end()!=m_timesRead.find(oaHash)){
359 m_timesRead.find(oaHash)->second++;
360 }
361 else{
362 std::pair<int,int> p(oaHash,1);
363 m_timesRead.insert(p);
364 }
365 return;
366}
std::map< int, int > m_timesRead
map counting Reads of each object by each algorithm.
Definition SGAudSvc.h:127
int m_nCurrObj
Definition SGAudSvc.h:134
int m_nCurrAlg
Definition SGAudSvc.h:133

◆ addWrite()

void SGAudSvc::addWrite ( )
private

Definition at line 371 of file SGAudSvc.cxx.

371 {
372 int oaHash=m_nCurrObj*1000 + m_nCurrAlg;
373 if (m_timesWritten.end()!=m_timesWritten.find(oaHash)){
374 m_timesWritten.find(oaHash)->second++;
375 }
376 else{
377 std::pair<int,int> p(oaHash,1);
378 m_timesWritten.insert(p);
379 }
380 return;
381}
std::map< int, int > m_timesWritten
map counting Writes of each object by each algorithm.
Definition SGAudSvc.h:129

◆ clearFakeCurrentAlg()

void SGAudSvc::clearFakeCurrentAlg ( )
overridevirtual

For implementing custom increased granularity auditing of for instance tools.

Definition at line 391 of file SGAudSvc.cxx.

391{ m_fakeCurrAlg.clear(); }
std::string m_fakeCurrAlg
Definition SGAudSvc.h:132

◆ finalize()

StatusCode SGAudSvc::finalize ( )
overridevirtual

Definition at line 81 of file SGAudSvc.cxx.

81 {
82
83 if (m_vAlg.size()==0) {
84 ATH_MSG_WARNING("No data gathered. This might be because you did not run over at least 3 events.");
85 return StatusCode::SUCCESS;
86 }
87
88 ATH_MSG_INFO("Writing output to: "<<m_outFileName);
89 std::ofstream f( m_outFileName.value().c_str() );
90
91 f << "Algs: " << m_vAlg.size() << std::endl;
92 std::vector<std::string>::iterator i;
93 for (i=m_vAlg.begin();i<m_vAlg.end();++i) {
94 f << (*i) << std::endl;
95 }
96
97 f << "Obj: "<< m_vObj.size()<<std::endl;
98 for (i=m_vObj.begin();i<m_vObj.end();++i) {
99 f << (*i) << std::endl;
100 }
101
102
103 for (unsigned int w=0;w<m_vAlg.size();w++){
104 for(unsigned int q=0;q<m_vObj.size();q++){
105 int oaHash=q*1000 + w;
106 if (m_timesRead.find(oaHash)==m_timesRead.end())
107 f << "0:";
108 else
109 f << m_timesRead.find(oaHash)->second << ":";
110 if (m_timesWritten.find(oaHash)==m_timesWritten.end())
111 f << "0\t";
112 else
113 f << m_timesWritten.find(oaHash)->second << "\t";
114 }
115 f << std::endl;
116 }
117
118 f.close();
119
120 if (m_ofa.is_open()) m_ofa.close();
121
122 if (m_ofs.is_open()) {
123
124 writeJSON();
125
126 m_ofs.close();
127 }
128
129
130 return StatusCode::SUCCESS;
131}
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
Gaudi::Property< std::string > m_outFileName
Definition SGAudSvc.h:100
std::ofstream m_ofs
Definition SGAudSvc.h:142
std::vector< std::string > m_vAlg
Vector of names of algorithms accessing SG.
Definition SGAudSvc.h:125
void writeJSON()
Definition SGAudSvc.cxx:396
std::vector< std::string > m_vObj
Vector of accessed SG objects names.
Definition SGAudSvc.h:123
std::ofstream m_ofa
Definition SGAudSvc.h:142

◆ getNobj()

void SGAudSvc::getNobj ( const std::string & name)
private

Definition at line 336 of file SGAudSvc.cxx.

336 {
337 std::vector<std::string>::iterator i;
338 int index=0;
339 for (i=m_vObj.begin();i<m_vObj.end();++i){
340 if (*i==name) {
343 return;
344 }
345 index++;
346 }
347 m_vObj.push_back(name);
350return;
351}
std::string m_currObj
Definition SGAudSvc.h:131
str index
Definition DeMoScan.py:362

◆ handle()

void SGAudSvc::handle ( const Incident & incident)
overridevirtual

incident service handle for EndEvent.

Calls monitor. There should be more elegant way to get number of events passed.

Definition at line 136 of file SGAudSvc.cxx.

137{
138 ATH_MSG_VERBOSE("Entering handle(). Incidence type: " << inc.type() <<
139 " from: " << inc.source());
140
141 if (inc.type() == IncidentType::BeginEvent) {
142 if (m_ofa.is_open())
143 m_ofa << "---- BEGIN EVENT " << m_nEvents << " ----" << std::endl;
144 m_inExec = true;
145
146 }
147
148 // Performing performance-monitoring for EndEvent incident
149 if ( inc.type() == IncidentType::EndEvent ) {
150 monitor();
151
152 if (m_ofa.is_open())
153 m_ofa << "---- END EVENT " << m_nEvents << " ----" << std::endl;
154 m_inExec = false;
155
156 }
157
158 // Performing performance-monitoring for BeginRun incident
159 // at this point everybody has been initialized, we can harvest performance
160 // data for the initialize step.
161
162 if ( inc.type() == IncidentType::BeginRun ) {
163 monitor();
164 }
165
166 return;
167}
#define ATH_MSG_VERBOSE(x)
bool m_inExec
Definition SGAudSvc.h:143
void monitor()
just counts events. called at EndEvent incident
Definition SGAudSvc.cxx:173
int m_nEvents
Definition SGAudSvc.h:135

◆ initialize()

StatusCode SGAudSvc::initialize ( )
overridevirtual

Gaudi Service Implementation.

Definition at line 52 of file SGAudSvc.cxx.

52 {
53
54 ATH_MSG_INFO("Initializing " << name() << "..." );
55
56 ATH_CHECK( p_algCtxSvc.retrieve() );
57 ATH_CHECK( m_pCID.retrieve() );
58
59 if (m_allFileName != "") {
60 m_ofa.open(m_allFileName.value().c_str());
61 }
62
63 if (m_sumFileName != "") {
64 m_ofs.open(m_sumFileName.value().c_str());
65 }
66
67 // Set to be listener for end-of-event
68 ServiceHandle<IIncidentSvc> incSvc( "IncidentSvc", this->name() );
69 ATH_CHECK( incSvc.retrieve() );
70
71 incSvc->addListener( this, IncidentType::BeginRun );
72 incSvc->addListener( this, IncidentType::BeginEvent );
73 incSvc->addListener( this, IncidentType::EndEvent );
74
75 return StatusCode::SUCCESS;
76}
#define ATH_CHECK
Evaluate an expression and check for errors.
Gaudi::Property< std::string > m_sumFileName
Definition SGAudSvc.h:106
Gaudi::Property< std::string > m_allFileName
Definition SGAudSvc.h:103

◆ monitor()

void SGAudSvc::monitor ( )
private

just counts events. called at EndEvent incident

Definition at line 173 of file SGAudSvc.cxx.

173 {
174 m_nEvents++;
175 return;
176}

◆ setFakeCurrentAlg()

void SGAudSvc::setFakeCurrentAlg ( const std::string & s)
overridevirtual

For implementing custom increased granularity auditing of for instance tools.

Definition at line 386 of file SGAudSvc.cxx.

◆ SGAudit()

void SGAudSvc::SGAudit ( const std::string & key,
const CLID & id,
const int & fnc,
const int & store_id )
overridevirtual

Definition at line 226 of file SGAudSvc.cxx.

227 {
228
229 // we can sometimes get here really early, before initialization.
230 if (m_pCID == 0) { return; }
231
232 bool a = SGGetCurrentAlg();
233
234 if (m_nEvents >= m_startEvent && store_id == 0 && a) {
235 if (typ == 0) {
236 SGAudRETRIEVE(key);
237 } else {
238 SGAudRECORD(key);
239 }
240 }
241
242 std::string idname;
243
244 if (m_ofa.is_open() || ( m_ofs.is_open() && ! m_useCLID ) ) {
245 if( ! m_pCID->getTypeNameOfID(id,idname).isSuccess()) {
246 std::ostringstream ost;
247 ost << id;
248 idname = ost.str();
249 }
250 }
251
252 if (m_ofa.is_open()) {
253 m_ofa << ( (typ == 1) ? "RECORD" : "RETRIEVE" ) << " clid: " << id
254 << " | ";
255
256 m_ofa << idname;
257
258 m_ofa << " key: " << key << " alg: " << m_currAlg
259 << " store: " << store_id
260 << std:: endl;
261 }
262
263 // store stuff for the summary
264
265 if (!m_ofs.is_open()) return;
266
267 if (m_nEvents < m_startEvent || !m_inExec) return;
268
269 if (m_currAlg == "----") return;
270
271 std::string kk;
272 if (m_useCLID) {
273 std::ostringstream ost;
274 ost << id << "/" << key;
275 kk = ost.str();
276 } else {
277 kk = idname + "/" + key;
278 }
279
280 DataMap::iterator itr;
281 if (typ == 0) {
282 itr = m_read.find(m_currAlg);
283 if (itr != m_read.end()) {
284 itr->second.insert(std::move(kk));
285 } else {
286 m_read[m_currAlg] = std::set<std::string> ( {std::move(kk)} );
287 }
288 } else {
289 itr = m_write.find(m_currAlg);
290 if (itr != m_write.end()) {
291 itr->second.insert(std::move(kk));
292 } else {
293 m_write[m_currAlg] = std::set<std::string> ( {std::move(kk)} );
294 }
295 }
296}
static Double_t a
std::string m_currAlg
Definition SGAudSvc.h:130
void SGAudRECORD(std::string SGobject)
Definition SGAudSvc.cxx:205
DataMap m_write
Definition SGAudSvc.h:140
bool SGGetCurrentAlg()
Gets name of curently running algorithm from AlgContextSvc.
Definition SGAudSvc.cxx:301
void SGAudRETRIEVE(std::string SGobject)
Definition SGAudSvc.cxx:181
Gaudi::Property< bool > m_useCLID
Definition SGAudSvc.h:115
DataMap m_read
Definition SGAudSvc.h:139
Gaudi::Property< int > m_startEvent
Definition SGAudSvc.h:112

◆ SGAudRECORD()

void SGAudSvc::SGAudRECORD ( std::string SGobject)
private

Definition at line 205 of file SGAudSvc.cxx.

205 {
206 // if (m_nEvents<3) return;
207 if (SGobject=="") SGobject="noKey";
208 for (unsigned int i = 0; i < SGobject.length(); i++)
209 if (!std::isdigit(SGobject[i])){
210 //isAnumb=false;
211 break;
212 }
213
214 if (m_currObj==SGobject)
215 addWrite();
216 else {
217 getNobj(SGobject);
218 addWrite();
219 }
220
221 return;
222}
void getNobj(const std::string &name)
Definition SGAudSvc.cxx:336
void addWrite()
Definition SGAudSvc.cxx:371

◆ SGAudRETRIEVE()

void SGAudSvc::SGAudRETRIEVE ( std::string SGobject)
private

Definition at line 181 of file SGAudSvc.cxx.

181 {
182 // if (m_nEvents<3) return;
183 if (SGobject=="") SGobject="noKey";
184 bool isAnumb=true;
185 for (unsigned int i = 0; i < SGobject.length(); i++)
186 if (!std::isdigit(SGobject[i])){
187 isAnumb=false;
188 break;
189 }
190
191 if (!isAnumb){
192 if (m_currObj==SGobject)
193 addRead();
194 else {
195 getNobj(SGobject);
196 addRead();
197 }
198 }
199 return;
200}
void addRead()
Definition SGAudSvc.cxx:356

◆ SGGetCurrentAlg()

bool SGAudSvc::SGGetCurrentAlg ( )

Gets name of curently running algorithm from AlgContextSvc.

Definition at line 301 of file SGAudSvc.cxx.

301 {
302
303 IAlgorithm *asdf = p_algCtxSvc->currentAlg();
304 if (!asdf || m_nEvents==0) { // to skip before first event
305 m_currAlg="----";
306 m_nCurrAlg=-1;
307 return false;
308 }
309 std::string name = asdf->name();
310
311 if ( !m_ignoreFakeAlgs && !m_fakeCurrAlg.empty() )
313
314 if (name!=m_currAlg){
315 std::vector<std::string>::iterator i;
316 int index=0;
317 for (i=m_vAlg.begin();i<m_vAlg.end();++i){
318 if (*i==name) {
320 m_currAlg=std::move(name);
321 return true;
322 }
323 index++;
324 }
325 m_vAlg.push_back(name);
327 m_currAlg=std::move(name);
328 return true;
329 }
330 return true;
331}
Gaudi::Property< bool > m_ignoreFakeAlgs
Definition SGAudSvc.h:109

◆ writeJSON()

void SGAudSvc::writeJSON ( )
private

Definition at line 396 of file SGAudSvc.cxx.

396 {
397
398 DataMap::const_iterator itr;
399 std::set<std::string>::const_iterator it2;
400 std::vector<std::string>::const_iterator ia;
401
402 m_ofs << "{ \"algorithms\" : [" << std::endl;
403 for (ia = m_vAlg.begin(); ia != m_vAlg.end(); ++ia) {
404 m_ofs << " {" << std::endl;
405 m_ofs << " \"name\" : \"" << *ia << "\"," << std::endl;
406 m_ofs << " \"inputs\" : [";
407
408 itr = m_read.find(*ia);
409 if (itr != m_read.end()) {
410 for (it2 = itr->second.begin(); it2 != itr->second.end(); ++it2) {
411 if (it2 != itr->second.begin()) m_ofs << ",";
412 m_ofs << "\"" << *it2 << "\"";
413 }
414 }
415 m_ofs << "]," << std::endl;
416
417 m_ofs << " \"outputs\" : [";
418
419 itr = m_write.find(*ia);
420 if (itr != m_write.end()) {
421 for (it2 = itr->second.begin(); it2 != itr->second.end(); ++it2) {
422 if (it2 != itr->second.begin()) m_ofs << ",";
423 m_ofs << "\"" << *it2 << "\"";
424 }
425 }
426 m_ofs << "]," << std::endl;
427 m_ofs << " }," << std::endl;
428 }
429 m_ofs << " ]" << std::endl << "}" << std::endl;
430
431}

Member Data Documentation

◆ m_allFileName

Gaudi::Property<std::string> SGAudSvc::m_allFileName
private
Initial value:
{ "FullFileName", "",
"Name of the output file to hold the full SG aud data"}

Definition at line 103 of file SGAudSvc.h.

103 { "FullFileName", "",
104 "Name of the output file to hold the full SG aud data"};

◆ m_currAlg

std::string SGAudSvc::m_currAlg
private

Definition at line 130 of file SGAudSvc.h.

◆ m_currObj

std::string SGAudSvc::m_currObj
private

Definition at line 131 of file SGAudSvc.h.

◆ m_fakeCurrAlg

std::string SGAudSvc::m_fakeCurrAlg
private

Definition at line 132 of file SGAudSvc.h.

◆ m_ignoreFakeAlgs

Gaudi::Property<bool> SGAudSvc::m_ignoreFakeAlgs
private
Initial value:
{this, "IgnoreFakeAlgs", false,
"Set to ignore any attempts to override current-alg"}

Definition at line 109 of file SGAudSvc.h.

109 {this, "IgnoreFakeAlgs", false,
110 "Set to ignore any attempts to override current-alg"};

◆ m_inExec

bool SGAudSvc::m_inExec {false}
private

Definition at line 143 of file SGAudSvc.h.

143{false};

◆ m_nCurrAlg

int SGAudSvc::m_nCurrAlg {0}
private

Definition at line 133 of file SGAudSvc.h.

133{0};

◆ m_nCurrObj

int SGAudSvc::m_nCurrObj {0}
private

Definition at line 134 of file SGAudSvc.h.

134{0};

◆ m_nEvents

int SGAudSvc::m_nEvents {0}
private

Definition at line 135 of file SGAudSvc.h.

135{0};

◆ m_ofa

std::ofstream SGAudSvc::m_ofa
private

Definition at line 142 of file SGAudSvc.h.

◆ m_ofs

std::ofstream SGAudSvc::m_ofs
private

Definition at line 142 of file SGAudSvc.h.

◆ m_outFileName

Gaudi::Property<std::string> SGAudSvc::m_outFileName
private
Initial value:
{this, "OutFileName", "SGAudSvc.out",
"Name of the output file to hold SGAudSvc data"}

Definition at line 100 of file SGAudSvc.h.

100 {this, "OutFileName", "SGAudSvc.out",
101 "Name of the output file to hold SGAudSvc data"};

◆ m_pCID

ServiceHandle<IClassIDSvc> SGAudSvc::m_pCID
private

Definition at line 120 of file SGAudSvc.h.

◆ m_read

DataMap SGAudSvc::m_read
private

Definition at line 139 of file SGAudSvc.h.

◆ m_startEvent

Gaudi::Property<int> SGAudSvc::m_startEvent
private
Initial value:
{this, "StartEvent", 3,
"Event number to start recording data"}

Definition at line 112 of file SGAudSvc.h.

112 {this, "StartEvent", 3,
113 "Event number to start recording data"};

◆ m_sumFileName

Gaudi::Property<std::string> SGAudSvc::m_sumFileName
private
Initial value:
{this, "SummaryFileName", "",
"Name of the output file to hold the summary output in json format"}

Definition at line 106 of file SGAudSvc.h.

106 {this, "SummaryFileName", "",
107 "Name of the output file to hold the summary output in json format"};

◆ m_timesRead

std::map<int,int> SGAudSvc::m_timesRead
private

map counting Reads of each object by each algorithm.

Definition at line 127 of file SGAudSvc.h.

◆ m_timesWritten

std::map<int,int> SGAudSvc::m_timesWritten
private

map counting Writes of each object by each algorithm.

Definition at line 129 of file SGAudSvc.h.

◆ m_useCLID

Gaudi::Property<bool> SGAudSvc::m_useCLID
private
Initial value:
{this, "UseCLID", true,
"Use CLID or DataObj name in Summary File"}

Definition at line 115 of file SGAudSvc.h.

115 {this, "UseCLID", true,
116 "Use CLID or DataObj name in Summary File"};

◆ m_vAlg

std::vector<std::string> SGAudSvc::m_vAlg
private

Vector of names of algorithms accessing SG.

Definition at line 125 of file SGAudSvc.h.

◆ m_vObj

std::vector<std::string> SGAudSvc::m_vObj
private

Vector of accessed SG objects names.

Definition at line 123 of file SGAudSvc.h.

◆ m_write

DataMap SGAudSvc::m_write
private

Definition at line 140 of file SGAudSvc.h.

◆ p_algCtxSvc

ServiceHandle<IAlgContextSvc> SGAudSvc::p_algCtxSvc
private

Pointer to the AlgContextScv.

Definition at line 119 of file SGAudSvc.h.


The documentation for this class was generated from the following files: