31 #include "fastjet/LimitedWarning.hh"
37 FASTJET_BEGIN_NAMESPACE
39 #ifdef FASTJET_HAVE_LIMITED_THREAD_SAFETY
40 atomic<ostream *> LimitedWarning::_default_ostr{&cerr};
41 atomic<mutex *> LimitedWarning::_stream_mutex{
nullptr};
42 atomic<int> LimitedWarning::_max_warn_default{5};
43 std::mutex LimitedWarning::_global_warnings_summary_mutex;
45 ostream * LimitedWarning::_default_ostr = &cerr;
46 int LimitedWarning::_max_warn_default = 5;
49 std::list< LimitedWarning::Summary > LimitedWarning::_global_warnings_summary;
58 int LimitedWarning::n_warn_so_far()
const{
62 if (((LimitedWarning::Summary *)_this_warning_summary) == 0)
return 0;
63 return (*_this_warning_summary).second;
67 void LimitedWarning::warn(
const char * warning, std::ostream * ostr) {
69 if (((LimitedWarning::Summary *)_this_warning_summary) == 0){
70 #ifdef FASTJET_HAVE_LIMITED_THREAD_SAFETY
79 std::lock_guard<std::mutex> guard(_global_warnings_summary_mutex);
84 if (((LimitedWarning::Summary *)_this_warning_summary) == 0){
86 _global_warnings_summary.push_back(Summary(warning, 0));
87 _this_warning_summary = & (_global_warnings_summary.back());
92 _global_warnings_summary.push_back(Summary(warning, 0));
93 _this_warning_summary = & (_global_warnings_summary.back());
99 unsigned int count = (*_this_warning_summary).second.step();
102 if ((_max_warn<0) || (count < (
unsigned int)_max_warn)) {
104 ostringstream warnstr;
105 warnstr <<
"WARNING from FastJet: ";
107 if ((_max_warn>0) && (count+1 == (
unsigned int)_max_warn))
108 warnstr <<
" (LAST SUCH WARNING)";
109 warnstr << std::endl;
115 #ifdef FASTJET_HAVE_LIMITED_THREAD_SAFETY
117 std::lock_guard<std::mutex> guard(*_stream_mutex);
118 (*ostr) << warnstr.str();
123 (*ostr) << warnstr.str();
132 string LimitedWarning::summary() {
134 #ifdef FASTJET_HAVE_LIMITED_THREAD_SAFETY
140 std::lock_guard<std::mutex> guard(_global_warnings_summary_mutex);
142 for (list<Summary>::const_iterator it = _global_warnings_summary.begin();
143 it != _global_warnings_summary.end(); it++) {
144 str << it->second <<
" times: " << it->first << endl;
146 #ifdef FASTJET_HAVE_LIMITED_THREAD_SAFETY
152 FASTJET_END_NAMESPACE