diff --git a/Control/AthenaKernel/AthenaKernel/IAthenaSummarySvc.h b/Control/AthenaKernel/AthenaKernel/IAthenaSummarySvc.h index d50975e7924ad8452fd7a6234630b2a21e3224a1..a78093dcea970df620c3e522ba2795afab31a0c1 100644 --- a/Control/AthenaKernel/AthenaKernel/IAthenaSummarySvc.h +++ b/Control/AthenaKernel/AthenaKernel/IAthenaSummarySvc.h @@ -1,19 +1,12 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ #ifndef ATHENAKERNEL_IATHENASUMMARYSVC_H #define ATHENAKERNEL_IATHENASUMMARYSVC_H -#ifndef GAUDIKERNEL_ISERVICE_H - #include "GaudiKernel/IService.h" -#endif -#ifndef KERNEL_STATUSCODES_H - #include "GaudiKernel/StatusCode.h" -#endif -#ifndef GAUDIKERNEL_CLASSID_H - #include "GaudiKernel/ClassID.h" -#endif +#include "GaudiKernel/IService.h" +#include "GaudiKernel/StatusCode.h" #include <string> @@ -25,8 +18,7 @@ class IAthenaSummarySvc : virtual public IService { public: - /// Retrieve interface ID - static const InterfaceID& interfaceID(); + DeclareInterfaceID(IAthenaSummarySvc, 1, 0); virtual ~IAthenaSummarySvc(); @@ -35,15 +27,6 @@ public: virtual void addListener(const std::string&) = 0; virtual void addSummary(const std::string&, const std::string&) = 0; virtual const std::string& getOutputFile() const = 0; - - }; -inline -const InterfaceID& -IAthenaSummarySvc::interfaceID() { - static const InterfaceID IID("IAthenaSummarySvc", 1, 0); - return IID; -} - #endif diff --git a/Control/AthenaServices/src/AthenaSummarySvc.cxx b/Control/AthenaServices/src/AthenaSummarySvc.cxx index b45a363ba9a91b670f8e2ac6b889780710f104f7..b3236b23415b03616fb8ff8e07ca5ee56887a10f 100644 --- a/Control/AthenaServices/src/AthenaSummarySvc.cxx +++ b/Control/AthenaServices/src/AthenaSummarySvc.cxx @@ -24,7 +24,6 @@ #include "PerfMonKernel/IPerfMonSvc.h" #include "PerfMonEvent/DataModel.h" #include "AthenaKernel/ILoggedMessageSvc.h" -#include "AthenaKernel/ICoreDumpSvc.h" #include <fstream> #include <unistd.h> @@ -32,15 +31,15 @@ #include <sstream> #include <ctype.h> -static std::string levelNames[MSG::NUM_LEVELS]; +static const std::string levelNames[MSG::NUM_LEVELS] = {"NIL", "VERBOSE", "DEBUG", "INFO", + "WARNING", "ERROR", "FATAL", "ALWAYS"}; using namespace std; char* AthenaSummarySvc::s_block = nullptr; bool AthenaSummarySvc::s_badalloc = false; -const char* II("\001"); +const char* const II("\001"); -using namespace std; // /////////////////////////////////////////////////////////////////////////// @@ -114,7 +113,7 @@ public: private: map<string, vector<string> > m_dat; - static ostringstream m_ofs; + static ostringstream m_ofs ATLAS_THREAD_SAFE; }; @@ -135,45 +134,17 @@ inline void tolower(std::string &s) // AthenaSummarySvc::AthenaSummarySvc( const std::string& name, ISvcLocator* svc ) - : AthService( name, svc ), m_log(msgSvc(), name), p_incSvc("IncidentSvc",name), - p_logMsg(nullptr), - m_new(nullptr),m_status(0),m_eventsRead(0),m_eventsWritten(0), - m_eventsSkipped(0),m_runs(0) - + : base_class( name, svc ), + p_incSvc("IncidentSvc",name) { - - declareProperty("SummaryFile",m_summaryFile="AthSummary.txt","Output File"); - declareProperty("SummaryFileFormat",m_summaryFormat="both", - "output format: one of 'ascii', 'python', 'both'"); - declareProperty("ExtraIncidents", m_extraInc, "user incidets to monitor"); - declareProperty("keywords",m_keywords, - "kewords to scan for in MessageSvc. WARNING: THIS IS VERY SLOW!!!"); m_new = std::set_new_handler( &AthenaSummarySvc::newHandler ); - - levelNames[0] = "NIL"; - levelNames[1] = "VERBOSE"; - levelNames[2] = "DEBUG"; - levelNames[3] = "INFO"; - levelNames[4] = "WARNING"; - levelNames[5] = "ERROR"; - levelNames[6] = "FATAL"; - levelNames[7] = "ALWAYS"; - -} - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -AthenaSummarySvc::~AthenaSummarySvc() { - } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ StatusCode AthenaSummarySvc::initialize() { - m_log.setLevel( m_outputLevel.value() ); - - m_log << MSG::DEBUG << "Initializing AthenaSummarySvc" << endmsg; + ATH_MSG_DEBUG("Initializing AthenaSummarySvc"); int pri=100; p_incSvc->addListener( this, "BeginInputFile", pri, true); @@ -194,34 +165,29 @@ StatusCode AthenaSummarySvc::initialize() { vector<string>::const_iterator itr; for (itr=m_extraInc.value().begin(); itr != m_extraInc.value().end(); ++itr) { - m_log << MSG::DEBUG << "Tracking incident \"" << *itr << "\"" << endmsg; + ATH_MSG_DEBUG("Tracking incident \"" << *itr << "\""); addListener(*itr); } p_logMsg = dynamic_cast< ILoggedMessageSvc* > ( msgSvc().get() ); if (p_logMsg == nullptr) { - m_log << MSG::INFO << "unable dcast IMessageSvc to ILoggedMessageSvc: " - << "not scanning for keywords in logs, or printing logged messages" - << endmsg; - } else { + ATH_MSG_INFO("unable dcast IMessageSvc to ILoggedMessageSvc: " + "not scanning for keywords in logs, or printing logged messages"); + } else { if (m_keywords.value().size() > 0) { IProperty *ip = dynamic_cast<IProperty*>( p_logMsg ); if (ip != nullptr) { - if (ip->setProperty(m_keywords).isFailure()) { - m_log << MSG::ERROR - << "could not set keywords property of LoggedMessageSvc" - << endmsg; - } else { - m_log << MSG::INFO << "Scanning log for keyword \"" << m_keywords - << "\". CAVEAT EMPTOR - THIS IS VERY SLOW!!" << endmsg; - } + if (ip->setProperty(m_keywords).isFailure()) { + ATH_MSG_ERROR("could not set keywords property of LoggedMessageSvc"); + } else { + ATH_MSG_INFO("Scanning log for keyword \"" << m_keywords + << "\". CAVEAT EMPTOR - THIS IS VERY SLOW!!"); + } } else { - m_log << MSG::ERROR << "could not dcast LoggedMessageSvc to IProperty" - << endmsg; + ATH_MSG_ERROR("could not dcast LoggedMessageSvc to IProperty"); } } - } std::string fmt = m_summaryFormat.value(); @@ -229,7 +195,7 @@ StatusCode AthenaSummarySvc::initialize() { m_summaryFormat = fmt; // save some space for the summary output if we run out of memory - m_log << MSG::DEBUG << "allocating block of 100 pages" << endmsg; + ATH_MSG_DEBUG("allocating block of 100 pages"); s_block = new char[ sysconf( _SC_PAGESIZE ) * 100 ]; @@ -261,33 +227,16 @@ StatusCode AthenaSummarySvc::finalize() { /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -StatusCode -AthenaSummarySvc::queryInterface(const InterfaceID& riid, void** ppvInterface) -{ - if ( IAthenaSummarySvc::interfaceID().versionMatch(riid) ) { - *ppvInterface = (IAthenaSummarySvc*)this; - } - else { - // Interface is not directly available: try out a base class - return AthService::queryInterface(riid, ppvInterface); - } - addRef(); - return StatusCode::SUCCESS; -} - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - void AthenaSummarySvc::addListener( const std::string& inc ) { - m_log << MSG::DEBUG << "now listening to incident " << inc << endmsg; + ATH_MSG_DEBUG("now listening to incident " << inc); if (m_extraIncidents.find( inc ) == m_extraIncidents.end()) { p_incSvc->addListener( this, inc, 100, true); m_extraIncidents[inc] = map<string,int>(); } else { - m_log << MSG::INFO << "already listening to Incident " << inc << endmsg; + ATH_MSG_INFO("already listening to Incident " << inc); } } @@ -297,7 +246,7 @@ AthenaSummarySvc::addListener( const std::string& inc ) { void AthenaSummarySvc::addSummary(const std::string& dict, const std::string& info) { - m_log << MSG::DEBUG << "adding extra info: " << dict << "/" << info << endmsg; + ATH_MSG_DEBUG("adding extra info: " << dict << "/" << info); m_extraInfo.push_back( make_pair(dict,info) ); @@ -350,15 +299,14 @@ AthenaSummarySvc::newHandler() { void AthenaSummarySvc::handle(const Incident &inc) { - m_log << MSG::DEBUG << "handle incident: " << inc.type() << " " - << inc.source() << endmsg; + ATH_MSG_DEBUG("handle incident: " << inc.type() << " " << inc.source()); string fileName; const FileIncident *fi = dynamic_cast<const FileIncident*>( &inc ); if (fi != nullptr) { // FIXME!!! waiting on AthenaPoolKernel-00-00-07 - m_log << MSG::INFO << " -> file incident: " << fi->fileName() << " [GUID: " << fi->fileGuid() << "]" << endmsg; + ATH_MSG_INFO(" -> file incident: " << fi->fileName() << " [GUID: " << fi->fileGuid() << "]"); fileName = fi->fileName(); } else { fileName = inc.source(); @@ -401,17 +349,16 @@ AthenaSummarySvc::handle(const Incident &inc) { StatusCode AthenaSummarySvc::createSummary() { - m_log << MSG::DEBUG << " createSummary " << endmsg; + ATH_MSG_DEBUG("createSummary"); std::ofstream ofs; ofs.open(m_summaryFile.value().c_str()); if (!ofs) { - m_log << MSG::ERROR << "Unable to open output file \"" << m_summaryFile.value() << "\"" - << endmsg; + ATH_MSG_ERROR("Unable to open output file \"" << m_summaryFile.value() << "\""); return StatusCode::FAILURE; } - m_log << MSG::DEBUG << "Writing to \"" << m_summaryFile.value() << "\"" << endmsg; + ATH_MSG_DEBUG("Writing to \"" << m_summaryFile.value() << "\""); if (m_summaryFormat.value() == "ascii" || m_summaryFormat.value() == "both") { createASCII(ofs); @@ -433,7 +380,7 @@ AthenaSummarySvc::createSummary() { void AthenaSummarySvc::createASCII( std::ofstream& ofs ) { - m_log << MSG::DEBUG << " createASCII" << endmsg; + ATH_MSG_DEBUG("createASCII"); list<string>::const_iterator itr; @@ -471,13 +418,10 @@ AthenaSummarySvc::createASCII( std::ofstream& ofs ) { IProperty *ip = dynamic_cast<IProperty*>( p_logMsg ); if (ip != nullptr) { if (ip->getProperty(&thresh).isFailure()) { - m_log << MSG::ERROR - << "could not get loggingLevel property of LoggedMessageSvc" - << endmsg; + ATH_MSG_ERROR("could not get loggingLevel property of LoggedMessageSvc"); } } else { - m_log << MSG::ERROR << "could not dcast LoggedMessageSvc to IProperty" - << endmsg; + ATH_MSG_ERROR("could not dcast LoggedMessageSvc to IProperty"); } @@ -531,9 +475,7 @@ AthenaSummarySvc::createASCII( std::ofstream& ofs ) { // Get Perfmon data IPerfMonSvc *ipms; if (service("PerfMonSvc",ipms,false).isFailure()) { - m_log << MSG::DEBUG - << "unable to get the PerfMonSvc: not printing perf summaries" - << endmsg; + ATH_MSG_DEBUG("unable to get the PerfMonSvc: not printing perf summaries"); } else { ofs << "Monitored Components:" << endl; @@ -562,7 +504,7 @@ AthenaSummarySvc::createASCII( std::ofstream& ofs ) { void AthenaSummarySvc::createDict( std::ofstream& ofd) { - m_log << MSG::DEBUG << " createDict" << endmsg; + ATH_MSG_DEBUG("createDict"); list<string>::const_iterator itr; @@ -615,13 +557,10 @@ AthenaSummarySvc::createDict( std::ofstream& ofd) { IProperty *ip = dynamic_cast<IProperty*>( p_logMsg ); if (ip != nullptr) { if (ip->getProperty(&thresh).isFailure()) { - m_log << MSG::ERROR - << "could not get loggingLevel property of LoggedMessageSvc" - << endmsg; + ATH_MSG_ERROR("could not get loggingLevel property of LoggedMessageSvc"); } } else { - m_log << MSG::ERROR << "could not dcast LoggedMessageSvc to IProperty" - << endmsg; + ATH_MSG_ERROR("could not dcast LoggedMessageSvc to IProperty"); } PD mlog; @@ -681,9 +620,7 @@ AthenaSummarySvc::createDict( std::ofstream& ofd) { // Get Perfmon data IPerfMonSvc *ipms; if (service("PerfMonSvc",ipms,false).isFailure()) { - m_log << MSG::DEBUG - << "unable to get the PerfMonSvc: not printing perf summaries" - << endmsg; + ATH_MSG_DEBUG("unable to get the PerfMonSvc: not printing perf summaries"); } else { PD mon,ini,exe,fin; diff --git a/Control/AthenaServices/src/AthenaSummarySvc.h b/Control/AthenaServices/src/AthenaSummarySvc.h index b9b75df7773d4009eb56dd0fdc32d10be85257de..2f143a33096092007198cacf4c85c636b2578610 100644 --- a/Control/AthenaServices/src/AthenaSummarySvc.h +++ b/Control/AthenaServices/src/AthenaSummarySvc.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ #ifndef ATHENASERVICES_ATHENASUMSVC_H @@ -11,91 +11,67 @@ * AthenaSummarySvc * * Author: Charles Leggett - * $Id: $ * * Provides summary at end of athena job * *****************************************************************************/ #include "AthenaBaseComps/AthService.h" -#ifndef KERNEL_STATUSCODES_H - #include "GaudiKernel/StatusCode.h" -#endif -#ifndef GAUDIKERNEL_CLASSID_H - #include "GaudiKernel/ClassID.h" -#endif -#ifndef GAUDIKERNEL_MSGSTREAM_H - #include "GaudiKernel/MsgStream.h" -#endif -#ifndef SGTOOLS_DATAPROXY_H - #include "SGTools/DataProxy.h" -#endif - -#ifndef ATHENAKERNEL_IATHENASUMMARYSVC_H - #include "AthenaKernel/IAthenaSummarySvc.h" -#endif +#include "AthenaKernel/IAthenaSummarySvc.h" +#include "AthenaKernel/ILoggedMessageSvc.h" +#include "CxxUtils/checker_macros.h" +#include "GaudiKernel/StatusCode.h" #include "GaudiKernel/ServiceHandle.h" #include "GaudiKernel/IIncidentSvc.h" #include "GaudiKernel/IIncidentListener.h" -#include "AthenaKernel/ILoggedMessageSvc.h" #include <list> #include <map> #include <string> #include <fstream> -// Forward declarations - - -class AthenaSummarySvc: virtual public AthService, - virtual public IIncidentListener, - virtual public IAthenaSummarySvc { +class ATLAS_CHECK_THREAD_SAFETY AthenaSummarySvc : + public extends<AthService, IIncidentListener, IAthenaSummarySvc> { public: AthenaSummarySvc( const std::string& name, ISvcLocator* svc ); - - // Destructor. - virtual ~AthenaSummarySvc(); - - virtual StatusCode initialize(); - virtual StatusCode reinitialize(); - virtual StatusCode finalize(); - - virtual StatusCode queryInterface( const InterfaceID& riid, - void** ppvInterface ); - StatusCode createSummary(); - void setStatus(int s) {m_status = s;} - void addListener(const std::string& incident_name); - void addSummary(const std::string& dict_key, const std::string& data); + virtual StatusCode initialize() override; + virtual StatusCode reinitialize() override; + virtual StatusCode finalize() override; - const std::string& getOutputFile() const { return m_summaryFile; } + virtual StatusCode createSummary() override; + virtual void setStatus(int s) override {m_status = s;} + virtual void addListener(const std::string& incident_name) override; + virtual void addSummary(const std::string& dict_key, const std::string& data) override; + virtual const std::string& getOutputFile() const override { return m_summaryFile; } private: void createDict(std::ofstream& ); void createASCII(std::ofstream& ); - - // methods void handle(const Incident &inc); static void newHandler(); // properties - StringProperty m_summaryFile, m_summaryFormat; - StringArrayProperty m_extraInc, m_keywords; + StringProperty m_summaryFile{this, "SummaryFile", "AthSummary.txt", + "Output File"}; + StringProperty m_summaryFormat{this, "SummaryFileFormat", "both", + "output format: one of 'ascii', 'python', 'both'"}; + StringArrayProperty m_extraInc{this, "ExtraIncidents", {}, + "user incidets to monitor"}; + StringArrayProperty m_keywords{this, "keywords", {}, + "kewords to scan for in MessageSvc. WARNING: THIS IS VERY SLOW!!!"}; // member data - mutable MsgStream m_log; ServiceHandle<IIncidentSvc> p_incSvc; - ILoggedMessageSvc* p_logMsg; - std::new_handler m_new; - static char* s_block; - static bool s_badalloc; - int m_status; + ILoggedMessageSvc* p_logMsg{nullptr}; + static char* s_block ATLAS_THREAD_SAFE; // used during initialize + static bool s_badalloc ATLAS_THREAD_SAFE; // flag set after bad-alloc std::list<std::string> m_inputFilesRead; std::list<std::string> m_outputFiles; @@ -104,11 +80,12 @@ private: std::map< std::string, std::map<std::string, int> > m_extraIncidents; std::vector< std::pair<std::string, std::string> > m_extraInfo; - unsigned int m_eventsRead, m_eventsWritten, m_eventsSkipped, m_runs; - - - - + std::new_handler m_new{nullptr}; + int m_status{0}; + unsigned int m_eventsRead{0}; + unsigned int m_eventsWritten{0}; + unsigned int m_eventsSkipped{0}; + unsigned int m_runs{0}; }; #endif