NAMD
InfoStream.C
Go to the documentation of this file.
1 
7 /*
8  Defines a new stream: iout, for "i"nforming consoles.
9 */
10 
11 #include "InfoStream.h"
12 #include "charm++.h"
13 #include "Vector.h"
14 #include "Tensor.h"
15 #include <stdio.h>
16 
17 CkpvExtern(infostream, iout_obj);
18 
19 std::ostream& infostream::access_iout_obj() {
20  return CkpvAccess(iout_obj);
21 }
22 
23 class CkPrintf_stringbuf : public std::stringbuf {
24 protected:
25  virtual int sync();
26 };
27 
29 
31  // rdbuf() returns a pointer to the new'ed CkPrintf_stringbuf object
32  // https://www.cplusplus.com/reference/ios/ios/rdbuf/
33  delete rdbuf();
34 }
35 
36 /* output using CkPrintf() (end by inform) */
38  // Even though str() returns a *copy* of the string, the RHS rules
39  // should avoid doing two copies for assignment to infostr.
40  //
41  // Note that str().c_str() should be avoided due to possibility for
42  // leaving a dangling pointer or undefined behavior at best, e.g.,
43  // https://stackoverflow.com/questions/21034834/is-there-issue-will-stringstream-str-c-str
44  // Copying into a named temporary is considered good practice.
45  std::string infostr = str();
46  CkPrintf("%s",infostr.c_str());
47 #ifndef NAMD_NO_STDOUT_FLUSH
48  fflush(stdout); // since CkPrintf doesn't always flush
49 #endif
50  str("");
51  return 0;
52 }
53 
54 std::ostream& endi(std::ostream& s) {
55  // flush() will cause overloaded sync() to be called
56  // https://www.cplusplus.com/reference/ostream/ostream/flush/
57  s.flush();
58  return s;
59 }
60 
61 std::ostream& iPE(std::ostream& s) {
62  return s << "Pe(" << CkMyPe() << ')';
63 }
64 
65 std::ostream& operator<<(std::ostream& strm, const Vector &v1) {
66  strm << v1.x << " " << v1.y << " " << v1.z;
67  return strm;
68 }
69 
70 std::ostream& operator<<(std::ostream& strm, const Tensor &t1) {
71  strm << t1.xx << " " << t1.xy << " " << t1.xz << " "
72  << t1.yx << " " << t1.yy << " " << t1.yz << " "
73  << t1.zx << " " << t1.zy << " " << t1.zz;
74  return strm;
75 }
76 
81 std::ostream& iINFO (std::ostream& s) { return s << "Info: "; }
82 std::ostream& iWARN (std::ostream& s) { return s << "Warning: "; }
83 std::ostream& iERROR(std::ostream& s) { return s << "ERROR: "; }
84 std::ostream& iDEBUG(std::ostream& s) { return s << "DEBUG: "; }
85 
86 
BigReal zy
Definition: Tensor.h:19
std::ostream & iINFO(std::ostream &s)
Definition: InfoStream.C:81
BigReal xz
Definition: Tensor.h:17
static std::ostream & access_iout_obj()
Definition: InfoStream.C:19
virtual int sync()
Definition: InfoStream.C:37
Definition: Vector.h:64
std::ostream & iPE(std::ostream &s)
Definition: InfoStream.C:61
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
BigReal z
Definition: Vector.h:66
BigReal yz
Definition: Tensor.h:18
std::ostream & iWARN(std::ostream &s)
Definition: InfoStream.C:82
CkpvExtern(infostream, iout_obj)
datastream & operator<<(datastream &strm, const Vector &v1)
Definition: DataStream.C:25
std::ostream & iDEBUG(std::ostream &s)
Definition: InfoStream.C:84
BigReal yx
Definition: Tensor.h:18
BigReal x
Definition: Vector.h:66
BigReal xx
Definition: Tensor.h:17
BigReal zz
Definition: Tensor.h:19
Definition: Tensor.h:15
BigReal xy
Definition: Tensor.h:17
BigReal y
Definition: Vector.h:66
BigReal yy
Definition: Tensor.h:18
std::ostream & iERROR(std::ostream &s)
Definition: InfoStream.C:83
BigReal zx
Definition: Tensor.h:19