CHROMA
xml_group_reader.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Read an XML group as a std::string
3  */
4 
5 #include "io/xml_group_reader.h"
6 
7 namespace Chroma
8 {
9 
10  // Read group and return as a std::string
11  GroupXML_t readXMLGroup(XMLReader& xml_in,
12  const std::string& path, const std::string& type_name)
13  {
14  GroupXML_t group;
15 
16 // QDPIO::cout << __func__ << ": here is the current context XX";
17 // xml_in.printCurrentContext(cout);
18 // QDPIO::cout << "XX" << std::endl;
19 
20  try
21  {
22  XMLReader xml_tmp(xml_in, path);
23  std::ostringstream os;
24  xml_tmp.print(os);
25  read(xml_tmp, type_name, group.id);
26  group.xml = os.str();
27  group.path = "/" + path;
28  }
29  catch(const std::string& e)
30  {
31  QDPIO::cerr << __func__ << ": caught exception reading XML: " << e << std::endl;
32  QDP_abort(1);
33  }
34 
35  return group;
36  }
37 
38 
39  // Read group and return as a std::string
40  multi1d<GroupXML_t> readXMLArrayGroup(XMLReader& xml_in,
41  const std::string& path,
42  const std::string& type_name)
43  {
44  multi1d<GroupXML_t> group;
45 
46 // QDPIO::cout << __func__ << ": here is the current context XX";
47 // xml_in.printCurrentContext(cout);
48 // QDPIO::cout << "XX" << std::endl;
49 
50  try
51  {
52  XMLReader xml_tmp(xml_in, path);
53  group.resize(xml_tmp.count("elem"));
54 
55  for(int i=0; i < group.size(); i++)
56  {
57  // Create the query for the element
58  std::ostringstream element_xpath;
59  element_xpath << "elem[" << (i+1) << "]";
60 
61  XMLReader xml_elem(xml_tmp, element_xpath.str());
62  std::ostringstream os;
63  xml_elem.print(os);
64  read(xml_elem, type_name, group[i].id);
65  group[i].xml = os.str();
66  group[i].path = "/elem";
67  }
68  }
69  catch(const std::string& e)
70  {
71  QDPIO::cerr << __func__ << ": caught exception reading XML: " << e << std::endl;
72  QDP_abort(1);
73  }
74 
75  return group;
76  }
77 
78 } // end namespace Chroma
void read(XMLReader &xml, const std::string &path, AsqtadFermActParams &param)
Read parameters.
multi1d< GroupXML_t > readXMLArrayGroup(XMLReader &xml_in, const std::string &path, const std::string &type_name)
Read group and return as a std::string.
GroupXML_t readXMLGroup(XMLReader &xml_in, const std::string &path, const std::string &type_name)
Read group and return as a std::string.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
int i
Definition: pbg5p_w.cc:55
::std::string string
Definition: gtest.h:1979
Hold group xml and type id.
Read an XML group as a std::string.