18#include "GaudiKernel/FileIncident.h"
19#include "GaudiKernel/ISvcLocator.h"
20#include "GaudiKernel/Incident.h"
21#include "GaudiKernel/System.h"
29static constexpr std::string
levelNames[MSG::NUM_LEVELS] = {
"NIL",
"VERBOSE",
"DEBUG",
"INFO",
30 "WARNING",
"ERROR",
"FATAL",
"ALWAYS"};
34char* AthenaSummarySvc::s_block =
nullptr;
35bool AthenaSummarySvc::s_badalloc =
false;
36const char*
const II(
"\001");
46 PD(
const string&
a,
const string& b) {
add(
a,b); }
48 void add(
const string&
a,
const char* b) {
51 void add(
const string&
a,
const string& b) {
54 void add(
const string&
a,
const PD& p) {
55 m_dat[
a].push_back( p.dump() );
58 void add(
const string&
a,
const T t) {
59 m_dat[
a].push_back(std::format(
"\001{}", t));
62 operator const string ()
const
69 map<string,vector<string> >::const_iterator itr;
71 for (itr=
m_dat.begin(); itr !=
m_dat.end(); ++itr) {
72 if (
x.length() > 1) {
x+=
','; }
73 x +=
"\"" + itr->first +
"\":";
74 vector<string> v = itr->second;
75 if (v.size() > 1) {
x +=
'['; }
76 for (iv = 0; iv < v.size(); ++iv) {
77 if (iv > 0) {
x +=
','; }
78 if (v[iv][0] ==
'{') {
80 }
else if (v[iv].compare(0,1,
II)==0) {
81 x.append( v[iv], 1,v[iv].
length());
83 x +=
"\"" + v[iv] +
"\"";
86 if (v.size() > 1) {
x +=
']'; }
95 map<string, vector<string> >
m_dat;
103 std::transform(s.begin(), s.end(), s.begin(),
104 [](
unsigned char c){ return std::tolower(c); } );
112 : base_class( name, svc ),
125 p_incSvc->addListener(
this,
"BeginInputFile", pri,
true);
126 p_incSvc->addListener(
this,
"EndInputFile", pri,
true);
127 p_incSvc->addListener(
this,
"BeginOutputFile", pri,
true);
128 p_incSvc->addListener(
this,
"FailOutputFile", pri,
true);
129 p_incSvc->addListener(
this,
"WroteToOutputFile", pri,
true);
130 p_incSvc->addListener(
this,
"EndOutputFile", pri,
true);
132 p_incSvc->addListener(
this,
"AbortEvent", pri,
true);
134 p_incSvc->addListener(
this,
"BeginEvent", pri,
true);
135 p_incSvc->addListener(
this,
"EndEvent", pri,
true);
136 p_incSvc->addListener(
this,
"BeginRun", pri,
true);
137 p_incSvc->addListener(
this,
"EndRun", pri,
true);
139 p_incSvc->addListener(
this,
"FirstInputFile", pri,
true );
141 vector<string>::const_iterator itr;
149 ATH_MSG_INFO(
"unable dcast IMessageSvc to ILoggedMessageSvc: "
150 "not scanning for keywords in logs, or printing logged messages");
154 IProperty *ip =
dynamic_cast<IProperty*
>(
p_logMsg );
156 if (ip->setProperty(
m_keywords).isFailure()) {
157 ATH_MSG_ERROR(
"could not set keywords property of LoggedMessageSvc");
160 <<
"\". CAVEAT EMPTOR - THIS IS VERY SLOW!!");
163 ATH_MSG_ERROR(
"could not dcast LoggedMessageSvc to IProperty");
174 const long pageSize = sysconf( _SC_PAGESIZE );
175 if (pageSize < 1 || pageSize > 1024*1024*1024) {
177 return StatusCode::FAILURE;
179 s_block =
new char[ pageSize * 100 ];
182 return StatusCode(s_block!=
nullptr);
190 delete[] s_block; s_block =
nullptr;
191 long pageSize = sysconf( _SC_PAGESIZE );
192 if (pageSize < 1 || pageSize > 1024*1024*1024) {
194 return StatusCode::FAILURE;
196 s_block =
new char[ pageSize * 100 ];
197 return s_block ? StatusCode::SUCCESS : StatusCode::FAILURE;
207 delete[] s_block; s_block =
nullptr;
208 std::set_new_handler(
m_new );
210 return StatusCode::SUCCESS;
221 p_incSvc->addListener(
this, inc, 100,
true);
249 throw std::bad_alloc();
252 delete[] s_block; s_block =
nullptr;
255 std::cerr <<
"AthenaSummarySvc FATAL out of memory: saving summary ..."
258 SmartIF<IAthenaSummarySvc> ipa(Gaudi::svcLocator()->service(
"AthenaSummarySvc"));
262 if ( System::backTrace(btrace,5,3) ) {
263 ipa->addSummary(
"badalloc backtrace",btrace);
267 ipa->createSummary().ignore();
269 std::cerr <<
"AthenaSummarySvc ERROR unable to get hold of myself and print summary"
277 throw std::bad_alloc();
286 ATH_MSG_DEBUG(
"handle incident: " << inc.type() <<
" " << inc.source());
290 const FileIncident *fi =
dynamic_cast<const FileIncident*
>( &inc );
293 ATH_MSG_INFO(
" -> file incident: " << fi->fileName() <<
" [GUID: " << fi->fileGuid() <<
"]");
294 fileName = fi->fileName();
296 fileName = inc.source();
299 if (inc.type() ==
"BeginInputFile" ) {
301 }
else if (inc.type() ==
"BeginOutputFile") {
303 }
else if (inc.type() ==
"FailOutputFile") {
305 }
else if (inc.type() ==
"BeginEvent") {
307 }
else if (inc.type() ==
"SkipEvent") {
309 }
else if (inc.type() ==
"WriteEvent") {
311 }
else if (inc.type() ==
"BeginRun") {
313 }
else if (inc.type() ==
"EndRun") {
316 map<std::string, map<string,int> >::iterator itr
321 if (it != itr->second.end()) {
342 return StatusCode::FAILURE;
357 return StatusCode::SUCCESS;
369 list<string>::const_iterator itr;
373 ofs <<
" " << *itr <<
'\n';
378 ofs <<
" " << *itr <<
'\n';
383 ofs <<
" " << *itr <<
'\n';
390 ofs <<
"Runs: " <<
m_runs <<
'\n';
393 ofs <<
"Message Count: " <<
'\n';
394 ofs <<
" FATAL: " << msgSvc()->messageCount( MSG::FATAL ) <<
'\n';
395 ofs <<
" ERROR: " << msgSvc()->messageCount( MSG::ERROR ) <<
'\n';
396 ofs <<
" WARNING: " << msgSvc()->messageCount( MSG::WARNING ) <<
'\n';
397 ofs <<
" INFO: " << msgSvc()->messageCount( MSG::INFO ) <<
'\n';
401 IntegerProperty thresh(
"loggingLevel",MSG::VERBOSE);
402 IProperty *ip =
dynamic_cast<IProperty*
>(
p_logMsg );
404 if (ip->getProperty(&thresh).isFailure()) {
405 ATH_MSG_ERROR(
"could not get loggingLevel property of LoggedMessageSvc");
408 ATH_MSG_ERROR(
"could not dcast LoggedMessageSvc to IProperty");
413 ofs <<
"Message Log: " <<
'\n';
414 vector<pair<string,string> > msgs;
415 vector<pair<string,string> >::const_iterator mitr;
416 for (
unsigned int l=thresh.value(); l < MSG::ALWAYS; l++) {
418 msgs =
p_logMsg->getMessages( MSG::Level(l) );
419 ofs <<
" " << msgs.size() <<
'\n';
420 for (mitr=msgs.begin(); mitr != msgs.end(); ++mitr) {
421 ofs <<
" " << mitr->first <<
" : " << mitr->second <<
'\n';
425 ofs <<
"Keyword tracked messages: " <<
'\n';
426 for (
const auto&
msg :
p_logMsg->getKeyMessages()) {
429 <<
" " <<
msg.message
436 ofs <<
"Extra Summary Info:" <<
'\n';
437 vector<pair<string,string> >::const_iterator itr (
m_extraInfo.begin() );
439 ofs <<
" " << itr->first <<
" : " << itr->second <<
'\n';
444 ofs <<
"Extra Incident Counts:" <<
'\n';
445 map<string, map<string,int> >::const_iterator itr(
m_extraIncidents.begin());
447 ofs <<
" " << itr->first;
448 if (itr->second.begin() == itr->second.end()) {
449 ofs <<
" : 0" <<
'\n';
452 it != itr->second.end(); ++it) {
453 ofs <<
" :: " << it->first <<
":" << it->second;
461 ofs <<
"std::bad_alloc caught: out of memory condition detected"
465 ofs <<
"Exit Status: " <<
m_status <<
'\n';
476 list<string>::const_iterator itr;
483 if (f.length() > 0) { f +=
","; }
490 if (f.length() > 0) { f +=
","; }
493 files.add(
"write",f);
497 if (f.length() > 0) { f +=
","; }
500 files.add(
"write error",f);
502 p.add(
"files",
files);
509 p.add(
"events",events);
514 msg.add(
"FATAL",msgSvc()->messageCount( MSG::FATAL ));
515 msg.add(
"ERROR",msgSvc()->messageCount( MSG::ERROR ));
516 msg.add(
"WARNING",msgSvc()->messageCount( MSG::WARNING ));
517 msg.add(
"INFO",msgSvc()->messageCount( MSG::INFO ));
519 p.add(
"message count",
msg);
523 IntegerProperty thresh(
"loggingLevel",MSG::VERBOSE);
524 IProperty *ip =
dynamic_cast<IProperty*
>(
p_logMsg );
526 if (ip->getProperty(&thresh).isFailure()) {
527 ATH_MSG_ERROR(
"could not get loggingLevel property of LoggedMessageSvc");
530 ATH_MSG_ERROR(
"could not dcast LoggedMessageSvc to IProperty");
534 vector<pair<string,string> > msgs;
535 vector<pair<string,string> >::const_iterator mitr;
536 for (
unsigned int l=thresh.value(); l < MSG::ALWAYS; l++) {
538 msgs =
p_logMsg->getMessages( MSG::Level(l) );
539 for (mitr=msgs.begin(); mitr != msgs.end(); ++mitr) {
540 slog.
add(mitr->first, mitr->second);
545 p.add(
"messages",mlog);
551 vector<pair<string,string> >::const_iterator itr (
m_extraInfo.begin() );
553 string dat = itr->second;
554 while( dat.find(
"\n") != string::npos) {
555 dat.erase(dat.find(
"\n"),1);
557 user.add(itr->first, dat);
559 p.add(
"user data",user);
564 map<string, map<string,int> >::const_iterator itr(
m_extraIncidents.begin());
566 if (itr->second.begin() == itr->second.end()) {
567 inc.
add(itr->first,0);
571 it != itr->second.end(); ++it) {
572 inc2.
add(it->first, it->second);
574 inc.
add(itr->first, inc2);
584 p.add(
"extra incidents",inc);
588 p.add(
"bad_alloc",s_badalloc);
590 ofd << p.dump() << endl;
const char *const II("\001")
static constexpr std::string levelNames[MSG::NUM_LEVELS]
void tolower(std::string &s)
std::list< std::string > m_outputFilesError
StringArrayProperty m_extraInc
virtual StatusCode createSummary() override
std::vector< std::pair< std::string, std::string > > m_extraInfo
StringArrayProperty m_keywords
void createASCII(std::ofstream &)
unsigned int m_eventsWritten
ServiceHandle< IIncidentSvc > p_incSvc
std::list< std::string > m_inputFilesRead
virtual void addListener(const std::string &incident_name) override
std::map< std::string, std::map< std::string, int > > m_extraIncidents
StringProperty m_summaryFile
std::list< std::string > m_outputFiles
void createDict(std::ofstream &)
AthenaSummarySvc(const std::string &name, ISvcLocator *svc)
virtual StatusCode initialize() override
virtual StatusCode reinitialize() override
StringProperty m_summaryFormat
virtual StatusCode finalize() override
virtual void handle(const Incident &inc) override
virtual void addSummary(const std::string &dict_key, const std::string &data) override
ILoggedMessageSvc * p_logMsg
unsigned int m_eventsRead
unsigned int m_eventsSkipped
Extends IMessageSvc to get logged messages.
void add(const string &a, const T t)
void add(const string &a, const char *b)
PD(const string &a, const string &b)
void add(const string &a, const string &b)
void add(const string &a, const PD &p)
map< string, vector< string > > m_dat
std::vector< std::string > files
file names and file pointers