Import Geant4 0.0.0 source tree

This commit is contained in:
Gabriele Cosmo
2016-06-01 15:25:35 +02:00
parent 54d6b71f95
commit b97f8d0df7
3237 changed files with 807095 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
# $Id: GNUmakefile,v 2.1 1998/08/22 01:33:14 gcosmo Exp $
# -------------------------------------------------------------
# GNUmakefile for intercoms library. Gabriele Cosmo, 11/11/96.
# -------------------------------------------------------------
name := G4intercoms
ifndef G4INSTALL
G4INSTALL = ../..
endif
include $(G4INSTALL)/config/architecture.gmk
CPPFLAGS += -I$(G4BASE)/global/management/include \
-I$(G4BASE)/global/HEPRandom/include \
-I$(G4BASE)/global/HEPGeometry/include
include $(G4INSTALL)/config/common.gmk
.PHONY: global
global: lib
+124
View File
@@ -0,0 +1,124 @@
$Id: History,v 2.16 1998/12/03 15:42:29 stesting Exp $
-------------------------------------------------------------------
=========================================================
Geant4 - an Object-Oriented Toolkit for Simulation in HEP
=========================================================
Category History file
---------------------
This file should be used by G4 developers and category coordinators
to briefly summarize all major modifications introduced in the code
and keep track of all category-tags.
It DOES NOT substitute the CVS log-message one should put at every
committal in the CVS repository !
----------------------------------------------------------
* Reverse chronological order (last date on top), please *
----------------------------------------------------------
Dec 03, 98 J.Allison (tag intercoms-00-04-04)
- Protected G4UImanager::SetCoutDestination with #ifdef G4STREAM.
Dec 02, 98 M.Asai (tag intercoms-00-04-03)
- G4UnitsMessenger is constructed/destructed by G4UImanager.
Nov 27, 98 M.Asai (tag intercoms-00-04-02)
- G4UnitsMessenger has been inported from global/management to avoid a loop dependency.
Nov 25, 98 J.Allison (tag intercoms-00-04-01)
- Allowed quotation-mark-enclosed blank-embedded parameters in GetCurrentValue.
- "Cosmetic" change to G4UIparameter (M.Asai).
Nov 05, 98 M.Asai (tag intercoms-00-03-07)
- Move G4strstreambuf.hh to global category to avoid a loop dependency (M.Nagamatsu)
affected files are G4UImanager.hh G4UImanager.cc, G4UIsession.hh.
Oct 26, 98 M.Asai (tag intercoms-00-03-06)
- Add SetCoutDestination(NULL) to the constructor and destructor of G4UImanager.
Oct 20, 98 M.Asai (tag intercoms-00-03-05)
- Change static methods in G4UIcommand which are for unit conversion from protected
to public.
Oct 13, 98 M.Asai (tag intercoms-00-03-04)
- Interoducing a concrete implementation of G4cout/G4cerr (M.Nagamatsu).
affected files : include/G4UImanager.hh G4strstreambuf.hh
src/G4UImanager.cc G4UIsession.cc
Oct 01, 98 M.Asai (tag intercoms-00-03-03)
- Introducing a new UI command named "manual".
Sep 27, 98 M.Asai (tag intercoms-00-03-02)
- Fixes a bug in G4UIparameter. This bug caused a trouble of range
checking *only* for the parameter(s) atouched to the G4UIcommand
base class objects.
Sep 25, 98 M.Asai (tag intercoms-00-03-01)
- Minor modification in G4UIcommand.cc.
- "DeregisterDependent()" method is implemented in G4StateManager and
this method is invoked by the destructor of G4VStateDependent base class.
Aug 11, 98 M.Asai (tag intercoms-00-02-01)
- G4UIcommand.cc corresponds to "string with blanks".
July 15, 98 M.Asai (tag intercoms-00-01-03)
July 13, 98 M.Asai (tag intercoms-00-01-02)
- Bug in G4UIcommand.hh is fixed.
July 4, 98 <.Asai (tag intercoms-00-01-01)
- Ready for the beta release.
June 30, 98 M.Asai (tag intercoms-00-07-01)
- Debug G4UIdirectory.cc for protecting against missing "/" at the tail.
June 10, 98 M.Asai
- Introducing more methods in G4UIcommand, G4UIcmdWithADoubleAndUnit,
G4UIcmdWith3VectorAndUnit with the new G4UnitsTable
- Tagged as intercoms-00-06-02
June 8, 98 M.Asai
- Introducing new methods in G4UIcommand, G4UIcmdWithADoubleAndUnit,
G4UIcmdWith3VectorAndUnit with the new G4UnitsTable
- Tagged as intercoms-00-06-01
April 21, 98 M.Asai
- G5ApplicationState.hh, G4StateManager.h and .cc, G4VStateDependent.hh
and .cc are moved from "globals/management".
- Tagged as intercoms-00-05-03.
April 20, 98 M.Asai
- tagged intercoms-00-05-02.
April 9, 98 G.Cosmo
- Porting on DEC-cxx 6.0.
Removed meaningless usage of "const" qualifier from functions
return type for basic types by value. Modified files:
G4UIcommand.hh, G4UIcommandTree.hh, G4UIparameter.hh
April 6, 98 M.Nagamatu
- added getRange() to G4UIcommand.hh
March 27, 98 M.Asai
- remove redandant constructors/methods from
G4UIparameter, G4UIcommand, G4UIcmd***
- tagged intercoms-00-05-01
March 2, 98 S.Sadilov
- fix include <strstrea.h> in G4UIcommand.cc for WinNT
February 18, 98 John Allison
- made G4UIcommand::valueOf a static member function.
- tagged intercoms-00-04-01
February 3, 98 M.Asai - (intercoms-00-03-02)
- Debugged : G4UImanager.cc
- Tagged as intercoms-00-03-02
January 29, 98 M.Asai - (intercoms-00-03-01)
- Tagged as intercoms-00-03-01
December 19, 97 G. Cosmo - (alpha03)
- Created.
@@ -0,0 +1,66 @@
// 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: G4ApplicationState.hh,v 2.1 1998/07/12 02:59:26 urbi Exp $
// GEANT4 tag $Name: geant4-00 $
//
#ifndef G4APPLICATIONSTATE_H
#define G4APPLICATIONSTATE_H 1
// Specifies the state of the G4 application
//
// States:
// PreInit
// At the very begining of the Application. G4StateManager starts
// with this state. G4Initializer changes this state to Init when
// G4Initializer::Initialize() method starts. At the moment of
// the state change of PreInit->Init, no material, geometrical,
// particle or physics process has been initialized.
// Init
// During the G4Initializer::Initialize() method. G4Initializer
// changes this state to Idle when all initialization procedures
// are successfully Done.
// Idle
// Ready to start "BeamOn". G4RunManager changes this state to
// GeomClosed when G4RunManager::BeamOn() method starts and
// G4GeometryManager::CloseGeometry() is Done. At the end of
// BeamOn() method, G4RunManager will reset the application state
// to Idle after G4GeometryManager::OpenGeometry() is Done.
// GeomClosed
// G4 is in this state between G4GeometryManager::CloseGeometry()
// and G4GeometryManager::OpenGeometry(), but no event is in
// progress. At the begining of each event (construction of a
// G4Event object and primary particle generation), G4RunManager
// changes this state to EventProc and resets to GeomClosed state
// when G4EventManager::ProcessOneEvent() is over.
// EventProc
// Processing an event.
// Quit
// G4 is in this state when the destructor of G4RunManager is invoked.
//
//
// PreInit
// |
// v
// Init
// |
// v
// Idle ------> Quit
// |^
// v|
// GeomClosed (at each run)
// |^
// v|
// EventProc (at each event)
//
enum G4ApplicationState
{PreInit, Init, Idle, GeomClosed, EventProc, Quit};
#endif
@@ -0,0 +1,71 @@
// 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.hh,v 2.2 1998/09/25 13:09:16 asaim Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
// ------------------------------------------------------------
// GEANT 4 class header file
//
// For information related to this code contact:
// CERN, CN Division, ASD group
// ---------------- G4StateManager ----------------
// by Gabriele Cosmo, November 1996
// Class responsible for handling and updating the running state
// of the Geant4 application during its different phases.
// The class is a singleton, it can be accessed via the public
// method G4StateManager::GetStateManager().
// ------------------------------------------------------------
#ifndef G4StateManager_h
#define G4StateManager_h 1
#include <rw/tpordvec.h>
#include "globals.hh"
#include "G4ApplicationState.hh"
#include "G4VStateDependent.hh"
class G4StateManager {
public:
static G4StateManager* GetStateManager();
protected:
G4StateManager();
public:
~G4StateManager();
public:
G4ApplicationState GetCurrentState();
G4ApplicationState GetPreviousState();
G4bool SetNewState(G4ApplicationState requestedState);
G4bool RegisterDependent(G4VStateDependent* aDependent);
G4bool DeregisterDependent(G4VStateDependent* aDependent);
G4VStateDependent* RemoveDependent(const G4VStateDependent* aDependent);
G4String GetStateString(G4ApplicationState aState);
void Pause();
void Pause(char* msg);
void Pause(G4String msg);
private:
G4StateManager(const G4StateManager &right);
G4StateManager& operator=(const G4StateManager &right);
G4int operator==(const G4StateManager &right) const;
G4int operator!=(const G4StateManager &right) const;
private:
static G4StateManager* theStateManager;
G4ApplicationState theCurrentState;
G4ApplicationState thePreviousState;
RWTPtrOrderedVector<G4VStateDependent> theDependentsList;
};
#endif
+42
View File
@@ -0,0 +1,42 @@
// 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.hh,v 2.1 1998/07/12 02:59:27 urbi Exp $
// GEANT4 tag $Name: geant4-00 $
//
// $id$
#ifndef G4UIbatch_h
#define G4UIbatch_h 1
#include "globals.hh"
#include "G4UIsession.hh"
#include <fstream.h>
class G4UImanager;
class G4UIbatch : public G4UIsession
{
public:
G4UIbatch(G4String fileName,G4UIsession* prevSession=NULL);
~G4UIbatch();
G4UIsession * SessionStart();
void PauseSessionStart(G4String Prompt);
private:
G4UImanager * UImanager;
G4UIsession * previousSession;
ifstream macroFile;
G4String macroFileName;
G4bool openFailed;
};
#endif
@@ -0,0 +1,32 @@
// 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.hh,v 2.1 1998/07/12 02:59:27 urbi Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
#ifndef G4UIcmdWith3Vector_H
#define G4UIcmdWith3Vector_H 1
#include "G4UIcommand.hh"
#include "G4ThreeVector.hh"
class G4UIcmdWith3Vector : public G4UIcommand
{
public:
G4UIcmdWith3Vector
(const char * theCommandPath,G4UImessenger * theMessenger);
G4ThreeVector GetNew3VectorValue(G4String paramString);
G4String ConvertToString(G4ThreeVector vec);
void SetParameterName(const char * theNameX,const char * theNameY,
const char * theNameZ,G4bool omittable,G4bool currentAsDefault=false);
void SetDefaultValue(G4ThreeVector defVal);
};
#endif
@@ -0,0 +1,37 @@
// 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.hh,v 2.1 1998/07/12 02:59:28 urbi Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
#ifndef G4UIcmdWith3VectorAndUnit_H
#define G4UIcmdWith3VectorAndUnit_H 1
#include "G4UIcommand.hh"
#include "G4ThreeVector.hh"
class G4UIcmdWith3VectorAndUnit : public G4UIcommand
{
public:
G4UIcmdWith3VectorAndUnit
(const char * theCommandPath,G4UImessenger * theMessenger);
G4ThreeVector GetNew3VectorValue(G4String paramString);
G4ThreeVector GetNew3VectorRawValue(G4String paramString);
G4double GetNewUnitValue(G4String paramString);
G4String ConvertToString(G4ThreeVector vec,const char * unitName);
void SetParameterName(const char * theNameX,const char * theNameY,
const char * theNameZ,G4bool omittable,G4bool currentAsDefault=false);
void SetDefaultValue(G4ThreeVector defVal);
void SetUnitCategory(const char * unitCategory);
void SetUnitCandidates(const char * candidateList);
void SetDefaultUnit(const char * defUnit);
};
#endif
@@ -0,0 +1,31 @@
// 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.hh,v 2.1 1998/07/12 02:59:28 urbi Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
#ifndef G4UIcmdWithABool_H
#define G4UIcmdWithABool_H 1
#include "G4UIcommand.hh"
class G4UIcmdWithABool : public G4UIcommand
{
public:
G4UIcmdWithABool
(const char * theCommandPath,G4UImessenger * theMessenger);
G4bool GetNewBoolValue(G4String paramString);
G4String ConvertToString(G4bool intValue);
void SetParameterName(const char * theName,G4bool omittable,
G4bool currentAsDefault=false);
void SetDefaultValue(G4bool defVal);
};
#endif
@@ -0,0 +1,31 @@
// 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.hh,v 2.1 1998/07/12 02:59:30 urbi Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
#ifndef G4UIcmdWithADouble_H
#define G4UIcmdWithADouble_H 1
#include "G4UIcommand.hh"
class G4UIcmdWithADouble : public G4UIcommand
{
public:
G4UIcmdWithADouble
(const char * theCommandPath,G4UImessenger * theMessenger);
G4double GetNewDoubleValue(G4String paramString);
G4String ConvertToString(G4double dblValue);
void SetParameterName(const char * theName,G4bool omittable,
G4bool currentAsDefault=false);
void SetDefaultValue(G4double defVal);
};
#endif
@@ -0,0 +1,36 @@
// 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.hh,v 2.1 1998/07/12 02:59:30 urbi Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
#ifndef G4UIcmdWithADoubleAndUnit_H
#define G4UIcmdWithADoubleAndUnit_H 1
#include "G4UIcommand.hh"
class G4UIcmdWithADoubleAndUnit : public G4UIcommand
{
public:
G4UIcmdWithADoubleAndUnit
(const char * theCommandPath,G4UImessenger * theMessenger);
G4double GetNewDoubleValue(G4String paramString);
G4double GetNewDoubleRawValue(G4String paramString);
G4double GetNewUnitValue(G4String paramString);
G4String ConvertToString(G4double dblValue,const char * unitName);
void SetParameterName(const char * theName,G4bool omittable,
G4bool currentAsDefault=false);
void SetDefaultValue(G4double defVal);
void SetUnitCategory(const char * unitCategory);
void SetUnitCandidates(const char * candidateList);
void SetDefaultUnit(const char * defUnit);
};
#endif
@@ -0,0 +1,30 @@
// 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.hh,v 2.1 1998/07/12 02:59:31 urbi Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
#ifndef G4UIcmdWithAString_H
#define G4UIcmdWithAString_H 1
#include "G4UIcommand.hh"
class G4UIcmdWithAString : public G4UIcommand
{
public:
G4UIcmdWithAString
(const char * theCommandPath,G4UImessenger * theMessenger);
void SetParameterName(const char * theName,G4bool omittable,
G4bool currentAsDefault=false);
void SetCandidates(const char * candidateList);
void SetDefaultValue(const char * defVal);
};
#endif
@@ -0,0 +1,31 @@
// 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.hh,v 2.1 1998/07/12 02:59:31 urbi Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
#ifndef G4UIcmdWithAnInteger_H
#define G4UIcmdWithAnInteger_H 1
#include "G4UIcommand.hh"
class G4UIcmdWithAnInteger : public G4UIcommand
{
public:
G4UIcmdWithAnInteger
(const char * theCommandPath,G4UImessenger * theMessenger);
G4int GetNewIntValue(G4String paramString);
G4String ConvertToString(G4int intValue);
void SetParameterName(const char * theName,G4bool omittable,
G4bool currentAsDefault=false);
void SetDefaultValue(G4int defVal);
};
#endif
@@ -0,0 +1,25 @@
// 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.hh,v 2.0 1998/07/02 17:07:57 gunter Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
#ifndef G4UIcmdWithoutParameter_H
#define G4UIcmdWithoutParameter_H 1
#include "G4UIcommand.hh"
class G4UIcmdWithoutParameter : public G4UIcommand
{
public:
G4UIcmdWithoutParameter
(const char * theCommandPath,G4UImessenger * theMessenger);
};
#endif
+139
View File
@@ -0,0 +1,139 @@
// 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.hh,v 2.3 1998/10/20 03:41:30 asaim Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
#ifndef G4UIcommand_h
#define G4UIcommand_h 1
#include "G4UIparameter.hh"
class G4UImessenger;
#include "globals.hh"
#include "G4ApplicationState.hh"
#include <rw/tpordvec.h>
#include <rw/tvordvec.h>
#include "G4UItokenNum.hh"
class G4UIcommand
{
public:
G4UIcommand();
G4UIcommand(const char * theCommandPath, G4UImessenger * theMessenger);
virtual ~G4UIcommand();
int operator==(const G4UIcommand &right) const;
int operator!=(const G4UIcommand &right) const;
G4int DoIt(G4String parameterList);
G4String GetCurrentValue();
void AvailableForStates(G4ApplicationState s1);
void AvailableForStates(G4ApplicationState s1,G4ApplicationState s2);
void AvailableForStates(G4ApplicationState s1,G4ApplicationState s2,
G4ApplicationState s3);
void AvailableForStates(G4ApplicationState s1,G4ApplicationState s2,
G4ApplicationState s3,G4ApplicationState s4);
void AvailableForStates(G4ApplicationState s1,G4ApplicationState s2,
G4ApplicationState s3,G4ApplicationState s4,
G4ApplicationState s5);
G4bool IsAvailable();
virtual void List();
public:
static G4double ValueOf(G4String unitName);
static G4String CategoryOf(G4String unitName);
static G4String UnitsList(G4String unitCategory);
private:
void G4UIcommandCommonConstructorCode (const char * theCommandPath);
G4UImessenger *messenger;
G4String commandPath;
G4String commandName;
G4String rangeString;
RWTPtrOrderedVector<G4UIparameter> parameter;
RWTValOrderedVector<G4String> commandGuidance;
RWTValOrderedVector<G4ApplicationState> availabelStateList;
public:
inline void SetRange(const char* rs)
{ rangeString = rs; }
inline const G4String GetRange() const
{ return rangeString; };
inline G4int GetGuidanceEntries() const
{ return commandGuidance.entries(); }
inline const G4String GetGuidanceLine(int i) const
{ return commandGuidance[i]; }
inline const G4String GetCommandPath() const
{ return commandPath; }
inline const G4String GetCommandName() const
{ return commandName; }
inline G4int GetParameterEntries() const
{ return parameter.entries(); }
inline G4UIparameter * GetParameter(int i) const
{ return parameter[i]; }
inline void SetParameter(G4UIparameter *const newParameter)
{ parameter.insert( newParameter ); }
inline void SetGuidance(const char * aGuidance)
{
G4String * theGuidance = new G4String( aGuidance );
commandGuidance.insert( *theGuidance );
}
inline const G4String GetTitle() const
{
if(commandGuidance.entries() == 0)
{ return G4String("...Title not available..."); }
else
{ return commandGuidance(0); }
}
protected:
int CheckNewValue(G4String newValue);
// --- the following is used by CheckNewValue() --------
private:
int TypeCheck(G4String newValue);
int RangeCheck(G4String newValue);
int IsInt(const char* str, short maxLength);
int IsDouble(const char* str);
int ExpectExponent(const char* str);
// syntax nodes
yystype Expression( void );
yystype LogicalORExpression( void );
yystype LogicalANDExpression( void );
yystype EqualityExpression ( void );
yystype RelationalExpression( void );
yystype AdditiveExpression( void );
yystype MultiplicativeExpression( void );
yystype UnaryExpression( void );
yystype PrimaryExpression( void );
// semantics routines
int Eval2( yystype arg1, int op, yystype arg2 );
int CompareInt( int arg1, int op, int arg2);
int CompareDouble( double arg1, int op, double arg2);
// utility
tokenNum Yylex( void ); // returns next token
unsigned IndexOf( G4String ); // returns the index of the var name
unsigned IsParameter( G4String ); // returns 1 or 0
int G4UIpGetc( void ); // read one char from rangeBuf
int G4UIpUngetc( int c ); // put back
int Backslash( int c );
int Follow( int expect, int ifyes, int ifno );
G4String TokenToStr(int token);
void PrintToken(void); // for debug
// data
G4String rangeBuf;
int bp; // buffer pointer for rangeBuf
tokenNum token;
yystype yylval;
RWTValOrderedVector<yystype> newVal;
int paramERR;
};
#endif
@@ -0,0 +1,25 @@
// 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: G4UIcommandStatus.hh,v 2.0 1998/07/02 17:08:01 gunter Exp $
// GEANT4 tag $Name: geant4-00 $
//
#ifndef G4UIcommandStatus_h
#define G4UIcommandStatus_h 1
enum G4UIcommandStatus
{
fCommandSucceeded = 0,
fCommandNotFound = 100,
fIllegalApplicationState = 200,
fParameterOutOfRange = 300,
fParameterUnreadable = 400,
fParameterOutOfCandidates = 500
};
#endif
@@ -0,0 +1,77 @@
// 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.hh,v 2.1 1998/07/12 02:59:32 urbi Exp $
// GEANT4 tag $Name: geant4-00 $
//
#ifndef G4UIcommandTree_h
#define G4UIcommandTree_h 1
#include "G4UIcommand.hh"
#include "globals.hh"
#include <rw/tpordvec.h>
class G4UIcommandTree
{
public:
G4UIcommandTree();
G4UIcommandTree(G4String thePathName);
G4UIcommandTree(char * thePathName);
~G4UIcommandTree();
int operator==(const G4UIcommandTree &right) const;
int operator!=(const G4UIcommandTree &right) const;
public:
void AddNewCommand(G4UIcommand * newCommand);
void RemoveCommand(G4UIcommand * aCommand);
G4UIcommand * FindPath(G4String commandPath);
void List();
void ListCurrent();
void ListCurrentWithNum();
private:
RWTPtrOrderedVector<G4UIcommand> command;
RWTPtrOrderedVector<G4UIcommandTree> tree;
G4UIcommand *guidance;
G4String pathName;
public:
inline const G4UIcommand * GetGuidance() const
{ return guidance; };
inline const G4String GetPathName() const
{ return pathName; };
inline G4int GetTreeEntry() const
{ return tree.entries(); };
inline G4int GetCommandEntry() const
{ return command.entries(); };
inline G4UIcommandTree * GetTree(int i)
{ return tree[i-1]; };
inline G4UIcommandTree * GetTree(G4String comName)
{
for( int i=0; i < tree.entries(); i++)
{
if( comName == tree[i]->GetPathName() )
{ return tree[i]; }
}
return NULL;
};
inline G4UIcommand * GetCommand(int i)
{ return command[i-1]; };
inline const G4String GetTitle() const
{
if(guidance==NULL)
{ return G4String("...Title not available..."); }
else
{ return guidance->GetTitle(); }
};
};
#endif
@@ -0,0 +1,40 @@
// 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.hh,v 2.3 1998/10/01 15:49:53 asaim Exp $
// GEANT4 tag $Name: geant4-00 $
//
#ifndef G4UIcontrolMessenger_h
#define G4UIcontrolMessenger_h 1
#include "G4UImessenger.hh"
class G4UIdirectory;
class G4UIcmdWithAString;
class G4UIcmdWithAnInteger;
class G4UIcmdWithoutParameter;
class G4UIcontrolMessenger : public G4UImessenger
{
public:
G4UIcontrolMessenger();
~G4UIcontrolMessenger();
void SetNewValue(G4UIcommand * command,G4String newValue);
G4String GetCurrentValue(G4UIcommand * command);
private:
G4UIdirectory * controlDirectory;
G4UIcmdWithAString * ExecuteCommand;
G4UIcmdWithAnInteger * verboseCommand;
G4UIcmdWithAString * historyCommand;
G4UIcmdWithoutParameter * stopStoreHistoryCommand;
G4UIcmdWithAString * ManualCommand;
};
#endif
+25
View File
@@ -0,0 +1,25 @@
// 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.hh,v 2.0 1998/07/02 17:08:07 gunter Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
#ifndef G4UIdirectory_H
#define G4UIdirectory_H 1
#include "G4UIcommand.hh"
class G4UIdirectory : public G4UIcommand
{
public:
G4UIdirectory(char * theCommandPath);
G4UIdirectory(const char * theCommandPath);
};
#endif
+127
View File
@@ -0,0 +1,127 @@
// 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.hh,v 2.5 1998/12/02 09:57:48 asaim Exp $
// GEANT4 tag $Name: geant4-00 $
//
#ifndef G4UImanager_h
#define G4UImanager_h 1
#include "globals.hh"
#include <rw/ctoken.h>
#include <rw/tvordvec.h>
#include <fstream.h>
class G4UIcommandTree;
class G4UIcommand;
class G4UIsession;
class G4UIcontrolMessenger;
class G4UnitsMessenger;
class G4UImanager
{
public:
static G4UImanager * GetUIpointer();
protected:
G4UImanager();
public:
~G4UImanager();
private:
G4UImanager(const G4UImanager &right);
const G4UImanager & operator=(const G4UImanager &right);
int operator==(const G4UImanager &right) const;
int operator!=(const G4UImanager &right) const;
public:
G4String GetCurrentValues(const char * aCommand);
void AddNewCommand(G4UIcommand * newCommand);
void RemoveCommand(G4UIcommand * aCommand);
void ExecuteMacroFile(G4String fileName);
G4int ApplyCommand(char * aCommand);
G4int ApplyCommand(G4String aCommand);
void StoreHistory(G4String fileName="G4history.macro");
void StoreHistory(G4bool historySwitch,
G4String fileName="G4history.macro");
void PauseSession(G4String msg);
void ListCommands(G4String direc);
private:
void CreateMessenger();
G4UIcommandTree* FindDirectory(const char* dirName);
public:
// following three methods will be removed quite soon.
void Interact();
void Interact(char * promptCharacters);
void Interact(G4String promptCharacters);
private:
static G4UImanager * fUImanager;
static G4bool fUImanagerHasBeenKilled;
G4UIcommandTree * treeTop;
G4UIsession * session;
G4UIcontrolMessenger * UImessenger;
G4UnitsMessenger * UnitsMessenger;
G4String savedParameters;
G4UIcommand * savedCommand;
G4int verboseLevel;
ofstream historyFile;
G4bool saveHistory;
RWTValOrderedVector<G4String> histVec;
public:
G4String GetCurrentStringValue(const char * aCommand,
int parameterNumber=1, G4bool reGet=true);
G4int GetCurrentIntValue(const char * aCommand,
int parameterNumber=1, G4bool reGet=true);
G4double GetCurrentDoubleValue(const char * aCommand,
int parameterNumber=1, G4bool reGet=true);
G4String GetCurrentStringValue(const char * aCommand,
const char * aParameterName, G4bool reGet=true);
G4int GetCurrentIntValue(const char * aCommand,
const char * aParameterName, G4bool reGet=true);
G4double GetCurrentDoubleValue(const char * aCommand,
const char * aParameterName, G4bool reGet=true);
public:
inline G4UIcommandTree * GetTree() const
{ return treeTop; };
inline G4UIsession * GetSession() const
{ return session; };
inline void SetSession(G4UIsession *const value)
{ session = value; };
inline void SetVerboseLevel(G4int val)
{ verboseLevel = val; };
inline G4int GetVerboseLevel() const
{ return verboseLevel; };
inline G4int GetNumberOfHistory() const
{ return histVec.entries(); };
inline G4String GetPreviousCommand(G4int i) const
{
G4String st;
if(i>=0 && i<histVec.entries())
{ st = histVec[i]; }
return st;
}
public:
void SetCoutDestination(G4UIsession *const value);
// Old methods kept for backward compatibility
// inline G4UIcommandTree * GetTree() const
// { return treeTop; };
// inline G4UIsession * GetSession() const
// { return session; };
// inline void SetSession(G4UIsession *const value)
// { session = value; };
};
#endif
+44
View File
@@ -0,0 +1,44 @@
// 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.hh,v 2.2 1998/07/13 17:12:50 urbi Exp $
// GEANT4 tag $Name: geant4-00 $
//
#ifndef G4UImessenger_h
#define G4UImessenger_h 1
#include "globals.hh"
#include "G4ios.hh"
class G4UIcommand;
class G4UImessenger
{
public:
G4UImessenger();
virtual ~G4UImessenger();
virtual G4String GetCurrentValue(G4UIcommand * command);
virtual void SetNewValue(G4UIcommand * command,G4String newValue);
// For RWTPtrOrderedVector...
G4bool operator == (const G4UImessenger& messenger) const;
protected:
G4String ItoS(G4int i);
G4String DtoS(G4double a);
G4String BtoS(G4bool b);
G4int StoI(G4String s);
G4double StoD(G4String s);
G4bool StoB(G4String s);
protected:
void AddUIcommand(G4UIcommand * newCommand);
};
#endif
+144
View File
@@ -0,0 +1,144 @@
// 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.hh,v 2.1 1998/07/12 02:59:36 urbi Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
// ---------------------------------------------------------------------
#ifndef G4UIparameter_h
#define G4UIparameter_h 1
#include "globals.hh"
#ifdef WIN32
# include <Strstrea.h>
#else
# include <strstream.h>
#endif
#include "G4UItokenNum.hh"
class G4UIparameter
{
public:
G4UIparameter();
G4UIparameter(char theType);
G4UIparameter(const char * theName, char theType, G4bool theOmittable);
~G4UIparameter();
int operator==(const G4UIparameter &right) const;
int operator!=(const G4UIparameter &right) const;
G4int CheckNewValue(G4String newValue);
void List();
private:
G4String parameterName;
G4String parameterGuidance;
G4String defaultValue;
G4String parameterRange;
G4String parameterCandidate;
char parameterType;
G4bool omittable;
G4bool currentAsDefaultFlag;
G4int widget;
public:
// defaultValue
inline void SetDefaultValue(const char * theDefaultValue)
{ defaultValue = theDefaultValue; }
void SetDefaultValue(G4int theDefaultValue);
void SetDefaultValue(G4double theDefaultValue);
inline G4String GetDefaultValue() const
{ return defaultValue; }
// parameterType
inline char GetParameterType() const
{ return parameterType; }
// parameterRange
inline void SetParameterRange(const char * theRange)
{ parameterRange = theRange; }
inline G4String GetParameterRange() const
{ return parameterRange; }
// parameterName
inline void SetParameterName(const char * theName)
{ parameterName = theName; }
inline G4String GetParameterName() const
{ return parameterName; }
// parameterCandidates
inline void SetParameterCandidates(const char * theString)
{ parameterCandidate = theString; }
inline G4String GetParameterCandidates() const
{ return parameterCandidate; }
// omittable
inline void SetOmittable(G4bool om)
{ omittable = om; }
inline G4bool IsOmittable() const
{ return omittable; }
// currentAsDefaultFlag
inline void SetCurrentAsDefault(G4bool val)
{ currentAsDefaultFlag = val; }
inline G4bool GetCurrentAsDefault() const
{ return currentAsDefaultFlag; }
// out of date methods
inline void SetWidget(G4int theWidget)
{ widget = theWidget; }
inline const G4String GetParameterGuidance() const
{ return parameterGuidance; }
inline void SetGuidance(const char * theGuidance)
{ parameterGuidance = theGuidance; }
private:
// --- the following is used by CheckNewValue() -------
int TypeCheck(G4String newValue );
int RangeCheck(G4String newValue );
int CandidateCheck(G4String newValue );
int IsInt(const char* str, short maxDigit);
int IsDouble(const char* str);
int ExpectExponent(const char* str);
// syntax nodes
yystype Expression( void );
yystype LogicalORExpression( void );
yystype LogicalANDExpression( void );
yystype EqualityExpression ( void );
yystype RelationalExpression( void );
yystype AdditiveExpression( void );
yystype MultiplicativeExpression( void );
yystype UnaryExpression( void );
yystype PrimaryExpression( void );
// semantics routines
int Eval2( yystype arg1, int op, yystype arg2 );
int CompareInt( int arg1, int op, int arg2);
int CompareDouble( double arg1, int op, double arg2);
// utility
tokenNum Yylex( void ); // returns next token
int G4UIpGetc( void ); // read one char from rangeBuf
int G4UIpUngetc( int c ); // put back
int Backslash( int c );
int Follow( int expect, int ifyes, int ifno );
G4String TokenToStr(int token);
//void PrintToken(void); // debug
// data
G4String rangeBuf;
int bp; // buffer pointer for rangeBuf
tokenNum token;
yystype yylval;
yystype newVal;
int paramERR;
//------------ end of CheckNewValue() related member --------------
};
#endif
+44
View File
@@ -0,0 +1,44 @@
// 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.hh,v 2.2 1998/11/04 11:53:31 yhajime Exp $
// GEANT4 tag $Name: geant4-00 $
//
// $id$
#ifndef G4UIsession_h
#define G4UIsession_h 1
#include "G4coutDestination.hh"
#include "globals.hh"
class G4UIsession : public G4coutDestination
{
// Base class of UI/GUI session
public:
G4UIsession();
virtual ~G4UIsession();
virtual G4UIsession * SessionStart();
// This method will be invoked by main().
// Optionally, it can be invoked by another session.
virtual void PauseSessionStart(G4String Prompt);
// This method will be invoked by G4UImanager
// when G4kernel becomes to Pause state.
virtual G4int ReceiveG4cout(G4String coutString);
virtual G4int ReceiveG4cerr(G4String cerrString);
// These two methods will be invoked by G4strstreambuf.
};
#endif
+46
View File
@@ -0,0 +1,46 @@
// 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: G4UItokenNum.hh,v 2.0 1998/07/02 17:08:13 gunter Exp $
// GEANT4 tag $Name: geant4-00 $
//
// G4UItokenNum.hh
#ifndef G4UItokenNum_hh
#define G4UItokenNum_hh 1
#include "globals.hh"
enum tokenNum {
IDENTIFIER = 257,
CONSTINT = 258,
CONSTDOUBLE= 259,
CONSTCHAR = 260,
CONSTSTRING= 261,
GT = 262,
GE = 263,
LT = 264,
LE = 265,
EQ = 266,
NE = 267,
//LOGICALNOT = 268,
LOGICALOR = 269,
LOGICALAND = 270
};
typedef struct yystype {
tokenNum type;
double D;
int I;
char C;
G4String S;
int operator==(const yystype &right) const
{ return (this == &right); }
} yystype;
#endif
@@ -0,0 +1,41 @@
// 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.hh,v 2.1 1998/11/27 06:12:47 asaim Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
#ifndef G4UnitsMessenger_h
#define G4UnitsMessenger_h 1
#include "globals.hh"
#include "G4UImessenger.hh"
class G4UIdirectory;
class G4UIcmdWithoutParameter;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
class G4UnitsMessenger: public G4UImessenger
{
public:
G4UnitsMessenger();
~G4UnitsMessenger();
void SetNewValue(G4UIcommand*, G4String);
private:
G4UIdirectory* UnitsTableDir;
G4UIcmdWithoutParameter* ListCmd;
};
#endif
@@ -0,0 +1,44 @@
// 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.hh,v 2.1 1998/07/12 02:59:38 urbi Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
// ------------------------------------------------------------
// GEANT 4 class header file
//
// For information related to this code contact:
// CERN, CN Division, ASD group
// ---------------- G4VStateDependent ----------------
// by Gabriele Cosmo, November 1996
// Abstract class responsible to Notify the change of state
// ------------------------------------------------------------
#ifndef G4VStateDependent_h
#define G4VStateDependent_h 1
#include "globals.hh"
#include "G4ApplicationState.hh"
class G4VStateDependent {
public:
G4VStateDependent();
virtual ~G4VStateDependent();
G4int operator==(const G4VStateDependent &right) const;
G4int operator!=(const G4VStateDependent &right) const;
virtual G4bool Notify(G4ApplicationState requestedState) = 0;
private:
G4VStateDependent(const G4VStateDependent &right);
G4VStateDependent& operator=(const G4VStateDependent &right);
};
#endif
+159
View File
@@ -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;
// }
}
+70
View File
@@ -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));
}
+59
View File
@@ -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)
{;}
+955
View File
@@ -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;
}
+234
View File
@@ -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;
}
+22
View File
@@ -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)
{;}
+327
View File
@@ -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
}
+99
View File
@@ -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;
}
+735
View File
@@ -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 ******
+34
View File
@@ -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;
}
+50
View File
@@ -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....
+55
View File
@@ -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);
}