QMCPACK
ProgressReportEngine.h
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2016 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
8 // Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
9 // Mark Dewing, markdewing@gmail.com, University of Illinois at Urbana-Champaign
10 //
11 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
12 //////////////////////////////////////////////////////////////////////////////////////
13 
14 
15 /** @file ProgressReportEngine.h
16  * @brief declaration of ProgressReportEngine
17  */
18 
19 #ifndef QMCPLUSPLUS_PROGRESSREPORTENGINE_H
20 #define QMCPLUSPLUS_PROGRESSREPORTENGINE_H
21 
23 #include "Message/Communicate.h"
24 #include "Utilities/Timer.h"
26 
27 namespace qmcplusplus
28 {
29 /**
30  *
31  * Final class and should not be derived.
32  */
34 {
35 public:
36  inline ReportEngine(const std::string& cname, const std::string& fname)
37  : ClassName(cname), FuncName(fname), LogBuffer(infoDebug)
38  {
39  if (DoOutput)
40  {
41  LogBuffer << " " << ClassName << "::" << FuncName << '\n';
42  LogBuffer.flush(); //always flush
43  }
44  }
45 
46  inline ~ReportEngine()
47  {
48  LogBuffer.flush();
49  }
50 
51  inline void flush()
52  {
53  if (DoOutput)
54  {
55  LogBuffer << '\n';
56  LogBuffer.flush();
57  }
58  }
59 
60  inline void warning(const std::string& msg) { LogBuffer << ("WARNING: " + msg + '\n'); }
61 
62  inline void error(const std::string& msg, bool fatal = false)
63  {
64  app_error() << ("ERROR: " + msg + '\n');
65  if (fatal)
66  APP_ABORT(ClassName + "::" + FuncName);
67  }
68 
69  void echo(xmlNodePtr cur, bool recursive = false);
70 
71  static void enableOutput() { DoOutput = true; }
72 
73 private:
74  /** class Name
75  */
76  std::string ClassName;
77  /** name of the current member function
78  */
79  std::string FuncName;
80  /** arguments
81  */
82  std::vector<std::string> ArgList;
83  /** stream for log message
84  */
86  //disable copy constructor
88 
89  static bool DoOutput;
90 };
91 
92 // templated version of operator<< for Inform objects
93 template<class T>
94 inline ReportEngine& operator<<(ReportEngine& o, const T& val)
95 {
96  app_debug() << val;
97  return o;
98 }
99 } // namespace qmcplusplus
100 #endif // QMCPLUSPLUS_MPIOBJECTBASE_H
void echo(xmlNodePtr cur, bool recursive=false)
Interface to output streams.
Definition: InfoStream.h:28
std::string FuncName
name of the current member function
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
Declaration of OutputManager class.
ReportEngine(const ReportEngine &a)
#define app_debug
Definition: OutputManager.h:75
InfoStream infoDebug
void warning(const std::string &msg)
std::ostream & app_error()
Definition: OutputManager.h:67
std::vector< std::string > ArgList
arguments
Timer class.
ReportEngine(const std::string &cname, const std::string &fname)
Declaration of OhmmsElementBase and define xml-related macros.
Final class and should not be derived.
InfoStream & LogBuffer
stream for log message
std::ostream & operator<<(std::ostream &out, const AntiSymTensor< T, D > &rhs)
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
Definition: AppAbort.h:27
void flush()
flush stream buffer
Definition: InfoStream.cpp:39
void error(const std::string &msg, bool fatal=false)
std::string ClassName
class Name