Message: Re: Where is the definition of G4cout? Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

None Re: Where is the definition of G4cout? 

Forum: Run Management
Re: Question Where is the definition of G4cout? (Gianfranco Gargano)
Date: 11 Jul, 2011
From: Joel Long <Joel Long>

On Fri, 08 Jul 2011 08:59:47 GMT, Gianfranco Gargano wrote:
> I need to know how to control the way G4cout transmit string to
> G4coutDestination. Someone could show me where G4cout is defined?
> 

Hello,

The attached class demonstrate rerouting G4cout and G4cerr to a user-supplied filepath. Extend G4UISession, implementing RecieveG4cour and RecieveG4cerr as needed for your application.

Hope this helps, Joel

P.S. It won't let me attach the files for some reason, but they are short, so I'll copy their contents here.

This is the header file:

#ifndef LoggedSession_hh
#define LoggedSession_hh

#include "G4UIsession.hh"
#include <iostream>
#include <fstream>

using namespace std;

class LoggedSession : G4UIsession {
public:
	LoggedSession(G4String,G4String);
	~LoggedSession();

	G4UIsession* SessionStart();
	G4int ReceiveG4cout(G4String);
	G4int ReceiveG4cerr(G4String);

private:
	ofstream outFile;
	ofstream errFile;
};

#endif

And here is the cc file:

#include "LoggedSession.hh"
#include "G4UImanager.hh"

LoggedSession::LoggedSession(G4String outputFileName,G4String errFileName){
//	outFile = ofstream(outputFileName);
//	errFile = ofstream(inputFileName);
	outFile.open(outputFileName);
	errFile.open(errFileName);
	G4UImanager* UI = G4UImanager::GetUIpointer();
	UI->SetCoutDestination(this);
}

LoggedSession::~LoggedSession(){
	outFile.close();
	errFile.close();
}

G4UIsession* LoggedSession::SessionStart(){
	return NULL;
}

G4int LoggedSession::ReceiveG4cout(G4String output){
	outFile<<output;
	outFile.flush();
	return 0;
}

G4int LoggedSession::ReceiveG4cerr(G4String err){
	errFile<<err;
	errFile.flush();
	return 0;
}

 Add Message Add Message
to: "Re: Where is the definition of G4cout?"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews


[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]