ARTS 2.5.9 (git: 825fa5f2)
messages.h
Go to the documentation of this file.
1/* Copyright (C) 2000-2012 Stefan Buehler <sbuehler@ltu.se>
2
3 This program is free software; you can redistribute it and/or modify it
4 under the terms of the GNU General Public License as published by the
5 Free Software Foundation; either version 2, or (at your option) any
6 later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 USA. */
17
39#ifndef messages_h
40#define messages_h
41
42#include <fstream>
43#include <iostream>
44
45#include "arts.h"
46#include "arts_omp.h"
47
48class Verbosity {
49 public:
50 Verbosity() : va(0), vs(0), vf(0), in_main_agenda(false) {}
51
52 Verbosity(Index vagenda, Index vscreen, Index vfile)
53 : va(vagenda), vs(vscreen), vf(vfile), in_main_agenda(false) {}
54
60 bool valid() const {
61 return (va >= 0 && va <= 3) && (vs >= 0 && vs <= 3) && (vf >= 0 && vf <= 3);
62 }
63
64 Index get_agenda_verbosity() const { return va; }
65 Index get_screen_verbosity() const { return vs; }
66 Index get_file_verbosity() const { return vf; }
67 bool is_main_agenda() const { return in_main_agenda; }
68
72 void set_main_agenda(bool main_agenda) { in_main_agenda = main_agenda; }
73
74 friend ostream& operator<<(ostream& os, const Verbosity& v);
75
76 private:
84};
85
86class ArtsOut {
87 public:
88 ArtsOut(const int p, const Verbosity& v) : verbosity(v), priority(p) {}
89
90 int get_priority() const { return priority; }
91 const Verbosity& get_verbosity() const { return verbosity; }
92
97 bool sufficient_priority() const {
100 }
101
108 }
109
116 }
117
124 }
125
130 bool in_main_agenda() const { return verbosity.is_main_agenda(); }
131
132 private:
135};
136
137class ArtsOut0 : public ArtsOut {
138 public:
139 ArtsOut0(const Verbosity& v) : ArtsOut(0, v) {}
140};
141
142class ArtsOut1 : public ArtsOut {
143 public:
144 ArtsOut1(const Verbosity& v) : ArtsOut(1, v) {}
145};
146
147class ArtsOut2 : public ArtsOut {
148 public:
149 ArtsOut2(const Verbosity& v) : ArtsOut(2, v) {}
150};
151
152class ArtsOut3 : public ArtsOut {
153 public:
154 ArtsOut3(const Verbosity& v) : ArtsOut(3, v) {}
155};
156
158template <class T>
159ArtsOut& operator<<(ArtsOut& aos, const T& t) {
160 extern ofstream report_file;
161
162 // cout << "Printing object of type: " << typeid(t).name() << "\n";
163
164 // If we are not in the main agenda, then the condition for agenda
165 // output must be fulfilled in addition to the condition for
166 // screen or file.
167
168 if (aos.sufficient_priority_agenda()) {
169 // We are marking the actual output operations as omp
170 // critical, to somewhat reduce the mess when several threads
171 // output simultaneously.
172
173 // This works well if the output operations themselves are
174 // atomic, that is if a string is prepared beforehand and then
175 // put to outx with a single << operation.
176
177 if (aos.sufficient_priority_screen()) {
178#pragma omp critical(ArtsOut_screen)
179 {
180 if (aos.get_priority() == 0)
181 cerr << t << flush;
182 else
183 cout << t << flush;
184 }
185 }
186
187 if (aos.sufficient_priority_file()) {
188#pragma omp critical(ArtsOut_file)
189 {
190 // if (report_file) // Check if report file is good
191 report_file << t << flush;
192 // The flush here is necessary to make the output really
193 // appear in the report file. We are not producing a huge
194 // amount of output to the report file, so I think the
195 // performance penalty here is acceptable.
196 }
197 }
198 }
199
200 return aos;
201}
202
203#define CREATE_OUT0 ArtsOut0 out0(verbosity)
204#define CREATE_OUT1 ArtsOut1 out1(verbosity)
205#define CREATE_OUT2 ArtsOut2 out2(verbosity)
206#define CREATE_OUT3 ArtsOut3 out3(verbosity)
207
208#define CREATE_OUTS \
209 ArtsOut0 out0(verbosity); \
210 ArtsOut1 out1(verbosity); \
211 ArtsOut2 out2(verbosity); \
212 ArtsOut3 out3(verbosity)
213
214#endif // messages_h
The global header file for ARTS.
Header file for helper functions for OpenMP.
ArtsOut0(const Verbosity &v)
Definition: messages.h:139
ArtsOut1(const Verbosity &v)
Definition: messages.h:144
ArtsOut2(const Verbosity &v)
Definition: messages.h:149
ArtsOut3(const Verbosity &v)
Definition: messages.h:154
ArtsOut(const int p, const Verbosity &v)
Definition: messages.h:88
const Verbosity & get_verbosity() const
Definition: messages.h:91
bool sufficient_priority_file() const
Does the current message have sufficient priority for file?
Definition: messages.h:122
int priority
Definition: messages.h:134
int get_priority() const
Definition: messages.h:90
bool sufficient_priority() const
Does the current message have sufficient priority for output?
Definition: messages.h:97
bool sufficient_priority_agenda() const
Does the current message have sufficient priority for agenda?
Definition: messages.h:106
bool sufficient_priority_screen() const
Does the current message have sufficient priority for screen?
Definition: messages.h:114
bool in_main_agenda() const
Are we in the main agenda?
Definition: messages.h:130
const Verbosity & verbosity
Definition: messages.h:133
Verbosity()
Definition: messages.h:50
Index get_screen_verbosity() const
Definition: messages.h:65
void set_main_agenda(bool main_agenda)
Definition: messages.h:72
Index vf
Verbosity for output to file.
Definition: messages.h:82
Verbosity(Index vagenda, Index vscreen, Index vfile)
Definition: messages.h:52
Index vs
Verbosity for output to screen.
Definition: messages.h:80
bool is_main_agenda() const
Definition: messages.h:67
Index get_agenda_verbosity() const
Definition: messages.h:64
void set_screen_verbosity(Index v)
Definition: messages.h:70
bool valid() const
Check if artsmessages contains valid message levels.
Definition: messages.h:60
Index va
Verbosity for agenda output.
Definition: messages.h:78
void set_agenda_verbosity(Index v)
Definition: messages.h:69
friend ostream & operator<<(ostream &os, const Verbosity &v)
Definition: messages.cc:47
Index get_file_verbosity() const
Definition: messages.h:66
void set_file_verbosity(Index v)
Definition: messages.h:71
bool in_main_agenda
Definition: messages.h:83
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
ofstream report_file
The report file.
Definition: messages.cc:45
ArtsOut & operator<<(ArtsOut &aos, const T &t)
Output operator for ArtsOut.
Definition: messages.h:159
#define v