CHROMA
inline_qio_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 writing
5  */
6 
10 
13 
14 #include "meas/hadron/diquark_w.h"
15 #include "util/ferm/eigeninfo.h"
18 #include "handle.h"
20 
21 namespace Chroma
22 {
23  namespace InlineQIOReadNamedObjEnv
24  {
25  //! IO function std::map environment
26  /*! \ingroup inlineio */
27  namespace QIOReadObjectEnv
28  {
29  /*! @ingroup inlineio */
31  {
32  public:
33  virtual ~QIOReadObject() {}
34 
35  //! Read the object
36  virtual void operator()(QDP_serialparallel_t serpar) = 0;
37  };
38 
39 
40  namespace
41  {
42  //! QIO read factory (foundry)
43  /*! \ingroup inlineio */
44  typedef SingletonHolder<
47  TYPELIST_1(const Params&),
48  QIOReadObject* (*)(const Params&),
50  TheQIOReadObjectFactory;
51  }
52 
53  // Anonymous namespace
54  namespace
55  {
56  //------------------------------------------------------------------------
57  class QIOReadLatProp : public QIOReadObject
58  {
59  private:
60  Params params;
61 
62  public:
63  QIOReadLatProp(const Params& p) : params(p) {}
64 
65  //! Read a propagator
66  void operator()(QDP_serialparallel_t serpar) {
67  LatticePropagator obj;
68  XMLReader file_xml, record_xml;
69 
70  QDPFileReader to(file_xml,params.file.file_name,serpar);
71  read(to,record_xml,obj);
72  close(to);
73 
74  TheNamedObjMap::Instance().create<LatticePropagator>(params.named_obj.object_id);
75  TheNamedObjMap::Instance().getData<LatticePropagator>(params.named_obj.object_id) = obj;
76  TheNamedObjMap::Instance().get(params.named_obj.object_id).setFileXML(file_xml);
77  TheNamedObjMap::Instance().get(params.named_obj.object_id).setRecordXML(record_xml);
78  }
79  };
80 
81  // Call back
82  QIOReadObject* qioReadLatProp(const Params& p)
83  {
84  return new QIOReadLatProp(p);
85  }
86 
87 
88  //------------------------------------------------------------------------
89  //! Read a single prec propagator
90  class QIOReadLatPropF : public QIOReadObject
91  {
92  private:
93  Params params;
94 
95  public:
96  QIOReadLatPropF(const Params& p) : params(p) {}
97 
98  //! Read a propagator
99  void operator()(QDP_serialparallel_t serpar) {
100  LatticePropagatorF obj;
101  XMLReader file_xml, record_xml;
102 
103  QDPFileReader to(file_xml,params.file.file_name,serpar);
104  read(to,record_xml,obj);
105  close(to);
106 
107  TheNamedObjMap::Instance().create<LatticePropagator>(params.named_obj.object_id);
108  TheNamedObjMap::Instance().getData<LatticePropagator>(params.named_obj.object_id) = obj;
109  TheNamedObjMap::Instance().get(params.named_obj.object_id).setFileXML(file_xml);
110  TheNamedObjMap::Instance().get(params.named_obj.object_id).setRecordXML(record_xml);
111  }
112  };
113 
114  // Call back
115  QIOReadObject* qioReadLatPropF(const Params& p)
116  {
117  return new QIOReadLatPropF(p);
118  }
119 
120 
121  //------------------------------------------------------------------------
122  //! Read a double prec propagator
123  class QIOReadLatPropD : public QIOReadObject
124  {
125  private:
126  Params params;
127 
128  public:
129  QIOReadLatPropD(const Params& p) : params(p) {}
130 
131  //! Read a propagator
132  void operator()(QDP_serialparallel_t serpar) {
133  LatticePropagatorD obj;
134  XMLReader file_xml, record_xml;
135 
136  QDPFileReader to(file_xml,params.file.file_name,serpar);
137  read(to,record_xml,obj);
138  close(to);
139 
140  TheNamedObjMap::Instance().create<LatticePropagator>(params.named_obj.object_id);
141  TheNamedObjMap::Instance().getData<LatticePropagator>(params.named_obj.object_id) = obj;
142  TheNamedObjMap::Instance().get(params.named_obj.object_id).setFileXML(file_xml);
143  TheNamedObjMap::Instance().get(params.named_obj.object_id).setRecordXML(record_xml);
144  }
145  };
146 
147  // Call back
148  QIOReadObject* qioReadLatPropD(const Params& p)
149  {
150  return new QIOReadLatPropD(p);
151  }
152 
153 
154  //------------------------------------------------------------------------
155  //! Read a staggered prop -- floating precision
156  class QIOReadStagLatProp : public QIOReadObject
157  {
158  private:
159  Params params;
160 
161  public:
162  QIOReadStagLatProp(const Params& p) : params(p) {}
163 
164  //! Read a propagator
165  void operator()(QDP_serialparallel_t serpar) {
166  LatticeStaggeredPropagator obj;
167  XMLReader file_xml, record_xml;
168 
169  QDPFileReader to(file_xml,params.file.file_name,serpar);
170  read(to,record_xml,obj);
171  close(to);
172 
173  TheNamedObjMap::Instance().create<LatticeStaggeredPropagator>(params.named_obj.object_id);
174  TheNamedObjMap::Instance().getData<LatticeStaggeredPropagator>(params.named_obj.object_id) = obj;
175  TheNamedObjMap::Instance().get(params.named_obj.object_id).setFileXML(file_xml);
176  TheNamedObjMap::Instance().get(params.named_obj.object_id).setRecordXML(record_xml);
177  }
178  };
179 
180  // Call back
181  QIOReadObject* qioReadStagLatProp(const Params& p)
182  {
183  return new QIOReadStagLatProp(p);
184  }
185 
186 
187  //------------------------------------------------------------------------
188  //! Read a staggered prop -- object on disk is single precision
189  class QIOReadStagLatPropF : public QIOReadObject
190  {
191  private:
192  Params params;
193 
194  public:
195  QIOReadStagLatPropF(const Params& p) : params(p) {}
196 
197  //! Read a propagator
198  void operator()(QDP_serialparallel_t serpar) {
199  LatticeStaggeredPropagatorF obj;
200  XMLReader file_xml, record_xml;
201 
202  QDPFileReader to(file_xml,params.file.file_name,serpar);
203  read(to,record_xml,obj);
204  close(to);
205 
206  TheNamedObjMap::Instance().create<LatticeStaggeredPropagator>(params.named_obj.object_id);
207  TheNamedObjMap::Instance().getData<LatticeStaggeredPropagator>(params.named_obj.object_id) = obj;
208  TheNamedObjMap::Instance().get(params.named_obj.object_id).setFileXML(file_xml);
209  TheNamedObjMap::Instance().get(params.named_obj.object_id).setRecordXML(record_xml);
210  }
211  };
212 
213  // Call back
214  QIOReadObject* qioReadStagLatPropF(const Params& p)
215  {
216  return new QIOReadStagLatPropF(p);
217  }
218 
219  //------------------------------------------------------------------------
220  //! Read a staggered prop -- file on disk is double prec
221  class QIOReadStagLatPropD : public QIOReadObject
222  {
223  private:
224  Params params;
225 
226  public:
227  QIOReadStagLatPropD(const Params& p) : params(p) {}
228 
229  //! Read a propagator
230  void operator()(QDP_serialparallel_t serpar) {
231  LatticeStaggeredPropagatorD obj;
232  XMLReader file_xml, record_xml;
233 
234  QDPFileReader to(file_xml,params.file.file_name,serpar);
235  read(to,record_xml,obj);
236  close(to);
237 
238  TheNamedObjMap::Instance().create<LatticeStaggeredPropagator>(params.named_obj.object_id);
239  TheNamedObjMap::Instance().getData<LatticeStaggeredPropagator>(params.named_obj.object_id) = obj;
240  TheNamedObjMap::Instance().get(params.named_obj.object_id).setFileXML(file_xml);
241  TheNamedObjMap::Instance().get(params.named_obj.object_id).setRecordXML(record_xml);
242  }
243  };
244 
245  // Call back
246  QIOReadObject* qioReadStagLatPropD(const Params& p)
247  {
248  return new QIOReadStagLatPropD(p);
249  }
250 
251 
252 
253  //------------------------------------------------------------------------
254  //------------------------------------------------------------------------
255  class QIOReadSubsetVectorsLCV : public QIOReadObject
256  {
257  private:
258  Params params;
259  Handle< MapObject<int,EVPair<LatticeColorVector> > > obj;
260 
261  public:
262  QIOReadSubsetVectorsLCV(const Params& params_) : params(params_)
263  {
264  try
265  {
266  // Generate a metadata
267  std::string file_str;
268  if (1)
269  {
270  XMLBufferWriter file_xml;
271 
272  push(file_xml, "MODMetaData");
273  write(file_xml, "id", std::string("eigenColorVec"));
274  write(file_xml, "lattSize", QDP::Layout::lattSize());
275  // write(file_xml, "num_vecs", params.param.num_vecs); // do not know num_vecs till data is read
276  pop(file_xml);
277 
278  file_str = file_xml.str();
279  }
280 
281  // Create the entry
282  std::istringstream xml_nam(params.named_obj_xml.xml);
283  XMLReader namtop(xml_nam);
284  GroupXML_t colorvec_obj = readXMLGroup(namtop, "MapObject", "MapObjType");
285 
286  TheNamedObjMap::Instance().create< Handle< MapObject<int,EVPair<LatticeColorVector> > > >(params.named_obj.object_id);
287  TheNamedObjMap::Instance().getData< Handle< MapObject<int,EVPair<LatticeColorVector> > > >(params.named_obj.object_id) =
288  TheMapObjIntKeyColorEigenVecFactory::Instance().createObject(colorvec_obj.id,
289  namtop,
290  colorvec_obj.path,
291  file_str);
292  }
293  catch (std::bad_cast)
294  {
295  QDPIO::cerr << "QIOReadSubsetVectorsLCV: caught dynamic cast error" << std::endl;
296  QDP_abort(1);
297  }
298  catch (const std::string& e)
299  {
300  QDPIO::cerr << "QIOReadSubsetVectorsLCV: error creating prop: " << e << std::endl;
301  QDP_abort(1);
302  }
303 
304  // Cast should be valid now
305  obj = TheNamedObjMap::Instance().getData< Handle< MapObject<int,EVPair<LatticeColorVector> > > >(params.named_obj.object_id);
306  }
307 
308  //! Read a propagator
309  void operator()(QDP_serialparallel_t serpar) {
310  // Stuff
311  XMLReader file_xml, record_xml, largest_record_xml;
312 
313  // Open file
314  QDPFileReader to(file_xml,params.file.file_name,serpar);
315 
316  // Extract number of EVs from XML
317  int N, decay_dir;
318  try {
319  XMLReader vec_xml(file_xml, "/AllVectors");
320 
321  read(vec_xml, "n_vec", N);
322  read(vec_xml, "decay_dir", decay_dir);
323  }
324  catch(const std::string& e) {
325  QDPIO::cerr<< "Caught Exception while reading XML: " << e << std::endl;
326  QDP_abort(1);
327  }
328 
329  // Resize arrays
330  const int Lt = QDP::Layout::lattSize()[decay_dir];
331 
332  // Determine if number of eigenvectors to read is specified in input xml
333  int num_vecs = 0;
334  std::istringstream xml_nam(params.named_obj_xml.xml);
335  XMLReader param_xml_top(xml_nam);
336  XMLReader param_xml(param_xml_top, "MapObject");
337  if(param_xml.count("num_vecs") > 0)
338  read(param_xml, "num_vecs", num_vecs);
339  else
340  num_vecs = N;
341  if(num_vecs > N)
342  {
343  QDPIO::cerr<< "Error: number of vectors to read, num_vecs= " << num_vecs << ", is greater than number in file, N= " << N << std::endl;
344  QDP_abort(1);
345  }
346 
347  // Loop and read evecs
348  QDPIO::cout << "About to read " << num_vecs << " out of " << N << " evectors from QIO..."<<std::endl;
349  for(int n=0; n < num_vecs; n++)
350  {
351  XMLReader record_xml_dummy;
352  EVPair<LatticeColorVector> read_pair;
353 
354  read(to, record_xml_dummy, read_pair.eigenVector);
355 
356  read_pair.eigenValue.weights.resize(Lt);
357  read(record_xml_dummy, "/VectorInfo/weights", read_pair.eigenValue.weights);
358  QDPIO::cout << "Inserting Pair " << n << " into Map" << std::endl;
359  obj->insert(n, read_pair);
360 
361  }
362 
363  // Set File and Record XML throw away dummy XMLs
364  // BJOO: Yes that's all very well. but RecordXML has to hold something
365  XMLBufferWriter dummy;
366  push(dummy,"DummyRecordXML");
367  write(dummy, "mapSize", num_vecs);
368  pop(dummy);
369  record_xml.open(dummy);
370 
371  TheNamedObjMap::Instance().get(params.named_obj.object_id).setFileXML(file_xml);
372  TheNamedObjMap::Instance().get(params.named_obj.object_id).setRecordXML(record_xml);
373 
374  // Done
375  close(to);
376  }
377  };
378 
379  // Call back
380  QIOReadObject* qioReadSubsetVectorsLCV(const Params& p)
381  {
382  return new QIOReadSubsetVectorsLCV(p);
383  }
384 
385 
386 
387  //------------------------------------------------------------------------
388  //------------------------------------------------------------------------
389  //------------------------------------------------------------------------
390  //------------------------------------------------------------------------
391  //------------------------------------------------------------------------
392  //------------------------------------------------------------------------
393  //------------------------------------------------------------------------
394  //! Read a fermion
395  class QIOReadLatFerm : public QIOReadObject
396  {
397  private:
398  Params params;
399 
400  public:
401  QIOReadLatFerm(const Params& p) : params(p) {}
402 
403  //! Read a propagator
404  void operator()(QDP_serialparallel_t serpar) {
405  LatticeFermion obj;
406  XMLReader file_xml, record_xml;
407 
408  QDPFileReader to(file_xml,params.file.file_name,serpar);
409  read(to,record_xml,obj);
410  close(to);
411 
412  TheNamedObjMap::Instance().create<LatticeFermion>(params.named_obj.object_id);
413  TheNamedObjMap::Instance().getData<LatticeFermion>(params.named_obj.object_id) = obj;
414  TheNamedObjMap::Instance().get(params.named_obj.object_id).setFileXML(file_xml);
415  TheNamedObjMap::Instance().get(params.named_obj.object_id).setRecordXML(record_xml);
416  }
417  };
418 
419  // Call back
420  QIOReadObject* qioReadLatFerm(const Params& p)
421  {
422  return new QIOReadLatFerm(p);
423  }
424 
425 
426 #if 0
427  // RGE: FOR SOME REASON, QDP CANNOT CAST A DOUBLE TO FLOATING HERE. NEED TO FIX.
428 
429  //! Read a single prec fermion
430  void QIOReadLatFermF(const std::string& buffer_id,
431  const std::string& file,
432  QDP_serialparallel_t serpar)
433  {
434  LatticeFermionF obj;
435  XMLReader file_xml, record_xml;
436 
437  QDPFileReader to(file_xml,params.file.file_name,serpar);
438  read(to,record_xml,obj);
439  close(to);
440 
441  TheNamedObjMap::Instance().create<LatticeFermion>(params.named_obj.object_id);
442  TheNamedObjMap::Instance().getData<LatticeFermion>(params.named_obj.object_id) = obj;
443  TheNamedObjMap::Instance().get(params.named_obj.object_id).setFileXML(file_xml);
444  TheNamedObjMap::Instance().get(params.named_obj.object_id).setRecordXML(record_xml);
445  }
446 
447 
448  //! Read a double prec fermion
449  void QIOReadLatFermD(const std::string& buffer_id,
450  const std::string& file,
451  QDP_serialparallel_t serpar)
452  {
453  LatticeFermionD obj;
454  XMLReader file_xml, record_xml;
455 
456  QDPFileReader to(file_xml,params.file.file_name,serpar);
457  read(to,record_xml,obj);
458  close(to);
459 
460  TheNamedObjMap::Instance().create<LatticeFermion>(params.named_obj.object_id);
461  TheNamedObjMap::Instance().getData<LatticeFermion>(params.named_obj.object_id) = obj;
462  TheNamedObjMap::Instance().get(params.named_obj.object_id).setFileXML(file_xml);
463  TheNamedObjMap::Instance().get(params.named_obj.object_id).setRecordXML(record_xml);
464  }
465 #endif
466 
467  //------------------------------------------------------------------------
468  //! Read a gauge field in floating precision
469  class QIOReadArrayLatColMat : public QIOReadObject
470  {
471  private:
472  Params params;
473 
474  public:
475  QIOReadArrayLatColMat(const Params& p) : params(p) {}
476 
477  //! Read a propagator
478  void operator()(QDP_serialparallel_t serpar) {
479  multi1d<LatticeColorMatrix> obj;
480  XMLReader file_xml, record_xml;
481 
482  obj.resize(Nd); // BAD BAD BAD - FIX THIS
483 
484  QDPFileReader to(file_xml,params.file.file_name,serpar);
485  read(to,record_xml,obj);
486  close(to);
487 
488  TheNamedObjMap::Instance().create< multi1d<LatticeColorMatrix> >(params.named_obj.object_id);
489  TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.object_id) = obj;
490  TheNamedObjMap::Instance().get(params.named_obj.object_id).setFileXML(file_xml);
491  TheNamedObjMap::Instance().get(params.named_obj.object_id).setRecordXML(record_xml);
492  }
493  };
494 
495  // Call back
496  QIOReadObject* qioReadArrayLatColMat(const Params& p)
497  {
498  return new QIOReadArrayLatColMat(p);
499  }
500 
501 
502  //------------------------------------------------------------------------
503  //! Read a single prec Gauge fields
504  class QIOReadArrayLatColMatF : public QIOReadObject
505  {
506  private:
507  Params params;
508 
509  public:
510  QIOReadArrayLatColMatF(const Params& p) : params(p) {}
511 
512  //! Read a propagator
513  void operator()(QDP_serialparallel_t serpar) {
514  multi1d<LatticeColorMatrixF> obj;
515  XMLReader file_xml, record_xml;
516 
517  obj.resize(Nd); // BAD BAD BAD - FIX THIS
518 
519  QDPFileReader to(file_xml,params.file.file_name,serpar);
520  read(to,record_xml,obj);
521  close(to);
522 
523  TheNamedObjMap::Instance().create< multi1d<LatticeColorMatrix> >(params.named_obj.object_id);
524  (TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.object_id)).resize(Nd);
525  for(int i=0; i < Nd; i++) {
526  (TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.object_id))[i] = obj[i];
527  }
528  TheNamedObjMap::Instance().get(params.named_obj.object_id).setFileXML(file_xml);
529  TheNamedObjMap::Instance().get(params.named_obj.object_id).setRecordXML(record_xml);
530  }
531  };
532 
533  // Call back
534  QIOReadObject* qioReadArrayLatColMatF(const Params& p)
535  {
536  return new QIOReadArrayLatColMatF(p);
537  }
538 
539 
540  //------------------------------------------------------------------------
541  //! Read a Double Prec Gauge Field
542  class QIOReadArrayLatColMatD : public QIOReadObject
543  {
544  private:
545  Params params;
546 
547  public:
548  QIOReadArrayLatColMatD(const Params& p) : params(p) {}
549 
550  //! Read a propagator
551  void operator()(QDP_serialparallel_t serpar) {
552  multi1d<LatticeColorMatrixD> obj;
553  XMLReader file_xml, record_xml;
554 
555  obj.resize(Nd); // BAD BAD BAD - FIX THIS
556 
557  QDPFileReader to(file_xml,params.file.file_name,serpar);
558  read(to,record_xml,obj);
559  close(to);
560 
561  TheNamedObjMap::Instance().create< multi1d<LatticeColorMatrix> >(params.named_obj.object_id);
562  (TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.object_id)).resize(Nd);
563  for(int i=0; i < Nd;i++) {
564  (TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.object_id))[i] = obj[i];
565  }
566 
567  TheNamedObjMap::Instance().get(params.named_obj.object_id).setFileXML(file_xml);
568  TheNamedObjMap::Instance().get(params.named_obj.object_id).setRecordXML(record_xml);
569  }
570  };
571 
572 
573  // Call back
574  QIOReadObject* qioReadArrayLatColMatD(const Params& p)
575  {
576  return new QIOReadArrayLatColMatD(p);
577  }
578 
579 
580  //------------------------------------------------------------------------
581  //! Read a QQDiquark object in floating precision
582  class QIOReadQQDiquarkContract : public QIOReadObject
583  {
584  private:
585  Params params;
586 
587  public:
588  QIOReadQQDiquarkContract(const Params& p) : params(p) {}
589 
590  //! Read a propagator
591  void operator()(QDP_serialparallel_t serpar) {
592  // Read the 1-d flattened array version
593  XMLReader file_xml, record_xml;
594  const int sz_qq = Ns*Ns*Ns*Ns*Nc*Nc;
595  multi1d<LatticeComplex> obj_1d(sz_qq);
596 
597  QDPFileReader to(file_xml,params.file.file_name,serpar);
598  read(to,record_xml,obj_1d);
599  close(to);
600 
601  // Create the named object
602  TheNamedObjMap::Instance().create<QQDiquarkContract_t>(params.named_obj.object_id);
603  TheNamedObjMap::Instance().get(params.named_obj.object_id).setFileXML(file_xml);
604  TheNamedObjMap::Instance().get(params.named_obj.object_id).setRecordXML(record_xml);
605 
606  // Convert the 1-d object into an N-d object
607  QQDiquarkContract_t& obj = TheNamedObjMap::Instance().getData<QQDiquarkContract_t>(params.named_obj.object_id);
608  multi1d<int> sz(6);
609  sz = Ns;
610  sz[4] = Nc; // cf
611  sz[5] = Nc; // ci
612  obj.comp.resize(sz);
613 
614  int cnt = 0;
615  multi1d<int> ranks(6);
616  for(ranks[0]=0; ranks[0] < sz[0]; ++ranks[0])
617  for(ranks[1]=0; ranks[1] < sz[1]; ++ranks[1])
618  for(ranks[2]=0; ranks[2] < sz[2]; ++ranks[2])
619  for(ranks[3]=0; ranks[3] < sz[3]; ++ranks[3])
620  for(ranks[4]=0; ranks[4] < sz[4]; ++ranks[4])
621  for(ranks[5]=0; ranks[5] < sz[5]; ++ranks[5])
622  {
623  // Sanity check - the size better match
624  if (cnt >= sz_qq)
625  {
626  QDPIO::cerr << __func__ << ": size mismatch for multi1Nd object" << std::endl;
627  QDP_abort(1);
628  }
629 
630  obj.comp[ranks] = obj_1d[cnt++];
631  }
632  }
633  };
634 
635  // Call back
636  QIOReadObject* qioReadQQDiquarkContract(const Params& p)
637  {
638  return new QIOReadQQDiquarkContract(p);
639  }
640 
641 
642  //------------------------------------------------------------------------
643  class QIOReadEigenInfoLatticeFermion : public QIOReadObject
644  {
645  private:
646  Params params;
647 
648  public:
649  QIOReadEigenInfoLatticeFermion(const Params& p) : params(p) {}
650 
651  //! Read a propagator
652  void operator()(QDP_serialparallel_t serpar) {
653  multi1d<Real64> evalsD;
654 
655  // RGE: I BELIEVE ALL THE COMPLAINTS BELOW ARE NOW FIXED IN QDP++,
656  // BUT I DO NOT WANT TO REMOVE THE CODE YET - CANNOT BE BOTHERED DEBUGGING
657 
658  // BUG? Need to read these as an array even though there is only one
659  // and also I need to know in advance the array size.
660  multi1d<Real64> largestD(1);
661 
662  // Would like this to be double, but casting double prec to single prec doesn't work.
663  LatticeFermion evecD;
664 
665  // Stuff
666  XMLReader file_xml, record_xml, largest_record_xml;
667 
668  // Open file
669  QDPFileReader to(file_xml,params.file.file_name,serpar);
670 
671  // Create object
672  TheNamedObjMap::Instance().create< EigenInfo<LatticeFermion> >(params.named_obj.object_id);
673 
674  // Read largest ev plus XML file containing number of eval/evec pairs
675  read(to, largest_record_xml, largestD);
676 
677  // Extract number of EVs from XML
678  int size;
679  try {
680  read(largest_record_xml, "/NumElem/n_vec", size);
681  }
682  catch(const std::string& e) {
683  QDPIO::cerr<< "Caught Exception while reading XML: " << e << std::endl;
684  QDP_abort(1);
685  }
686 
687  // Set largest EV
688  TheNamedObjMap::Instance().getData< EigenInfo<LatticeFermion> >(params.named_obj.object_id).getLargest()=largestD[0];
689 
690  // REsize eval arrays so that IO works correctly
691  evalsD.resize(size);
692 
693  // Read evals
694  read(to, record_xml, evalsD);
695 
696  QDPIO::cout << "Read " << evalsD.size() << "Evals " << std::endl;
697  for(int i=0; i < evalsD.size(); i++) {
698  QDPIO::cout << "Eval["<<i<<"] = " << Real(evalsD[i]) << std::endl;
699  }
700 
701  // Resize eval array
702  TheNamedObjMap::Instance().getData< EigenInfo<LatticeFermion> >(params.named_obj.object_id).getEvalues().resize(evalsD.size());
703 
704  // Downcast evals to Real() precision
705  for (int i=0; i<evalsD.size(); i++)
706  TheNamedObjMap::Instance().getData< EigenInfo<LatticeFermion> >(params.named_obj.object_id).getEvalues()[i] = Real(evalsD[i]);
707 
708 
709  // Resize evec arrays
710  // THIS IS AN EIGEN INFO - NOT SUBSET VECTORS
711  TheNamedObjMap::Instance().getData< EigenInfo<LatticeFermion> >(params.named_obj.object_id).getEvectors().resize(evalsD.size());
712 
713  // Loop and read evecs
714  for (int i=0; i<evalsD.size(); i++)
715  {
716  XMLReader record_xml_dummy;
717  read(to, record_xml_dummy, evecD);
718  LatticeFermion evecR;
719  evecR=evecD;
720 
721  TheNamedObjMap::Instance().getData< EigenInfo<LatticeFermion> >(params.named_obj.object_id).getEvectors()[i]=evecR;
722  }
723 
724  // Set File and Record XML throw away dummy XMLs
725  TheNamedObjMap::Instance().get(params.named_obj.object_id).setFileXML(file_xml);
726  TheNamedObjMap::Instance().get(params.named_obj.object_id).setRecordXML(record_xml);
727 
728  // Done - That too was unnecessarily painful
729  close(to);
730  }
731  };
732 
733  // Call back
734  QIOReadObject* qioReadEigenInfoLatticeFermion(const Params& p)
735  {
736  return new QIOReadEigenInfoLatticeFermion(p);
737  }
738 
739 
740  //-----------------------------------------------------------------------
741  //! Read a RitzPairs Type
742  class QIOReadRitzPairsLatticeFermion : public QIOReadObject
743  {
744  private:
745  Params params;
746 
747  public:
748  QIOReadRitzPairsLatticeFermion(const Params& p) : params(p) {}
749 
750  //! Read a propagator
751  void operator()(QDP_serialparallel_t serpar) {
752  // File XML
753  XMLReader file_xml;
754 
755  // Open file
756  QDPFileReader to(file_xml,params.file.file_name,serpar);
757 
758  // Create the named object
759  TheNamedObjMap::Instance().create< LinAlg::RitzPairs<LatticeFermion> >(params.named_obj.object_id);
760  TheNamedObjMap::Instance().get(params.named_obj.object_id).setFileXML(file_xml);
761 
762  // A shorthand for the object
763  LinAlg::RitzPairs<LatticeFermion>& obj =
764  TheNamedObjMap::Instance().getData<LinAlg::RitzPairs< LatticeFermion> >(params.named_obj.object_id);
765 
766  XMLReader record_xml;
767  TheNamedObjMap::Instance().get(params.named_obj.object_id).setRecordXML(record_xml);
768 
769  int Nmax;
770  read(file_xml, "/RitzPairs/Nmax", Nmax);
771  read(file_xml, "/RitzPairs/Neig", obj.Neig);
772 
773  obj.evec.resize(Nmax);
774  obj.eval.resize(Nmax);
775 
776  if (obj.Neig > Nmax)
777  {
778  QDPIO::cerr << __func__ << ": error, found Neig > Nmax" << std::endl;
779  QDP_abort(1);
780  }
781 
782  // Read a record for each eigenvalue (in xml) and eigenstd::vector
783  for(int i=0; i < obj.Neig; ++i)
784  {
785  XMLReader record_xml;
786  read(to, record_xml, obj.evec.vec[i]);
787 
788  read(record_xml, "/Eigenstd::vector/eigenValue", obj.eval.vec[i]);
789  }
790 
791  // Close
792  close(to);
793  }
794  };
795 
796  // Call back
797  QIOReadObject* qioReadRitzPairsLatticeFermion(const Params& p)
798  {
799  return new QIOReadRitzPairsLatticeFermion(p);
800  }
801 
802 
803 
804  //------------------------------------------------------------------------
805  //------------------------------------------------------------------------
806 
807  //! Local registration flag
808  bool registered = false;
809 
810  } // end namespace
811 
812 
813  //! Register all the factories
814  bool registerAll()
815  {
816  bool success = true;
817  if (! registered)
818  {
819  success &= TheQIOReadObjectFactory::Instance().registerObject(std::string("LatticePropagator"),
820  qioReadLatProp);
821  success &= TheQIOReadObjectFactory::Instance().registerObject(std::string("LatticePropagatorF"),
822  qioReadLatPropF);
823  success &= TheQIOReadObjectFactory::Instance().registerObject(std::string("LatticePropagatorD"),
824  qioReadLatPropD);
825 
826  success &= TheQIOReadObjectFactory::Instance().registerObject(std::string("LatticeStaggeredPropagator"),
827  qioReadStagLatProp);
828  success &= TheQIOReadObjectFactory::Instance().registerObject(std::string("LatticeStaggeredPropagatorF"),
829  qioReadStagLatPropF);
830  success &= TheQIOReadObjectFactory::Instance().registerObject(std::string("LatticeStaggeredPropagatorD"),
831  qioReadStagLatPropD);
832 
833  success &= TheQIOReadObjectFactory::Instance().registerObject(std::string("SubsetVectorsLatticeColorVector"),
834  qioReadSubsetVectorsLCV);
835 
836  success &= TheQIOReadObjectFactory::Instance().registerObject(std::string("LatticeFermion"),
837  qioReadLatFerm);
838 
839 // success &= TheQIOReadObjectFactory::Instance().registerObject(std::string("LatticeFermionF"),
840 // qioReadLatFermF);
841 // success &= TheQIOReadObjectFactory::Instance().registerObject(std::string("LatticeFermionD"),
842 // qioReadLatFermD);
843 
844  success &= TheQIOReadObjectFactory::Instance().registerObject(std::string("Multi1dLatticeColorMatrix"),
845  qioReadArrayLatColMat);
846 
847  success &= TheQIOReadObjectFactory::Instance().registerObject(std::string("Multi1dLatticeColorMatrixF"),
848  qioReadArrayLatColMatF);
849 
850  success &= TheQIOReadObjectFactory::Instance().registerObject(std::string("Multi1dLatticeColorMatrixD"),
851  qioReadArrayLatColMatD);
852 
853  success &= TheQIOReadObjectFactory::Instance().registerObject(std::string("QQDiquarkContract"),
854  qioReadQQDiquarkContract);
855 
856  success &= TheQIOReadObjectFactory::Instance().registerObject(std::string("EigenInfoLatticeFermion"),
857  qioReadEigenInfoLatticeFermion);
858 
859  success &= TheQIOReadObjectFactory::Instance().registerObject(std::string("RitzPairsLatticeFermion"),
860  qioReadRitzPairsLatticeFermion);
861 
862  registered = true;
863  }
864  return success;
865  }
866  } // namespace QIOReadObjectEnv
867 
868 
869  //------------------------------------------------------------------------
870  namespace
871  {
872  AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
873  const std::string& path)
874  {
875  return new InlineMeas(Params(xml_in, path));
876  }
877 
878  //! Local registration flag
879  bool registered = false;
880 
881  const std::string name = "QIO_READ_NAMED_OBJECT";
882  }
883 
884  //! Register all the factories
885  bool registerAll()
886  {
887  bool success = true;
888  if (! registered)
889  {
890  success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
891  success &= QIOReadObjectEnv::registerAll();
893  registered = true;
894  }
895  return success;
896  }
897 
898 
899  //------------------------------------------------------------------------
901  {
904  };
905 
906 
907  //! Object buffer
908  void read(XMLReader& xml, const std::string& path, Params::NamedObject_t& input)
909  {
910  XMLReader inputtop(xml, path);
911 
912  read(inputtop, "object_id", input.object_id);
913  read(inputtop, "object_type", input.object_type);
914  }
915 
916  //! File output
917  void read(XMLReader& xml, const std::string& path, Params::File_t& input)
918  {
919  XMLReader inputtop(xml, path);
920 
921  read(inputtop, "file_name", input.file_name);
922  if( inputtop.count("parallel_io") == 1 ) {
923  read(inputtop, "parallel_io", input.parallel_io);
924  }
925  else {
926  input.parallel_io = Layout::isIOGridDefined() && ( Layout::numIONodeGrid() > 1 );
927  }
928  }
929 
930 
931  // Param stuff
933 
934  Params::Params(XMLReader& xml_in, const std::string& path)
935  {
936  try
937  {
938  XMLReader paramtop(xml_in, path);
939 
940  if (paramtop.count("Frequency") == 1)
941  read(paramtop, "Frequency", frequency);
942  else
943  frequency = 1;
944 
945  // Named objects - original copy
946  named_obj_xml = readXMLGroup(paramtop, "NamedObject", "object_type");
947 
948  // Named objects - make a concrete copy. Useful for digging out basic stuff.
949  read(paramtop, "NamedObject", named_obj);
950 
951  // File name
952  read(paramtop, "File", file);
953  }
954  catch(const std::string& e)
955  {
956  QDPIO::cerr << __func__ << ": caught Exception reading XML: " << e << std::endl;
957  QDP_abort(1);
958  }
959  }
960 
961 
962  void
963  InlineMeas::operator()(unsigned long update_no,
964  XMLWriter& xml_out)
965  {
966  START_CODE();
967 
968  push(xml_out, "qio_read_named_obj");
969  write(xml_out, "update_no", update_no);
970 
971  QDPIO::cout << name << ": object reader" << std::endl;
972  StopWatch swatch;
973 
974  // Read the object
975  // ONLY SciDAC output format is supported in this task
976  // Other tasks could support other disk formats
977  try
978  {
979  QDPIO::cout << "Attempt to read object name = " << params.named_obj.object_id << std::endl;
980  write(xml_out, "object_id", params.named_obj.object_id);
981 
982  // Create the object reader
984  QIOReadObjectEnv::TheQIOReadObjectFactory::Instance().createObject(params.named_obj.object_type,
985  params));
986  QDP_serialparallel_t serpar;
987  if ( params.file.parallel_io ) {
988  QDPIO::cout << "Attempting Parallel IO read" << std::endl;
989  serpar = QDPIO_PARALLEL;
990  }
991  else {
992  serpar = QDPIO_SERIAL;
993  }
994 
995  // Read the object
996  swatch.start();
997 
998  (*qioReadObject)(serpar);
999 
1000  swatch.stop();
1001 
1002  QDPIO::cout << "Object successfully read: time= "
1003  << swatch.getTimeInSeconds()
1004  << " secs" << std::endl;
1005  }
1006  catch( std::bad_cast )
1007  {
1008  QDPIO::cerr << name << ": caught dynamic cast error"
1009  << std::endl;
1010  QDP_abort(1);
1011  }
1012  catch (const std::string& e)
1013  {
1014  QDPIO::cerr << name << ": std::map call failed: " << e
1015  << std::endl;
1016  QDP_abort(1);
1017  }
1018 
1019  QDPIO::cout << name << ": ran successfully" << std::endl;
1020 
1021  pop(xml_out); // qio_read_named_obj
1022 
1023  END_CODE();
1024  }
1025 
1026  }
1027 
1028 }
Inline measurement factory.
Class for counted reference semantics.
Definition: handle.h:33
void operator()(const unsigned long update_no, XMLWriter &xml_out)
Do the writing.
virtual void operator()(QDP_serialparallel_t serpar)=0
Read the object.
Object factory class.
Definition: objfactory.h:82
static T & Instance()
Definition: singleton.h:432
Construct a diquark object.
Hold eigenvalues and eigenvectors.
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.
Class for counted reference semantics.
Params params
Handle< MapObject< int, EVPair< LatticeColorVector > > > obj
Inline task to read an object from a named buffer.
Key for propagator colorstd::vector sources.
unsigned n
Definition: ldumul_w.cc:36
Nd
Definition: meslate.cc:74
Named object function std::map.
static bool registered
Local registration flag.
const std::string name
Name to be used.
void read(XMLReader &xml, const std::string &path, Params::NamedObject_t &input)
Object buffer.
bool registerAll()
Register all the factories.
bool registerAll()
aggregate everything
multi1d< Hadron2PtContraction_t > operator()(const multi1d< LatticeColorMatrix > &u)
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
push(xml_out,"Condensates")
int i
Definition: pbg5p_w.cc:55
pop(xml_out)
START_CODE()
::std::string string
Definition: gtest.h:1979
Real dummy
Definition: qtopcor.cc:36
Holds of vectors and weights.
#define TYPELIST_1(T1)
Definition: typelist.h:41