LDMX Software
simcore::LoggedSession Class Reference

Session that routes G4cout and G4cerr through the Framework logger. More...

#include <G4Session.h>

Public Member Functions

 LoggedSession (std::string logging_prefix="Geant4")
 Constructor - creates a logger named "Geant4".
 
 ~LoggedSession () override=default
 Destructor.
 
G4int ReceiveG4cout (const G4String &message) override
 Receive a message from G4cout.
 
G4int ReceiveG4cerr (const G4String &message) override
 Receive a message from G4cerr.
 

Private Attributes

framework::logging::logger the_log_
 Framework logger for Geant4 messages.
 

Detailed Description

Session that routes G4cout and G4cerr through the Framework logger.

This session intercepts all Geant4 output and routes it through the Framework's logging system with the logger name "Geant4". Messages are parsed to determine appropriate log levels:

  • G4cout with "WARNING" -> warn
  • G4cout with "ERROR" -> error
  • G4cout with verbose tracking info -> trace
  • G4cout default -> debug
  • G4cerr with "ERROR" or "FATAL" -> error
  • G4cerr default -> warn

Definition at line 33 of file G4Session.h.

Constructor & Destructor Documentation

◆ LoggedSession()

simcore::LoggedSession::LoggedSession ( std::string logging_prefix = "Geant4")

Constructor - creates a logger named "Geant4".

Definition at line 5 of file G4Session.cxx.

6 : the_log_{::framework::logging::makeLogger(logging_prefix)} {}
framework::logging::logger the_log_
Framework logger for Geant4 messages.
Definition G4Session.h:61

Member Function Documentation

◆ ReceiveG4cerr()

G4int simcore::LoggedSession::ReceiveG4cerr ( const G4String & message)
override

Receive a message from G4cerr.

Parameters
messageThe message from Geant4
Returns
0 for success

Definition at line 23 of file G4Session.cxx.

23 {
24 std::string message = msg;
25 std::transform(message.begin(), message.end(), message.begin(), ::toupper);
26
27 if (message.find("ERROR") != std::string::npos ||
28 message.find("FATAL") != std::string::npos) {
29 ldmx_log(error) << msg;
30 } else {
31 ldmx_log(debug) << msg;
32 }
33
34 return 0;
35}

◆ ReceiveG4cout()

G4int simcore::LoggedSession::ReceiveG4cout ( const G4String & message)
override

Receive a message from G4cout.

Parameters
messageThe message from Geant4
Returns
0 for success

Definition at line 8 of file G4Session.cxx.

8 {
9 std::string message = msg;
10 std::transform(message.begin(), message.end(), message.begin(), ::toupper);
11
12 if (message.find("WARNING") != std::string::npos) {
13 ldmx_log(warn) << msg;
14 } else if (message.find("ERROR") != std::string::npos) {
15 ldmx_log(error) << msg;
16 } else {
17 ldmx_log(debug) << msg;
18 }
19
20 return 0;
21}

Member Data Documentation

◆ the_log_

framework::logging::logger simcore::LoggedSession::the_log_
mutableprivate

Framework logger for Geant4 messages.

Definition at line 61 of file G4Session.h.


The documentation for this class was generated from the following files: