ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4tgrParameterMgr.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4tgrParameterMgr.cc
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 //
28 //
29 // class G4tgrParameterMgr
30 
31 // History:
32 // - Created. P.Arce, CIEMAT (November 2007)
33 // -------------------------------------------------------------------------
34 
35 #include "G4tgrParameterMgr.hh"
36 #include "G4tgrUtils.hh"
37 #include "G4tgrMaterialFactory.hh"
39 #include "G4tgrFileReader.hh"
40 #include "G4tgrMessenger.hh"
41 #include "G4UIcommand.hh"
42 
44 
45 
46 //-------------------------------------------------------------
48 {
49 }
50 
51 
52 //-------------------------------------------------------------
54 {
55  delete theInstance;
56 }
57 
58 
59 //-------------------------------------------------------------
61 {
62  if( !theInstance )
63  {
65  }
66  return theInstance;
67 }
68 
69 
70 //-------------------------------------------------------------
71 void G4tgrParameterMgr::AddParameterNumber( const std::vector<G4String>& wl,
72  G4bool mustBeNew )
73 {
74  CheckIfNewParameter( wl, mustBeNew );
75 
76  //----- Convert third argument to double, but then store it as string
77  // for later use in CLHEP evaluator
78  G4float val = G4tgrUtils::GetDouble( wl[2] );
80 
81 #ifdef G4VERBOSE
83  {
84  G4cout << " G4tgrParameterMgr::AddParameterNumber() -"
85  << " parameter added " << wl[1]
86  << " = " << theParameterList[ wl[1] ] << G4endl;
87  }
88 #endif
89 }
90 
91 
92 //-------------------------------------------------------------
93 void G4tgrParameterMgr::AddParameterString( const std::vector<G4String>& wl,
94  G4bool mustBeNew )
95 {
96  CheckIfNewParameter( wl, mustBeNew );
97 
98  //----- Store parameter as string
99  theParameterList[ wl[1] ] = wl[2];
100 
101 #ifdef G4VERBOSE
103  {
104  G4cout << " G4tgrParameterMgr::AddParameterString() -"
105  << " parameter added " << wl[1]
106  << " = " << theParameterList[ wl[1] ] << G4endl;
107  }
108 #endif
109 }
110 
111 //-------------------------------------------------------------
112 void G4tgrParameterMgr::CheckIfNewParameter( const std::vector<G4String>& wl,
113  G4bool mustBeNew )
114 {
115  //---------- Find first if it exists already
116  G4bool existsAlready;
117  G4mapss::iterator sdite = theParameterList.find( wl[1] );
118  if( sdite == theParameterList.end() )
119  {
120  existsAlready = false;
121  }
122  else
123  {
124  existsAlready = true;
125  }
126 
127  if(existsAlready)
128  {
129  if( mustBeNew )
130  {
131  G4String ErrMessage = "Parameter already exists... " + wl[1];
132  G4Exception("G4tgrParameterMgr::CheckParameter()",
133  "IllegalConstruct", FatalException, ErrMessage);
134  }
135  else
136  {
137  G4String WarMessage = "Parameter already exists... " + wl[1];
138  G4Exception("G4tgrParameterMgr::CheckParameter()",
139  "NotRecommended", JustWarning, WarMessage);
140  }
141  }
142 
143  //---------- Check for miminum number of words read
144  G4tgrUtils::CheckWLsize( wl, 3, WLSIZE_EQ, "Parameter::AddParameter");
145 }
146 
147 
148 //-------------------------------------------------------------
150 {
151  G4String par = "";
152 
153  G4mapss::iterator sdite = theParameterList.find( name );
154  if( sdite == theParameterList.end() )
155  {
156  if( exists )
157  {
158  DumpList();
159  G4String ErrMessage = "Parameter not found in list: " + name;
160  G4Exception("G4tgrParameterMgr::FindParameter()",
161  "InvalidSetup", FatalException, ErrMessage);
162  }
163  }
164  else
165  {
166  exists = 1;
167  par = ((*sdite).second);
168 #ifdef G4VERBOSE
170  {
171  G4cout << " G4tgrParameterMgr::FindParameter() -"
172  << " parameter found " << name << " = " << par << G4endl;
173  }
174 #endif
175  }
176 
177  return par;
178 }
179 
180 
181 //-------------------------------------------------------------
183 {
184  //---------- Dump number of objects of each class
185  G4cout << " @@@@@@@@@@@@@@@@@@ Dumping parameter list " << G4endl;
186  G4mapss::const_iterator cite;
187  for( cite = theParameterList.begin();cite != theParameterList.end(); cite++ )
188  {
189  G4cout << (*cite).first << " = " << (*cite).second << G4endl;
190  }
191 }