CHROMA
inline_write_timeslice_map_obj_disk.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Inline task to time-sliced std::map object
3  */
4 
5 #include "chromabase.h"
6 #include "singleton.h"
7 #include "funcmap.h"
8 
9 #include "qdp_map_obj_disk.h"
10 #include "qdp_disk_map_slice.h"
11 
15 
16 #include "util/info/proginfo.h"
17 
21 
23 
24 namespace Chroma
25 {
26  namespace InlineWriteTimeSliceMapObjDiskEnv
27  {
28  namespace WriteMapObjCallEnv
29  {
30  struct DumbDisambiguator {};
31 
32  //! Write object function std::map
33  /*! \ingroup inlineio */
34  typedef SingletonHolder<
36  void,
38  TYPELIST_1(const Params&),
39  void (*)(const Params& named_obj),
42 
43 
44  namespace
45  {
46  static bool registered = false;
47 
48  void writeMapObjEVPairLCV(const Params& params)
49  {
50  // Input object
51  QDP::MapObject<int,EVPair<LatticeColorVector> >& input_obj =
53  std::vector<int> keys; input_obj.keys(keys);
54 
55  const int decay_dir = Nd-1;
56 
57  XMLBufferWriter file_xml;
58 
59  push(file_xml, "MODMetaData");
60  write(file_xml, "id", std::string("eigenVecsTimeSlice"));
61  write(file_xml, "lattSize", QDP::Layout::lattSize());
62  write(file_xml, "decay_dir", decay_dir);
63  write(file_xml, "num_vecs", keys.size());
64  proginfo(file_xml); // Print out basic program info
65  write(file_xml, "Weights", getEigenValues(input_obj, keys.size()));
66  pop(file_xml);
67 
68  // Create the entry
69  QDP::MapObjectDisk<KeyTimeSliceColorVec_t,TimeSliceIO<LatticeColorVector> > output_obj;
70 
71  output_obj.insertUserdata(file_xml.str());
72  output_obj.open(params.named_obj.output_file, std::ios_base::in | std::ios_base::out | std::ios_base::trunc);
73 
74  // Copy the key/value-s
75  int Lt = Layout::lattSize()[decay_dir];
76 
77  int start = params.param.start_t;
78  int end = params.param.end_t;
79  QDPIO::cout << "start_t = " << start << ", end_t = " << end << "\n";
80 
81  for(int i=0; i < keys.size(); i++)
82  {
83  // Get the value
84  EVPair<LatticeColorVector> tmpvec; input_obj.get(keys[i], tmpvec);
85 
86  // We know the keys are simple integers from 0 to N-1.
87  // Write with a time-slice key.
88  for(int t=0; t < Lt; t++)
89  {
90  if ( ( ( start < end ) && ( t >= start && t < end ) ) ||
91  ( ( end < start ) && ( t >= start || t < end ) ) )
92  {
93  KeyTimeSliceColorVec_t time_key;
94  time_key.t_slice = t;
95  time_key.colorvec = keys[i];
96 
97  output_obj.insert(time_key, TimeSliceIO<LatticeColorVector>(tmpvec.eigenVector,t));
98  }
99  }
100  }
101 
102  output_obj.flush();
103  }
104 
105 
106  template<typename V>
107  void writeMapObjArrayLatColMat(const Params& params)
108  {
109  // Input object
110  XMLBufferWriter gauge_xml;
111 
112  // Make a copy because the TimeSliceIO critter wants a modifiable reference
113  multi1d<V> u = TheNamedObjMap::Instance().getData< multi1d<V> >(params.named_obj.input_id);
114  TheNamedObjMap::Instance().get(params.named_obj.input_id).getRecordXML(gauge_xml);
115 
116  const int decay_dir = Nd-1;
117 
118  XMLBufferWriter file_xml;
119 
120  push(file_xml, "MODMetaData");
121  write(file_xml, "id", std::string("gaugeFieldTimeSlice"));
122  write(file_xml, "lattSize", QDP::Layout::lattSize());
123  write(file_xml, "decay_dir", decay_dir);
124  proginfo(file_xml); // Print out basic program info
125  write(file_xml, "Config_info", gauge_xml);
126  pop(file_xml);
127 
128  // Create the entry
129  QDP::MapObjectDisk<KeyTimeSliceGauge_t,TimeSliceIO<V> > output_obj;
130 
131  output_obj.insertUserdata(file_xml.str());
132  output_obj.open(params.named_obj.output_file, std::ios_base::in | std::ios_base::out | std::ios_base::trunc);
133 
134  // Copy the key/value-s
135  int Lt = Layout::lattSize()[decay_dir];
136 
137  for(int mu=0; mu < u.size(); mu++)
138  {
139  // Write with a time-slice key.
140  for(int t=0; t < Lt; t++)
141  {
142  KeyTimeSliceGauge_t time_key;
143  time_key.t_slice = t;
144  time_key.dir = mu;
145 
146  output_obj.insert(time_key, TimeSliceIO<V>(u[mu],t));
147  }
148  }
149 
150  output_obj.flush();
151  }
152 
153 
154 
155  template<typename V>
156  void writeMapObjKeyIntValLat(const Params& params)
157  {
158  // Input object
159  XMLBufferWriter gauge_xml;
160 
161  // Make a copy because the TimeSliceIO critter wants a modifiable reference
162  V u = TheNamedObjMap::Instance().getData<V>(params.named_obj.input_id);
163  TheNamedObjMap::Instance().get(params.named_obj.input_id).getRecordXML(gauge_xml);
164 
165  const int decay_dir = Nd-1;
166 
167  XMLBufferWriter file_xml;
168 
169  push(file_xml, "MODMetaData");
170  write(file_xml, "id", std::string("gaugeFieldTimeSlice"));
171  write(file_xml, "lattSize", QDP::Layout::lattSize());
172  write(file_xml, "decay_dir", decay_dir);
173  proginfo(file_xml); // Print out basic program info
174  write(file_xml, "Config_info", gauge_xml);
175  pop(file_xml);
176 
177  // Create the entry
178  QDP::MapObjectDisk<int,TimeSliceIO<V> > output_obj;
179 
180  output_obj.insertUserdata(file_xml.str());
181 
182  // Open file. Note, a trunc is used. Doesn't have to be here, but if only time-slices are written as the key,
183  // there isn't any other way to disambiguate the keys. So, not much use in allowing multiple writes to the
184  // file
185  output_obj.open(params.named_obj.output_file, std::ios_base::in | std::ios_base::out | std::ios_base::trunc);
186 
187  // Copy the key/value-s
188  int Lt = Layout::lattSize()[decay_dir];
189 
190  // Write with a time-slice key.
191  for(int t=0; t < Lt; t++)
192  {
193  output_obj.insert(t, TimeSliceIO<V>(u,t));
194  }
195 
196  output_obj.flush();
197  }
198 
199 
200  bool registerAll(void)
201  {
202  bool success = true;
203  if (! registered )
204  {
205  success &= TheWriteMapObjFuncMap::Instance().registerFunction("KeyTintValTLatticeColorVector",
206  writeMapObjEVPairLCV);
207  success &= TheWriteMapObjFuncMap::Instance().registerFunction("ArrayLatticeColorMatrix",
208  writeMapObjArrayLatColMat<LatticeColorMatrix>);
209  success &= TheWriteMapObjFuncMap::Instance().registerFunction("ArrayLatticeColorMatrixF",
210  writeMapObjArrayLatColMat<LatticeColorMatrixF>);
211  success &= TheWriteMapObjFuncMap::Instance().registerFunction("ArrayLatticeColorMatrixD",
212  writeMapObjArrayLatColMat<LatticeColorMatrixD>);
213  success &= TheWriteMapObjFuncMap::Instance().registerFunction("KeyIntValLatticePropagator",
214  writeMapObjKeyIntValLat<LatticePropagator>);
215  success &= TheWriteMapObjFuncMap::Instance().registerFunction("KeyIntValLatticePropagatorF",
216  writeMapObjKeyIntValLat<LatticePropagatorF>);
217  success &= TheWriteMapObjFuncMap::Instance().registerFunction("KeyIntValLatticePropagatorD",
218  writeMapObjKeyIntValLat<LatticePropagatorD>);
219  success &= TheWriteMapObjFuncMap::Instance().registerFunction("KeyIntValLatticeFermion",
220  writeMapObjKeyIntValLat<LatticeFermion>);
221  success &= TheWriteMapObjFuncMap::Instance().registerFunction("KeyIntValLatticeFermionF",
222  writeMapObjKeyIntValLat<LatticeFermionF>);
223  success &= TheWriteMapObjFuncMap::Instance().registerFunction("KeyIntValLatticeFermionD",
224  writeMapObjKeyIntValLat<LatticeFermionD>);
225  success &= TheWriteMapObjFuncMap::Instance().registerFunction("KeyIntValLatticeColorMatrix",
226  writeMapObjKeyIntValLat<LatticeColorMatrix>);
227  success &= TheWriteMapObjFuncMap::Instance().registerFunction("KeyIntValLatticeColorMatrixF",
228  writeMapObjKeyIntValLat<LatticeColorMatrixF>);
229  success &= TheWriteMapObjFuncMap::Instance().registerFunction("KeyIntValLatticeColorMatrixD",
230  writeMapObjKeyIntValLat<LatticeColorMatrixD>);
231  success &= TheWriteMapObjFuncMap::Instance().registerFunction("KeyIntValLatticeColorVector",
232  writeMapObjKeyIntValLat<LatticeColorVector>);
233  success &= TheWriteMapObjFuncMap::Instance().registerFunction("KeyIntValLatticeColorVectorF",
234  writeMapObjKeyIntValLat<LatticeColorVectorF>);
235  success &= TheWriteMapObjFuncMap::Instance().registerFunction("KeyIntValLatticeColorVectorD",
236  writeMapObjKeyIntValLat<LatticeColorVectorD>);
237 
238  registered = true;
239  }
240  return success;
241  }
242  }
243  }
244 
245 
246  namespace
247  {
248  AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
249  const std::string& path)
250  {
251  return new InlineMeas(Params(xml_in, path));
252  }
253 
254  //! Local registration flag
255  bool registered = false;
256 
257  const std::string name = "WRITE_TIMESLICE_MAP_OBJECT_DISK";
258  }
259 
260  //! Register all the factories
261  bool registerAll()
262  {
263  bool success = true;
264  if (! registered)
265  {
266  success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
267  success &= WriteMapObjCallEnv::registerAll();
268  registered = true;
269  }
270  return success;
271  }
272 
273 
274  void read(XMLReader& xml, const std::string& path, Params::Param_t& input)
275  {
276  XMLReader inputtop(xml, path);
277 
278  read(inputtop, "start_t", input.start_t);
279  read(inputtop, "end_t", input.end_t);
280  }
281 
282 
283  //! Object buffer
284  void read(XMLReader& xml, const std::string& path, Params::NamedObject_t& input)
285  {
286  XMLReader inputtop(xml, path);
287 
288  read(inputtop, "object_type", input.object_type);
289  read(inputtop, "input_id", input.input_id);
290  read(inputtop, "output_file", input.output_file);
291  }
292 
293  // Param stuff
295 
296  Params::Params(XMLReader& xml_in, const std::string& path)
297  {
298  try
299  {
300  XMLReader paramtop(xml_in, path);
301 
302  if (paramtop.count("Frequency") == 1)
303  read(paramtop, "Frequency", frequency);
304  else
305  frequency = 1;
306 
307  // Parameters for source construction
308  read(paramtop, "NamedObject", named_obj);
309 
310  if (paramtop.count("Param") == 1)
311  read(paramtop, "Param", param);
312  else
313  {
314  param.start_t = 0;
315  param.end_t = Layout::lattSize()[Nd-1];
316  }
317  }
318  catch(const std::string& e)
319  {
320  QDPIO::cerr << __func__ << ": caught Exception reading XML: " << e << std::endl;
321  QDP_abort(1);
322  }
323  }
324 
325 
326  void
327  InlineMeas::operator()(unsigned long update_no, XMLWriter& xml_out)
328  {
329  START_CODE();
330 
331  registerAll();
332 
333  push(xml_out, "write_timeslice_map_object_disk");
334  write(xml_out, "update_no", update_no);
335 
336  QDPIO::cout << name << ": std::map object write to a time-slice format" << std::endl;
337  StopWatch swatch;
338 
339  // Write the object
340  QDPIO::cout << "Attempt to time-slice write the input object name = " << params.named_obj.input_id << std::endl;
341 
342  write(xml_out, "object_type", params.named_obj.object_type);
343  write(xml_out, "input_id", params.named_obj.input_id);
344  write(xml_out, "output_file", params.named_obj.output_file);
345 
346  try
347  {
348  swatch.reset();
349  swatch.start();
350 
351  // Write the object
353 
354  swatch.stop();
355 
356  QDPIO::cout << "Object successfully copied: time= "
357  << swatch.getTimeInSeconds()
358  << " secs" << std::endl;
359  }
360  catch( std::bad_cast )
361  {
362  QDPIO::cerr << name
363  << ": cast error for input_id= " << params.named_obj.input_id
364  << " with type= " << params.named_obj.object_type
365  << std::endl;
366  QDP_abort(1);
367  }
368  catch (const std::string& e)
369  {
370  QDPIO::cerr << name << ": error message: " << e << std::endl;
371  QDP_abort(1);
372  }
373  catch(const char* e)
374  {
375  QDPIO::cout << name << ": Caught const char * exception: " << e << std::endl;
376  QDP_abort(1);
377  }
378 
379  QDPIO::cout << name << ": ran successfully" << std::endl;
380 
381  pop(xml_out); // read_named_obj
382 
383  END_CODE();
384  }
385 
386  }
387 }
Inline measurement factory.
Primary include file for CHROMA library code.
Object factory class.
Definition: funcmap.h:89
Class for counted reference semantics.
Definition: handle.h:33
void operator()(const unsigned long update_no, XMLWriter &xml_out)
Do the writing.
static T & Instance()
Definition: singleton.h:432
int mu
Definition: cool.cc:24
Map of function calls.
void write(XMLWriter &xml, const std::string &path, const AsqtadFermActParams &param)
Writer parameters.
void proginfo(XMLWriter &xml)
Print out basic information about this program.
Definition: proginfo.cc:24
Params params
Inline task to time-sliced std::map object.
Key for time-sliced color eigenvectors.
Key for time-sliced gauge fields.
int t
Definition: meslate.cc:37
Nd
Definition: meslate.cc:74
Named object function std::map.
static bool registered
Local registration flag.
const std::string name
Name to be used.
void read(XMLReader &xml, const std::string &path, Params::Param_t &input)
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
static multi1d< LatticeColorMatrix > u
push(xml_out,"Condensates")
int i
Definition: pbg5p_w.cc:55
multi1d< SubsetVectorWeight_t > getEigenValues(const MapObject< int, EVPair< LatticeColorVector > > &eigen_source, int num_vecs)
pop(xml_out)
static QDP_ColorVector * out
Constructor.
START_CODE()
static QDP_ColorVector * in
::std::string string
Definition: gtest.h:1979
Print out basic info about this program.
Singleton support.
A Pair type.
Holds of vectors and eigenvalues.
Holds of vectors and weights.
#define TYPELIST_1(T1)
Definition: typelist.h:41