CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
ExceptionHandler Class Reference

#include <ExceptionHandler.h>

Inheritance diagram for ExceptionHandler:

Public Member Functions

 ExceptionHandler (double th, bool tr)
 
 ExceptionHandler (const ExceptionHandler &)=delete
 
bool Notify (const char *exceptionOrigin, const char *exceptionCode, G4ExceptionSeverity severity, const char *description) override
 
int operator!= (const ExceptionHandler &right) const
 
ExceptionHandleroperator= (const ExceptionHandler &right)=delete
 
int operator== (const ExceptionHandler &right) const
 
 ~ExceptionHandler () override
 

Private Attributes

double m_eth
 
int m_number {0}
 
bool m_trace
 

Detailed Description

Definition at line 19 of file ExceptionHandler.h.

Constructor & Destructor Documentation

◆ ExceptionHandler() [1/2]

ExceptionHandler::ExceptionHandler ( double  th,
bool  tr 
)
explicit

Definition at line 12 of file ExceptionHandler.cc.

12 : m_eth(th), m_trace(tr) {}

◆ ~ExceptionHandler()

ExceptionHandler::~ExceptionHandler ( )
override

Definition at line 14 of file ExceptionHandler.cc.

14 {}

◆ ExceptionHandler() [2/2]

ExceptionHandler::ExceptionHandler ( const ExceptionHandler )
delete

Member Function Documentation

◆ Notify()

bool ExceptionHandler::Notify ( const char *  exceptionOrigin,
const char *  exceptionCode,
G4ExceptionSeverity  severity,
const char *  description 
)
override

Definition at line 16 of file ExceptionHandler.cc.

References edmLumisInFiles::description, Exception, m_eth, m_number, m_trace, ValidateTausOnZEEFastSim_cff::proc, ErrorSummaryFilter_cfi::severity, and HLT_2022v14_cff::track.

19  {
20  static const G4String es_banner = "\n-------- EEEE ------- G4Exception-START -------- EEEE -------\n";
21  static const G4String ee_banner = "\n-------- EEEE -------- G4Exception-END --------- EEEE -------\n";
22  static const G4String ws_banner = "\n-------- WWWW ------- G4Exception-START -------- WWWW -------\n";
23  static const G4String we_banner = "\n-------- WWWW -------- G4Exception-END --------- WWWW -------\n";
24 
25  G4Track* track = G4EventManager::GetEventManager()->GetTrackingManager()->GetTrack();
26  double ekin = m_eth;
27 
28  std::stringstream message;
29  message << "*** G4Exception : " << exceptionCode << "\n"
30  << " issued by : " << exceptionOrigin << "\n"
31  << description;
32 
33  // part of exception happens outside tracking loop
34  if (nullptr != track) {
35  ekin = track->GetKineticEnergy();
36  message << "\n CMS info: "
37  << "TrackID=" << track->GetTrackID() << " ParentID=" << track->GetParentID() << " "
38  << track->GetParticleDefinition()->GetParticleName() << "; Ekin(MeV)=" << ekin / CLHEP::MeV
39  << "; time(ns)=" << track->GetGlobalTime() / CLHEP::ns << "; status=" << track->GetTrackStatus()
40  << "\n position(mm): " << track->GetPosition() << "; direction: " << track->GetMomentumDirection();
41  const G4VPhysicalVolume* vol = track->GetVolume();
42  if (nullptr != vol) {
43  message << "\n PhysicalVolume: " << vol->GetName() << ";";
44  const G4LogicalVolume* lv = vol->GetLogicalVolume();
45  if (nullptr != lv) {
46  message << " material: " << lv->GetMaterial()->GetName();
47  }
48  }
49  message << "\n stepNumber=" << track->GetCurrentStepNumber()
50  << "; stepLength(mm)=" << track->GetStepLength() / CLHEP::mm << "; weight=" << track->GetWeight();
51  const G4VProcess* proc = track->GetCreatorProcess();
52  if (nullptr != proc) {
53  message << "; creatorProcess: " << proc->GetProcessName() << "; modelID=" << track->GetCreatorModelID();
54  }
55  }
56  message << " \n";
57 
58  G4ExceptionSeverity localSeverity = severity;
59  std::stringstream mescode;
60  mescode << exceptionCode << "\n";
61  G4String code;
62  mescode >> code;
63 
64  // track is killed
65  if (ekin < m_eth && (code == "GeomNav0003" || code == "GeomField0003")) {
66  localSeverity = JustWarning;
67  track->SetTrackStatus(fStopAndKill);
68  ++m_number;
69  }
70 
71  bool res = false;
72  switch (localSeverity) {
73  case FatalException:
74  case FatalErrorInArgument:
75  case RunMustBeAborted:
76  case EventMustBeAborted:
77  edm::LogWarning("SimG4CoreApplication") << es_banner << message.str() << ee_banner;
78  throw cms::Exception("Geant4 fatal exception");
79  res = m_trace;
80  break;
81 
82  case JustWarning:
83  if (m_number < 20)
84  edm::LogWarning("SimG4CoreApplication")
85  << ws_banner << message.str() << "*** This is just a warning message. ***" << we_banner;
86  break;
87  }
88  return res;
89 }
Definition: Electron.h:6
Log< level::Warning, false > LogWarning

◆ operator!=()

int ExceptionHandler::operator!= ( const ExceptionHandler right) const
inline

Definition at line 25 of file ExceptionHandler.h.

25 { return (this != &right); }

◆ operator=()

ExceptionHandler& ExceptionHandler::operator= ( const ExceptionHandler right)
delete

◆ operator==()

int ExceptionHandler::operator== ( const ExceptionHandler right) const
inline

Definition at line 24 of file ExceptionHandler.h.

24 { return (this == &right); }

Member Data Documentation

◆ m_eth

double ExceptionHandler::m_eth
private

Definition at line 36 of file ExceptionHandler.h.

Referenced by Notify().

◆ m_number

int ExceptionHandler::m_number {0}
private

Definition at line 37 of file ExceptionHandler.h.

Referenced by Notify().

◆ m_trace

bool ExceptionHandler::m_trace
private

Definition at line 38 of file ExceptionHandler.h.

Referenced by Notify().