source: trunk/examples/advanced/radiation_monitor/application/src/RadmonApplication.cc @ 1321

Last change on this file since 1321 was 807, checked in by garnier, 16 years ago

update

File size: 13.6 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// File name:     RadmonApplication.cc
28// Creation date: Sep 2005
29// Main author:   Riccardo Capra <capra@ge.infn.it>
30//
31// Id:            $Id: RadmonApplication.cc,v 1.12.2.2 2006/06/29 16:08:29 gunter Exp $
32// Tag:           $Name: geant4-09-01-patch-02 $
33//
34
35// Include files
36#include "RadmonApplication.hh"
37#include "RadmonApplicationOptions.hh"
38
39#include "RadmonDetectorLayout.hh"
40#include "RadmonDetectorConstruction.hh"
41#include "RadmonDetectorLabelledEntitiesConstructorsFactory.hh"
42#include "RadmonDetectorMessenger.hh"
43
44#include "RadmonGeneratorLayout.hh"
45#include "RadmonPrimaryGeneratorAction.hh"
46#include "RadmonGeneratorsWithLabelFactory.hh"
47#include "RadmonGeneratorMessenger.hh"
48
49#include "RadmonPhysicsLayout.hh"
50#include "RadmonPhysicsList.hh"
51#include "RadmonSubPhysicsListWithLabelFactory.hh"
52#include "RadmonPhysicsMessenger.hh"
53
54#ifdef G4ANALYSIS_USE
55 #include "RadmonAnalysisLayout.hh"
56 #include "RadmonAnalysis.hh"
57 #include "RadmonDataAnalysisWithLabelFactory.hh"
58 #include "RadmonAnalysisMessenger.hh"
59#endif /* G4ANALYSIS_USE */
60
61#include "RadmonEventAction.hh"
62#include "RadmonSteppingAction.hh"
63#include "RadmonApplicationMessenger.hh"
64
65#include "G4RunManager.hh"
66#include "G4UImanager.hh"
67#include "G4UIdirectory.hh"
68#include "G4UIterminal.hh"
69#include "G4UItcsh.hh"
70
71#ifdef    G4VIS_USE
72 #include "G4VisExecutive.hh"
73#endif /* G4VIS_USE */
74
75
76
77                                                RadmonApplication :: RadmonApplication(const RadmonApplicationOptions & options)
78:
79 RadmonApplicationDetectorSetup(options),
80 RadmonApplicationGeneratorSetup(options),
81 RadmonApplicationPhysicsSetup(options),
82 #ifdef    G4ANALYSIS_USE
83  RadmonApplicationAnalysisSetup(options),
84 #endif /* G4ANALYSIS_USE */
85 valid(false),
86 runManager(0),
87 detectorLayout(0),
88 generatorLayout(0),
89 physicsLayout(0),
90 #ifdef    G4ANALYSIS_USE
91  analysisLayout(0),
92 #endif /* G4ANALYSIS_USE */
93 detectorsFactory(0),
94 generatorsFactory(0),
95 physicsFactory(0),
96 #ifdef    G4ANALYSIS_USE
97  analysisFactory(0),
98  analysis(0),
99 #endif /* G4ANALYSIS_USE */
100 #ifdef    G4VIS_USE
101  visManager(0),
102 #endif /* G4VIS_USE */
103 uiManager(0),
104 detectorMessenger(0),
105 generatorMessenger(0),
106 physicsMessenger(0),
107 #ifdef    G4ANALYSIS_USE
108  analysisMessenger(0),
109 #endif /* G4ANALYSIS_USE */
110 applicationMessenger(0),
111 session(0),
112 directory(0)
113{
114 // Construct the default run manager
115 runManager=new G4RunManager();
116 
117 if (runManager==0)
118 {
119  G4cerr << options.ApplicationName() << ": Run manager not allocated." << G4endl;
120  return;
121 }
122 
123 
124 // Construct the detector layout
125 detectorLayout=new RadmonDetectorLayout;
126 
127 if (detectorLayout==0)
128 {
129  G4cerr << options.ApplicationName() << ": Detector layout not allocated." << G4endl;
130  return;
131 }
132 
133 
134 // Construct the generator layout
135 generatorLayout=new RadmonGeneratorLayout;
136 
137 if (generatorLayout==0)
138 {
139  G4cerr << options.ApplicationName() << ": Generator layout not allocated." << G4endl;
140  return;
141 }
142 
143 
144 // Construct the physics list layout
145 physicsLayout=new RadmonPhysicsLayout;
146 
147 if (physicsLayout==0)
148 {
149  G4cerr << options.ApplicationName() << ": Physics list layout not allocated." << G4endl;
150  return;
151 }
152 
153 
154 // Construct the analysis list layout
155 #ifdef    G4ANALYSIS_USE
156  analysisLayout=new RadmonAnalysisLayout;
157 
158  if (analysisLayout==0)
159  {
160   G4cerr << options.ApplicationName() << ": Analysis layout not allocated." << G4endl;
161   return;
162  }
163 #endif /* G4ANALYSIS_USE */ 
164 
165 
166 // Construct the detectors factory
167 detectorsFactory=new RadmonDetectorLabelledEntitiesConstructorsFactory;
168 
169 if (detectorsFactory==0)
170 {
171  G4cerr << options.ApplicationName() << ": Detectors factory not allocated." << G4endl;
172  return;
173 }
174 
175 
176 // Construct the entity constructors
177 if (!CreateDetectorEntityConstructors(detectorsFactory))
178 {
179  G4cerr << options.ApplicationName() << ": Entity constructors not allocated." << G4endl;
180  return;
181 }
182 
183 
184 // Construct the generators factory
185 generatorsFactory=new RadmonGeneratorsWithLabelFactory;
186 
187 if (generatorsFactory==0)
188 {
189  G4cerr << options.ApplicationName() << ": Generators factory not allocated." << G4endl;
190  return;
191 }
192 
193 
194 // Construct the generators algorithms
195 if (!CreateGenerators(generatorsFactory))
196 {
197  G4cerr << options.ApplicationName() << ": Generator algorithms not allocated." << G4endl;
198  return;
199 }
200 
201 
202 // Construct the physics list factory
203 physicsFactory=new RadmonSubPhysicsListWithLabelFactory;
204 
205 if (physicsFactory==0)
206 {
207  G4cerr << options.ApplicationName() << ": Physics list factory not allocated." << G4endl;
208  return;
209 }
210 
211 
212 // Construct the sub physics lists
213 if (!CreateSubPhysicsList(physicsFactory))
214 {
215  G4cerr << options.ApplicationName() << ": Sub physics lists not allocated." << G4endl;
216  return;
217 }
218 
219 
220 // Construct the analysis list factory
221 #ifdef    G4ANALYSIS_USE
222  analysisFactory=new RadmonDataAnalysisWithLabelFactory;
223 
224  if (analysisFactory==0)
225  {
226   G4cerr << options.ApplicationName() << ": Analysis factory not allocated." << G4endl;
227   return;
228  }
229 
230 
231  // Construct the data analyses
232  if (!CreateDataAnalysis(analysisFactory))
233  {
234   G4cerr << options.ApplicationName() << ": Data analyses not allocated." << G4endl;
235   return;
236  }
237 #endif /* G4ANALYSIS_USE */
238 
239 
240 // Construct the physics list
241 RadmonPhysicsList * physicsList(new RadmonPhysicsList(physicsLayout, physicsFactory));
242 
243 if (physicsList==0)
244 {
245  G4cerr << options.ApplicationName() << ": Physics list not allocated." << G4endl;
246  return;
247 }
248 
249 
250 // The subphysics list factory will be owned by the physicsList
251 physicsFactory=0;
252 
253 runManager->SetUserInitialization(physicsList);
254 
255           
256 // Construct the detector construction
257 RadmonDetectorConstruction * detectorConstruction(new RadmonDetectorConstruction(detectorLayout, detectorsFactory));
258 
259 if (detectorConstruction==0)
260 {
261  G4cerr << options.ApplicationName() << ": Detector construction not allocated." << G4endl;
262  return;
263 }
264 
265 
266 // The detectors factory will be owned by the detectorConstruction
267 detectorsFactory=0; 
268 
269 runManager->SetUserInitialization(detectorConstruction);
270 
271
272 // Construct the primary generator
273 RadmonPrimaryGeneratorAction * primaryGenerator(new RadmonPrimaryGeneratorAction(generatorLayout, generatorsFactory));
274 
275 if (detectorConstruction==0)
276 {
277  G4cerr << options.ApplicationName() << ": Primary generator not allocated." << G4endl;
278  return;
279 }
280 
281 
282 // The primary generators factory will be owned by the primaryGenerator
283 generatorsFactory=0;
284 
285 runManager->SetUserAction(primaryGenerator);
286 
287           
288 // Construct the analysis
289 #ifdef    G4ANALYSIS_USE
290  AIDA::IAnalysisFactory * aida(AIDA_createAnalysisFactory());
291 
292  if (aida==0)
293  {
294   G4cerr << options.ApplicationName() << ": AIDA_createAnalysisFactory returned 0." << G4endl;
295   return;
296  }
297 
298  analysis=new RadmonAnalysis(analysisLayout, analysisFactory, aida);
299 
300  if (analysis==0)
301  {
302   delete aida;
303   G4cerr << options.ApplicationName() << ": Analysis not allocated." << G4endl;
304   return;
305  }
306 
307  // The data analyses factory will be owned by the analysis
308  analysisFactory=0;
309 
310  RadmonEventAction * eventAction(RadmonEventAction::Instance());
311  eventAction->AttachObserver(analysis);
312 #endif /* G4ANALYSIS_USE */
313           
314 // Initialize the run manager (disabled in order to have UI physics list)
315 // runManager->Initialize();
316
317 
318 // Construct the visualization manager
319 #ifdef    G4VIS_USE
320  G4VisManager * visManager(new G4VisExecutive);
321 
322  if (visManager==0)
323  {
324   G4cerr << options.ApplicationName() << ": Vis manager not allocated." << G4endl;
325   return;
326  }
327 
328  visManager->Initialize();
329 #endif /* G4VIS_USE */
330 
331 
332 // Gets the user interface
333 uiManager = G4UImanager::GetUIpointer();
334 
335 if (uiManager==0)
336 {
337  G4cerr << options.ApplicationName() << ": UI manager not allocated." << G4endl;
338  return;
339 }
340
341
342 // Construct the Radmon directory
343 directory = new G4UIdirectory("/radmon/");
344 
345 if (directory==0)
346 {
347  G4cerr << options.ApplicationName() << ": Radmon directory not allocated." << G4endl;
348  return;
349 }
350 
351 directory->SetGuidance("Radmon application directory.");
352
353
354 // Construct the messenger to modify the detector layout
355 detectorMessenger=new RadmonDetectorMessenger(detectorLayout);
356 
357 if (detectorMessenger==0)
358 {
359  G4cerr << options.ApplicationName() << ": Detector layout messenger not allocated." << G4endl;
360  return;
361 }
362 
363 
364 // Construct the messenger to modify the generator layout
365 generatorMessenger=new RadmonGeneratorMessenger(generatorLayout);
366 
367 if (generatorMessenger==0)
368 {
369  G4cerr << options.ApplicationName() << ": Generator layout messenger not allocated." << G4endl;
370  return;
371 }
372 
373 
374 // Construct the messenger to modify the physics list layout
375 physicsMessenger=new RadmonPhysicsMessenger(physicsLayout);
376 
377 if (physicsMessenger==0)
378 {
379  G4cerr << options.ApplicationName() << ": Physics list layout messenger not allocated." << G4endl;
380  return;
381 }
382 
383 
384 // Construct the messenger to modify the analysis layout
385 #ifdef    G4ANALYSIS_USE
386  analysisMessenger=new RadmonAnalysisMessenger(analysisLayout);
387 
388  if (analysisMessenger==0)
389  {
390   G4cerr << options.ApplicationName() << ": Analysis layout messenger not allocated." << G4endl;
391   return;
392  }
393 #endif /* G4ANALYSIS_USE */
394 
395 
396 // Construct the messenger to modify applications options
397 applicationMessenger=new RadmonApplicationMessenger;
398 
399 if (applicationMessenger==0)
400 {
401  G4cerr << options.ApplicationName() << ": Application messenger not allocated." << G4endl;
402  return;
403 }
404 
405 
406 // Construct the interactive session
407 if (options.Interactive())
408 {
409  session=new G4UIterminal(new G4UItcsh);
410 
411  if (session==0)
412  {
413   G4cerr << options.ApplicationName() << ": Interactive session not allocated." << G4endl;
414   return;
415  }
416 }
417 
418 
419 // Runs startup macros
420 RunMacro(options, options.StartupFileName());
421 
422 if (options.FileName())
423  if (!RunMacro(options, options.FileName()))
424  {
425   G4cerr << options.ApplicationName() << ": File \"" << options.FileName() << "\" not found." << G4endl; 
426   return;
427  }
428 
429 // Runs the interactive session
430 if (options.Interactive())
431 {
432  if (options.Verbose())
433   G4cout << options.ApplicationName() << ": Interactive session starts ..." << G4endl;
434 
435  session->SessionStart();
436 }
437 
438 valid=true;
439}
440
441
442
443                                                RadmonApplication :: ~RadmonApplication()
444{
445 // Desctruct the interactive session
446 delete session;
447
448 // Destruct the messenger to modify applications options
449 delete applicationMessenger; 
450
451 // Destruct the analysis messenger to modify the layout
452 #ifdef    G4ANALYSIS_USE
453  delete analysisMessenger; 
454 #endif /* G4ANALYSIS_USE */
455 
456 // Destruct the physics list messenger to modify the layout
457 delete physicsMessenger;
458 
459 // Destruct the generator messenger to modify the layout
460 delete generatorMessenger;
461 
462 // Destruct the detector messenger to modify the layout
463 delete detectorMessenger;
464 
465 // Destruct the Radmon directory
466 delete directory;
467 
468 // Destruct the visualization manager
469 #ifdef    G4VIS_USE
470  delete visManager;
471 #endif /* G4VIS_USE */
472
473 // Destruct the analysis
474 #ifdef    G4ANALYSIS_USE
475  delete analysis; 
476
477  // Destruct the analyses factory
478  delete analysisFactory; 
479 #endif /* G4ANALYSIS_USE */
480 
481 // Destruct the sub physics list factory
482 delete physicsFactory;
483
484 // Destruct the generators factory
485 delete generatorsFactory;
486
487 // Destruct the detectors factory
488 delete detectorsFactory;
489
490 // Destruct the default run manager
491 delete runManager;
492 
493 // Destruct the analysis layout
494 #ifdef    G4ANALYSIS_USE
495  delete analysisLayout; 
496 #endif /* G4ANALYSIS_USE */
497
498 // Destruct the physics list layout
499 delete physicsLayout; 
500
501 // Destruct the generator layout
502 delete generatorLayout; 
503
504 // Destruct the detector layout
505 delete detectorLayout; 
506}
507
508
509
510
511
512G4bool                                          RadmonApplication :: RunMacro(const RadmonApplicationOptions & options, const char * fileName)
513{
514 std::ifstream test(fileName);
515 
516 if (!test.good())
517  return false;
518 
519 test.close();
520 
521 if (options.Verbose())
522  G4cout << options.ApplicationName() << ": Running macro \"" << fileName << "\" ..." << G4endl;
523
524 G4String command("/control/execute ");
525 command+=fileName;
526 uiManager->ApplyCommand(command);
527 
528 return true;
529}
Note: See TracBrowser for help on using the repository browser.