FastJet 3.0.2
LimitedWarning.hh
00001 #ifndef __FASTJET_LIMITEDWARNING_HH__
00002 #define __FASTJET_LIMITEDWARNING_HH__
00003 
00004 //STARTHEADER
00005 // $Id: LimitedWarning.hh 2577 2011-09-13 15:11:38Z salam $
00006 //
00007 // Copyright (c) 2005-2011, Matteo Cacciari, Gavin P. Salam and Gregory Soyez
00008 //
00009 //----------------------------------------------------------------------
00010 // This file is part of FastJet.
00011 //
00012 //  FastJet is free software; you can redistribute it and/or modify
00013 //  it under the terms of the GNU General Public License as published by
00014 //  the Free Software Foundation; either version 2 of the License, or
00015 //  (at your option) any later version.
00016 //
00017 //  The algorithms that underlie FastJet have required considerable
00018 //  development and are described in hep-ph/0512210. If you use
00019 //  FastJet as part of work towards a scientific publication, please
00020 //  include a citation to the FastJet paper.
00021 //
00022 //  FastJet is distributed in the hope that it will be useful,
00023 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00024 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00025 //  GNU General Public License for more details.
00026 //
00027 //  You should have received a copy of the GNU General Public License
00028 //  along with FastJet. If not, see <http://www.gnu.org/licenses/>.
00029 //----------------------------------------------------------------------
00030 //ENDHEADER
00031 
00032 
00033 #include "fastjet/internal/base.hh"
00034 #include <iostream>
00035 #include <string>
00036 #include <list>
00037 
00038 FASTJET_BEGIN_NAMESPACE
00039 
00040 /// @ingroup error_handling
00041 /// \class LimitedWarning
00042 /// class to provide facilities for giving warnings up to some maximum
00043 /// number of times and to provide global summaries of warnings that have
00044 /// been issued.
00045 class LimitedWarning {
00046 public:
00047   
00048   /// constructor that provides a default maximum number of warnings
00049   LimitedWarning() : _max_warn(_max_warn_default), _n_warn_so_far(0), _this_warning_summary(0) {}
00050 
00051   /// constructor that provides a user-set max number of warnings
00052   LimitedWarning(int max_warn) : _max_warn(max_warn), _n_warn_so_far(0), _this_warning_summary(0) {}
00053 
00054   /// outputs a warning to standard error (or the user's default
00055   /// warning stream if set)
00056   void warn(const std::string & warning);
00057 
00058   /// outputs a warning to the specified stream
00059   void warn(const std::string & warning, std::ostream * ostr);
00060 
00061   /// sets the default output stream for all warnings (by default
00062   /// cerr; passing a null pointer prevents warnings from being output)
00063   static void set_default_stream(std::ostream * ostr) {
00064     _default_ostr = ostr;
00065   }
00066 
00067   /// sets the default maximum number of warnings of a given kind
00068   /// before warning messages are silenced.
00069   static void set_default_max_warn(int max_warn) {
00070     _max_warn_default = max_warn;
00071   }
00072 
00073   /// returns a summary of all the warnings that came through the
00074   /// LimiteWarning class
00075   static std::string summary();
00076 
00077 private:
00078   int _max_warn, _n_warn_so_far;
00079   static int _max_warn_default;
00080   static std::ostream * _default_ostr;
00081   typedef std::pair<std::string, unsigned int> Summary;
00082   static std::list< Summary > _global_warnings_summary;
00083   Summary * _this_warning_summary;
00084   
00085 };
00086 
00087 FASTJET_END_NAMESPACE
00088 
00089 #endif // __FASTJET_LIMITEDWARNING_HH__
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends