CHROMA
inline_qio_write_obj.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Inline task to write an object from a named buffer
3  *
4  * Named object writing
5  */
6 
12 
13 namespace Chroma
14 {
15  namespace InlineQIOWriteNamedObjEnv
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 = "QIO_WRITE_NAMED_OBJECT";
29  }
30 
31  //! Register all the factories
32  bool registerAll()
33  {
34  bool success = true;
35  if (! registered)
36  {
37  // Datatype writer
39 
40  // Inline measurement
41  success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
42 
43  registered = true;
44  }
45  return success;
46  }
47 
48 
49  //! Object buffer
50  void write(XMLWriter& xml, const std::string& path, const Params::NamedObject_t& input)
51  {
52  push(xml, path);
53 
54  write(xml, "object_id", input.object_id);
55  write(xml, "object_type", input.object_type);
56 
57  pop(xml);
58  }
59 
60  //! File output
61  void write(XMLWriter& xml, const std::string& path, const Params::File_t& input)
62  {
63  push(xml, path);
64 
65  write(xml, "file_name", input.file_name);
66  write(xml, "file_volfmt", input.file_volfmt);
67  write(xml, "parallel_io", input.parallel_io);
68 
69  pop(xml);
70  }
71 
72 
73  //! Object buffer
74  void read(XMLReader& xml, const std::string& path, Params::NamedObject_t& input)
75  {
76  XMLReader inputtop(xml, path);
77 
78  read(inputtop, "object_id", input.object_id);
79  read(inputtop, "object_type", input.object_type);
80  }
81 
82  //! File output
83  void read(XMLReader& xml, const std::string& path, Params::File_t& input)
84  {
85  XMLReader inputtop(xml, path);
86 
87  read(inputtop, "file_name", input.file_name);
88  Chroma::read(inputtop, "file_volfmt", input.file_volfmt);
89  if (inputtop.count("parallel_io") > 0) {
90  read(inputtop, "parallel_io", input.parallel_io);
91  } else {
92  input.parallel_io = Layout::isIOGridDefined() && (Layout::numIONodeGrid() > 1);
93  }
94 
95  }
96 
97 
98  // Param stuff
100 
101  Params::Params(XMLReader& xml_in, const std::string& path)
102  {
103  try
104  {
105  XMLReader paramtop(xml_in, path);
106 
107  if (paramtop.count("Frequency") == 1)
108  read(paramtop, "Frequency", frequency);
109  else
110  frequency = 1;
111 
112  // Parameters for source construction
113  read(paramtop, "NamedObject", named_obj);
114 
115  // Read in the destination
116  read(paramtop, "File", file);
117  }
118  catch(const std::string& e)
119  {
120  QDPIO::cerr << __func__ << ": caught Exception reading XML: " << e << std::endl;
121  QDP_abort(1);
122  }
123  }
124 
125 
126  void
127  Params::writeXML(XMLWriter& xml_out, const std::string& path)
128  {
129  push(xml_out, path);
130 
131  // Parameters for source construction
132  write(xml_out, "NamedObject", named_obj);
133 
134  // Write out the destination
135  write(xml_out, "File", file);
136 
137  pop(xml_out);
138  }
139 
140 
141  void
142  InlineMeas::operator()(unsigned long update_no,
143  XMLWriter& xml_out)
144  {
145  START_CODE();
146 
147  push(xml_out, "qio_write_named_obj");
148  write(xml_out, "update_no", update_no);
149 
150  QDPIO::cout << name << ": object writer" << std::endl;
151  StopWatch swatch;
152 
153  // Write the object
154  // ONLY SciDAC output format is supported in this task
155  // Other tasks could support other disk formats
156  QDPIO::cout << "Attempt to write object name = " << params.named_obj.object_id << std::endl;
157  write(xml_out, "object_id", params.named_obj.object_id);
158  QDP_serialparallel_t parallel_io_type = QDPIO_SERIAL;
159  if ( params.file.parallel_io ) {
160  QDPIO::cout << "Attempting to write with Parallel IO" << std::endl;
161  parallel_io_type = QDPIO_PARALLEL;
162  }
163  else {
164  QDPIO::cout << "Attempting to write without parallel IO" << std::endl;
165  parallel_io_type = QDPIO_SERIAL;
166  }
167 
168  try
169  {
170  swatch.reset();
171 
172  // Write the object
173  swatch.start();
177  params.file.file_volfmt, parallel_io_type);
178  swatch.stop();
179 
180  QDPIO::cout << "Object successfully written: time= "
181  << swatch.getTimeInSeconds()
182  << " secs" << std::endl;
183  }
184  catch( std::bad_cast )
185  {
186  QDPIO::cerr << name << ": cast error"
187  << std::endl;
188  QDP_abort(1);
189  }
190  catch (const std::string& e)
191  {
192  QDPIO::cerr << name << ": error message: " << e
193  << std::endl;
194  QDP_abort(1);
195  }
196 
197  QDPIO::cout << name << ": ran successfully" << std::endl;
198 
199  pop(xml_out); // write_named_obj
200 
201  END_CODE();
202  }
203 
204  }
205 
206 }
Inline measurement factory.
void operator()(const unsigned long update_no, XMLWriter &xml_out)
Do the writing.
static T & Instance()
Definition: singleton.h:432
QDP volfmt enum.
void read(XMLReader &xml, const std::string &path, AsqtadFermActParams &param)
Read parameters.
Inline task to write an object from a named buffer.
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::NamedObject_t &input)
Object buffer.
void write(XMLWriter &xml, const std::string &path, const Params::NamedObject_t &input)
Object buffer.
bool registerAll()
Register all the factories.
bool registerAll()
Register all the factories.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
push(xml_out,"Condensates")
pop(xml_out)
START_CODE()
::std::string string
Definition: gtest.h:1979
Write object function std::map.
struct Chroma::InlineQIOWriteNamedObjEnv::Params::File_t file
void writeXML(XMLWriter &xml_out, const std::string &path)
struct Chroma::InlineQIOWriteNamedObjEnv::Params::NamedObject_t named_obj