CHROMA
monomial_io.cc
Go to the documentation of this file.
1 #include "chromabase.h"
2 #include "io/monomial_io.h"
5 
6 namespace Chroma {
7 
8 void read(XMLReader& xml,
9  const std::string& path,
10  Handle< Monomial< multi1d<LatticeColorMatrix>,
11  multi1d<LatticeColorMatrix> > >& mon_handle )
12 {
13  XMLReader paramtop(xml, path);
14  std::string monomial_name;
15  try {
16  read( paramtop, "./Name", monomial_name);
17  mon_handle = TheMonomialFactory::Instance().createObject( monomial_name, xml, path );
18  }
19  catch( const std::string& e ) {
20  QDPIO::cerr << "Error Reading Monommial: " << e << std::endl;
21  QDP_abort(1);
22  }
23 }
24 
25 void read(XMLReader& xml,
26  const std::string& path,
27  Handle< ExactMonomial< multi1d<LatticeColorMatrix>,
28  multi1d<LatticeColorMatrix> > >& mon_handle )
29 {
30 
31  XMLReader paramtop(xml, path);
32  std::string monomial_name;
33  Monomial<multi1d<LatticeColorMatrix>, multi1d<LatticeColorMatrix> >* m;
34 
35  try {
36  read( paramtop, "./Name", monomial_name);
37  m = TheMonomialFactory::Instance().createObject( monomial_name, xml, path );
38  }
39  catch( const std::string& e ) {
40  QDPIO::cerr << "Error Reading Monommial: " << e << std::endl;
41  QDP_abort(1);
42  }
43 
44  ExactMonomial<multi1d<LatticeColorMatrix>, multi1d<LatticeColorMatrix> >* em;
45  em = dynamic_cast< ExactMonomial<multi1d<LatticeColorMatrix>, multi1d<LatticeColorMatrix> >* >(m);
46  if( em == 0 ) {
47  QDPIO::cerr << "Failed to downcast monomial to exact monomial " << std::endl;
48  QDP_abort(1);
49  }
50 
51  mon_handle = em;
52 
53 }
54 
55 //! Read a named monomial from an XML reader, usa factory to create and assign the pointer to a handle in the named object std::map of monomial handles.
56 /*! \ingroup io */
57 void readNamedMonomial(XMLReader& xml,
58  const std::string& path,
59  std::string& monomial_id)
60 
61 {
62 
63  typedef multi1d<LatticeColorMatrix> LCM;
64 
65  try {
66  XMLReader paramtop(xml, path);
67 
68  try {
69  XMLReader named_object_xml(paramtop, "./NamedObject");
70  read(named_object_xml, "./monomial_id", monomial_id);
71  }
72  catch(const std::string& e) {
73  QDPIO::cerr << "Failed to find NamedObject tag or monomial ID in readNamedMonomial" << std::endl << std::flush;
74  QDP_abort(1);
75  }
76 
77  // Create the ID in the named Object space:
78  TheNamedObjMap::Instance().create< Handle<Monomial<LCM,LCM> > >(monomial_id);
79  XMLBufferWriter file_xml;
80  push(file_xml, "DummyFileXML");
81  pop(file_xml);
82 
83  XMLBufferWriter record_xml;
84  push(record_xml, "Monomial");
85  record_xml << paramtop; // Everything in current scope int
86  pop(record_xml);
87 
88  TheNamedObjMap::Instance().get(monomial_id).setFileXML(file_xml);
89  TheNamedObjMap::Instance().get(monomial_id).setRecordXML(record_xml);
90 
91  std::string monomial_name;
92  read( paramtop, "./Name", monomial_name);
93 
94 
95  Handle< Monomial<LCM,LCM> > mon_handle( TheMonomialFactory::Instance().createObject( monomial_name, xml, path ) );
96 
97  // Here I add the handle to the named object std::map...
98  TheNamedObjMap::Instance().getData< Handle< Monomial<LCM,LCM> > >(monomial_id) = mon_handle;
99  }
100  catch( const std::string &e) {
101  QDPIO::cerr << "Caught exception with message: " << e << std::endl;
102  QDP_abort(1);
103  }
104 }
105 
106 void readNamedMonomialArray(XMLReader& xml,
107  const std::string& path)
108 {
109  try {
110  std::string monomial_id;
111  XMLReader arraytop(xml, path);
112  int n_items = arraytop.count("./elem");
113  for(int i=1; i <= n_items; i++) {
114  std::ostringstream os;
115  os << "./elem["<< i << "]";
116  readNamedMonomial(arraytop, os.str(), monomial_id);
117  QDPIO::cout << "Read Monomial with monomial id: " << monomial_id <<std::endl;
118 
119  }
120  }
121  catch( const std::string& e) {
122  QDPIO::cout << "Caught Exception with message: " << e << std::endl << std::flush;
123  QDP_abort(1);
124  }
125 }
126 
127 }
Primary include file for CHROMA library code.
Abstract monomial class, for exact algorithms.
Definition: abs_monomial.h:75
Class for counted reference semantics.
Definition: handle.h:33
An abstract monomial class, for inexact algorithms.
Definition: abs_monomial.h:43
static T & Instance()
Definition: singleton.h:432
void read(XMLReader &xml, const std::string &path, AsqtadFermActParams &param)
Read parameters.
void readNamedMonomialArray(XMLReader &xml, const std::string &path)
Read an array of named monomials from an XML reader. use factory to create the monomials and put them...
Definition: monomial_io.cc:106
void readNamedMonomial(XMLReader &xml, const std::string &path, std::string &monomial_id)
Read a named monomial from an XML reader, usa factory to create and assign the pointer to a handle in...
Definition: monomial_io.cc:57
static int m[4]
Definition: make_seeds.cc:16
Monomial factories.
Monomial IO.
Named object function std::map.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
push(xml_out,"Condensates")
int i
Definition: pbg5p_w.cc:55
pop(xml_out)
multi1d< LatticeColorMatrix > LCM
Definition: asqtad_qprop.cc:20
::std::string string
Definition: gtest.h:1979