Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4Timer.cc File Reference
#include "G4Timer.hh"
#include "G4ios.hh"
#include <iomanip>
#include "G4ExceptionSeverity.hh"

Go to the source code of this file.

Functions

void G4Exception (const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
 
std::ostream & operator<< (std::ostream &os, const G4Timer &t)
 

Function Documentation

◆ G4Exception()

void G4Exception ( const char *  originOfException,
const char *  exceptionCode,
G4ExceptionSeverity  severity,
const char *  comments 
)

Definition at line 35 of file G4Exception.cc.

37{
38 G4VExceptionHandler* exceptionHandler =
40 G4bool toBeAborted = true;
41 if(exceptionHandler != nullptr)
42 {
43 toBeAborted = exceptionHandler->Notify(originOfException, exceptionCode,
44 severity, description);
45 }
46 else
47 {
48 static const G4String& es_banner = G4ExceptionErrBannerStart();
49 static const G4String& ee_banner = G4ExceptionErrBannerEnd();
50 static const G4String& ws_banner = G4ExceptionWarnBannerStart();
51 static const G4String& we_banner = G4ExceptionWarnBannerEnd();
52 std::ostringstream message;
53 message << "\n*** ExceptionHandler is not defined ***\n"
54 << "*** G4Exception : " << exceptionCode << G4endl
55 << " issued by : " << originOfException << G4endl
56 << description << G4endl;
57 switch(severity)
58 {
59 case FatalException:
60 G4cerr << es_banner << message.str() << "*** Fatal Exception ***"
61 << ee_banner << G4endl;
62 break;
64 G4cerr << es_banner << message.str()
65 << "*** Fatal Error In Argument ***" << ee_banner << G4endl;
66 break;
68 G4cerr << es_banner << message.str() << "*** Run Must Be Aborted ***"
69 << ee_banner << G4endl;
70 break;
72 G4cerr << es_banner << message.str() << "*** Event Must Be Aborted ***"
73 << ee_banner << G4endl;
74 break;
75 default:
76 G4cout << ws_banner << message.str()
77 << "*** This is just a warning message. ***" << we_banner
78 << G4endl;
79 toBeAborted = false;
80 break;
81 }
82 }
83 if(toBeAborted)
84 {
86 {
87 G4cerr << G4endl << "*** G4Exception: Aborting execution ***" << G4endl;
88 abort();
89 }
90 else
91 {
92 G4cerr << G4endl << "*** G4Exception: Abortion suppressed ***" << G4endl
93 << "*** No guarantee for further execution ***" << G4endl;
94 }
95 }
96}
@ G4State_Abort
@ FatalException
@ FatalErrorInArgument
@ RunMustBeAborted
@ EventMustBeAborted
const G4String G4ExceptionErrBannerEnd()
Definition: G4Exception.hh:51
const G4String G4ExceptionErrBannerStart()
Definition: G4Exception.hh:42
const G4String G4ExceptionWarnBannerEnd()
Definition: G4Exception.hh:55
const G4String G4ExceptionWarnBannerStart()
Definition: G4Exception.hh:46
bool G4bool
Definition: G4Types.hh:86
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
G4VExceptionHandler * GetExceptionHandler() const
static G4StateManager * GetStateManager()
virtual G4bool Notify(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)=0

Referenced by G4Exception().

◆ operator<<()

std::ostream & operator<< ( std::ostream &  os,
const G4Timer t 
)

Definition at line 88 of file G4Timer.cc.

89{
90 // so fixed doesn't propagate
91 std::stringstream ss;
92 ss << std::fixed;
93 if(t.IsValid())
94 {
95 ss << "User=" << t.GetUserElapsed() << "s Real=" << t.GetRealElapsed()
96 << "s Sys=" << t.GetSystemElapsed() << "s";
97#ifdef G4MULTITHREADED
98 // avoid possible FPE error
99 if(t.GetRealElapsed() > 1.0e-6)
100 {
101 G4double cpu_util = (t.GetUserElapsed() + t.GetSystemElapsed()) /
102 t.GetRealElapsed() * 100.0;
103 ss << std::setprecision(1);
104 ss << " [Cpu=" << std::setprecision(1) << cpu_util << "%]";
105 }
106#endif
107 }
108 else
109 {
110 ss << "User=****s Real=****s Sys=****s";
111 }
112 os << ss.str();
113
114 return os;
115}
double G4double
Definition: G4Types.hh:83
G4double GetSystemElapsed() const
Definition: G4Timer.cc:132
G4bool IsValid() const
G4double GetUserElapsed() const
Definition: G4Timer.cc:143
G4double GetRealElapsed() const
Definition: G4Timer.cc:121