Loading...
Searching...
No Matches
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//
26/// \file persistency/gdml/G01/load_gdml.cc
27/// \brief Main program of the persistency/gdml/G01 example
28//
29//
30//
31//
32// --------------------------------------------------------------
33// GEANT 4 - load_gdml
34//
35// --------------------------------------------------------------
36
37#include <vector>
38
39#include "G4Types.hh"
40
41#include "G4RunManagerFactory.hh"
42
43#include "G4UImanager.hh"
44
45#include "G4LogicalVolumeStore.hh"
46#include "G4TransportationManager.hh"
47
51
52#include "FTFP_BERT.hh"
53
54#include "G4VisExecutive.hh"
55#include "G4UIExecutive.hh"
56
57#include "G4GDMLParser.hh"
58
59void print_aux(const G4GDMLAuxListType* auxInfoList, G4String prepend="|")
60{
61 for(std::vector<G4GDMLAuxStructType>::const_iterator
62 iaux = auxInfoList->begin(); iaux != auxInfoList->end(); iaux++ )
63 {
64 G4String str=iaux->type;
65 G4String val=iaux->value;
66 G4String unit=iaux->unit;
67
68 G4cout << prepend << str << " : " << val << " " << unit << G4endl;
69
70 if (iaux->auxList) print_aux(iaux->auxList, prepend + "|");
71 }
72 return;
73}
74
75// --------------------------------------------------------------
76
77int main(int argc,char **argv)
78{
79 G4cout << G4endl;
80 G4cout << "Usage: load_gdml <intput_gdml_file:mandatory>"
81 << " <output_gdml_file:optional>" << G4endl;
82 G4cout << G4endl;
83
84 if (argc<2)
85 {
86 G4cout << "Error! Mandatory input file is not specified!" << G4endl;
87 G4cout << G4endl;
88 return -1;
89 }
90
91 G4GDMLParser parser;
92
93// Uncomment the following if wish to avoid names stripping
94// parser.SetStripFlag(false);
95
96// Uncomment the following and set a string with proper absolute path and
97// schema filename if wishing to use alternative schema for parsing validation
98// parser.SetImportSchema("");
99
100 parser.SetOverlapCheck(true);
101 parser.Read(argv[1]);
102
103 if (argc>4)
104 {
105 G4cout << "Error! Too many arguments!" << G4endl;
106 G4cout << G4endl;
107 return -1;
108 }
109
110 auto* runManager = G4RunManagerFactory::CreateRunManager();
111
112 runManager->SetUserInitialization(new G01DetectorConstruction(
113 parser.GetWorldVolume()));
114 runManager->SetUserInitialization(new FTFP_BERT);
115 runManager->SetUserInitialization(new G01ActionInitialization());
116
117 runManager->Initialize();
118
119 // Initialize visualization
120 G4VisManager* visManager = new G4VisExecutive;
121 visManager->Initialize();
122
123 // Get the pointer to the User Interface manager
124 G4UImanager* UImanager = G4UImanager::GetUIpointer();
125
126 ///////////////////////////////////////////////////////////////////////
127 //
128 // Example how to retrieve Auxiliary Information
129 //
130
131 G4cout << std::endl;
132
133 const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
134 std::vector<G4LogicalVolume*>::const_iterator lvciter;
135 for( lvciter = lvs->begin(); lvciter != lvs->end(); lvciter++ )
136 {
137 G4GDMLAuxListType auxInfo = parser.GetVolumeAuxiliaryInformation(*lvciter);
138
139 if (auxInfo.size()>0)
140 G4cout << "Auxiliary Information is found for Logical Volume : "
141 << (*lvciter)->GetName() << G4endl;
142
143 print_aux(&auxInfo);
144 }
145
146 // now the 'global' auxiliary info
147 G4cout << std::endl;
148 G4cout << "Global auxiliary info:" << std::endl;
149 G4cout << std::endl;
150
151 print_aux(parser.GetAuxList());
152
153 G4cout << std::endl;
154
155 //
156 // End of Auxiliary Information block
157 //
158 ////////////////////////////////////////////////////////////////////////
159
160
161 runManager->BeamOn(0);
162
163 // example of writing out
164
165 if (argc>=3)
166 {
167/*
168 G4GDMLAuxStructType mysubaux = {"mysubtype", "mysubvalue", "mysubunit", 0};
169 G4GDMLAuxListType* myauxlist = new G4GDMLAuxListType();
170 myauxlist->push_back(mysubaux);
171
172 G4GDMLAuxStructType myaux = {"mytype", "myvalue", "myunit", myauxlist};
173 parser.AddAuxiliary(myaux);
174
175
176 // example of setting auxiliary info for world volume
177 // (can be set for any volume)
178
179 G4GDMLAuxStructType mylocalaux = {"sometype", "somevalue", "someunit", 0};
180
181 parser.AddVolumeAuxiliary(mylocalaux,
182 G4TransportationManager::GetTransportationManager()
183 ->GetNavigatorForTracking()->GetWorldVolume()->GetLogicalVolume());
184*/
185
186 parser.SetRegionExport(true);
187 // parser.SetEnergyCutsExport(true);
188 // parser.SetOutputFileOverwrite(true);
189 parser.Write(argv[2], G4TransportationManager::GetTransportationManager()
190 ->GetNavigatorForTracking()->GetWorldVolume()->GetLogicalVolume());
191 }
192
193
194 if (argc==4) // batch mode
195 {
196 G4String command = "/control/execute ";
197 G4String fileName = argv[3];
198 UImanager->ApplyCommand(command+fileName);
199 }
200 else // interactive mode
201 {
202 G4UIExecutive* ui = new G4UIExecutive(argc, argv);
203 UImanager->ApplyCommand("/control/execute vis.mac");
204 ui->SessionStart();
205 delete ui;
206 }
207
208 delete visManager;
209 delete runManager;
210
211 return 0;
212}
Definition of the G01ActionInitialization class.
Definition of the G01DetectorConstruction class.
Definition of the G01PrimaryGeneratorAction class.
Action initialization class.
Detector construction allowing to use the geometry read from the GDML file.
void print_aux(const G4GDMLAuxListType *auxInfoList, G4String prepend="|")
Definition load_gdml.cc:59
int main()
Definition testCommon.cc:47

Applications | User Support | Publications | Collaboration