00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "G4tgrParameterMgr.hh"
00037 #include "G4tgrUtils.hh"
00038 #include "G4tgrMaterialFactory.hh"
00039 #include "G4tgrRotationMatrixFactory.hh"
00040 #include "G4tgrFileReader.hh"
00041 #include "G4tgrMessenger.hh"
00042 #include "G4UIcommand.hh"
00043
00044 G4tgrParameterMgr* G4tgrParameterMgr::theInstance = 0;
00045
00046
00047
00048 G4tgrParameterMgr::G4tgrParameterMgr()
00049 {
00050 }
00051
00052
00053
00054 G4tgrParameterMgr::~G4tgrParameterMgr()
00055 {
00056 delete theInstance;
00057 }
00058
00059
00060
00061 G4tgrParameterMgr* G4tgrParameterMgr::GetInstance()
00062 {
00063 if( !theInstance )
00064 {
00065 theInstance = new G4tgrParameterMgr;
00066 }
00067 return theInstance;
00068 }
00069
00070
00071
00072 void G4tgrParameterMgr::AddParameterNumber( const std::vector<G4String>& wl,
00073 G4bool mustBeNew )
00074 {
00075 CheckIfNewParameter( wl, mustBeNew );
00076
00077
00078
00079 G4float val = G4tgrUtils::GetDouble( wl[2] );
00080 theParameterList[ wl[1] ] = G4UIcommand::ConvertToString( val );
00081
00082 #ifdef G4VERBOSE
00083 if( G4tgrMessenger::GetVerboseLevel() >= 2 )
00084 {
00085 G4cout << " G4tgrParameterMgr::AddParameterNumber() -"
00086 << " parameter added " << wl[1]
00087 << " = " << theParameterList[ wl[1] ] << G4endl;
00088 }
00089 #endif
00090 }
00091
00092
00093
00094 void G4tgrParameterMgr::AddParameterString( const std::vector<G4String>& wl,
00095 G4bool mustBeNew )
00096 {
00097 CheckIfNewParameter( wl, mustBeNew );
00098
00099
00100 theParameterList[ wl[1] ] = wl[2];
00101
00102 #ifdef G4VERBOSE
00103 if( G4tgrMessenger::GetVerboseLevel() >= 2 )
00104 {
00105 G4cout << " G4tgrParameterMgr::AddParameterString() -"
00106 << " parameter added " << wl[1]
00107 << " = " << theParameterList[ wl[1] ] << G4endl;
00108 }
00109 #endif
00110 }
00111
00112
00113 void G4tgrParameterMgr::CheckIfNewParameter( const std::vector<G4String>& wl,
00114 G4bool mustBeNew )
00115 {
00116
00117 G4bool existsAlready;
00118 G4mapss::iterator sdite = theParameterList.find( wl[1] );
00119 if( sdite == theParameterList.end() )
00120 {
00121 existsAlready = false;
00122 }
00123 else
00124 {
00125 existsAlready = true;
00126 }
00127
00128 if(existsAlready)
00129 {
00130 if( mustBeNew )
00131 {
00132 G4String ErrMessage = "Parameter already exists... " + wl[1];
00133 G4Exception("G4tgrParameterMgr::CheckParameter()",
00134 "IllegalConstruct", FatalException, ErrMessage);
00135 }
00136 else
00137 {
00138 G4String WarMessage = "Parameter already exists... " + wl[1];
00139 G4Exception("G4tgrParameterMgr::CheckParameter()",
00140 "NotRecommended", JustWarning, WarMessage);
00141 }
00142 }
00143
00144
00145 G4tgrUtils::CheckWLsize( wl, 3, WLSIZE_EQ, "Parameter::AddParameter");
00146 }
00147
00148
00149
00150 G4String G4tgrParameterMgr::FindParameter( const G4String& name, G4bool exists )
00151 {
00152 G4String par = "";
00153
00154 G4mapss::iterator sdite = theParameterList.find( name );
00155 if( sdite == theParameterList.end() )
00156 {
00157 if( exists )
00158 {
00159 DumpList();
00160 G4String ErrMessage = "Parameter not found in list: " + name;
00161 G4Exception("G4tgrParameterMgr::FindParameter()",
00162 "InvalidSetup", FatalException, ErrMessage);
00163 }
00164 }
00165 else
00166 {
00167 exists = 1;
00168 par = ((*sdite).second);
00169 #ifdef G4VERBOSE
00170 if( G4tgrMessenger::GetVerboseLevel() >= 3 )
00171 {
00172 G4cout << " G4tgrParameterMgr::FindParameter() -"
00173 << " parameter found " << name << " = " << par << G4endl;
00174 }
00175 #endif
00176 }
00177
00178 return par;
00179 }
00180
00181
00182
00183 void G4tgrParameterMgr::DumpList()
00184 {
00185
00186 G4cout << " @@@@@@@@@@@@@@@@@@ Dumping parameter list " << G4endl;
00187 G4mapss::const_iterator cite;
00188 for( cite = theParameterList.begin();cite != theParameterList.end(); cite++ )
00189 {
00190 G4cout << (*cite).first << " = " << (*cite).second << G4endl;
00191 }
00192 }