CHROMA
inline_gaussian_obj.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Inline task to gaussian init a named object
3  *
4  * Named object initialization
5  */
6 
7 #include "singleton.h"
8 #include "funcmap.h"
9 #include "chromabase.h"
10 #include "handle.h"
11 
15 
17 #include "qdp_map_obj_memory.h"
18 
19 #include "util/ft/sftmom.h"
20 #include "meas/eig/gramschm.h"
21 
22 namespace Chroma
23 {
24  namespace InlineGaussianInitNamedObjEnv
25  {
26  //! IO function std::map environment
27  /*! \ingroup inlineio */
28  namespace GaussianInitObjCallMapEnv
29  {
30  // Anonymous namespace
31  namespace
32  {
33  struct DumbDisambiguator {};
34 
35  //! GaussianInit init function std::map
36  /*! \ingroup inlineio */
37  typedef SingletonHolder<
38  FunctionMap<DumbDisambiguator,
39  void,
41  TYPELIST_1(const std::string&),
42  void (*)(const std::string& buffer_id),
44  TheGaussianInitObjFuncMap;
45  }
46 
47 
48  namespace
49  {
50  //! Init a propagator
51  template<typename T>
52  void gaussianInitObj(const std::string& buffer_id)
53  {
54  TheNamedObjMap::Instance().create<T>(buffer_id);
55  XMLBufferWriter file_xml, record_xml;
56 
57  push(file_xml,"FileXML");
58  pop(file_xml);
59 
60  push(record_xml,"RecordXML");
61  pop(record_xml);
62 
63  gaussian(TheNamedObjMap::Instance().getData<T>(buffer_id));
64  TheNamedObjMap::Instance().get(buffer_id).setFileXML(file_xml);
65  TheNamedObjMap::Instance().get(buffer_id).setRecordXML(record_xml);
66  }
67 
68  //! Init a propagator
69  void gaussianInitMulti1dLatColMat(const std::string& buffer_id)
70  {
71  multi1d<LatticeColorMatrix> u(Nd);
72  for(int mu=0; mu < u.size(); ++mu)
73  gaussian(u[mu]);
74 
75  XMLBufferWriter file_xml, record_xml;
76 
77  push(file_xml,"FileXML");
78  pop(file_xml);
79 
80  push(record_xml,"RecordXML");
81  pop(record_xml);
82 
83  TheNamedObjMap::Instance().create< multi1d<LatticeColorMatrix> >(buffer_id);
84  TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(buffer_id) = u;
85  TheNamedObjMap::Instance().get(buffer_id).setFileXML(file_xml);
86  TheNamedObjMap::Instance().get(buffer_id).setRecordXML(record_xml);
87  }
88 
89 
90  //! Init a faky gaussian MapObject Type of struct of keys and vals
91  void gaussianInitMapObjKeyPropColorVecLatFerm(const std::string& buffer_id)
92  {
93  // Create the object
94  {
95  // Make a new object - for now memory. Later create with factory
96  Handle<QDP::MapObject<KeyPropColorVec_t,LatticeFermion> > new_obj_handle( new MapObjectMemory<KeyPropColorVec_t,LatticeFermion>() );
97 
98  // Create slot
100 
101  // Insert
103  }
104 
105  // Now make a working reference
106  QDP::MapObject<KeyPropColorVec_t,LatticeFermion>& obj =
108 
109  // Fix these. Put two sources in here.
110  int N = 8;
111  multi1d<int> t_sources(2);
112  t_sources[0] = 0;
113  t_sources[1] = QDP::Layout::lattSize()[Nd-1] / 2;
114 
115  // Loop over each source and create a fake set of propagators
116  for(int tt=0; tt < t_sources.size(); ++tt)
117  {
118  int t0 = t_sources[tt];
119 
120  for(int colorvec_src=0; colorvec_src < N; ++colorvec_src)
121  {
122  for(int spin_src=0; spin_src < Ns; ++spin_src)
123  {
124  // The key
125  KeyPropColorVec_t key;
126  key.t_source = t0;
127  key.colorvec_src = colorvec_src;
128  key.spin_src = spin_src;
129 
130  // The value
131  LatticeFermion val;
132  gaussian(val);
133 
134  // Insert the key and value into the std::map
135  obj.insert(key, val);
136  } // spin_src
137  } // colorvec_src
138  } // tt
139 
140  obj.flush(); // Done inserting
141 
142  // Write the meta-data for this operator
143  {
144  XMLBufferWriter file_xml;
145 
146  push(file_xml, "PropColorVectors");
147  write(file_xml, "num_records", obj.size());
148  push(file_xml, "Params");
149  pop(file_xml);
150  push(file_xml, "Config_info");
151  pop(file_xml);
152  pop(file_xml); // PropColorVectors
153 
154  XMLBufferWriter record_xml;
155  push(record_xml, "PropColorVector");
156  write(record_xml, "num_records", obj.size());
157  pop(record_xml);
158 
159  // Write the propagator xml info
160  TheNamedObjMap::Instance().get(buffer_id).setFileXML(file_xml);
161  TheNamedObjMap::Instance().get(buffer_id).setRecordXML(record_xml);
162  }
163  }
164 
165 
166  //! Local registration flag
167  bool registered = false;
168 
169  } // end namespace GaussianInitCallMap
170 
171  //! Register all the factories
172  bool registerAll()
173  {
174  bool success = true;
175  if (! registered)
176  {
177  success &= TheGaussianInitObjFuncMap::Instance().registerFunction(std::string("LatticePropagator"),
178  gaussianInitObj<LatticePropagator>);
179  success &= TheGaussianInitObjFuncMap::Instance().registerFunction(std::string("LatticeFermion"),
180  gaussianInitObj<LatticeFermion>);
181  success &= TheGaussianInitObjFuncMap::Instance().registerFunction(std::string("LatticeStaggeredPropagator"),
182  gaussianInitObj<LatticeStaggeredPropagator>);
183  success &= TheGaussianInitObjFuncMap::Instance().registerFunction(std::string("LatticeStaggeredFermion"),
184  gaussianInitObj<LatticeStaggeredFermion>);
185  success &= TheGaussianInitObjFuncMap::Instance().registerFunction(std::string("MapObjectKeyPropColorVecLatticeFermion"),
186  gaussianInitMapObjKeyPropColorVecLatFerm);
187 
188  registered = true;
189  }
190  return success;
191  }
192  } // end CallMap namespace
193 
194 
195  namespace
196  {
197  AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
198  const std::string& path)
199  {
200  return new InlineMeas(Params(xml_in, path));
201  }
202 
203  //! Local registration flag
204  bool registered = false;
205 
206  const std::string name = "GAUSSIAN_INIT_NAMED_OBJECT";
207  }
208 
209  //! Register all the factories
210  bool registerAll()
211  {
212  bool success = true;
213  if (! registered)
214  {
215  // Gaussian init functions
217  // Inline measurement
218  success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
219  registered = true;
220  }
221  return success;
222  }
223 
224 
225  //! Object buffer
226  void write(XMLWriter& xml, const std::string& path, const Params::NamedObject_t& input)
227  {
228  push(xml, path);
229 
230  write(xml, "object_id", input.object_id);
231  write(xml, "object_type", input.object_type);
232 
233  pop(xml);
234  }
235 
236 
237  //! Object buffer
238  void read(XMLReader& xml, const std::string& path, Params::NamedObject_t& input)
239  {
240  XMLReader inputtop(xml, path);
241 
242  read(inputtop, "object_id", input.object_id);
243  read(inputtop, "object_type", input.object_type);
244  }
245 
246 
247  // Param stuff
249 
250  Params::Params(XMLReader& xml_in, const std::string& path)
251  {
252  try
253  {
254  XMLReader paramtop(xml_in, path);
255 
256  if (paramtop.count("Frequency") == 1)
257  read(paramtop, "Frequency", frequency);
258  else
259  frequency = 1;
260 
261  // Ids
262  read(paramtop, "NamedObject", named_obj);
263  }
264  catch(const std::string& e)
265  {
266  QDPIO::cerr << __func__ << ": caught Exception reading XML: " << e << std::endl;
267  QDP_abort(1);
268  }
269  }
270 
271 
272  void
273  Params::writeXML(XMLWriter& xml_out, const std::string& path)
274  {
275  push(xml_out, path);
276 
277  // Ids
278  write(xml_out, "NamedObject", named_obj);
279 
280  pop(xml_out);
281  }
282 
283 
284  void
285  InlineMeas::operator()(unsigned long update_no,
286  XMLWriter& xml_out)
287  {
288  START_CODE();
289 
290  push(xml_out, "gaussian_init_named_obj");
291  write(xml_out, "update_no", update_no);
292 
293  QDPIO::cout << name << ": gaussian init an object of type "
294  << params.named_obj.object_type << std::endl;
295 
296  // Gaussian the object
297  QDPIO::cout << "Attempt to list all object names" << std::endl;
298  try
299  {
300  // Gaussian init the object
301  GaussianInitObjCallMapEnv::TheGaussianInitObjFuncMap::Instance().callFunction(params.named_obj.object_type,
303  }
304  catch (std::bad_cast)
305  {
306  QDPIO::cerr << name << ": cast error"
307  << std::endl;
308  QDP_abort(1);
309  }
310  catch (const std::string& e)
311  {
312  QDPIO::cerr << name << ": error message: " << e
313  << std::endl;
314  QDP_abort(1);
315  }
316 
317  QDPIO::cout << name << ": ran successfully" << std::endl;
318 
319  pop(xml_out); // gaussian_init_named_obj
320 
321  END_CODE();
322  }
323 
324  }
325 
326 }
Inline measurement factory.
Primary include file for CHROMA library code.
Object factory class.
Definition: funcmap.h:89
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
int mu
Definition: cool.cc:24
Map of function calls.
Gramm-Schmidt orthogonolization.
Class for counted reference semantics.
Inline task to gaussian init a named object.
Handle< MapObject< int, EVPair< LatticeColorVector > > > obj
Key for propagator colorstd::vector sources.
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 write(XMLWriter &xml, const std::string &path, const Params::NamedObject_t &input)
Object buffer.
bool registerAll()
Register all the factories.
void read(XMLReader &xml, const std::string &path, Params::NamedObject_t &input)
Object buffer.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
gaussian(aux)
static multi1d< LatticeColorMatrix > u
push(xml_out,"Condensates")
LinOpSysSolverMGProtoClover::T T
pop(xml_out)
START_CODE()
::std::string string
Definition: gtest.h:1979
Fourier transform phase factor support.
Singleton support.
struct Chroma::InlineGaussianInitNamedObjEnv::Params::NamedObject_t named_obj
void writeXML(XMLWriter &xml_out, const std::string &path)
#define TYPELIST_1(T1)
Definition: typelist.h:41