ARTS 2.5.11 (git: 6827797f)
messages.h
Go to the documentation of this file.
1
22#ifndef messages_h
23#define messages_h
24
25#include <fstream>
26#include <iostream>
27
28#include "arts.h"
29#include "arts_omp.h"
30
31class Verbosity {
32 public:
33 Verbosity() : va(0), vs(0), vf(0), in_main_agenda(false) {}
34
35 Verbosity(Index vagenda, Index vscreen, Index vfile)
36 : va(vagenda), vs(vscreen), vf(vfile), in_main_agenda(false) {}
37
43 bool valid() const {
44 return (va >= 0 && va <= 3) && (vs >= 0 && vs <= 3) && (vf >= 0 && vf <= 3);
45 }
46
47 Index get_agenda_verbosity() const { return va; }
48 Index get_screen_verbosity() const { return vs; }
49 Index get_file_verbosity() const { return vf; }
50 bool is_main_agenda() const { return in_main_agenda; }
51
52 void set_agenda_verbosity(Index v) { va = v; }
53 void set_screen_verbosity(Index v) { vs = v; }
54 void set_file_verbosity(Index v) { vf = v; }
55 void set_main_agenda(bool main_agenda) { in_main_agenda = main_agenda; }
56
57 friend ostream& operator<<(ostream& os, const Verbosity& v);
58
59 private:
61 Index va;
63 Index vs;
65 Index vf;
67};
68
69class ArtsOut {
70 public:
71 ArtsOut(const int p, const Verbosity& v) : verbosity(v), priority(p) {}
72
73 int get_priority() const { return priority; }
74 const Verbosity& get_verbosity() const { return verbosity; }
75
80 bool sufficient_priority() const {
83 }
84
91 }
92
99 }
100
107 }
108
113 bool in_main_agenda() const { return verbosity.is_main_agenda(); }
114
115 private:
118};
119
120class ArtsOut0 : public ArtsOut {
121 public:
122 ArtsOut0(const Verbosity& v) : ArtsOut(0, v) {}
123};
124
125class ArtsOut1 : public ArtsOut {
126 public:
127 ArtsOut1(const Verbosity& v) : ArtsOut(1, v) {}
128};
129
130class ArtsOut2 : public ArtsOut {
131 public:
132 ArtsOut2(const Verbosity& v) : ArtsOut(2, v) {}
133};
134
135class ArtsOut3 : public ArtsOut {
136 public:
137 ArtsOut3(const Verbosity& v) : ArtsOut(3, v) {}
138};
139
141template <class T>
142ArtsOut& operator<<(ArtsOut& aos, const T& t) {
143 extern ofstream report_file;
144
145 // cout << "Printing object of type: " << typeid(t).name() << "\n";
146
147 // If we are not in the main agenda, then the condition for agenda
148 // output must be fulfilled in addition to the condition for
149 // screen or file.
150
151 if (aos.sufficient_priority_agenda()) {
152 // We are marking the actual output operations as omp
153 // critical, to somewhat reduce the mess when several threads
154 // output simultaneously.
155
156 // This works well if the output operations themselves are
157 // atomic, that is if a string is prepared beforehand and then
158 // put to outx with a single << operation.
159
160 if (aos.sufficient_priority_screen()) {
161#pragma omp critical(ArtsOut_screen)
162 {
163 if (aos.get_priority() == 0)
164 cerr << t << flush;
165 else
166 cout << t << flush;
167 }
168 }
169
170 if (aos.sufficient_priority_file()) {
171#pragma omp critical(ArtsOut_file)
172 {
173 // if (report_file) // Check if report file is good
174 report_file << t << flush;
175 // The flush here is necessary to make the output really
176 // appear in the report file. We are not producing a huge
177 // amount of output to the report file, so I think the
178 // performance penalty here is acceptable.
179 }
180 }
181 }
182
183 return aos;
184}
185
186#define CREATE_OUT0 ArtsOut0 out0(verbosity)
187#define CREATE_OUT1 ArtsOut1 out1(verbosity)
188#define CREATE_OUT2 ArtsOut2 out2(verbosity)
189#define CREATE_OUT3 ArtsOut3 out3(verbosity)
190
191#define CREATE_OUTS \
192 ArtsOut0 out0(verbosity); \
193 ArtsOut1 out1(verbosity); \
194 ArtsOut2 out2(verbosity); \
195 ArtsOut3 out3(verbosity)
196
197#endif // messages_h
The global header file for ARTS.
Header file for helper functions for OpenMP.
ArtsOut0(const Verbosity &v)
Definition: messages.h:122
ArtsOut1(const Verbosity &v)
Definition: messages.h:127
ArtsOut2(const Verbosity &v)
Definition: messages.h:132
ArtsOut3(const Verbosity &v)
Definition: messages.h:137
ArtsOut(const int p, const Verbosity &v)
Definition: messages.h:71
const Verbosity & get_verbosity() const
Definition: messages.h:74
bool sufficient_priority_file() const
Does the current message have sufficient priority for file?
Definition: messages.h:105
int priority
Definition: messages.h:117
int get_priority() const
Definition: messages.h:73
bool sufficient_priority() const
Does the current message have sufficient priority for output?
Definition: messages.h:80
bool sufficient_priority_agenda() const
Does the current message have sufficient priority for agenda?
Definition: messages.h:89
bool sufficient_priority_screen() const
Does the current message have sufficient priority for screen?
Definition: messages.h:97
bool in_main_agenda() const
Are we in the main agenda?
Definition: messages.h:113
const Verbosity & verbosity
Definition: messages.h:116
Verbosity()
Definition: messages.h:33
Index get_screen_verbosity() const
Definition: messages.h:48
void set_main_agenda(bool main_agenda)
Definition: messages.h:55
Index vf
Verbosity for output to file.
Definition: messages.h:65
Verbosity(Index vagenda, Index vscreen, Index vfile)
Definition: messages.h:35
Index vs
Verbosity for output to screen.
Definition: messages.h:63
bool is_main_agenda() const
Definition: messages.h:50
Index get_agenda_verbosity() const
Definition: messages.h:47
void set_screen_verbosity(Index v)
Definition: messages.h:53
bool valid() const
Check if artsmessages contains valid message levels.
Definition: messages.h:43
Index va
Verbosity for agenda output.
Definition: messages.h:61
void set_agenda_verbosity(Index v)
Definition: messages.h:52
friend ostream & operator<<(ostream &os, const Verbosity &v)
Definition: messages.cc:30
Index get_file_verbosity() const
Definition: messages.h:49
void set_file_verbosity(Index v)
Definition: messages.h:54
bool in_main_agenda
Definition: messages.h:66
ofstream report_file
The report file.
Definition: messages.cc:28
ArtsOut & operator<<(ArtsOut &aos, const T &t)
Output operator for ArtsOut.
Definition: messages.h:142
#define v