FastJet 3.0.2
Error.cc
00001 //STARTHEADER
00002 // $Id: Error.cc 2687 2011-11-14 11:17:51Z soyez $
00003 //
00004 // Copyright (c) 2005-2011, Matteo Cacciari, Gavin P. Salam and Gregory Soyez
00005 //
00006 //----------------------------------------------------------------------
00007 // This file is part of FastJet.
00008 //
00009 //  FastJet is free software; you can redistribute it and/or modify
00010 //  it under the terms of the GNU General Public License as published by
00011 //  the Free Software Foundation; either version 2 of the License, or
00012 //  (at your option) any later version.
00013 //
00014 //  The algorithms that underlie FastJet have required considerable
00015 //  development and are described in hep-ph/0512210. If you use
00016 //  FastJet as part of work towards a scientific publication, please
00017 //  include a citation to the FastJet paper.
00018 //
00019 //  FastJet is distributed in the hope that it will be useful,
00020 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00021 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022 //  GNU General Public License for more details.
00023 //
00024 //  You should have received a copy of the GNU General Public License
00025 //  along with FastJet. If not, see <http://www.gnu.org/licenses/>.
00026 //----------------------------------------------------------------------
00027 //ENDHEADER
00028 
00029 #include "fastjet/Error.hh"
00030 #include "fastjet/config.h"
00031 #include <sstream>
00032 
00033 // printing the stack would need execinfo
00034 #ifdef FASTJET_HAVE_EXECINFO_H
00035 #include <execinfo.h>
00036 #include <cstdlib>
00037 #endif
00038 
00039 FASTJET_BEGIN_NAMESPACE      // defined in fastjet/internal/base.hh
00040 
00041 using namespace std;
00042 
00043 bool Error::_print_errors = true;
00044 bool Error::_print_backtrace = false;
00045 ostream * Error::_default_ostr = & cerr;
00046 
00047 Error::Error(const std::string & message_in) {
00048   _message = message_in; 
00049   if (_print_errors && _default_ostr){
00050     ostringstream oss;
00051     oss << "fastjet::Error:  "<< message_in << endl;
00052 
00053     // only print the stack if execinfo is available and stack enabled
00054 #ifdef FASTJET_HAVE_EXECINFO_H
00055     if (_print_backtrace){
00056       void * array[10];
00057       char ** messages;
00058  
00059       int size = backtrace(array, 10);
00060       messages = backtrace_symbols(array, size);
00061       
00062       oss << "stack:" << endl;
00063       for (int i = 1; i < size && messages != NULL; ++i){
00064         oss << "  #" << i << ": " << messages[i] << endl;
00065       }
00066       free(messages);
00067     }
00068 #endif
00069 
00070     *_default_ostr << oss.str();
00071     // get something written to file even 
00072     // if the program aborts
00073     _default_ostr->flush(); 
00074 
00075     // // output error message either to cerr or to the user-set stream
00076     // if (_default_ostr) { *_default_ostr << oss.str();
00077     //                       // get something written to file even 
00078     //                    // if the program aborts
00079     //                       _default_ostr->flush(); }
00080     // else               { std::cerr << oss.str(); }
00081     
00082   }
00083 }
00084 
00085 FASTJET_END_NAMESPACE
00086 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends