source: trunk/source/geometry/solids/test/fred/src/FredTest3Messenger.cc@ 1350

Last change on this file since 1350 was 1316, checked in by garnier, 15 years ago

update geant4-09-04-beta-cand-01 interfaces-V09-03-09 vis-V09-03-08

File size: 10.9 KB
Line 
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// FredTest3Messenger.cc
28//
29// Implementation of the messenger for controlling test 3
30//
31
32#include "FredTest3Messenger.hh"
33#include "FredTest3.hh"
34
35#include "G4ios.hh"
36#include "G4UIdirectory.hh"
37#include "G4UIcommand.hh"
38#include "G4UIcmdWith3VectorAndUnit.hh"
39#include "G4UIcmdWithAnInteger.hh"
40#include "G4UIcmdWithAString.hh"
41#include "G4UIcmdWithoutParameter.hh"
42
43#include <fstream>
44
45//
46// Constructor
47//
48FredTest3Messenger::FredTest3Messenger()
49{
50 //
51 // Defaults (of locally stored values)
52 //
53 errorFile = "test3.log";
54
55 //
56 // Create tester
57 //
58 tester = new FredTest3();
59
60 //
61 // Declare directory
62 //
63 test3Directory = new G4UIdirectory( "/fred/test3/" );
64 test3Directory->SetGuidance( "Controls for volume test 3" );
65
66 //
67 // Target command
68 //
69 targetCmd = new G4UIcmdWith3VectorAndUnit( "/fred/test3/target", this );
70 targetCmd->SetGuidance( "Center of distribution of random points" );
71 targetCmd->SetParameterName( "X", "Y", "Z", true, true );
72
73 //
74 // Widths command
75 //
76 widthsCmd = new G4UIcmdWith3VectorAndUnit( "/fred/test3/widths", this );
77 widthsCmd->SetGuidance( "Widths of distribution of random points" );
78 widthsCmd->SetParameterName( "Dx", "Dy", "Dz", true, true );
79
80 //
81 // Grid Size command
82 //
83 gridSizesCmd = new G4UIcmdWith3VectorAndUnit( "/fred/test3/gridSizes", this );
84 gridSizesCmd->SetGuidance( "Grid size, or zero for no grid" );
85 gridSizesCmd->SetParameterName( "Dx", "Dy", "Dz", true, true );
86
87 //
88 // Max Points command
89 //
90 maxPointsCmd = new G4UIcmdWithAnInteger( "/fred/test3/maxPoints", this );
91 maxPointsCmd->SetGuidance( "Maximum number of points before test ends" );
92
93 //
94 // Max Errors command
95 //
96 maxErrorsCmd = new G4UIcmdWithAnInteger( "/fred/test3/maxErrors", this );
97 maxErrorsCmd->SetGuidance( "Maximum number of errors before test ends" );
98
99 //
100 // Error filename command
101 //
102 errorFileCmd = new G4UIcmdWithAString( "/fred/test3/errorFileName", this );
103 errorFileCmd->SetGuidance( "Filename in which to send error listings" );
104
105 //
106 // Run command
107 //
108 runCmd = new G4UIcmdWithoutParameter( "/fred/test3/run", this );
109 runCmd->SetGuidance( "Execute test 3" );
110
111 //
112 // Run debug command
113 //
114 runDebugCmd = new G4UIcmdWithoutParameter( "/fred/test3/runDebug", this );
115 runDebugCmd->SetGuidance( "Debug all errors listed in log file" );
116
117 //
118 // Debug commands
119 //
120 debugCmd = new G4UIcmdWithAnInteger( "/fred/test3/debug", this );
121 debugCmd->SetGuidance( "Debug error listed in log file" );
122
123 debugInsideCmd = new G4UIcmdWithAnInteger( "/fred/test3/debugInside", this );
124 debugInsideCmd->SetGuidance( "Call G4VSolid::Inside for error listed in log file" );
125
126 debugToInPCmd = new G4UIcmdWithAnInteger( "/fred/test3/debugToInP", this );
127 debugToInPCmd->SetGuidance( "Call G4VSolid::DistanceToIn(p) for error listed in log file" );
128
129 debugToInPVCmd = new G4UIcmdWithAnInteger( "/fred/test3/debugToInPV", this );
130 debugToInPVCmd->SetGuidance( "Call G4VSolid::DistanceToIn(p,v) for error listed in log file" );
131
132 debugToOutPCmd = new G4UIcmdWithAnInteger( "/fred/test3/debugToOutP", this );
133 debugToOutPCmd->SetGuidance( "Call G4VSolid::DistanceToOut(p) for error listed in log file" );
134
135 debugToOutPVCmd = new G4UIcmdWithAnInteger( "/fred/test3/debugToOutPV", this );
136 debugToOutPVCmd->SetGuidance( "Call G4VSolid::DistanceToOut(p,v) for error listed in log file" );
137}
138
139
140//
141// Destructor
142//
143FredTest3Messenger::~FredTest3Messenger()
144{
145 delete targetCmd;
146 delete widthsCmd;
147 delete gridSizesCmd;
148 delete maxPointsCmd;
149 delete maxErrorsCmd;
150 delete errorFileCmd;
151 delete test3Directory;
152}
153
154
155//
156// InvokeTest3
157//
158// Run test 3
159//
160void FredTest3Messenger::InvokeTest3()
161{
162 //
163 // Is there a volume to test?
164 //
165 if (testVolume == 0) {
166 G4cerr << "Please initialize geometry before running test 3" << G4endl;
167 G4cerr << "Test 3 ABORTED" << G4endl;
168 return;
169 }
170
171 //
172 // Open output file
173 //
174 std::ofstream logFile( errorFile );
175
176 //
177 // Run the test
178 //
179 tester->RunTest( testVolume, logFile );
180}
181
182
183//
184// InvokeRunDebug
185//
186//
187void FredTest3Messenger::InvokeRunDebug()
188{
189 //
190 // Is there a volume to test?
191 //
192 // If I was really clever (I'm not) I would also check
193 // to make sure we have the same volume type and even the
194 // same volume parameters.
195 //
196 if (testVolume == 0) {
197 G4cerr << "Please initialize geometry before running test 3" << G4endl;
198 return;
199 }
200
201 //
202 // Open input file
203 //
204 std::ifstream logFile( errorFile );
205 if (!logFile) {
206 G4cerr << "Cannot open input file " << errorFile << G4endl;
207 return;
208 }
209
210 //
211 // Debug run
212 //
213
214 // Run the debug test
215 //
216 tester->RunDebug( testVolume, logFile );
217}
218
219
220//
221// DebugError
222//
223// Run an event that should (approximately) duplicate the conditions
224// of one of the bugs discovered in a previous test3 run and stored
225// in a log file
226//
227void FredTest3Messenger::Debug( const G4int errorIndex, FredTest3Messenger::Debugger *debugger )
228{
229 //
230 // Is there a volume to test?
231 //
232 // If I was really clever (I'm not) I would also check
233 // to make sure we have the same volume type and even the
234 // same volume parameters.
235 //
236 if (testVolume == 0) {
237 G4cerr << "Please initialize geometry before running test 3" << G4endl;
238 return;
239 }
240
241 //
242 // Open output file
243 //
244 std::ifstream logFile( errorFile );
245 if (!logFile) {
246 G4cerr << "Cannot open input file " << errorFile << G4endl;
247 return;
248 }
249
250 //
251 // Debug
252 //
253 if (debugger->DebugMe( logFile, errorIndex )) {
254 G4cerr << "Error reading index " << errorIndex << " from input file " << errorFile << G4endl;
255 }
256}
257
258
259//
260// DebugMe (various classes)
261//
262G4int FredTest3Messenger::DebugError::DebugMe( std::ifstream &logFile, const G4int errorIndex )
263{
264 return tester->DebugError( testVolume, logFile, errorIndex );
265}
266
267G4int FredTest3Messenger::DebugInside::DebugMe( std::ifstream &logFile, const G4int errorIndex )
268{
269 return tester->DebugInside( testVolume, logFile, errorIndex );
270}
271
272G4int FredTest3Messenger::DebugToInP::DebugMe( std::ifstream &logFile, const G4int errorIndex )
273{
274 return tester->DebugToInP( testVolume, logFile, errorIndex );
275}
276
277G4int FredTest3Messenger::DebugToInPV::DebugMe( std::ifstream &logFile, const G4int errorIndex )
278{
279 return tester->DebugToInPV( testVolume, logFile, errorIndex );
280}
281
282G4int FredTest3Messenger::DebugToOutP::DebugMe( std::ifstream &logFile, const G4int errorIndex )
283{
284 return tester->DebugToOutP( testVolume, logFile, errorIndex );
285}
286
287G4int FredTest3Messenger::DebugToOutPV::DebugMe( std::ifstream &logFile, const G4int errorIndex )
288{
289 return tester->DebugToOutPV( testVolume, logFile, errorIndex );
290}
291
292
293//
294// SetNewValue
295//
296// Call by the UI when user requests a change
297//
298void FredTest3Messenger::SetNewValue( G4UIcommand *command, G4String newValues )
299{
300 if (command == targetCmd) {
301 tester->SetTarget( targetCmd->GetNew3VectorValue( newValues ) );
302 }
303 else if (command == widthsCmd) {
304 tester->SetWidths( widthsCmd->GetNew3VectorValue( newValues ) );
305 }
306 else if (command == gridSizesCmd) {
307 tester->SetGrids( gridSizesCmd->GetNew3VectorValue( newValues ) );
308 }
309 else if (command == maxPointsCmd) {
310 tester->SetMaxPoints( maxPointsCmd->GetNewIntValue( newValues ) );
311 }
312 else if (command == maxErrorsCmd) {
313 tester->SetMaxErrors( maxErrorsCmd->GetNewIntValue( newValues ) );
314 }
315 else if (command == errorFileCmd) {
316 errorFile = newValues;
317 }
318 else if (command == runCmd) {
319 InvokeTest3();
320 }
321 else if (command == runDebugCmd) {
322 InvokeRunDebug();
323 }
324 else if (command == debugCmd) {
325 FredTest3Messenger::DebugError debugger( testVolume, tester );
326 Debug( debugCmd->GetNewIntValue( newValues ), &debugger );
327 }
328 else if (command == debugInsideCmd) {
329 FredTest3Messenger::DebugInside debugger( testVolume, tester );
330 Debug( debugInsideCmd->GetNewIntValue( newValues ), &debugger );
331 }
332 else if (command == debugToInPCmd) {
333 FredTest3Messenger::DebugToInP debugger( testVolume, tester );
334 Debug( debugToInPCmd->GetNewIntValue( newValues ), &debugger );
335 }
336 else if (command == debugToInPVCmd) {
337 FredTest3Messenger::DebugToInPV debugger( testVolume, tester );
338 Debug( debugToInPVCmd->GetNewIntValue( newValues ), &debugger );
339 }
340 else if (command == debugToOutPCmd) {
341 FredTest3Messenger::DebugToOutP debugger( testVolume, tester );
342 Debug( debugToOutPCmd->GetNewIntValue( newValues ), &debugger );
343 }
344 else if (command == debugToOutPVCmd) {
345 FredTest3Messenger::DebugToOutPV debugger( testVolume, tester );
346 Debug( debugToOutPVCmd->GetNewIntValue( newValues ), &debugger );
347 }
348 else {
349 G4Exception( "Unrecognized command" );
350 }
351}
352
353
354//
355// GetCurrentValue
356//
357G4String FredTest3Messenger::GetCurrentValue( G4UIcommand *command )
358{
359 if (command == targetCmd) {
360 return targetCmd->ConvertToString( tester->GetTarget(), "m" );
361 }
362 else if (command == widthsCmd) {
363 return widthsCmd->ConvertToString( tester->GetWidths(), "m" );
364 }
365 else if (command == gridSizesCmd) {
366 return gridSizesCmd->ConvertToString( tester->GetGrids(), "m" );
367 }
368 else if (command == maxPointsCmd) {
369 return maxPointsCmd->ConvertToString( tester->GetMaxPoints() );
370 }
371 else if (command == maxErrorsCmd) {
372 return maxErrorsCmd->ConvertToString( tester->GetMaxErrors() );
373 }
374 else if (command == errorFileCmd) {
375 return errorFile;
376 }
377 else if (command == runCmd) {
378 return "";
379 }
380 else if (command == runDebugCmd) {
381 return "";
382 }
383 else if (command == debugCmd ||
384 command == debugInsideCmd ||
385 command == debugToInPCmd ||
386 command == debugToInPVCmd ||
387 command == debugToOutPCmd ||
388 command == debugToOutPVCmd ) {
389 return "";
390 }
391
392 G4Exception( "Unrecognized command" );
393 return "";
394}
395
Note: See TracBrowser for help on using the repository browser.