Import Geant4 0.0.0 source tree
This commit is contained in:
@@ -0,0 +1,159 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the RD44 GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: G4StateManager.cc,v 2.2 1998/09/25 13:09:23 asaim Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
//
|
||||
// ------------------------------------------------------------
|
||||
// GEANT 4 class implementation file
|
||||
//
|
||||
// For information related to this code contact:
|
||||
// CERN, CN Division, ASD group
|
||||
// ---------------- G4StateManager ----------------
|
||||
// by Gabriele Cosmo, November 1996
|
||||
// ------------------------------------------------------------
|
||||
|
||||
#include "G4StateManager.hh"
|
||||
#include "G4UImanager.hh"
|
||||
|
||||
// Initialization of the static pointer of the single class instance
|
||||
G4StateManager* G4StateManager::theStateManager = 0;
|
||||
|
||||
G4StateManager::G4StateManager()
|
||||
:theCurrentState(PreInit),thePreviousState(PreInit) {;}
|
||||
|
||||
G4StateManager::~G4StateManager()
|
||||
{
|
||||
theDependentsList.clearAndDestroy();
|
||||
}
|
||||
|
||||
G4StateManager::G4StateManager(const G4StateManager &right)
|
||||
{
|
||||
*this = right;
|
||||
}
|
||||
|
||||
G4StateManager& G4StateManager::operator=(const G4StateManager &right)
|
||||
{
|
||||
*this = right;
|
||||
return *this;
|
||||
}
|
||||
|
||||
G4int G4StateManager::operator==(const G4StateManager &right) const
|
||||
{
|
||||
return (this == (G4StateManager *) &right);
|
||||
}
|
||||
|
||||
G4int G4StateManager::operator!=(const G4StateManager &right) const
|
||||
{
|
||||
return (this != (G4StateManager *) &right);
|
||||
}
|
||||
|
||||
|
||||
G4StateManager* G4StateManager::GetStateManager()
|
||||
{
|
||||
if (!theStateManager)
|
||||
{
|
||||
theStateManager = new G4StateManager;
|
||||
}
|
||||
return theStateManager;
|
||||
}
|
||||
|
||||
G4bool G4StateManager::RegisterDependent(G4VStateDependent* aDependent)
|
||||
{
|
||||
G4bool ack=true;
|
||||
theDependentsList.insert(aDependent);
|
||||
return ack;
|
||||
}
|
||||
|
||||
G4bool G4StateManager::DeregisterDependent(G4VStateDependent* aDependent)
|
||||
{
|
||||
G4VStateDependent* aD = theDependentsList.remove(aDependent);
|
||||
return (aD != NULL);
|
||||
}
|
||||
|
||||
G4ApplicationState G4StateManager::GetCurrentState()
|
||||
{
|
||||
return theCurrentState;
|
||||
}
|
||||
|
||||
G4ApplicationState G4StateManager::GetPreviousState()
|
||||
{
|
||||
return thePreviousState;
|
||||
}
|
||||
|
||||
G4bool G4StateManager::SetNewState(G4ApplicationState requestedState)
|
||||
{
|
||||
G4int i=0;
|
||||
G4bool ack = true;
|
||||
G4ApplicationState savedState = thePreviousState;
|
||||
thePreviousState = theCurrentState;
|
||||
theCurrentState = requestedState;
|
||||
while ((ack) && (i<theDependentsList.entries())) {
|
||||
ack = theDependentsList(i)->Notify(requestedState);
|
||||
i++;
|
||||
}
|
||||
|
||||
if(!ack)
|
||||
{
|
||||
theCurrentState = thePreviousState;
|
||||
thePreviousState = savedState;
|
||||
}
|
||||
return ack;
|
||||
}
|
||||
|
||||
G4VStateDependent* G4StateManager::RemoveDependent(const G4VStateDependent* aDependent)
|
||||
{
|
||||
return theDependentsList.remove(aDependent);
|
||||
}
|
||||
|
||||
G4String G4StateManager::GetStateString(G4ApplicationState aState)
|
||||
{
|
||||
G4String stateName;
|
||||
switch(aState)
|
||||
{
|
||||
case PreInit:
|
||||
stateName = "PreInit"; break;
|
||||
case Init:
|
||||
stateName = "Init"; break;
|
||||
case Idle:
|
||||
stateName = "Idle"; break;
|
||||
case GeomClosed:
|
||||
stateName = "GeomClosed"; break;
|
||||
case EventProc:
|
||||
stateName = "EventProc"; break;
|
||||
case Quit:
|
||||
stateName = "Quit"; break;
|
||||
default:
|
||||
stateName = "Unknown";
|
||||
}
|
||||
return stateName;
|
||||
}
|
||||
|
||||
void G4StateManager::Pause()
|
||||
{
|
||||
Pause("G4_pause> ");
|
||||
}
|
||||
|
||||
void G4StateManager::Pause(char* msg)
|
||||
{
|
||||
G4String msgS = msg;
|
||||
Pause(msgS);
|
||||
}
|
||||
|
||||
void G4StateManager::Pause(G4String msg)
|
||||
{
|
||||
G4UImanager::GetUIpointer()->PauseSession(msg);
|
||||
// if(theCurrentState==EventProc)
|
||||
// {
|
||||
// G4ApplicationState savedState = thePreviousState;
|
||||
// SetNewState(Pause);
|
||||
// theCurrentState = thePreviousState;
|
||||
// thePreviousState = savedState;
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the RD44 GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: G4UIbatch.cc,v 2.2 1998/07/13 17:12:53 urbi Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
|
||||
#include "G4UIbatch.hh"
|
||||
#include "G4UImanager.hh"
|
||||
#include "G4ios.hh"
|
||||
|
||||
G4UIbatch::G4UIbatch(G4String fileName,G4UIsession* prevSession)
|
||||
:macroFileName(fileName),previousSession(prevSession),
|
||||
openFailed(false)
|
||||
{
|
||||
const char* theFileName = fileName;
|
||||
UImanager = G4UImanager::GetUIpointer();
|
||||
UImanager->SetSession(this);
|
||||
macroFile.open((char*)theFileName);
|
||||
if(macroFile.fail())
|
||||
{
|
||||
G4cerr << "macro file <" << fileName << "> could not open."
|
||||
<< endl;
|
||||
openFailed = true;
|
||||
}
|
||||
}
|
||||
|
||||
G4UIbatch::~G4UIbatch()
|
||||
{
|
||||
if(!openFailed) macroFile.close();
|
||||
}
|
||||
|
||||
G4UIsession * G4UIbatch::SessionStart()
|
||||
{
|
||||
if(!openFailed)
|
||||
{
|
||||
char commandLine[256];
|
||||
int lineLength = 255;
|
||||
|
||||
while(1)
|
||||
{
|
||||
macroFile.getline( commandLine, lineLength );
|
||||
if( macroFile.bad() )
|
||||
{
|
||||
G4cout << "Cannot read " << macroFileName << "." << endl;
|
||||
break;
|
||||
}
|
||||
if( macroFile.eof() ) break;
|
||||
commandLine[lineLength] = '\0';
|
||||
if( commandLine[0] != '#' )
|
||||
{ UImanager->ApplyCommand(commandLine); }
|
||||
else
|
||||
{ G4cout << commandLine << endl; }
|
||||
}
|
||||
}
|
||||
return previousSession;
|
||||
}
|
||||
|
||||
void G4UIbatch::PauseSessionStart(G4String Prompt)
|
||||
{
|
||||
G4cout << "Pause session <" << Prompt << "> start." << endl;
|
||||
SessionStart();
|
||||
G4cout << "Pause session <" << Prompt << "> Terminate." << endl;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the RD44 GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: G4UIcmdWith3Vector.cc,v 2.1 1998/07/12 02:59:42 urbi Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
//
|
||||
|
||||
#include "G4UIcmdWith3Vector.hh"
|
||||
#ifdef WIN32
|
||||
# include <Strstrea.h>
|
||||
#else
|
||||
# include <strstream.h>
|
||||
#endif
|
||||
|
||||
G4UIcmdWith3Vector::G4UIcmdWith3Vector
|
||||
(const char * theCommandPath,G4UImessenger * theMessenger)
|
||||
:G4UIcommand(theCommandPath,theMessenger)
|
||||
{
|
||||
G4UIparameter * dblParamX = new G4UIparameter('d');
|
||||
SetParameter(dblParamX);
|
||||
G4UIparameter * dblParamY = new G4UIparameter('d');
|
||||
SetParameter(dblParamY);
|
||||
G4UIparameter * dblParamZ = new G4UIparameter('d');
|
||||
SetParameter(dblParamZ);
|
||||
}
|
||||
|
||||
G4ThreeVector G4UIcmdWith3Vector::GetNew3VectorValue(G4String paramString)
|
||||
{
|
||||
G4double vx;
|
||||
G4double vy;
|
||||
G4double vz;
|
||||
const char* t = paramString;
|
||||
istrstream is((char*)t);
|
||||
is >> vx >> vy >> vz;
|
||||
return G4ThreeVector(vx,vy,vz);
|
||||
}
|
||||
|
||||
G4String G4UIcmdWith3Vector::ConvertToString(G4ThreeVector vec)
|
||||
{
|
||||
char st[100];
|
||||
ostrstream os(st,100);
|
||||
os << vec.x() << " " << vec.y() << " " << vec.z() << '\0';
|
||||
G4String vl = st;
|
||||
return vl;
|
||||
}
|
||||
|
||||
void G4UIcmdWith3Vector::SetParameterName
|
||||
(const char * theNameX,const char * theNameY,const char * theNameZ,
|
||||
G4bool omittable,G4bool currentAsDefault)
|
||||
{
|
||||
G4UIparameter * theParamX = GetParameter(0);
|
||||
theParamX->SetParameterName(theNameX);
|
||||
theParamX->SetOmittable(omittable);
|
||||
theParamX->SetCurrentAsDefault(currentAsDefault);
|
||||
G4UIparameter * theParamY = GetParameter(1);
|
||||
theParamY->SetParameterName(theNameY);
|
||||
theParamY->SetOmittable(omittable);
|
||||
theParamY->SetCurrentAsDefault(currentAsDefault);
|
||||
G4UIparameter * theParamZ = GetParameter(2);
|
||||
theParamZ->SetParameterName(theNameZ);
|
||||
theParamZ->SetOmittable(omittable);
|
||||
theParamZ->SetCurrentAsDefault(currentAsDefault);
|
||||
}
|
||||
|
||||
void G4UIcmdWith3Vector::SetDefaultValue(G4ThreeVector vec)
|
||||
{
|
||||
G4UIparameter * theParamX = GetParameter(0);
|
||||
theParamX->SetDefaultValue(vec.x());
|
||||
G4UIparameter * theParamY = GetParameter(1);
|
||||
theParamY->SetDefaultValue(vec.y());
|
||||
G4UIparameter * theParamZ = GetParameter(2);
|
||||
theParamZ->SetDefaultValue(vec.z());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the RD44 GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: G4UIcmdWith3VectorAndUnit.cc,v 2.1 1998/07/12 02:59:43 urbi Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
//
|
||||
|
||||
#include "G4UIcmdWith3VectorAndUnit.hh"
|
||||
#ifdef WIN32
|
||||
# include <Strstrea.h>
|
||||
#else
|
||||
# include <strstream.h>
|
||||
#endif
|
||||
|
||||
G4UIcmdWith3VectorAndUnit::G4UIcmdWith3VectorAndUnit
|
||||
(const char * theCommandPath,G4UImessenger * theMessenger)
|
||||
:G4UIcommand(theCommandPath,theMessenger)
|
||||
{
|
||||
G4UIparameter * dblParamX = new G4UIparameter('d');
|
||||
SetParameter(dblParamX);
|
||||
G4UIparameter * dblParamY = new G4UIparameter('d');
|
||||
SetParameter(dblParamY);
|
||||
G4UIparameter * dblParamZ = new G4UIparameter('d');
|
||||
SetParameter(dblParamZ);
|
||||
G4UIparameter * untParam = new G4UIparameter('s');
|
||||
SetParameter(untParam);
|
||||
untParam->SetParameterName("Unit");
|
||||
}
|
||||
|
||||
G4ThreeVector G4UIcmdWith3VectorAndUnit::GetNew3VectorValue(G4String paramString)
|
||||
{
|
||||
G4double vx;
|
||||
G4double vy;
|
||||
G4double vz;
|
||||
char unts[30];
|
||||
const char* t = paramString;
|
||||
istrstream is((char*)t);
|
||||
is >> vx >> vy >> vz >> unts;
|
||||
G4String unt = unts;
|
||||
G4double uv = ValueOf(unt);
|
||||
return G4ThreeVector(vx*uv,vy*uv,vz*uv);
|
||||
}
|
||||
|
||||
G4ThreeVector G4UIcmdWith3VectorAndUnit::GetNew3VectorRawValue(G4String paramString)
|
||||
{
|
||||
G4double vx;
|
||||
G4double vy;
|
||||
G4double vz;
|
||||
char unts[30];
|
||||
const char* t = paramString;
|
||||
istrstream is((char*)t);
|
||||
is >> vx >> vy >> vz >> unts;
|
||||
return G4ThreeVector(vx,vy,vz);
|
||||
}
|
||||
|
||||
G4double G4UIcmdWith3VectorAndUnit::GetNewUnitValue(G4String paramString)
|
||||
{
|
||||
G4double vx;
|
||||
G4double vy;
|
||||
G4double vz;
|
||||
char unts[30];
|
||||
const char* t = paramString;
|
||||
istrstream is((char*)t);
|
||||
is >> vx >> vy >> vz >> unts;
|
||||
G4String unt = unts;
|
||||
return ValueOf(unt);
|
||||
}
|
||||
|
||||
G4String G4UIcmdWith3VectorAndUnit::ConvertToString
|
||||
(G4ThreeVector vec,const char * unitName)
|
||||
{
|
||||
G4String unt = unitName;
|
||||
G4double uv = ValueOf(unitName);
|
||||
|
||||
char st[100];
|
||||
ostrstream os(st,100);
|
||||
os << vec.x()/uv << " " << vec.y()/uv << " " << vec.z()/uv
|
||||
<< " " << unitName << '\0';
|
||||
G4String vl = st;
|
||||
return vl;
|
||||
}
|
||||
|
||||
void G4UIcmdWith3VectorAndUnit::SetParameterName
|
||||
(const char * theNameX,const char * theNameY,const char * theNameZ,
|
||||
G4bool omittable,G4bool currentAsDefault)
|
||||
{
|
||||
G4UIparameter * theParamX = GetParameter(0);
|
||||
theParamX->SetParameterName(theNameX);
|
||||
theParamX->SetOmittable(omittable);
|
||||
theParamX->SetCurrentAsDefault(currentAsDefault);
|
||||
G4UIparameter * theParamY = GetParameter(1);
|
||||
theParamY->SetParameterName(theNameY);
|
||||
theParamY->SetOmittable(omittable);
|
||||
theParamY->SetCurrentAsDefault(currentAsDefault);
|
||||
G4UIparameter * theParamZ = GetParameter(2);
|
||||
theParamZ->SetParameterName(theNameZ);
|
||||
theParamZ->SetOmittable(omittable);
|
||||
theParamZ->SetCurrentAsDefault(currentAsDefault);
|
||||
}
|
||||
|
||||
void G4UIcmdWith3VectorAndUnit::SetDefaultValue(G4ThreeVector vec)
|
||||
{
|
||||
G4UIparameter * theParamX = GetParameter(0);
|
||||
theParamX->SetDefaultValue(vec.x());
|
||||
G4UIparameter * theParamY = GetParameter(1);
|
||||
theParamY->SetDefaultValue(vec.y());
|
||||
G4UIparameter * theParamZ = GetParameter(2);
|
||||
theParamZ->SetDefaultValue(vec.z());
|
||||
}
|
||||
|
||||
void G4UIcmdWith3VectorAndUnit::SetUnitCategory(const char * unitCategory)
|
||||
{
|
||||
SetUnitCandidates(UnitsList(unitCategory));
|
||||
}
|
||||
|
||||
void G4UIcmdWith3VectorAndUnit::SetUnitCandidates(const char * candidateList)
|
||||
{
|
||||
G4UIparameter * untParam = GetParameter(3);
|
||||
G4String canList = candidateList;
|
||||
untParam->SetParameterCandidates(canList);
|
||||
}
|
||||
|
||||
void G4UIcmdWith3VectorAndUnit::SetDefaultUnit(const char * defUnit)
|
||||
{
|
||||
G4UIparameter * untParam = GetParameter(3);
|
||||
untParam->SetOmittable(true);
|
||||
untParam->SetDefaultValue(defUnit);
|
||||
SetUnitCategory(CategoryOf(defUnit));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the RD44 GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: G4UIcmdWithABool.cc,v 2.1 1998/07/12 02:59:43 urbi Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
//
|
||||
|
||||
#include "G4UIcmdWithABool.hh"
|
||||
#ifdef WIN32
|
||||
# include <Strstrea.h>
|
||||
#else
|
||||
# include <strstream.h>
|
||||
#endif
|
||||
|
||||
G4UIcmdWithABool::G4UIcmdWithABool
|
||||
(const char * theCommandPath,G4UImessenger * theMessenger)
|
||||
:G4UIcommand(theCommandPath,theMessenger)
|
||||
{
|
||||
G4UIparameter * blParam = new G4UIparameter('b');
|
||||
SetParameter(blParam);
|
||||
}
|
||||
|
||||
G4bool G4UIcmdWithABool::GetNewBoolValue(G4String paramString)
|
||||
{
|
||||
G4String v = paramString;
|
||||
v.toUpper();
|
||||
G4bool vl = false;
|
||||
if( v=="Y" || v=="YES" || v=="1" || v=="T" || v=="TRUE" )
|
||||
{ vl = true; }
|
||||
return vl;
|
||||
}
|
||||
|
||||
G4String G4UIcmdWithABool::ConvertToString(G4bool blValue)
|
||||
{
|
||||
G4String vl = "0";
|
||||
if(blValue) vl = "1";
|
||||
return vl;
|
||||
}
|
||||
|
||||
void G4UIcmdWithABool::SetParameterName
|
||||
(const char * theName,G4bool omittable,G4bool currentAsDefault)
|
||||
{
|
||||
G4UIparameter * theParam = GetParameter(0);
|
||||
theParam->SetParameterName(theName);
|
||||
theParam->SetOmittable(omittable);
|
||||
theParam->SetCurrentAsDefault(currentAsDefault);
|
||||
}
|
||||
|
||||
void G4UIcmdWithABool::SetDefaultValue(G4bool defVal)
|
||||
{
|
||||
G4UIparameter * theParam = GetParameter(0);
|
||||
theParam->SetDefaultValue(defVal);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the RD44 GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: G4UIcmdWithADouble.cc,v 2.1 1998/07/12 02:59:44 urbi Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
//
|
||||
|
||||
#include "G4UIcmdWithADouble.hh"
|
||||
#ifdef WIN32
|
||||
# include <Strstrea.h>
|
||||
#else
|
||||
# include <strstream.h>
|
||||
#endif
|
||||
|
||||
G4UIcmdWithADouble::G4UIcmdWithADouble
|
||||
(const char * theCommandPath,G4UImessenger * theMessenger)
|
||||
:G4UIcommand(theCommandPath,theMessenger)
|
||||
{
|
||||
G4UIparameter * dblParam = new G4UIparameter('d');
|
||||
SetParameter(dblParam);
|
||||
}
|
||||
|
||||
G4double G4UIcmdWithADouble::GetNewDoubleValue(G4String paramString)
|
||||
{
|
||||
G4double vl;
|
||||
const char* t = paramString;
|
||||
istrstream is((char*)t);
|
||||
is >> vl;
|
||||
return vl;
|
||||
}
|
||||
|
||||
G4String G4UIcmdWithADouble::ConvertToString(G4double dblValue)
|
||||
{
|
||||
char st[20];
|
||||
ostrstream os(st,20);
|
||||
os << dblValue << '\0';
|
||||
G4String vl = st;
|
||||
return vl;
|
||||
}
|
||||
|
||||
void G4UIcmdWithADouble::SetParameterName
|
||||
(const char * theName,G4bool omittable,G4bool currentAsDefault)
|
||||
{
|
||||
G4UIparameter * theParam = GetParameter(0);
|
||||
theParam->SetParameterName(theName);
|
||||
theParam->SetOmittable(omittable);
|
||||
theParam->SetCurrentAsDefault(currentAsDefault);
|
||||
}
|
||||
|
||||
void G4UIcmdWithADouble::SetDefaultValue(G4double defVal)
|
||||
{
|
||||
G4UIparameter * theParam = GetParameter(0);
|
||||
theParam->SetDefaultValue(defVal);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the RD44 GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: G4UIcmdWithADoubleAndUnit.cc,v 2.1 1998/07/12 02:59:44 urbi Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
//
|
||||
|
||||
#include "G4UIcmdWithADoubleAndUnit.hh"
|
||||
#ifdef WIN32
|
||||
# include <Strstrea.h>
|
||||
#else
|
||||
# include <strstream.h>
|
||||
#endif
|
||||
|
||||
G4UIcmdWithADoubleAndUnit::G4UIcmdWithADoubleAndUnit
|
||||
(const char * theCommandPath,G4UImessenger * theMessenger)
|
||||
:G4UIcommand(theCommandPath,theMessenger)
|
||||
{
|
||||
G4UIparameter * dblParam = new G4UIparameter('d');
|
||||
SetParameter(dblParam);
|
||||
G4UIparameter * untParam = new G4UIparameter('s');
|
||||
SetParameter(untParam);
|
||||
untParam->SetParameterName("Unit");
|
||||
}
|
||||
|
||||
G4double G4UIcmdWithADoubleAndUnit::GetNewDoubleValue(G4String paramString)
|
||||
{
|
||||
G4double vl;
|
||||
char unts[30];
|
||||
|
||||
const char* t = paramString;
|
||||
istrstream is((char*)t);
|
||||
is >> vl >> unts;
|
||||
G4String unt = unts;
|
||||
|
||||
return (vl*ValueOf(unt));
|
||||
}
|
||||
|
||||
G4double G4UIcmdWithADoubleAndUnit::GetNewDoubleRawValue(G4String paramString)
|
||||
{
|
||||
G4double vl;
|
||||
char unts[30];
|
||||
|
||||
const char* t = paramString;
|
||||
istrstream is((char*)t);
|
||||
is >> vl >> unts;
|
||||
|
||||
return vl;
|
||||
}
|
||||
|
||||
G4double G4UIcmdWithADoubleAndUnit::GetNewUnitValue(G4String paramString)
|
||||
{
|
||||
G4double vl;
|
||||
char unts[30];
|
||||
|
||||
const char* t = paramString;
|
||||
istrstream is((char*)t);
|
||||
is >> vl >> unts;
|
||||
G4String unt = unts;
|
||||
|
||||
return ValueOf(unt);
|
||||
}
|
||||
|
||||
G4String G4UIcmdWithADoubleAndUnit::ConvertToString
|
||||
(G4double dblValue,const char * unitName)
|
||||
{
|
||||
G4String unt = unitName;
|
||||
G4double uv = ValueOf(unitName);
|
||||
|
||||
char st[50];
|
||||
ostrstream os(st,50);
|
||||
os << dblValue/uv << " " << unitName << '\0';
|
||||
G4String vl = st;
|
||||
return vl;
|
||||
}
|
||||
|
||||
void G4UIcmdWithADoubleAndUnit::SetParameterName
|
||||
(const char * theName,G4bool omittable,G4bool currentAsDefault)
|
||||
{
|
||||
G4UIparameter * theParam = GetParameter(0);
|
||||
theParam->SetParameterName(theName);
|
||||
theParam->SetOmittable(omittable);
|
||||
theParam->SetCurrentAsDefault(currentAsDefault);
|
||||
}
|
||||
|
||||
void G4UIcmdWithADoubleAndUnit::SetDefaultValue(G4double defVal)
|
||||
{
|
||||
G4UIparameter * theParam = GetParameter(0);
|
||||
theParam->SetDefaultValue(defVal);
|
||||
}
|
||||
|
||||
void G4UIcmdWithADoubleAndUnit::SetUnitCategory(const char * unitCategory)
|
||||
{
|
||||
SetUnitCandidates(UnitsList(unitCategory));
|
||||
}
|
||||
|
||||
void G4UIcmdWithADoubleAndUnit::SetUnitCandidates(const char * candidateList)
|
||||
{
|
||||
G4UIparameter * untParam = GetParameter(1);
|
||||
G4String canList = candidateList;
|
||||
untParam->SetParameterCandidates(canList);
|
||||
}
|
||||
|
||||
void G4UIcmdWithADoubleAndUnit::SetDefaultUnit(const char * defUnit)
|
||||
{
|
||||
G4UIparameter * untParam = GetParameter(1);
|
||||
untParam->SetOmittable(true);
|
||||
untParam->SetDefaultValue(defUnit);
|
||||
SetUnitCategory(CategoryOf(defUnit));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the RD44 GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: G4UIcmdWithAString.cc,v 2.1 1998/07/12 02:59:46 urbi Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
//
|
||||
|
||||
#include "G4UIcmdWithAString.hh"
|
||||
#ifdef WIN32
|
||||
# include <Strstrea.h>
|
||||
#else
|
||||
# include <strstream.h>
|
||||
#endif
|
||||
|
||||
G4UIcmdWithAString::G4UIcmdWithAString
|
||||
(const char * theCommandPath,G4UImessenger * theMessenger)
|
||||
:G4UIcommand(theCommandPath,theMessenger)
|
||||
{
|
||||
G4UIparameter * strParam = new G4UIparameter('s');
|
||||
SetParameter(strParam);
|
||||
}
|
||||
|
||||
void G4UIcmdWithAString::SetParameterName
|
||||
(const char * theName,G4bool omittable,G4bool currentAsDefault)
|
||||
{
|
||||
G4UIparameter * theParam = GetParameter(0);
|
||||
theParam->SetParameterName(theName);
|
||||
theParam->SetOmittable(omittable);
|
||||
theParam->SetCurrentAsDefault(currentAsDefault);
|
||||
}
|
||||
|
||||
void G4UIcmdWithAString::SetCandidates(const char * candidateList)
|
||||
{
|
||||
G4UIparameter * theParam = GetParameter(0);
|
||||
G4String canList = candidateList;
|
||||
theParam->SetParameterCandidates(canList);
|
||||
}
|
||||
|
||||
void G4UIcmdWithAString::SetDefaultValue(const char * defVal)
|
||||
{
|
||||
G4UIparameter * theParam = GetParameter(0);
|
||||
theParam->SetDefaultValue(defVal);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the RD44 GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: G4UIcmdWithAnInteger.cc,v 2.1 1998/07/12 02:59:47 urbi Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
//
|
||||
|
||||
#include "G4UIcmdWithAnInteger.hh"
|
||||
#ifdef WIN32
|
||||
# include <Strstrea.h>
|
||||
#else
|
||||
# include <strstream.h>
|
||||
#endif
|
||||
|
||||
G4UIcmdWithAnInteger::G4UIcmdWithAnInteger
|
||||
(const char * theCommandPath,G4UImessenger * theMessenger)
|
||||
:G4UIcommand(theCommandPath,theMessenger)
|
||||
{
|
||||
G4UIparameter * intParam = new G4UIparameter('i');
|
||||
SetParameter(intParam);
|
||||
}
|
||||
|
||||
G4int G4UIcmdWithAnInteger::GetNewIntValue(G4String paramString)
|
||||
{
|
||||
G4int vl;
|
||||
const char* t = paramString;
|
||||
istrstream is((char*)t);
|
||||
is >> vl;
|
||||
return vl;
|
||||
}
|
||||
|
||||
G4String G4UIcmdWithAnInteger::ConvertToString(G4int intValue)
|
||||
{
|
||||
char st[20];
|
||||
ostrstream os(st,20);
|
||||
os << intValue << '\0';
|
||||
G4String vl = st;
|
||||
return vl;
|
||||
}
|
||||
|
||||
void G4UIcmdWithAnInteger::SetParameterName
|
||||
(const char * theName,G4bool omittable,G4bool currentAsDefault)
|
||||
{
|
||||
G4UIparameter * theParam = GetParameter(0);
|
||||
theParam->SetParameterName(theName);
|
||||
theParam->SetOmittable(omittable);
|
||||
theParam->SetCurrentAsDefault(currentAsDefault);
|
||||
}
|
||||
|
||||
void G4UIcmdWithAnInteger::SetDefaultValue(G4int defVal)
|
||||
{
|
||||
G4UIparameter * theParam = GetParameter(0);
|
||||
theParam->SetDefaultValue(defVal);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the RD44 GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: G4UIcmdWithoutParameter.cc,v 2.0 1998/07/02 17:08:48 gunter Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
//
|
||||
|
||||
#include "G4UIcmdWithoutParameter.hh"
|
||||
|
||||
G4UIcmdWithoutParameter::G4UIcmdWithoutParameter
|
||||
(const char * theCommandPath,G4UImessenger * theMessenger)
|
||||
:G4UIcommand(theCommandPath,theMessenger)
|
||||
{;}
|
||||
|
||||
@@ -0,0 +1,955 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the RD44 GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: G4UIcommand.cc,v 2.7 1998/11/25 16:15:25 allison Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
//
|
||||
|
||||
#include "G4UIcommand.hh"
|
||||
#include "G4UImessenger.hh"
|
||||
#include "G4UImanager.hh"
|
||||
#include "G4UIcommandStatus.hh"
|
||||
#include "G4StateManager.hh"
|
||||
#include "G4UnitsTable.hh"
|
||||
#include <rw/ctoken.h>
|
||||
#include "G4ios.hh"
|
||||
|
||||
G4UIcommand::G4UIcommand():paramERR(0) { }
|
||||
|
||||
G4UIcommand::G4UIcommand(const char * theCommandPath,
|
||||
G4UImessenger * theMessenger)
|
||||
:messenger(theMessenger), paramERR(0)
|
||||
{
|
||||
G4String comStr = theCommandPath;
|
||||
if(!theMessenger)
|
||||
{ // this must be a directory
|
||||
if(comStr(comStr.length()-1)!='/')
|
||||
{
|
||||
G4cerr << "G4UIcommand Warning : " << endl;
|
||||
G4cerr << " <" << theCommandPath << "> must be a directory." << endl;
|
||||
G4cerr << " '/' is appended." << endl;
|
||||
comStr += "/";
|
||||
}
|
||||
}
|
||||
G4UIcommandCommonConstructorCode (comStr);
|
||||
G4String nullString;
|
||||
availabelStateList.clear();
|
||||
availabelStateList.insert(PreInit);
|
||||
availabelStateList.insert(Init);
|
||||
availabelStateList.insert(Idle);
|
||||
availabelStateList.insert(GeomClosed);
|
||||
availabelStateList.insert(EventProc);
|
||||
}
|
||||
|
||||
void G4UIcommand::G4UIcommandCommonConstructorCode
|
||||
(const char * theCommandPath)
|
||||
{
|
||||
commandPath = theCommandPath;
|
||||
commandName = theCommandPath;
|
||||
int commandNameIndex = commandName.last('/');
|
||||
commandName.remove(0,commandNameIndex+1);
|
||||
|
||||
G4UImanager::GetUIpointer()->AddNewCommand(this);
|
||||
}
|
||||
|
||||
G4UIcommand::~G4UIcommand()
|
||||
{
|
||||
G4UImanager* fUImanager = G4UImanager::GetUIpointer();
|
||||
if(fUImanager) fUImanager->RemoveCommand(this);
|
||||
|
||||
int n_parameterEntry = parameter.entries();
|
||||
for( int i_thParameter=0; i_thParameter < n_parameterEntry; i_thParameter++ )
|
||||
{ delete parameter[i_thParameter]; }
|
||||
}
|
||||
|
||||
int G4UIcommand::operator==(const G4UIcommand &right) const
|
||||
{
|
||||
return ( commandPath == right.GetCommandPath() );
|
||||
}
|
||||
|
||||
int G4UIcommand::operator!=(const G4UIcommand &right) const
|
||||
{
|
||||
return ( commandPath != right.GetCommandPath() );
|
||||
}
|
||||
|
||||
G4int G4UIcommand::DoIt(G4String parameterList)
|
||||
{
|
||||
G4String correctParameters;
|
||||
int n_parameterEntry = parameter.entries();
|
||||
if( n_parameterEntry != 0 )
|
||||
{
|
||||
G4String aToken;
|
||||
G4String correctToken;
|
||||
RWCTokenizer parameterToken( parameterList );
|
||||
for( int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ )
|
||||
{
|
||||
if(i_thParameter > 0)
|
||||
{
|
||||
correctParameters.append(" ");
|
||||
}
|
||||
aToken = parameterToken();
|
||||
if( aToken(0)=='"' )
|
||||
{
|
||||
while( aToken(aToken.length()-1) != '"' )
|
||||
{
|
||||
G4String additionalToken = parameterToken();
|
||||
if( additionalToken.isNull() )
|
||||
{ return fParameterUnreadable+i_thParameter; }
|
||||
aToken += " ";
|
||||
aToken += additionalToken;
|
||||
}
|
||||
// aToken.strip(G4String::both,'"');
|
||||
}
|
||||
if( aToken.isNull() || aToken == "!" )
|
||||
{
|
||||
if(parameter[i_thParameter]->IsOmittable())
|
||||
{
|
||||
if(parameter[i_thParameter]->GetCurrentAsDefault())
|
||||
{
|
||||
RWCTokenizer cvt(messenger->GetCurrentValue(this));
|
||||
G4String parVal;
|
||||
for(int ii=0;ii<i_thParameter;ii++)
|
||||
{ parVal = cvt(); }
|
||||
G4String aCVToken = cvt();
|
||||
if (aCVToken(0)=='"')
|
||||
{
|
||||
while( aCVToken(aCVToken.length()-1) != '"' )
|
||||
{
|
||||
G4String additionalToken = cvt();
|
||||
if( additionalToken.isNull() )
|
||||
{ return fParameterUnreadable+i_thParameter; }
|
||||
aCVToken += " ";
|
||||
aCVToken += additionalToken;
|
||||
}
|
||||
// aCVToken.strip(G4String::both,'"');
|
||||
}
|
||||
correctParameters.append(aCVToken);
|
||||
}
|
||||
else
|
||||
{ correctParameters.append(parameter[i_thParameter]->GetDefaultValue()); }
|
||||
}
|
||||
else
|
||||
{ return fParameterUnreadable+i_thParameter; }
|
||||
}
|
||||
else
|
||||
{
|
||||
int stat = parameter[i_thParameter]->CheckNewValue( aToken );
|
||||
if(stat) return stat+i_thParameter;
|
||||
correctParameters.append(aToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(CheckNewValue( correctParameters ))
|
||||
{ return fParameterOutOfRange+99; }
|
||||
|
||||
messenger->SetNewValue( this, correctParameters );
|
||||
return 0;
|
||||
}
|
||||
|
||||
G4String G4UIcommand::GetCurrentValue()
|
||||
{
|
||||
return messenger->GetCurrentValue(this);
|
||||
}
|
||||
|
||||
void G4UIcommand::AvailableForStates(G4ApplicationState s1)
|
||||
{
|
||||
availabelStateList.clear();
|
||||
availabelStateList.insert(s1);
|
||||
}
|
||||
|
||||
void G4UIcommand::AvailableForStates(G4ApplicationState s1,
|
||||
G4ApplicationState s2)
|
||||
{
|
||||
availabelStateList.clear();
|
||||
availabelStateList.insert(s1);
|
||||
availabelStateList.insert(s2);
|
||||
}
|
||||
|
||||
void G4UIcommand::AvailableForStates(G4ApplicationState s1,
|
||||
G4ApplicationState s2,
|
||||
G4ApplicationState s3)
|
||||
{
|
||||
availabelStateList.clear();
|
||||
availabelStateList.insert(s1);
|
||||
availabelStateList.insert(s2);
|
||||
availabelStateList.insert(s3);
|
||||
}
|
||||
|
||||
void G4UIcommand::AvailableForStates(G4ApplicationState s1,
|
||||
G4ApplicationState s2,
|
||||
G4ApplicationState s3,
|
||||
G4ApplicationState s4)
|
||||
{
|
||||
availabelStateList.clear();
|
||||
availabelStateList.insert(s1);
|
||||
availabelStateList.insert(s2);
|
||||
availabelStateList.insert(s3);
|
||||
availabelStateList.insert(s4);
|
||||
}
|
||||
|
||||
void G4UIcommand::AvailableForStates(G4ApplicationState s1,
|
||||
G4ApplicationState s2,
|
||||
G4ApplicationState s3,
|
||||
G4ApplicationState s4,
|
||||
G4ApplicationState s5)
|
||||
{
|
||||
availabelStateList.clear();
|
||||
availabelStateList.insert(s1);
|
||||
availabelStateList.insert(s2);
|
||||
availabelStateList.insert(s3);
|
||||
availabelStateList.insert(s4);
|
||||
availabelStateList.insert(s5);
|
||||
}
|
||||
|
||||
G4bool G4UIcommand::IsAvailable()
|
||||
{
|
||||
G4bool av = false;
|
||||
G4ApplicationState currentState
|
||||
= G4StateManager::GetStateManager()->GetCurrentState();
|
||||
|
||||
int nState = availabelStateList.entries();
|
||||
for(int i=0;i<nState;i++)
|
||||
{
|
||||
if(availabelStateList[i]==currentState)
|
||||
{
|
||||
av = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return av;
|
||||
}
|
||||
|
||||
G4double G4UIcommand::ValueOf(G4String unitName)
|
||||
{
|
||||
G4double value = 0.;
|
||||
value = G4UnitDefinition::GetValueOf(unitName);
|
||||
return value;
|
||||
}
|
||||
|
||||
G4String G4UIcommand::CategoryOf(G4String unitName)
|
||||
{
|
||||
return G4UnitDefinition::GetCategory(unitName);
|
||||
}
|
||||
|
||||
G4String G4UIcommand::UnitsList(G4String unitCategory)
|
||||
{
|
||||
G4String retStr;
|
||||
G4UnitsTable& UTbl = G4UnitDefinition::GetUnitsTable();
|
||||
G4int i;
|
||||
for(i=0;i<UTbl.entries();i++)
|
||||
{ if(UTbl[i]->GetName()==unitCategory) break; }
|
||||
if(i==UTbl.entries())
|
||||
{
|
||||
G4cerr << "Unit category <" << unitCategory << "> is not defined." << endl;
|
||||
return retStr;
|
||||
}
|
||||
G4UnitsContainer& UCnt = UTbl[i]->GetUnitsList();
|
||||
retStr = UCnt[0]->GetSymbol();
|
||||
G4int je = UCnt.entries();
|
||||
for(int j=1;j<je;j++)
|
||||
{
|
||||
retStr += " ";
|
||||
retStr += UCnt[j]->GetSymbol();
|
||||
}
|
||||
for(int k=0;k<je;k++)
|
||||
{
|
||||
retStr += " ";
|
||||
retStr += UCnt[k]->GetName();
|
||||
}
|
||||
return retStr;
|
||||
}
|
||||
|
||||
void G4UIcommand::List()
|
||||
{
|
||||
G4cout << endl;
|
||||
G4cout << endl;
|
||||
if(commandPath(commandPath.length()-1)!='/')
|
||||
{ G4cout << "Command " << commandPath << endl; }
|
||||
G4cout << "Guidance :" << endl;
|
||||
int n_guidanceEntry = commandGuidance.entries();
|
||||
for( int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ )
|
||||
{ G4cout << commandGuidance[i_thGuidance] << endl; }
|
||||
if( ! rangeString.isNull() )
|
||||
{ G4cout << " Range of parameters : " << rangeString << endl; }
|
||||
int n_parameterEntry = parameter.entries();
|
||||
if( n_parameterEntry > 0 )
|
||||
{
|
||||
for( int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ )
|
||||
{ parameter[i_thParameter]->List(); }
|
||||
}
|
||||
G4cout << endl;
|
||||
}
|
||||
|
||||
// ----- the following is used by CheckNewValue() ------------
|
||||
|
||||
|
||||
#include <ctype.h> // isalpha(), toupper()
|
||||
#ifdef WIN32
|
||||
#include <strstrea.h>
|
||||
#else
|
||||
#include <strstream.h>
|
||||
#endif
|
||||
|
||||
//#include "checkNewValue_debug.icc"
|
||||
//#define DEBUG 1
|
||||
|
||||
int G4UIcommand::
|
||||
CheckNewValue(G4String newValue)
|
||||
{
|
||||
yystype result;
|
||||
// if( TypeCheck(newValue) == 0 ) return 1;
|
||||
if( ! rangeString.isNull() )
|
||||
{ if( RangeCheck(newValue) == 0 ) return fParameterOutOfRange; }
|
||||
return 0; // succeeded
|
||||
}
|
||||
|
||||
// ------------------ type check routines -------------------
|
||||
|
||||
int G4UIcommand::
|
||||
TypeCheck(G4String newValues)
|
||||
{
|
||||
G4String aNewValue;
|
||||
char type;
|
||||
const char* t = newValues;
|
||||
istrstream is((char*)t);
|
||||
for (unsigned i=0; i< parameter.entries(); i++) {
|
||||
is >> aNewValue;
|
||||
type = toupper(parameter(i)->GetParameterType());
|
||||
switch ( type ) {
|
||||
case 'D':
|
||||
if( IsDouble(aNewValue)==0 ){
|
||||
G4cerr << aNewValue << ": double value expected."
|
||||
<< endl;
|
||||
return 0;
|
||||
} break;
|
||||
case 'I':
|
||||
if( IsInt(aNewValue,20)==0 ){
|
||||
G4cerr <<aNewValue<<": integer expected."
|
||||
<<endl;
|
||||
return 0;
|
||||
} break;
|
||||
case 'S':
|
||||
break;
|
||||
case 'B':
|
||||
aNewValue.toUpper();
|
||||
if (aNewValue == "Y" || aNewValue == "N"
|
||||
||aNewValue == "YES" || aNewValue == "NO"
|
||||
||aNewValue == "1" || aNewValue == "0"
|
||||
||aNewValue == "T" || aNewValue == "F"
|
||||
||aNewValue == "TRUE" || aNewValue == "FALSE")
|
||||
return 1;
|
||||
else return 0;
|
||||
break;
|
||||
default: ;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int G4UIcommand::
|
||||
IsInt(const char* buf, short maxDigits)
|
||||
{
|
||||
const char* p= buf;
|
||||
int length=0;
|
||||
if( *p == '+' || *p == '-') { ++p; }
|
||||
if( isdigit( (int)(*p) )) {
|
||||
while( isdigit( (int)(*p) )) { ++p; ++length; }
|
||||
if( *p == '\0' ) {
|
||||
if( length > maxDigits) {
|
||||
G4cerr <<"digit length exceeds"<<endl;
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
} else {
|
||||
// G4cerr <<"illegal character after int:"<<buf<<endl;
|
||||
}
|
||||
} else {
|
||||
// G4cerr <<"illegal int:"<<buf<<endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int G4UIcommand::
|
||||
ExpectExponent(const char* str) // used only by IsDouble()
|
||||
{
|
||||
int maxExplength;
|
||||
if( IsInt( str, maxExplength=7 )) return 1;
|
||||
else return 0;
|
||||
}
|
||||
|
||||
|
||||
int G4UIcommand::
|
||||
IsDouble(const char* buf)
|
||||
{
|
||||
const char* p= buf;
|
||||
switch( *p) {
|
||||
case '+': case '-': ++p;
|
||||
if( isdigit(*p) ) {
|
||||
while( isdigit( (int)(*p) )) { ++p; }
|
||||
switch ( *p ) {
|
||||
case '\0': return 1;
|
||||
// break;
|
||||
case 'E': case 'e':
|
||||
return ExpectExponent(++p );
|
||||
// break;
|
||||
case '.': ++p;
|
||||
if( *p == '\0' ) return 1;
|
||||
if( *p == 'e' || *p =='E' ) return ExpectExponent(++p );
|
||||
if( isdigit(*p) ) {
|
||||
while( isdigit( (int)(*p) )) { ++p; }
|
||||
if( *p == '\0' ) return 1;
|
||||
if( *p == 'e' || *p =='E') return ExpectExponent(++p);
|
||||
} else return 0; break;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
if( *p == '.' ) { ++p;
|
||||
if( isdigit(*p) ) {
|
||||
while( isdigit( (int)(*p) )) { ++p; }
|
||||
if( *p == '\0' ) return 1;
|
||||
if( *p == 'e' || *p =='E') return ExpectExponent(++p);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '.': ++p;
|
||||
if( isdigit(*p) ) {
|
||||
while( isdigit( (int)(*p) )) { ++p; }
|
||||
if( *p == '\0' ) return 1;
|
||||
if( *p == 'e' || *p =='E' ) return ExpectExponent(++p);
|
||||
} break;
|
||||
default: // digit is expected
|
||||
if( isdigit(*p) ) {
|
||||
while( isdigit( (int)(*p) )) { ++p; }
|
||||
if( *p == '\0' ) return 1;
|
||||
if( *p == 'e' || *p =='E') return ExpectExponent(++p);
|
||||
if( *p == '.' ) { ++p;
|
||||
if( *p == '\0' ) return 1;
|
||||
if( *p == 'e' || *p =='E') return ExpectExponent(++p);
|
||||
if( isdigit(*p) ) {
|
||||
while( isdigit( (int)(*p) )) { ++p; }
|
||||
if( *p == '\0' ) return 1;
|
||||
if( *p == 'e' || *p =='E') return ExpectExponent(++p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// ------------------ range Check routines -------------------
|
||||
int G4UIcommand::
|
||||
RangeCheck(G4String newValue) {
|
||||
yystype result;
|
||||
char type;
|
||||
bp = 0; // reset buffer pointer for G4UIpGetc()
|
||||
const char* t = newValue;
|
||||
istrstream is((char*)t);
|
||||
for (unsigned i=0; i< parameter.entries(); i++) {
|
||||
type= toupper(parameter(i)->GetParameterType());
|
||||
switch ( type ) {
|
||||
case 'D': is >> newVal(i).D; break;
|
||||
case 'I': is >> newVal(i).I; break;
|
||||
case 'S':
|
||||
case 'B':
|
||||
default: ;
|
||||
}
|
||||
}
|
||||
// PrintToken(); // Print tokens (consumes all tokens)
|
||||
token= Yylex();
|
||||
result = Expression();
|
||||
|
||||
if( paramERR == 1 ) return 0;
|
||||
if( result.type != CONSTINT) {
|
||||
G4cerr << "Illegal Expression in parameter range." << endl;
|
||||
return 0;
|
||||
}
|
||||
if ( result.I ) return 1;
|
||||
G4cerr << "parameter out of range: "<< rangeString << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ------------------ syntax node functions ------------------
|
||||
yystype G4UIcommand::
|
||||
Expression(void)
|
||||
{
|
||||
yystype result;
|
||||
#ifdef DEBUG
|
||||
G4cerr << " Expression()" << endl;
|
||||
#endif
|
||||
result = LogicalORExpression();
|
||||
return result;
|
||||
}
|
||||
|
||||
yystype G4UIcommand::
|
||||
LogicalORExpression(void)
|
||||
{
|
||||
yystype result;
|
||||
yystype p;
|
||||
p = LogicalANDExpression();
|
||||
if( token != LOGICALOR) return p;
|
||||
if( p.type == CONSTSTRING || p.type == IDENTIFIER ) {
|
||||
G4cerr << "Parameter range: illegal type at '||'" << endl;
|
||||
paramERR = 1;
|
||||
}
|
||||
result.I = p.I;
|
||||
while (token == LOGICALOR)
|
||||
{
|
||||
token = Yylex();
|
||||
p = LogicalANDExpression();
|
||||
if( p.type == CONSTSTRING || p.type == IDENTIFIER ) {
|
||||
G4cerr << "Parameter range: illegal type at '||'" <<endl;
|
||||
paramERR = 1;
|
||||
}
|
||||
switch (p.type) {
|
||||
case CONSTINT:
|
||||
result.I += p.I;
|
||||
result.type = CONSTINT; break;
|
||||
case CONSTDOUBLE:
|
||||
result.I += (p.D != 0.0);
|
||||
result.type = CONSTINT; break;
|
||||
default:
|
||||
G4cerr << "Parameter range: unknown type"<<endl;
|
||||
paramERR = 1;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
yystype G4UIcommand::
|
||||
LogicalANDExpression(void)
|
||||
{
|
||||
yystype result;
|
||||
yystype p;
|
||||
p = EqualityExpression();
|
||||
if( token != LOGICALAND) return p;
|
||||
if( p.type == CONSTSTRING || p.type == IDENTIFIER ) {
|
||||
G4cerr << "Parameter range: illegal type at '&&'" << endl;
|
||||
paramERR = 1;
|
||||
}
|
||||
result.I = p.I;
|
||||
while (token == LOGICALAND)
|
||||
{
|
||||
token = Yylex();
|
||||
p = EqualityExpression();
|
||||
if( p.type == CONSTSTRING || p.type == IDENTIFIER ) {
|
||||
G4cerr << "Parameter range: illegal type at '&&'" << endl;
|
||||
paramERR = 1;
|
||||
}
|
||||
switch (p.type) {
|
||||
case CONSTINT:
|
||||
result.I *= p.I;
|
||||
result.type = CONSTINT; break;
|
||||
case CONSTDOUBLE:
|
||||
result.I *= (p.D != 0.0);
|
||||
result.type = CONSTINT; break;
|
||||
default:
|
||||
G4cerr << "Parameter range: unknown type."<< endl;
|
||||
paramERR = 1;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
yystype G4UIcommand::
|
||||
EqualityExpression(void)
|
||||
{
|
||||
yystype arg1, arg2;
|
||||
int operat;
|
||||
yystype result;
|
||||
#ifdef DEBUG
|
||||
G4cerr << " EqualityExpression()" <<endl;
|
||||
#endif
|
||||
result = RelationalExpression();
|
||||
if( token==EQ || token==NE ) {
|
||||
operat = token;
|
||||
token = Yylex();
|
||||
arg1 = result;
|
||||
arg2 = RelationalExpression();
|
||||
result.I = Eval2( arg1, operat, arg2 ); // semantic action
|
||||
result.type = CONSTINT;
|
||||
#ifdef DEBUG
|
||||
G4cerr << " return code of Eval2(): " << result.I <<endl;
|
||||
#endif
|
||||
} else {
|
||||
if (result.type != CONSTINT && result.type != CONSTDOUBLE) {
|
||||
G4cerr << "Parameter range: error at EqualityExpression"
|
||||
<< endl;
|
||||
paramERR = 1;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
yystype G4UIcommand::
|
||||
RelationalExpression(void)
|
||||
{
|
||||
yystype arg1, arg2;
|
||||
int operat;
|
||||
yystype result;
|
||||
#ifdef DEBUG
|
||||
G4cerr << " RelationalExpression()" <<endl;
|
||||
#endif
|
||||
|
||||
arg1 = AdditiveExpression();
|
||||
if( token==GT || token==GE || token==LT || token==LE ) {
|
||||
operat = token;
|
||||
token = Yylex();
|
||||
arg2 = AdditiveExpression();
|
||||
result.I = Eval2( arg1, operat, arg2 ); // semantic action
|
||||
result.type = CONSTINT;
|
||||
#ifdef DEBUG
|
||||
G4cerr << " return code of Eval2(): " << result.I << endl;
|
||||
#endif
|
||||
} else {
|
||||
result = arg1;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
G4cerr <<" return RelationalExpression()"<< endl;
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
yystype G4UIcommand::
|
||||
AdditiveExpression(void)
|
||||
{ yystype result;
|
||||
result = MultiplicativeExpression();
|
||||
if( token != '+' && token != '-' ) return result;
|
||||
G4cerr << "Parameter range: operator "
|
||||
<< (char)token
|
||||
<< " is not supported." << endl;
|
||||
paramERR = 1;
|
||||
return result;
|
||||
}
|
||||
|
||||
yystype G4UIcommand::
|
||||
MultiplicativeExpression(void)
|
||||
{ yystype result;
|
||||
result = UnaryExpression();
|
||||
if( token != '*' && token != '/' && token != '%' ) return result;
|
||||
G4cerr << "Parameter range: operator "
|
||||
<< (char)token
|
||||
<< " is not supported." << endl;
|
||||
paramERR = 1;
|
||||
return result;
|
||||
}
|
||||
|
||||
yystype G4UIcommand::
|
||||
UnaryExpression(void)
|
||||
{
|
||||
yystype result;
|
||||
yystype p;
|
||||
#ifdef DEBUG
|
||||
G4cerr <<" UnaryExpression"<< endl;
|
||||
#endif
|
||||
switch(token) {
|
||||
case '-':
|
||||
token = Yylex();
|
||||
p = UnaryExpression();
|
||||
if (p.type == CONSTINT) {
|
||||
result.I = - p.I;
|
||||
result.type = CONSTINT;
|
||||
}
|
||||
if (p.type == CONSTDOUBLE) {
|
||||
result.D = - p.D;
|
||||
result.type = CONSTDOUBLE;
|
||||
} break;
|
||||
case '+':
|
||||
token = Yylex();
|
||||
result = UnaryExpression(); break;
|
||||
case '!':
|
||||
token = Yylex();
|
||||
G4cerr << "Parameter range error: "
|
||||
<< "operator '!' is not supported (sorry)."
|
||||
<< endl;
|
||||
paramERR = 1;
|
||||
result = UnaryExpression(); break;
|
||||
default:
|
||||
result = PrimaryExpression();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
yystype G4UIcommand::
|
||||
PrimaryExpression(void)
|
||||
{
|
||||
yystype result;
|
||||
#ifdef DEBUG
|
||||
G4cerr <<" primary_exp"<<endl;
|
||||
#endif
|
||||
switch (token) {
|
||||
case IDENTIFIER:
|
||||
result.S = yylval.S;
|
||||
result.type = token;
|
||||
token = Yylex(); break;
|
||||
case CONSTINT:
|
||||
result.I = yylval.I;
|
||||
result.type = token;
|
||||
token= Yylex(); break;
|
||||
case CONSTDOUBLE:
|
||||
result.D = yylval.D;
|
||||
result.type = token;
|
||||
token = Yylex(); break;
|
||||
case '(' :
|
||||
token= Yylex();
|
||||
result = Expression();
|
||||
if( token != ')' ) {
|
||||
G4cerr << " ')' expected" << endl;
|
||||
paramERR = 1;
|
||||
}
|
||||
token = Yylex();
|
||||
break;
|
||||
default:
|
||||
return result;
|
||||
}
|
||||
return result; // never executed
|
||||
}
|
||||
|
||||
//---------------- semantic routines ---------------------------------
|
||||
|
||||
int G4UIcommand::
|
||||
Eval2(yystype arg1, int op, yystype arg2)
|
||||
{
|
||||
char newValtype;
|
||||
if( (arg1.type != IDENTIFIER) && (arg2.type != IDENTIFIER)) {
|
||||
G4cerr << commandName
|
||||
<< ": meaningless comparison"
|
||||
<< endl;
|
||||
paramERR = 1;
|
||||
}
|
||||
|
||||
if( arg1.type == IDENTIFIER) {
|
||||
unsigned i = IndexOf( arg1.S );
|
||||
newValtype = toupper(parameter(i)->GetParameterType());
|
||||
switch ( newValtype ) {
|
||||
case 'I':
|
||||
if( arg2.type == CONSTINT ) {
|
||||
return CompareInt( newVal(i).I, op, arg2.I );
|
||||
} else {
|
||||
G4cerr << "integer operand expected for "
|
||||
<< rangeString
|
||||
<< '.' << endl;
|
||||
} break;
|
||||
case 'D':
|
||||
if( arg2.type == CONSTDOUBLE ) {
|
||||
return CompareDouble( newVal(i).D, op, arg2.D );
|
||||
} else
|
||||
if ( arg2.type == CONSTINT ) { // integral promotion
|
||||
return CompareDouble( newVal(i).D, op, arg2.I );
|
||||
} break;
|
||||
default: ;
|
||||
}
|
||||
}
|
||||
if( arg2.type == IDENTIFIER) {
|
||||
unsigned i = IndexOf( arg2.S );
|
||||
newValtype = toupper(parameter(i)->GetParameterType());
|
||||
switch ( newValtype ) {
|
||||
case 'I':
|
||||
if( arg1.type == CONSTINT ) {
|
||||
return CompareInt( arg1.I, op, newVal(i).I );
|
||||
} else {
|
||||
G4cerr << "integer operand expected for "
|
||||
<< rangeString
|
||||
<< '.' << endl;
|
||||
} break;
|
||||
case 'D':
|
||||
if( arg1.type == CONSTDOUBLE ) {
|
||||
return CompareDouble( arg1.D, op, newVal(i).D );
|
||||
} else
|
||||
if ( arg1.type == CONSTINT ) { // integral promotion
|
||||
return CompareDouble( arg1.I, op, newVal(i).D );
|
||||
} break;
|
||||
default: ;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int G4UIcommand::
|
||||
CompareInt(int arg1, int op, int arg2)
|
||||
{
|
||||
int result;
|
||||
G4String opr;
|
||||
switch (op) {
|
||||
case GT: result = ( arg1 > arg2); opr= ">" ; break;
|
||||
case GE: result = ( arg1 >= arg2); opr= ">="; break;
|
||||
case LT: result = ( arg1 < arg2); opr= "<" ; break;
|
||||
case LE: result = ( arg1 <= arg2); opr= "<="; break;
|
||||
case EQ: result = ( arg1 == arg2); opr= "=="; break;
|
||||
case NE: result = ( arg1 != arg2); opr= "!="; break;
|
||||
default:
|
||||
G4cerr << "Parameter range: error at CompareInt" << endl;
|
||||
paramERR = 1;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
G4cerr << "CompareInt "
|
||||
<< arg1 << " " << opr << arg2
|
||||
<< " result: " << result
|
||||
<< endl;
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
int G4UIcommand::
|
||||
CompareDouble(double arg1, int op, double arg2)
|
||||
{
|
||||
int result;
|
||||
G4String opr;
|
||||
switch (op) {
|
||||
case GT: result = ( arg1 > arg2); opr= ">"; break;
|
||||
case GE: result = ( arg1 >= arg2); opr= ">="; break;
|
||||
case LT: result = ( arg1 < arg2); opr= "<"; break;
|
||||
case LE: result = ( arg1 <= arg2); opr= "<="; break;
|
||||
case EQ: result = ( arg1 == arg2); opr= "=="; break;
|
||||
case NE: result = ( arg1 != arg2); opr= "!="; break;
|
||||
default:
|
||||
G4cerr << "Parameter range: error at CompareDouble"
|
||||
<< endl;
|
||||
paramERR = 1;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
G4cerr << "CompareDouble "
|
||||
<< arg1 <<" " << opr << " "<< arg2
|
||||
<< " result: " << result
|
||||
<< endl;
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
unsigned G4UIcommand::
|
||||
IndexOf( G4String nam)
|
||||
{
|
||||
unsigned i;
|
||||
G4String pname;
|
||||
for( i=0; i<parameter.entries(); i++)
|
||||
{
|
||||
pname = parameter(i)-> GetParameterName();
|
||||
if( pname == nam ) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
paramERR = 1;
|
||||
G4cerr << "parameter name:"<<nam<<" not found."<< endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
unsigned G4UIcommand::
|
||||
IsParameter(G4String nam)
|
||||
{
|
||||
G4String pname;
|
||||
for(unsigned i=0; i<parameter.entries(); i++)
|
||||
{
|
||||
pname = parameter(i)-> GetParameterName();
|
||||
if( pname == nam ) return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// --------------------- utility functions --------------------------
|
||||
|
||||
tokenNum G4UIcommand::
|
||||
Yylex() // reads input and returns token number, KR486
|
||||
{ // (returns EOF)
|
||||
int c;
|
||||
G4String buf;
|
||||
|
||||
while(( c= G4UIpGetc())==' '|| c=='\t' || c== '\n' )
|
||||
;
|
||||
if (c== EOF)
|
||||
return (tokenNum)EOF; // KR488
|
||||
buf= "";
|
||||
if (isdigit(c) || c== '.') { // I or D
|
||||
do {
|
||||
buf += G4String((unsigned char)c);
|
||||
c=G4UIpGetc();
|
||||
} while (c=='.' || isdigit(c) ||
|
||||
c=='e' || c=='E' || c=='+' || c=='-');
|
||||
G4UIpUngetc(c);
|
||||
const char* t = buf;
|
||||
istrstream is((char*)t);
|
||||
if ( IsInt(buf.data(),20) ) {
|
||||
is >> yylval.I;
|
||||
return CONSTINT;
|
||||
} else
|
||||
if ( IsDouble(buf.data()) ) {
|
||||
is >> yylval.D;
|
||||
return CONSTDOUBLE;
|
||||
} else {
|
||||
G4cerr << buf<<": numeric format error."<<endl;
|
||||
}
|
||||
}
|
||||
buf="";
|
||||
if (isalpha(c)|| c=='_') { // IDENTIFIER
|
||||
do {
|
||||
buf += G4String((unsigned char)c);
|
||||
} while ((c=G4UIpGetc()) != EOF && (isalnum(c) || c=='_'));
|
||||
G4UIpUngetc(c);
|
||||
if( IsParameter(buf) ) {
|
||||
yylval.S =buf;
|
||||
return IDENTIFIER;
|
||||
} else {
|
||||
G4cerr << buf << " is not a parameter name."<< endl;
|
||||
paramERR = 1;
|
||||
}
|
||||
}
|
||||
switch (c) {
|
||||
case '>': return (tokenNum) Follow('=', GE, GT);
|
||||
case '<': return (tokenNum) Follow('=', LE, LT);
|
||||
case '=': return (tokenNum) Follow('=', EQ, '=');
|
||||
case '!': return (tokenNum) Follow('=', NE, '!');
|
||||
case '|': return (tokenNum) Follow('|', LOGICALOR, '|');
|
||||
case '&': return (tokenNum) Follow('&', LOGICALAND, '&');
|
||||
default:
|
||||
return (tokenNum) c;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int G4UIcommand::
|
||||
Follow(int expect, int ifyes, int ifno)
|
||||
{
|
||||
int c = G4UIpGetc();
|
||||
if ( c== expect)
|
||||
return ifyes;
|
||||
G4UIpUngetc(c);
|
||||
return ifno;
|
||||
}
|
||||
|
||||
//------------------ low level routines -----------------------------
|
||||
int G4UIcommand::
|
||||
G4UIpGetc() { // emulation of getc()
|
||||
int length = rangeString.length();
|
||||
if( bp < length)
|
||||
return rangeString(bp++);
|
||||
else
|
||||
return EOF;
|
||||
}
|
||||
int G4UIcommand::
|
||||
G4UIpUngetc(int c) { // emulation of ungetc()
|
||||
if (c<0) return -1;
|
||||
if (bp >0 && c == rangeString(bp-1)) {
|
||||
--bp;
|
||||
} else {
|
||||
G4cerr << "G4UIpUngetc() failed." << endl;
|
||||
G4cerr << "bp="<<bp <<" c="<<c
|
||||
<< " pR(bp-1)=" << rangeString(bp-1)
|
||||
<< endl;
|
||||
paramERR = 1;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,234 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the RD44 GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: G4UIcommandTree.cc,v 2.2 1998/07/13 17:12:57 urbi Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
|
||||
#include "G4UIcommandTree.hh"
|
||||
#include "G4ios.hh"
|
||||
|
||||
G4UIcommandTree::G4UIcommandTree()
|
||||
:guidance(NULL)
|
||||
{ }
|
||||
|
||||
G4UIcommandTree::G4UIcommandTree(G4String thePathName)
|
||||
:guidance(NULL)
|
||||
{
|
||||
pathName = thePathName;
|
||||
}
|
||||
|
||||
G4UIcommandTree::G4UIcommandTree(char * thePathName)
|
||||
:guidance(NULL)
|
||||
{
|
||||
pathName = thePathName;
|
||||
}
|
||||
|
||||
G4UIcommandTree::~G4UIcommandTree()
|
||||
{
|
||||
int i;
|
||||
int n_treeEntry = tree.entries();
|
||||
for( i=0; i < n_treeEntry; i++ )
|
||||
{ delete tree[i]; }
|
||||
}
|
||||
|
||||
int G4UIcommandTree::operator==(const G4UIcommandTree &right) const
|
||||
{
|
||||
return ( pathName == right.GetPathName() );
|
||||
}
|
||||
|
||||
int G4UIcommandTree::operator!=(const G4UIcommandTree &right) const
|
||||
{
|
||||
return ( pathName != right.GetPathName() );
|
||||
}
|
||||
|
||||
void G4UIcommandTree::AddNewCommand(G4UIcommand *newCommand)
|
||||
{
|
||||
G4String commandPath = newCommand->GetCommandPath();
|
||||
G4String remainingPath = commandPath;
|
||||
remainingPath.remove(0,pathName.length());
|
||||
if( remainingPath.isNull() )
|
||||
{
|
||||
guidance = newCommand;
|
||||
return;
|
||||
}
|
||||
int i = remainingPath.first('/');
|
||||
if( i == RW_NPOS )
|
||||
{
|
||||
// Find command
|
||||
int n_commandEntry = command.entries();
|
||||
for( int i_thCommand = 0; i_thCommand < n_commandEntry; i_thCommand++ )
|
||||
{
|
||||
if( remainingPath == command[i_thCommand]->GetCommandName() )
|
||||
{ return; }
|
||||
}
|
||||
command.insert( newCommand );
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Find path
|
||||
G4String nextPath = pathName;
|
||||
nextPath.append(remainingPath(0,i+1));
|
||||
int n_treeEntry = tree.entries();
|
||||
for( int i_thTree = 0; i_thTree < n_treeEntry; i_thTree++ )
|
||||
{
|
||||
if( nextPath == tree[i_thTree]->GetPathName() )
|
||||
{
|
||||
tree[i_thTree]->AddNewCommand( newCommand );
|
||||
return;
|
||||
}
|
||||
}
|
||||
G4UIcommandTree * newTree = new G4UIcommandTree( nextPath );
|
||||
tree.insert( newTree );
|
||||
newTree->AddNewCommand( newCommand );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void G4UIcommandTree::RemoveCommand(G4UIcommand *aCommand)
|
||||
{
|
||||
G4String commandPath = aCommand->GetCommandPath();
|
||||
G4String remainingPath = commandPath;
|
||||
remainingPath.remove(0,pathName.length());
|
||||
if( remainingPath.isNull() )
|
||||
{
|
||||
guidance = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
int i = remainingPath.first('/');
|
||||
if( i == RW_NPOS )
|
||||
{
|
||||
// Find command
|
||||
int n_commandEntry = command.entries();
|
||||
for( int i_thCommand = 0; i_thCommand < n_commandEntry; i_thCommand++ )
|
||||
{
|
||||
if( remainingPath == command[i_thCommand]->GetCommandName() )
|
||||
{
|
||||
command.remove(command[i_thCommand]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Find path
|
||||
G4String nextPath = pathName;
|
||||
nextPath.append(remainingPath(0,i+1));
|
||||
int n_treeEntry = tree.entries();
|
||||
for( int i_thTree = 0; i_thTree < n_treeEntry; i_thTree++ )
|
||||
{
|
||||
if( nextPath == tree[i_thTree]->GetPathName() )
|
||||
{
|
||||
tree[i_thTree]->RemoveCommand( aCommand );
|
||||
int n_commandRemain = tree[i_thTree]->GetCommandEntry();
|
||||
if(n_commandRemain==0)
|
||||
{
|
||||
G4UIcommandTree * emptyTree = tree[i_thTree];
|
||||
tree.remove(tree[i_thTree]);
|
||||
delete emptyTree;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
G4UIcommand * G4UIcommandTree::FindPath(G4String commandPath)
|
||||
{
|
||||
if( commandPath.index( pathName ) == RW_NPOS )
|
||||
{ return NULL; }
|
||||
G4String remainingPath = commandPath;
|
||||
remainingPath.remove(0,pathName.length());
|
||||
int i = remainingPath.first('/');
|
||||
if( i == RW_NPOS )
|
||||
{
|
||||
// Find command
|
||||
int n_commandEntry = command.entries();
|
||||
for( int i_thCommand = 0; i_thCommand < n_commandEntry; i_thCommand++ )
|
||||
{
|
||||
if( remainingPath == command[i_thCommand]->GetCommandName() )
|
||||
{ return command[i_thCommand]; }
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Find path
|
||||
G4String nextPath = pathName;
|
||||
nextPath.append(remainingPath(0,i+1));
|
||||
int n_treeEntry = tree.entries();
|
||||
for( int i_thTree = 0; i_thTree < n_treeEntry; i_thTree++ )
|
||||
{
|
||||
if( nextPath == tree[i_thTree]->GetPathName() )
|
||||
{ return tree[i_thTree]->FindPath( commandPath ); }
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void G4UIcommandTree::ListCurrent()
|
||||
{
|
||||
G4cout << "Command directory path : " << pathName << endl;
|
||||
if( guidance != NULL ) guidance->List();
|
||||
int i = 0;
|
||||
G4cout << " Sub-directories : " << endl;
|
||||
int n_treeEntry = tree.entries();
|
||||
for( int i_thTree = 0; i_thTree < n_treeEntry; i_thTree++ )
|
||||
{
|
||||
G4cout << " " << tree[i_thTree]->GetPathName()
|
||||
<< " " << tree[i_thTree]->GetTitle() << endl;
|
||||
}
|
||||
G4cout << " Commands : " << endl;
|
||||
int n_commandEntry = command.entries();
|
||||
for( int i_thCommand = 0; i_thCommand < n_commandEntry; i_thCommand++ )
|
||||
{
|
||||
G4cout << " " << command[i_thCommand]->GetCommandName()
|
||||
<< " * " << command[i_thCommand]->GetTitle() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void G4UIcommandTree::ListCurrentWithNum()
|
||||
{
|
||||
G4cout << "Command directory path : " << pathName << endl;
|
||||
if( guidance != NULL ) guidance->List();
|
||||
int i = 0;
|
||||
G4cout << " Sub-directories : " << endl;
|
||||
int n_treeEntry = tree.entries();
|
||||
for( int i_thTree = 0; i_thTree < n_treeEntry; i_thTree++ )
|
||||
{
|
||||
i++;
|
||||
G4cout << " " << i << ") " << tree[i_thTree]->GetPathName()
|
||||
<< " " << tree[i_thTree]->GetTitle() << endl;
|
||||
}
|
||||
G4cout << " Commands : " << endl;
|
||||
int n_commandEntry = command.entries();
|
||||
for( int i_thCommand = 0; i_thCommand < n_commandEntry; i_thCommand++ )
|
||||
{
|
||||
i++;
|
||||
G4cout << " " << i << ") " << command[i_thCommand]->GetCommandName()
|
||||
<< " * " << command[i_thCommand]->GetTitle() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void G4UIcommandTree::List()
|
||||
{
|
||||
ListCurrent();
|
||||
int n_commandEntry = command.entries();
|
||||
for( int i_thCommand = 0; i_thCommand < n_commandEntry; i_thCommand++ )
|
||||
{
|
||||
command[i_thCommand]->List();
|
||||
}
|
||||
int n_treeEntry = tree.entries();
|
||||
for( int i_thTree = 0; i_thTree < n_treeEntry; i_thTree++ )
|
||||
{
|
||||
tree[i_thTree]->List();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the RD44 GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: G4UIcontrolMessenger.cc,v 2.4 1998/10/01 15:50:00 asaim Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
|
||||
#include "G4UIcontrolMessenger.hh"
|
||||
#include "G4UImanager.hh"
|
||||
#include "G4UIdirectory.hh"
|
||||
#include "G4UIcmdWithAString.hh"
|
||||
#include "G4UIcmdWithAnInteger.hh"
|
||||
#include "G4UIcmdWithoutParameter.hh"
|
||||
#include "G4ios.hh"
|
||||
|
||||
G4UIcontrolMessenger::G4UIcontrolMessenger()
|
||||
{
|
||||
controlDirectory = new G4UIdirectory("/control/");
|
||||
controlDirectory->SetGuidance("UI control commands.");
|
||||
|
||||
ExecuteCommand = new G4UIcmdWithAString("/control/execute",this);
|
||||
ExecuteCommand->SetGuidance("Execute a macro file.");
|
||||
ExecuteCommand->SetParameterName("fileName",false);
|
||||
|
||||
verboseCommand = new G4UIcmdWithAnInteger("/control/verbose",this);
|
||||
verboseCommand->SetGuidance("Applied command will also be shown on screen.");
|
||||
verboseCommand->SetGuidance("This command is useful with MACRO file.");
|
||||
verboseCommand->SetGuidance(" 0 : silent");
|
||||
verboseCommand->SetGuidance(" 1 : only the valid commands are shown.");
|
||||
verboseCommand->SetGuidance(" 2 : comment lines are also shown (default).");
|
||||
verboseCommand->SetParameterName("switch",true);
|
||||
verboseCommand->SetRange("switch >= 0 && switch <=2");
|
||||
verboseCommand->SetDefaultValue(2);
|
||||
|
||||
historyCommand = new G4UIcmdWithAString("/control/saveHistory",this);
|
||||
historyCommand->SetGuidance("Store command history to a file.");
|
||||
historyCommand->SetGuidance("Defaul file name is G4history.macro.");
|
||||
historyCommand->SetParameterName("fileName",true);
|
||||
historyCommand->SetDefaultValue("G4History.macro");
|
||||
|
||||
stopStoreHistoryCommand
|
||||
= new G4UIcmdWithoutParameter("/control/stopSavingHistory",this);
|
||||
stopStoreHistoryCommand->SetGuidance("Stop saving history file.");
|
||||
|
||||
ManualCommand = new G4UIcmdWithAString("/control/manual",this);
|
||||
ManualCommand->SetGuidance("Display all of sub-directories and commands.");
|
||||
ManualCommand->SetGuidance("Directory path should be given by FULL-PATH.");
|
||||
ManualCommand->SetParameterName("dirPath",true);
|
||||
ManualCommand->SetDefaultValue("/");
|
||||
}
|
||||
|
||||
G4UIcontrolMessenger::~G4UIcontrolMessenger()
|
||||
{
|
||||
delete ExecuteCommand;
|
||||
delete verboseCommand;
|
||||
delete historyCommand;
|
||||
delete stopStoreHistoryCommand;
|
||||
delete ManualCommand;
|
||||
|
||||
delete controlDirectory;
|
||||
}
|
||||
|
||||
void G4UIcontrolMessenger::SetNewValue(G4UIcommand * command,G4String newValue)
|
||||
{
|
||||
G4UImanager * UI = G4UImanager::GetUIpointer();
|
||||
|
||||
if(command==ExecuteCommand)
|
||||
{
|
||||
UI->ExecuteMacroFile(newValue);
|
||||
}
|
||||
if(command==verboseCommand)
|
||||
{
|
||||
UI->SetVerboseLevel(verboseCommand->GetNewIntValue(newValue));
|
||||
}
|
||||
if(command==historyCommand)
|
||||
{
|
||||
UI->StoreHistory(newValue);
|
||||
}
|
||||
if(command==stopStoreHistoryCommand)
|
||||
{
|
||||
UI->StoreHistory(false);
|
||||
}
|
||||
if(command==ManualCommand)
|
||||
{
|
||||
UI->ListCommands(newValue);
|
||||
}
|
||||
}
|
||||
|
||||
G4String G4UIcontrolMessenger::GetCurrentValue(G4UIcommand * command)
|
||||
{
|
||||
G4UImanager * UI = G4UImanager::GetUIpointer();
|
||||
G4String currentValue;
|
||||
|
||||
if(command==verboseCommand)
|
||||
{
|
||||
currentValue = verboseCommand->ConvertToString(UI->GetVerboseLevel());
|
||||
}
|
||||
|
||||
return currentValue;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the RD44 GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: G4UIdirectory.cc,v 2.0 1998/07/02 17:08:55 gunter Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
//
|
||||
|
||||
#include "G4UIdirectory.hh"
|
||||
|
||||
G4UIdirectory::G4UIdirectory(char * theCommandPath)
|
||||
:G4UIcommand(theCommandPath,NULL)
|
||||
{;}
|
||||
|
||||
G4UIdirectory::G4UIdirectory(const char * theCommandPath)
|
||||
:G4UIcommand(theCommandPath,NULL)
|
||||
{;}
|
||||
|
||||
@@ -0,0 +1,327 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the RD44 GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: G4UImanager.cc,v 2.8 1998/12/03 15:41:52 stesting Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
//
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
#include "G4UImanager.hh"
|
||||
#include "G4UIcommandStatus.hh"
|
||||
#include "G4UIcommandTree.hh"
|
||||
#include "G4UIcommand.hh"
|
||||
#include "G4UIsession.hh"
|
||||
#include "G4UIbatch.hh"
|
||||
#include "G4UIcontrolMessenger.hh"
|
||||
#include "G4UnitsMessenger.hh"
|
||||
#include "G4ios.hh"
|
||||
#include "G4strstreambuf.hh"
|
||||
|
||||
#ifdef WIN32
|
||||
# include <Strstrea.h>
|
||||
#else
|
||||
# include <strstream.h>
|
||||
#endif
|
||||
|
||||
G4UImanager * G4UImanager::fUImanager = 0;
|
||||
G4bool G4UImanager::fUImanagerHasBeenKilled = false;
|
||||
|
||||
G4UImanager * G4UImanager::GetUIpointer()
|
||||
{
|
||||
if(!fUImanager)
|
||||
{
|
||||
if(!fUImanagerHasBeenKilled)
|
||||
{
|
||||
fUImanager = new G4UImanager;
|
||||
fUImanager->CreateMessenger();
|
||||
}
|
||||
}
|
||||
return fUImanager;
|
||||
}
|
||||
|
||||
G4UImanager::G4UImanager():savedCommand(NULL)
|
||||
{
|
||||
treeTop = new G4UIcommandTree("/");
|
||||
G4String nullString;
|
||||
savedParameters = nullString;
|
||||
verboseLevel = 0;
|
||||
saveHistory = false;
|
||||
session = NULL;
|
||||
SetCoutDestination(session);
|
||||
}
|
||||
|
||||
void G4UImanager::CreateMessenger()
|
||||
{
|
||||
UImessenger = new G4UIcontrolMessenger;
|
||||
UnitsMessenger = new G4UnitsMessenger;
|
||||
}
|
||||
|
||||
G4UImanager::~G4UImanager()
|
||||
{
|
||||
SetCoutDestination(NULL);
|
||||
histVec.clear();
|
||||
if(saveHistory) historyFile.close();
|
||||
delete UImessenger;
|
||||
delete UnitsMessenger;
|
||||
delete treeTop;
|
||||
fUImanagerHasBeenKilled = true;
|
||||
fUImanager = NULL;
|
||||
}
|
||||
|
||||
G4UImanager::G4UImanager(const G4UImanager &right) { }
|
||||
const G4UImanager & G4UImanager::operator=(const G4UImanager &right)
|
||||
{ return right; }
|
||||
int G4UImanager::operator==(const G4UImanager &right) const
|
||||
{ return false; }
|
||||
int G4UImanager::operator!=(const G4UImanager &right) const
|
||||
{ return true; }
|
||||
|
||||
G4String G4UImanager::GetCurrentValues(const char * aCommand)
|
||||
{
|
||||
G4String theCommand = aCommand;
|
||||
savedCommand = treeTop->FindPath( theCommand );
|
||||
if( savedCommand == NULL )
|
||||
{
|
||||
G4cerr << "command not found" << endl;
|
||||
return G4String();
|
||||
}
|
||||
return savedCommand->GetCurrentValue();
|
||||
}
|
||||
|
||||
G4String G4UImanager::GetCurrentStringValue(const char * aCommand,
|
||||
int parameterNumber, G4bool reGet)
|
||||
{
|
||||
if(reGet || savedCommand == NULL)
|
||||
{
|
||||
savedParameters = GetCurrentValues( aCommand );
|
||||
}
|
||||
RWCTokenizer savedToken( savedParameters );
|
||||
G4String token;
|
||||
for(int i_thParameter=0;i_thParameter<parameterNumber;i_thParameter++)
|
||||
{
|
||||
token = savedToken();
|
||||
if( token.isNull() ) return G4String();
|
||||
if( token[(size_t)0] == '"' )
|
||||
{
|
||||
token.append(" ");
|
||||
token.append(savedToken("\""));
|
||||
}
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
G4String G4UImanager::GetCurrentStringValue(const char * aCommand,
|
||||
const char * aParameterName, G4bool reGet)
|
||||
{
|
||||
if(reGet || savedCommand == NULL)
|
||||
{
|
||||
G4String parameterValues = GetCurrentValues( aCommand );
|
||||
}
|
||||
for(int i=0;i<savedCommand->GetParameterEntries();i++)
|
||||
{
|
||||
if( aParameterName ==
|
||||
savedCommand->GetParameter(i)->GetParameterName() )
|
||||
return GetCurrentStringValue(aCommand,i+1,false);
|
||||
}
|
||||
return G4String();
|
||||
}
|
||||
|
||||
G4int G4UImanager::GetCurrentIntValue(const char * aCommand,
|
||||
const char * aParameterName, G4bool reGet)
|
||||
{
|
||||
G4String targetParameter =
|
||||
GetCurrentStringValue( aCommand, aParameterName, reGet );
|
||||
G4int value;
|
||||
const char* t = targetParameter;
|
||||
istrstream is((char*)t);
|
||||
is >> value;
|
||||
return value;
|
||||
}
|
||||
|
||||
G4int G4UImanager::GetCurrentIntValue(const char * aCommand,
|
||||
int parameterNumber, G4bool reGet)
|
||||
{
|
||||
G4String targetParameter =
|
||||
GetCurrentStringValue( aCommand, parameterNumber, reGet );
|
||||
G4int value;
|
||||
const char* t = targetParameter;
|
||||
istrstream is((char*)t);
|
||||
is >> value;
|
||||
return value;
|
||||
}
|
||||
|
||||
G4double G4UImanager::GetCurrentDoubleValue(const char * aCommand,
|
||||
const char * aParameterName, G4bool reGet)
|
||||
{
|
||||
G4String targetParameter =
|
||||
GetCurrentStringValue( aCommand, aParameterName, reGet );
|
||||
G4double value;
|
||||
const char* t = targetParameter;
|
||||
istrstream is((char*)t);
|
||||
is >> value;
|
||||
return value;
|
||||
}
|
||||
|
||||
G4double G4UImanager::GetCurrentDoubleValue(const char * aCommand,
|
||||
int parameterNumber, G4bool reGet)
|
||||
{
|
||||
G4String targetParameter =
|
||||
GetCurrentStringValue( aCommand, parameterNumber, reGet );
|
||||
G4double value;
|
||||
const char* t = targetParameter;
|
||||
istrstream is((char*)t);
|
||||
is >> value;
|
||||
return value;
|
||||
}
|
||||
|
||||
void G4UImanager::AddNewCommand(G4UIcommand * newCommand)
|
||||
{
|
||||
treeTop->AddNewCommand( newCommand );
|
||||
}
|
||||
|
||||
void G4UImanager::RemoveCommand(G4UIcommand * aCommand)
|
||||
{
|
||||
treeTop->RemoveCommand( aCommand );
|
||||
}
|
||||
|
||||
void G4UImanager::ExecuteMacroFile(G4String fileName)
|
||||
{
|
||||
G4UIsession* batchSession = new G4UIbatch(fileName,session);
|
||||
session = batchSession;
|
||||
G4UIsession* previousSession = session->SessionStart();
|
||||
delete session;
|
||||
session = previousSession;
|
||||
}
|
||||
|
||||
int G4UImanager::ApplyCommand(char * aCommand)
|
||||
{
|
||||
G4String theCommand = aCommand;
|
||||
return ApplyCommand(theCommand);
|
||||
}
|
||||
|
||||
int G4UImanager::ApplyCommand(G4String aCommand)
|
||||
{
|
||||
if(verboseLevel) G4cout << aCommand << endl;
|
||||
|
||||
G4String commandString;
|
||||
G4String commandParameter;
|
||||
int i = aCommand.index(" ");
|
||||
if( i != RW_NPOS )
|
||||
{
|
||||
commandString = aCommand(0,i);
|
||||
commandParameter = aCommand(i+1,aCommand.length()-(i+1));
|
||||
}
|
||||
else
|
||||
{
|
||||
commandString = aCommand;
|
||||
}
|
||||
|
||||
G4UIcommand * targetCommand = treeTop->FindPath( commandString );
|
||||
if( targetCommand == NULL )
|
||||
{
|
||||
// G4cout << commandString << " NOT FOUND." << endl;
|
||||
return fCommandNotFound;
|
||||
}
|
||||
|
||||
if(!(targetCommand->IsAvailable()))
|
||||
{ return fIllegalApplicationState; }
|
||||
|
||||
if(saveHistory) historyFile << aCommand << endl;
|
||||
histVec.insert(aCommand);
|
||||
return targetCommand->DoIt( commandParameter );
|
||||
}
|
||||
|
||||
void G4UImanager::StoreHistory(G4String fileName)
|
||||
{ StoreHistory(true,fileName); }
|
||||
|
||||
void G4UImanager::StoreHistory(G4bool historySwitch,G4String fileName)
|
||||
{
|
||||
if(historySwitch)
|
||||
{
|
||||
if(saveHistory)
|
||||
{ historyFile.close(); }
|
||||
const char* theFileName = fileName;
|
||||
historyFile.open((char*)theFileName);
|
||||
saveHistory = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
historyFile.close();
|
||||
saveHistory = false;
|
||||
}
|
||||
saveHistory = historySwitch;
|
||||
}
|
||||
|
||||
void G4UImanager::PauseSession(G4String msg)
|
||||
{
|
||||
if(session) session->PauseSessionStart(msg);
|
||||
}
|
||||
|
||||
void G4UImanager::ListCommands(G4String direct)
|
||||
{
|
||||
G4UIcommandTree* comTree = FindDirectory(direct);
|
||||
if(comTree)
|
||||
{ comTree->List(); }
|
||||
else
|
||||
{ G4cout << direct << " is not found." << endl; }
|
||||
}
|
||||
|
||||
G4UIcommandTree* G4UImanager::FindDirectory(const char* dirName)
|
||||
{
|
||||
G4String aDirName = dirName;
|
||||
G4String targetDir = aDirName.strip(G4String::both);
|
||||
if( targetDir( targetDir.length()-1 ) != '/' )
|
||||
{ targetDir += "/"; }
|
||||
G4UIcommandTree* comTree = treeTop;
|
||||
if( targetDir == "/" )
|
||||
{ return comTree; }
|
||||
int idx = 1;
|
||||
while( idx < targetDir.length()-1 )
|
||||
{
|
||||
int i = targetDir.index("/",idx);
|
||||
comTree = comTree->GetTree(targetDir(0,i+1));
|
||||
if( comTree == NULL )
|
||||
{ return NULL; }
|
||||
idx = i+1;
|
||||
}
|
||||
return comTree;
|
||||
}
|
||||
|
||||
void G4UImanager::Interact()
|
||||
{
|
||||
Interact(G4String("G4> "));
|
||||
}
|
||||
|
||||
void G4UImanager::Interact(char * pC)
|
||||
{
|
||||
G4String cc = pC;
|
||||
Interact(cc);
|
||||
}
|
||||
|
||||
void G4UImanager::Interact(G4String pC)
|
||||
{
|
||||
G4cerr << "G4UImanager::Interact() is out of date and is not used anymore." << endl;
|
||||
G4cerr << "This method will be removed shortly!!!" << endl;
|
||||
G4cerr << "In case of main() use" << endl;
|
||||
G4cerr << " G4UIsession * session = new G4UIterminal;" << endl;
|
||||
G4cerr << " session->SessionStart();" << endl;
|
||||
G4cerr << "In other cases use" << endl;
|
||||
G4cerr << " G4StateManager::GetStateManager()->Pause();" << endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void G4UImanager::SetCoutDestination(G4UIsession *const value)
|
||||
{
|
||||
#ifdef G4STREAM
|
||||
G4coutbuf.SetDestination(value);
|
||||
G4cerrbuf.SetDestination(value);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the RD44 GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: G4UImessenger.cc,v 2.2 1998/07/13 17:13:04 urbi Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
|
||||
#include "G4UImessenger.hh"
|
||||
#include "G4UImanager.hh"
|
||||
#include "G4UIcommand.hh"
|
||||
#include <string.h>
|
||||
#include "G4ios.hh"
|
||||
|
||||
#ifdef WIN32
|
||||
# include <Strstrea.h>
|
||||
#else
|
||||
# include <strstream.h>
|
||||
#endif
|
||||
|
||||
|
||||
G4UImessenger::G4UImessenger() { }
|
||||
|
||||
G4UImessenger::~G4UImessenger() { }
|
||||
|
||||
G4String G4UImessenger::GetCurrentValue(G4UIcommand * command)
|
||||
{
|
||||
G4String nullString;
|
||||
return nullString;
|
||||
}
|
||||
|
||||
void G4UImessenger::SetNewValue(G4UIcommand * command,G4String newValue)
|
||||
{ ; }
|
||||
|
||||
G4bool G4UImessenger::operator == (const G4UImessenger& messenger) const {
|
||||
return this == &messenger;
|
||||
}
|
||||
|
||||
G4String G4UImessenger::ItoS(G4int i)
|
||||
{
|
||||
char defVal[20];
|
||||
ostrstream os(defVal,20);
|
||||
os << i << '\0';
|
||||
return G4String(defVal);
|
||||
}
|
||||
|
||||
G4String G4UImessenger::DtoS(G4double a)
|
||||
{
|
||||
char defVal[40];
|
||||
ostrstream os(defVal,40);
|
||||
os << a << '\0';
|
||||
return G4String(defVal);
|
||||
}
|
||||
|
||||
G4String G4UImessenger::BtoS(G4bool b)
|
||||
{
|
||||
G4String vl = "0";
|
||||
if(b) vl = "true";
|
||||
return vl;
|
||||
}
|
||||
|
||||
G4int G4UImessenger::StoI(G4String s)
|
||||
{
|
||||
G4int vl;
|
||||
const char* t = s;
|
||||
istrstream is((char*)t);
|
||||
is >> vl;
|
||||
return vl;
|
||||
}
|
||||
|
||||
G4double G4UImessenger::StoD(G4String s)
|
||||
{
|
||||
G4double vl;
|
||||
const char* t = s;
|
||||
istrstream is((char*)t);
|
||||
is >> vl;
|
||||
return vl;
|
||||
}
|
||||
|
||||
G4bool G4UImessenger::StoB(G4String s)
|
||||
{
|
||||
G4String v = s;
|
||||
v.toUpper();
|
||||
G4bool vl = false;
|
||||
if( v=="Y" || v=="YES" || v=="1" || v=="T" || v=="TRUE" )
|
||||
{ vl = true; }
|
||||
return vl;
|
||||
}
|
||||
|
||||
|
||||
void G4UImessenger::AddUIcommand(G4UIcommand * newCommand)
|
||||
{
|
||||
G4cerr << "Warning : Old style definition of G4UIcommand <"
|
||||
<< newCommand->GetCommandPath() << ">." << endl;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,735 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the RD44 GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: G4UIparameter.cc,v 2.5 1998/11/13 11:36:39 asaim Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
|
||||
#include "G4UIparameter.hh"
|
||||
#include "G4UIcommandStatus.hh"
|
||||
|
||||
#include <rw/ctoken.h>
|
||||
|
||||
#include "G4ios.hh"
|
||||
G4UIparameter::G4UIparameter():paramERR(0)
|
||||
{
|
||||
G4String nullString;
|
||||
parameterName = nullString;
|
||||
parameterType = '\0';
|
||||
omittable = false;
|
||||
parameterGuidance = nullString;
|
||||
defaultValue = nullString;
|
||||
parameterRange = nullString;
|
||||
currentAsDefaultFlag = false;
|
||||
parameterCandidate = nullString;
|
||||
widget = 0;
|
||||
}
|
||||
|
||||
G4UIparameter::G4UIparameter(char theType):paramERR(0)
|
||||
{
|
||||
G4String nullString;
|
||||
parameterName = nullString;
|
||||
parameterType = theType;
|
||||
omittable = false;
|
||||
parameterGuidance = nullString;
|
||||
defaultValue = nullString;
|
||||
parameterRange = nullString;
|
||||
currentAsDefaultFlag = false;
|
||||
parameterCandidate = nullString;
|
||||
widget = 0;
|
||||
}
|
||||
|
||||
G4UIparameter::G4UIparameter(const char * theName, char theType, G4bool theOmittable):paramERR(0)
|
||||
{
|
||||
parameterName = theName;
|
||||
parameterType = theType;
|
||||
omittable = theOmittable;
|
||||
G4String nullString;
|
||||
parameterGuidance = nullString;
|
||||
defaultValue = nullString;
|
||||
parameterRange = nullString;
|
||||
currentAsDefaultFlag = false;
|
||||
parameterCandidate = nullString;
|
||||
widget = 0;
|
||||
}
|
||||
|
||||
G4UIparameter::~G4UIparameter()
|
||||
{ }
|
||||
|
||||
int G4UIparameter::operator==(const G4UIparameter &right) const
|
||||
{
|
||||
return ( this == &right );
|
||||
}
|
||||
|
||||
int G4UIparameter::operator!=(const G4UIparameter &right) const
|
||||
{
|
||||
return ( this != &right );
|
||||
}
|
||||
|
||||
void G4UIparameter::List()
|
||||
{
|
||||
G4cout << endl << "Parameter : " << parameterName << endl;
|
||||
if( ! parameterGuidance.isNull() )
|
||||
G4cout << parameterGuidance << endl ;
|
||||
G4cout << " Parameter type : " << parameterType << endl;
|
||||
if(omittable)
|
||||
{ G4cout << " Omittable : True" << endl; }
|
||||
else
|
||||
{ G4cout << " Omittable : False" << endl; }
|
||||
if( currentAsDefaultFlag )
|
||||
{ G4cout << " Default value : taken from the current value" << endl; }
|
||||
else if( ! defaultValue.isNull() )
|
||||
{ G4cout << " Default value : " << defaultValue << endl; }
|
||||
if( ! parameterRange.isNull() )
|
||||
G4cout << " Parameter range : " << parameterRange << endl;
|
||||
if( ! parameterCandidate.isNull() )
|
||||
G4cout << " Candidates : " << parameterCandidate << endl;
|
||||
}
|
||||
|
||||
void G4UIparameter::SetDefaultValue(G4int theDefaultValue)
|
||||
{
|
||||
char defVal[20];
|
||||
ostrstream os(defVal,20);
|
||||
os << theDefaultValue << '\0';
|
||||
defaultValue = defVal;
|
||||
}
|
||||
|
||||
void G4UIparameter::SetDefaultValue(G4double theDefaultValue)
|
||||
{
|
||||
char defVal[20];
|
||||
ostrstream os(defVal,20);
|
||||
os << theDefaultValue << '\0';
|
||||
defaultValue = defVal;
|
||||
}
|
||||
|
||||
|
||||
// ---------- CheckNewValue() related routines -----------
|
||||
#include <ctype.h>
|
||||
#include "G4UItokenNum.hh"
|
||||
|
||||
//#include "checkNewValue_debug.icc"
|
||||
//#define DEBUG 1
|
||||
|
||||
int G4UIparameter::
|
||||
CheckNewValue( G4String newValue ) {
|
||||
if( TypeCheck(newValue) == 0) return fParameterUnreadable;
|
||||
if( ! parameterRange.isNull() )
|
||||
{ if( RangeCheck(newValue) == 0 ) return fParameterOutOfRange; }
|
||||
if( ! parameterCandidate.isNull() )
|
||||
{ if( CandidateCheck(newValue) == 0 ) return fParameterOutOfCandidates; }
|
||||
return 0; // succeeded
|
||||
}
|
||||
|
||||
int G4UIparameter::
|
||||
CandidateCheck(G4String newValue) {
|
||||
RWCTokenizer candidateTokenizer(parameterCandidate);
|
||||
G4String aToken;
|
||||
int iToken = 0;
|
||||
while( ! (aToken=candidateTokenizer()).isNull() )
|
||||
{
|
||||
iToken++;
|
||||
if(aToken==newValue) return iToken;
|
||||
}
|
||||
G4cerr << "parameter value is not listed in the candidate List." << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int G4UIparameter::
|
||||
RangeCheck(G4String newValue) {
|
||||
yystype result;
|
||||
bp = 0; // reset buffer pointer for G4UIpGetc()
|
||||
const char* t = newValue;
|
||||
istrstream is((char*)t);
|
||||
char type = toupper( parameterType );
|
||||
switch (type) {
|
||||
case 'D': { is >> newVal.D; } break;
|
||||
case 'I': { is >> newVal.I; } break;
|
||||
default: ;
|
||||
}
|
||||
// PrintToken(); // Print tokens (consumes all tokens)
|
||||
token= Yylex();
|
||||
result = Expression();
|
||||
if( paramERR == 1 ) return 0;
|
||||
if( result.type != CONSTINT) {
|
||||
G4cerr << "Illegal Expression in parameter range." << endl;
|
||||
return 0;
|
||||
}
|
||||
if ( result.I ) return 1;
|
||||
G4cerr << "parameter out of range: "<< parameterRange << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int G4UIparameter::
|
||||
TypeCheck(G4String newValue)
|
||||
{
|
||||
char type = toupper( parameterType );
|
||||
switch(type) {
|
||||
case 'D':
|
||||
if( IsDouble(newValue.data())== 0) {
|
||||
G4cerr<<newValue<<": double value expected."
|
||||
<< endl;
|
||||
return 0;
|
||||
} break;
|
||||
case 'I':
|
||||
if( IsInt(newValue.data(),20)== 0) {
|
||||
G4cerr<<newValue<<": integer expected."
|
||||
<< endl;
|
||||
return 0;
|
||||
} break;
|
||||
case 'S': break;
|
||||
case 'B':
|
||||
newValue.toUpper();
|
||||
if ( newValue == "Y" || newValue == "N"
|
||||
||newValue == "YES" || newValue == "NO"
|
||||
||newValue == "1" || newValue == "0"
|
||||
||newValue == "T" || newValue == "F"
|
||||
||newValue == "TRUE" || newValue == "FALSE")
|
||||
return 1;
|
||||
else {
|
||||
G4cerr<<newValue<<": bool expected." << endl;
|
||||
return 0;
|
||||
}
|
||||
default: ;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int G4UIparameter::
|
||||
IsInt(const char* buf, short maxDigits) // do not allow any ws
|
||||
{
|
||||
const char* p= buf;
|
||||
int length=0;
|
||||
if( *p == '+' || *p == '-') { ++p; }
|
||||
if( isdigit( (int)(*p) )) {
|
||||
while( isdigit( (int)(*p) )) { ++p; ++length; }
|
||||
if( *p == '\0' ) {
|
||||
if( length > maxDigits) {
|
||||
G4cerr <<"digit length exceeds"<<endl;
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
} else {
|
||||
// G4cerr <<"illegal character after int:"<<buf<<endl;
|
||||
}
|
||||
} else {
|
||||
// G4cerr <<"illegal int:"<<buf<<endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int G4UIparameter::
|
||||
ExpectExponent(const char* str) // used only by IsDouble()
|
||||
{
|
||||
int maxExplength;
|
||||
if( IsInt( str, maxExplength=7 )) return 1;
|
||||
else return 0;
|
||||
}
|
||||
|
||||
int G4UIparameter::
|
||||
IsDouble(const char* buf) // see state diagram for this spec.
|
||||
{
|
||||
const char* p= buf;
|
||||
switch( *p) {
|
||||
case '+': case '-': ++p;
|
||||
if( isdigit(*p) ) {
|
||||
while( isdigit( (int)(*p) )) { ++p; }
|
||||
switch ( *p ) {
|
||||
case '\0': return 1; //break;
|
||||
case 'E': case 'e':
|
||||
return ExpectExponent(++p ); //break;
|
||||
case '.': ++p;
|
||||
if( *p == '\0' ) return 1;
|
||||
if( *p == 'e' || *p =='E' ) return ExpectExponent(++p );
|
||||
if( isdigit(*p) ) {
|
||||
while( isdigit( (int)(*p) )) { ++p; }
|
||||
if( *p == '\0' ) return 1;
|
||||
if( *p == 'e' || *p =='E') return ExpectExponent(++p);
|
||||
} else return 0; break;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
if( *p == '.' ) { ++p;
|
||||
if( isdigit(*p) ) {
|
||||
while( isdigit( (int)(*p) )) { ++p; }
|
||||
if( *p == '\0' ) return 1;
|
||||
if( *p == 'e' || *p =='E') return ExpectExponent(++p);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '.': ++p;
|
||||
if( isdigit(*p) ) {
|
||||
while( isdigit( (int)(*p) )) { ++p; }
|
||||
if( *p == '\0' ) return 1;
|
||||
if( *p == 'e' || *p =='E' ) return ExpectExponent(++p);
|
||||
} break;
|
||||
default: // digit is expected
|
||||
if( isdigit(*p) ) {
|
||||
while( isdigit( (int)(*p) )) { ++p; }
|
||||
if( *p == '\0' ) return 1;
|
||||
if( *p == 'e' || *p =='E') return ExpectExponent(++p);
|
||||
if( *p == '.' ) { ++p;
|
||||
if( *p == '\0' ) return 1;
|
||||
if( *p == 'e' || *p =='E') return ExpectExponent(++p);
|
||||
if( isdigit(*p) ) {
|
||||
while( isdigit( (int)(*p) )) { ++p; }
|
||||
if( *p == '\0' ) return 1;
|
||||
if( *p == 'e' || *p =='E') return ExpectExponent(++p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// ------------------ syntax node functions ------------------
|
||||
|
||||
yystype G4UIparameter::
|
||||
Expression(void)
|
||||
{
|
||||
yystype result;
|
||||
#ifdef DEBUG
|
||||
G4cerr << " Expression()" << endl;
|
||||
#endif
|
||||
result = LogicalORExpression();
|
||||
return result;
|
||||
}
|
||||
|
||||
yystype G4UIparameter::
|
||||
LogicalORExpression(void)
|
||||
{
|
||||
yystype result;
|
||||
yystype p;
|
||||
p = LogicalANDExpression();
|
||||
if( token != LOGICALOR) return p;
|
||||
if( p.type == CONSTSTRING || p.type == IDENTIFIER ) {
|
||||
G4cerr << "Parameter range: illegal type at '||'" << endl;
|
||||
paramERR = 1;
|
||||
}
|
||||
result.I = p.I;
|
||||
while (token == LOGICALOR)
|
||||
{
|
||||
token = Yylex();
|
||||
p = LogicalANDExpression();
|
||||
if( p.type == CONSTSTRING || p.type == IDENTIFIER ) {
|
||||
G4cerr << "Parameter range: illegal type at '||'" <<endl;
|
||||
paramERR = 1;
|
||||
}
|
||||
switch (p.type) {
|
||||
case CONSTINT:
|
||||
result.I += p.I;
|
||||
result.type = CONSTINT; break;
|
||||
case CONSTDOUBLE:
|
||||
result.I += (p.D != 0.0);
|
||||
result.type = CONSTINT; break;
|
||||
default:
|
||||
G4cerr << "Parameter range: unknown type"<<endl;
|
||||
paramERR = 1;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
yystype G4UIparameter::
|
||||
LogicalANDExpression(void)
|
||||
{
|
||||
yystype result;
|
||||
yystype p;
|
||||
p = EqualityExpression();
|
||||
if( token != LOGICALAND) return p;
|
||||
if( p.type == CONSTSTRING || p.type == IDENTIFIER ) {
|
||||
G4cerr << "Parameter range: illegal type at '&&'" << endl;
|
||||
paramERR = 1;
|
||||
}
|
||||
result.I = p.I;
|
||||
while (token == LOGICALAND)
|
||||
{
|
||||
token = Yylex();
|
||||
p = EqualityExpression();
|
||||
if( p.type == CONSTSTRING || p.type == IDENTIFIER ) {
|
||||
G4cerr << "Parameter range: illegal type at '&&'" << endl;
|
||||
paramERR = 1;
|
||||
}
|
||||
switch (p.type) {
|
||||
case CONSTINT:
|
||||
result.I *= p.I;
|
||||
result.type = CONSTINT; break;
|
||||
case CONSTDOUBLE:
|
||||
result.I *= (p.D != 0.0);
|
||||
result.type = CONSTINT; break;
|
||||
default:
|
||||
G4cerr << "Parameter range: unknown type."<< endl;
|
||||
paramERR = 1;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
yystype G4UIparameter::
|
||||
EqualityExpression(void)
|
||||
{
|
||||
yystype arg1, arg2;
|
||||
int operat;
|
||||
yystype result;
|
||||
#ifdef DEBUG
|
||||
G4cerr << " EqualityExpression()" <<endl;
|
||||
#endif
|
||||
result = RelationalExpression();
|
||||
if( token==EQ || token==NE ) {
|
||||
operat = token;
|
||||
token = Yylex();
|
||||
arg1 = result;
|
||||
arg2 = RelationalExpression();
|
||||
result.I = Eval2( arg1, operat, arg2 ); // semantic action
|
||||
result.type = CONSTINT;
|
||||
#ifdef DEBUG
|
||||
G4cerr << " return code of Eval2(): " << result.I <<endl;
|
||||
#endif
|
||||
} else {
|
||||
if (result.type != CONSTINT && result.type != CONSTDOUBLE) {
|
||||
G4cerr << "Parameter range: error at EqualityExpression"
|
||||
<< endl;
|
||||
paramERR = 1;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
yystype G4UIparameter::
|
||||
RelationalExpression(void)
|
||||
{
|
||||
yystype arg1, arg2;
|
||||
int operat;
|
||||
yystype result;
|
||||
#ifdef DEBUG
|
||||
G4cerr << " RelationalExpression()" <<endl;
|
||||
#endif
|
||||
|
||||
arg1 = AdditiveExpression();
|
||||
if( token==GT || token==GE || token==LT || token==LE ) {
|
||||
operat = token;
|
||||
token = Yylex();
|
||||
arg2 = AdditiveExpression();
|
||||
result.I = Eval2( arg1, operat, arg2 ); // semantic action
|
||||
result.type = CONSTINT;
|
||||
#ifdef DEBUG
|
||||
G4cerr << " return Eval2(): " << endl;
|
||||
#endif
|
||||
} else {
|
||||
result = arg1;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
G4cerr <<" return RelationalExpression()" <<endl;
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
yystype G4UIparameter::
|
||||
AdditiveExpression(void)
|
||||
{ yystype result;
|
||||
result = MultiplicativeExpression();
|
||||
if( token != '+' && token != '-' ) return result;
|
||||
G4cerr << "Parameter range: operator "
|
||||
<< (char)token
|
||||
<< " is not supported." << endl;
|
||||
paramERR = 1;
|
||||
return result;
|
||||
}
|
||||
|
||||
yystype G4UIparameter::
|
||||
MultiplicativeExpression(void)
|
||||
{ yystype result;
|
||||
result = UnaryExpression();
|
||||
if( token != '*' && token != '/' && token != '%' ) return result;
|
||||
G4cerr << "Parameter range: operator "
|
||||
<< (char)token
|
||||
<< " is not supported." << endl;
|
||||
paramERR = 1;
|
||||
return result;
|
||||
}
|
||||
|
||||
yystype G4UIparameter::
|
||||
UnaryExpression(void)
|
||||
{
|
||||
yystype result;
|
||||
yystype p;
|
||||
#ifdef DEBUG
|
||||
G4cerr <<" UnaryExpression"<< endl;
|
||||
#endif
|
||||
switch(token) {
|
||||
case '-':
|
||||
token = Yylex();
|
||||
p = UnaryExpression();
|
||||
if (p.type == CONSTINT) {
|
||||
result.I = - p.I;
|
||||
result.type = CONSTINT;
|
||||
}
|
||||
if (p.type == CONSTDOUBLE) {
|
||||
result.D = - p.D;
|
||||
result.type = CONSTDOUBLE;
|
||||
} break;
|
||||
case '+':
|
||||
token = Yylex();
|
||||
result = UnaryExpression(); break;
|
||||
case '!':
|
||||
token = Yylex();
|
||||
G4cerr << "Parameter range error: "
|
||||
<< "operator '!' is not supported (sorry)."
|
||||
<< endl;
|
||||
paramERR = 1;
|
||||
result = UnaryExpression(); break;
|
||||
default:
|
||||
result = PrimaryExpression();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
yystype G4UIparameter::
|
||||
PrimaryExpression(void)
|
||||
{
|
||||
yystype result;
|
||||
#ifdef DEBUG
|
||||
G4cerr <<" PrimaryExpression" << endl;
|
||||
#endif
|
||||
switch (token) {
|
||||
case IDENTIFIER:
|
||||
result.S = yylval.S;
|
||||
result.type = token;
|
||||
token = Yylex(); break;
|
||||
case CONSTINT:
|
||||
result.I = yylval.I;
|
||||
result.type = token;
|
||||
token= Yylex(); break;
|
||||
case CONSTDOUBLE:
|
||||
result.D = yylval.D;
|
||||
result.type = token;
|
||||
token = Yylex(); break;
|
||||
case '(' :
|
||||
token= Yylex();
|
||||
result = Expression();
|
||||
if( token != ')' ) {
|
||||
G4cerr << " ')' expected" << endl;
|
||||
paramERR = 1;
|
||||
}
|
||||
token = Yylex();
|
||||
break;
|
||||
default:
|
||||
return result;
|
||||
}
|
||||
return result; // never executed
|
||||
}
|
||||
|
||||
//---------------- semantic routines ---------------------------------
|
||||
|
||||
int G4UIparameter::
|
||||
Eval2(yystype arg1, int op, yystype arg2)
|
||||
{
|
||||
if( (arg1.type != IDENTIFIER) && (arg2.type != IDENTIFIER)) {
|
||||
G4cerr << parameterName
|
||||
<< ": meaningless comparison "
|
||||
<< arg1.type << " " << arg2.type << endl;
|
||||
paramERR = 1;
|
||||
}
|
||||
char type = toupper( parameterType );
|
||||
if( arg1.type == IDENTIFIER) {
|
||||
switch (type) {
|
||||
case 'I':
|
||||
if ( arg2.type == CONSTINT ) {
|
||||
return CompareInt( newVal.I, op, arg2.I );
|
||||
} else {
|
||||
G4cerr << "integer operand expected for "
|
||||
<< parameterRange << '.'
|
||||
<< endl;
|
||||
}
|
||||
break;
|
||||
case 'D':
|
||||
if ( arg2.type == CONSTDOUBLE ) {
|
||||
return CompareDouble( newVal.D, op, arg2.D );
|
||||
} else
|
||||
if ( arg2.type == CONSTINT ) { // integral promotion
|
||||
return CompareDouble( newVal.D, op, arg2.I );
|
||||
} break;
|
||||
default: ;
|
||||
}
|
||||
}
|
||||
if( arg2.type == IDENTIFIER) {
|
||||
switch (type) {
|
||||
case 'I':
|
||||
if ( arg1.type == CONSTINT ) {
|
||||
return CompareInt( arg1.I, op, newVal.I );
|
||||
} else {
|
||||
G4cerr << "integer operand expected for "
|
||||
<< parameterRange << '.'
|
||||
<< endl;
|
||||
}
|
||||
break;
|
||||
case 'D':
|
||||
if ( arg1.type == CONSTDOUBLE ) {
|
||||
return CompareDouble( arg1.D, op, newVal.D );
|
||||
} else
|
||||
if ( arg1.type == CONSTINT ) { // integral promotion
|
||||
return CompareDouble( arg1.I, op, newVal.D );
|
||||
} break;
|
||||
default: ;
|
||||
}
|
||||
}
|
||||
G4cerr << "no param name is specified at the param range."<<endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int G4UIparameter::
|
||||
CompareInt(int arg1, int op, int arg2)
|
||||
{
|
||||
int result;
|
||||
G4String opr;
|
||||
switch (op) {
|
||||
case GT: result = ( arg1 > arg2); opr= ">" ; break;
|
||||
case GE: result = ( arg1 >= arg2); opr= ">="; break;
|
||||
case LT: result = ( arg1 < arg2); opr= "<" ; break;
|
||||
case LE: result = ( arg1 <= arg2); opr= "<="; break;
|
||||
case EQ: result = ( arg1 == arg2); opr= "=="; break;
|
||||
case NE: result = ( arg1 != arg2); opr= "!="; break;
|
||||
default:
|
||||
G4cerr << "Parameter range: error at CompareInt" << endl;
|
||||
paramERR = 1;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
G4cerr << "CompareInt "
|
||||
<< arg1 << " " << opr << arg2
|
||||
<< " result: " << result
|
||||
<< endl;
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
int G4UIparameter::
|
||||
CompareDouble(double arg1, int op, double arg2)
|
||||
{
|
||||
int result;
|
||||
G4String opr;
|
||||
switch (op) {
|
||||
case GT: result = ( arg1 > arg2); opr= ">"; break;
|
||||
case GE: result = ( arg1 >= arg2); opr= ">="; break;
|
||||
case LT: result = ( arg1 < arg2); opr= "<"; break;
|
||||
case LE: result = ( arg1 <= arg2); opr= "<="; break;
|
||||
case EQ: result = ( arg1 == arg2); opr= "=="; break;
|
||||
case NE: result = ( arg1 != arg2); opr= "!="; break;
|
||||
default:
|
||||
G4cerr << "Parameter range: error at CompareDouble" << endl;
|
||||
paramERR = 1;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
G4cerr << "CompareDouble "
|
||||
<< arg1 <<" " << opr << " "<< arg2
|
||||
<< " result: " << result
|
||||
<< endl;
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
// --------------------- utility functions --------------------------
|
||||
|
||||
tokenNum G4UIparameter::
|
||||
Yylex() // reads input and returns token number KR486
|
||||
{ // (returns EOF)
|
||||
int c;
|
||||
G4String buf;
|
||||
|
||||
while(( c= G4UIpGetc())==' '|| c=='\t' || c== '\n' )
|
||||
;
|
||||
if (c== EOF)
|
||||
return (tokenNum)EOF; // KR488
|
||||
buf= "";
|
||||
if (isdigit(c) || c== '.') { // I or D
|
||||
do {
|
||||
buf += G4String((unsigned char)c);
|
||||
c=G4UIpGetc();
|
||||
} while (c=='.' || isdigit(c) ||
|
||||
c=='e' || c=='E' || c=='+' || c=='-');
|
||||
G4UIpUngetc(c);
|
||||
const char* t = buf;
|
||||
istrstream is((char*)t);
|
||||
if ( IsInt(buf.data(),20) ) {
|
||||
is >> yylval.I;
|
||||
return CONSTINT;
|
||||
} else
|
||||
if ( IsDouble(buf.data()) ) {
|
||||
is >> yylval.D;
|
||||
return CONSTDOUBLE;
|
||||
} else {
|
||||
G4cerr << buf<<": numeric format error."<<endl;
|
||||
}
|
||||
}
|
||||
buf="";
|
||||
if (isalpha(c)|| c=='_') { // IDENTIFIER
|
||||
do {
|
||||
buf += G4String((unsigned char)c);
|
||||
} while ((c=G4UIpGetc()) != EOF && (isalnum(c) || c=='_'));
|
||||
G4UIpUngetc(c);
|
||||
if( buf == parameterName ) {
|
||||
yylval.S =buf;
|
||||
return IDENTIFIER;
|
||||
} else {
|
||||
G4cerr << buf << " is not a parameter name."<< endl;
|
||||
paramERR = 1;
|
||||
}
|
||||
}
|
||||
switch (c) {
|
||||
case '>': return (tokenNum) Follow('=', GE, GT);
|
||||
case '<': return (tokenNum) Follow('=', LE, LT);
|
||||
case '=': return (tokenNum) Follow('=', EQ, '=');
|
||||
case '!': return (tokenNum) Follow('=', NE, '!');
|
||||
case '|': return (tokenNum) Follow('|', LOGICALOR, '|');
|
||||
case '&': return (tokenNum) Follow('&', LOGICALAND, '&');
|
||||
default:
|
||||
return (tokenNum) c;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int G4UIparameter::
|
||||
Follow(int expect, int ifyes, int ifno)
|
||||
{
|
||||
int c = G4UIpGetc();
|
||||
if ( c== expect)
|
||||
return ifyes;
|
||||
G4UIpUngetc(c);
|
||||
return ifno;
|
||||
}
|
||||
|
||||
//------------------ low level routines -----------------------------
|
||||
int G4UIparameter::
|
||||
G4UIpGetc() { // emulation of getc()
|
||||
int length = parameterRange.length();
|
||||
if( bp < length)
|
||||
return parameterRange(bp++);
|
||||
else
|
||||
return EOF;
|
||||
}
|
||||
int G4UIparameter::
|
||||
G4UIpUngetc(int c) { // emulation of ungetc()
|
||||
if (c<0) return -1;
|
||||
if (bp >0 && c == parameterRange(bp-1)) {
|
||||
--bp;
|
||||
} else {
|
||||
G4cerr << "G4UIpUngetc() failed." << endl;
|
||||
G4cerr << "bp="<<bp <<" c="<<c
|
||||
<< " pR(bp-1)=" << parameterRange(bp-1)
|
||||
<< endl;
|
||||
paramERR = 1;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
// ***** end of CheckNewValue() related code ******
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the RD44 GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: G4UIsession.cc,v 2.2 1998/10/13 05:36:06 masayasu Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
//
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
#include "G4UIsession.hh"
|
||||
|
||||
G4UIsession::G4UIsession() {;}
|
||||
|
||||
G4UIsession::~G4UIsession() {;}
|
||||
|
||||
G4UIsession * G4UIsession::SessionStart() { return NULL; }
|
||||
|
||||
void G4UIsession::PauseSessionStart(G4String Prompt) {;}
|
||||
|
||||
G4int G4UIsession::ReceiveG4cout(G4String coutString)
|
||||
{
|
||||
cout << coutString << flush;
|
||||
return 0;
|
||||
}
|
||||
|
||||
G4int G4UIsession::ReceiveG4cerr(G4String cerrString)
|
||||
{
|
||||
cerr << cerrString << flush;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the RD44 GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: G4UnitsMessenger.cc,v 2.1 1998/11/27 06:12:55 asaim Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
//
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
||||
|
||||
#include "G4UnitsMessenger.hh"
|
||||
|
||||
#include "G4UnitsTable.hh"
|
||||
#include "G4UIdirectory.hh"
|
||||
#include "G4UIcmdWithoutParameter.hh"
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
||||
|
||||
G4UnitsMessenger::G4UnitsMessenger()
|
||||
{
|
||||
UnitsTableDir = new G4UIdirectory("/units/");
|
||||
UnitsTableDir->SetGuidance("Available units.");
|
||||
|
||||
ListCmd = new G4UIcmdWithoutParameter("/units/list",this);
|
||||
ListCmd->SetGuidance("full list of available units.");
|
||||
ListCmd->AvailableForStates(Idle);
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
||||
|
||||
G4UnitsMessenger::~G4UnitsMessenger()
|
||||
{
|
||||
delete ListCmd;
|
||||
delete UnitsTableDir;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
||||
|
||||
void G4UnitsMessenger::SetNewValue(G4UIcommand* command,G4String newValue)
|
||||
{
|
||||
if (command == ListCmd)
|
||||
{ G4UnitDefinition::PrintUnitsTable(); }
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
||||
@@ -0,0 +1,55 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the RD44 GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: G4VStateDependent.cc,v 2.2 1998/09/25 13:09:24 asaim Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
//
|
||||
// ------------------------------------------------------------
|
||||
// GEANT 4 class implementation file
|
||||
//
|
||||
// For information related to this code contact:
|
||||
// CERN, CN Division, ASD group
|
||||
// ---------------- G4VStateDependent ----------------
|
||||
// by Gabriele Cosmo, November 1996
|
||||
// ------------------------------------------------------------
|
||||
|
||||
#include "G4VStateDependent.hh"
|
||||
#include "G4StateManager.hh"
|
||||
|
||||
G4VStateDependent::G4VStateDependent()
|
||||
{
|
||||
G4StateManager * stateManager = G4StateManager::GetStateManager();
|
||||
stateManager->RegisterDependent(this);
|
||||
}
|
||||
|
||||
G4VStateDependent::~G4VStateDependent()
|
||||
{
|
||||
G4StateManager * stateManager = G4StateManager::GetStateManager();
|
||||
stateManager->DeregisterDependent(this);
|
||||
}
|
||||
|
||||
G4VStateDependent::G4VStateDependent(const G4VStateDependent &right)
|
||||
{
|
||||
*this = right;
|
||||
}
|
||||
|
||||
G4VStateDependent& G4VStateDependent::operator=(const G4VStateDependent &right)
|
||||
{
|
||||
*this = right;
|
||||
return *this;
|
||||
}
|
||||
|
||||
G4int G4VStateDependent::operator==(const G4VStateDependent &right) const
|
||||
{
|
||||
return (this == (G4VStateDependent *) &right);
|
||||
}
|
||||
|
||||
G4int G4VStateDependent::operator!=(const G4VStateDependent &right) const
|
||||
{
|
||||
return (this != (G4VStateDependent *) &right);
|
||||
}
|
||||
Reference in New Issue
Block a user