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