Geant4  10.02
G4GDMLParser.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 //
27 // $Id: G4GDMLParser.cc 90041 2015-05-11 09:46:06Z gcosmo $
28 //
29 //
30 // class G4GDMLParser Implementation
31 //
32 // -------------------------------------------------------------------------
33 
34 #include "G4GDMLParser.hh"
35 
36 #include "G4UnitsTable.hh"
37 #include "G4LogicalVolumeStore.hh"
38 #include "G4RegionStore.hh"
39 #include "G4UserLimits.hh"
40 #include "G4ProductionCuts.hh"
41 #include "G4ReflectionFactory.hh"
42 #include "G4Track.hh"
43 
45  : rlist(0), ullist(0), urcode(false), uwcode(false), strip(true), rexp(false)
46 {
49  messenger = new G4GDMLMessenger(this);
50 
52 }
53 
55  : rlist(0), ullist(0), urcode(true), uwcode(false), strip(true), rexp(false)
56 {
57  reader = extr;
59  messenger = new G4GDMLMessenger(this);
60 
62 }
63 
66  : rlist(0), ullist(0), urcode(true), uwcode(true), strip(true), rexp(false)
67 {
68  reader = extr;
69  writer = extw;
70  messenger = new G4GDMLMessenger(this);
71 
73 }
74 
76 {
77  xercesc::XMLPlatformUtils::Terminate();
78  if (!urcode) { delete reader; }
79  if (!uwcode) { delete writer; delete ullist; delete rlist; }
80 
81  delete messenger;
82 }
83 
85 {
87  const G4GDMLAuxListType* auxInfoList = GetAuxList();
88  for(std::vector<G4GDMLAuxStructType>::const_iterator
89  iaux = auxInfoList->begin(); iaux != auxInfoList->end(); iaux++ )
90  {
91  if (iaux->type != "Region") return;
92 
93  G4String name = iaux->value;
94  if (strip) { reader->StripName(name); }
95  if (name.contains("DefaultRegionForTheWorld")) continue;
96 
97  if (!iaux->auxList)
98  {
99  G4Exception("G4GDMLParser::ImportRegions()",
100  "ReadError", FatalException,
101  "Invalid definition of geometrical region!");
102  }
103  else // Create region and loop over all region attributes
104  {
105  G4Region* aRegion = new G4Region(name);
106  G4ProductionCuts* pcuts = new G4ProductionCuts();
107  aRegion->SetProductionCuts(pcuts);
108  for(std::vector<G4GDMLAuxStructType>::const_iterator
109  raux = iaux->auxList->begin(); raux != iaux->auxList->end(); raux++ )
110  {
111  const G4String& tag = raux->type;
112  if (tag=="volume")
113  {
114  G4String volname = raux->value;
115  if (strip) { reader->StripName(volname); }
117  aRegion->AddRootLogicalVolume(lvol);
118  if(reflFactory->IsConstituent(lvol)) aRegion->AddRootLogicalVolume(reflFactory->GetReflectedLV(lvol));
119  } else
120  if (tag=="pcut")
121  {
122  const G4String& cvalue = raux->value;
123  const G4String& cunit = raux->unit;
124  G4double cut = eval.Evaluate(cvalue) * G4UnitDefinition::GetValueOf(cunit);
125  pcuts->SetProductionCut(cut,"proton");
126  } else
127  if (tag=="ecut")
128  {
129  const G4String& cvalue = raux->value;
130  const G4String& cunit = raux->unit;
131  G4double cut = eval.Evaluate(cvalue) * G4UnitDefinition::GetValueOf(cunit);
132  pcuts->SetProductionCut(cut,"e-");
133  } else
134  if (tag=="poscut")
135  {
136  const G4String& cvalue = raux->value;
137  const G4String& cunit = raux->unit;
138  G4double cut = eval.Evaluate(cvalue) * G4UnitDefinition::GetValueOf(cunit);
139  pcuts->SetProductionCut(cut,"e+");
140  } else
141  if (tag=="gamcut")
142  {
143  const G4String& cvalue = raux->value;
144  const G4String& cunit = raux->unit;
145  G4double cut = eval.Evaluate(cvalue) * G4UnitDefinition::GetValueOf(cunit);
146  pcuts->SetProductionCut(cut,"gamma");
147  } else
148  if (tag=="ulimits")
149  {
150  G4double ustepMax=DBL_MAX, utrakMax=DBL_MAX, utimeMax=DBL_MAX;
151  G4double uekinMin=0., urangMin=0.;
152  const G4String& ulname = raux->value;
153  for(std::vector<G4GDMLAuxStructType>::const_iterator
154  uaux=raux->auxList->begin(); uaux!=raux->auxList->end(); uaux++ )
155  {
156  const G4String& ultag = uaux->type;
157  const G4String& uvalue = uaux->value;
158  const G4String& uunit = uaux->unit;
159  G4double ulvalue = eval.Evaluate(uvalue) * eval.Evaluate(uunit);
160  if (ultag=="ustepMax") { ustepMax = ulvalue; } else
161  if (ultag=="utrakMax") { utrakMax = ulvalue; } else
162  if (ultag=="utimeMax") { utimeMax = ulvalue; } else
163  if (ultag=="uekinMin") { uekinMin = ulvalue; } else
164  if (ultag=="urangMin") { urangMin = ulvalue; }
165  else
166  {
167  G4Exception("G4GDMLParser::ImportRegions()",
168  "ReadError", FatalException,
169  "Invalid definition of user-limits!");
170  }
171  }
172  G4UserLimits* ulimits = new G4UserLimits(ulname, ustepMax, utrakMax,
173  utimeMax, uekinMin, urangMin);
174  aRegion->SetUserLimits(ulimits);
175  }
176  else continue; // Ignore unknown tags
177  }
178  }
179  }
180 }
181 
182 void G4GDMLParser::ExportRegions(G4bool storeReferences)
183 {
186  for (size_t i=0; i<rstore->size(); ++i) // Skip default regions associated to worlds
187  {
188  const G4String& tname = (*rstore)[i]->GetName();
189  if (tname.contains("DefaultRegionForParallelWorld")) continue;
190  const G4String& rname = writer->GenerateName(tname,(*rstore)[i]);
191  rlist = new G4GDMLAuxListType();
192  G4GDMLAuxStructType raux = {"Region", rname, "", rlist};
193  std::vector<G4LogicalVolume*>::iterator rlvol_iter
194  = (*rstore)[i]->GetRootLogicalVolumeIterator();
195  for (size_t j=0; j<(*rstore)[i]->GetNumberOfRootVolumes(); ++j)
196  {
197  G4LogicalVolume* rlvol = *rlvol_iter;
198  if(reflFactory->IsReflected(rlvol)) continue;
199  G4String vname = writer->GenerateName(rlvol->GetName(), rlvol);
200  if (!storeReferences) { reader->StripName(vname); }
201  G4GDMLAuxStructType rsubaux = {"volume", vname, "", 0};
202  rlist->push_back(rsubaux);
203  rlvol_iter++;
204  }
205  G4double gam_cut = (*rstore)[i]->GetProductionCuts()->GetProductionCut("gamma");
206  G4GDMLAuxStructType caux1 = {"gamcut", eval.ConvertToString(gam_cut), "mm", 0};
207  rlist->push_back(caux1);
208  G4double e_cut = (*rstore)[i]->GetProductionCuts()->GetProductionCut("e-");
209  G4GDMLAuxStructType caux2 = {"ecut", eval.ConvertToString(e_cut), "mm", 0};
210  rlist->push_back(caux2);
211  G4double pos_cut = (*rstore)[i]->GetProductionCuts()->GetProductionCut("e+");
212  G4GDMLAuxStructType caux3 = {"poscut", eval.ConvertToString(pos_cut), "mm", 0};
213  rlist->push_back(caux3);
214  G4double p_cut = (*rstore)[i]->GetProductionCuts()->GetProductionCut("proton");
215  G4GDMLAuxStructType caux4 = {"pcut", eval.ConvertToString(p_cut), "mm", 0};
216  rlist->push_back(caux4);
217  if ((*rstore)[i]->GetUserLimits())
218  {
219  const G4Track fake_trk;
220  ullist = new G4GDMLAuxListType();
221  const G4String& utype = (*rstore)[i]->GetUserLimits()->GetType();
222  G4GDMLAuxStructType uaux = {"ulimits", utype, "mm", ullist};
223  G4double max_step = (*rstore)[i]->GetUserLimits()->GetMaxAllowedStep(fake_trk);
224  G4GDMLAuxStructType ulaux1 = {"ustepMax", eval.ConvertToString(max_step), "mm", 0};
225  ullist->push_back(ulaux1);
226  G4double max_trk = (*rstore)[i]->GetUserLimits()->GetUserMaxTrackLength(fake_trk);
227  G4GDMLAuxStructType ulaux2 = {"utrakMax", eval.ConvertToString(max_trk), "mm", 0};
228  ullist->push_back(ulaux2);
229  G4double max_time = (*rstore)[i]->GetUserLimits()->GetUserMaxTime(fake_trk);
230  G4GDMLAuxStructType ulaux3 = {"utimeMax", eval.ConvertToString(max_time), "mm", 0};
231  ullist->push_back(ulaux3);
232  G4double min_ekin = (*rstore)[i]->GetUserLimits()->GetUserMinEkine(fake_trk);
233  G4GDMLAuxStructType ulaux4 = {"uekinMin", eval.ConvertToString(min_ekin), "mm", 0};
234  ullist->push_back(ulaux4);
235  G4double min_rng = (*rstore)[i]->GetUserLimits()->GetUserMinRange(fake_trk);
236  G4GDMLAuxStructType ulaux5 = {"urangMin", eval.ConvertToString(min_rng), "mm", 0};
237  ullist->push_back(ulaux5);
238  rlist->push_back(uaux);
239  }
240  AddAuxiliary(raux);
241  }
242 }
void AddRootLogicalVolume(G4LogicalVolume *lv)
Definition: G4Region.cc:254
G4String name
Definition: TRTMaterials.hh:40
void Initialize()
Definition: errprop.cc:101
G4GDMLEvaluator eval
Definition: xmlparse.cc:187
void SetProductionCut(G4double cut, G4int index=-1)
G4bool IsReflected(G4LogicalVolume *lv) const
const G4GDMLAuxListType * GetAuxList() const
G4LogicalVolume * GetVolume(const G4String &name, G4bool verbose=true) const
static G4ReflectionFactory * Instance()
static G4RegionStore * GetInstance()
G4GDMLReadStructure * reader
G4GDMLAuxListType * rlist
static G4double GetValueOf(const G4String &)
G4String ConvertToString(G4int ival)
bool G4bool
Definition: G4Types.hh:79
static G4LogicalVolumeStore * GetInstance()
G4GDMLAuxListType * ullist
G4String GenerateName(const G4String &, const void *const)
Definition: G4GDMLWrite.cc:123
void StripName(G4String &) const
Definition: G4GDMLRead.cc:103
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
void ExportRegions(G4bool storeReferences=true)
G4bool contains(const std::string &) const
std::vector< G4GDMLAuxStructType > G4GDMLAuxListType
G4LogicalVolume * GetReflectedLV(G4LogicalVolume *lv) const
G4GDMLMessenger * messenger
void SetProductionCuts(G4ProductionCuts *cut)
void SetUserLimits(G4UserLimits *ul)
void AddAuxiliary(G4GDMLAuxStructType myaux)
const G4String & GetName() const
double G4double
Definition: G4Types.hh:76
G4GDMLWriteStructure * writer
#define DBL_MAX
Definition: templates.hh:83
G4bool IsConstituent(G4LogicalVolume *lv) const
void ImportRegions()
Definition: G4GDMLParser.cc:84
G4double Evaluate(const G4String &)