QMCPACK
RecordNamedProperty< T > Struct Template Reference

Vectorized record engine for scalar properties. More...

+ Inheritance diagram for RecordNamedProperty< T >:
+ Collaboration diagram for RecordNamedProperty< T >:

Public Member Functions

 RecordNamedProperty ()
 
 RecordNamedProperty (int n)
 
 RecordNamedProperty (const RecordNamedProperty< T > &a)
 
void clear ()
 
operator[] (int i) const
 
T & operator[] (int i)
 
std::vector< T >::iterator begin ()
 iterators to use std algorithms More...
 
std::vector< T >::iterator end ()
 
std::vector< T >::const_iterator begin () const
 
std::vector< T >::const_iterator end () const
 
int add (const std::string &aname)
 
int append (const std::string &aroot, int first, int last)
 add multiple items with the aroot More...
 
int size () const
 
void setValues (T v)
 
void resize (int n)
 
void reset (const char *fileroot, bool append=false) override
 implement virtual functions More...
 
void report (int iter) override
 
void finalize () override
 
bool put (xmlNodePtr cur) override
 
- Public Member Functions inherited from RecordProperty
 RecordProperty ()
 
virtual ~RecordProperty ()
 

Public Attributes

std::optional< std::ofstream > OutStream
 
std::vector< T > Values
 
std::vector< std::string > Names
 
- Public Attributes inherited from RecordProperty
int stride
 
std::string FileName
 

Detailed Description

template<class T>
struct RecordNamedProperty< T >

Vectorized record engine for scalar properties.

A series of values with the name is recorded as a table of multiple columns.

Definition at line 100 of file RecordProperty.h.

Constructor & Destructor Documentation

◆ RecordNamedProperty() [1/3]

RecordNamedProperty ( )
inline

Definition at line 106 of file RecordProperty.h.

107  {
108  Values.reserve(20);
109  Names.reserve(20);
110  }
std::vector< std::string > Names
std::vector< T > Values

◆ RecordNamedProperty() [2/3]

RecordNamedProperty ( int  n)
inlineexplicit

Definition at line 112 of file RecordProperty.h.

113  {
114  Values.resize(n, T());
115  Names.resize(n);
116  }
std::vector< std::string > Names
std::vector< T > Values

◆ RecordNamedProperty() [3/3]

RecordNamedProperty ( const RecordNamedProperty< T > &  a)
inline

Definition at line 118 of file RecordProperty.h.

118 : OutStream(), Values(a.Values), Names(a.Names) {}
std::optional< std::ofstream > OutStream
std::vector< std::string > Names
std::vector< T > Values

Member Function Documentation

◆ add()

◆ append()

int append ( const std::string &  aroot,
int  first,
int  last 
)
inline

add multiple items with the aroot

Parameters
arootroot
firstfirst index
lastlast index
Returns
the last valid index

Definition at line 156 of file RecordProperty.h.

Referenced by RecordNamedProperty< RealType >::reset().

157  {
158  for (int i = first; i < last; ++i)
159  {
160  std::ostringstream o;
161  o << aroot << i;
162  Names.push_back(o.str());
163  Values.push_back(T());
164  }
165  return Values.size();
166  }
std::vector< std::string > Names
std::vector< T > Values

◆ begin() [1/2]

◆ begin() [2/2]

std::vector<T>::const_iterator begin ( ) const
inline

Definition at line 132 of file RecordProperty.h.

132 { return Values.begin(); }
std::vector< T > Values

◆ clear()

void clear ( )
inline

Definition at line 120 of file RecordProperty.h.

Referenced by ParticleSet::initPropertyList(), EstimatorManagerBase::reset(), and EstimatorManagerNew::reset().

121  {
122  Names.clear();
123  Values.clear();
124  }
std::vector< std::string > Names
std::vector< T > Values

◆ end() [1/2]

std::vector<T>::iterator end ( )
inline

Definition at line 131 of file RecordProperty.h.

131 { return Values.end(); }
std::vector< T > Values

◆ end() [2/2]

std::vector<T>::const_iterator end ( ) const
inline

Definition at line 133 of file RecordProperty.h.

133 { return Values.end(); }
std::vector< T > Values

◆ finalize()

void finalize ( )
inlineoverridevirtual

Implements RecordProperty.

Definition at line 223 of file RecordProperty.h.

223 {}

◆ operator[]() [1/2]

T operator[] ( int  i) const
inline

Definition at line 126 of file RecordProperty.h.

126 { return Values[i]; }
std::vector< T > Values

◆ operator[]() [2/2]

T& operator[] ( int  i)
inline

Definition at line 127 of file RecordProperty.h.

127 { return Values[i]; }
std::vector< T > Values

◆ put()

bool put ( xmlNodePtr  cur)
overridevirtual

Implements RecordProperty.

Definition at line 228 of file RecordProperty.h.

229 {
230  xmlAttrPtr att = cur->properties;
231  while (att != NULL)
232  {
233  std::string aname((const char*)(att->name));
234  if (aname == "stride")
235  {
236  stride = atoi((const char*)(att->children->content));
237  }
238  att = att->next;
239  }
240  return true;
241 }

◆ report()

void report ( int  iter)
inlineoverridevirtual

Implements RecordProperty.

Definition at line 213 of file RecordProperty.h.

214  {
215  if (stride && iter % stride == 0)
216  {
217  for (int i = 0; i < Values.size(); i++)
218  (*OutStream) << std::setw(15) << Values[i];
219  (*OutStream) << std::endl;
220  }
221  }
std::optional< std::ofstream > OutStream
std::vector< T > Values

◆ reset()

void reset ( const char *  fileroot,
bool  append = false 
)
inlineoverridevirtual

implement virtual functions

Implements RecordProperty.

Definition at line 191 of file RecordProperty.h.

192  {
193  if (append)
194  {
195  OutStream = std::ofstream(fileroot, std::ios_base::app);
196  }
197  else
198  {
199  OutStream = std::ofstream(fileroot);
200  }
201  if (!append)
202  {
203  OutStream->setf(std::ios::left, std::ios::adjustfield);
204  *OutStream << "# ";
205  for (int i = 0; i < Names.size(); i++)
206  (*OutStream) << std::setw(15) << Names[i].c_str();
207  (*OutStream) << std::endl;
208  }
209  OutStream->setf(std::ios::scientific, std::ios::floatfield);
210  OutStream->setf(std::ios::right, std::ios::adjustfield);
211  }
int append(const std::string &aroot, int first, int last)
add multiple items with the aroot
std::optional< std::ofstream > OutStream
std::vector< std::string > Names

◆ resize()

void resize ( int  n)
inline

Definition at line 176 of file RecordProperty.h.

177  {
178  std::vector<T> a = Values;
179  std::vector<std::string> b = Names;
180  Values.resize(n, T());
181  for (int i = 0; i < a.size(); i++)
182  Values[i] = a[i];
183  //std::copy_n(a.begin(), a.size(), Values.begin());
184  Names.resize(n);
185  for (int i = 0; i < a.size(); i++)
186  Names[i] = b[i];
187  //std::copy_n(b.begin(), b.size(), Name.begin());
188  }
std::vector< std::string > Names
std::vector< T > Values

◆ setValues()

void setValues ( v)
inline

Definition at line 170 of file RecordProperty.h.

Referenced by EstimatorManagerBase::start(), and EstimatorManagerNew::startDriverRun().

171  {
172  for (int i = 0; i < Values.size(); i++)
173  Values[i] = v;
174  }
std::vector< T > Values

◆ size()

Member Data Documentation

◆ Names

◆ OutStream

std::optional<std::ofstream> OutStream

◆ Values


The documentation for this struct was generated from the following file: