source: trunk/examples/extended/g3tog4/cltog4/cltog4.cc @ 812

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

update

File size: 4.1 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// $Id: cltog4.cc,v 1.6 2006/06/29 17:20:32 gunter Exp $
28// GEANT4 tag $Name:  $
29//
30//
31#include "G4ios.hh"
32#include <fstream>
33#include <cmath>
34
35// example header file includes
36
37#include "G3toG4DetectorConstruction.hh"
38#include "G3toG4RunAction.hh"
39#include "G3toG4PrimaryGeneratorAction.hh"
40#include "G3toG4PhysicsList.hh"
41#include "G4LogicalVolume.hh"
42#include "G3VolTable.hh"
43
44// geant4 includes
45
46#include "G4RunManager.hh"
47#include "G4UImanager.hh"
48#include "G4UIterminal.hh"
49
50int main(int argc, char** argv)
51{
52  G4String inFile;
53  G4String macroFile = "";
54 
55  if (argc < 2) {
56    G4cout << "Correct syntax:" << argv[0] << " <call_list_file> [ <macro_file> ]"
57           << G4endl;
58    G4cout << "If only one argument is specified, macro file " << macroFile
59           << "will be used." << G4endl
60           << "The second argument is used to override the default macro file"
61           << " name." << G4endl;
62   
63    return 1;
64  }
65  if (argc >= 2) {
66    // Process the command line
67    inFile = argv[1];
68    std::ifstream in(inFile);
69    if (!in) {
70      G4cout << "Cannot open input file """ << inFile << """" << G4endl;
71      return 1;
72    }
73  }
74  if (argc >= 3) {
75    macroFile = argv[2];
76    std::ifstream mac(macroFile);
77    if (!mac) {
78      G4cout << "Cannot open macro file """ << macroFile << """" << G4endl;
79      return 2;
80    }
81  }
82  if (argc >= 4) {
83    G4cout << "Too many command line arguments (" << argc <<")" << G4endl;
84    return 1;
85  }
86  // run manager
87  G4RunManager * RunManager = new G4RunManager;
88  // user initialization classes
89  RunManager->SetUserInitialization(new G3toG4DetectorConstruction(inFile));
90  RunManager->SetUserInitialization(new G3toG4PhysicsList);
91 
92  // user action classes
93  RunManager->SetUserAction(new G3toG4RunAction);
94  RunManager->SetUserAction(new G3toG4PrimaryGeneratorAction);
95
96  G4UImanager * UI = G4UImanager::GetUIpointer();
97  // set some additional defaults and initial actions
98 
99  UI->ApplyCommand("/control/verbose 1");
100  UI->ApplyCommand("/run/verbose 1");
101  UI->ApplyCommand("/tracking/verbose 1");
102  UI->ApplyCommand("/tracking/storeTrajectory 1");
103  UI->ApplyCommand("/run/initialize");
104 
105  G4bool batch_mode = macroFile != "";
106 
107  if(!batch_mode) {
108    G4UIsession * session = new G4UIterminal;
109    if (session != 0) {
110      session->SessionStart();
111      delete session;
112      //      G4cout << "deleted G4UITerminal..." << G4endl;
113    }
114  }
115  else {
116    // Batch mode
117    G4String command = "/control/execute ";
118    UI->ApplyCommand(command+macroFile);
119  }
120  delete RunManager;
121  return EXIT_SUCCESS;
122}
Note: See TracBrowser for help on using the repository browser.