Geant4 10.7.0
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)
 
virtual ~G4FilecoutDestination ()
 
void SetFileName (const G4String &fname)
 
void Open (std::ios_base::openmode mode=std::ios_base::app)
 
void Close ()
 
virtual G4int ReceiveG4cout (const G4String &msg) override
 
virtual G4int ReceiveG4cerr (const G4String &msg) override
 
- Public Member Functions inherited from G4coutDestination
 G4coutDestination ()=default
 
virtual ~G4coutDestination ()
 
void AddCoutTransformer (const Transformer &t)
 
void AddCoutTransformer (Transformer &&t)
 
void AddCerrTransformer (const Transformer &t)
 
void AddCerrTransformer (Transformer &&t)
 
virtual void ResetTransformers ()
 
virtual G4int ReceiveG4cout (const G4String &msg)
 
virtual G4int ReceiveG4cerr (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< 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 ( )
virtual

Definition at line 36 of file G4FilecoutDestination.cc.

37{
38 Close();
39 if(m_output)
40 m_output.reset();
41}

Member Function Documentation

◆ Close()

void G4FilecoutDestination::Close ( )

Definition at line 59 of file G4FilecoutDestination.cc.

60{
61 if(m_output && m_output->is_open())
62 {
63 m_output->close();
64 }
65}

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

◆ Open()

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

Definition at line 44 of file G4FilecoutDestination.cc.

45{
46 if(m_name.isNull())
47 {
48#ifndef __MIC
49 // Cannot use G4Exception, because G4cout/G4cerr is not setup
50 throw std::ios_base::failure("No output file name specified");
51#endif
52 }
53 if(m_output != nullptr && m_output->is_open())
54 Close();
55 m_output.reset(new std::ofstream(m_name, std::ios_base::out | mode));
56}
G4bool isNull() const

Referenced by ReceiveG4cerr(), and ReceiveG4cout().

◆ ReceiveG4cerr()

G4int G4FilecoutDestination::ReceiveG4cerr ( const G4String msg)
overridevirtual

Reimplemented from G4coutDestination.

Definition at line 77 of file G4FilecoutDestination.cc.

78{
79 if(m_output == nullptr || !m_output->is_open())
80 Open(m_mode);
81 *m_output << msg;
82 return 0;
83}
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 68 of file G4FilecoutDestination.cc.

69{
70 if(m_output == nullptr || !m_output->is_open())
71 Open(m_mode);
72 *m_output << msg;
73 return 0;
74}

◆ 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: