18#include "GaudiKernel/FileIncident.h"
19#include "GaudiKernel/ISvcLocator.h"
20#include "GaudiKernel/Incident.h"
21#include "GaudiKernel/System.h"
30static constexpr std::string
levelNames[MSG::NUM_LEVELS] = {
"NIL",
"VERBOSE",
"DEBUG",
"INFO",
31 "WARNING",
"ERROR",
"FATAL",
"ALWAYS"};
35char* AthenaSummarySvc::s_block =
nullptr;
36bool AthenaSummarySvc::s_badalloc =
false;
37const char*
const II(
"\001");
47 PD(
const string&
a,
const string& b) {
add(
a,b); }
49 void add(
const string&
a,
const char* b) {
52 void add(
const string&
a,
const string& b) {
55 void add(
const string&
a,
const PD& p) {
56 m_dat[
a].push_back( p.dump() );
59 void add(
const string&
a,
const T t) {
60 m_dat[
a].push_back(std::format(
"\001{}", t));
63 operator const string ()
const
70 map<string,vector<string> >::const_iterator itr;
72 for (itr=
m_dat.begin(); itr !=
m_dat.end(); ++itr) {
73 if (
x.length() > 1) {
x+=
','; }
74 x +=
"\"" + itr->first +
"\":";
75 vector<string> v = itr->second;
76 if (v.size() > 1) {
x +=
'['; }
77 for (iv = 0; iv < v.size(); ++iv) {
78 if (iv > 0) {
x +=
','; }
79 if (v[iv][0] ==
'{') {
81 }
else if (v[iv].compare(0,1,
II)==0) {
82 x.append( v[iv], 1,v[iv].
length());
84 x +=
"\"" + v[iv] +
"\"";
87 if (v.size() > 1) {
x +=
']'; }
96 map<string, vector<string> >
m_dat;
104 std::transform(s.begin(), s.end(), s.begin(),
105 [](
unsigned char c){ return std::tolower(c); } );
113 : base_class( name, svc ),
126 p_incSvc->addListener(
this,
"BeginInputFile", pri,
true);
127 p_incSvc->addListener(
this,
"EndInputFile", pri,
true);
128 p_incSvc->addListener(
this,
"BeginOutputFile", pri,
true);
129 p_incSvc->addListener(
this,
"FailOutputFile", pri,
true);
130 p_incSvc->addListener(
this,
"WroteToOutputFile", pri,
true);
131 p_incSvc->addListener(
this,
"EndOutputFile", pri,
true);
133 p_incSvc->addListener(
this,
"AbortEvent", pri,
true);
135 p_incSvc->addListener(
this,
"BeginEvent", pri,
true);
136 p_incSvc->addListener(
this,
"EndEvent", pri,
true);
137 p_incSvc->addListener(
this,
"BeginRun", pri,
true);
138 p_incSvc->addListener(
this,
"EndRun", pri,
true);
140 p_incSvc->addListener(
this,
"FirstInputFile", pri,
true );
142 vector<string>::const_iterator itr;
150 ATH_MSG_INFO(
"unable dcast IMessageSvc to ILoggedMessageSvc: "
151 "not scanning for keywords in logs, or printing logged messages");
155 IProperty *ip =
dynamic_cast<IProperty*
>(
p_logMsg );
157 if (ip->setProperty(
m_keywords).isFailure()) {
158 ATH_MSG_ERROR(
"could not set keywords property of LoggedMessageSvc");
160 ATH_MSG_INFO(
"Scanning log for keyword \"{}\". CAVEAT EMPTOR - THIS IS VERY SLOW!!",
164 ATH_MSG_ERROR(
"could not dcast LoggedMessageSvc to IProperty");
175 const long pageSize = sysconf( _SC_PAGESIZE );
176 if (pageSize < 1 || pageSize > 1024*1024*1024) {
178 return StatusCode::FAILURE;
180 s_block =
new char[ pageSize * 100 ];
183 return StatusCode(s_block!=
nullptr);
191 delete[] s_block; s_block =
nullptr;
192 long pageSize = sysconf( _SC_PAGESIZE );
193 if (pageSize < 1 || pageSize > 1024*1024*1024) {
195 return StatusCode::FAILURE;
197 s_block =
new char[ pageSize * 100 ];
198 return s_block ? StatusCode::SUCCESS : StatusCode::FAILURE;
208 delete[] s_block; s_block =
nullptr;
209 std::set_new_handler(
m_new );
211 return StatusCode::SUCCESS;
222 p_incSvc->addListener(
this, inc, 100,
true);
250 throw std::bad_alloc();
253 delete[] s_block; s_block =
nullptr;
256 std::println (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::println (std::cerr,
"AthenaSummarySvc ERROR unable to get hold of myself and print summary");
276 throw std::bad_alloc();
285 ATH_MSG_DEBUG(
"handle incident: {} {}", inc.type(), inc.source());
289 const FileIncident *fi =
dynamic_cast<const FileIncident*
>( &inc );
293 fi->fileName(), 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()) {
343 return StatusCode::FAILURE;
358 return StatusCode::SUCCESS;
370 list<string>::const_iterator itr;
374 std::println (ofs,
" {}", *itr);
377 std::println (ofs,
"Files written: {}",
m_outputFiles.size());
379 std::println (ofs,
" {}", *itr);
384 std::println (ofs,
" {}", *itr);
391 std::println (ofs,
"Runs: {}",
m_runs);
394 std::println (ofs,
"Message Count: ");
395 std::println (ofs,
" FATAL: {}", msgSvc()->messageCount( MSG::FATAL ));
396 std::println (ofs,
" ERROR: {}", msgSvc()->messageCount( MSG::ERROR ));
397 std::println (ofs,
" WARNING: {}", msgSvc()->messageCount( MSG::WARNING ));
398 std::println (ofs,
" INFO: {}", msgSvc()->messageCount( MSG::INFO ));
402 IntegerProperty thresh(
"loggingLevel",MSG::VERBOSE);
403 IProperty *ip =
dynamic_cast<IProperty*
>(
p_logMsg );
405 if (ip->getProperty(&thresh).isFailure()) {
406 ATH_MSG_ERROR(
"could not get loggingLevel property of LoggedMessageSvc");
409 ATH_MSG_ERROR(
"could not dcast LoggedMessageSvc to IProperty");
414 std::println (ofs,
"Message Log: ");
415 vector<pair<string,string> > msgs;
416 vector<pair<string,string> >::const_iterator mitr;
417 for (
unsigned int l=thresh.value(); l < MSG::ALWAYS; l++) {
419 msgs =
p_logMsg->getMessages( MSG::Level(l) );
420 std::println (ofs,
" {}", msgs.size());
421 for (mitr=msgs.begin(); mitr != msgs.end(); ++mitr) {
422 std::println (ofs,
" {} : {}", mitr->first, mitr->second);
426 std::println (ofs,
"Keyword tracked messages: ");
427 for (
const auto&
msg :
p_logMsg->getKeyMessages()) {
428 std::println (ofs,
" {} {} {}",
435 std::println (ofs,
"Extra Summary Info:");
436 vector<pair<string,string> >::const_iterator itr (
m_extraInfo.begin() );
438 std::println (ofs,
" {} : {}", itr->first, itr->second);
443 std::println (ofs,
"Extra Incident Counts:");
444 map<string, map<string,int> >::const_iterator itr(
m_extraIncidents.begin());
446 std::print (ofs,
" {}", itr->first);
447 if (itr->second.begin() == itr->second.end()) {
448 std::println (ofs,
" : 0");
451 it != itr->second.end(); ++it) {
452 std::print (ofs,
" :: {}: {}", it->first, it->second);
460 std::println (ofs,
"std::bad_alloc caught: out of memory condition detected");
463 std::println (ofs,
"Exit Status: {}",
m_status);
474 list<string>::const_iterator itr;
481 if (f.length() > 0) { f +=
","; }
488 if (f.length() > 0) { f +=
","; }
491 files.add(
"write",f);
495 if (f.length() > 0) { f +=
","; }
498 files.add(
"write error",f);
500 p.add(
"files",
files);
507 p.add(
"events",events);
512 msg.add(
"FATAL",msgSvc()->messageCount( MSG::FATAL ));
513 msg.add(
"ERROR",msgSvc()->messageCount( MSG::ERROR ));
514 msg.add(
"WARNING",msgSvc()->messageCount( MSG::WARNING ));
515 msg.add(
"INFO",msgSvc()->messageCount( MSG::INFO ));
517 p.add(
"message count",
msg);
521 IntegerProperty thresh(
"loggingLevel",MSG::VERBOSE);
522 IProperty *ip =
dynamic_cast<IProperty*
>(
p_logMsg );
524 if (ip->getProperty(&thresh).isFailure()) {
525 ATH_MSG_ERROR(
"could not get loggingLevel property of LoggedMessageSvc");
528 ATH_MSG_ERROR(
"could not dcast LoggedMessageSvc to IProperty");
532 vector<pair<string,string> > msgs;
533 vector<pair<string,string> >::const_iterator mitr;
534 for (
unsigned int l=thresh.value(); l < MSG::ALWAYS; l++) {
536 msgs =
p_logMsg->getMessages( MSG::Level(l) );
537 for (mitr=msgs.begin(); mitr != msgs.end(); ++mitr) {
538 slog.
add(mitr->first, mitr->second);
543 p.add(
"messages",mlog);
549 vector<pair<string,string> >::const_iterator itr (
m_extraInfo.begin() );
551 string dat = itr->second;
552 while( dat.find(
"\n") != string::npos) {
553 dat.erase(dat.find(
"\n"),1);
555 user.add(itr->first, dat);
557 p.add(
"user data",user);
562 map<string, map<string,int> >::const_iterator itr(
m_extraIncidents.begin());
564 if (itr->second.begin() == itr->second.end()) {
565 inc.
add(itr->first,0);
569 it != itr->second.end(); ++it) {
570 inc2.
add(it->first, it->second);
572 inc.
add(itr->first, inc2);
582 p.add(
"extra incidents",inc);
586 p.add(
"bad_alloc",s_badalloc);
588 std::println (ofd,
"{}", p.dump());
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_INFO(x,...)
#define ATH_MSG_FATAL(x,...)
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