Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
load_gdml.cc
이 파일의 문서화 페이지로 가기
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 103272 2017-03-23 13:47:10Z 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 #include "G4VisExecutive.hh"
51 #include "G4UIExecutive.hh"
52 
53 #include "G4GDMLParser.hh"
54 
55 void print_aux(const G4GDMLAuxListType* auxInfoList, G4String prepend="|")
56 {
57  for(std::vector<G4GDMLAuxStructType>::const_iterator
58  iaux = auxInfoList->begin(); iaux != auxInfoList->end(); iaux++ )
59  {
60  G4String str=iaux->type;
61  G4String val=iaux->value;
62  G4String unit=iaux->unit;
63 
64  G4cout << prepend << str << " : " << val << " " << unit << G4endl;
65 
66  if (iaux->auxList) print_aux(iaux->auxList, prepend + "|");
67  }
68  return;
69 }
70 
71 // --------------------------------------------------------------
72 
73 int main(int argc,char **argv)
74 {
75  G4cout << G4endl;
76  G4cout << "Usage: load_gdml <intput_gdml_file:mandatory>"
77  << " <output_gdml_file:optional>" << G4endl;
78  G4cout << G4endl;
79 
80  if (argc<2)
81  {
82  G4cout << "Error! Mandatory input file is not specified!" << G4endl;
83  G4cout << G4endl;
84  return -1;
85  }
86 
88 
89 // Uncomment the following if wish to avoid names stripping
90 // parser.SetStripFlag(false);
91 
92  parser.Read(argv[1]);
93 
94  if (argc>4)
95  {
96  G4cout << "Error! Too many arguments!" << G4endl;
97  G4cout << G4endl;
98  return -1;
99  }
100 
101  G4RunManager* runManager = new G4RunManager;
102 
104  parser.GetWorldVolume()));
105  runManager->SetUserInitialization(new FTFP_BERT);
106  runManager->SetUserAction(new G01PrimaryGeneratorAction);
107 
108  runManager->Initialize();
109 
110  // Initialize visualization
111  G4VisManager* visManager = new G4VisExecutive;
112  visManager->Initialize();
113 
114  // Get the pointer to the User Interface manager
115  G4UImanager* UImanager = G4UImanager::GetUIpointer();
116 
118  //
119  // Example how to retrieve Auxiliary Information
120  //
121 
122  G4cout << std::endl;
123 
125  std::vector<G4LogicalVolume*>::const_iterator lvciter;
126  for( lvciter = lvs->begin(); lvciter != lvs->end(); lvciter++ )
127  {
128  G4GDMLAuxListType auxInfo = parser.GetVolumeAuxiliaryInformation(*lvciter);
129 
130  if (auxInfo.size()>0)
131  G4cout << "Auxiliary Information is found for Logical Volume : "
132  << (*lvciter)->GetName() << G4endl;
133 
134  print_aux(&auxInfo);
135  }
136 
137  // now the 'global' auxiliary info
138  G4cout << std::endl;
139  G4cout << "Global auxiliary info:" << std::endl;
140  G4cout << std::endl;
141 
142  print_aux(parser.GetAuxList());
143 
144  G4cout << std::endl;
145 
146  //
147  // End of Auxiliary Information block
148  //
150 
151  // example of writing out
152 
153  if (argc>=3)
154  {
155 /*
156  G4GDMLAuxStructType mysubaux = {"mysubtype", "mysubvalue", "mysubunit", 0};
157  G4GDMLAuxListType* myauxlist = new G4GDMLAuxListType();
158  myauxlist->push_back(mysubaux);
159 
160  G4GDMLAuxStructType myaux = {"mytype", "myvalue", "myunit", myauxlist};
161  parser.AddAuxiliary(myaux);
162 
163 
164  // example of setting auxiliary info for world volume
165  // (can be set for any volume)
166 
167  G4GDMLAuxStructType mylocalaux = {"sometype", "somevalue", "someunit", 0};
168 
169  parser.AddVolumeAuxiliary(mylocalaux,
170  G4TransportationManager::GetTransportationManager()
171  ->GetNavigatorForTracking()->GetWorldVolume()->GetLogicalVolume());
172 */
173  parser.SetRegionExport(true);
175  ->GetNavigatorForTracking()->GetWorldVolume()->GetLogicalVolume());
176  }
177 
178 
179  if (argc==4) // batch mode
180  {
181  G4String command = "/control/execute ";
182  G4String fileName = argv[3];
183  UImanager->ApplyCommand(command+fileName);
184  }
185  else // interactive mode
186  {
187  G4UIExecutive* ui = new G4UIExecutive(argc, argv);
188  UImanager->ApplyCommand("/control/execute vis.mac");
189  ui->SessionStart();
190  delete ui;
191  }
192 
193  delete visManager;
194  delete runManager;
195 
196  return 0;
197 }
G4VPhysicalVolume * GetWorldVolume(const G4String &setupName="Default") const
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:466
#define G4endl
Definition: G4ios.hh:61
virtual void SetUserAction(G4UserRunAction *userAction)
void Read(const G4String &filename, G4bool Validate=true)
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:73
Detector construction allowing to use the geometry read from the GDML file.
const G4GDMLAuxListType * GetAuxList() const
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)
void SetRegionExport(G4bool)
G4GDMLAuxListType GetVolumeAuxiliaryInformation(G4LogicalVolume *lvol) const
CommandLineParser * parser(0)
void print_aux(const G4GDMLAuxListType *auxInfoList, G4String prepend="|")
Definition: load_gdml.cc:55
int main(int argc, char **argv)
Definition: genwindef.cc:359
static G4TransportationManager * GetTransportationManager()
std::vector< G4GDMLAuxStructType > G4GDMLAuxListType
Definition of the G01DetectorConstruction class.
G4GLOB_DLL std::ostream G4cout
void Initialize()
void Write(const G4String &filename, const G4VPhysicalVolume *pvol=0, G4bool storeReferences=true, const G4String &SchemaLocation=G4GDML_DEFAULT_SCHEMALOCATION)
Definition of the G01PrimaryGeneratorAction class.
Minimal primary generator action to demonstrate the use of GDML geometries.
virtual void Initialize()
static G4LogicalVolumeStore * GetInstance()