CHROMA
inline_xml_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 
11 
12 namespace Chroma
13 {
14  namespace InlineXMLWriteNamedObjEnv
15  {
16  namespace
17  {
18  AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
19  const std::string& path)
20  {
21  return new InlineXMLWriteNamedObj(InlineXMLWriteNamedObjParams(xml_in, path));
22  }
23 
24  //! Local registration flag
25  bool registered = false;
26  }
27 
28  const std::string name = "XML_WRITE_NAMED_OBJECT";
29 
30  //! Register all the factories
31  bool registerAll()
32  {
33  bool success = true;
34  if (! registered)
35  {
36  // Datatype writer
38 
39  // Inline measurement
40  success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
41 
42  registered = true;
43  }
44  return success;
45  }
46  }
47 
48 
49  //! Object buffer
50  void write(XMLWriter& xml, const std::string& path, const InlineXMLWriteNamedObjParams::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 InlineXMLWriteNamedObjParams::File_t& input)
62  {
63  push(xml, path);
64 
65  write(xml, "file_name", input.file_name);
66 
67  pop(xml);
68  }
69 
70 
71  //! Object buffer
72  void read(XMLReader& xml, const std::string& path, InlineXMLWriteNamedObjParams::NamedObject_t& input)
73  {
74  XMLReader inputtop(xml, path);
75 
76  read(inputtop, "object_id", input.object_id);
77  read(inputtop, "object_type", input.object_type);
78  }
79 
80  //! File output
81  void read(XMLReader& xml, const std::string& path, InlineXMLWriteNamedObjParams::File_t& input)
82  {
83  XMLReader inputtop(xml, path);
84 
85  read(inputtop, "file_name", input.file_name);
86  }
87 
88 
89  // Param stuff
91 
93  {
94  try
95  {
96  XMLReader paramtop(xml_in, path);
97 
98  if (paramtop.count("Frequency") == 1)
99  read(paramtop, "Frequency", frequency);
100  else
101  frequency = 1;
102 
103  // Parameters for source construction
104  read(paramtop, "NamedObject", named_obj);
105 
106  // Read in the destination
107  read(paramtop, "File", file);
108  }
109  catch(const std::string& e)
110  {
111  QDPIO::cerr << __func__ << ": caught Exception reading XML: " << e << std::endl;
112  QDP_abort(1);
113  }
114  }
115 
116 
117  void
118  InlineXMLWriteNamedObjParams::write(XMLWriter& xml_out, const std::string& path)
119  {
120  push(xml_out, path);
121 
122  // Parameters for source construction
123  Chroma::write(xml_out, "NamedObject", named_obj);
124 
125  // Write out the destination
126  Chroma::write(xml_out, "File", file);
127 
128  pop(xml_out);
129  }
130 
131 
132  void
133  InlineXMLWriteNamedObj::operator()(unsigned long update_no,
134  XMLWriter& xml_out)
135  {
136  START_CODE();
137 
138  push(xml_out, "xml_write_named_obj");
139  write(xml_out, "update_no", update_no);
140 
141  QDPIO::cout << InlineXMLWriteNamedObjEnv::name << ": object writer" << std::endl;
142  StopWatch swatch;
143 
144  // Write the object
145  // ONLY XML output format is supported in this task
146  // Other tasks could support other formats
147  QDPIO::cout << "Attempt to write object name = " << params.named_obj.object_id << std::endl;
148  write(xml_out, "object_id", params.named_obj.object_id);
149  try
150  {
151  swatch.reset();
152 
153  // Write the object
154  swatch.start();
158  swatch.stop();
159 
160  QDPIO::cout << "Object successfully written: time= "
161  << swatch.getTimeInSeconds()
162  << " secs" << std::endl;
163  }
164  catch( std::bad_cast )
165  {
166  QDPIO::cerr << InlineXMLWriteNamedObjEnv::name << ": cast error"
167  << std::endl;
168  QDP_abort(1);
169  }
170  catch (const std::string& e)
171  {
172  QDPIO::cerr << InlineXMLWriteNamedObjEnv::name << ": error message: " << e
173  << std::endl;
174  QDP_abort(1);
175  }
176 
177  QDPIO::cout << InlineXMLWriteNamedObjEnv::name << ": ran successfully" << std::endl;
178 
179  pop(xml_out); // write_named_obj
180 
181  END_CODE();
182  }
183 
184 }
Inline measurement factory.
Inline writing of memory objects.
void operator()(const unsigned long update_no, XMLWriter &xml_out)
Do the writing.
InlineXMLWriteNamedObjParams params
static T & Instance()
Definition: singleton.h:432
void read(XMLReader &xml, const std::string &path, AsqtadFermActParams &param)
Read parameters.
void write(XMLWriter &xml, const std::string &path, const AsqtadFermActParams &param)
Writer parameters.
Inline task to write an object from a named buffer.
Named object function std::map.
static bool registered
Local registration flag.
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
struct Chroma::InlineXMLWriteNamedObjParams::NamedObject_t named_obj
struct Chroma::InlineXMLWriteNamedObjParams::File_t file
void write(XMLWriter &xml_out, const std::string &path)
Write object function std::map.