ARTS  2.0.49
messages.h
Go to the documentation of this file.
1 /* Copyright (C) 2000-2008 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 <iostream>
43 #include <fstream>
44 
45 #include "arts.h"
46 #include "array.h"
47 #include "arts_omp.h"
48 
49 
50 class Verbosity {
51 public:
52  Verbosity() : va(0), vs(1), vf(1), in_main_agenda(false) {}
53 
54  Verbosity(Index vagenda, Index vscreen, Index vfile)
55  : va(vagenda), vs(vscreen), vf(vfile), in_main_agenda(false) {}
56 
61  bool valid() const
62  { return (va>=0 && va<=3) && (vs>=0 && vs<=3) && (vf>=0 || vf<=3); }
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 
69  void set_agenda_verbosity(Index v) { va = v; }
70  void set_screen_verbosity(Index v) { vs = v; }
71  void set_file_verbosity(Index v) { vf = v; }
72  void set_main_agenda(bool main_agenda) { in_main_agenda = main_agenda; }
73 
74  friend ostream& operator<<(ostream& os, const Verbosity& v);
75 private:
83 };
84 
85 
86 class ArtsOut {
87 public:
88  ArtsOut (const int p, const Verbosity& v)
89  : verbosity(v), priority(p) { }
90 
91  int get_priority () const { return priority; }
92  const Verbosity& get_verbosity () const { return verbosity; }
93 
95 
100  {
102  }
103 
105 
110  {
112  }
113 
115 
120  {
122  }
123 
124  bool in_main_agenda() const
125  {
126  return verbosity.is_main_agenda();
127  }
128 
129 private:
131  int priority;
132 };
133 
134 class ArtsOut0 : public ArtsOut {
135 public:
136  ArtsOut0 (const Verbosity& v) : ArtsOut(0, v) { }
137 };
138 
139 class ArtsOut1 : public ArtsOut {
140 public:
141  ArtsOut1 (const Verbosity& v) : ArtsOut(1, v) { }
142 };
143 
144 class ArtsOut2 : public ArtsOut {
145 public:
146  ArtsOut2 (const Verbosity& v) : ArtsOut(2, v) { }
147 };
148 
149 class ArtsOut3 : public ArtsOut {
150 public:
151  ArtsOut3 (const Verbosity& v) : ArtsOut(3, v) { }
152 };
153 
154 
156 template<class T>
157 ArtsOut& operator<<(ArtsOut& aos, const T& t)
158 {
159  extern ofstream report_file;
160 
161  // cout << "Printing object of type: " << typeid(t).name() << "\n";
162 
163  // If we are not in the main agenda, then the condition for agenda
164  // output must be fulfilled in addition to the condition for
165  // screen or file.
166 
167  if (aos.in_main_agenda() || aos.sufficient_priority_agenda())
168  {
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  {
179 #pragma omp critical
180  {
181  if (aos.get_priority() == 0)
182  cerr << t;
183  else
184  cout << t;
185  }
186  }
187 
188  if (aos.sufficient_priority_file())
189  {
190 #pragma omp critical
191  {
192  // if (report_file) // Check if report file is good
193  report_file << t << flush;
194  // The flush here is necessary to make the output really
195  // appear in the report file. We are not producing a huge
196  // amount of output to the report file, so I think the
197  // performance penalty here is acceptable.
198  }
199  }
200  }
201 
202  return aos;
203 }
204 
205 #define CREATE_OUT0 ArtsOut0 out0(verbosity);
206 #define CREATE_OUT1 ArtsOut1 out1(verbosity);
207 #define CREATE_OUT2 ArtsOut2 out2(verbosity);
208 #define CREATE_OUT3 ArtsOut3 out3(verbosity);
209 
210 #define CREATE_OUTS \
211 ArtsOut0 out0(verbosity); \
212 ArtsOut1 out1(verbosity); \
213 ArtsOut2 out2(verbosity); \
214 ArtsOut3 out3(verbosity);
215 
216 #endif // messages_h
Verbosity::is_main_agenda
bool is_main_agenda() const
Definition: messages.h:67
ArtsOut::in_main_agenda
bool in_main_agenda() const
Definition: messages.h:124
operator<<
ArtsOut & operator<<(ArtsOut &aos, const T &t)
Output operator for ArtsOut.
Definition: messages.h:157
Verbosity::Verbosity
Verbosity()
Definition: messages.h:52
ArtsOut::priority
int priority
Definition: messages.h:131
Verbosity::Verbosity
Verbosity(Index vagenda, Index vscreen, Index vfile)
Definition: messages.h:54
ArtsOut1::ArtsOut1
ArtsOut1(const Verbosity &v)
Definition: messages.h:141
ArtsOut
Definition: messages.h:86
ArtsOut::sufficient_priority_screen
bool sufficient_priority_screen() const
Does the current message have sufficient priority for screen?
Definition: messages.h:109
array.h
This file contains the definition of Array.
ArtsOut3
Definition: messages.h:149
ArtsOut::verbosity
Verbosity verbosity
Definition: messages.h:130
Verbosity::va
Index va
Verbosity for agenda output. Can be 0-3.
Definition: messages.h:77
Verbosity::vs
Index vs
Verbosity for output to screen. Can be 0-3.
Definition: messages.h:79
ArtsOut0
Definition: messages.h:134
Verbosity::vf
Index vf
Verbosity for output to file. Can be 0-3.
Definition: messages.h:81
report_file
ofstream report_file
The report file.
Definition: messages.cc:45
Verbosity
Definition: messages.h:50
Verbosity::set_agenda_verbosity
void set_agenda_verbosity(Index v)
Definition: messages.h:69
Verbosity::get_agenda_verbosity
Index get_agenda_verbosity() const
Definition: messages.h:64
ArtsOut3::ArtsOut3
ArtsOut3(const Verbosity &v)
Definition: messages.h:151
ArtsOut0::ArtsOut0
ArtsOut0(const Verbosity &v)
Definition: messages.h:136
ArtsOut1
Definition: messages.h:139
Verbosity::in_main_agenda
bool in_main_agenda
Definition: messages.h:82
Verbosity::valid
bool valid() const
Check if artsmessages contains valid message levels.
Definition: messages.h:61
ArtsOut::get_priority
int get_priority() const
Definition: messages.h:91
Verbosity::set_file_verbosity
void set_file_verbosity(Index v)
Definition: messages.h:71
Verbosity::set_main_agenda
void set_main_agenda(bool main_agenda)
Definition: messages.h:72
Verbosity::get_screen_verbosity
Index get_screen_verbosity() const
Definition: messages.h:65
Verbosity::get_file_verbosity
Index get_file_verbosity() const
Definition: messages.h:66
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
ArtsOut2
Definition: messages.h:144
ArtsOut::ArtsOut
ArtsOut(const int p, const Verbosity &v)
Definition: messages.h:88
ArtsOut::get_verbosity
const Verbosity & get_verbosity() const
Definition: messages.h:92
Verbosity::operator<<
friend ostream & operator<<(ostream &os, const Verbosity &v)
Definition: messages.cc:48
arts_omp.h
Header file for helper functions for OpenMP.
ArtsOut2::ArtsOut2
ArtsOut2(const Verbosity &v)
Definition: messages.h:146
Verbosity::set_screen_verbosity
void set_screen_verbosity(Index v)
Definition: messages.h:70
ArtsOut::sufficient_priority_file
bool sufficient_priority_file() const
Does the current message have sufficient priority for file?
Definition: messages.h:119
ArtsOut::sufficient_priority_agenda
bool sufficient_priority_agenda() const
Does the current message have sufficient priority for agenda?
Definition: messages.h:99
arts.h
The global header file for ARTS.