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