Geant4  10.01
load_gdml.cc
Go to the documentation of this file.
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 //
28 //
29 //
30 // $Id: load_gdml.cc 82284 2014-06-13 14:50:49Z gcosmo $
31 //
32 //
33 // --------------------------------------------------------------
34 // GEANT 4 - load_gdml
35 //
36 // --------------------------------------------------------------
37 
38 #include <vector>
39 
40 #include "G4RunManager.hh"
41 #include "G4UImanager.hh"
42 
43 #include "G4LogicalVolumeStore.hh"
45 
48 #include "FTFP_BERT.hh"
49 
50 #ifdef G4VIS_USE
51 #include "G4VisExecutive.hh"
52 #endif
53 
54 #ifdef G4UI_USE
55 #include "G4UIExecutive.hh"
56 #endif
57 
58 #include "G4GDMLParser.hh"
59 
60 int main(int argc,char **argv)
61 {
62  G4cout << G4endl;
63  G4cout << "Usage: load_gdml <intput_gdml_file:mandatory>"
64  << " <output_gdml_file:optional>" << G4endl;
65  G4cout << G4endl;
66 
67  if (argc<2)
68  {
69  G4cout << "Error! Mandatory input file is not specified!" << G4endl;
70  G4cout << G4endl;
71  return -1;
72  }
73 
75 
76 // Uncomment the following if wish to avoid names stripping
77 // parser.SetStripFlag(false);
78 
79  parser.Read(argv[1]);
80 
81  if (argc>4)
82  {
83  G4cout << "Error! Too many arguments!" << G4endl;
84  G4cout << G4endl;
85  return -1;
86  }
87 
88  G4RunManager* runManager = new G4RunManager;
89 
91  parser.GetWorldVolume()));
92  runManager->SetUserInitialization(new FTFP_BERT);
94 
95  runManager->Initialize();
96 
97  if (argc>=3)
98  {
100  ->GetNavigatorForTracking()->GetWorldVolume()->GetLogicalVolume());
101  }
102 
103  G4UImanager* UImanager = G4UImanager::GetUIpointer();
104 
106  //
107  // Example how to retrieve Auxiliary Information
108  //
110  std::vector<G4LogicalVolume*>::const_iterator lvciter;
111  for( lvciter = lvs->begin(); lvciter != lvs->end(); lvciter++ )
112  {
113  G4GDMLAuxListType auxInfo = parser.GetVolumeAuxiliaryInformation(*lvciter);
114  std::vector<G4GDMLAuxPairType>::const_iterator ipair = auxInfo.begin();
115  for( ipair = auxInfo.begin(); ipair != auxInfo.end(); ipair++ )
116  {
117  G4String str=ipair->type;
118  G4String val=ipair->value;
119  G4cout << " Auxiliary Information is found for Logical Volume : "
120  << (*lvciter)->GetName() << G4endl;
121  G4cout << " Name of Auxiliary type is : " << str << G4endl;
122  G4cout << " Associated Auxiliary value is : " << val << G4endl;
123  }
124  }
125  //
126  // End of Auxiliary Information block
127  //
129 
130  if (argc==4) // batch mode
131  {
132  G4String command = "/control/execute ";
133  G4String fileName = argv[3];
134  UImanager->ApplyCommand(command+fileName);
135  }
136  else // interactive mode
137  {
138 #ifdef G4UI_USE
139  G4UIExecutive* ui = new G4UIExecutive(argc, argv);
140 #ifdef G4VIS_USE
141  G4VisManager* visManager = new G4VisExecutive;
142  visManager->Initialize();
143  UImanager->ApplyCommand("/control/execute vis.mac");
144 #endif
145  ui->SessionStart();
146 #ifdef G4VIS_USE
147  delete visManager;
148 #endif
149  delete ui;
150 #endif
151  }
152 
153  delete runManager;
154 
155  return 0;
156 }
int main(int argc, char **argv)
Definition: load_gdml.cc:60
Minimal primary generator action to demonstrate the use of GDML geometries.
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)
G4GDMLAuxListType GetVolumeAuxiliaryInformation(G4LogicalVolume *logvol) const
Definition of the G01DetectorConstruction class.
G4VPhysicalVolume * GetWorldVolume(const G4String &setupName="Default") const
Detector construction allowing to use the geometry read from the GDML file.
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
G4GLOB_DLL std::ostream G4cout
static G4LogicalVolumeStore * GetInstance()
void Write(const G4String &filename, const G4VPhysicalVolume *pvol=0, G4bool storeReferences=true, const G4String &SchemaLocation=G4GDML_DEFAULT_SCHEMALOCATION)
CommandLineParser * parser(0)
static G4TransportationManager * GetTransportationManager()
void Initialize()
std::vector< G4GDMLAuxPairType > G4GDMLAuxListType
void Read(const G4String &filename, G4bool Validate=true)
Definition of the G01PrimaryGeneratorAction class.
virtual void Initialize()
#define G4endl
Definition: G4ios.hh:61
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:432
virtual void SetUserAction(G4UserRunAction *userAction)