Geant4  10.02.p02
G4tgrParameterMgr.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id: G4tgrParameterMgr.cc 66872 2013-01-15 01:25:57Z japost $
28 //
29 //
30 // class G4tgrParameterMgr
31 
32 // History:
33 // - Created. P.Arce, CIEMAT (November 2007)
34 // -------------------------------------------------------------------------
35 
36 #include "G4tgrParameterMgr.hh"
37 #include "G4tgrUtils.hh"
38 #include "G4tgrMaterialFactory.hh"
40 #include "G4tgrFileReader.hh"
41 #include "G4tgrMessenger.hh"
42 #include "G4UIcommand.hh"
43 
45 
46 
47 //-------------------------------------------------------------
49 {
50 }
51 
52 
53 //-------------------------------------------------------------
55 {
56  delete theInstance;
57 }
58 
59 
60 //-------------------------------------------------------------
62 {
63  if( !theInstance )
64  {
66  }
67  return theInstance;
68 }
69 
70 
71 //-------------------------------------------------------------
72 void G4tgrParameterMgr::AddParameterNumber( const std::vector<G4String>& wl,
73  G4bool mustBeNew )
74 {
75  CheckIfNewParameter( wl, mustBeNew );
76 
77  //----- Convert third argument to double, but then store it as string
78  // for later use in CLHEP evaluator
79  G4float val = G4tgrUtils::GetDouble( wl[2] );
81 
82 #ifdef G4VERBOSE
84  {
85  G4cout << " G4tgrParameterMgr::AddParameterNumber() -"
86  << " parameter added " << wl[1]
87  << " = " << theParameterList[ wl[1] ] << G4endl;
88  }
89 #endif
90 }
91 
92 
93 //-------------------------------------------------------------
94 void G4tgrParameterMgr::AddParameterString( const std::vector<G4String>& wl,
95  G4bool mustBeNew )
96 {
97  CheckIfNewParameter( wl, mustBeNew );
98 
99  //----- Store parameter as string
100  theParameterList[ wl[1] ] = wl[2];
101 
102 #ifdef G4VERBOSE
104  {
105  G4cout << " G4tgrParameterMgr::AddParameterString() -"
106  << " parameter added " << wl[1]
107  << " = " << theParameterList[ wl[1] ] << G4endl;
108  }
109 #endif
110 }
111 
112 //-------------------------------------------------------------
113 void G4tgrParameterMgr::CheckIfNewParameter( const std::vector<G4String>& wl,
114  G4bool mustBeNew )
115 {
116  //---------- Find first if it exists already
117  G4bool existsAlready;
118  G4mapss::iterator sdite = theParameterList.find( wl[1] );
119  if( sdite == theParameterList.end() )
120  {
121  existsAlready = false;
122  }
123  else
124  {
125  existsAlready = true;
126  }
127 
128  if(existsAlready)
129  {
130  if( mustBeNew )
131  {
132  G4String ErrMessage = "Parameter already exists... " + wl[1];
133  G4Exception("G4tgrParameterMgr::CheckParameter()",
134  "IllegalConstruct", FatalException, ErrMessage);
135  }
136  else
137  {
138  G4String WarMessage = "Parameter already exists... " + wl[1];
139  G4Exception("G4tgrParameterMgr::CheckParameter()",
140  "NotRecommended", JustWarning, WarMessage);
141  }
142  }
143 
144  //---------- Check for miminum number of words read
145  G4tgrUtils::CheckWLsize( wl, 3, WLSIZE_EQ, "Parameter::AddParameter");
146 }
147 
148 
149 //-------------------------------------------------------------
151 {
152  G4String par = "";
153 
154  G4mapss::iterator sdite = theParameterList.find( name );
155  if( sdite == theParameterList.end() )
156  {
157  if( exists )
158  {
159  DumpList();
160  G4String ErrMessage = "Parameter not found in list: " + name;
161  G4Exception("G4tgrParameterMgr::FindParameter()",
162  "InvalidSetup", FatalException, ErrMessage);
163  }
164  }
165  else
166  {
167  exists = 1;
168  par = ((*sdite).second);
169 #ifdef G4VERBOSE
171  {
172  G4cout << " G4tgrParameterMgr::FindParameter() -"
173  << " parameter found " << name << " = " << par << G4endl;
174  }
175 #endif
176  }
177 
178  return par;
179 }
180 
181 
182 //-------------------------------------------------------------
184 {
185  //---------- Dump number of objects of each class
186  G4cout << " @@@@@@@@@@@@@@@@@@ Dumping parameter list " << G4endl;
187  G4mapss::const_iterator cite;
188  for( cite = theParameterList.begin();cite != theParameterList.end(); cite++ )
189  {
190  G4cout << (*cite).first << " = " << (*cite).second << G4endl;
191  }
192 }
G4String FindParameter(const G4String &name, G4bool exists=true)
G4String name
Definition: TRTMaterials.hh:40
float G4float
Definition: G4Types.hh:77
static void CheckWLsize(const std::vector< G4String > &wl, unsigned int nWCheck, WLSIZEtype st, const G4String &methodName)
Definition: G4tgrUtils.cc:475
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:371
void AddParameterString(const std::vector< G4String > &wl, G4bool mustBeNew=0)
#define G4ThreadLocal
Definition: tls.hh:89
G4GLOB_DLL std::ostream G4cout
static G4int GetVerboseLevel()
bool G4bool
Definition: G4Types.hh:79
static G4tgrParameterMgr * GetInstance()
static G4ThreadLocal G4tgrParameterMgr * theInstance
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static G4double GetDouble(const G4String &str, G4double unitval=1.)
Definition: G4tgrUtils.cc:205
void CheckIfNewParameter(const std::vector< G4String > &wl, G4bool mustBeNew)
#define G4endl
Definition: G4ios.hh:61
void AddParameterNumber(const std::vector< G4String > &wl, G4bool mustBeNew=0)