ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
MessageHelper Class Reference

#include <MessageHelper.h>

Collaboration diagram for MessageHelper:

Public Member Functions

 MessageHelper (const AthAlgTool &parent, unsigned int num)
 Pass to the constructor the number of messages. More...
 
void incrementCount (unsigned int messageNumber)
 
void printSummary (void) const
 
void printWarning (unsigned int messageNumber) const
 
void printWarning (unsigned int messageNumber, const std::string &addition) const
 
void setMaxNumberOfMessagesPrinted (unsigned int num)
 
void setMessage (unsigned int messageNumber, const std::string &message)
 
bool wouldPrintWarning (unsigned int messageNumber) const
 

Private Attributes

const AthAlgToolm_parent
 
unsigned int m_maxWarnings
 Maximum number of WARNING messages permitted. More...
 
std::vector< std::atomic< unsigned int > > m_warningCounts ATLAS_THREAD_SAFE
 The counts per error (the index is the error number) More...
 
std::vector< std::string > m_warningText
 The text for the WARNINGs (the index is the error number). More...
 

Detailed Description

Definition at line 16 of file MessageHelper.h.

Constructor & Destructor Documentation

◆ MessageHelper()

MessageHelper::MessageHelper ( const AthAlgTool parent,
unsigned int  num 
)
inline

Pass to the constructor the number of messages.

Definition at line 41 of file MessageHelper.h.

42  : m_parent(parent),
43  m_maxWarnings(3),
44  m_warningCounts(num),
45  m_warningText(num) {}

Member Function Documentation

◆ incrementCount()

void MessageHelper::incrementCount ( unsigned int  messageNumber)
inline

Definition at line 47 of file MessageHelper.h.

47  {
48  m_warningCounts[messageNumber]++;
49 }

◆ printSummary()

void MessageHelper::printSummary ( void  ) const
inline

Definition at line 51 of file MessageHelper.h.

51  {
52  bool haveWarnings = false;
53  for (unsigned int i = 0; i < m_warningCounts.size(); ++i) {
54  if (!m_warningCounts[i])
55  continue;
56  haveWarnings = true;
57  break;
58  }
59  if (!haveWarnings)
60  return;
61 
62  std::stringstream out;
63  out << " summary of WARNING occurences (maximum shown during job: "
64  << m_maxWarnings << "):";
65  m_parent.msg(MSG::INFO) << out.str() << endmsg;
66 
67  for (unsigned int i = 0; i < m_warningCounts.size(); ++i) {
68  if (!m_warningCounts[i])
69  continue;
70  out.str("");
71  out << " " << m_warningCounts[i] << ":\t" << m_warningText[i];
72  m_parent.msg(MSG::INFO) << out.str() << endmsg;
73  }
74 }

◆ printWarning() [1/2]

void MessageHelper::printWarning ( unsigned int  messageNumber) const
inline

Definition at line 76 of file MessageHelper.h.

76  {
77  unsigned int count = ++m_warningCounts[messageNumber];
78  if (!m_parent.msgLvl(MSG::WARNING) || count > m_maxWarnings)
79  return;
80 
81  m_parent.msg(MSG::WARNING) << m_warningText[messageNumber] << endmsg;
82  if (count == m_maxWarnings)
83  m_parent.msg(MSG::WARNING)
84  << "Limit reached. No more messages of this type will be printed."
85  << endmsg;
86 }

◆ printWarning() [2/2]

void MessageHelper::printWarning ( unsigned int  messageNumber,
const std::string &  addition 
) const
inline

Definition at line 88 of file MessageHelper.h.

89  {
90  unsigned int count = ++m_warningCounts[messageNumber];
91  if (!m_parent.msgLvl(MSG::WARNING) || count > m_maxWarnings)
92  return;
93 
94  m_parent.msg(MSG::WARNING)
95  << m_warningText[messageNumber] << addition << endmsg;
96  if (count == m_maxWarnings)
97  m_parent.msg(MSG::WARNING)
98  << "Limit reached. No more messages of this type will be printed."
99  << endmsg;
100 }

◆ setMaxNumberOfMessagesPrinted()

void MessageHelper::setMaxNumberOfMessagesPrinted ( unsigned int  num)
inline

Definition at line 102 of file MessageHelper.h.

102  {
103  m_maxWarnings = num;
104 }

◆ setMessage()

void MessageHelper::setMessage ( unsigned int  messageNumber,
const std::string &  message 
)
inline

Definition at line 106 of file MessageHelper.h.

107  {
108  if (messageNumber >= m_warningCounts.size())
109  std::abort();
110  m_warningCounts[messageNumber] = 0;
111  m_warningText[messageNumber] = message;
112 }

◆ wouldPrintWarning()

bool MessageHelper::wouldPrintWarning ( unsigned int  messageNumber) const
inline

Definition at line 114 of file MessageHelper.h.

114  {
115  if (m_parent.msgLvl(MSG::WARNING) &&
116  m_warningCounts[messageNumber] <= m_maxWarnings)
117  return true;
118  return false;
119 }

Member Data Documentation

◆ ATLAS_THREAD_SAFE

std::vector<std::atomic<unsigned int> > m_warningCounts MessageHelper::ATLAS_THREAD_SAFE
mutableprivate

The counts per error (the index is the error number)

Definition at line 34 of file MessageHelper.h.

◆ m_maxWarnings

unsigned int MessageHelper::m_maxWarnings
private

Maximum number of WARNING messages permitted.

Definition at line 32 of file MessageHelper.h.

◆ m_parent

const AthAlgTool& MessageHelper::m_parent
private

Definition at line 30 of file MessageHelper.h.

◆ m_warningText

std::vector<std::string> MessageHelper::m_warningText
private

The text for the WARNINGs (the index is the error number).

Filled in ctor.

Definition at line 37 of file MessageHelper.h.


The documentation for this class was generated from the following file:
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
AthCommonMsg::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
ReweightUtils.message
message
Definition: ReweightUtils.py:15
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
lumiFormat.i
int i
Definition: lumiFormat.py:85
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
test_pyathena.parent
parent
Definition: test_pyathena.py:15
MessageHelper::m_warningText
std::vector< std::string > m_warningText
The text for the WARNINGs (the index is the error number).
Definition: MessageHelper.h:37
MessageHelper::m_parent
const AthAlgTool & m_parent
Definition: MessageHelper.h:30
trigbs_pickEvents.num
num
Definition: trigbs_pickEvents.py:76
MessageHelper::m_maxWarnings
unsigned int m_maxWarnings
Maximum number of WARNING messages permitted.
Definition: MessageHelper.h:32
AthCommonMsg::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24