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 38 of file SGAudSvc.cxx.

38 :
39 base_class ( name, pSvcLocator ),
40 p_algCtxSvc("AlgContextSvc", name),
41 m_pCID("ClassIDSvc", name)
42{
43}
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 355 of file SGAudSvc.cxx.

355 {
356 int oaHash=m_nCurrObj*1000 + m_nCurrAlg;
357 if (m_timesRead.end()!=m_timesRead.find(oaHash)){
358 m_timesRead.find(oaHash)->second++;
359 }
360 else{
361 std::pair<int,int> p(oaHash,1);
362 m_timesRead.insert(p);
363 }
364 return;
365}
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 370 of file SGAudSvc.cxx.

370 {
371 int oaHash=m_nCurrObj*1000 + m_nCurrAlg;
372 if (m_timesWritten.end()!=m_timesWritten.find(oaHash)){
373 m_timesWritten.find(oaHash)->second++;
374 }
375 else{
376 std::pair<int,int> p(oaHash,1);
377 m_timesWritten.insert(p);
378 }
379 return;
380}
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 390 of file SGAudSvc.cxx.

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

◆ finalize()

StatusCode SGAudSvc::finalize ( )
overridevirtual

Definition at line 80 of file SGAudSvc.cxx.

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

335 {
336 std::vector<std::string>::iterator i;
337 int index=0;
338 for (i=m_vObj.begin();i<m_vObj.end();++i){
339 if (*i==name) {
342 return;
343 }
344 index++;
345 }
346 m_vObj.push_back(name);
349return;
350}
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 135 of file SGAudSvc.cxx.

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

◆ initialize()

StatusCode SGAudSvc::initialize ( )
overridevirtual

Gaudi Service Implementation.

Definition at line 51 of file SGAudSvc.cxx.

51 {
52
53 ATH_MSG_INFO("Initializing " << name() << "..." );
54
55 ATH_CHECK( p_algCtxSvc.retrieve() );
56 ATH_CHECK( m_pCID.retrieve() );
57
58 if (m_allFileName != "") {
59 m_ofa.open(m_allFileName.value().c_str());
60 }
61
62 if (m_sumFileName != "") {
63 m_ofs.open(m_sumFileName.value().c_str());
64 }
65
66 // Set to be listener for end-of-event
67 ServiceHandle<IIncidentSvc> incSvc( "IncidentSvc", this->name() );
68 ATH_CHECK( incSvc.retrieve() );
69
70 incSvc->addListener( this, IncidentType::BeginRun );
71 incSvc->addListener( this, IncidentType::BeginEvent );
72 incSvc->addListener( this, IncidentType::EndEvent );
73
74 return StatusCode::SUCCESS;
75}
#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 172 of file SGAudSvc.cxx.

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

◆ setFakeCurrentAlg()

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

For implementing custom increased granularity auditing of for instance tools.

Definition at line 385 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 225 of file SGAudSvc.cxx.

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

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

◆ SGAudRETRIEVE()

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

Definition at line 180 of file SGAudSvc.cxx.

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

◆ SGGetCurrentAlg()

bool SGAudSvc::SGGetCurrentAlg ( )

Gets name of curently running algorithm from AlgContextSvc.

Definition at line 300 of file SGAudSvc.cxx.

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

◆ writeJSON()

void SGAudSvc::writeJSON ( )
private

Definition at line 395 of file SGAudSvc.cxx.

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

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: