CHROMA
inline_szin_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 
11 
12 namespace Chroma
13 {
14  namespace InlineSZINReadNamedObjEnv
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_READ_NAMED_OBJECT";
28  }
29 
30  //! Register all the factories
31  bool registerAll()
32  {
33  bool success = true;
34  if (! registered)
35  {
36  // Datatype reader
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 read(XMLReader& xml, const std::string& path, Params::NamedObject_t& input)
50  {
51  XMLReader inputtop(xml, path);
52 
53  read(inputtop, "object_id", input.object_id);
54  read(inputtop, "object_type", input.object_type);
55  }
56 
57  //! File output
58  void read(XMLReader& xml, const std::string& path, Params::File_t& input)
59  {
60  XMLReader inputtop(xml, path);
61 
62  read(inputtop, "file_name", input.file_name);
63  }
64 
65 
66  // Param stuff
68 
69  Params::Params(XMLReader& xml_in, const std::string& path)
70  {
71  try
72  {
73  XMLReader paramtop(xml_in, path);
74 
75  if (paramtop.count("Frequency") == 1)
76  read(paramtop, "Frequency", frequency);
77  else
78  frequency = 1;
79 
80  // Parameters for source construction
81  read(paramtop, "NamedObject", named_obj);
82 
83  // Read in the destination
84  read(paramtop, "File", file);
85  }
86  catch(const std::string& e)
87  {
88  QDPIO::cerr << __func__ << ": caught Exception reading XML: " << e << std::endl;
89  QDP_abort(1);
90  }
91  }
92 
93 
94  void
95  InlineMeas::operator()(unsigned long update_no,
96  XMLWriter& xml_out)
97  {
98  START_CODE();
99 
100  push(xml_out, "szin_read_named_obj");
101  write(xml_out, "update_no", update_no);
102 
103  QDPIO::cout << name << ": object reader" << std::endl;
104  StopWatch swatch;
105 
106  // Read the object
107  // ONLY SZIN output format is supported in this task
108  // Other tasks could support other disk formats
109  QDPIO::cout << "Attempt to read object name = " << params.named_obj.object_id << std::endl;
110  QDPIO::cout << "Attempt to read file name = " << params.file.file_name << std::endl;
111  write(xml_out, "object_id", params.named_obj.object_id);
112  try
113  {
114  swatch.reset();
115 
116 // // Read the object
117 // TheSZINReadObjFuncMap::Instance().dump();
118 
119  // Read the object
120  swatch.start();
124  swatch.stop();
125 
126  QDPIO::cout << "SZIN Object successfully read: time= "
127  << swatch.getTimeInSeconds()
128  << " secs" << std::endl;
129  }
130  catch( std::bad_cast )
131  {
132  QDPIO::cerr << name << ": cast error"
133  << std::endl;
134  QDP_abort(1);
135  }
136  catch (const std::string& e)
137  {
138  QDPIO::cerr << name << ": error message: " << e
139  << std::endl;
140  QDP_abort(1);
141  }
142 
143  QDPIO::cout << name << ": ran successfully" << std::endl;
144 
145  pop(xml_out); // read_named_obj
146 
147  END_CODE();
148  }
149 
150  }
151 
152 }
Inline measurement factory.
void operator()(const unsigned long update_no, XMLWriter &xml_out)
Do the writing.
static T & Instance()
Definition: singleton.h:432
void write(XMLWriter &xml, const std::string &path, const AsqtadFermActParams &param)
Writer parameters.
Inline task to read 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.
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::InlineSZINReadNamedObjEnv::Params::File_t file
struct Chroma::InlineSZINReadNamedObjEnv::Params::NamedObject_t named_obj
Read object function std::map.