Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
cheprep::XMLHepRepWriter Class Reference

#include <XMLHepRepWriter.h>

+ Inheritance diagram for cheprep::XMLHepRepWriter:

Public Member Functions

 XMLHepRepWriter (std::ostream *out, bool randomAccess, bool compress)
 
 ~XMLHepRepWriter ()
 
bool addProperty (std::string key, std::string value)
 
bool close ()
 
bool write (HEPREP::HepRep *heprep, std::string name)
 
bool write (std::vector< std::string > layers)
 
bool write (HEPREP::HepRepTypeTree *typeTree)
 
bool write (HEPREP::HepRepType *type)
 
bool write (HEPREP::HepRepTreeID *treeID)
 
bool write (HEPREP::HepRepAction *action)
 
bool write (HEPREP::HepRepInstanceTree *instanceTree)
 
bool write (HEPREP::HepRepInstance *instance)
 
bool write (HEPREP::HepRepPoint *point)
 
bool write (HEPREP::HepRepAttribute *attribute)
 
bool write (HEPREP::HepRepDefinition *definition)
 
bool write (HEPREP::HepRepAttValue *attValue)
 
bool write (HEPREP::HepRepAttDef *attDef)
 
- Public Member Functions inherited from HEPREP::HepRepWriter
virtual ~HepRepWriter ()
 Destructor.
 
virtual bool addProperty (std::string key, std::string value)=0
 
virtual bool close ()=0
 
virtual bool write (HepRep *heprep, std::string name)=0
 
virtual bool write (std::vector< std::string > layerOrder)=0
 
virtual bool write (HepRepTypeTree *typeTree)=0
 
virtual bool write (HepRepType *type)=0
 
virtual bool write (HepRepTreeID *treeID)=0
 
virtual bool write (HepRepAction *action)=0
 
virtual bool write (HepRepInstanceTree *instanceTree)=0
 
virtual bool write (HepRepInstance *instance)=0
 
virtual bool write (HepRepPoint *point)=0
 
virtual bool write (HepRepAttribute *attribute)=0
 
virtual bool write (HepRepDefinition *definition)=0
 
virtual bool write (HepRepAttValue *attValue)=0
 
virtual bool write (HepRepAttDef *attDef)=0
 

Detailed Description

Definition at line 38 of file XMLHepRepWriter.h.

Constructor & Destructor Documentation

◆ XMLHepRepWriter()

cheprep::XMLHepRepWriter::XMLHepRepWriter ( std::ostream *  out,
bool  randomAccess,
bool  compress 
)

Definition at line 21 of file XMLHepRepWriter.cc.

22 : out(os),
23 compress(useCompression) {
24
25 this->nameSpace = NAMESPACE;
26
27 if (randomAccess) {
28 zip = new ZipOutputStream(*os);
29 out = zip;
30 gz = NULL;
31 } else {
32 zip = NULL;
33 if (useCompression) {
34#ifndef CHEPREP_NO_ZLIB
35 gz = new GZIPOutputStream(*os);
36 out = gz;
37#else
38 cerr << "WARNING: the .gz output stream you are creating will be a plain file," << endl;
39 cerr << "since compression support (ZLIB) was not compiled into the library." << endl;
40 cerr << "To add ZLIB support, you need to undefine CHEPREP_NO_ZLIB." << endl;
41 gz = NULL;
42#endif
43 } else {
44 gz = NULL;
45 }
46 }
47}
#define NAMESPACE

◆ ~XMLHepRepWriter()

cheprep::XMLHepRepWriter::~XMLHepRepWriter ( )

Definition at line 49 of file XMLHepRepWriter.cc.

49 {
50 delete gz;
51 delete zip;
52}

Member Function Documentation

◆ addProperty()

bool cheprep::XMLHepRepWriter::addProperty ( std::string  key,
std::string  value 
)
virtual

Adds a property, to be written to the HepRep file when closed.

Parameters
key
value
Returns
false in case of a stream problem.

Implements HEPREP::HepRepWriter.

Definition at line 54 of file XMLHepRepWriter.cc.

54 {
55 properties[key] = value;
56 return true;
57}

◆ close()

bool cheprep::XMLHepRepWriter::close ( )
virtual

Closes the writer and its underlying stream.

Returns
false in case of a stream problem.

Implements HEPREP::HepRepWriter.

Definition at line 59 of file XMLHepRepWriter.cc.

59 {
60 if (zip != NULL) {
61 zip->putNextEntry("heprep.properties", true);
62
63 map<string, string>::iterator i = properties.begin();
64 while (i != properties.end()) {
65 *zip << (*i).first << "=" << (*i).second << endl;
66 i++;
67 }
68 zip->closeEntry();
69 zip->close();
70 }
71
72 if (gz != NULL) {
73 gz->close();
74 }
75 return true;
76}
void putNextEntry(const std::string &name, bool compress)

◆ write() [1/13]

bool cheprep::XMLHepRepWriter::write ( HEPREP::HepRep heprep,
std::string  name 
)
virtual

Writes a HepRep.

Parameters
heprepto be written.
namefor the heprep to be written (for tagged access), may be ommited.
Returns
false in case of a stream problem.

Implements HEPREP::HepRepWriter.

Definition at line 78 of file XMLHepRepWriter.cc.

78 {
79 if (zip != NULL) {
80 zip->putNextEntry(name, compress);
81 }
82
83 if (name.rfind(".bheprep") == name.length()-8) {
84 xml = new BHepRepWriter(*out);
85 } else {
86 xml = new XMLWriter(out, " ", NAMESPACE);
87 }
88
89 xml->openDoc();
90 xml->setAttribute("version", (string)"2.0");
91 xml->setAttribute("xmlns", (string)"http://java.freehep.org/schemas/heprep/2.0");
92 xml->setAttribute("xmlns", "xsi", "http://www.w3.org/2001/XMLSchema-instance");
93 xml->setAttribute("xsi", "schemaLocation", "http://java.freehep.org/schemas/heprep/2.0 http://java.freehep.org/schemas/heprep/2.0/HepRep.xsd");
94 xml->openTag(nameSpace, "heprep");
95 write(heprep->getLayerOrder());
96 vector<HepRepTypeTree*> typeTreeSet = heprep->getTypeTreeList();
97 for (vector<HepRepTypeTree*>::iterator i1=typeTreeSet.begin(); i1 != typeTreeSet.end(); i1++) {
98 write(*i1);
99 }
100 vector<HepRepInstanceTree*> instanceTreeSet = heprep->getInstanceTreeList();
101 for (vector<HepRepInstanceTree*>::iterator i2=instanceTreeSet.begin(); i2 != instanceTreeSet.end(); i2++) {
102 write(*i2);
103 }
104 xml->closeTag();
105 xml->closeDoc();
106// xml->close();
107 delete xml;
108
109 if (zip != NULL) {
110 zip->closeEntry();
111 }
112
113 return true;
114}
virtual std::vector< HepRepInstanceTree * > getInstanceTreeList()=0
virtual std::vector< HepRepTypeTree * > getTypeTreeList()=0
virtual std::vector< std::string > getLayerOrder()=0
virtual void setAttribute(std::string ns, std::string name, std::string value)=0
virtual void openTag(std::string ns, std::string name)=0
virtual void closeTag()=0
virtual void openDoc(std::string version="1.0", std::string encoding="", bool standalone=false)=0
virtual void closeDoc(bool force=false)=0
bool write(HEPREP::HepRep *heprep, std::string name)

Referenced by write().

◆ write() [2/13]

bool cheprep::XMLHepRepWriter::write ( HEPREP::HepRepAction action)
virtual

Writes a HepRepAction.

Parameters
actionto be written.
Returns
false in case of a stream problem.

Implements HEPREP::HepRepWriter.

Definition at line 167 of file XMLHepRepWriter.cc.

167 {
168 xml->setAttribute("name", action->getName());
169 xml->setAttribute("expression", action->getExpression());
170 xml->printTag(nameSpace, "action");
171 return true;
172}
virtual std::string getExpression()=0
virtual std::string getName()=0
virtual void printTag(std::string ns, std::string name)=0

◆ write() [3/13]

bool cheprep::XMLHepRepWriter::write ( HEPREP::HepRepAttDef attDef)
virtual

Writes a HepRepAttDef.

Parameters
attDefto be written.
Returns
false in case of a stream problem.

Implements HEPREP::HepRepWriter.

Definition at line 278 of file XMLHepRepWriter.cc.

278 {
279 xml->setAttribute("name", attDef->getName());
280 xml->setAttribute("desc", attDef->getDescription());
281 xml->setAttribute("category", attDef->getCategory());
282 xml->setAttribute("extra", attDef->getExtra());
283 xml->printTag(nameSpace, "attdef");
284 return true;
285}
virtual std::string getExtra()=0
virtual std::string getName()=0
virtual std::string getDescription()=0
virtual std::string getCategory()=0

◆ write() [4/13]

bool cheprep::XMLHepRepWriter::write ( HEPREP::HepRepAttribute attribute)
virtual

Writes a HepRepAttribute.

Parameters
attributeto be written.
Returns
false in case of a stream problem.

Implements HEPREP::HepRepWriter.

Definition at line 228 of file XMLHepRepWriter.cc.

228 {
229 // BUG FIX. Do something special for layers, because these do not end
230 // up in the normal iteration.
231 HepRepAttValue* layerAtt = attribute->getAttValueFromNode("layer");
232 if (layerAtt != NULL) write(layerAtt);
233
234 set<HepRepAttValue*> attSet = attribute->getAttValuesFromNode();
235 for (set<HepRepAttValue*>::iterator i=attSet.begin(); i != attSet.end(); i++) {
236 write(*i);
237 }
238 return true;
239}
virtual HepRepAttValue * getAttValueFromNode(std::string lowerCaseName)=0
virtual std::set< HepRepAttValue * > getAttValuesFromNode()=0

◆ write() [5/13]

bool cheprep::XMLHepRepWriter::write ( HEPREP::HepRepAttValue attValue)
virtual

Writes a HepRepAttValue.

Parameters
attValueto be written.
Returns
false in case of a stream problem.

Implements HEPREP::HepRepWriter.

Definition at line 249 of file XMLHepRepWriter.cc.

249 {
250 string name = attValue->getName();
251
252 xml->setAttribute("name", name);
253
254 switch(attValue->getType()) {
255 default: xml->setAttribute("value", attValue->getAsString());
256 break;
257 case HepRepConstants::TYPE_STRING: xml->setAttribute("value", attValue->getString());
258 break;
259 case HepRepConstants::TYPE_LONG: xml->setAttribute("value", attValue->getLong());
260 break;
261 case HepRepConstants::TYPE_INT: xml->setAttribute("value", attValue->getInteger());
262 break;
263 case HepRepConstants::TYPE_DOUBLE: xml->setAttribute("value", attValue->getDouble());
264 break;
265 case HepRepConstants::TYPE_BOOLEAN: xml->setAttribute("value", attValue->getBoolean());
266 break;
267 case HepRepConstants::TYPE_COLOR: xml->setAttribute("value", attValue->getColor());
268 }
269
270 if (attValue->showLabel() != HepRepConstants::SHOW_NONE) {
271 xml->setAttribute("showlabel", attValue->showLabel());
272 }
273
274 xml->printTag(nameSpace, "attvalue");
275 return true;
276}
virtual std::string getName()=0
virtual std::vector< double > getColor()=0
virtual bool getBoolean()=0
virtual std::string getString()=0
virtual int showLabel()=0
virtual int64 getLong()=0
virtual double getDouble()=0
virtual int getInteger()=0
virtual std::string getAsString()=0
virtual int getType()=0

◆ write() [6/13]

bool cheprep::XMLHepRepWriter::write ( HEPREP::HepRepDefinition definition)
virtual

Writes a HepRepDefinition.

Parameters
definitionto be written.
Returns
false in case of a stream problem.

Implements HEPREP::HepRepWriter.

Definition at line 241 of file XMLHepRepWriter.cc.

241 {
242 set<HepRepAttDef*> list = definition->getAttDefsFromNode();
243 for (set<HepRepAttDef*>::iterator i=list.begin(); i != list.end(); i++) {
244 write(*i);
245 }
246 return true;
247}
virtual std::set< HepRepAttDef * > getAttDefsFromNode()=0

◆ write() [7/13]

bool cheprep::XMLHepRepWriter::write ( HEPREP::HepRepInstance instance)
virtual

Writes a HepRepInstance.

Parameters
instanceto be written.
Returns
false in case of a stream problem.

Implements HEPREP::HepRepWriter.

Definition at line 195 of file XMLHepRepWriter.cc.

195 {
196 // FIXME FREEHEP-356
197 xml->setAttribute("type", instance->getType()->getFullName());
198 xml->openTag(nameSpace, "instance");
199 write((HepRepAttribute*)instance);
200
201 vector<HepRepPoint*> pointList = instance->getPoints();
202 for (vector<HepRepPoint*>::iterator i1=pointList.begin(); i1 != pointList.end(); i1++) {
203 write(*i1);
204 }
205
206 vector<HepRepInstance*> instanceList = instance->getInstances();
207 for (vector<HepRepInstance*>::iterator i2=instanceList.begin(); i2 != instanceList.end(); i2++) {
208 write(*i2);
209 }
210 xml->closeTag();
211 return true;
212}
virtual HepRepType * getType()=0
virtual std::vector< HepRepPoint * > getPoints()=0
virtual std::vector< HepRepInstance * > getInstances()=0
virtual std::string getFullName()=0

◆ write() [8/13]

bool cheprep::XMLHepRepWriter::write ( HEPREP::HepRepInstanceTree instanceTree)
virtual

Writes a HepRepInstanceTree.

Parameters
instanceTreeto be written.
Returns
false in case of a stream problem.

Implements HEPREP::HepRepWriter.

Definition at line 174 of file XMLHepRepWriter.cc.

174 {
175 xml->setAttribute("name", instanceTree->getName());
176 xml->setAttribute("version", instanceTree->getVersion());
177 xml->setAttribute("typetreename", instanceTree->getTypeTree()->getName());
178 xml->setAttribute("typetreeversion", instanceTree->getTypeTree()->getVersion());
179 xml->openTag(nameSpace, "instancetree");
180 // refs
181 vector<HepRepTreeID*> instanceTreeSet = instanceTree->getInstanceTreeList();
182 for (vector<HepRepTreeID*>::iterator i1=instanceTreeSet.begin(); i1 != instanceTreeSet.end(); i1++) {
183 write(*i1);
184 }
185
186 // instances
187 vector<HepRepInstance*> instanceList = instanceTree->getInstances();
188 for (vector<HepRepInstance*>::iterator i2=instanceList.begin(); i2 != instanceList.end(); i2++) {
189 write(*i2);
190 }
191 xml->closeTag();
192 return true;
193}
virtual HepRepTreeID * getTypeTree()=0
virtual std::vector< HepRepInstance * > getInstances()=0
virtual std::vector< HepRepTreeID * > getInstanceTreeList()=0
virtual std::string getName()=0
virtual std::string getVersion()=0

◆ write() [9/13]

bool cheprep::XMLHepRepWriter::write ( HEPREP::HepRepPoint point)
virtual

Writes a HepRepPoint.

Parameters
pointto be written.
Returns
false in case of a stream problem.

Implements HEPREP::HepRepWriter.

Definition at line 214 of file XMLHepRepWriter.cc.

214 {
215 xml->setAttribute("x", point->getX());
216 xml->setAttribute("y", point->getY());
217 xml->setAttribute("z", point->getZ());
218 if (point->getAttValuesFromNode().size() != 0) {
219 xml->openTag(nameSpace, "point");
220 write((HepRepAttribute*)point);
221 xml->closeTag();
222 } else {
223 xml->printTag(nameSpace, "point");
224 }
225 return true;
226}
virtual double getY()=0
virtual double getZ()=0
virtual double getX()=0

◆ write() [10/13]

bool cheprep::XMLHepRepWriter::write ( HEPREP::HepRepTreeID treeID)
virtual

Writes a HepRepTreeID.

Parameters
treeIDto be written.
Returns
false in case of a stream problem.

Implements HEPREP::HepRepWriter.

Definition at line 159 of file XMLHepRepWriter.cc.

159 {
160 xml->setAttribute("qualifier", treeID->getQualifier());
161 xml->setAttribute("name", treeID->getName());
162 xml->setAttribute("version", treeID->getVersion());
163 xml->printTag(nameSpace, "treeid");
164 return true;
165}
virtual std::string getQualifier()=0

◆ write() [11/13]

bool cheprep::XMLHepRepWriter::write ( HEPREP::HepRepType type)
virtual

Writes a HepRepType.

Parameters
typeto be written.
Returns
false in case of a stream problem.

Implements HEPREP::HepRepWriter.

Definition at line 145 of file XMLHepRepWriter.cc.

145 {
146 xml->setAttribute("name", type->getName());
147 xml->openTag(nameSpace, "type");
148 write((HepRepDefinition*)type);
149 write((HepRepAttribute*)type);
150
151 vector<HepRepType*> types = type->getTypeList();
152 for (vector<HepRepType*>::iterator i=types.begin(); i != types.end(); i++) {
153 write(*i);
154 }
155 xml->closeTag();
156 return true;
157}
virtual std::string getName()=0
virtual std::vector< HepRepType * > getTypeList()=0

◆ write() [12/13]

bool cheprep::XMLHepRepWriter::write ( HEPREP::HepRepTypeTree typeTree)
virtual

Writes a HepRepTypeTree.

Parameters
typeTreeto be written.
Returns
false in case of a stream problem.

Implements HEPREP::HepRepWriter.

Definition at line 131 of file XMLHepRepWriter.cc.

131 {
132 xml->setAttribute("name", typeTree->getName());
133 xml->setAttribute("version", typeTree->getVersion());
134 xml->openTag(nameSpace, "typetree");
135
136 vector<HepRepType*> types = typeTree->getTypeList();
137 for (vector<HepRepType*>::iterator i=types.begin(); i != types.end(); i++) {
138 write(*i);
139 }
140
141 xml->closeTag();
142 return true;
143}
virtual std::vector< HepRepType * > getTypeList()=0

◆ write() [13/13]

bool cheprep::XMLHepRepWriter::write ( std::vector< std::string >  layerOrder)
virtual

Writes the layerOrder.

Parameters
layerOrderto be written.
Returns
false in case of a stream problem.

Implements HEPREP::HepRepWriter.

Definition at line 116 of file XMLHepRepWriter.cc.

116 {
117 string layerOrder = "";
118 bool comma = false;
119 for (vector<string>::iterator i=layers.begin(); i != layers.end(); i++) {
120 if (comma) {
121 layerOrder.append(", ");
122 }
123 layerOrder.append(*i);
124 comma = true;
125 }
126 xml->setAttribute("order", layerOrder);
127 xml->printTag(nameSpace, "layer");
128 return true;
129}

The documentation for this class was generated from the following files: