Import Geant4 9.6.0 source tree
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4UIaliasList.cc,v 1.6 2006-06-29 19:08:33 gunter Exp $
|
||||
//
|
||||
|
||||
#include "G4AnyType.hh"
|
||||
#include "G4UIcommand.hh"
|
||||
#include "G4Types.hh"
|
||||
#include "G4ThreeVector.hh"
|
||||
|
||||
template <> void G4AnyType::Ref<bool>::FromString(const std::string& val) {
|
||||
fRef = G4UIcommand::ConvertToBool(val.c_str());
|
||||
}
|
||||
|
||||
template <> void G4AnyType::Ref<G4String>::FromString(const std::string& val) {
|
||||
if (val[0] == '"' ) fRef = val.substr(1,val.size()-2);
|
||||
else fRef = val;
|
||||
}
|
||||
|
||||
template <> void G4AnyType::Ref<G4ThreeVector>::FromString(const std::string& val) {
|
||||
fRef = G4UIcommand::ConvertTo3Vector(val.c_str());
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4UIaliasList.cc,v 1.6 2006-06-29 19:08:33 gunter Exp $
|
||||
//
|
||||
|
||||
#include "G4GenericMessenger.hh"
|
||||
#include "G4Types.hh"
|
||||
#include "G4UImessenger.hh"
|
||||
#include "G4UIcommand.hh"
|
||||
#include "G4UIcmdWithADoubleAndUnit.hh"
|
||||
#include "G4UIcmdWith3VectorAndUnit.hh"
|
||||
#include "G4UIdirectory.hh"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class G4InvalidUICommand: public std::bad_cast {
|
||||
public:
|
||||
G4InvalidUICommand() {}
|
||||
virtual const char* what() const throw() {
|
||||
return "G4InvalidUICommand: command does not exists or is of invalid type";
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
G4GenericMessenger::G4GenericMessenger(void* obj, const G4String& dir, const G4String& doc): directory(dir), object(obj) {
|
||||
// Check if parent commnand is already existing.
|
||||
// In fact there is no way to check this. UImanager->GetTree()->FindPath() will always rerurn NULL is a dicrectory is given
|
||||
size_t pos = dir.find_last_of('/', dir.size()-2);
|
||||
while(pos != 0 && pos != std::string::npos) {
|
||||
G4UIdirectory* d = new G4UIdirectory(dir.substr(0,pos+1).c_str());
|
||||
G4String guidance = "Commands for ";
|
||||
guidance += dir.substr(1,pos-1);
|
||||
d->SetGuidance(guidance);
|
||||
pos = dir.find_last_of('/', pos-1);
|
||||
}
|
||||
dircmd = new G4UIdirectory(dir);
|
||||
dircmd->SetGuidance(doc);
|
||||
}
|
||||
|
||||
G4GenericMessenger::~G4GenericMessenger() {
|
||||
delete dircmd;
|
||||
for (std::map<G4String, Property>::iterator i = properties.begin(); i != properties.end(); i++) delete i->second.command;
|
||||
for (std::map<G4String, Method>::iterator i = methods.begin(); i != methods.end(); i++) delete i->second.command;
|
||||
}
|
||||
|
||||
|
||||
G4GenericMessenger::Command&
|
||||
G4GenericMessenger::DeclareProperty(const G4String& name, const G4AnyType& var, const G4String& doc) {
|
||||
G4String fullpath = directory+name;
|
||||
G4UIcommand* cmd = new G4UIcommand(fullpath.c_str(), this);
|
||||
if(doc != "") cmd->SetGuidance(doc);
|
||||
char ptype;
|
||||
if(var.TypeInfo() == typeid(int) || var.TypeInfo() == typeid(long) ||
|
||||
var.TypeInfo() == typeid(unsigned int) || var.TypeInfo() == typeid(unsigned long)) ptype = 'i';
|
||||
else if(var.TypeInfo() == typeid(float) || var.TypeInfo() == typeid(double)) ptype = 'd';
|
||||
else if(var.TypeInfo() == typeid(bool)) ptype = 'b';
|
||||
else if(var.TypeInfo() == typeid(G4String)) ptype = 's';
|
||||
else ptype = 's';
|
||||
cmd->SetParameter(new G4UIparameter("value", ptype, false));
|
||||
return properties[name] = Property(var, cmd);
|
||||
}
|
||||
|
||||
|
||||
G4GenericMessenger::Command&
|
||||
G4GenericMessenger::DeclareMethod(const G4String& name, const G4AnyMethod& fun, const G4String& doc) {
|
||||
G4String fullpath = directory+name;
|
||||
G4UIcommand* cmd = new G4UIcommand(fullpath.c_str(), this);
|
||||
if(doc != "") cmd->SetGuidance(doc);
|
||||
for (size_t i = 0; i < fun.NArg(); i++) {
|
||||
cmd->SetParameter(new G4UIparameter("arg", 's', false));
|
||||
}
|
||||
return methods[name] = Method(fun, object, cmd);
|
||||
}
|
||||
|
||||
G4String G4GenericMessenger::GetCurrentValue(G4UIcommand* command) {
|
||||
if ( properties.find(command->GetCommandName()) != properties.end()) {
|
||||
Property& p = properties[command->GetCommandName()];
|
||||
return p.variable.ToString();
|
||||
}
|
||||
else {
|
||||
throw G4InvalidUICommand();
|
||||
}
|
||||
}
|
||||
|
||||
void G4GenericMessenger::SetNewValue(G4UIcommand* command, G4String newValue) {
|
||||
// Check if there are units on this commands
|
||||
if (typeid(*command) == typeid(G4UIcmdWithADoubleAndUnit)) {
|
||||
newValue = G4UIcommand::ConvertToString(G4UIcommand::ConvertToDimensionedDouble(newValue));
|
||||
}
|
||||
else if (typeid(*command) == typeid(G4UIcmdWith3VectorAndUnit)) {
|
||||
newValue = G4UIcommand::ConvertToString(G4UIcommand::ConvertToDimensioned3Vector(newValue));
|
||||
}
|
||||
|
||||
if ( properties.find(command->GetCommandName()) != properties.end()) {
|
||||
Property& p = properties[command->GetCommandName()];
|
||||
p.variable.FromString(newValue);
|
||||
}
|
||||
else if (methods.find(command->GetCommandName()) != methods.end()) {
|
||||
Method& m = methods[command->GetCommandName()];
|
||||
if(m.method.NArg() == 0)
|
||||
m.method.operator()(m.object);
|
||||
else if (m.method.NArg() > 0) {
|
||||
m.method.operator()(m.object,newValue);
|
||||
}
|
||||
else {
|
||||
throw G4InvalidUICommand();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void G4GenericMessenger::SetGuidance(const G4String& s) {
|
||||
dircmd->SetGuidance(s);
|
||||
}
|
||||
|
||||
|
||||
G4GenericMessenger::Command& G4GenericMessenger::Command::SetUnit(const G4String& unit, UnitSpec spec) {
|
||||
// Change the type of command (unfortunatelly this is done a posteriory)
|
||||
// We need to delete the old command before creating the new one and therefore we need to recover the information
|
||||
// before the deletetion
|
||||
G4String cmdpath = command->GetCommandPath();
|
||||
G4UImessenger* messenger = command->GetMessenger();
|
||||
G4String range = command->GetRange();
|
||||
std::vector<G4String> guidance;
|
||||
for (G4int i = 0; i < command->GetGuidanceEntries(); i++) guidance.push_back(command->GetGuidanceLine(i));
|
||||
// Before deleting the command we need to add a fake one to avoid deleting the directory entry and with its guidance
|
||||
G4UIcommand tmp((cmdpath+"_tmp").c_str(), messenger);
|
||||
delete command;
|
||||
|
||||
if (*type == typeid(float) || *type == typeid(double) ) {
|
||||
G4UIcmdWithADoubleAndUnit* cmd_t = new G4UIcmdWithADoubleAndUnit(cmdpath, messenger);
|
||||
if(spec == UnitDefault) cmd_t->SetDefaultUnit(unit);
|
||||
else if(spec == UnitCategory) cmd_t->SetUnitCategory(unit);
|
||||
command = cmd_t;
|
||||
}
|
||||
else if (*type == typeid(G4ThreeVector)) {
|
||||
G4UIcmdWith3VectorAndUnit* cmd_t = new G4UIcmdWith3VectorAndUnit(cmdpath, messenger);
|
||||
if(spec == UnitDefault) cmd_t->SetDefaultUnit(unit);
|
||||
else if(spec == UnitCategory) cmd_t->SetUnitCategory(unit);
|
||||
command = cmd_t;
|
||||
}
|
||||
else {
|
||||
G4cerr << "Only parameters of type <double> or <float> can be associated with units" << G4endl;
|
||||
return *this;
|
||||
}
|
||||
for (size_t i = 0; i < guidance.size(); i++) command->SetGuidance(guidance[i]);
|
||||
command->SetRange(range);
|
||||
return *this;
|
||||
}
|
||||
|
||||
G4GenericMessenger::Command& G4GenericMessenger::Command::SetParameterName(const G4String& name,G4bool omittable, G4bool currentAsDefault) {
|
||||
G4UIparameter* theParam = command->GetParameter(0);
|
||||
theParam->SetParameterName(name);
|
||||
theParam->SetOmittable(omittable);
|
||||
theParam->SetCurrentAsDefault(currentAsDefault);
|
||||
return *this;
|
||||
}
|
||||
|
||||
G4GenericMessenger::Command& G4GenericMessenger::Command::SetCandidates(const G4String& candList) {
|
||||
G4UIparameter * theParam = command->GetParameter(0);
|
||||
theParam->SetParameterCandidates(candList);
|
||||
return *this;
|
||||
}
|
||||
|
||||
G4GenericMessenger::Command& G4GenericMessenger::Command::SetDefaultValue(const G4String& defVal) {
|
||||
G4UIparameter * theParam = command->GetParameter(0);
|
||||
theParam->SetDefaultValue(defVal);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -24,8 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4UIaliasList.cc,v 1.6 2006-06-29 19:08:33 gunter Exp $
|
||||
// GEANT4 tag $Name: not supported by cvs2svn $
|
||||
// $Id$
|
||||
//
|
||||
|
||||
#include "G4UIaliasList.hh"
|
||||
|
||||
@@ -23,8 +23,7 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id: G4UIbatch.cc,v 1.18 2010-11-11 11:30:45 gcosmo Exp $
|
||||
// GEANT4 tag $Name: not supported by cvs2svn $
|
||||
// $Id$
|
||||
//
|
||||
// ====================================================================
|
||||
// G4UIbatch.cc
|
||||
@@ -43,7 +42,7 @@ static void Tokenize(const G4String& str, std::vector<G4String>& tokens)
|
||||
|
||||
G4String::size_type pos0= str.find_first_not_of(delimiter);
|
||||
G4String::size_type pos = str.find_first_of(delimiter, pos0);
|
||||
|
||||
|
||||
while (pos != G4String::npos || pos0 != G4String::npos) {
|
||||
if (str[pos0] == '\"') {
|
||||
pos = str.find_first_of("\"", pos0+1);
|
||||
@@ -67,14 +66,14 @@ static void Tokenize(const G4String& str, std::vector<G4String>& tokens)
|
||||
// ====================================================================
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
G4UIbatch::G4UIbatch(const char* fileName, G4UIsession* prevSession)
|
||||
G4UIbatch::G4UIbatch(const char* fileName, G4UIsession* prevSession)
|
||||
: previousSession(prevSession), isOpened(false)
|
||||
////////////////////////////////////////////////////////////////////
|
||||
{
|
||||
macroStream.open(fileName, std::ios::in);
|
||||
if(macroStream.fail()) {
|
||||
G4cerr << "***** Can not open a macro file <"
|
||||
<< fileName << ">"
|
||||
G4cerr << "***** Can not open a macro file <"
|
||||
<< fileName << ">"
|
||||
<< G4endl;
|
||||
} else {
|
||||
isOpened= true;
|
||||
@@ -85,7 +84,7 @@ G4UIbatch::G4UIbatch(const char* fileName, G4UIsession* prevSession)
|
||||
|
||||
|
||||
///////////////////////
|
||||
G4UIbatch::~G4UIbatch()
|
||||
G4UIbatch::~G4UIbatch()
|
||||
///////////////////////
|
||||
{
|
||||
if(isOpened) macroStream.close();
|
||||
@@ -98,6 +97,7 @@ G4String G4UIbatch::ReadCommand()
|
||||
{
|
||||
enum { BUFSIZE= 4096 };
|
||||
static char linebuf[BUFSIZE];
|
||||
const char ctrM = 0x0d;
|
||||
|
||||
G4String cmdtotal= "";
|
||||
G4bool qcontinued= false;
|
||||
@@ -114,6 +114,7 @@ G4String G4UIbatch::ReadCommand()
|
||||
|
||||
// strip
|
||||
cmdline= cmdline.strip(G4String::both);
|
||||
cmdline= cmdline.strip(G4String::trailing, ctrM);
|
||||
|
||||
// skip null line if single line
|
||||
if(!qcontinued && cmdline.size()==0) continue;
|
||||
@@ -190,7 +191,7 @@ G4int G4UIbatch::ExecCommand(const G4String& command)
|
||||
|
||||
|
||||
///////////////////////////////////////
|
||||
G4UIsession * G4UIbatch::SessionStart()
|
||||
G4UIsession * G4UIbatch::SessionStart()
|
||||
///////////////////////////////////////
|
||||
{
|
||||
if(!isOpened) return previousSession;
|
||||
@@ -198,14 +199,14 @@ G4UIsession * G4UIbatch::SessionStart()
|
||||
while(1) {
|
||||
G4String newCommand = ReadCommand();
|
||||
|
||||
if(newCommand == "exit") {
|
||||
if(newCommand == "exit") {
|
||||
break;
|
||||
}
|
||||
|
||||
// just echo something
|
||||
if( newCommand[(size_t)0] == '#') {
|
||||
if( newCommand[(size_t)0] == '#') {
|
||||
if(G4UImanager::GetUIpointer()-> GetVerboseLevel()==2) {
|
||||
G4cout << newCommand << G4endl;
|
||||
G4cout << newCommand << G4endl;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -222,9 +223,9 @@ G4UIsession * G4UIbatch::SessionStart()
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
void G4UIbatch::PauseSessionStart(G4String Prompt)
|
||||
//////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////
|
||||
void G4UIbatch::PauseSessionStart(const G4String& Prompt)
|
||||
/////////////////////////////////////////////////////////
|
||||
{
|
||||
G4cout << "Pause session <" << Prompt << "> start." << G4endl;
|
||||
|
||||
|
||||
@@ -24,8 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4UIcmdWith3Vector.cc,v 1.8 2006-06-29 19:08:38 gunter Exp $
|
||||
// GEANT4 tag $Name: not supported by cvs2svn $
|
||||
// $Id$
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
@@ -24,8 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4UIcmdWith3VectorAndUnit.cc,v 1.10 2010-08-03 07:10:47 kmura Exp $
|
||||
// GEANT4 tag $Name: not supported by cvs2svn $
|
||||
// $Id$
|
||||
//
|
||||
//
|
||||
|
||||
@@ -52,9 +51,9 @@ G4UIcmdWith3VectorAndUnit::G4UIcmdWith3VectorAndUnit
|
||||
G4int G4UIcmdWith3VectorAndUnit::DoIt(G4String parameterList)
|
||||
{
|
||||
std::vector<G4String> token_vector;
|
||||
G4Tokenizer token(parameterList);
|
||||
G4Tokenizer tkn(parameterList);
|
||||
G4String str;
|
||||
while( (str = token()) != "" ) {
|
||||
while( (str = tkn()) != "" ) {
|
||||
token_vector.push_back(str);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,8 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4UIcmdWithABool.cc,v 1.8 2006-06-29 19:08:43 gunter Exp $
|
||||
// GEANT4 tag $Name: not supported by cvs2svn $
|
||||
// $Id$
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
@@ -24,8 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4UIcmdWithADouble.cc,v 1.8 2006-06-29 19:08:45 gunter Exp $
|
||||
// GEANT4 tag $Name: not supported by cvs2svn $
|
||||
// $Id$
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
@@ -24,8 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4UIcmdWithADoubleAndUnit.cc,v 1.10 2010-08-03 07:10:47 kmura Exp $
|
||||
// GEANT4 tag $Name: not supported by cvs2svn $
|
||||
// $Id$
|
||||
//
|
||||
//
|
||||
|
||||
@@ -49,9 +48,9 @@ G4UIcmdWithADoubleAndUnit::G4UIcmdWithADoubleAndUnit
|
||||
G4int G4UIcmdWithADoubleAndUnit::DoIt(G4String parameterList)
|
||||
{
|
||||
std::vector<G4String> token_vector;
|
||||
G4Tokenizer token(parameterList);
|
||||
G4Tokenizer tkn(parameterList);
|
||||
G4String str;
|
||||
while( (str = token()) != "" ) {
|
||||
while( (str = tkn()) != "" ) {
|
||||
token_vector.push_back(str);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,8 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4UIcmdWithAString.cc,v 1.6 2006-06-29 19:08:50 gunter Exp $
|
||||
// GEANT4 tag $Name: not supported by cvs2svn $
|
||||
// $Id$
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
@@ -24,8 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4UIcmdWithAnInteger.cc,v 1.8 2006-06-29 19:08:52 gunter Exp $
|
||||
// GEANT4 tag $Name: not supported by cvs2svn $
|
||||
// $Id$
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
@@ -24,8 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4UIcmdWithoutParameter.cc,v 1.4 2006-06-29 19:08:54 gunter Exp $
|
||||
// GEANT4 tag $Name: not supported by cvs2svn $
|
||||
// $Id$
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
@@ -24,8 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4UIcommand.cc,v 1.25 2006-06-29 19:08:56 gunter Exp $
|
||||
// GEANT4 tag $Name: not supported by cvs2svn $
|
||||
// $Id$
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
@@ -24,8 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4UIcommandTree.cc,v 1.16 2009-11-06 06:16:07 kmura Exp $
|
||||
// GEANT4 tag $Name: not supported by cvs2svn $
|
||||
// $Id$
|
||||
//
|
||||
|
||||
#include "G4UIcommandTree.hh"
|
||||
@@ -159,7 +158,7 @@ void G4UIcommandTree::RemoveCommand(G4UIcommand *aCommand)
|
||||
// L. Garnier 01.28.08 This function has not a good name. In fact, it try
|
||||
// to match a command name, not a path. It should be rename as FindCommandName
|
||||
|
||||
G4UIcommand * G4UIcommandTree::FindPath(const char* commandPath)
|
||||
G4UIcommand * G4UIcommandTree::FindPath(const char* commandPath) const
|
||||
{
|
||||
G4String remainingPath = commandPath;
|
||||
if( remainingPath.index( pathName ) == std::string::npos )
|
||||
@@ -197,7 +196,7 @@ G4UIcommand * G4UIcommandTree::FindPath(const char* commandPath)
|
||||
* @commandPath : command or path to match
|
||||
* @return the commandTree found or NULL if not
|
||||
*/
|
||||
G4UIcommandTree * G4UIcommandTree::FindCommandTree(const char* commandPath)
|
||||
G4UIcommandTree* G4UIcommandTree::FindCommandTree(const char* commandPath)
|
||||
{
|
||||
G4String remainingPath = commandPath;
|
||||
if( remainingPath.index( pathName ) == std::string::npos )
|
||||
@@ -225,23 +224,23 @@ G4UIcommandTree * G4UIcommandTree::FindCommandTree(const char* commandPath)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
G4String G4UIcommandTree::CompleteCommandPath(const G4String aCommandPath)
|
||||
G4String G4UIcommandTree::CompleteCommandPath(const G4String& aCommandPath)
|
||||
{
|
||||
G4String pathName = aCommandPath;
|
||||
G4String pName = aCommandPath;
|
||||
G4String remainingPath = aCommandPath;
|
||||
G4String empty = "";
|
||||
G4String matchingPath = empty;
|
||||
|
||||
// find the tree
|
||||
G4int jpre= pathName.last('/');
|
||||
if(jpre != G4int(G4String::npos)) pathName.remove(jpre+1);
|
||||
G4UIcommandTree* aTree = FindCommandTree(pathName);
|
||||
G4int jpre= pName.last('/');
|
||||
if(jpre != G4int(G4String::npos)) pName.remove(jpre+1);
|
||||
G4UIcommandTree* aTree = FindCommandTree(pName);
|
||||
|
||||
if (!aTree) {
|
||||
return empty;
|
||||
}
|
||||
|
||||
if( pathName.index( pathName ) == std::string::npos ) return empty;
|
||||
if( pName.index( pName ) == std::string::npos ) return empty;
|
||||
|
||||
std::vector<G4String> paths;
|
||||
|
||||
@@ -326,7 +325,7 @@ G4String G4UIcommandTree::GetFirstMatchedString(const G4String& str1,
|
||||
return strMatched;
|
||||
}
|
||||
|
||||
void G4UIcommandTree::ListCurrent()
|
||||
void G4UIcommandTree::ListCurrent() const
|
||||
{
|
||||
G4cout << "Command directory path : " << pathName << G4endl;
|
||||
if( guidance != NULL ) guidance->List();
|
||||
@@ -346,7 +345,7 @@ void G4UIcommandTree::ListCurrent()
|
||||
}
|
||||
}
|
||||
|
||||
void G4UIcommandTree::ListCurrentWithNum()
|
||||
void G4UIcommandTree::ListCurrentWithNum() const
|
||||
{
|
||||
G4cout << "Command directory path : " << pathName << G4endl;
|
||||
if( guidance != NULL ) guidance->List();
|
||||
@@ -369,7 +368,7 @@ void G4UIcommandTree::ListCurrentWithNum()
|
||||
}
|
||||
}
|
||||
|
||||
void G4UIcommandTree::List()
|
||||
void G4UIcommandTree::List() const
|
||||
{
|
||||
ListCurrent();
|
||||
G4int n_commandEntry = command.size();
|
||||
|
||||
@@ -24,8 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4UIcontrolMessenger.cc,v 1.12 2010-08-25 06:09:57 asaim Exp $
|
||||
// GEANT4 tag $Name: not supported by cvs2svn $
|
||||
// $Id$
|
||||
//
|
||||
|
||||
#include <stdlib.h>
|
||||
@@ -48,6 +47,11 @@ G4UIcontrolMessenger::G4UIcontrolMessenger()
|
||||
controlDirectory = new G4UIdirectory("/control/");
|
||||
controlDirectory->SetGuidance("UI control commands.");
|
||||
|
||||
macroPathCommand = new G4UIcmdWithAString("/control/macroPath",this);
|
||||
macroPathCommand->SetGuidance("Set macro search path"
|
||||
"with colon-separated list.");
|
||||
macroPathCommand->SetParameterName("path",false);
|
||||
|
||||
ExecuteCommand = new G4UIcmdWithAString("/control/execute",this);
|
||||
ExecuteCommand->SetGuidance("Execute a macro file.");
|
||||
ExecuteCommand->SetParameterName("fileName",false);
|
||||
@@ -233,6 +237,7 @@ G4UIcontrolMessenger::G4UIcontrolMessenger()
|
||||
|
||||
G4UIcontrolMessenger::~G4UIcontrolMessenger()
|
||||
{
|
||||
delete macroPathCommand;
|
||||
delete ExecuteCommand;
|
||||
delete suppressAbortionCommand;
|
||||
delete verboseCommand;
|
||||
@@ -262,10 +267,14 @@ G4UIcontrolMessenger::~G4UIcontrolMessenger()
|
||||
void G4UIcontrolMessenger::SetNewValue(G4UIcommand * command,G4String newValue)
|
||||
{
|
||||
G4UImanager * UI = G4UImanager::GetUIpointer();
|
||||
|
||||
|
||||
if( command == macroPathCommand) {
|
||||
UI-> SetMacroSearchPath(newValue);
|
||||
UI-> ParseMacroSearchPath();
|
||||
}
|
||||
if(command==ExecuteCommand)
|
||||
{
|
||||
UI->ExecuteMacroFile(newValue);
|
||||
UI-> ExecuteMacroFile(UI-> FindMacroPath(newValue));
|
||||
}
|
||||
if(command==suppressAbortionCommand)
|
||||
{
|
||||
@@ -417,6 +426,9 @@ G4String G4UIcontrolMessenger::GetCurrentValue(G4UIcommand * command)
|
||||
G4UImanager * UI = G4UImanager::GetUIpointer();
|
||||
G4String currentValue;
|
||||
|
||||
if( command == macroPathCommand ) {
|
||||
currentValue = UI-> GetMacroSearchPath();
|
||||
}
|
||||
if(command==verboseCommand)
|
||||
{
|
||||
currentValue = verboseCommand->ConvertToString(UI->GetVerboseLevel());
|
||||
|
||||
@@ -24,8 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4UIdirectory.cc,v 1.4 2006-06-29 19:09:02 gunter Exp $
|
||||
// GEANT4 tag $Name: not supported by cvs2svn $
|
||||
// $Id$
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
@@ -24,10 +24,9 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4UImanager.cc,v 1.34 2010-05-19 14:50:30 lgarnier Exp $
|
||||
// GEANT4 tag $Name: not supported by cvs2svn $
|
||||
// $Id$
|
||||
//
|
||||
//
|
||||
//
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
#include "G4UImanager.hh"
|
||||
@@ -44,14 +43,14 @@
|
||||
#include "G4Tokenizer.hh"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
G4UImanager * G4UImanager::fUImanager = 0;
|
||||
G4bool G4UImanager::fUImanagerHasBeenKilled = false;
|
||||
|
||||
G4UImanager * G4UImanager::GetUIpointer()
|
||||
{
|
||||
if(!fUImanager)
|
||||
if(!fUImanager)
|
||||
{
|
||||
if(!fUImanagerHasBeenKilled)
|
||||
{
|
||||
@@ -79,6 +78,7 @@ G4UImanager::G4UImanager()
|
||||
pauseAtBeginOfEvent = false;
|
||||
pauseAtEndOfEvent = false;
|
||||
maxHistSize = 20;
|
||||
searchPath="";
|
||||
}
|
||||
|
||||
void G4UImanager::CreateMessenger()
|
||||
@@ -123,7 +123,7 @@ G4String G4UImanager::GetCurrentValues(const char * aCommand)
|
||||
{
|
||||
G4String theCommand = aCommand;
|
||||
savedCommand = treeTop->FindPath( theCommand );
|
||||
if( savedCommand == NULL )
|
||||
if( savedCommand == NULL )
|
||||
{
|
||||
G4cerr << "command not found" << G4endl;
|
||||
return G4String();
|
||||
@@ -131,7 +131,7 @@ G4String G4UImanager::GetCurrentValues(const char * aCommand)
|
||||
return savedCommand->GetCurrentValue();
|
||||
}
|
||||
|
||||
G4String G4UImanager::GetCurrentStringValue(const char * aCommand,
|
||||
G4String G4UImanager::GetCurrentStringValue(const char * aCommand,
|
||||
G4int parameterNumber, G4bool reGet)
|
||||
{
|
||||
if(reGet || savedCommand == NULL)
|
||||
@@ -153,7 +153,7 @@ G4int parameterNumber, G4bool reGet)
|
||||
return token;
|
||||
}
|
||||
|
||||
G4String G4UImanager::GetCurrentStringValue(const char * aCommand,
|
||||
G4String G4UImanager::GetCurrentStringValue(const char * aCommand,
|
||||
const char * aParameterName, G4bool reGet)
|
||||
{
|
||||
if(reGet || savedCommand == NULL)
|
||||
@@ -172,7 +172,7 @@ const char * aParameterName, G4bool reGet)
|
||||
G4int G4UImanager::GetCurrentIntValue(const char * aCommand,
|
||||
const char * aParameterName, G4bool reGet)
|
||||
{
|
||||
G4String targetParameter =
|
||||
G4String targetParameter =
|
||||
GetCurrentStringValue( aCommand, aParameterName, reGet );
|
||||
G4int value;
|
||||
const char* t = targetParameter;
|
||||
@@ -184,7 +184,7 @@ const char * aParameterName, G4bool reGet)
|
||||
G4int G4UImanager::GetCurrentIntValue(const char * aCommand,
|
||||
G4int parameterNumber, G4bool reGet)
|
||||
{
|
||||
G4String targetParameter =
|
||||
G4String targetParameter =
|
||||
GetCurrentStringValue( aCommand, parameterNumber, reGet );
|
||||
G4int value;
|
||||
const char* t = targetParameter;
|
||||
@@ -196,7 +196,7 @@ G4int parameterNumber, G4bool reGet)
|
||||
G4double G4UImanager::GetCurrentDoubleValue(const char * aCommand,
|
||||
const char * aParameterName, G4bool reGet)
|
||||
{
|
||||
G4String targetParameter =
|
||||
G4String targetParameter =
|
||||
GetCurrentStringValue( aCommand, aParameterName, reGet );
|
||||
G4double value;
|
||||
const char* t = targetParameter;
|
||||
@@ -208,7 +208,7 @@ const char * aParameterName, G4bool reGet)
|
||||
G4double G4UImanager::GetCurrentDoubleValue(const char * aCommand,
|
||||
G4int parameterNumber, G4bool reGet)
|
||||
{
|
||||
G4String targetParameter =
|
||||
G4String targetParameter =
|
||||
GetCurrentStringValue( aCommand, parameterNumber, reGet );
|
||||
G4double value;
|
||||
const char* t = targetParameter;
|
||||
@@ -255,7 +255,7 @@ void G4UImanager::LoopS(const char* valueList)
|
||||
is >> d1 >> d2 >> d3;
|
||||
Loop(mf,vn,d1,d2,d3);
|
||||
}
|
||||
|
||||
|
||||
void G4UImanager::Loop(const char * macroFile,const char * variableName,
|
||||
G4double initialValue,G4double finalValue,G4double stepSize)
|
||||
{
|
||||
@@ -263,18 +263,18 @@ void G4UImanager::Loop(const char * macroFile,const char * variableName,
|
||||
if (stepSize > 0) {
|
||||
for(G4double d=initialValue;d<=finalValue;d+=stepSize)
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << d;
|
||||
cd += os.str();
|
||||
cd += " ";
|
||||
std::ostringstream os;
|
||||
os << d;
|
||||
cd += os.str();
|
||||
cd += " ";
|
||||
}
|
||||
} else {
|
||||
for(G4double d=initialValue;d>=finalValue;d+=stepSize)
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << d;
|
||||
cd += os.str();
|
||||
cd += " ";
|
||||
std::ostringstream os;
|
||||
os << d;
|
||||
cd += os.str();
|
||||
cd += " ";
|
||||
}
|
||||
}
|
||||
Foreach(macroFile,variableName,cd);
|
||||
@@ -327,7 +327,7 @@ G4String G4UImanager::SolveAlias(const char* aCmd)
|
||||
if( ib == G4int(std::string::npos) )
|
||||
{
|
||||
G4cerr << aCommand << G4endl;
|
||||
for(G4int iz=0;iz<ia;iz++) G4cerr << " ";
|
||||
for(G4int i=0;i<ia;i++) G4cerr << " ";
|
||||
G4cerr << "^" << G4endl;
|
||||
G4cerr << "Unmatched alias parenthis -- command ignored" << G4endl;
|
||||
G4String nullStr;
|
||||
@@ -361,7 +361,7 @@ G4String G4UImanager::SolveAlias(const char* aCmd)
|
||||
return aCommand;
|
||||
}
|
||||
|
||||
G4int G4UImanager::ApplyCommand(G4String aCmd)
|
||||
G4int G4UImanager::ApplyCommand(const G4String& aCmd)
|
||||
{
|
||||
return ApplyCommand(aCmd.data());
|
||||
}
|
||||
@@ -412,10 +412,10 @@ G4int G4UImanager::ApplyCommand(const char * aCmd)
|
||||
if( targetCommand == NULL )
|
||||
{ return fCommandNotFound; }
|
||||
|
||||
if(!(targetCommand->IsAvailable()))
|
||||
if(!(targetCommand->IsAvailable()))
|
||||
{ return fIllegalApplicationState; }
|
||||
|
||||
if(saveHistory) historyFile << aCommand << G4endl;
|
||||
|
||||
if(saveHistory) historyFile << aCommand << G4endl;
|
||||
if( G4int(histVec.size()) >= maxHistSize )
|
||||
{ histVec.erase(histVec.begin()); }
|
||||
histVec.push_back(aCommand);
|
||||
@@ -444,7 +444,7 @@ void G4UImanager::StoreHistory(G4bool historySwitch,const char* fileName)
|
||||
|
||||
void G4UImanager::PauseSession(const char* msg)
|
||||
{
|
||||
if(session) session->PauseSessionStart(msg);
|
||||
if(session) session->PauseSessionStart(msg);
|
||||
}
|
||||
|
||||
void G4UImanager::ListCommands(const char* direct)
|
||||
@@ -527,7 +527,7 @@ void G4UImanager::SetAlias(const char * aliasLine)
|
||||
G4String aliasName = aLine(0,i);
|
||||
G4String aliasValue = aLine(i+1,aLine.length()-(i+1));
|
||||
if(aliasValue(0)=='"')
|
||||
{
|
||||
{
|
||||
G4String strippedValue;
|
||||
if(aliasValue(aliasValue.length()-1)=='"')
|
||||
{ strippedValue = aliasValue(1,aliasValue.length()-2); }
|
||||
@@ -552,7 +552,7 @@ void G4UImanager::ListAlias()
|
||||
}
|
||||
|
||||
void G4UImanager::CreateHTML(const char* dir)
|
||||
{
|
||||
{
|
||||
G4UIcommandTree* tr = FindDirectory(dir);
|
||||
if(tr!=0)
|
||||
{ tr->CreateHTML(); }
|
||||
@@ -560,3 +560,47 @@ void G4UImanager::CreateHTML(const char* dir)
|
||||
{ G4cerr << "Directory <" << dir << "> is not found." << G4endl; }
|
||||
}
|
||||
|
||||
void G4UImanager::ParseMacroSearchPath()
|
||||
{
|
||||
searchDirs.clear();
|
||||
|
||||
size_t idxfirst = 0;
|
||||
size_t idxend = 0;
|
||||
G4String pathstring = "";
|
||||
while( (idxend = searchPath.index(':', idxfirst)) != G4String::npos) {
|
||||
pathstring = searchPath.substr(idxfirst, idxend-idxfirst);
|
||||
if(pathstring.size() != 0) searchDirs.push_back(pathstring);
|
||||
idxfirst = idxend + 1;
|
||||
}
|
||||
|
||||
pathstring = searchPath.substr(idxfirst, searchPath.size()-idxfirst);
|
||||
if(pathstring.size() != 0) searchDirs.push_back(pathstring);
|
||||
}
|
||||
|
||||
|
||||
static G4bool FileFound(const G4String& fname)
|
||||
{
|
||||
G4bool qopen = false;
|
||||
std::ifstream fs;
|
||||
fs.open(fname.c_str(), std::ios::in);
|
||||
if(fs.good()) {
|
||||
fs.close();
|
||||
qopen = true;
|
||||
}
|
||||
return qopen;
|
||||
}
|
||||
|
||||
G4String G4UImanager::FindMacroPath(const G4String& fname) const
|
||||
{
|
||||
G4String macrofile = fname;
|
||||
|
||||
for (size_t i = 0; i < searchDirs.size(); i++) {
|
||||
G4String fullpath = searchDirs[i] + "/" + fname;
|
||||
if ( FileFound(fullpath) ) {
|
||||
macrofile = fullpath;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return macrofile;
|
||||
}
|
||||
|
||||
@@ -24,20 +24,32 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4UImessenger.cc,v 1.7 2006-06-29 19:09:06 gunter Exp $
|
||||
// GEANT4 tag $Name: not supported by cvs2svn $
|
||||
// $Id$
|
||||
//
|
||||
|
||||
#include "G4UImessenger.hh"
|
||||
#include "G4UImanager.hh"
|
||||
#include "G4UIcommand.hh"
|
||||
#include "G4UIdirectory.hh"
|
||||
#include "G4UIcommandTree.hh"
|
||||
#include "G4ios.hh"
|
||||
#include <sstream>
|
||||
|
||||
G4UImessenger::G4UImessenger()
|
||||
: baseDir(NULL), baseDirName("")
|
||||
{
|
||||
}
|
||||
|
||||
G4UImessenger::G4UImessenger() { }
|
||||
G4UImessenger::G4UImessenger(const G4String& path, const G4String& dsc)
|
||||
: baseDir(NULL), baseDirName("")
|
||||
{
|
||||
CreateDirectory(path, dsc);
|
||||
}
|
||||
|
||||
G4UImessenger::~G4UImessenger() { }
|
||||
G4UImessenger::~G4UImessenger()
|
||||
{
|
||||
if(baseDir) delete baseDir;
|
||||
}
|
||||
|
||||
G4String G4UImessenger::GetCurrentValue(G4UIcommand*)
|
||||
{
|
||||
@@ -73,27 +85,27 @@ G4String G4UImessenger::BtoS(G4bool b)
|
||||
return vl;
|
||||
}
|
||||
|
||||
G4int G4UImessenger::StoI(G4String s)
|
||||
G4int G4UImessenger::StoI(G4String str)
|
||||
{
|
||||
G4int vl;
|
||||
const char* t = s;
|
||||
const char* t = str;
|
||||
std::istringstream is(t);
|
||||
is >> vl;
|
||||
return vl;
|
||||
}
|
||||
|
||||
G4double G4UImessenger::StoD(G4String s)
|
||||
G4double G4UImessenger::StoD(G4String str)
|
||||
{
|
||||
G4double vl;
|
||||
const char* t = s;
|
||||
const char* t = str;
|
||||
std::istringstream is(t);
|
||||
is >> vl;
|
||||
return vl;
|
||||
}
|
||||
|
||||
G4bool G4UImessenger::StoB(G4String s)
|
||||
G4bool G4UImessenger::StoB(G4String str)
|
||||
{
|
||||
G4String v = s;
|
||||
G4String v = str;
|
||||
v.toUpper();
|
||||
G4bool vl = false;
|
||||
if( v=="Y" || v=="YES" || v=="1" || v=="T" || v=="TRUE" )
|
||||
@@ -108,3 +120,19 @@ void G4UImessenger::AddUIcommand(G4UIcommand * newCommand)
|
||||
<< newCommand->GetCommandPath() << ">." << G4endl;
|
||||
}
|
||||
|
||||
void G4UImessenger::CreateDirectory(const G4String& path, const G4String& dsc)
|
||||
{
|
||||
G4UImanager* ui = G4UImanager::GetUIpointer();
|
||||
|
||||
G4String fullpath = path;
|
||||
if(fullpath(fullpath.length()-1) != '/') fullpath.append("/");
|
||||
|
||||
G4UIcommandTree* tree= ui-> GetTree()-> FindCommandTree(fullpath.c_str());
|
||||
if (tree) {
|
||||
baseDirName = tree-> GetPathName();
|
||||
} else {
|
||||
baseDir = new G4UIdirectory(fullpath.c_str());
|
||||
baseDirName = fullpath;
|
||||
baseDir-> SetGuidance(dsc.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,8 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4UIparameter.cc,v 1.14 2006-06-29 19:09:09 gunter Exp $
|
||||
// GEANT4 tag $Name: not supported by cvs2svn $
|
||||
// $Id$
|
||||
//
|
||||
|
||||
#include "G4UIparameter.hh"
|
||||
|
||||
@@ -24,8 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4UIsession.cc,v 1.7 2006-06-29 19:09:11 gunter Exp $
|
||||
// GEANT4 tag $Name: not supported by cvs2svn $
|
||||
// $Id$
|
||||
//
|
||||
//
|
||||
// ---------------------------------------------------------------------
|
||||
@@ -38,15 +37,15 @@ G4UIsession::~G4UIsession() {;}
|
||||
|
||||
G4UIsession * G4UIsession::SessionStart() { return NULL; }
|
||||
|
||||
void G4UIsession::PauseSessionStart(G4String) {;}
|
||||
void G4UIsession::PauseSessionStart(const G4String&) {;}
|
||||
|
||||
G4int G4UIsession::ReceiveG4cout(G4String coutString)
|
||||
G4int G4UIsession::ReceiveG4cout(const G4String& coutString)
|
||||
{
|
||||
std::cout << coutString << std::flush;
|
||||
return 0;
|
||||
}
|
||||
|
||||
G4int G4UIsession::ReceiveG4cerr(G4String cerrString)
|
||||
G4int G4UIsession::ReceiveG4cerr(const G4String& cerrString)
|
||||
{
|
||||
std::cerr << cerrString << std::flush;
|
||||
return 0;
|
||||
|
||||
@@ -24,8 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4UnitsMessenger.cc,v 1.7 2006-06-29 19:09:13 gunter Exp $
|
||||
// GEANT4 tag $Name: not supported by cvs2svn $
|
||||
// $Id$
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
@@ -24,8 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4VGlobalFastSimulationManager.cc,v 1.5 2006-06-29 19:09:15 gunter Exp $
|
||||
// GEANT4 tag $Name: not supported by cvs2svn $
|
||||
// $Id$
|
||||
//
|
||||
//
|
||||
// Abstract interface for GEANT4 Global Fast Simulation Manager.
|
||||
|
||||
Reference in New Issue
Block a user