CHROMA
inline_eigen_lime_colvec_read_obj.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Inline task to read an object from a named buffer
3  *
4  * Named object reading
5  */
6 
7 #include "chromabase.h"
8 //#include "qdp_iogauge.h"
12 
14 
17 
18 namespace Chroma
19 {
20  namespace InlineEigenLimeColVecReadNamedObjEnv
21  {
22  //! Object buffer
23  void write(XMLWriter& xml, const std::string& path, const Params::NamedObject_t& input)
24  {
25  push(xml, path);
26 
27  write(xml, "object_id", input.object_id);
28  xml << input.object_map.xml;
29 
30  pop(xml);
31  }
32 
33  //! File output
34  void write(XMLWriter& xml, const std::string& path, const Params::File_t& input)
35  {
36  push(xml, path);
37 
38  write(xml, "file_names", input.file_names);
39 
40  pop(xml);
41  }
42 
43 
44  //! Object buffer
45  void read(XMLReader& xml, const std::string& path, Params::NamedObject_t& input)
46  {
47  XMLReader inputtop(xml, path);
48 
49  read(inputtop, "object_id", input.object_id);
50 
51  // User Specified MapObject tags
52  input.object_map = readXMLGroup(inputtop, "ColorVecMapObject", "MapObjType");
53  }
54 
55  //! File output
56  void read(XMLReader& xml, const std::string& path, Params::File_t& input)
57  {
58  XMLReader inputtop(xml, path);
59 
60  read(inputtop, "file_names", input.file_names);
61  }
62 
63 
64  namespace
65  {
66  AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
67  const std::string& path)
68  {
69  return new InlineMeas(Params(xml_in, path));
70  }
71 
72  //! Local registration flag
73  bool registered = false;
74  }
75 
76  const std::string name = "EIGENINFO_LIME_COLORVEC_READ_NAMED_OBJECT";
77 
78  //! Register all the factories
79  bool registerAll()
80  {
81  bool success = true;
82  if (! registered)
83  {
84  success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
86  registered = true;
87  }
88  return success;
89  }
90  // Param stuff
92 
93  Params::Params(XMLReader& xml_in, const std::string& path)
94  {
95  try
96  {
97  XMLReader paramtop(xml_in, path);
98 
99  if (paramtop.count("Frequency") == 1)
100  read(paramtop, "Frequency", frequency);
101  else
102  frequency = 1;
103 
104  // Parameters for source construction
105  read(paramtop, "NamedObject", named_obj);
106 
107  // Read in the destination
108  read(paramtop, "File", file);
109  }
110  catch(const std::string& e)
111  {
112  QDPIO::cerr << __func__ << ": caught Exception reading XML: " << e << std::endl;
113  QDP_abort(1);
114  }
115  }
116 
117 
118  void
119  Params::writeXML(XMLWriter& xml_out, const std::string& path)
120  {
121  push(xml_out, path);
122 
123  // Parameters for source construction
124  write(xml_out, "NamedObject", named_obj);
125 
126  // Write out the destination
127  write(xml_out, "File", file);
128 
129  pop(xml_out);
130  }
131 
132 
133  void
134  InlineMeas::operator()(unsigned long update_no, XMLWriter& xml_out)
135  {
136  START_CODE();
137 
138  push(xml_out, "eigeninfo_lime_colorvec_read_named_obj");
139  write(xml_out, "update_no", update_no);
140 
141  QDPIO::cout << name << ": object reader" << std::endl;
142  StopWatch swatch;
143 
144  // Read the object
145  QDPIO::cout << "Attempt to read object name = " << params.named_obj.object_id << std::endl;
146  write(xml_out, "object_id", params.named_obj.object_id);
147  try
148  {
149  swatch.reset();
150 
151  // Generate a metadata
152  std::string file_str;
153  if (1)
154  {
155  XMLBufferWriter file_xml;
156 
157  push(file_xml, "MODMetaData");
158  write(file_xml, "id", std::string("eigenColorVec"));
159  write(file_xml, "lattSize", QDP::Layout::lattSize());
160  // write(file_xml, "num_vecs", readpair.eigenValue.weights.size()); // do not have num_vecs before the data is read!
161  pop(file_xml);
162 
163  file_str = file_xml.str();
164  }
165 
166  typedef LatticeColorVector T;
167 
168  std::istringstream xml_s(params.named_obj.object_map.xml);
169  XMLReader MapObjReader(xml_s);
170 
171  // Create the entry
174  MapObjReader,
176  file_str) );
177 
180 
181  // Argh, burying this in here
182  const int decay_dir = Nd-1;
183  const int Lt = QDP::Layout::lattSize()[decay_dir];
184 
185  // Read the object
186  swatch.start();
187 
188  //Make the final file xml which will only contain
189  //gauge info, and eigen calculation info
190  XMLBufferWriter final_file_xml;
191 
192  XMLBufferWriter final_record_xml;
193  push(final_record_xml, "SubsetVectors");
194  push(final_record_xml, "InfoArray");
195  for(int i=0; i < params.file.file_names.size(); ++i)
196  {
197  XMLReader curr_file_xml;
198  XMLReader curr_record_xml;
199 
200  std::string filename = params.file.file_names[i];
201  QDPFileReader rdr(curr_file_xml, filename, QDPIO_SERIAL);
202  EVPair<T> readpair;
203 
204  read(rdr, curr_record_xml, readpair.eigenVector);
205  if (curr_record_xml.count("/LaplaceEigInfo/EigenValues") != 0)
206  read(curr_record_xml, "/LaplaceEigInfo/EigenValues", readpair.eigenValue.weights);
207  else if (curr_record_xml.count("/LaplaceEigInfo/EigParams/EigenValues") != 0)
208  read(curr_record_xml, "/LaplaceEigInfo/EigParams/EigenValues", readpair.eigenValue.weights);
209  else
210  {
211  QDPIO::cerr << __func__ << ": LaplaceEigInfo tag for EigenValues not found\n" << std::endl;
212  QDP_abort(1);
213  }
214 
215  eigen->insert(i,readpair);
216 
217  write(final_record_xml, "elem", curr_record_xml);
218 
219  //Plop some info into the file xml only once
220  if (i == 0 )
221  {
222  write(final_file_xml, "Input", curr_file_xml);
223  }
224 
225  }
226 
227  pop(final_record_xml);
228  pop(final_record_xml);
229 
230  swatch.stop();
231 
232  TheNamedObjMap::Instance().get(params.named_obj.object_id).setFileXML(final_file_xml);
233  TheNamedObjMap::Instance().get(params.named_obj.object_id).setRecordXML(final_record_xml);
234 
235  QDPIO::cout << "Object successfully read: time= "
236  << swatch.getTimeInSeconds()
237  << " secs" << std::endl;
238  }
239  catch( std::bad_cast )
240  {
241  QDPIO::cerr << name << ": cast error" << std::endl;
242  QDP_abort(1);
243  }
244  catch (const std::string& e)
245  {
246  QDPIO::cerr << name << ": error message: " << e << std::endl;
247  QDP_abort(1);
248  }
249 
250  QDPIO::cout << name << ": ran successfully" << std::endl;
251 
252  pop(xml_out); // read_named_obj
253 
254  END_CODE();
255  }
256 
257  }
258 }
Inline measurement factory.
Primary include file for CHROMA library code.
Class for counted reference semantics.
Definition: handle.h:33
void operator()(const unsigned long update_no, XMLWriter &xml_out)
Do the writing.
static T & Instance()
Definition: singleton.h:432
GroupXML_t readXMLGroup(XMLReader &xml_in, const std::string &path, const std::string &type_name)
Read group and return as a std::string.
Inline task to read an object from a named buffer.
Nd
Definition: meslate.cc:74
Named object function std::map.
static bool registered
Local registration flag.
void write(XMLWriter &xml, const std::string &path, const Params::NamedObject_t &input)
Object buffer.
void read(XMLReader &xml, const std::string &path, Params::NamedObject_t &input)
Object buffer.
bool registerAll()
aggregate everything
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
push(xml_out,"Condensates")
LinOpSysSolverMGProtoClover::T T
int i
Definition: pbg5p_w.cc:55
pop(xml_out)
START_CODE()
::std::string string
Definition: gtest.h:1979
A Pair type.
SubsetVectorWeight_t eigenValue
struct Chroma::InlineEigenLimeColVecReadNamedObjEnv::Params::NamedObject_t named_obj
void writeXML(XMLWriter &xml_out, const std::string &path)
struct Chroma::InlineEigenLimeColVecReadNamedObjEnv::Params::File_t file
Holds of vectors and weights.