CHROMA
inline_distillution_noise.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Setup the origin and noise factory for distillution
3  *
4  * Setup for distillution
5  */
6 
10 #include "util/info/proginfo.h"
12 
14 
15 namespace Chroma
16 {
17  namespace InlineDistillutionNoiseEnv
18  {
19  //! Propagator input
20  void read(XMLReader& xml, const std::string& path, Params::NamedObject_t& input)
21  {
22  XMLReader inputtop(xml, path);
23 
24  read(inputtop, "distillution_id", input.distillution_id);
25  }
26 
27  //! Propagator output
28  void write(XMLWriter& xml, const std::string& path, const Params::NamedObject_t& input)
29  {
30  push(xml, path);
31 
32  write(xml, "distillution_id", input.distillution_id);
33 
34  pop(xml);
35  }
36 
37 
38  //! Propagator input
39  void read(XMLReader& xml, const std::string& path, Params::Param_t& input)
40  {
41  XMLReader inputtop(xml, path);
42 
43  read(inputtop, "decay_dir", input.decay_dir);
44  read(inputtop, "ensemble", input.ensemble);
45  read(inputtop, "sequence", input.sequence);
46  }
47 
48  //! Propagator output
49  void write(XMLWriter& xml, const std::string& path, const Params::Param_t& input)
50  {
51  push(xml, path);
52 
53  write(xml, "decay_dir", input.decay_dir);
54  write(xml, "ensemble", input.ensemble);
55  write(xml, "sequence", input.sequence);
56 
57  pop(xml);
58  }
59 
60 
61  //! Propagator input
62  void read(XMLReader& xml, const std::string& path, Params& input)
63  {
64  Params tmp(xml, path);
65  input = tmp;
66  }
67 
68  //! Propagator output
69  void write(XMLWriter& xml, const std::string& path, const Params& input)
70  {
71  push(xml, path);
72 
73  write(xml, "Param", input.param);
74  write(xml, "NamedObject", input.named_obj);
75 
76  pop(xml);
77  }
78 
79 
80  //---------------------------------------------------------------------------------
81  namespace
82  {
83  AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
84  const std::string& path)
85  {
86  return new InlineMeas(Params(xml_in, path));
87  }
88 
89  //! Local registration flag
90  bool registered = false;
91  }
92 
93  const std::string name = "DISTILLUTION_NOISE";
94 
95  //! Register all the factories
96  bool registerAll()
97  {
98  bool success = true;
99  if (! registered)
100  {
101  success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
102  registered = true;
103  }
104  return success;
105  }
106 
107 
108  //----------------------------------------------------------------------------
109  // Param stuff
111 
112  Params::Params(XMLReader& xml_in, const std::string& path)
113  {
114  try
115  {
116  XMLReader paramtop(xml_in, path);
117 
118  if (paramtop.count("Frequency") == 1)
119  read(paramtop, "Frequency", frequency);
120  else
121  frequency = 1;
122 
123  // Parameters for source construction
124  read(paramtop, "Param", param);
125 
126  // Read in the output propagator/source configuration info
127  read(paramtop, "NamedObject", named_obj);
128 
129  // Possible alternate XML file pattern
130  if (paramtop.count("xml_file") != 0)
131  {
132  read(paramtop, "xml_file", xml_file);
133  }
134  }
135  catch(const std::string& e)
136  {
137  QDPIO::cerr << __func__ << ": Caught Exception reading XML: " << e << std::endl;
138  QDP_abort(1);
139  }
140  }
141 
142 
143 
144  // Function call
145  void
146  InlineMeas::operator()(unsigned long update_no,
147  XMLWriter& xml_out)
148  {
149  // If xml file not empty, then use alternate
150  if (params.xml_file != "")
151  {
152  std::string xml_file = makeXMLFileName(params.xml_file, update_no);
153 
154  push(xml_out, "DistillutionNoise");
155  write(xml_out, "update_no", update_no);
156  write(xml_out, "xml_file", xml_file);
157  pop(xml_out);
158 
159  XMLFileWriter xml(xml_file);
160  func(update_no, xml);
161  }
162  else
163  {
164  func(update_no, xml_out);
165  }
166  }
167 
168 
169  // Real work done here
170  void
171  InlineMeas::func(unsigned long update_no,
172  XMLWriter& xml_out)
173  {
174  START_CODE();
175 
176  StopWatch snoop;
177  snoop.reset();
178  snoop.start();
179 
180  push(xml_out, "DistillutionNoise");
181  write(xml_out, "update_no", update_no);
182 
183  QDPIO::cout << name << ": initialize distillution noise factory" << std::endl;
184 
185  proginfo(xml_out); // Print out basic program info
186 
187  // Write out the input
188  write(xml_out, "Input", params);
189 
190  //
191  // Read in the source along with relevant information.
192  //
193  QDPIO::cout << "Create a distillution factory" << std::endl;
194  try
195  {
196  // Build new object
200 
201  }
202  catch (std::bad_cast)
203  {
204  QDPIO::cerr << name << ": caught dynamic cast error" << std::endl;
205  QDP_abort(1);
206  }
207  catch (const std::string& e)
208  {
209  QDPIO::cerr << name << ": error creating distillution_noise object: " << e << std::endl;
210  QDP_abort(1);
211  }
212 
213  pop(xml_out); // distillution_noise
214 
215  snoop.stop();
216  QDPIO::cout << name << ": total time = "
217  << snoop.getTimeInSeconds()
218  << " secs" << std::endl;
219 
220  QDPIO::cout << name << ": ran successfully" << std::endl;
221 
222  END_CODE();
223  }
224 
225  }
226 
227 } // namespace Chroma
Inline measurement factory.
Class for counted reference semantics.
Definition: handle.h:33
void func(const unsigned long update_no, XMLWriter &xml_out)
Do the measurement.
void operator()(const unsigned long update_no, XMLWriter &xml_out)
Do the measurement.
static T & Instance()
Definition: singleton.h:432
Support for distillution - random time-slices and quark line noises.
void proginfo(XMLWriter &xml)
Print out basic information about this program.
Definition: proginfo.cc:24
std::string makeXMLFileName(std::string xml_file, unsigned long update_no)
Return a xml file name for inline measurements.
Setup the origin and noise factory for distillution.
Make xml file writer.
Named object function std::map.
static bool registered
Local registration flag.
bool registerAll()
Register all the factories.
void write(XMLWriter &xml, const std::string &path, const Params::NamedObject_t &input)
Propagator output.
void read(XMLReader &xml, const std::string &path, Params::NamedObject_t &input)
Propagator input.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
LatticeFermion tmp
Definition: mespbg5p_w.cc:36
push(xml_out,"Condensates")
pop(xml_out)
START_CODE()
::std::string string
Definition: gtest.h:1979
Print out basic info about this program.