Geant4 9.6.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 52 of file G4XXXFileViewer.hh.

Constructor & Destructor Documentation

◆ FileWriter()

G4XXXFileViewer::FileWriter::FileWriter ( )
inline

Definition at line 54 of file G4XXXFileViewer.hh.

54: fOpen(false) {}

Member Function Documentation

◆ Close()

void G4XXXFileViewer::FileWriter::Close ( )

Definition at line 40 of file G4XXXFileViewer.cc.

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

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

◆ IsOpen()

G4bool G4XXXFileViewer::FileWriter::IsOpen ( )
inline

Definition at line 55 of file G4XXXFileViewer.hh.

55{return fOpen;}

◆ Rewind()

void G4XXXFileViewer::FileWriter::Rewind ( )
inline

Definition at line 59 of file G4XXXFileViewer.hh.

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

Referenced by G4XXXFileViewer::ClearView().

◆ WriteItem()

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

Definition at line 49 of file G4XXXFileViewer.cc.

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

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