Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4XXXFileViewer::FileWriter Class Reference

#include <G4XXXFileViewer.hh>

Public Member Functions

 FileWriter ()
 
G4bool IsOpen ()
 
void WriteItem (const G4String &item)
 
void Close ()
 
void Rewind ()
 

Detailed Description

Definition at line 51 of file G4XXXFileViewer.hh.

Constructor & Destructor Documentation

◆ FileWriter()

G4XXXFileViewer::FileWriter::FileWriter ( )
inline

Definition at line 53 of file G4XXXFileViewer.hh.

53: fOpen(false) {}

Member Function Documentation

◆ Close()

void G4XXXFileViewer::FileWriter::Close ( )

Definition at line 39 of file G4XXXFileViewer.cc.

40{
41 if (fOpen) {
42 G4cout << "Closing file " << fFileName << G4endl;
43 fFile.close();
44 fOpen = false;
45 }
46}
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout

Referenced by G4XXXFileViewer::ShowView(), and G4XXXFileViewer::~G4XXXFileViewer().

◆ IsOpen()

G4bool G4XXXFileViewer::FileWriter::IsOpen ( )
inline

Definition at line 54 of file G4XXXFileViewer.hh.

54{return fOpen;}

◆ Rewind()

void G4XXXFileViewer::FileWriter::Rewind ( )
inline

Definition at line 58 of file G4XXXFileViewer.hh.

58{if (fOpen) {fFile.close(); fFile.open(fFileName.c_str());}}

Referenced by G4XXXFileViewer::ClearView().

◆ WriteItem()

void G4XXXFileViewer::FileWriter::WriteItem ( const G4String item)

Definition at line 48 of file G4XXXFileViewer.cc.

49{
50 if (!fOpen)
51 {
52 std::ifstream ifs;
53 std::ostringstream oss;
54 G4int i = 0;
55 do {
56 oss.str("");
57 oss << "g4_" << i << ".XXXFile";
58 ifs.open(oss.str().c_str());
59 if (!ifs) break; // Doesn't exist, so can open a new file.
60 else ifs.close();
61 ++i;
62 } while(true);
63 fFileName = oss.str();
64 G4cout << "Opening file " << fFileName << G4endl;
65 fFile.open(fFileName.c_str());
66 fOpen = true;
67 }
68 if (fFile.good()) fFile << item << std::endl;
69 else G4cout << "G4XXXFileViewer::FileWriter::WriteItem: ERROR" << G4endl;
70}
int G4int
Definition: G4Types.hh:85

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