Fork me on GitHub

Changeset 49234af in git for external/fastjet/Error.cc


Ignore:
Timestamp:
Dec 9, 2014, 1:27:13 PM (10 years ago)
Author:
Michele <michele.selvaggi@…>
Branches:
ImprovedOutputFile, Timing, dual_readout, llp, master
Children:
37deb3b, 9e991f8
Parents:
f6b6ee7 (diff), e7e90df (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'TestFastJet310b1'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • external/fastjet/Error.cc

    rf6b6ee7 r49234af  
    1 //STARTHEADER
    2 // $Id$
     1//FJSTARTHEADER
     2// $Id: Error.cc 3695 2014-09-18 13:57:56Z cacciari $
    33//
    4 // Copyright (c) 2005-2011, Matteo Cacciari, Gavin P. Salam and Gregory Soyez
     4// Copyright (c) 2005-2014, Matteo Cacciari, Gavin P. Salam and Gregory Soyez
    55//
    66//----------------------------------------------------------------------
     
    1313//
    1414//  The algorithms that underlie FastJet have required considerable
    15 //  development and are described in hep-ph/0512210. If you use
     15//  development. They are described in the original FastJet paper,
     16//  hep-ph/0512210 and in the manual, arXiv:1111.6097. If you use
    1617//  FastJet as part of work towards a scientific publication, please
    17 //  include a citation to the FastJet paper.
     18//  quote the version you use and include a citation to the manual and
     19//  optionally also to hep-ph/0512210.
    1820//
    1921//  FastJet is distributed in the hope that it will be useful,
     
    2527//  along with FastJet. If not, see <http://www.gnu.org/licenses/>.
    2628//----------------------------------------------------------------------
    27 //ENDHEADER
     29//FJENDHEADER
    2830
    2931#include "fastjet/Error.hh"
     
    3133#include <sstream>
    3234
     35#ifndef __FJCORE__
    3336// printing the stack would need execinfo
    3437#ifdef FASTJET_HAVE_EXECINFO_H
    3538#include <execinfo.h>
    3639#include <cstdlib>
    37 #endif
     40#ifdef FASTJET_HAVE_DEMANGLING_SUPPORT
     41#include <cstdio>
     42#include <cxxabi.h>
     43#endif // FASTJET_HAVE_DEMANGLING_SUPPORT
     44#endif // FASTJET_HAVE_EXECINFO_H
     45#endif  // __FJCORE__
    3846
    3947FASTJET_BEGIN_NAMESPACE      // defined in fastjet/internal/base.hh
     
    4452bool Error::_print_backtrace = false;
    4553ostream * Error::_default_ostr = & cerr;
     54#if (!defined(FASTJET_HAVE_EXECINFO_H)) || defined(__FJCORE__)
     55  LimitedWarning Error::_execinfo_undefined;
     56#endif
    4657
     58//----------------------------------------------------------------------
     59#ifndef __FJCORE__
     60
     61// demangling only is included, i.e. --enable-demangling is specified
     62// at configure time, execinfo.h is present and the GNU C++ ABI is
     63// supported
     64#if defined(FASTJET_HAVE_EXECINFO_H) && defined(FASTJET_HAVE_DEMANGLING_SUPPORT)
     65// demangle a given backtrace symbol
     66//
     67// Notes:
     68//  - at the moment, only the symbol is parsed.
     69//  - one can get the offset by using
     70//      "%*[^(]%*[^_]%127[^+)]%64[+x0123456789abcdef]", symbol, offset
     71//    and checking if sscanf returns 0, 1 or 2
     72//    (offset includes the leading +)
     73//  - Similarly one could exctract the address and try to convert it
     74//    into a filename+line number like addr2line does but this seems
     75//    to require exteral dependencies. If we want to go down that
     76//    route, one could look into the inplementation o faddr2line(.c)
     77//    and/or dladdr.
     78string Error::_demangle(const char* symbol) {
     79  size_t size;
     80  int status;
     81  char temp[128];
     82  char* demangled;
     83  // first, try to demangle a c++ name
     84  // decryption:
     85  //   %*[^(]  matches any number of characters different from "("
     86  //           the * tells not to store in input var
     87  //   %*[^_]  matches any number of characters different from "_"
     88  //           the * tells not to store in input var
     89  //   %127[^)+]  matches at most 127 characters different from "+"
     90  //              match is stored
     91  if (1 == sscanf(symbol, "%*[^(]%*[^_]%127[^)+]", temp)) {
     92    //cout << symbol << " -> " << temp << endl;
     93    if (NULL != (demangled = abi::__cxa_demangle(temp, NULL, &size, &status))) {
     94      string result(demangled);
     95      free(demangled);
     96      return result;
     97    }
     98  }
     99  //if that didn't work, try to get a regular c symbol
     100  if (1 == sscanf(symbol, "%127s", temp)) {
     101    return temp;
     102  }
     103 
     104  //if all else fails, just return the symbol
     105  return symbol;
     106}
     107#endif  // FASTJET_HAVE_DEMANGLING_SUPPORT && FASTJET_HAVE_EXECINFO_H
     108#endif  // __FJCORE__
     109
     110
     111//----------------------------------------------------------------------
    47112Error::Error(const std::string & message_in) {
    48113  _message = message_in;
     114
    49115  if (_print_errors && _default_ostr){
    50116    ostringstream oss;
    51117    oss << "fastjet::Error:  "<< message_in << endl;
    52118
     119#ifndef __FJCORE__
    53120    // only print the stack if execinfo is available and stack enabled
    54121#ifdef FASTJET_HAVE_EXECINFO_H
     
    62129      oss << "stack:" << endl;
    63130      for (int i = 1; i < size && messages != NULL; ++i){
     131#ifdef FASTJET_HAVE_DEMANGLING_SUPPORT
     132        oss << "  #" << i << ": " << _demangle(messages[i])
     133            << " [" << messages[i]  << "]" << endl;
     134#else
    64135        oss << "  #" << i << ": " << messages[i] << endl;
     136#endif
    65137      }
    66138      free(messages);
    67139    }
    68 #endif
     140#endif  // FASTJET_HAVE_EXECINFO_H
     141#endif  // __FJCORE__
    69142
    70143    *_default_ostr << oss.str();
     
    83156}
    84157
     158//----------------------------------------------------------------------
     159void Error::set_print_backtrace(bool enabled) {
     160#if (!defined(FASTJET_HAVE_EXECINFO_H)) || defined(__FJCORE__)
     161  if (enabled) {
     162    _execinfo_undefined.warn("Error::set_print_backtrace(true) will not work with this build of FastJet");
     163  }
     164#endif   
     165  _print_backtrace = enabled;
     166}
     167
    85168FASTJET_END_NAMESPACE
    86169
Note: See TracChangeset for help on using the changeset viewer.