CHROMA
inline_szin_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 InlineSZINWriteNamedObjEnv
15  {
16  namespace
17  {
18  AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
19  const std::string& path)
20  {
21  return new InlineMeas(Params(xml_in, path));
22  }
23 
24  //! Local registration flag
25  bool registered = false;
26 
27  const std::string name = "SZIN_WRITE_NAMED_OBJECT";
28  }
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  //! Object buffer
49  void write(XMLWriter& xml, const std::string& path, const Params::NamedObject_t& input)
50  {
51  push(xml, path);
52 
53  write(xml, "object_id", input.object_id);
54  write(xml, "object_type", input.object_type);
55 
56  pop(xml);
57  }
58 
59  //! File output
60  void write(XMLWriter& xml, const std::string& path, const Params::File_t& input)
61  {
62  push(xml, path);
63 
64  write(xml, "file_name", input.file_name);
65 
66  pop(xml);
67  }
68 
69 
70  //! Object buffer
71  void read(XMLReader& xml, const std::string& path, Params::NamedObject_t& input)
72  {
73  XMLReader inputtop(xml, path);
74 
75  read(inputtop, "object_id", input.object_id);
76  read(inputtop, "object_type", input.object_type);
77  }
78 
79  //! File output
80  void read(XMLReader& xml, const std::string& path, Params::File_t& input)
81  {
82  XMLReader inputtop(xml, path);
83 
84  read(inputtop, "file_name", input.file_name);
85 
86  /*
87  * Now information about whether to truncate the configuration
88  */
89  input.trunc = false;
90  input.j_decay = Nd-1;
91  input.t_start = 0;
92  input.t_end = QDP::Layout::lattSize()[input.j_decay]-1;
93 
94  if (inputtop.count("trunc") == 1)
95  {
96  read(inputtop, "trunc", input.trunc);
97  if (input.trunc)
98  {
99  read(inputtop, "t_start", input.t_start);
100  read(inputtop, "t_end", input.t_end);
101  read(inputtop, "j_decay", input.j_decay);
102  }
103  }
104  }
105 
106 
107  // Param stuff
109 
110  Params::Params(XMLReader& xml_in, const std::string& path)
111  {
112  try
113  {
114  XMLReader paramtop(xml_in, path);
115 
116  if (paramtop.count("Frequency") == 1)
117  read(paramtop, "Frequency", frequency);
118  else
119  frequency = 1;
120 
121  // Parameters for source construction
122  read(paramtop, "NamedObject", named_obj);
123 
124  // Read in the destination
125  read(paramtop, "File", file);
126  }
127  catch(const std::string& e)
128  {
129  QDPIO::cerr << __func__ << ": caught Exception reading XML: " << e << std::endl;
130  QDP_abort(1);
131  }
132  }
133 
134 
135  void
136  Params::writeXML(XMLWriter& xml_out, const std::string& path)
137  {
138  push(xml_out, path);
139 
140  // Parameters for source construction
141  write(xml_out, "NamedObject", named_obj);
142 
143  // Write out the destination
144  write(xml_out, "File", file);
145 
146  pop(xml_out);
147  }
148 
149 
150  void
151  InlineMeas::operator()(unsigned long update_no,
152  XMLWriter& xml_out)
153  {
154  START_CODE();
155 
156  push(xml_out, "szin_write_named_obj");
157  write(xml_out, "update_no", update_no);
158 
159  QDPIO::cout << name << ": object writer" << std::endl;
160  StopWatch swatch;
161 
162  // Write the object
163  // ONLY SZIN output format is supported in this task
164  // Other tasks could support other disk formats
165  QDPIO::cout << "Attempt to write object name = " << params.named_obj.object_id << std::endl;
166  write(xml_out, "object_id", params.named_obj.object_id);
167  try
168  {
169  swatch.reset();
170 
171  // Write the object
172  swatch.start();
178  params.file.t_end);
179  swatch.stop();
180 
181  QDPIO::cout << "Object successfully written: time= "
182  << swatch.getTimeInSeconds()
183  << " secs" << std::endl;
184  }
185  catch( std::bad_cast )
186  {
187  QDPIO::cerr << name << ": cast error"
188  << std::endl;
189  QDP_abort(1);
190  }
191  catch (const std::string& e)
192  {
193  QDPIO::cerr << name << ": error message: " << e
194  << std::endl;
195  QDP_abort(1);
196  }
197 
198  QDPIO::cout << name << ": ran successfully" << std::endl;
199 
200  pop(xml_out); // write_named_obj
201 
202  END_CODE();
203  }
204 
205  }
206 
207 }
Inline measurement factory.
void operator()(const unsigned long update_no, XMLWriter &xml_out)
Do the writing.
static T & Instance()
Definition: singleton.h:432
Inline task to write 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.
void write(XMLWriter &xml, const std::string &path, const Params::NamedObject_t &input)
Object buffer.
bool registerAll()
Register all the factories.
void read(XMLReader &xml, const std::string &path, Params::NamedObject_t &input)
Object buffer.
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::InlineSZINWriteNamedObjEnv::Params::File_t file
void writeXML(XMLWriter &xml_out, const std::string &path)
struct Chroma::InlineSZINWriteNamedObjEnv::Params::NamedObject_t named_obj
Write object function std::map.