Geant4  10.02.p02
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 89264 2015-03-30 08:18:11Z 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 void print_aux(const G4GDMLAuxListType* auxInfoList, G4String prepend="|")
61 {
62  for(std::vector<G4GDMLAuxStructType>::const_iterator iaux = auxInfoList->begin();
63  iaux != auxInfoList->end(); iaux++ )
64  {
65  G4String str=iaux->type;
66  G4String val=iaux->value;
67  G4String unit=iaux->unit;
68 
69  G4cout << prepend << str << " : " << val << " " << unit << G4endl;
70 
71  if (iaux->auxList) print_aux(iaux->auxList, prepend + "|");
72  }
73  return;
74 }
75 
76 
77 int 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 
92 
93 // Uncomment the following if wish to avoid names stripping
94 // parser.SetStripFlag(false);
95 
96  parser.Read(argv[1]);
97 
98  if (argc>4)
99  {
100  G4cout << "Error! Too many arguments!" << G4endl;
101  G4cout << G4endl;
102  return -1;
103  }
104 
105  G4RunManager* runManager = new G4RunManager;
106 
108  parser.GetWorldVolume()));
109  runManager->SetUserInitialization(new FTFP_BERT);
110  runManager->SetUserAction(new G01PrimaryGeneratorAction);
111 
112  runManager->Initialize();
113 
114  G4UImanager* UImanager = G4UImanager::GetUIpointer();
115 
117  //
118  // Example how to retrieve Auxiliary Information
119  //
120 
121  std::cout << std::endl;
122 
124  std::vector<G4LogicalVolume*>::const_iterator lvciter;
125  for( lvciter = lvs->begin(); lvciter != lvs->end(); lvciter++ )
126  {
127  G4GDMLAuxListType auxInfo = parser.GetVolumeAuxiliaryInformation(*lvciter);
128 
129  if (auxInfo.size()>0)
130  G4cout << "Auxiliary Information is found for Logical Volume : "
131  << (*lvciter)->GetName() << G4endl;
132 
133  print_aux(&auxInfo);
134  }
135 
136  // now the 'global' auxiliary info
137  std::cout << std::endl;
138  std::cout << "Global auxiliary info:" << std::endl;
139  std::cout << std::endl;
140 
141  print_aux(parser.GetAuxList());
142 
143  std::cout << std::endl;
144 
145  //
146  // End of Auxiliary Information block
147  //
149 
150  // example of writing out
151 
152  if (argc>=3)
153  {
154 /*
155  G4GDMLAuxStructType mysubaux = {"mysubtype", "mysubvalue", "mysubunit", 0};
156  G4GDMLAuxListType* myauxlist = new G4GDMLAuxListType();
157  myauxlist->push_back(mysubaux);
158 
159  G4GDMLAuxStructType myaux = {"mytype", "myvalue", "myunit", myauxlist};
160  parser.AddAuxiliary(myaux);
161 
162 
163  // example of setting auxiliary info for world volume (can be set for any volume)
164 
165  G4GDMLAuxStructType mylocalaux = {"sometype", "somevalue", "someunit", 0};
166 
167  parser.AddVolumeAuxiliary(mylocalaux, G4TransportationManager::GetTransportationManager()
168  ->GetNavigatorForTracking()->GetWorldVolume()->GetLogicalVolume());
169 */
170  parser.SetRegionExport(true);
172  ->GetNavigatorForTracking()->GetWorldVolume()->GetLogicalVolume());
173  }
174 
175 
176  if (argc==4) // batch mode
177  {
178  G4String command = "/control/execute ";
179  G4String fileName = argv[3];
180  UImanager->ApplyCommand(command+fileName);
181  }
182  else // interactive mode
183  {
184 #ifdef G4UI_USE
185  G4UIExecutive* ui = new G4UIExecutive(argc, argv);
186 #ifdef G4VIS_USE
187  G4VisManager* visManager = new G4VisExecutive;
188  visManager->Initialize();
189  UImanager->ApplyCommand("/control/execute vis.mac");
190 #endif
191  ui->SessionStart();
192 #ifdef G4VIS_USE
193  delete visManager;
194 #endif
195  delete ui;
196 #endif
197  }
198 
199  delete runManager;
200 
201  return 0;
202 }
203 
204 
int main(int argc, char **argv)
Definition: load_gdml.cc:77
Minimal primary generator action to demonstrate the use of GDML geometries.
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)
Definition of the G01DetectorConstruction class.
G4VPhysicalVolume * GetWorldVolume(const G4String &setupName="Default") const
G4GDMLAuxListType GetVolumeAuxiliaryInformation(G4LogicalVolume *lvol) const
Detector construction allowing to use the geometry read from the GDML file.
void SetRegionExport(G4bool)
const G4GDMLAuxListType * GetAuxList() const
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)
void print_aux(const G4GDMLAuxListType *auxInfoList, G4String prepend="|")
Definition: load_gdml.cc:60
static G4TransportationManager * GetTransportationManager()
void Initialize()
std::vector< G4GDMLAuxStructType > 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:446
virtual void SetUserAction(G4UserRunAction *userAction)