Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4FilecoutDestination Class Reference

#include <G4FilecoutDestination.hh>

+ Inheritance diagram for G4FilecoutDestination:

Public Member Functions

 G4FilecoutDestination (const G4String &fname, std::ios_base::openmode mode=std::ios_base::app)
 
 ~G4FilecoutDestination () override
 
void SetFileName (const G4String &fname)
 
void Open (std::ios_base::openmode mode=std::ios_base::app)
 
void Close ()
 
G4int ReceiveG4debug (const G4String &msg) override
 
G4int ReceiveG4cout (const G4String &msg) override
 
G4int ReceiveG4cerr (const G4String &msg) override
 
- Public Member Functions inherited from G4coutDestination
 G4coutDestination ()=default
 
virtual ~G4coutDestination ()=default
 
void AddDebugTransformer (const Transformer &t)
 
void AddDebugTransformer (Transformer &&t)
 
void AddCoutTransformer (const Transformer &t)
 
void AddCoutTransformer (Transformer &&t)
 
void AddCerrTransformer (const Transformer &t)
 
void AddCerrTransformer (Transformer &&t)
 
virtual void ResetTransformers ()
 
G4int ReceiveG4debug_ (const G4String &msg)
 
G4int ReceiveG4cout_ (const G4String &msg)
 
G4int ReceiveG4cerr_ (const G4String &msg)
 

Additional Inherited Members

- Public Types inherited from G4coutDestination
using Transformer = std::function<G4bool(G4String&)>
 
- Protected Attributes inherited from G4coutDestination
std::vector< TransformertransformersDebug
 
std::vector< TransformertransformersCout
 
std::vector< TransformertransformersCerr
 
- Static Protected Attributes inherited from G4coutDestination
static G4MTGLOB_DLL G4coutDestinationmasterG4coutDestination = nullptr
 

Detailed Description

Definition at line 44 of file G4FilecoutDestination.hh.

Constructor & Destructor Documentation

◆ G4FilecoutDestination()

G4FilecoutDestination::G4FilecoutDestination ( const G4String & fname,
std::ios_base::openmode mode = std::ios_base::app )
inlineexplicit

Definition at line 47 of file G4FilecoutDestination.hh.

49 : m_name(fname)
50 , m_mode(mode)
51 , m_output(nullptr)
52 {}

◆ ~G4FilecoutDestination()

G4FilecoutDestination::~G4FilecoutDestination ( )
override

Definition at line 37 of file G4FilecoutDestination.cc.

38{
39 Close();
40 if(m_output)
41 {
42 m_output.reset();
43 }
44}

Member Function Documentation

◆ Close()

void G4FilecoutDestination::Close ( )

Definition at line 64 of file G4FilecoutDestination.cc.

65{
66 if(m_output && m_output->is_open())
67 {
68 m_output->close();
69 }
70}

Referenced by Open(), and ~G4FilecoutDestination().

◆ Open()

void G4FilecoutDestination::Open ( std::ios_base::openmode mode = std::ios_base::app)

Definition at line 47 of file G4FilecoutDestination.cc.

48{
49 if(m_name.empty())
50 {
51#ifndef __MIC
52 // Cannot use G4Exception, because G4cout/G4cerr is not setup
53 throw std::ios_base::failure("No output file name specified");
54#endif
55 }
56 if(m_output != nullptr && m_output->is_open())
57 {
58 Close();
59 }
60 m_output = std::make_unique<std::ofstream>(m_name, std::ios_base::out | mode);
61}

Referenced by ReceiveG4cerr(), ReceiveG4cout(), and ReceiveG4debug().

◆ ReceiveG4cerr()

G4int G4FilecoutDestination::ReceiveG4cerr ( const G4String & msg)
overridevirtual

Reimplemented from G4coutDestination.

Definition at line 95 of file G4FilecoutDestination.cc.

96{
97 if(m_output == nullptr || !m_output->is_open())
98 {
99 Open(m_mode);
100 }
101 *m_output << msg;
102 return 0;
103}
void Open(std::ios_base::openmode mode=std::ios_base::app)

◆ ReceiveG4cout()

G4int G4FilecoutDestination::ReceiveG4cout ( const G4String & msg)
overridevirtual

Reimplemented from G4coutDestination.

Definition at line 84 of file G4FilecoutDestination.cc.

85{
86 if(m_output == nullptr || !m_output->is_open())
87 {
88 Open(m_mode);
89 }
90 *m_output << msg;
91 return 0;
92}

◆ ReceiveG4debug()

G4int G4FilecoutDestination::ReceiveG4debug ( const G4String & msg)
overridevirtual

Reimplemented from G4coutDestination.

Definition at line 73 of file G4FilecoutDestination.cc.

74{
75 if(m_output == nullptr || !m_output->is_open())
76 {
77 Open(m_mode);
78 }
79 *m_output << msg;
80 return 0;
81}

◆ SetFileName()

void G4FilecoutDestination::SetFileName ( const G4String & fname)
inline

Definition at line 55 of file G4FilecoutDestination.hh.

55{ m_name = fname; }

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