TBTK
Streams

Customizable Streams

It is often useful to print information to the screen during execution. Both for the sake of providing information about the progress of a calculation and for debuging code during development. It is perfectly possible to use the standard C style printf() or C++ style cout streams for these purposes. However, TBTK provides its own Stream interface that allows for customization of the output such as easy redirection of output to a logfile, etc. Moreover, all TBTK functions use the Stream interface, and it is therefore useful to know how to handle these Streams in order to for example mute TBTK.

Streams::out, Streams::log, and Streams::err

The Stream interface has three different output channels called Streams::out, Streams::log, and Streams::err. The Streams::out and Streams::err channels are by default equivalent to cout and cerr and is meant for standard out put and error output, respectively. In addition, the two buffers are forked to the Streams::log buffer which by default does nothing. However, it is possible to make Streams::log write to an output file by typing

Streams::openLog("Logfile");

To ensure that all information is written to file at the end of a calculation, a corresponding close call should be made at the end of the program

Streams::closeLog();

It is further possible to turn of the output that is directed to cout as follows

Streams::setStdMuteOut();

while the output to cerr is muted by

Streams::setStdMuteErr();

We note that if a log is opened, muting any of these two channels will not turn of the output written to the logfile. It is therefore possible to mute any output that otherwise would have gone to the screen and only redirect it to a file. However, it is recommended to not mute the error stream, since cerr is designed to not be buffered, while the other streams are. This means that information written to cerr before a crash will be guaranteed to reach the screen, while information written to the other streams do not provide this guarantee.

Communicators

Although not part of the actual Stream interface, many classes implements a so called Communicator interface. It is useful to know, that in addition to muting the Streams themselves it is possible to globally mute all Communicators by typing

Communicator::setGlobalVerbose(false);

or individual objects implementing the Communicator interface using

communicator.setVerbose(false);