File: Exception.cc

package info (click to toggle)
thepeg 1.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 9,312 kB
  • ctags: 11,509
  • sloc: cpp: 57,129; sh: 11,315; java: 3,212; lisp: 1,402; makefile: 830; ansic: 58; perl: 3
file content (144 lines) | stat: -rw-r--r-- 3,331 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// -*- C++ -*-
//
// Exception.cc is a part of ThePEG - Toolkit for HEP Event Generation
// Copyright (C) 1999-2011 Leif Lonnblad
//
// ThePEG is licenced under version 2 of the GPL, see COPYING for details.
// Please respect the MCnet academic guidelines, see GUIDELINES for details.
//
//
// This is the implementation of the non-inlined, non-templated member
// functions of the Exception class.
//

#include "Exception.h"
#include <iostream>
#include <cstdlib>
#include "ThePEG/Interface/Interfaced.h"
#include "ThePEG/Repository/CurrentGenerator.h"
#include "ThePEG/EventRecord/Event.h"
#include "ThePEG/Utilities/Debug.h"

void breakThePEG() {
  return;
}

extern "C" {
  void debugThePEG(const ThePEG::Interfaced * i) {
    i->debug();
  }

  void debugEvent() {
    using namespace ThePEG;
    if ( !CurrentGenerator::isVoid() &&
	 CurrentGenerator::current().currentEvent() )
      cerr << *CurrentGenerator::current().currentEvent();
  }

  long debugEventNumber() {
    using namespace ThePEG;
    if ( !CurrentGenerator::isVoid() )
      return CurrentGenerator::current().currentEventNumber();
    return 0;
  }

  void debugDump() {
    using namespace ThePEG;
    if ( !CurrentGenerator::isVoid() ) CurrentGenerator::current().dump();
  }

  void debugParticle(const ThePEG::Particle * p) {
    using namespace ThePEG;
    cerr << *p;
  }
  void debugParticles(int n, const ThePEG::Particle ** p) {
    using namespace ThePEG;
    LorentzMomentum sum;
    for ( int i = 0; i < n; i++ ) {
      cerr << **p;
      sum += (**p).momentum();
      ++p;
    }
    cerr << ounit(sum,GeV) << "GeV \t" << ounit(sum.m(),GeV) << " GeV\n";
  }

}

namespace ThePEG {

Veto::Veto() {
  if ( ThePEG_DEBUG_LEVEL ) breakThePEG();
}

Exception::Exception(const string & newMessage, Severity newSeverity)
  : theMessage(newMessage), handled(false), theSeverity(newSeverity) {
  breakThePEG();
  if ( noabort && ( theSeverity == abortnow || theSeverity == maybeabort ) )
       theSeverity = runerror;
  if ( theSeverity == abortnow ) {
    writeMessage();
    abort();
  }
}

Exception::~Exception() throw() {
  if ( !handled ) {
    writeMessage();
    if ( theSeverity == maybeabort ) abort();
  }
}

void Exception::severity(Severity newSeverity) {
  theSeverity = newSeverity;
  if ( noabort && ( theSeverity == abortnow || theSeverity == maybeabort ) )
       theSeverity = runerror;
  if ( theSeverity == abortnow ) {
    writeMessage(cerr);
    abort();
  }
}

void Exception::writeMessage(ostream & os) const {
  switch ( severity() ) {
  case unknown:
    os << "unknown error type: ";
    break;
  case info:
    os << "Informational exception: ";
    break;
  case warning:
    os << "Warning: ";
    break;
  case setuperror:
  case eventerror:
  case runerror:
  case maybeabort:
  case abortnow:
    os << "Error: ";
    break;
  }
  os << message() << endl;
  switch ( severity() ) {
  case eventerror:
    os << "The generated event will be discarded." << endl;
    break;
  case runerror:
    os << "This run will be aborted." << endl;
    break;
  case maybeabort:
  case abortnow:
    os << "The program will now abort and dump core." << endl;
    break;
  case unknown:
  case info:
  case warning:
  case setuperror:
    break;
  }
}

ostream * Exception::errstream = &cerr;

bool Exception::noabort = false;

}