CHROMA
inline_nersc_read_obj.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Inline task to read an object from a named buffer
3  *
4  * Named object writing
5  */
6 
7 #include "chromabase.h"
8 #include "qdp_iogauge.h"
12 
13 namespace Chroma
14 {
15  namespace InlineNERSCReadNamedObjEnv
16  {
17  namespace
18  {
19  AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
20  const std::string& path)
21  {
22  return new InlineMeas(Params(xml_in, path));
23  }
24 
25  //! Local registration flag
26  bool registered = false;
27 
28  const std::string name = "NERSC_READ_NAMED_OBJECT";
29  }
30 
31  //! Register all the factories
32  bool registerAll()
33  {
34  bool success = true;
35  if (! registered)
36  {
37  success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
38  registered = true;
39  }
40  return success;
41  }
42 
43 
44  //! Object buffer
45  void write(XMLWriter& xml, const std::string& path, const Params::NamedObject_t& input)
46  {
47  push(xml, path);
48 
49  write(xml, "object_id", input.object_id);
50 
51  pop(xml);
52  }
53 
54  //! File output
55  void write(XMLWriter& xml, const std::string& path, const Params::File_t& input)
56  {
57  push(xml, path);
58 
59  write(xml, "file_name", input.file_name);
60 
61  pop(xml);
62  }
63 
64 
65  //! Object buffer
66  void read(XMLReader& xml, const std::string& path, Params::NamedObject_t& input)
67  {
68  XMLReader inputtop(xml, path);
69 
70  read(inputtop, "object_id", input.object_id);
71  }
72 
73  //! File output
74  void read(XMLReader& xml, const std::string& path, Params::File_t& input)
75  {
76  XMLReader inputtop(xml, path);
77 
78  read(inputtop, "file_name", input.file_name);
79  }
80 
81 
82  // Param stuff
84 
85  Params::Params(XMLReader& xml_in, const std::string& path)
86  {
87  try
88  {
89  XMLReader paramtop(xml_in, path);
90 
91  if (paramtop.count("Frequency") == 1)
92  read(paramtop, "Frequency", frequency);
93  else
94  frequency = 1;
95 
96  // Parameters for source construction
97  read(paramtop, "NamedObject", named_obj);
98 
99  // Read in the destination
100  read(paramtop, "File", file);
101  }
102  catch(const std::string& e)
103  {
104  QDPIO::cerr << __func__ << ": caught Exception reading XML: " << e << std::endl;
105  QDP_abort(1);
106  }
107  }
108 
109 
110  void
111  Params::writeXML(XMLWriter& xml_out, const std::string& path)
112  {
113  push(xml_out, path);
114 
115  // Parameters for source construction
116  write(xml_out, "NamedObject", named_obj);
117 
118  // Write out the destination
119  write(xml_out, "File", file);
120 
121  pop(xml_out);
122  }
123 
124 
125  void
126  InlineMeas::operator()(unsigned long update_no,
127  XMLWriter& xml_out)
128  {
129  START_CODE();
130 
131  push(xml_out, "nersc_read_named_obj");
132  write(xml_out, "update_no", update_no);
133 
134  QDPIO::cout << InlineNERSCReadNamedObjEnv::name << ": object reader" << std::endl;
135  StopWatch swatch;
136 
137  // Read the object
138  // ONLY SciDAC output format is supported in this task
139  // Other tasks could support other disk formats
140  QDPIO::cout << "Attempt to read object name = " << params.named_obj.object_id << std::endl;
141  write(xml_out, "object_id", params.named_obj.object_id);
142  try
143  {
144  swatch.reset();
145 
146  XMLReader record_xml;
147  multi1d<LatticeColorMatrix> u(Nd);
148 
149  // Read the object
150  swatch.start();
151  QDP::readArchiv(record_xml, u, params.file.file_name);
152  swatch.stop();
153 
154  XMLBufferWriter file_xml;
155  push(file_xml, "NERSC");
156  pop(file_xml);
157 
158  TheNamedObjMap::Instance().create< multi1d<LatticeColorMatrix> >(params.named_obj.object_id);
159  TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.object_id) = u;
160  TheNamedObjMap::Instance().get(params.named_obj.object_id).setFileXML(file_xml);
161  TheNamedObjMap::Instance().get(params.named_obj.object_id).setRecordXML(record_xml);
162 
163  QDPIO::cout << "Object successfully written: time= "
164  << swatch.getTimeInSeconds()
165  << " secs" << std::endl;
166  }
167  catch( std::bad_cast )
168  {
169  QDPIO::cerr << name << ": cast error"
170  << std::endl;
171  QDP_abort(1);
172  }
173  catch (const std::string& e)
174  {
175  QDPIO::cerr << name << ": error message: " << e
176  << std::endl;
177  QDP_abort(1);
178  }
179 
180  QDPIO::cout << name << ": ran successfully" << std::endl;
181 
182  pop(xml_out); // read_named_obj
183 
184  END_CODE();
185  }
186 
187  } // namespace InlineNERSCReadNamedObjEnv
188 
189 }
Inline measurement factory.
Primary include file for CHROMA library code.
void operator()(const unsigned long update_no, XMLWriter &xml_out)
Do the writing.
static T & Instance()
Definition: singleton.h:432
Inline task to read an object from a named buffer.
Nd
Definition: meslate.cc:74
Named object function std::map.
static bool registered
Local registration flag.
const std::string name
Name to be used.
bool registerAll()
Register all the factories.
void read(XMLReader &xml, const std::string &path, Params::NamedObject_t &input)
Object buffer.
void write(XMLWriter &xml, const std::string &path, const Params::NamedObject_t &input)
Object buffer.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
static multi1d< LatticeColorMatrix > u
push(xml_out,"Condensates")
pop(xml_out)
START_CODE()
::std::string string
Definition: gtest.h:1979
void writeXML(XMLWriter &xml_out, const std::string &path)
struct Chroma::InlineNERSCReadNamedObjEnv::Params::File_t file
struct Chroma::InlineNERSCReadNamedObjEnv::Params::NamedObject_t named_obj