ARTS 2.5.0 (git: 9ee3ac6c)
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 "array.h"
46#include "arts.h"
47#include "arts_omp.h"
48
49class Verbosity {
50 public:
51 Verbosity() : va(0), vs(0), vf(0), in_main_agenda(false) {}
52
53 Verbosity(Index vagenda, Index vscreen, Index vfile)
54 : va(vagenda), vs(vscreen), vf(vfile), in_main_agenda(false) {}
55
61 bool valid() const {
62 return (va >= 0 && va <= 3) && (vs >= 0 && vs <= 3) && (vf >= 0 && vf <= 3);
63 }
64
65 Index get_agenda_verbosity() const { return va; }
66 Index get_screen_verbosity() const { return vs; }
67 Index get_file_verbosity() const { return vf; }
68 bool is_main_agenda() const { return in_main_agenda; }
69
73 void set_main_agenda(bool main_agenda) { in_main_agenda = main_agenda; }
74
75 friend ostream& operator<<(ostream& os, const Verbosity& v);
76
77 private:
85};
86
87class ArtsOut {
88 public:
89 ArtsOut(const int p, const Verbosity& v) : verbosity(v), priority(p) {}
90
91 int get_priority() const { return priority; }
92 const Verbosity& get_verbosity() const { return verbosity; }
93
98 bool sufficient_priority() const {
101 }
102
109 }
110
117 }
118
125 }
126
131 bool in_main_agenda() const { return verbosity.is_main_agenda(); }
132
133 private:
136};
137
138class ArtsOut0 : public ArtsOut {
139 public:
140 ArtsOut0(const Verbosity& v) : ArtsOut(0, v) {}
141};
142
143class ArtsOut1 : public ArtsOut {
144 public:
145 ArtsOut1(const Verbosity& v) : ArtsOut(1, v) {}
146};
147
148class ArtsOut2 : public ArtsOut {
149 public:
150 ArtsOut2(const Verbosity& v) : ArtsOut(2, v) {}
151};
152
153class ArtsOut3 : public ArtsOut {
154 public:
155 ArtsOut3(const Verbosity& v) : ArtsOut(3, v) {}
156};
157
159template <class T>
160ArtsOut& operator<<(ArtsOut& aos, const T& t) {
161 extern ofstream report_file;
162
163 // cout << "Printing object of type: " << typeid(t).name() << "\n";
164
165 // If we are not in the main agenda, then the condition for agenda
166 // output must be fulfilled in addition to the condition for
167 // screen or file.
168
169 if (aos.sufficient_priority_agenda()) {
170 // We are marking the actual output operations as omp
171 // critical, to somewhat reduce the mess when several threads
172 // output simultaneously.
173
174 // This works well if the output operations themselves are
175 // atomic, that is if a string is prepared beforehand and then
176 // put to outx with a single << operation.
177
178 if (aos.sufficient_priority_screen()) {
179#pragma omp critical(ArtsOut_screen)
180 {
181 if (aos.get_priority() == 0)
182 cerr << t << flush;
183 else
184 cout << t << flush;
185 }
186 }
187
188 if (aos.sufficient_priority_file()) {
189#pragma omp critical(ArtsOut_file)
190 {
191 // if (report_file) // Check if report file is good
192 report_file << t << flush;
193 // The flush here is necessary to make the output really
194 // appear in the report file. We are not producing a huge
195 // amount of output to the report file, so I think the
196 // performance penalty here is acceptable.
197 }
198 }
199 }
200
201 return aos;
202}
203
204#define CREATE_OUT0 ArtsOut0 out0(verbosity)
205#define CREATE_OUT1 ArtsOut1 out1(verbosity)
206#define CREATE_OUT2 ArtsOut2 out2(verbosity)
207#define CREATE_OUT3 ArtsOut3 out3(verbosity)
208
209#define CREATE_OUTS \
210 ArtsOut0 out0(verbosity); \
211 ArtsOut1 out1(verbosity); \
212 ArtsOut2 out2(verbosity); \
213 ArtsOut3 out3(verbosity)
214
215#endif // messages_h
This file contains the definition of Array.
The global header file for ARTS.
Header file for helper functions for OpenMP.
ArtsOut0(const Verbosity &v)
Definition: messages.h:140
ArtsOut1(const Verbosity &v)
Definition: messages.h:145
ArtsOut2(const Verbosity &v)
Definition: messages.h:150
ArtsOut3(const Verbosity &v)
Definition: messages.h:155
ArtsOut(const int p, const Verbosity &v)
Definition: messages.h:89
const Verbosity & get_verbosity() const
Definition: messages.h:92
bool sufficient_priority_file() const
Does the current message have sufficient priority for file?
Definition: messages.h:123
int priority
Definition: messages.h:135
int get_priority() const
Definition: messages.h:91
bool sufficient_priority() const
Does the current message have sufficient priority for output?
Definition: messages.h:98
bool sufficient_priority_agenda() const
Does the current message have sufficient priority for agenda?
Definition: messages.h:107
bool sufficient_priority_screen() const
Does the current message have sufficient priority for screen?
Definition: messages.h:115
bool in_main_agenda() const
Are we in the main agenda?
Definition: messages.h:131
const Verbosity & verbosity
Definition: messages.h:134
Verbosity()
Definition: messages.h:51
Index get_screen_verbosity() const
Definition: messages.h:66
void set_main_agenda(bool main_agenda)
Definition: messages.h:73
Index vf
Verbosity for output to file.
Definition: messages.h:83
Verbosity(Index vagenda, Index vscreen, Index vfile)
Definition: messages.h:53
Index vs
Verbosity for output to screen.
Definition: messages.h:81
bool is_main_agenda() const
Definition: messages.h:68
Index get_agenda_verbosity() const
Definition: messages.h:65
void set_screen_verbosity(Index v)
Definition: messages.h:71
bool valid() const
Check if artsmessages contains valid message levels.
Definition: messages.h:61
Index va
Verbosity for agenda output.
Definition: messages.h:79
void set_agenda_verbosity(Index v)
Definition: messages.h:70
friend ostream & operator<<(ostream &os, const Verbosity &v)
Definition: messages.cc:47
Index get_file_verbosity() const
Definition: messages.h:67
void set_file_verbosity(Index v)
Definition: messages.h:72
bool in_main_agenda
Definition: messages.h:84
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:160
#define v