00001
00002
00003
00004
00005
00006
00007
00008 #include "handle.h"
00009 #include "meas/inline/hadron/inline_make_source_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 InlineMakeSourceEnv
00025 {
00026 namespace
00027 {
00028 AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
00029 const std::string& path)
00030 {
00031 return new InlineMakeSource(InlineMakeSourceParams(xml_in, path));
00032 }
00033
00034
00035 bool registered = false;
00036 }
00037
00038 const std::string name = "MAKE_SOURCE";
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, InlineMakeSourceParams::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 InlineMakeSourceParams::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 InlineMakeSourceParams::InlineMakeSourceParams() { frequency = 0; }
00078
00079 InlineMakeSourceParams::InlineMakeSourceParams(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 InlineMakeSourceParams::write(XMLWriter& xml_out, const std::string& path)
00113 {
00114 push(xml_out, path);
00115
00116
00117 Chroma::write(xml_out, "Param", param);
00118
00119
00120 Chroma::write(xml_out, "NamedObject", named_obj);
00121
00122 pop(xml_out);
00123 }
00124
00125
00126
00127 void
00128 InlineMakeSource::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");
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 InlineMakeSource::func(unsigned long update_no,
00154 XMLWriter& xml_out)
00155 {
00156 START_CODE();
00157
00158 QDPIO::cout << InlineMakeSourceEnv::name << ": propagator source constructor" << endl;
00159
00160 StopWatch snoop;
00161 snoop.reset();
00162 snoop.start();
00163
00164
00165 XMLBufferWriter gauge_xml;
00166 multi1d<LatticeColorMatrix> u;
00167 try
00168 {
00169 u = TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
00170 TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
00171 TheNamedObjMap::Instance().get(params.named_obj.gauge_id).getRecordXML(gauge_xml);
00172 }
00173 catch( std::bad_cast )
00174 {
00175 QDPIO::cerr << InlineMakeSourceEnv::name << ": caught dynamic cast error"
00176 << endl;
00177 QDP_abort(1);
00178 }
00179 catch (const string& e)
00180 {
00181 QDPIO::cerr << InlineMakeSourceEnv::name << ": error extracting gauge field: " << e
00182 << endl;
00183 QDP_abort(1);
00184 }
00185
00186
00187 QDP::Seed ran_seed;
00188 QDP::RNG::savern(ran_seed);
00189
00190 push(xml_out, "make_source");
00191 write(xml_out, "update_no", update_no);
00192
00193 proginfo(xml_out);
00194
00195
00196 write(xml_out, "RNG", ran_seed);
00197
00198
00199 params.write(xml_out, "Input");
00200
00201
00202 write(xml_out, "Config_info", gauge_xml);
00203
00204
00205 MesPlq(xml_out, "Observables", u);
00206
00207
00208
00209
00210 LatticePropagator quark_source;
00211
00212 try
00213 {
00214 std::istringstream xml_s(params.param.source.xml);
00215 XMLReader sourcetop(xml_s);
00216 QDPIO::cout << "Source = " << params.param.source.id << endl;
00217
00218 Handle< QuarkSourceConstruction<LatticePropagator> >
00219 sourceConstruction(ThePropSourceConstructionFactory::Instance().createObject(params.param.source.id,
00220 sourcetop,
00221 params.param.source.path));
00222 quark_source = (*sourceConstruction)(u);
00223 }
00224 catch(const std::string& e)
00225 {
00226 QDPIO::cerr << InlineMakeSourceEnv::name << ": Caught Exception creating source: " << e << endl;
00227 QDP_abort(1);
00228 }
00229
00230
00231
00232
00233 {
00234
00235 SftMom phases(0, true, Nd-1);
00236
00237 multi1d<Double> source_corr = sumMulti(localNorm2(quark_source),
00238 phases.getSet());
00239
00240 push(xml_out, "Source_correlator");
00241 write(xml_out, "source_corr", source_corr);
00242 pop(xml_out);
00243 }
00244
00245
00246
00247 try
00248 {
00249 QDPIO::cout << "Attempt to update source" << endl;
00250
00251 XMLBufferWriter file_xml;
00252 push(file_xml, "make_source");
00253 write(file_xml, "id", uniqueId());
00254 pop(file_xml);
00255
00256 XMLBufferWriter record_xml;
00257
00258
00259 {
00260 MakeSourceProp_t prop_header;
00261 prop_header.source_header = params.param;
00262 prop_header.gauge_header = gauge_xml.printCurrentContext();
00263 write(record_xml, "MakeSource", prop_header);
00264 }
00265
00266
00267 TheNamedObjMap::Instance().create<LatticePropagator>(params.named_obj.source_id);
00268 TheNamedObjMap::Instance().getData<LatticePropagator>(params.named_obj.source_id) = quark_source;
00269 TheNamedObjMap::Instance().get(params.named_obj.source_id).setFileXML(file_xml);
00270 TheNamedObjMap::Instance().get(params.named_obj.source_id).setRecordXML(record_xml);
00271
00272 QDPIO::cout << "Source successfully update" << endl;
00273 }
00274 catch (std::bad_cast)
00275 {
00276 QDPIO::cerr << InlineMakeSourceEnv::name << ": dynamic cast error"
00277 << endl;
00278 QDP_abort(1);
00279 }
00280 catch (const string& e)
00281 {
00282 QDPIO::cerr << InlineMakeSourceEnv::name << ": error message: " << e << endl;
00283 QDP_abort(1);
00284 }
00285
00286 pop(xml_out);
00287
00288
00289
00290
00291 snoop.stop();
00292 QDPIO::cout << InlineMakeSourceEnv::name << ": total time = "
00293 << snoop.getTimeInSeconds()
00294 << " secs" << endl;
00295
00296 QDPIO::cout << InlineMakeSourceEnv::name << ": ran successfully" << endl;
00297
00298 END_CODE();
00299 }
00300
00301 };