Fork me on GitHub

source: git/external/fastjet/LimitedWarning.cc@ e01b141

Last change on this file since e01b141 was b7b836a, checked in by Pavel Demin <pavel-demin@…>, 6 years ago

update FastJet library to 3.3.1 and FastJet Contrib library to 1.036

  • Property mode set to 100644
File size: 3.2 KB
RevLine 
[35cdc46]1//FJSTARTHEADER
[b7b836a]2// $Id: LimitedWarning.cc 4354 2018-04-22 07:12:37Z salam $
[d7d2da3]3//
[b7b836a]4// Copyright (c) 2005-2018, Matteo Cacciari, Gavin P. Salam and Gregory Soyez
[d7d2da3]5//
6//----------------------------------------------------------------------
7// This file is part of FastJet.
8//
9// FastJet is free software; you can redistribute it and/or modify
10// it under the terms of the GNU General Public License as published by
11// the Free Software Foundation; either version 2 of the License, or
12// (at your option) any later version.
13//
14// The algorithms that underlie FastJet have required considerable
[35cdc46]15// development. They are described in the original FastJet paper,
16// hep-ph/0512210 and in the manual, arXiv:1111.6097. If you use
[d7d2da3]17// FastJet as part of work towards a scientific publication, please
[35cdc46]18// quote the version you use and include a citation to the manual and
19// optionally also to hep-ph/0512210.
[d7d2da3]20//
21// FastJet is distributed in the hope that it will be useful,
22// but WITHOUT ANY WARRANTY; without even the implied warranty of
23// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24// GNU General Public License for more details.
25//
26// You should have received a copy of the GNU General Public License
27// along with FastJet. If not, see <http://www.gnu.org/licenses/>.
28//----------------------------------------------------------------------
[35cdc46]29//FJENDHEADER
[d7d2da3]30
31#include "fastjet/LimitedWarning.hh"
32#include <sstream>
33#include <limits>
34
35using namespace std;
36
37FASTJET_BEGIN_NAMESPACE
38
39ostream * LimitedWarning::_default_ostr = &cerr;
40std::list< LimitedWarning::Summary > LimitedWarning::_global_warnings_summary;
41int LimitedWarning::_max_warn_default = 5;
42
43
[35cdc46]44// /// output a warning to ostr
45// void LimitedWarning::warn(const std::string & warning) {
46// warn(warning, _default_ostr);
47// }
[d7d2da3]48
[35cdc46]49void LimitedWarning::warn(const char * warning, std::ostream * ostr) {
[d7d2da3]50 if (_this_warning_summary == 0) {
51 // prepare the information for the summary
52 _global_warnings_summary.push_back(Summary(warning, 0));
53 _this_warning_summary = & (_global_warnings_summary.back());
54 }
55 if (_n_warn_so_far < _max_warn) {
56 // prepare the warning within a string stream
57 ostringstream warnstr;
[35cdc46]58 warnstr << "WARNING from FastJet: ";
[d7d2da3]59 warnstr << warning;
60 _n_warn_so_far++;
61 if (_n_warn_so_far == _max_warn) warnstr << " (LAST SUCH WARNING)";
62 warnstr << std::endl;
63 // arrange for the whole warning to be output in one go (that way
64 // user can easily insert their own printout, e.g. event number
65 // before the warning string).
66 if (ostr) {
67 (*ostr) << warnstr.str();
68 ostr->flush(); // get something written to file even if the program aborts
69 }
70 }
71
72 // maintain the count, but do not allow overflow
73 if (_this_warning_summary->second < numeric_limits<unsigned>::max()) {
74 _this_warning_summary->second++;
75 }
76}
77
78//----------------------------------------------------------------------
79string LimitedWarning::summary() {
80 ostringstream str;
81 for (list<Summary>::const_iterator it = _global_warnings_summary.begin();
82 it != _global_warnings_summary.end(); it++) {
83 str << it->second << " times: " << it->first << endl;
84 }
85 return str.str();
86}
87
88FASTJET_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.