Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions
cheprep::XMLHepRepWriter Class Reference

#include <XMLHepRepWriter.h>

Inheritance diagram for cheprep::XMLHepRepWriter:
HEPREP::HepRepWriter

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. More...
 

Detailed Description

Definition at line 38 of file XMLHepRepWriter.h.

Constructor & Destructor Documentation

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

Definition at line 21 of file XMLHepRepWriter.cc.

References NAMESPACE.

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

Definition at line 50 of file XMLHepRepWriter.cc.

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

Member Function Documentation

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 55 of file XMLHepRepWriter.cc.

55  {
56  properties[key] = value;
57  return true;
58 }
const XML_Char int const XML_Char * value
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 60 of file XMLHepRepWriter.cc.

References cheprep::GZIPOutputStream::close(), cheprep::ZipOutputStream::close(), cheprep::ZipOutputStream::closeEntry(), and cheprep::ZipOutputStream::putNextEntry().

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

References cheprep::AbstractXMLWriter::closeDoc(), cheprep::ZipOutputStream::closeEntry(), cheprep::AbstractXMLWriter::closeTag(), HEPREP::HepRep::getInstanceTreeList(), HEPREP::HepRep::getLayerOrder(), HEPREP::HepRep::getTypeTreeList(), NAMESPACE, cheprep::AbstractXMLWriter::openDoc(), cheprep::AbstractXMLWriter::openTag(), cheprep::ZipOutputStream::putNextEntry(), and cheprep::AbstractXMLWriter::setAttribute().

Referenced by write().

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

References cheprep::AbstractXMLWriter::printTag(), and cheprep::AbstractXMLWriter::setAttribute().

117  {
118  string layerOrder = "";
119  bool comma = false;
120  for (vector<string>::iterator i=layers.begin(); i != layers.end(); i++) {
121  if (comma) {
122  layerOrder.append(", ");
123  }
124  layerOrder.append(*i);
125  comma = true;
126  }
127  xml->setAttribute("order", layerOrder);
128  xml->printTag(nameSpace, "layer");
129  return true;
130 }
virtual void printTag(std::string ns, std::string name)=0
virtual void setAttribute(std::string ns, std::string name, std::string value)=0
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 132 of file XMLHepRepWriter.cc.

References cheprep::AbstractXMLWriter::closeTag(), HEPREP::HepRepTreeID::getName(), HEPREP::HepRepTypeTree::getTypeList(), HEPREP::HepRepTreeID::getVersion(), cheprep::AbstractXMLWriter::openTag(), cheprep::AbstractXMLWriter::setAttribute(), and write().

132  {
133  xml->setAttribute("name", typeTree->getName());
134  xml->setAttribute("version", typeTree->getVersion());
135  xml->openTag(nameSpace, "typetree");
136 
137  vector<HepRepType*> types = typeTree->getTypeList();
138  for (vector<HepRepType*>::iterator i=types.begin(); i != types.end(); i++) {
139  write(*i);
140  }
141 
142  xml->closeTag();
143  return true;
144 }
virtual void openTag(std::string ns, std::string name)=0
virtual std::string getName()=0
virtual void closeTag()=0
virtual void setAttribute(std::string ns, std::string name, std::string value)=0
bool write(HEPREP::HepRep *heprep, std::string name)
virtual std::string getVersion()=0
virtual std::vector< HepRepType * > getTypeList()=0
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 146 of file XMLHepRepWriter.cc.

References cheprep::AbstractXMLWriter::closeTag(), HEPREP::HepRepType::getName(), HEPREP::HepRepType::getTypeList(), cheprep::AbstractXMLWriter::openTag(), cheprep::AbstractXMLWriter::setAttribute(), and write().

146  {
147  xml->setAttribute("name", type->getName());
148  xml->openTag(nameSpace, "type");
149  write((HepRepDefinition*)type);
150  write((HepRepAttribute*)type);
151 
152  vector<HepRepType*> types = type->getTypeList();
153  for (vector<HepRepType*>::iterator i=types.begin(); i != types.end(); i++) {
154  write(*i);
155  }
156  xml->closeTag();
157  return true;
158 }
virtual void openTag(std::string ns, std::string name)=0
virtual void closeTag()=0
virtual std::vector< HepRepType * > getTypeList()=0
virtual void setAttribute(std::string ns, std::string name, std::string value)=0
virtual std::string getName()=0
bool write(HEPREP::HepRep *heprep, std::string name)
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 160 of file XMLHepRepWriter.cc.

References HEPREP::HepRepTreeID::getName(), HEPREP::HepRepTreeID::getQualifier(), HEPREP::HepRepTreeID::getVersion(), cheprep::AbstractXMLWriter::printTag(), and cheprep::AbstractXMLWriter::setAttribute().

160  {
161  xml->setAttribute("qualifier", treeID->getQualifier());
162  xml->setAttribute("name", treeID->getName());
163  xml->setAttribute("version", treeID->getVersion());
164  xml->printTag(nameSpace, "treeid");
165  return true;
166 }
virtual std::string getName()=0
virtual void printTag(std::string ns, std::string name)=0
virtual void setAttribute(std::string ns, std::string name, std::string value)=0
virtual std::string getQualifier()=0
virtual std::string getVersion()=0
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 168 of file XMLHepRepWriter.cc.

References HEPREP::HepRepAction::getExpression(), HEPREP::HepRepAction::getName(), cheprep::AbstractXMLWriter::printTag(), and cheprep::AbstractXMLWriter::setAttribute().

168  {
169  xml->setAttribute("name", action->getName());
170  xml->setAttribute("expression", action->getExpression());
171  xml->printTag(nameSpace, "action");
172  return true;
173 }
virtual std::string getExpression()=0
virtual std::string getName()=0
virtual void printTag(std::string ns, std::string name)=0
virtual void setAttribute(std::string ns, std::string name, std::string value)=0
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 175 of file XMLHepRepWriter.cc.

References cheprep::AbstractXMLWriter::closeTag(), HEPREP::HepRepInstanceTree::getInstances(), HEPREP::HepRepInstanceTree::getInstanceTreeList(), HEPREP::HepRepTreeID::getName(), HEPREP::HepRepInstanceTree::getTypeTree(), HEPREP::HepRepTreeID::getVersion(), cheprep::AbstractXMLWriter::openTag(), cheprep::AbstractXMLWriter::setAttribute(), and write().

175  {
176  xml->setAttribute("name", instanceTree->getName());
177  xml->setAttribute("version", instanceTree->getVersion());
178  xml->setAttribute("typetreename", instanceTree->getTypeTree()->getName());
179  xml->setAttribute("typetreeversion", instanceTree->getTypeTree()->getVersion());
180  xml->openTag(nameSpace, "instancetree");
181  // refs
182  vector<HepRepTreeID*> instanceTreeSet = instanceTree->getInstanceTreeList();
183  for (vector<HepRepTreeID*>::iterator i1=instanceTreeSet.begin(); i1 != instanceTreeSet.end(); i1++) {
184  write(*i1);
185  }
186 
187  // instances
188  vector<HepRepInstance*> instanceList = instanceTree->getInstances();
189  for (vector<HepRepInstance*>::iterator i2=instanceList.begin(); i2 != instanceList.end(); i2++) {
190  write(*i2);
191  }
192  xml->closeTag();
193  return true;
194 }
virtual void openTag(std::string ns, std::string name)=0
virtual std::string getName()=0
virtual HepRepTreeID * getTypeTree()=0
virtual void closeTag()=0
virtual void setAttribute(std::string ns, std::string name, std::string value)=0
virtual std::vector< HepRepInstance * > getInstances()=0
bool write(HEPREP::HepRep *heprep, std::string name)
virtual std::string getVersion()=0
virtual std::vector< HepRepTreeID * > getInstanceTreeList()=0
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 196 of file XMLHepRepWriter.cc.

References cheprep::AbstractXMLWriter::closeTag(), HEPREP::HepRepType::getFullName(), HEPREP::HepRepInstance::getInstances(), HEPREP::HepRepInstance::getPoints(), HEPREP::HepRepInstance::getType(), cheprep::AbstractXMLWriter::openTag(), cheprep::AbstractXMLWriter::setAttribute(), and write().

196  {
197  // FIXME FREEHEP-356
198  xml->setAttribute("type", instance->getType()->getFullName());
199  xml->openTag(nameSpace, "instance");
200  write((HepRepAttribute*)instance);
201 
202  vector<HepRepPoint*> pointList = instance->getPoints();
203  for (vector<HepRepPoint*>::iterator i1=pointList.begin(); i1 != pointList.end(); i1++) {
204  write(*i1);
205  }
206 
207  vector<HepRepInstance*> instanceList = instance->getInstances();
208  for (vector<HepRepInstance*>::iterator i2=instanceList.begin(); i2 != instanceList.end(); i2++) {
209  write(*i2);
210  }
211  xml->closeTag();
212  return true;
213 }
virtual void openTag(std::string ns, std::string name)=0
virtual std::vector< HepRepInstance * > getInstances()=0
virtual std::vector< HepRepPoint * > getPoints()=0
virtual void closeTag()=0
virtual void setAttribute(std::string ns, std::string name, std::string value)=0
virtual HepRepType * getType()=0
bool write(HEPREP::HepRep *heprep, std::string name)
virtual std::string getFullName()=0
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 215 of file XMLHepRepWriter.cc.

References cheprep::AbstractXMLWriter::closeTag(), HEPREP::HepRepAttribute::getAttValuesFromNode(), HEPREP::HepRepPoint::getX(), HEPREP::HepRepPoint::getY(), HEPREP::HepRepPoint::getZ(), cheprep::AbstractXMLWriter::openTag(), cheprep::AbstractXMLWriter::printTag(), cheprep::AbstractXMLWriter::setAttribute(), and write().

215  {
216  xml->setAttribute("x", point->getX());
217  xml->setAttribute("y", point->getY());
218  xml->setAttribute("z", point->getZ());
219  if (point->getAttValuesFromNode().size() != 0) {
220  xml->openTag(nameSpace, "point");
221  write((HepRepAttribute*)point);
222  xml->closeTag();
223  } else {
224  xml->printTag(nameSpace, "point");
225  }
226  return true;
227 }
virtual double getY()=0
virtual void openTag(std::string ns, std::string name)=0
virtual void printTag(std::string ns, std::string name)=0
virtual void closeTag()=0
virtual void setAttribute(std::string ns, std::string name, std::string value)=0
virtual double getX()=0
bool write(HEPREP::HepRep *heprep, std::string name)
virtual double getZ()=0
virtual std::set< HepRepAttValue * > getAttValuesFromNode()=0
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 229 of file XMLHepRepWriter.cc.

References HEPREP::HepRepAttribute::getAttValueFromNode(), HEPREP::HepRepAttribute::getAttValuesFromNode(), and write().

229  {
230  // BUG FIX. Do something special for layers, because these do not end
231  // up in the normal iteration.
232  HepRepAttValue* layerAtt = attribute->getAttValueFromNode("layer");
233  if (layerAtt != NULL) write(layerAtt);
234 
235  set<HepRepAttValue*> attSet = attribute->getAttValuesFromNode();
236  for (set<HepRepAttValue*>::iterator i=attSet.begin(); i != attSet.end(); i++) {
237  write(*i);
238  }
239  return true;
240 }
virtual HepRepAttValue * getAttValueFromNode(std::string lowerCaseName)=0
bool write(HEPREP::HepRep *heprep, std::string name)
virtual std::set< HepRepAttValue * > getAttValuesFromNode()=0
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 242 of file XMLHepRepWriter.cc.

References HEPREP::HepRepDefinition::getAttDefsFromNode(), and write().

242  {
243  set<HepRepAttDef*> list = definition->getAttDefsFromNode();
244  for (set<HepRepAttDef*>::iterator i=list.begin(); i != list.end(); i++) {
245  write(*i);
246  }
247  return true;
248 }
bool write(HEPREP::HepRep *heprep, std::string name)
virtual std::set< HepRepAttDef * > getAttDefsFromNode()=0
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 250 of file XMLHepRepWriter.cc.

References HEPREP::HepRepAttValue::getAsString(), HEPREP::HepRepAttValue::getBoolean(), HEPREP::HepRepAttValue::getColor(), HEPREP::HepRepAttValue::getDouble(), HEPREP::HepRepAttValue::getInteger(), HEPREP::HepRepAttValue::getLong(), HEPREP::HepRepAttValue::getName(), HEPREP::HepRepAttValue::getString(), HEPREP::HepRepAttValue::getType(), cheprep::AbstractXMLWriter::printTag(), cheprep::AbstractXMLWriter::setAttribute(), and HEPREP::HepRepAttValue::showLabel().

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

References HEPREP::HepRepAttDef::getCategory(), HEPREP::HepRepAttDef::getDescription(), HEPREP::HepRepAttDef::getExtra(), HEPREP::HepRepAttDef::getName(), cheprep::AbstractXMLWriter::printTag(), and cheprep::AbstractXMLWriter::setAttribute().

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

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