CHROMA
inline_erase_obj.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Inline task to erase an object from a named buffer
3  *
4  * Named object writing
5  */
6 
10 
11 namespace Chroma
12 {
13  namespace InlineEraseNamedObjEnv
14  {
15  namespace
16  {
17  AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
18  const std::string& path)
19  {
20  return new InlineMeas(Params(xml_in, path));
21  }
22 
23  //! Local registration flag
24  bool registered = false;
25 
26  const std::string name = "ERASE_NAMED_OBJECT";
27  }
28 
29  //! Register all the factories
30  bool registerAll()
31  {
32  bool success = true;
33  if (! registered)
34  {
35  success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
36  registered = true;
37  }
38  return success;
39  }
40 
41 
42  //! Object buffer
43  void write(XMLWriter& xml, const std::string& path, const Params::NamedObject_t& input)
44  {
45  push(xml, path);
46 
47  write(xml, "object_id", input.object_id);
48 
49  pop(xml);
50  }
51 
52 
53  //! Object buffer
54  void read(XMLReader& xml, const std::string& path, Params::NamedObject_t& input)
55  {
56  XMLReader inputtop(xml, path);
57 
58  read(inputtop, "object_id", input.object_id);
59  }
60 
61 
62  // Param stuff
64 
65  Params::Params(XMLReader& xml_in, const std::string& path)
66  {
67  try
68  {
69  XMLReader paramtop(xml_in, path);
70 
71  if (paramtop.count("Frequency") == 1)
72  read(paramtop, "Frequency", frequency);
73  else
74  frequency = 1;
75 
76  // Ids
77  read(paramtop, "NamedObject", named_obj);
78  }
79  catch(const std::string& e)
80  {
81  QDPIO::cerr << __func__ << ": caught Exception reading XML: " << e << std::endl;
82  QDP_abort(1);
83  }
84  }
85 
86 
87  void
88  Params::writeXML(XMLWriter& xml_out, const std::string& path)
89  {
90  push(xml_out, path);
91 
92  // Ids
93  write(xml_out, "NamedObject", named_obj);
94 
95  pop(xml_out);
96  }
97 
98 
99  void
100  InlineMeas::operator()(unsigned long update_no,
101  XMLWriter& xml_out)
102  {
103  START_CODE();
104 
105  push(xml_out, "erase_named_obj");
106  write(xml_out, "update_no", update_no);
107 
108  QDPIO::cout << name << ": object erase" << std::endl;
109 
110  // Erase the object
111  QDPIO::cout << "Attempt to erase object name = " << params.named_obj.object_id << std::endl;
112  write(xml_out, "object_id", params.named_obj.object_id);
113  try
114  {
115  // Now erase the object
117 
118  QDPIO::cout << "Object erased" << std::endl;
119  }
120  catch( std::bad_cast )
121  {
122  QDPIO::cerr << name << ": cast error"
123  << std::endl;
124  QDP_abort(1);
125  }
126  catch (const std::string& e)
127  {
128  QDPIO::cerr << name << ": error message: " << e
129  << std::endl;
130  QDP_abort(1);
131  }
132 
133  QDPIO::cout << name << ": ran successfully" << std::endl;
134 
135  pop(xml_out); // erase_named_obj
136 
137  END_CODE();
138  }
139 
140  }
141 
142 }
Inline measurement factory.
Inline writing of memory objects.
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.
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
push(xml_out,"Condensates")
pop(xml_out)
START_CODE()
::std::string string
Definition: gtest.h:1979
struct Chroma::InlineEraseNamedObjEnv::Params::NamedObject_t named_obj
void writeXML(XMLWriter &xml_out, const std::string &path)