00001
00002
00003
00004
00005
00006
00007
00008 #include "handle.h"
00009 #include "meas/inline/hadron_s/inline_make_source_s.h"
00010 #include "meas/inline/abs_inline_measurement_factory.h"
00011 #include "meas/glue/mesplq.h"
00012 #include "meas/sources/source_const_factory.h"
00013 #include "meas/sources/source_const_aggregate.h"
00014
00015 #include "util/ft/sftmom.h"
00016 #include "util/info/proginfo.h"
00017 #include "util/info/unique_id.h"
00018 #include "meas/inline/make_xml_file.h"
00019
00020 #include "meas/inline/io/named_objmap.h"
00021
00022 namespace Chroma
00023 {
00024
00025 void read(XMLReader& xml, const string& path, InlineStaggeredMakeSourceEnv::Params::NamedObject_t& input)
00026 {
00027 XMLReader inputtop(xml, path);
00028
00029 read(inputtop, "gauge_id", input.gauge_id);
00030 read(inputtop, "source_id", input.source_id);
00031 }
00032
00033
00034 void write(XMLWriter& xml, const string& path, const InlineStaggeredMakeSourceEnv::Params::NamedObject_t& input)
00035 {
00036 push(xml, path);
00037
00038 write(xml, "gauge_id", input.gauge_id);
00039 write(xml, "source_id", input.source_id);
00040
00041 pop(xml);
00042 }
00043
00044
00045 namespace InlineStaggeredMakeSourceEnv
00046 {
00047 namespace
00048 {
00049 AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
00050 const std::string& path)
00051 {
00052 return new InlineMeas(Params(xml_in, path));
00053 }
00054
00055
00056 bool registered = false;
00057 }
00058
00059 const std::string name = "MAKE_SOURCE_STAG";
00060
00061
00062 bool registerAll()
00063 {
00064 bool success = true;
00065 if (! registered)
00066 {
00067 success &= QuarkSourceConstructionEnv::registerAll();
00068 success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
00069 registered = true;
00070 }
00071 return success;
00072 }
00073
00074
00075
00076
00077 Params::Params() { frequency = 0; }
00078
00079 Params::Params(XMLReader& xml_in, const std::string& path)
00080 {
00081 try
00082 {
00083 XMLReader paramtop(xml_in, path);
00084
00085 if (paramtop.count("Frequency") == 1)
00086 read(paramtop, "Frequency", frequency);
00087 else
00088 frequency = 1;
00089
00090
00091 read(paramtop, "Param", param);
00092
00093
00094 read(paramtop, "NamedObject", named_obj);
00095
00096
00097 if (paramtop.count("xml_file") != 0)
00098 {
00099 read(paramtop, "xml_file", xml_file);
00100 }
00101 }
00102 catch(const std::string& e)
00103 {
00104 QDPIO::cerr << __func__ << ": Caught Exception reading XML: " << e << endl;
00105 QDP_abort(1);
00106 }
00107 }
00108
00109
00110
00111 void
00112 Params::writeXML(XMLWriter& xml_out, const std::string& path)
00113 {
00114 push(xml_out, path);
00115
00116
00117 write(xml_out, "Param", param);
00118
00119
00120 write(xml_out, "NamedObject", named_obj);
00121
00122 pop(xml_out);
00123 }
00124
00125
00126
00127 void
00128 InlineMeas::operator()(unsigned long update_no,
00129 XMLWriter& xml_out)
00130 {
00131
00132 if (params.xml_file != "")
00133 {
00134 string xml_file = makeXMLFileName(params.xml_file, update_no);
00135
00136 push(xml_out, "make_source_stag");
00137 write(xml_out, "update_no", update_no);
00138 write(xml_out, "xml_file", xml_file);
00139 pop(xml_out);
00140
00141 XMLFileWriter xml(xml_file);
00142 func(update_no, xml);
00143 }
00144 else
00145 {
00146 func(update_no, xml_out);
00147 }
00148 }
00149
00150
00151
00152 void
00153 InlineMeas::func(unsigned long update_no,
00154 XMLWriter& xml_out)
00155 {
00156 START_CODE();
00157
00158 StopWatch snoop;
00159 snoop.reset();
00160 snoop.start();
00161
00162
00163 multi1d<LatticeColorMatrix> u;
00164 XMLBufferWriter gauge_xml;
00165 try
00166 {
00167 u = TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
00168 TheNamedObjMap::Instance().get(params.named_obj.gauge_id).getRecordXML(gauge_xml);
00169 }
00170 catch( std::bad_cast )
00171 {
00172 QDPIO::cerr << name << ": caught dynamic cast error"
00173 << endl;
00174 QDP_abort(1);
00175 }
00176 catch (const string& e)
00177 {
00178 QDPIO::cerr << name << ": map call failed: " << e
00179 << endl;
00180 QDP_abort(1);
00181 }
00182
00183
00184 QDP::Seed ran_seed;
00185 QDP::RNG::savern(ran_seed);
00186
00187 push(xml_out, "make_source_stag");
00188 write(xml_out, "update_no", update_no);
00189
00190 QDPIO::cout << name << ": propagator source constructor" << endl;
00191
00192 proginfo(xml_out);
00193
00194
00195 write(xml_out, "RNG", ran_seed);
00196
00197
00198 params.writeXML(xml_out, "Input");
00199
00200
00201 write(xml_out, "Config_info", gauge_xml);
00202
00203
00204 MesPlq(xml_out, "Observables", u);
00205
00206
00207
00208
00209 LatticeStaggeredPropagator quark_source;
00210
00211 try
00212 {
00213 std::istringstream xml_s(params.param.source.xml);
00214 XMLReader sourcetop(xml_s);
00215 QDPIO::cout << "Source = " << params.param.source.id << endl;
00216
00217 Handle< QuarkSourceConstruction<LatticeStaggeredPropagator> >
00218 sourceConstruction(TheStagPropSourceConstructionFactory::Instance().createObject(params.param.source.id,
00219 sourcetop,
00220 params.param.source.path));
00221 quark_source = (*sourceConstruction)(u);
00222 }
00223 catch(const std::string& e)
00224 {
00225 QDPIO::cerr << name << ": Caught Exception creating source: " << e << endl;
00226 QDP_abort(1);
00227 }
00228
00229
00230
00231
00232 {
00233
00234 SftMom phases(0, true, Nd-1);
00235
00236 multi1d<Double> source_corr = sumMulti(localNorm2(quark_source),
00237 phases.getSet());
00238
00239 push(xml_out, "Source_correlator");
00240 write(xml_out, "source_corr", source_corr);
00241 pop(xml_out);
00242 }
00243
00244
00245
00246 try
00247 {
00248 QDPIO::cout << "Attempt to update source" << endl;
00249
00250 XMLBufferWriter file_xml;
00251 push(file_xml, "make_source");
00252 write(file_xml, "id", uniqueId());
00253 pop(file_xml);
00254
00255 XMLBufferWriter record_xml;
00256 push(record_xml, "MakeSource");
00257 write(record_xml, "PropSource", params.param);
00258 write(record_xml, "RNG", ran_seed);
00259 write(record_xml, "Config_info", gauge_xml);
00260 pop(record_xml);
00261
00262
00263 TheNamedObjMap::Instance().create<LatticeStaggeredPropagator>(params.named_obj.source_id);
00264 TheNamedObjMap::Instance().getData<LatticeStaggeredPropagator>(params.named_obj.source_id) = quark_source;
00265 TheNamedObjMap::Instance().get(params.named_obj.source_id).setFileXML(file_xml);
00266 TheNamedObjMap::Instance().get(params.named_obj.source_id).setRecordXML(record_xml);
00267
00268 QDPIO::cout << "Source successfully update" << endl;
00269 }
00270 catch (std::bad_cast)
00271 {
00272 QDPIO::cerr << name << ": dynamic cast error"
00273 << endl;
00274 QDP_abort(1);
00275 }
00276 catch (const string& e)
00277 {
00278 QDPIO::cerr << name << ": error message: " << e << endl;
00279 QDP_abort(1);
00280 }
00281
00282 pop(xml_out);
00283
00284
00285
00286
00287 snoop.stop();
00288 QDPIO::cout << name << ": total time = "
00289 << snoop.getTimeInSeconds()
00290 << " secs" << endl;
00291
00292 QDPIO::cout << name << ": ran successfully" << endl;
00293
00294 END_CODE();
00295 }
00296
00297 }
00298
00299 }