CHROMA
inline_eigen_bin_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 
21 
22  //! Object buffer
23  void write(XMLWriter& xml, const std::string& path, const InlineEigenBinColVecReadNamedObjEnv::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 InlineEigenBinColVecReadNamedObjEnv::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
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, InlineEigenBinColVecReadNamedObjEnv::Params::File_t& input)
57  {
58  XMLReader inputtop(xml, path);
59 
60  read(inputtop, "file_names", input.file_names);
61  }
62 
63 
64  namespace InlineEigenBinColVecReadNamedObjEnv
65  {
66  namespace
67  {
68  AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
69  const std::string& path)
70  {
71  return new InlineMeas(Params(xml_in, path));
72  }
73 
74  //! Local registration flag
75  bool registered = false;
76  }
77 
78  const std::string name = "EIGENINFO_BIN_COLORVEC_READ_NAMED_OBJECT";
79 
80  //! Register all the factories
81  bool registerAll()
82  {
83  bool success = true;
84  if (! registered)
85  {
86  success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
88  registered = true;
89  }
90  return success;
91  }
92  // Param stuff
94 
95  Params::Params(XMLReader& xml_in, const std::string& path)
96  {
97  try
98  {
99  XMLReader paramtop(xml_in, path);
100 
101  if (paramtop.count("Frequency") == 1)
102  read(paramtop, "Frequency", frequency);
103  else
104  frequency = 1;
105 
106  // Parameters for source construction
107  read(paramtop, "NamedObject", named_obj);
108 
109  // Read in the destination
110  read(paramtop, "File", file);
111  }
112  catch(const std::string& e)
113  {
114  QDPIO::cerr << __func__ << ": caught Exception reading XML: " << e << std::endl;
115  QDP_abort(1);
116  }
117  }
118 
119 
120  void
121  Params::writeXML(XMLWriter& xml_out, const std::string& path)
122  {
123  push(xml_out, path);
124 
125  // Parameters for source construction
126  write(xml_out, "NamedObject", named_obj);
127 
128  // Write out the destination
129  write(xml_out, "File", file);
130 
131  pop(xml_out);
132  }
133 
134 
135  void
136  InlineMeas::operator()(unsigned long update_no, XMLWriter& xml_out)
137  {
138  START_CODE();
139 
140  push(xml_out, "eigeninfo_bin_colorvec_read_named_obj");
141  write(xml_out, "update_no", update_no);
142 
143  QDPIO::cout << name << ": object reader" << std::endl;
144  StopWatch swatch;
145 
146  // Read the object
147  QDPIO::cout << "Attempt to read object name = " << params.named_obj.object_id << std::endl;
148  write(xml_out, "object_id", params.named_obj.object_id);
149  try
150  {
151  swatch.reset();
152 
153  // Generate a metadata
154  std::string file_str;
155  if (1)
156  {
157  XMLBufferWriter file_xml;
158 
159  push(file_xml, "MODMetaData");
160  write(file_xml, "id", std::string("eigenColorVec"));
161  write(file_xml, "lattSize", QDP::Layout::lattSize());
162  // write(file_xml, "num_vecs", params.param.num_vecs); // do not know num_vecs till data is read
163  pop(file_xml);
164 
165  file_str = file_xml.str();
166  }
167 
168  // Create the entry
169  typedef LatticeColorVector T;
170 
171  std::istringstream xml_s(params.named_obj.object_map.xml);
172  XMLReader MapObjReader(xml_s);
173 
176  MapObjReader,
178  file_str) );
179 
182 
183  // Argh, burying this in here
184  const int decay_dir = Nd-1;
185  const int Lt = QDP::Layout::lattSize()[decay_dir];
186 
187  // Read the object
188  swatch.start();
189  for(int i=0; i < params.file.file_names.size(); ++i)
190  {
191  BinaryFileReader bin(params.file.file_names[i]);
192 
193  EVPair<T> read_pair;
194  // Read the std::vector
195  read(bin, read_pair.eigenVector);
196 
197  // Resize the eigenvalue.weights array
198  read_pair.eigenValue.weights.resize(Lt);
199 
200  // Read the weights
201  for(int t=0; t < Lt; ++t)
202  {
203  read(bin, read_pair.eigenValue.weights[t]);
204  }
205 
206  // Insert into new std::map
207  eigen->insert(i,read_pair);
208 
209  }
210 
211  swatch.stop();
212 
213  XMLBufferWriter file_xml;
214  push(file_xml, "SubsetVectors");
215  pop(file_xml);
216 
217  XMLBufferWriter record_xml;
218  push(record_xml, "SubsetVectors");
219  pop(record_xml);
220 
221  TheNamedObjMap::Instance().get(params.named_obj.object_id).setFileXML(file_xml);
222  TheNamedObjMap::Instance().get(params.named_obj.object_id).setRecordXML(record_xml);
223 
224  QDPIO::cout << "Object successfully read: time= "
225  << swatch.getTimeInSeconds()
226  << " secs" << std::endl;
227  }
228  catch( std::bad_cast )
229  {
230  QDPIO::cerr << name << ": cast error" << std::endl;
231  QDP_abort(1);
232  }
233  catch (const std::string& e)
234  {
235  QDPIO::cerr << name << ": error message: " << e << std::endl;
236  QDP_abort(1);
237  }
238 
239  QDPIO::cout << name << ": ran successfully" << std::endl;
240 
241  pop(xml_out); // read_named_obj
242 
243  END_CODE();
244  }
245 
246  }
247 }
Inline measurement factory.
Primary include file for CHROMA library code.
Class for counted reference semantics.
Definition: handle.h:33
Inline reading of latticecolorvectors that are eigenvectors.
void operator()(const unsigned long update_no, XMLWriter &xml_out)
Do the writing.
static T & Instance()
Definition: singleton.h:432
void read(XMLReader &xml, const std::string &path, AsqtadFermActParams &param)
Read parameters.
void write(XMLWriter &xml, const std::string &path, const AsqtadFermActParams &param)
Writer parameters.
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.
int t
Definition: meslate.cc:37
Nd
Definition: meslate.cc:74
Named object function std::map.
static bool registered
Local registration flag.
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::InlineEigenBinColVecReadNamedObjEnv::Params::File_t file
void writeXML(XMLWriter &xml_out, const std::string &path)
struct Chroma::InlineEigenBinColVecReadNamedObjEnv::Params::NamedObject_t named_obj
Holds of vectors and weights.