00001
00002
00003
00004
00005
00006
00007
00008 #include "chromabase.h"
00009 #include "qdp_iogauge.h"
00010 #include "meas/inline/abs_inline_measurement_factory.h"
00011 #include "meas/inline/io/inline_eigen_bin_lime_colvec_read_obj.h"
00012 #include "meas/inline/io/named_objmap.h"
00013
00014 #include "util/ferm/subset_vectors.h"
00015
00016 namespace Chroma
00017 {
00018
00019
00020
00021 void write(XMLWriter& xml, const string& path, const InlineEigenBinLimeColVecReadNamedObjEnv::Params::NamedObject_t& input)
00022 {
00023 push(xml, path);
00024
00025 write(xml, "object_id", input.object_id);
00026
00027 pop(xml);
00028 }
00029
00030
00031 void write(XMLWriter& xml, const string& path, const InlineEigenBinLimeColVecReadNamedObjEnv::Params::File_t& input)
00032 {
00033 push(xml, path);
00034
00035 write(xml, "file_name", input.file_name);
00036
00037 pop(xml);
00038 }
00039
00040
00041
00042 void read(XMLReader& xml, const string& path, InlineEigenBinLimeColVecReadNamedObjEnv::Params::NamedObject_t& input)
00043 {
00044 XMLReader inputtop(xml, path);
00045
00046 read(inputtop, "object_id", input.object_id);
00047 }
00048
00049
00050 void read(XMLReader& xml, const string& path, InlineEigenBinLimeColVecReadNamedObjEnv::Params::File_t& input)
00051 {
00052 XMLReader inputtop(xml, path);
00053
00054 read(inputtop, "file_name", input.file_name);
00055 }
00056
00057
00058 namespace InlineEigenBinLimeColVecReadNamedObjEnv
00059 {
00060
00061
00062
00063 multi1d<int> coords(const int x, const int y, const int z, const int t)
00064 {
00065 multi1d<int> ret(4);
00066
00067 ret[0] = x;
00068 ret[1] = y;
00069 ret[2] = z;
00070 ret[3] = t;
00071
00072 return ret;
00073 }
00074
00075
00076 void unserialize(LatticeColorVector &cvec, const multi1d< Complex > &vec,
00077 const int& t)
00078 {
00079 int vsize = QDP::Layout::lattSize()[0] * QDP::Layout::lattSize()[0] * QDP::Layout::lattSize()[0] * Nc;
00080
00081 if (vec.size() != vsize)
00082 {
00083 cerr << "in unserialize: invalid size of serialized vector"
00084 << endl;
00085
00086 exit(0);
00087 }
00088
00089
00090 for (int x = 0 ; x < QDP::Layout::lattSize()[0] ; ++x)
00091 for (int y = 0 ; y < QDP::Layout::lattSize()[0] ; ++y)
00092 for (int z = 0 ; z < QDP::Layout::lattSize()[0] ; ++z)
00093 {
00094 ColorVector sitevec = zero;
00095
00096 for (int c = 0 ; c < Nc ; ++c)
00097 {
00098 Complex temp = vec[ c + Nc*(z + QDP::Layout::lattSize()[0]*(y + QDP::Layout::lattSize()[0]*x)) ];
00099
00100 pokeColor(sitevec, temp, c);
00101 }
00102
00103 pokeSite(cvec, sitevec, coords(x, y, z, t) );
00104 }
00105
00106 }
00107
00108
00109
00110
00111 namespace
00112 {
00113 AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
00114 const std::string& path)
00115 {
00116 return new InlineMeas(Params(xml_in, path));
00117 }
00118
00119
00120 bool registered = false;
00121 }
00122
00123 const std::string name = "EIGENINFO_BIN_LIME_COLORVEC_READ_NAMED_OBJECT";
00124
00125
00126 bool registerAll()
00127 {
00128 bool success = true;
00129 if (! registered)
00130 {
00131 success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
00132 registered = true;
00133 }
00134 return success;
00135 }
00136
00137 Params::Params() { frequency = 0; }
00138
00139 Params::Params(XMLReader& xml_in, const std::string& path)
00140 {
00141 try
00142 {
00143 XMLReader paramtop(xml_in, path);
00144
00145 if (paramtop.count("Frequency") == 1)
00146 read(paramtop, "Frequency", frequency);
00147 else
00148 frequency = 1;
00149
00150
00151 read(paramtop, "NamedObject", named_obj);
00152
00153
00154 read(paramtop, "File", file);
00155
00156 }
00157 catch(const std::string& e)
00158 {
00159 QDPIO::cerr << __func__ << ": caught Exception reading XML: " << e << endl;
00160 QDP_abort(1);
00161 }
00162 }
00163
00164
00165 void
00166 Params::writeXML(XMLWriter& xml_out, const std::string& path)
00167 {
00168 push(xml_out, path);
00169
00170
00171 write(xml_out, "NamedObject", named_obj);
00172
00173
00174 write(xml_out, "File", file);
00175
00176 pop(xml_out);
00177 }
00178
00179
00180 void
00181 InlineMeas::operator()(unsigned long update_no, XMLWriter& xml_out)
00182 {
00183 START_CODE();
00184
00185 push(xml_out, "eigeninfo_bin_lime_colorvec_read_named_obj");
00186 write(xml_out, "update_no", update_no);
00187
00188 QDPIO::cout << name << ": object reader" << endl;
00189 StopWatch swatch;
00190
00191
00192 QDPIO::cout << "Attempt to read object name = " << params.named_obj.object_id << endl;
00193 write(xml_out, "object_id", params.named_obj.object_id);
00194 try
00195 {
00196 swatch.reset();
00197
00198 typedef LatticeColorVector T;
00199
00200 TheNamedObjMap::Instance().create< SubsetVectors<T> >(params.named_obj.object_id);
00201 SubsetVectors<T>& eigen = TheNamedObjMap::Instance().getData< SubsetVectors<T> >(params.named_obj.object_id);
00202
00203
00204 int nt = QDP::Layout::lattSize()[Nd-1];
00205 int ns = QDP::Layout::lattSize()[0];
00206
00207 int ndim = ns * ns * ns * Nc;
00208
00209
00210 swatch.start();
00211
00212
00213
00214 XMLBufferWriter final_file_xml;
00215
00216 XMLBufferWriter final_record_xml;
00217 push(final_record_xml, "SubsetVectors");
00218 push(final_record_xml, "InfoArray");
00219
00220 XMLReader file_xml;
00221
00222 std::string filename = params.file.file_name;
00223 QDPFileReader rdr(file_xml, filename, QDPIO_SERIAL);
00224
00225
00226 write(final_file_xml, "Input", file_xml);
00227
00228
00229
00230 for (int t = 0 ; t < nt ; ++t)
00231 {
00232
00233 XMLReader curr_record_xml;
00234 BinaryBufferReader bin_rdr;
00235 read(rdr, curr_record_xml, bin_rdr);
00236
00237
00238
00239 multi1d<Real> evals;
00240
00241 if (curr_record_xml.count("/LaplaceEigInfo/EigenValues") != 0)
00242 read(curr_record_xml, "/LaplaceEigInfo/EigenValues", evals);
00243 else if (curr_record_xml.count("/LaplaceEigInfo/EigParams/EigenValues") != 0)
00244 read(curr_record_xml, "/LaplaceEigInfo/EigParams/EigenValues", evals);
00245 else
00246 {
00247 QDPIO::cerr << __func__ << ": LaplaceEigInfo tag for EigenValues not found\n" << std::endl;
00248 QDP_abort(1);
00249 }
00250
00251 int nev = evals.size();
00252
00253 if (t == 0)
00254 {
00255 eigen.getEvalues().resize(nev);
00256 eigen.getEvectors().resize(nev);
00257 eigen.getDecayDir() = Nd - 1;
00258
00259 for (int v = 0 ; v < nev ; ++v)
00260 {
00261 eigen.getEvectors()[v] = zero;
00262 eigen.getEvalues()[v].weights.resize(nt);
00263 }
00264 }
00265
00266 for (int n = 0 ; n < nev ; n++)
00267 {
00268
00269 eigen.getEvalues()[n].weights[t] = evals[n];
00270
00271 multi1d<Complex> temp;
00272 read(bin_rdr, temp);
00273
00274 if (temp.size() != ndim )
00275 {
00276 QDPIO::cerr << "Invalid array size" << endl;
00277 exit(1);
00278 }
00279
00280 unserialize(eigen.getEvectors()[n], temp, t);
00281 }
00282
00283 write(final_record_xml, "elem", curr_record_xml);
00284
00285 }
00286
00287 pop(final_record_xml);
00288 pop(final_record_xml);
00289
00290 swatch.stop();
00291
00292 TheNamedObjMap::Instance().get(params.named_obj.object_id).setFileXML(final_file_xml);
00293 TheNamedObjMap::Instance().get(params.named_obj.object_id).setRecordXML(final_record_xml);
00294
00295 QDPIO::cout << "Object successfully read: time= "
00296 << swatch.getTimeInSeconds()
00297 << " secs" << endl;
00298 }
00299 catch( std::bad_cast )
00300 {
00301 QDPIO::cerr << name << ": cast error" << endl;
00302 QDP_abort(1);
00303 }
00304 catch (const string& e)
00305 {
00306 QDPIO::cerr << name << ": error message: " << e << endl;
00307 QDP_abort(1);
00308 }
00309
00310 QDPIO::cout << name << ": ran successfully" << endl;
00311
00312 pop(xml_out);
00313
00314 END_CODE();
00315 }
00316
00317 }
00318 }