LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
mf::service::ELdestination Class Reference

#include "ELdestination.h"

Inheritance diagram for mf::service::ELdestination:
mf::service::ELostreamOutput mf::service::ELstatistics mfplugins::ELsyslog

Classes

struct  Category
 
struct  CategoryParams
 
struct  Config
 
class  MsgFormatSettings
 
class  MsgStatistics
 
struct  StatsCount
 
struct  XidLimiter
 

Public Types

enum  flag_enum {
  NO_LINE_BREAKS, TIMESTAMP, MILLISECOND, MODULE,
  SUBROUTINE, TEXT, SOME_CONTEXT, SERIAL,
  FULL_CONTEXT, TIME_SEPARATE, EPILOGUE_SEPARATE, NFLAGS
}
 

Public Member Functions

virtual ~ELdestination () noexcept=default
 
 ELdestination (Config const &)
 
 ELdestination (ELdestination const &)=delete
 
 ELdestination (ELdestination &&)=delete
 
ELdestinationoperator= (ELdestination const &)=delete
 
ELdestinationoperator= (ELdestination &&)=delete
 
void setThreshold (ELseverityLevel sv)
 
virtual void log (mf::ErrorObj &)
 
virtual void finish ()
 
virtual void summary ()
 

Protected Member Functions

std::string summarizeContext (std::string const &)
 
void emitToken (std::ostream &os, std::string const &s, bool nl=false, bool preambleMode=false)
 
std::string formSummary ()
 
bool skipMsg (ELextendedID const &)
 
void resetLimiters ()
 
void resetMsgCounters ()
 
virtual void fillPrefix (std::ostringstream &, mf::ErrorObj const &msg)
 
virtual void fillUsrMsg (std::ostringstream &, mf::ErrorObj const &msg)
 
virtual void fillSuffix (std::ostringstream &, mf::ErrorObj const &msg)
 
virtual void routePayload (std::ostringstream const &, mf::ErrorObj const &msg)
 
virtual void flush ()
 

Protected Attributes

ELseverityLevel threshold_
 
MsgFormatSettings format_
 
int defaultLimit_
 
int defaultReportEvery_
 
int defaultTimespan_
 
std::map< std::string const, CategoryParamscategoryParams_
 
std::map< ELextendedID const, XidLimiterxidLimiters_
 
std::map< ELextendedID const, StatsCountstatsMap_
 
bool outputStatistics_ {false}
 
bool updatedStats_ {false}
 
bool reset_ {false}
 

Private Attributes

std::size_t charsOnLine_ {}
 

Detailed Description

Definition at line 25 of file ELdestination.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

virtual mf::service::ELdestination::~ELdestination ( )
virtualdefaultnoexcept
mf::service::ELdestination::ELdestination ( Config const &  pset)

Definition at line 285 of file ELdestination.cc.

References evd::details::begin(), mf::detail::bold_fontify(), categoryParams_, charsOnLine_, defaultLimit_, defaultReportEvery_, defaultTimespan_, e, evd::details::end(), format_, fhicl::ParameterSet::get_if_present(), max, outputStatistics_, reset_, s, statsMap_, mf::service::ELdestination::Config::threshold, updatedStats_, fhicl::detail::validationException::what(), and xidLimiters_.

286  : threshold_{pset.threshold()}
287  , format_{pset.format()}
289  , defaultReportEvery_{-1}
291  , categoryParams_{}
292  , xidLimiters_{}
293  , statsMap_{}
294  , outputStatistics_{pset.outputStatistics()}
295  , updatedStats_{false}
296  , reset_{pset.msgStatistics().reset() ||
297  pset.msgStatistics().resetStatistics()}
298  , charsOnLine_{}
299  {
300  vector<string> configuration_errors;
301  // Grab this destination's category configurations.
302  fhicl::ParameterSet cats_pset{};
303  pset.categories.get_if_present<fhicl::ParameterSet>(cats_pset);
304  // Grab the list of categories, removing the default category
305  // since it is handled specially.
306  auto const default_category_name = "default"s;
307  auto categories = cats_pset.get_pset_names();
308  auto erase_from =
309  remove_if(begin(categories), end(categories), [](auto const& category) {
310  return category == "default"s;
311  });
312  categories.erase(erase_from, categories.cend());
313  // Setup the default configuration for categories--this involves
314  // resetting the limits table according to the user-specified
315  // default configuration.
316  auto const& default_pset =
317  cats_pset.get<fhicl::ParameterSet>("default"s, {});
318  try {
319  fhicl::WrappedTable<Category::Config> default_params{default_pset};
320  defaultLimit_ = (default_params().limit() < 0) ?
321  numeric_limits<decltype(defaultLimit_)>::max() :
322  default_params().limit();
323  defaultReportEvery_ = default_params().reportEvery();
324  defaultTimespan_ = (default_params().timespan() < 0) ?
325  numeric_limits<decltype(defaultTimespan_)>::max() :
326  default_params().timespan();
327  }
328  catch (fhicl::detail::validationException const& e) {
329  string msg{"Category: "s + detail::bold_fontify("default"s) + "\n\n"s};
330  msg += e.what();
331  configuration_errors.push_back(move(msg));
332  }
333  // Now establish this destination's limit/reportEvery/timespan for
334  // each category, using the values of the possibly-specified
335  // default configuration when a given category is missing the
336  // fields.
337  for (auto const& category : categories) {
338  fhicl::Table<Category::Config> category_params{fhicl::Name{category},
339  default_pset};
340  try {
341  category_params.validate_ParameterSet(
342  cats_pset.get<fhicl::ParameterSet>(category));
343  }
344  catch (fhicl::detail::validationException const& e) {
345  string msg{"Category: " + detail::bold_fontify(category) + "\n\n"};
346  msg += e.what();
347  configuration_errors.push_back(move(msg));
348  }
349  // limits_.setCategoryParams(category, category_params().limit(),
350  // category_params().reportEvery(), category_params().timespan());
351  // setCategoryParams(string const& category, int limit, int reportEvery,
352  // int timespan)
353  {
354  if (category_params().limit() < 0) {
355  categoryParams_[category].limit_ = numeric_limits<int>::max();
356  } else {
357  categoryParams_[category].limit_ = category_params().limit();
358  }
359  categoryParams_[category].reportEvery_ =
360  category_params().reportEvery();
361  if (category_params().timespan() < 0) {
362  categoryParams_[category].timespan_ = numeric_limits<int>::max();
363  } else {
364  categoryParams_[category].timespan_ = category_params().timespan();
365  }
366  }
367  }
368  if (!configuration_errors.empty()) {
369  string msg{"The following categories were misconfigured:\n\n"};
370  for (auto const& error : configuration_errors) {
371  msg += error;
372  }
374  }
375  }
Float_t s
Definition: plot.C:23
std::map< std::string const, CategoryParams > categoryParams_
std::string bold_fontify(std::string const &s)
Definition: bold_fontify.h:9
Int_t max
Definition: plot.C:27
std::map< ELextendedID const, StatsCount > statsMap_
std::vector< evd::details::RawDigitInfo_t >::const_iterator begin(RawDigitCacheDataClass const &cache)
bool get_if_present(std::string const &key, T &value) const
Definition: ParameterSet.h:208
ELseverityLevel threshold_
char const * what() const noexcept override
MsgFormatSettings format_
std::vector< evd::details::RawDigitInfo_t >::const_iterator end(RawDigitCacheDataClass const &cache)
std::map< ELextendedID const, XidLimiter > xidLimiters_
Float_t e
Definition: plot.C:34
mf::service::ELdestination::ELdestination ( ELdestination const &  )
delete
mf::service::ELdestination::ELdestination ( ELdestination &&  )
delete

Member Function Documentation

void mf::service::ELdestination::emitToken ( std::ostream &  os,
std::string const &  s,
bool  nl = false,
bool  preambleMode = false 
)
protected

Definition at line 408 of file ELdestination.cc.

References charsOnLine_, format_, art::detail::indent(), mf::service::ELdestination::MsgFormatSettings::lineLength, and s.

Referenced by mf::service::ELostreamOutput::ELostreamOutput(), fillPrefix(), fillSuffix(), and fillUsrMsg().

412  {
413  string indent(6, ' ');
414  if (s.empty()) {
415  if (nl) {
416  os << '\n';
417  charsOnLine_ = 0UL;
418  }
419  return;
420  }
421  if (!preambleMode) {
422  os << s;
423  return;
424  }
425  char const first = s[0];
426  char const second = (s.length() < 2) ? '\0' : s[1];
427  char const last = (s.length() < 2) ? '\0' : s[s.length() - 1];
428  char const last2 = (s.length() < 3) ? '\0' : s[s.length() - 2];
429  // checking -2 because the very last char is sometimes a ' '
430  // inserted by ErrorLog::operator<<
431  // Accounts for newline @ the beginning of the string
432  if (first == '\n' || (charsOnLine_ + s.length()) > format_.lineLength) {
433  charsOnLine_ = 0UL;
434  if (second != ' ') {
435  os << ' ';
436  ++charsOnLine_;
437  }
438  if (first == '\n') {
439  os << s.substr(1);
440  } else {
441  os << s;
442  }
443  } else {
444  os << s;
445  }
446  if ((last == '\n') || (last2 == '\n')) {
447  os << indent;
448  if (last != ' ') {
449  os << ' ';
450  }
451  charsOnLine_ = indent.length() + 1UL;
452  }
453  if (nl) {
454  os << '\n';
455  charsOnLine_ = 0UL;
456  } else {
457  charsOnLine_ += s.length();
458  }
459  }
Float_t s
Definition: plot.C:23
std::string indent(std::size_t const i)
MsgFormatSettings format_
std::string nl(std::size_t i=1)
void mf::service::ELdestination::fillPrefix ( std::ostringstream &  oss,
mf::ErrorObj const &  msg 
)
protectedvirtual

Reimplemented in mfplugins::ELsyslog.

Definition at line 462 of file ELdestination.cc.

References charsOnLine_, mf::ErrorObj::context(), emitToken(), EPILOGUE_SEPARATE, format_, mf::ErrorObj::idOverflow(), mf::ErrorObj::is_verbatim(), MODULE, s, mf::ErrorObj::serial(), SERIAL, SOME_CONTEXT, SUBROUTINE, TIME_SEPARATE, TIMESTAMP, mf::ErrorObj::timestamp(), mf::service::ELdestination::MsgFormatSettings::timestamp(), mf::service::ELdestination::MsgFormatSettings::want(), and mf::ErrorObj::xid().

Referenced by log().

463  {
464  if (msg.is_verbatim()) {
465  return;
466  }
467  auto const& xid = msg.xid();
468  charsOnLine_ = 0UL;
469  emitToken(oss, "%MSG"s, false, true);
470  emitToken(oss, xid.severity().getSymbol(), false, true);
471  emitToken(oss, " ", false, true);
472  emitToken(oss, xid.id(), false, true);
473  emitToken(oss, msg.idOverflow(), false, true);
474  emitToken(oss, ": ", false, true);
475  if (format_.want(SERIAL)) {
476  ostringstream s;
477  s << msg.serial();
478  emitToken(oss, "[serial #" + s.str() + "] ", false, true);
479  }
480  bool needAspace = true;
482  if (xid.module().length() + xid.subroutine().length() > 0) {
483  emitToken(oss, "\n", false, true);
484  needAspace = false;
485  } else if (format_.want(TIMESTAMP) && !format_.want(TIME_SEPARATE)) {
486  emitToken(oss, "\n", false, true);
487  needAspace = false;
488  }
489  }
490  if (format_.want(MODULE) && (xid.module().length() > 0)) {
491  if (needAspace) {
492  emitToken(oss, " ", false, true);
493  needAspace = false;
494  }
495  emitToken(oss, xid.module() + " ", false, true);
496  }
497  if (format_.want(SUBROUTINE) && (xid.subroutine().length() > 0)) {
498  if (needAspace) {
499  emitToken(oss, " ", false, true);
500  needAspace = false;
501  }
502  emitToken(oss, xid.subroutine() + "() ", false, true);
503  }
504  if (format_.want(TIMESTAMP)) {
505  if (format_.want(TIME_SEPARATE)) {
506  emitToken(oss, "\n", false, true);
507  needAspace = false;
508  }
509  if (needAspace) {
510  emitToken(oss, " ", false, true);
511  needAspace = false;
512  }
513  emitToken(oss, format_.timestamp(msg.timestamp()) + " ", false, true);
514  }
515  if (format_.want(SOME_CONTEXT)) {
516  if (needAspace) {
517  emitToken(oss, " ", false, true);
518  needAspace = false;
519  }
520  emitToken(oss, msg.context(), false, true);
521  }
522  }
Float_t s
Definition: plot.C:23
void emitToken(std::ostream &os, std::string const &s, bool nl=false, bool preambleMode=false)
MsgFormatSettings format_
void mf::service::ELdestination::fillSuffix ( std::ostringstream &  oss,
mf::ErrorObj const &  msg 
)
protectedvirtual

Reimplemented in mfplugins::ELsyslog.

Definition at line 552 of file ELdestination.cc.

References emitToken(), format_, mf::ErrorObj::is_verbatim(), NO_LINE_BREAKS, and mf::service::ELdestination::MsgFormatSettings::want().

Referenced by log().

553  {
554  if (!msg.is_verbatim() && !format_.want(NO_LINE_BREAKS)) {
555  emitToken(oss, "\n%MSG");
556  }
557  oss << '\n';
558  }
void emitToken(std::ostream &os, std::string const &s, bool nl=false, bool preambleMode=false)
MsgFormatSettings format_
void mf::service::ELdestination::fillUsrMsg ( std::ostringstream &  oss,
mf::ErrorObj const &  msg 
)
protectedvirtual

Reimplemented in mfplugins::ELsyslog.

Definition at line 525 of file ELdestination.cc.

References emitToken(), mf::ErrorObj::filename(), format_, mf::ErrorObj::is_verbatim(), mf::ErrorObj::items(), mf::ErrorObj::lineNumber(), NO_LINE_BREAKS, s, TEXT, util::flags::to_string(), and mf::service::ELdestination::MsgFormatSettings::want().

Referenced by mfplugins::ELsyslog::fillUsrMsg(), and log().

526  {
527  if (!format_.want(TEXT)) {
528  return;
529  }
530  // Determine if file and line should be included
531  if (!msg.is_verbatim()) {
532  if (!msg.filename().empty()) {
533  emitToken(oss, " "s);
534  emitToken(oss, msg.filename());
535  emitToken(oss, ":"s);
536  emitToken(oss, to_string(msg.lineNumber()));
537  }
538  // Check for user-requested line breaks
539  if (format_.want(NO_LINE_BREAKS)) {
540  emitToken(oss, " ==> ");
541  } else {
542  emitToken(oss, "", true);
543  }
544  }
545  // Print the contents.
546  for (auto const& val : msg.items()) {
547  emitToken(oss, val);
548  }
549  }
Float_t s
Definition: plot.C:23
void emitToken(std::ostream &os, std::string const &s, bool nl=false, bool preambleMode=false)
std::string to_string(Flag_t< Storage > const flag)
Convert a flag into a stream (shows its index).
Definition: BitMask.h:187
MsgFormatSettings format_
void mf::service::ELdestination::finish ( )
virtual

Definition at line 723 of file ELdestination.cc.

724  {}
void mf::service::ELdestination::flush ( )
protectedvirtual

Definition at line 735 of file ELdestination.cc.

References mf::ELwarning, log(), and s.

736  {
737  ErrorObj msg{ELwarning, "ELdestination"s};
738  msg << "Call to unimplemented flush()!";
739  log(msg);
740  }
Float_t s
Definition: plot.C:23
virtual void log(mf::ErrorObj &)
ELslProxy< ELwarningGen > constexpr ELwarning
string mf::service::ELdestination::formSummary ( )
protected

Definition at line 594 of file ELdestination.cc.

References art::left(), n, mf::ELseverityLevel::nLevels, art::right(), s, and statsMap_.

Referenced by mf::service::ELstatistics::summary(), and summary().

595  {
596  ostringstream s;
597  int n{};
598  // ----- Summary part I:
599  //
600  bool ftnote{false};
601  struct part3 {
602  long n{}, t{};
604  for (auto const& pr : statsMap_) {
605  auto const& xid = pr.first;
606  auto const& count = pr.second;
607  auto const& cat = xid.id();
608  // ----- Emit new part I header, if needed:
609  //
610  if (n == 0) {
611  s << "\n";
612  s << " type category sev module subroutine "
613  " count total\n"
614  << " ---- -------------------- -- ---------------- "
615  "---------------- ----- -----\n";
616  }
617  // ----- Emit detailed message information:
618  //
619  s
620  // Type
621  << right << setw(5) << ++n
622  << ' '
623  // Category
624  << left << setw(20) << cat.substr(0, 20)
625  << ' '
626  // Severity
627  << left << setw(2) << xid.severity().getSymbol()
628  << ' '
629  // Module
630  << left << setw(16) << xid.module().substr(0, 16)
631  << ' '
632  // Subroutine
633  << left << setw(16)
634  << xid.subroutine().substr(0, 16)
635  // Count
636  << right << setw(7) << count.n_ << left << setw(1)
637  << (count.ignoredFlag_ ? '*' : ' ')
638  // Total Count
639  << right << setw(8) << count.aggregateN_ << '\n';
640  ftnote = ftnote || count.ignoredFlag_;
641  // ----- Obtain information for Part III, below:
642  //
643  p3[xid.severity().getLevel()].n += count.n_;
644  p3[xid.severity().getLevel()].t += count.aggregateN_;
645  }
646  // ----- Provide footnote to part I, if needed:
647  //
648  if (ftnote) {
649  s << "\n* Some occurrences of this message were suppressed in all "
650  "logs, due to limits.\n";
651  }
652  // ----- Summary part II:
653  //
654  n = 0;
655  for (auto const& pr : statsMap_) {
656  auto const& xid = pr.first;
657  auto const& count = pr.second;
658  string const& cat = xid.id();
659  if (n == 0) {
660  s << '\n'
661  << " type category Examples: run/evt run/evt "
662  "run/evt\n"
663  << " ---- -------------------- ---------------- ---------------- "
664  "----------------\n";
665  }
666  s
667  // Type
668  << right << setw(5) << ++n
669  << ' '
670  // Category
671  << left << setw(20) << cat
672  << ' '
673  // Context1
674  << left << setw(16) << count.context1_.c_str()
675  << ' '
676  // Context2
677  << left << setw(16) << count.context2_.c_str()
678  << ' '
679  // ContextLast
680  << count.contextLast_ << '\n';
681  }
682  // ----- Summary part III:
683  //
684  s << '\n'
685  << "Severity # Occurrences Total Occurrences\n"
686  << "-------- ------------- -----------------\n";
687  for (int k = 0; k < ELseverityLevel::nLevels; ++k) {
688  if (p3[k].n != 0 || p3[k].t != 0) {
689  s
690  // Severity
691  << left << setw(8)
692  << ELseverityLevel{ELseverityLevel::ELsev_(k)}.getName().c_str()
693  // Occurrences
694  << right << setw(17)
695  << p3[k].n
696  // Total Occurrences
697  << right << setw(20) << p3[k].t << '\n';
698  }
699  }
700  return s.str();
701  }
Float_t s
Definition: plot.C:23
constexpr auto const & right(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:112
std::map< ELextendedID const, StatsCount > statsMap_
constexpr auto const & left(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:104
Char_t n[5]
void mf::service::ELdestination::log ( mf::ErrorObj msg)
virtual

Reimplemented in mf::service::ELstatistics.

Definition at line 565 of file ELdestination.cc.

References mf::ErrorObj::context(), fillPrefix(), fillSuffix(), fillUsrMsg(), outputStatistics_, routePayload(), mf::ErrorObj::setReactedTo(), mf::ELextendedID::severity(), skipMsg(), statsMap_, summarizeContext(), threshold_, updatedStats_, and mf::ErrorObj::xid().

Referenced by flush().

566  {
567  if (msg.xid().severity() < threshold_) {
568  if (outputStatistics_) {
569  statsMap_[msg.xid()].add(summarizeContext(msg.context()), false);
570  updatedStats_ = true;
571  }
572  return;
573  }
574  if (skipMsg(msg.xid())) {
575  if (outputStatistics_) {
576  statsMap_[msg.xid()].add(summarizeContext(msg.context()), false);
577  updatedStats_ = true;
578  }
579  return;
580  }
581  msg.setReactedTo(true);
582  ostringstream payload;
583  fillPrefix(payload, msg);
584  fillUsrMsg(payload, msg);
585  fillSuffix(payload, msg);
586  routePayload(payload, msg);
587  if (outputStatistics_) {
588  statsMap_[msg.xid()].add(summarizeContext(msg.context()), true);
589  updatedStats_ = true;
590  }
591  }
ELseverityLevel severity() const
Definition: ELextendedID.cc:33
virtual void fillUsrMsg(std::ostringstream &, mf::ErrorObj const &msg)
bool skipMsg(ELextendedID const &)
virtual void fillSuffix(std::ostringstream &, mf::ErrorObj const &msg)
std::string const & context() const
Definition: ErrorObj.cc:98
std::map< ELextendedID const, StatsCount > statsMap_
std::string summarizeContext(std::string const &)
ELextendedID const & xid() const
Definition: ErrorObj.cc:61
ELseverityLevel threshold_
virtual void fillPrefix(std::ostringstream &, mf::ErrorObj const &msg)
virtual void setReactedTo(bool)
Definition: ErrorObj.cc:177
virtual void routePayload(std::ostringstream const &, mf::ErrorObj const &msg)
ELdestination& mf::service::ELdestination::operator= ( ELdestination const &  )
delete
ELdestination& mf::service::ELdestination::operator= ( ELdestination &&  )
delete
void mf::service::ELdestination::resetLimiters ( )
protected

Definition at line 840 of file ELdestination.cc.

References xidLimiters_.

Referenced by mf::service::ELstatistics::summary(), and summary().

841  {
842  xidLimiters_.clear();
843  }
std::map< ELextendedID const, XidLimiter > xidLimiters_
void mf::service::ELdestination::resetMsgCounters ( )
protected

Definition at line 834 of file ELdestination.cc.

References statsMap_.

Referenced by mf::service::ELstatistics::summary(), and summary().

835  {
836  statsMap_.clear();
837  }
std::map< ELextendedID const, StatsCount > statsMap_
void mf::service::ELdestination::routePayload ( std::ostringstream const &  ,
mf::ErrorObj const &  msg 
)
protectedvirtual

Reimplemented in mf::service::ELostreamOutput, and mfplugins::ELsyslog.

Definition at line 561 of file ELdestination.cc.

Referenced by log(), and summary().

562  {}
void mf::service::ELdestination::setThreshold ( ELseverityLevel  sv)

Definition at line 729 of file ELdestination.cc.

References threshold_.

730  {
731  threshold_ = sv;
732  }
ELseverityLevel threshold_
bool mf::service::ELdestination::skipMsg ( ELextendedID const &  xid)
protected

Definition at line 746 of file ELdestination.cc.

References categoryParams_, defaultLimit_, defaultReportEvery_, defaultTimespan_, mf::ELextendedID::id(), mf::service::ELdestination::XidLimiter::limit_, mf::service::ELdestination::XidLimiter::msgCount_, mf::service::ELdestination::XidLimiter::previousTimestamp_, mf::service::ELdestination::XidLimiter::reportEvery_, mf::service::ELdestination::XidLimiter::skippedMsgCount_, mf::service::ELdestination::XidLimiter::timespan_, and xidLimiters_.

Referenced by mf::service::ELstatistics::log(), and log().

747  {
748  auto xl_iter = xidLimiters_.find(xid);
749  if (xl_iter == xidLimiters_.end()) {
750  // Need to create and initialize a limiter for this xid.
751  int limit{defaultLimit_};
752  int reportEvery{defaultReportEvery_};
753  int timespan{defaultTimespan_};
754  // Does the category of this xid have explicit limits?
755  auto cp_iter = categoryParams_.find(xid.id());
756  if (cp_iter != categoryParams_.end()) {
757  // Category limits found, use them.
758  auto const& cp = cp_iter->second;
759  limit = (cp.limit_ < 0) ? defaultLimit_ : cp.limit_;
760  reportEvery =
761  (cp.reportEvery_ < 0) ? defaultReportEvery_ : cp.reportEvery_;
762  timespan = (cp.timespan_ < 0) ? defaultTimespan_ : cp.timespan_;
763  }
764  XidLimiter& limiter = xidLimiters_[xid];
765  limiter.previousTimestamp_ = time(0);
766  limiter.msgCount_ = 0;
767  limiter.skippedMsgCount_ =
768  reportEvery -
769  1; // So that the FIRST of the prescaled messages emerges
770  limiter.limit_ = limit;
771  limiter.reportEvery_ = reportEvery;
772  limiter.timespan_ = timespan;
773  xl_iter = xidLimiters_.find(xid);
774  }
775  XidLimiter& limiter = xl_iter->second;
776  time_t now = time(0);
777  // Has it been so long that we should restart counting toward the limit?
778  if ((limiter.timespan_ >= 0) &&
779  (difftime(now, limiter.previousTimestamp_) >= limiter.timespan_)) {
780  limiter.msgCount_ = 0;
781  if (limiter.reportEvery_ > 0) {
782  // So this message will be reacted to
783  limiter.skippedMsgCount_ = limiter.reportEvery_ - 1;
784  } else {
785  limiter.skippedMsgCount_ = 0;
786  }
787  }
788  limiter.previousTimestamp_ = now;
789  ++limiter.msgCount_;
790  ++limiter.skippedMsgCount_;
791  if (limiter.skippedMsgCount_ < limiter.reportEvery_) {
792  // Skip message.
793  return true;
794  }
795  if (limiter.limit_ == 0) {
796  // Zero limit - never react to this
797  // Skip message.
798  return true;
799  }
800  if ((limiter.limit_ < 0) || (limiter.msgCount_ <= limiter.limit_)) {
801  limiter.skippedMsgCount_ = 0;
802  // Accept message.
803  return false;
804  }
805  // Now we are over the limit - have we exceeded limit by 2^N * limit?
806  long diff = limiter.msgCount_ - limiter.limit_;
807  long r = diff / limiter.limit_;
808  if (r * limiter.limit_ != diff) {
809  // Not a multiple of limit - don't react
810  // Skip message.
811  return true;
812  }
813  if (r == 1) {
814  // Exactly twice limit - react
815  limiter.skippedMsgCount_ = 0;
816  // Accept message.
817  return false;
818  }
819  while (r > 1) {
820  if ((r & 1) != 0) {
821  // Not 2**msgCount_ times limit - don't react
822  // Skip message.
823  return true;
824  }
825  r >>= 1;
826  }
827  // If you never get an odd number till one, r is 2**msgCount_ so react
828  limiter.skippedMsgCount_ = 0;
829  // Accept message.
830  return false;
831  }
std::map< std::string const, CategoryParams > categoryParams_
std::map< ELextendedID const, XidLimiter > xidLimiters_
string mf::service::ELdestination::summarizeContext ( std::string const &  )
protected

Definition at line 378 of file ELdestination.cc.

Referenced by mf::service::ELstatistics::log(), and log().

379  {
380  if (c.substr(0, 4) != "Run:") {
381  return c;
382  }
383  istringstream is(c);
384  string runWord;
385  int run;
386  is >> runWord >> run;
387  if (!is) {
388  return c;
389  }
390  if (runWord != "Run:") {
391  return c;
392  }
393  string eventWord;
394  int event;
395  is >> eventWord >> event;
396  if (!is) {
397  return c;
398  }
399  if (eventWord != "Event:") {
400  return c;
401  }
402  ostringstream os;
403  os << run << "/" << event;
404  return os.str();
405  }
Event finding and building.
void mf::service::ELdestination::summary ( )
virtual

Reimplemented in mf::service::ELstatistics.

Definition at line 706 of file ELdestination.cc.

References mf::ELzeroSeverity, formSummary(), outputStatistics_, reset_, resetLimiters(), resetMsgCounters(), routePayload(), s, and updatedStats_.

707  {
709  ostringstream payload;
710  payload << "\n=============================================\n\n"
711  << "MessageLogger Summary\n"
712  << formSummary();
713  routePayload(payload, ErrorObj{ELzeroSeverity, "No ostream"s});
714  }
715  updatedStats_ = false;
716  if (reset_) {
718  resetLimiters();
719  }
720  }
Float_t s
Definition: plot.C:23
ELslProxy< ELzeroSeverityGen > constexpr ELzeroSeverity
virtual void routePayload(std::ostringstream const &, mf::ErrorObj const &msg)

Member Data Documentation

std::map<std::string const, CategoryParams> mf::service::ELdestination::categoryParams_
protected

Definition at line 264 of file ELdestination.h.

Referenced by ELdestination(), and skipMsg().

std::size_t mf::service::ELdestination::charsOnLine_ {}
private

Definition at line 273 of file ELdestination.h.

Referenced by ELdestination(), emitToken(), and fillPrefix().

int mf::service::ELdestination::defaultLimit_
protected

Definition at line 261 of file ELdestination.h.

Referenced by ELdestination(), and skipMsg().

int mf::service::ELdestination::defaultReportEvery_
protected

Definition at line 262 of file ELdestination.h.

Referenced by ELdestination(), and skipMsg().

int mf::service::ELdestination::defaultTimespan_
protected

Definition at line 263 of file ELdestination.h.

Referenced by ELdestination(), and skipMsg().

MsgFormatSettings mf::service::ELdestination::format_
protected
bool mf::service::ELdestination::outputStatistics_ {false}
protected
bool mf::service::ELdestination::reset_ {false}
protected

Definition at line 269 of file ELdestination.h.

Referenced by ELdestination(), mf::service::ELstatistics::summary(), and summary().

std::map<ELextendedID const, StatsCount> mf::service::ELdestination::statsMap_
protected
ELseverityLevel mf::service::ELdestination::threshold_
protected

Definition at line 259 of file ELdestination.h.

Referenced by mf::service::ELstatistics::log(), log(), and setThreshold().

bool mf::service::ELdestination::updatedStats_ {false}
protected
std::map<ELextendedID const, XidLimiter> mf::service::ELdestination::xidLimiters_
protected

Definition at line 265 of file ELdestination.h.

Referenced by ELdestination(), resetLimiters(), and skipMsg().


The documentation for this class was generated from the following files: