source: trunk/source/persistency/gdml/src/#G4GDMLDefine.cc# @ 1315

Last change on this file since 1315 was 987, checked in by garnier, 15 years ago

fichiers manquants

File size: 8.9 KB
Line 
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: G4GDMLDefine.cc,v 1.14 2007/11/30 13:27:24 ztorzsok Exp $
28// GEANT4 tag $ Name:$
29//
30// class G4GDMLDefine Implementation
31//
32// Original author: Zoltan Torzsok, November 2007
33//
34// --------------------------------------------------------------------
35
36#include "G4GDMLDefine.hh"
37
38void G4GDMLDefine::constantRead(const xercesc::DOMElement* const element) {
39
40   G4String name;
41   G4String value;
42
43   const xercesc::DOMNamedNodeMap* const attributes = element->getAttributes();
44   XMLSize_t attributeCount = attributes->getLength();
45
46   for (XMLSize_t attribute_index=0;attribute_index<attributeCount;attribute_index++) {
47
48      xercesc::DOMNode* node = attributes->item(attribute_index);
49
50      if (node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) continue;
51
52      const xercesc::DOMAttr* const attribute = dynamic_cast<xercesc::DOMAttr*>(node);   
53
54      const G4String attribute_name = xercesc::XMLString::transcode(attribute->getName());
55      const G4String attribute_value = xercesc::XMLString::transcode(attribute->getValue());
56
57      if (attribute_name=="name") name  = attribute_value; else
58      if (attribute_name=="value") value = attribute_value;
59   }
60
61   eval.defineConstant(name,eval.Evaluate(value));
62}
63
64void G4GDMLDefine::positionRead(const xercesc::DOMElement* const element) {
65
66   G4String name;
67   G4String unit("1");
68   G4String x;
69   G4String y;
70   G4String z;
71
72   const xercesc::DOMNamedNodeMap* const attributes = element->getAttributes();
73   XMLSize_t attributeCount = attributes->getLength();
74
75   for (XMLSize_t attribute_index=0;attribute_index<attributeCount;attribute_index++) {
76
77      xercesc::DOMNode* node = attributes->item(attribute_index);
78
79      if (node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) continue;
80
81      const xercesc::DOMAttr* const attribute = dynamic_cast<xercesc::DOMAttr*>(node);   
82
83      const G4String attribute_name = xercesc::XMLString::transcode(attribute->getName());
84      const G4String attribute_value = xercesc::XMLString::transcode(attribute->getValue());
85
86      if (attribute_name=="name") name = attribute_value; else
87      if (attribute_name=="unit") unit = attribute_value; else
88      if (attribute_name=="x") x = attribute_value; else
89      if (attribute_name=="y") y = attribute_value; else
90      if (attribute_name=="z") z = attribute_value;
91   }
92
93   G4double _unit = eval.Evaluate(unit);
94
95   G4double _x = eval.Evaluate(x)*_unit;
96   G4double _y = eval.Evaluate(y)*_unit;
97   G4double _z = eval.Evaluate(z)*_unit;
98
99   positionMap[GenerateName(name)] = new G4ThreeVector(_x,_y,_z);
100}
101
102void G4GDMLDefine::rotationRead(const xercesc::DOMElement* const element) {
103
104   G4String name;
105   G4String unit("1");
106   G4String x;
107   G4String y;
108   G4String z;
109
110   const xercesc::DOMNamedNodeMap* const attributes = element->getAttributes();
111   XMLSize_t attributeCount = attributes->getLength();
112
113   for (XMLSize_t attribute_index=0;attribute_index<attributeCount;attribute_index++) {
114
115      xercesc::DOMNode* node = attributes->item(attribute_index);
116
117      if (node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) continue;
118
119      const xercesc::DOMAttr* const attribute = dynamic_cast<xercesc::DOMAttr*>(node);   
120
121      const G4String attribute_name = xercesc::XMLString::transcode(attribute->getName());
122      const G4String attribute_value = xercesc::XMLString::transcode(attribute->getValue());
123
124      if (attribute_name=="name") name = attribute_value; else
125      if (attribute_name=="unit") unit = attribute_value; else
126      if (attribute_name=="x") x = attribute_value; else
127      if (attribute_name=="y") y = attribute_value; else
128      if (attribute_name=="z") z = attribute_value;
129   }
130
131   G4double _unit = eval.Evaluate(unit);
132
133   G4double _x = eval.Evaluate(x)*_unit;
134   G4double _y = eval.Evaluate(y)*_unit;
135   G4double _z = eval.Evaluate(z)*_unit;
136
137   rotationMap[GenerateName(name)] = new G4ThreeVector(_x,_y,_z);
138}
139
140void G4GDMLDefine::scaleRead(const xercesc::DOMElement* const element) {
141
142   G4String name;
143   G4String x;
144   G4String y;
145   G4String z;
146
147   const xercesc::DOMNamedNodeMap* const attributes = element->getAttributes();
148   XMLSize_t attributeCount = attributes->getLength();
149
150   for (XMLSize_t attribute_index=0;attribute_index<attributeCount;attribute_index++) {
151
152      xercesc::DOMNode* node = attributes->item(attribute_index);
153
154      if (node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) continue;
155
156      const xercesc::DOMAttr* const attribute = dynamic_cast<xercesc::DOMAttr*>(node);   
157
158      const G4String attribute_name = xercesc::XMLString::transcode(attribute->getName());
159      const G4String attribute_value = xercesc::XMLString::transcode(attribute->getValue());
160
161      if (attribute_name=="name") name = attribute_value; else
162      if (attribute_name=="x") x = attribute_value; else
163      if (attribute_name=="y") y = attribute_value; else
164      if (attribute_name=="z") z = attribute_value;
165   }
166
167   G4double _x = eval.Evaluate(x);
168   G4double _y = eval.Evaluate(y);
169   G4double _z = eval.Evaluate(z);
170
171   scaleMap[GenerateName(name)] = new G4ThreeVector(_x,_y,_z);
172}
173
174void G4GDMLDefine::variableRead(const xercesc::DOMElement* const element) {
175
176   G4String name;
177   G4String value;
178
179   const xercesc::DOMNamedNodeMap* const attributes = element->getAttributes();
180   XMLSize_t attributeCount = attributes->getLength();
181
182   for (XMLSize_t attribute_index=0;attribute_index<attributeCount;attribute_index++) {
183
184      xercesc::DOMNode* node = attributes->item(attribute_index);
185
186      if (node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) continue;
187
188      const xercesc::DOMAttr* const attribute = dynamic_cast<xercesc::DOMAttr*>(node);   
189
190      const G4String attribute_name = xercesc::XMLString::transcode(attribute->getName());
191      const G4String attribute_value = xercesc::XMLString::transcode(attribute->getValue());
192
193      if (attribute_name=="name") name = attribute_value; else
194      if (attribute_name=="value") value = attribute_value;
195   }
196
197   eval.defineVariable(name,eval.Evaluate(value));
198}
199
200void G4GDMLDefine::defineRead(const xercesc::DOMElement* const element) {
201
202   for (xercesc::DOMNode* iter = element->getFirstChild();iter != 0;iter = iter->getNextSibling()) {
203
204      if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) continue;
205
206      const xercesc::DOMElement* const child = dynamic_cast<xercesc::DOMElement*>(iter);
207
208      const G4String tag = xercesc::XMLString::transcode(child->getTagName());
209
210      if (tag=="constant") constantRead(child); else
211      if (tag=="position") positionRead(child); else
212      if (tag=="rotation") rotationRead(child); else
213      if (tag=="scale") scaleRead(child); else
214      if (tag=="variable") variableRead(child); else
215      G4Exception("GDML: Unknown tag in define: "+tag);
216   }
217}
218
219G4ThreeVector* G4GDMLDefine::getPosition(const G4String& ref) {
220
221   if (positionMap.find(ref) != positionMap.end()) return positionMap[ref];
222
223   G4Exception("GDML: Referenced position '"+ref+"' was not found!");
224
225   return 0;
226}
227
228G4ThreeVector* G4GDMLDefine::getRotation(const G4String& ref) {
229
230   if (rotationMap.find(ref) != rotationMap.end()) return rotationMap[ref];
231
232   G4Exception("GDML: Referenced rotation '"+ref+"' was not found!");
233
234   return 0;
235}
236
237G4ThreeVector* G4GDMLDefine::getScale(const G4String& ref) {
238
239   if (scaleMap.find(ref) != scaleMap.end()) return scaleMap[ref];
240
241   G4Exception("GDML: Referenced scale '"+ref+"' was not found!");
242
243   return 0;
244}
Note: See TracBrowser for help on using the repository browser.