21 iop = derived =
false;
27 iop = derived =
false;
33 iop = derived =
false;
50 BasicXPathReader::open(filename);
53#if defined(USE_REMOTE_QIO)
54 QDPUtil::RemoteInputFileStream f;
55 f.open(filename.c_str(),std::ifstream::in);
56 BasicXPathReader::open(f);
59 f.open(filename.c_str(), std::ios::binary);
62 QDPIO::cerr <<
"Error opening read file = " << filename << std::endl;
65 BasicXPathReader::open(f);
78 BasicXPathReader::open(is);
89 BasicXPathReader::open(is);
100 BasicXPathReader::open((BasicXPathReader&)old, xpath);
112 BasicXPathReader::close();
133 BasicXPathReader::get(xpath, result);
177 const std::string& attrib_name,
186 BasicXPathReader::get(xpath, result);
195 const std::string& attrib_name,
199 BasicXPathReader::getAttribute(xpath, attrib_name, result);
208 std::ostringstream newos;
213 BasicXPathReader::print(newos);
224 std::ostringstream newos;
230 BasicXPathReader::printChildren(newos);
232 BasicXPathReader::printRoot(newos);
246 n = BasicXPathReader::count(xpath);
257 BasicXPathReader::registerNamespace(prefix, uri);
263 xml.
get(xpath, result);
274 xml.
get(xpath, result);
278 xml.
get(xpath, result);
282 xml.
get(xpath, result);
284 void read(
XMLReader& xml,
const std::string& xpath,
unsigned short int& result)
286 xml.
get(xpath, result);
290 xml.
get(xpath, result);
292 void read(
XMLReader& xml,
const std::string& xpath,
unsigned long int& result)
294 xml.
get(xpath, result);
298 xml.
get(xpath, result);
302 xml.
get(xpath, result);
306 xml.
get(xpath, result);
314 std::ostringstream error_message;
317 std::string list_string;
318 read(xml, s, list_string);
321 std::istringstream list_stream(list_string);
325 while(list_stream >> dummy)
328 if ((! list_stream.eof()) && list_stream.fail())
330 error_message <<
"Error in reading array " << s << std::endl;
331 throw error_message.str();
342 result.
resize(array_size);
347 std::istringstream list_stream2(list_string);
349 for(
int i=0; i < result.
size(); i++)
352 list_stream2 >> dummy;
428 std::ostringstream error_message;
431 std::string list_string;
432 read(xml, xpath, list_string);
435 std::istringstream list_stream(list_string);
439 while(list_stream >> dummy)
442 if ((! list_stream.eof()) && list_stream.fail())
444 error_message <<
"Error in reading array " << xpath << std::endl;
445 throw error_message.str();
449 result.resize(array_size);
454 std::istringstream list_stream2(list_string);
456 for(
int i=0; i < result.size(); i++)
459 list_stream2 >> result[i];
465 void read(
XMLReader& xml,
const std::string& xpath, std::vector<int>& result)
469 void read(
XMLReader& xml,
const std::string& xpath, std::vector<unsigned int>& result)
473 void read(
XMLReader& xml,
const std::string& xpath, std::vector<short int>& result)
477 void read(
XMLReader& xml,
const std::string& xpath, std::vector<unsigned short int>& result)
481 void read(
XMLReader& xml,
const std::string& xpath, std::vector<long int>& result)
485 void read(
XMLReader& xml,
const std::string& xpath, std::vector<unsigned long int>& result)
489 void read(
XMLReader& xml,
const std::string& xpath, std::vector<float>& result)
493 void read(
XMLReader& xml,
const std::string& xpath, std::vector<double>& result)
502 void read(
XMLReader& xml,
const std::string& xpath, std::vector<Integer>& result)
507 void read(
XMLReader& xml,
const std::string& xpath, std::vector<Real32>& result)
512 void read(
XMLReader& xml,
const std::string& xpath, std::vector<Real64>& result)
517 void read(
XMLReader& xml,
const std::string& xpath, std::vector<Boolean>& result)
531 std::string list_string;
532 read(xml, xpath, list_string);
535 std::istringstream list_stream(list_string);
538 while(list_stream >> dummy)
540 result.push_back(dummy);
550 void read(
XMLReader& xml,
const std::string& xpath, std::list<unsigned int>& result)
554 void read(
XMLReader& xml,
const std::string& xpath, std::list<short int>& result)
558 void read(
XMLReader& xml,
const std::string& xpath, std::list<unsigned short int>& result)
562 void read(
XMLReader& xml,
const std::string& xpath, std::list<long int>& result)
566 void read(
XMLReader& xml,
const std::string& xpath, std::list<unsigned long int>& result)
570 void read(
XMLReader& xml,
const std::string& xpath, std::list<float>& result)
574 void read(
XMLReader& xml,
const std::string& xpath, std::list<double>& result)
578 void read(
XMLReader& xml,
const std::string& xpath, std::list<bool>& result)
583 void read(
XMLReader& xml,
const std::string& xpath, std::list<Integer>& result)
588 void read(
XMLReader& xml,
const std::string& xpath, std::list<Real32>& result)
593 void read(
XMLReader& xml,
const std::string& xpath, std::list<Real64>& result)
598 void read(
XMLReader& xml,
const std::string& xpath, std::list<Boolean>& result)
639 XMLSimpleWriter::openTag(tagname);
645 XMLSimpleWriter::openTag(nsprefix,tagname);
651 XMLSimpleWriter::openTag(tagname,al);
655 const std::string& tagname,
656 XMLWriterAPI::AttributeList& al)
659 XMLSimpleWriter::openTag(nsprefix,tagname,al);
665 XMLSimpleWriter::closeTag();
671 XMLSimpleWriter::emptyTag(tagname);
676 XMLSimpleWriter::emptyTag(tagname,al);
680 const std::string& tagname,
681 XMLWriterAPI::AttributeList& al)
684 XMLSimpleWriter::emptyTag(nsprefix,tagname,al);
692 XMLSimpleWriter::write(output);
697 XMLSimpleWriter::write(output);
702 XMLSimpleWriter::write(output);
707 XMLSimpleWriter::write(output);
712 XMLSimpleWriter::write(output);
717 XMLSimpleWriter::write(output);
722 XMLSimpleWriter::write(output);
727 XMLSimpleWriter::write(output);
732 XMLSimpleWriter::write(output);
737 XMLSimpleWriter::write(output);
744 XMLSimpleWriter::writeXML(output);
764 std::ostringstream os;
765 const_cast<XMLReader&
>(d).printCurrentContext(os);
873 std::ostringstream output;
878 for(
int index=1; index < s1.size(); index++)
879 output <<
" " << s1[index];
922 std::ostringstream output;
928 for(
int index=1; index < s1.size(); index++)
929 output <<
" " << s1[index];
940 std::ostringstream output;
941 output.precision(15);
946 for(
int index=1; index < s1.size(); index++)
947 output <<
" " << s1[index];
968 std::ostringstream output;
974 for(
int index=1; index < s1.size(); index++)
975 output <<
" " << s1[index];
986 std::ostringstream output;
987 output.precision(15);
992 for(
int index=1; index < s1.size(); index++)
993 output <<
" " << s1[index];
1009 template<
typename T>
1012 std::ostringstream output;
1017 for(
unsigned index=1; index < s1.size(); index++)
1018 output <<
" " << s1[index];
1023 xml << output.str();
1032 void write(
XMLWriter& xml,
const std::string& xpath,
const std::vector<unsigned int>& output)
1036 void write(
XMLWriter& xml,
const std::string& xpath,
const std::vector<short int>& output)
1040 void write(
XMLWriter& xml,
const std::string& xpath,
const std::vector<unsigned short int>& output)
1044 void write(
XMLWriter& xml,
const std::string& xpath,
const std::vector<long int>& output)
1048 void write(
XMLWriter& xml,
const std::string& xpath,
const std::vector<unsigned long int>& output)
1055 std::ostringstream output;
1056 output.precision(7);
1061 for(
int index=1; index < s1.size(); index++)
1062 output <<
" " << s1[index];
1067 xml << output.str();
1073 std::ostringstream output;
1074 output.precision(15);
1079 for(
int index=1; index < s1.size(); index++)
1080 output <<
" " << s1[index];
1085 xml << output.str();
1088 void write(
XMLWriter& xml,
const std::string& xpath,
const std::vector<bool>& output)
1093 void write(
XMLWriter& xml,
const std::string& xpath,
const std::vector<Integer>& output)
1100 std::ostringstream output;
1101 output.precision(7);
1106 for(
int index=1; index < s1.size(); index++)
1107 output <<
" " << s1[index];
1112 xml << output.str();
1118 std::ostringstream output;
1119 output.precision(15);
1124 for(
int index=1; index < s1.size(); index++)
1125 output <<
" " << s1[index];
1130 xml << output.str();
1134 void write(
XMLWriter& xml,
const std::string& xpath,
const std::vector<Boolean>& output)
1142 template<
typename T>
1145 std::ostringstream output;
1149 typename std::list<T>::const_iterator t = s1.begin();
1153 for(; t != s1.end(); ++t)
1154 output <<
" " << *t;
1159 xml << output.str();
1168 void write(
XMLWriter& xml,
const std::string& xpath,
const std::list<unsigned int>& output)
1172 void write(
XMLWriter& xml,
const std::string& xpath,
const std::list<short int>& output)
1176 void write(
XMLWriter& xml,
const std::string& xpath,
const std::list<unsigned short int>& output)
1180 void write(
XMLWriter& xml,
const std::string& xpath,
const std::list<long int>& output)
1184 void write(
XMLWriter& xml,
const std::string& xpath,
const std::list<unsigned long int>& output)
1191 std::ostringstream output;
1192 output.precision(7);
1196 std::list<float>::const_iterator t = s1.begin();
1200 for(; t != s1.end(); ++t)
1201 output <<
" " << *t;
1206 xml << output.str();
1212 std::ostringstream output;
1213 output.precision(15);
1217 std::list<double>::const_iterator t = s1.begin();
1221 for(; t != s1.end(); ++t)
1222 output <<
" " << *t;
1227 xml << output.str();
1235 void write(
XMLWriter& xml,
const std::string& xpath,
const std::list<Integer>& output)
1242 std::ostringstream output;
1243 output.precision(7);
1247 std::list<Real32>::const_iterator t = s1.begin();
1251 for(; t != s1.end(); ++t)
1252 output <<
" " << *t;
1257 xml << output.str();
1263 std::ostringstream output;
1264 output.precision(15);
1268 std::list<Real64>::const_iterator t = s1.begin();
1272 for(; t != s1.end(); ++t)
1273 output <<
" " << *t;
1278 xml << output.str();
1282 void write(
XMLWriter& xml,
const std::string& xpath,
const std::list<Boolean>& output)
1296 output_stream.str(s);
1301 std::ostringstream s;
1306 s << output_stream.str() <<
"\n";
1325 output_stream.open(filename.c_str(), std::ofstream::out);
1326 if (output_stream.fail())
1328 QDPIO::cerr <<
"Error opening write file = " << filename << std::endl;
1332 writePrologue(output_stream);
1344 output_stream.close();
1356 s = output_stream.is_open();
1371 output_stream.flush();
1383 s = output_stream.fail();
1412 QDP_error_exit(
"XMLArrayWriter: internal error - array tag already written");
1414 if (! contextStack.empty())
1418 elem_qname =
"elem";
1431 QDP_error_exit(
"XMLArrayWriter: calling closeArray but not initialized");
1433 if (! contextStack.empty())
1438 if (array_size > 0 && elements_written != array_size)
1439 QDP_error_exit(
"XMLArrayWriter: failed to write all the %d required elements: instead = %d",
1440 array_size,elements_written);
1442 initP = arrayTag =
false;
1443 elements_written = 0;
1445 simpleElements =
false;
1462 if (elements_written == 0)
1466 simpleElements =
false;
1469 QDP_error_exit(
"XMLArrayWriter: internal error - data written but state not initialized");
1475 QDP_error_exit(
"XMLArrayWriter: suppose to write simple types but asked to write a struct");
1478 if (contextStack.empty())
1483 ElementType el = STRUCT;
1484 contextStack.push(el);
1493 QDP_error_exit(
"XMLArrayWriter: calling closeStruct but not initialized");
1495 if (contextStack.empty())
1502 ElementType topval = contextStack.top();
1503 if (topval != STRUCT)
1504 QDP_error_exit(
"XMLArrayWriter: found closeStruct without corresponding openStruct");
1510 if (contextStack.empty())
Writes metadata to an array which serves as a handle for another XML object.
void openArray(const std::string &tagname)
void openStruct(const std::string &tagname)
Writes an opening XML tag.
Writes XML metadata to a buffer.
std::string printCurrentContext() const
~XMLBufferWriter()
Destroy.
std::string str() const
Return entire buffer as a string.
void open(const std::string &s)
Construct from a string.
void flush()
Flush the buffer.
void close()
Closes the last file opened.
void open(const std::string &filename, bool write_prologue=true)
Opens a file.
bool is_open()
Queries whether the binary file is open.
bool fail() const
Return true if some failure occurred in previous IO operation.
void open(const std::string &filename)
Opens and reads an XML file.
void getAttribute(const std::string &xpath, const std::string &attrib_name, int &result)
read integer attributes so that I can read Matrices in XML
void printCurrentContext(std::ostream &is)
Print the current context.
XMLReader()
Empty constructor.
void readPrimitive(const std::string &xpath, T &output)
bool is_derived() const
Queries whether the XML data has been obtained from another XMLReader.
void registerNamespace(const std::string &prefix, const std::string &uri)
int count(const std::string &xpath)
Count the number of occurances from the Xpath query.
void get(const std::string &xpath, std::string &result)
Xpath query.
bool is_open()
Queries whether the binary file is open.
void close()
Closes the last file opened.
void print(std::ostream &is)
Return the entire contents of the Reader as a stream.
void readAttrPrimitive(const std::string &xpath, const std::string &attrib_name, T &result)
virtual void closeStruct()
virtual void closeSimple()
void openTag(const std::string &tagname)
Writes an opening XML tag.
void write(const std::string &output)
Write tag contents.
void emptyTag(const std::string &tagname)
Writes an empty tag.
void writeXML(const std::string &output)
void closeTag()
Closes a tag.
virtual void openSimple(const std::string &tagname)
Writes an opening XML tag.
virtual void openStruct(const std::string &tagname)
Writes an opening XML tag.
Container for a multi-dimensional 1D array.
int size() const
Size of array.
void resize(int ns1)
Resize routine, call a templated resize, using *this to disambiguate.
TextWriter & operator<<(TextWriter &txt, const std::string &output)
void write(BinaryWriter &bin, const std::string &output)
void read(BinaryReader &bin, std::string &input, size_t maxBytes)
bool primaryNode()
Returns whether this is the primary node.
StandardOutputStream cerr
void broadcast(T &dest)
Broadcast from primary node to all other nodes.
void broadcast_str(std::string &result)
Broadcast a string from primary node to all other nodes.
Yet another random number generator.
void writePrimitive(XMLWriter &xml, const std::string &s, const T &d)
bool QDP_isInitialized()
Is the machine initialized?
void readListPrimitive(XMLReader &xml, const std::string &xpath, std::list< T > &result)
Read a XML list element.
void QDP_error_exit(const char *format,...)
Simple error display and abort routine.
void readVectorPrimitive(XMLReader &xml, const std::string &xpath, std::vector< T > &result)
Read a XML vector element.
void push(XMLWriter &xml, const std::string &s)
Push a group name.
void writeListPrimitive(XMLWriter &xml, const std::string &s, const std::list< T > &s1)
void pop(XMLWriter &xml)
Pop a group name.
void readArrayPrimitive(XMLReader &xml, const std::string &s, multi1d< T > &result)
Read a XML multi1d element.
void QDP_abort(int status)
Panic button.
void writeVectorPrimitive(XMLWriter &xml, const std::string &s, const std::vector< T > &s1)
void writeArrayPrimitive(XMLWriter &xml, const std::string &s, const multi1d< T > &s1)
Primary include file for QDP.