Fork me on GitHub

source: git/external/fastjet/LimitedWarning.cc@ 66b590f

ImprovedOutputFile Timing dual_readout llp
Last change on this file since 66b590f was d7d2da3, checked in by pavel <pavel@…>, 12 years ago

move branches/ModularDelphes to trunk

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