MF_Messenger.cc

Go to the documentation of this file.
00001 //! \file
00002 //!
00003 //! Source file for Magnetic_Field messenger class for the user interface.
00004 //!
00005 //! Defines the singleton messenger class and its member routines which
00006 //! control the parameters of Magnetic_Field detector within the OLYMPUS
00007 //! Monte Carlo.  This allow the user to control the parameters and/or
00008 //! running from command files or interactively.
00009 //!
00010 //! \author D.K. Hasell
00011 //! \version 1.0
00012 //! \date 2010-10-17
00013 //!
00014 //! \ingroup control
00015 
00016 // *+****1****+****2****+****3****+****4****+****5****+****6****+****7****+****
00017 
00018 // Include user header files referenced in this file.
00019 
00020 #include "MF_Messenger.h"
00021 #include "Magnetic_Field.h"
00022 
00023 // Include the GEANT4 header files referenced in this file.
00024 
00025 #include "G4UIdirectory.hh"
00026 
00027 // Initialise the static data pointer for the MF_Messenger class.
00028 
00029 MF_Messenger * MF_Messenger::m_pInstance = 0;
00030 
00031 // Use the standard namespace.
00032 
00033 using namespace std;
00034 
00035 // *+****1****+****2****+****3****+****4****+****5****+****6****+****7****+****
00036 
00037 // Define the routine to return pointer to the instance of MF_Messenger.
00038 
00039 MF_Messenger * MF_Messenger::Instance() {
00040    if( m_pInstance == 0 ) {
00041       m_pInstance = new MF_Messenger();
00042    }
00043    return m_pInstance;
00044 }
00045 
00046 // Constructor of MF_Messenger class.
00047 
00048 MF_Messenger::MF_Messenger() {
00049 
00050    MFdir = new G4UIdirectory( "/Olympus/MF/" );
00051    MFdir->SetGuidance( "Magnetic Field user commands." );
00052 
00053 }
00054 
00055 // Routine to set a pointer to the MF_SD class and define the user
00056 // functions available.
00057 
00058 void MF_Messenger::setMFptr( Magnetic_Field * ptr ) {
00059 
00060    pMF = ptr;
00061 
00062    // Magnetic field scale.
00063 
00064    MFsetScale = new G4UIcmdWithADouble( "/Olympus/MF/setScale", this );
00065    MFsetScale->SetGuidance( "Set magnetic field scale factor." );
00066    MFsetScale->SetParameterName( "scale", false );
00067    MFsetScale->SetRange( "scale >= -2.0 && scale <= 2.0" );
00068    MFsetScale->AvailableForStates( G4State_Idle );
00069 
00070    MFgetScale = new G4UIcmdWithoutParameter( "/Olympus/MF/getScale", this );
00071    MFgetScale->SetGuidance( "Get magnetic field scale factor." );
00072 }
00073 
00074 // Routines to set new values and get current values.
00075 
00076 void MF_Messenger::SetNewValue( G4UIcommand * command, G4String newValue ) {
00077 
00078    // Magnetic field scale.
00079 
00080    if( command == MFsetScale ) {
00081       pMF->setScale( MFsetScale->GetNewDoubleValue( newValue ) );
00082       G4cout << "Magnetic Field scale = " << newValue << G4endl;
00083    }
00084    else if( command == MFgetScale ) {
00085       G4cout << "Magnetic Field scale = " << pMF->getScale() << G4endl;
00086    }
00087 
00088 }
00089 
00090 // Routine to get current value (not used).
00091 
00092 G4String MF_Messenger::GetCurrentValue( G4UIcommand * command ) {
00093    G4String cv;
00094    return cv;
00095 }