CHROMA
default_gauge_field.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Functions to set and get default gauge field
3  */
4 
5 #include "chromabase.h"
6 
9 
10 #include <stdio.h>
11 #include <typeinfo>
12 
13 namespace Chroma
14 {
15  namespace InlineDefaultGaugeField
16  {
17  //! Private namespace
18  /*! \ingroup inlineio */
19  namespace
20  {
21  bool initP = false;
22  const std::string private_id = "default_gauge_field";
23 // std::string private_id = "Supercalifragilisticexpialidocious";
24  }
25 
26 
27  //! Get the default gauge field named object id
28  /*! \ingroup inlineio */
30  {
31  return private_id;
32  }
33 
34 
35  //! Reset the default gauge field state
36  /*! \ingroup inlineio */
37  void reset()
38  {
39  START_CODE();
40 
41  // If initialized, then destroy and reset
42  if (initP)
43  {
44  // Only delete if the object is still present
45  if ( TheNamedObjMap::Instance().check(private_id) )
46  {
47  try
48  {
49  // Now erase the object
50  TheNamedObjMap::Instance().erase(private_id);
51  }
52  catch( std::bad_cast )
53  {
54  QDPIO::cerr << __func__ << ": cast error"
55  << std::endl;
56  QDP_abort(1);
57  }
58  catch (const std::string& e)
59  {
60  QDPIO::cerr << __func__ << ": error message: " << e
61  << std::endl;
62  QDP_abort(1);
63  }
64  }
65  }
66 
67  initP = false;
68 
69  END_CODE();
70  }
71 
72 
73 
74  //! Set the default gauge field
75  /*! \ingroup inlineio */
76  void set(const multi1d<LatticeColorMatrix>& u,
77  XMLBufferWriter& record_xml)
78  {
79  START_CODE();
80 
81  // This might be too restrictive - might prefer automatic resetting
82  if (initP)
83  {
84  QDPIO::cerr << __func__ << ": gauge field already initialized" << std::endl;
85  QDP_abort(1);
86  }
87 
88  // Generate a private file name suitable for a buffer name
89 // private_id = tmpnam(NULL);
90 
91  // Set the default gauge field
92  try
93  {
94  XMLBufferWriter file_xml;
95  push(file_xml, "gauge");
96  write(file_xml, "id", int(0));
97  pop(file_xml);
98 
99  // Save the gauge field in this private buffer
100  TheNamedObjMap::Instance().create< multi1d<LatticeColorMatrix> >(private_id);
101  TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(private_id) = u;
102  TheNamedObjMap::Instance().get(private_id).setFileXML(file_xml);
103  TheNamedObjMap::Instance().get(private_id).setRecordXML(record_xml);
104  }
105  catch (std::bad_cast)
106  {
107  QDPIO::cerr << __func__ << ": cast error"
108  << std::endl;
109  QDP_abort(1);
110  }
111  catch (const std::string& e)
112  {
113  QDPIO::cerr << __func__ << ": error message: " << e
114  << std::endl;
115  QDP_abort(1);
116  }
117 
118  initP = true;
119 
120  END_CODE();
121  }
122 
123 
124 
125  //! Get the default gauge field
126  /*! \ingroup inlineio */
127  void get(multi1d<LatticeColorMatrix>& u,
128  XMLBufferWriter& file_xml,
129  XMLBufferWriter& record_xml)
130  {
131  START_CODE();
132 
133  if (! initP)
134  {
135  QDPIO::cerr << __func__ << ": gauge field not initialized" << std::endl;
136  QDP_abort(1);
137  }
138 
139  // Extract the default gauge field from a named object
140  try
141  {
142  u = TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(private_id);
143  TheNamedObjMap::Instance().get(private_id).setFileXML(file_xml);
144  TheNamedObjMap::Instance().get(private_id).setRecordXML(record_xml);
145  }
146  catch (std::bad_cast)
147  {
148  QDPIO::cerr << __func__ << ": cast error"
149  << std::endl;
150  QDP_abort(1);
151  }
152  catch (const std::string& e)
153  {
154  QDPIO::cerr << __func__ << ": error message: " << e
155  << std::endl;
156  QDP_abort(1);
157  }
158 
159  END_CODE();
160  }
161 
162  }
163 
164 }
Primary include file for CHROMA library code.
static T & Instance()
Definition: singleton.h:432
Functions to set and get default gauge field.
void write(XMLWriter &xml, const std::string &path, const AsqtadFermActParams &param)
Writer parameters.
void reset()
Reset the default gauge field state.
void set(const multi1d< LatticeColorMatrix > &u, XMLBufferWriter &record_xml)
Set the default gauge field.
void get(multi1d< LatticeColorMatrix > &u, XMLBufferWriter &file_xml, XMLBufferWriter &record_xml)
Get the default gauge field.
std::string getId()
Get the default gauge field named object id.
Named object function std::map.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
static multi1d< LatticeColorMatrix > u
push(xml_out,"Condensates")
pop(xml_out)
START_CODE()
::std::string string
Definition: gtest.h:1979