5 #include "GaudiKernel/IAppMgrUI.h"
6 #include "GaudiKernel/IIncidentSvc.h"
7 #include "GaudiKernel/ITHistSvc.h"
8 #include "GaudiKernel/Kernel.h"
9 #include "GaudiKernel/Message.h"
10 #include "GaudiKernel/StatusCode.h"
11 #include "GaudiKernel/System.h"
25 static
const std::
string levelNames[
MSG::
NUM_LEVELS] = {
"NIL",
"VERBOSE",
"DEBUG",
"INFO",
26 "WARNING",
"ERROR",
"FATAL",
"ALWAYS"};
32 std::string
s =
msg.getSource() +
msg.getMessage();
33 s.erase(std::remove_if(
s.begin(),
s.end(), [](
char c) { return std::isdigit(c); }),
s.end());
34 return std::hash<std::string>()(
s);
39 base_class(
name, svcloc)
41 m_outputLevel.declareUpdateHandler([svcloc](Gaudi::Details::PropertyBase&) {
42 SmartIF<IAppMgrUI> app = svcloc;
43 if (app) app->outputLevelUpdate();
57 if (
sc.isFailure())
return sc;
60 sc = incSvc.retrieve();
71 std::cout <<
"TrigMessageSvc WARNING: Colors are not supported by TrigMessageSvc" << std::endl;
73 return StatusCode::SUCCESS;
78 m_state = Gaudi::StateMachine::OFFLINE;
80 if (
sc.isSuccess() ) m_state = Gaudi::StateMachine::INITIALIZED;
89 return StatusCode::SUCCESS;
103 return StatusCode::SUCCESS;
117 if (
histSvc.retrieve().isFailure() ) {
118 reportMessage(
name(), MSG::WARNING,
"Cannot find THistSvc. Message stats will not be published.");
124 const std::string
path =
"/EXPERT/HLTFramework/" +
name() +
"/";
126 m_msgCountHist =
new TH1I(
"MessageCount",
"Messages while RUNNING;Severity;Count",
127 nLevelBins, 0, nLevelBins);
129 const int nSrcBins = 1;
130 m_msgCountSrcHist =
new TH2I(
"MessageCountBySource",
"Messages while RUNNING;Severity;Source",
131 nLevelBins, 0, nLevelBins, nSrcBins, 0, nSrcBins);
139 reportMessage(
name(), MSG::WARNING,
"Cannot register monitoring histogram 'MessageCount'");
142 reportMessage(
name(), MSG::WARNING,
"Cannot register monitoring histogram 'MessageCountBySource'");
151 if (prop.name() ==
"alwaysLimit") {
152 Gaudi::Property<int>*
p =
dynamic_cast<Gaudi::Property<int>*
>(&prop);
153 if (
p &&
p->value() != 0) {
154 std::cout <<
"TrigMessageSvc ERROR: cannot suppress ALWAYS messages" << std::endl;
158 else if (prop.name() ==
"defaultLimit") {
165 else if (prop.name() !=
"fatalLimit" && prop.name() !=
"errorLimit" &&
166 prop.name() !=
"warningLimit" && prop.name() ==
"infoLimit" &&
167 prop.name() ==
"debugLimit" && prop.name() ==
"verboseLimit") {
168 std::cout <<
"TrigMessageSvc ERROR: Unknown message limit parameter: " << prop.name()
176 static const std::array<std::pair<const char*, MSG::Level>, 7> tbl{{{
"setFatal",
MSG::FATAL},
177 {
"setError", MSG::ERROR},
178 {
"setWarning", MSG::WARNING},
179 {
"setInfo", MSG::INFO},
184 auto i = std::find_if(
186 [&](
const std::pair<const char*, MSG::Level>&
t) {
return prop.name() ==
t.first; });
188 std::cerr <<
"TrigMessageSvc ERROR: Unknown message threshold parameter: " << prop.name()
194 Gaudi::Property<std::vector<std::string>>* sap =
195 dynamic_cast<Gaudi::Property<std::vector<std::string>
>*>(&prop);
197 std::cerr <<
"could not dcast " << prop.name()
198 <<
" to a Gaudi::Property<std::vector<std::string>> (which it "
210 std::ostringstream
os;
213 os <<
"Summarizing all message counts"
214 <<
" (severity >= " << levelNames[
m_statLevel] <<
")" << std::endl;
217 os <<
"Listing sources of suppressed message: " << std::endl;
220 os <<
"=====================================================" << std::endl;
221 os <<
" Message Source | Level | Count" << std::endl;
222 os <<
"-----------------------------+---------+-------------" << std::endl;
232 os.setf(std::ios_base::left, std::ios_base::adjustfield);
237 os.setf(std::ios_base::right, std::ios_base::adjustfield);
238 os << levelNames[
ic];
242 os << itr->second.msg[
ic];
249 os <<
"=====================================================" << std::endl;
254 return StatusCode::SUCCESS;
272 std::function<void()>
action;
285 const int key =
msg.getType();
290 std::unique_ptr<Message> newMessage;
301 if (nmsg > msgLimit) doPrint =
false;
302 if (nmsg == msgLimit) {
303 std::string txt = levelNames[
key] +
" message limit (" +
std::to_string(msgLimit) +
304 ") reached for " +
msg.getSource() +
". Suppressing further output.";
305 newMessage = std::make_unique<Message>(
msg.getSource(), MSG::WARNING, std::move(txt));
306 cmsg = newMessage.get();
310 else if (msgLimit < 0) {
312 const unsigned int mh = msgHash(*cmsg);
321 if (nmsg == abs(msgLimit)) {
322 std::ostringstream
os;
323 os <<
msg.getMessage() <<
" [Message limit (" << abs(msgLimit)
324 <<
") reached. Log-suppression of further output.]";
325 newMessage = std::make_unique<Message>(
msg.getSource(),
msg.getType(),
os.str());
326 cmsg = newMessage.get();
328 else if (nmsg > abs(msgLimit)) {
329 const int everyNth = (
int)exp10((
int)log10(nmsg));
330 if ((nmsg % everyNth) == 0) {
331 std::ostringstream
os;
332 os <<
msg.getMessage() <<
" [suppressed " << everyNth <<
" similar messages]";
333 newMessage = std::make_unique<Message>(
msg.getSource(),
msg.getType(),
os.str());
334 cmsg = newMessage.get();
349 (*m_defaultStream) << *cmsg << std::endl <<
std::flush;
386 const char* function_name =
"";
387 const int line_number = msgHash(
msg);
388 const char* package_name =
"HLT";
389 ers::LocalContext hlt_context_info(package_name,
filename, line_number, function_name);
399 std::ostringstream oss;
401 ers::HLTMessage ersMsg(hlt_context_info, oss.str());
402 ersMsg.add_qualifier(
"HLT");
405 switch (
msg.getType()) {
409 case MSG::INFO:
ers::info(ersMsg);
break;
410 case MSG::WARNING: ers::warning(ersMsg);
break;
414 std::ostringstream oss;
415 oss <<
"Unknown message severity level: " <<
msg.getType() <<
" Original message was: " <<
m;
416 ers::error(ers::HLTMessage(ERS_HERE, oss.str()));
432 return m_outputLevel;
444 m_outputLevel = new_level;
455 }
else if (
i->second !=
level ) {
466 const std::vector<std::string>&
filter)
const
468 if (
filter.empty())
return false;
470 if (
filter.size() == 1 && (*
it) ==
"*")
return true;
474 if ((*
it) ==
"*") pass =
true;
476 if (
"!" +
source == (*
it))
return false;
485 const EventContext::ContextID_t slot =
msg.getEventSlot();
486 const EventContext::ContextEvt_t
evt =
msg.getEventNumber();
491 if ( itr->second.first !=
evt ) {
496 const int N = ++itr->second.second.msg[
msg.getType()];