Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // G4tgrParameterMgr implementation << 27 // 26 // 28 // Author: P.Arce, CIEMAT (November 2007) << 27 // $Id: G4tgrParameterMgr.cc,v 1.7 2010-10-13 07:56:56 gcosmo Exp $ 29 // ------------------------------------------- << 28 // GEANT4 tag $Name: geant4-09-04-patch-02 $ >> 29 // >> 30 // >> 31 // class G4tgrParameterMgr >> 32 >> 33 // History: >> 34 // - Created. P.Arce, CIEMAT (November 2007) >> 35 // ------------------------------------------------------------------------- 30 36 31 #include "G4tgrParameterMgr.hh" 37 #include "G4tgrParameterMgr.hh" 32 #include "G4tgrUtils.hh" 38 #include "G4tgrUtils.hh" 33 #include "G4tgrMaterialFactory.hh" 39 #include "G4tgrMaterialFactory.hh" 34 #include "G4tgrRotationMatrixFactory.hh" 40 #include "G4tgrRotationMatrixFactory.hh" 35 #include "G4tgrFileReader.hh" 41 #include "G4tgrFileReader.hh" 36 #include "G4tgrMessenger.hh" 42 #include "G4tgrMessenger.hh" 37 #include "G4UIcommand.hh" 43 #include "G4UIcommand.hh" 38 44 39 G4ThreadLocal G4tgrParameterMgr* G4tgrParamete << 45 G4tgrParameterMgr* G4tgrParameterMgr::theInstance = 0; >> 46 40 47 41 // ------------------------------------------- << 48 //------------------------------------------------------------- 42 G4tgrParameterMgr::G4tgrParameterMgr() 49 G4tgrParameterMgr::G4tgrParameterMgr() 43 { 50 { 44 } 51 } 45 52 46 // ------------------------------------------- << 53 >> 54 //------------------------------------------------------------- 47 G4tgrParameterMgr::~G4tgrParameterMgr() 55 G4tgrParameterMgr::~G4tgrParameterMgr() 48 { 56 { 49 delete theInstance; 57 delete theInstance; 50 } 58 } 51 59 52 // ------------------------------------------- << 60 >> 61 //------------------------------------------------------------- 53 G4tgrParameterMgr* G4tgrParameterMgr::GetInsta 62 G4tgrParameterMgr* G4tgrParameterMgr::GetInstance() 54 { 63 { 55 if(theInstance == nullptr) << 64 if( !theInstance ) 56 { 65 { 57 theInstance = new G4tgrParameterMgr; 66 theInstance = new G4tgrParameterMgr; 58 } 67 } 59 return theInstance; 68 return theInstance; 60 } 69 } 61 70 62 // ------------------------------------------- << 71 63 void G4tgrParameterMgr::AddParameterNumber(con << 72 //------------------------------------------------------------- 64 G4b << 73 void G4tgrParameterMgr::AddParameterNumber( const std::vector<G4String>& wl, >> 74 G4bool mustBeNew ) 65 { 75 { 66 CheckIfNewParameter(wl, mustBeNew); << 76 CheckIfNewParameter( wl, mustBeNew ); 67 77 68 //----- Convert third argument to double, bu 78 //----- Convert third argument to double, but then store it as string 69 // for later use in CLHEP evaluator << 79 // for later use in CLHEP evaluator 70 G4float val = G4tgrUtils::GetDou << 80 G4float val = G4tgrUtils::GetDouble( wl[2] ); 71 theParameterList[wl[1]] = G4UIcommand::Conve << 81 theParameterList[ wl[1] ] = G4UIcommand::ConvertToString( val ); 72 82 73 #ifdef G4VERBOSE 83 #ifdef G4VERBOSE 74 if(G4tgrMessenger::GetVerboseLevel() >= 2) << 84 if( G4tgrMessenger::GetVerboseLevel() >= 2 ) 75 { 85 { 76 G4cout << " G4tgrParameterMgr::AddParamete 86 G4cout << " G4tgrParameterMgr::AddParameterNumber() -" 77 << " parameter added " << wl[1] << << 87 << " parameter added " << wl[1] 78 << G4endl; << 88 << " = " << theParameterList[ wl[1] ] << G4endl; 79 } 89 } 80 #endif 90 #endif 81 } 91 } 82 92 83 // ------------------------------------------- << 93 84 void G4tgrParameterMgr::AddParameterString(con << 94 //------------------------------------------------------------- 85 G4b << 95 void G4tgrParameterMgr::AddParameterString( const std::vector<G4String>& wl, >> 96 G4bool mustBeNew ) 86 { 97 { 87 CheckIfNewParameter(wl, mustBeNew); << 98 CheckIfNewParameter( wl, mustBeNew ); 88 99 89 //----- Store parameter as string 100 //----- Store parameter as string 90 theParameterList[wl[1]] = wl[2]; << 101 theParameterList[ wl[1] ] = wl[2]; 91 102 92 #ifdef G4VERBOSE 103 #ifdef G4VERBOSE 93 if(G4tgrMessenger::GetVerboseLevel() >= 2) << 104 if( G4tgrMessenger::GetVerboseLevel() >= 2 ) 94 { 105 { 95 G4cout << " G4tgrParameterMgr::AddParamete 106 G4cout << " G4tgrParameterMgr::AddParameterString() -" 96 << " parameter added " << wl[1] << << 107 << " parameter added " << wl[1] 97 << G4endl; << 108 << " = " << theParameterList[ wl[1] ] << G4endl; 98 } 109 } 99 #endif 110 #endif 100 } 111 } 101 112 102 // ------------------------------------------- << 113 //------------------------------------------------------------- 103 void G4tgrParameterMgr::CheckIfNewParameter(co << 114 void G4tgrParameterMgr::CheckIfNewParameter( const std::vector<G4String>& wl, 104 G4 << 115 G4bool mustBeNew ) 105 { 116 { 106 //---------- Find first if it exists already 117 //---------- Find first if it exists already 107 G4bool existsAlready; 118 G4bool existsAlready; 108 G4mapss::const_iterator sdite = theParameter << 119 G4mapss::iterator sdite = theParameterList.find( wl[1] ); 109 if(sdite == theParameterList.cend()) << 120 if( sdite == theParameterList.end() ) 110 { 121 { 111 existsAlready = false; 122 existsAlready = false; 112 } 123 } 113 else 124 else 114 { 125 { 115 existsAlready = true; 126 existsAlready = true; 116 } 127 } 117 128 118 if(existsAlready) 129 if(existsAlready) 119 { 130 { 120 if(mustBeNew) << 131 if( mustBeNew ) 121 { 132 { 122 G4String ErrMessage = "Parameter already 133 G4String ErrMessage = "Parameter already exists... " + wl[1]; 123 G4Exception("G4tgrParameterMgr::CheckPar << 134 G4Exception("G4tgrParameterMgr::CheckParameter()", 124 FatalException, ErrMessage); << 135 "IllegalConstruct", FatalException, ErrMessage); 125 } 136 } 126 else 137 else 127 { 138 { 128 G4String WarMessage = "Parameter already 139 G4String WarMessage = "Parameter already exists... " + wl[1]; 129 G4Exception("G4tgrParameterMgr::CheckPar << 140 G4Exception("G4tgrParameterMgr::CheckParameter()", 130 JustWarning, WarMessage); << 141 "NotRecommended", JustWarning, WarMessage); 131 } 142 } 132 } 143 } 133 << 144 134 //---------- Check for miminum number of wor << 145 //---------- Check for miminum number of words read 135 G4tgrUtils::CheckWLsize(wl, 3, WLSIZE_EQ, "P << 146 G4tgrUtils::CheckWLsize( wl, 3, WLSIZE_EQ, "Parameter::AddParameter"); 136 } 147 } 137 148 138 // ------------------------------------------- << 149 139 G4String G4tgrParameterMgr::FindParameter(cons << 150 //------------------------------------------------------------- >> 151 G4String G4tgrParameterMgr::FindParameter( const G4String& name, G4bool exists ) 140 { 152 { 141 G4String par = ""; 153 G4String par = ""; 142 << 154 143 G4mapss::const_iterator sdite = theParameter << 155 G4mapss::iterator sdite = theParameterList.find( name ); 144 if(sdite == theParameterList.cend()) << 156 if( sdite == theParameterList.end() ) 145 { 157 { 146 if(exists) << 158 if( exists ) 147 { 159 { 148 DumpList(); 160 DumpList(); 149 G4String ErrMessage = "Parameter not fou 161 G4String ErrMessage = "Parameter not found in list: " + name; 150 G4Exception("G4tgrParameterMgr::FindPara << 162 G4Exception("G4tgrParameterMgr::FindParameter()", 151 FatalException, ErrMessage); << 163 "InvalidSetup", FatalException, ErrMessage); 152 } 164 } 153 } 165 } 154 else 166 else 155 { 167 { 156 exists = 1; 168 exists = 1; 157 par = ((*sdite).second); << 169 par = ((*sdite).second); 158 #ifdef G4VERBOSE 170 #ifdef G4VERBOSE 159 if(G4tgrMessenger::GetVerboseLevel() >= 3) << 171 if( G4tgrMessenger::GetVerboseLevel() >= 3 ) 160 { << 172 { 161 G4cout << " G4tgrParameterMgr::FindParam << 173 G4cout << " G4tgrParameterMgr::FindParameter() -" 162 << " parameter found " << name << << 174 << " parameter found " << name << " = " << par << G4endl; 163 } << 175 } 164 #endif 176 #endif 165 } 177 } 166 178 167 return par; 179 return par; 168 } 180 } 169 181 170 // ------------------------------------------- << 182 >> 183 //------------------------------------------------------------- 171 void G4tgrParameterMgr::DumpList() 184 void G4tgrParameterMgr::DumpList() 172 { 185 { 173 //---------- Dump number of objects of each 186 //---------- Dump number of objects of each class 174 G4cout << " @@@@@@@@@@@@@@@@@@ Dumping param 187 G4cout << " @@@@@@@@@@@@@@@@@@ Dumping parameter list " << G4endl; 175 for(auto cite = theParameterList.cbegin(); << 188 G4mapss::const_iterator cite; 176 cite != theParameterList.cend(); ++ << 189 for( cite = theParameterList.begin();cite != theParameterList.end(); cite++ ) 177 { 190 { 178 G4cout << (*cite).first << " = " << (*cite 191 G4cout << (*cite).first << " = " << (*cite).second << G4endl; 179 } 192 } 180 } 193 } 181 194