ARTS  2.2.66
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 <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 
97  bool sufficient_priority() const
98  {
101  }
102 
104 
107  {
109  }
110 
112 
115  {
117  }
118 
120 
123  {
125  }
126 
128 
130  bool in_main_agenda() const
131  {
132  return verbosity.is_main_agenda();
133  }
134 
135 private:
137  int priority;
138 };
139 
140 class ArtsOut0 : public ArtsOut {
141 public:
142  ArtsOut0 (const Verbosity& v) : ArtsOut(0, v) { }
143 };
144 
145 class ArtsOut1 : public ArtsOut {
146 public:
147  ArtsOut1 (const Verbosity& v) : ArtsOut(1, v) { }
148 };
149 
150 class ArtsOut2 : public ArtsOut {
151 public:
152  ArtsOut2 (const Verbosity& v) : ArtsOut(2, v) { }
153 };
154 
155 class ArtsOut3 : public ArtsOut {
156 public:
157  ArtsOut3 (const Verbosity& v) : ArtsOut(3, v) { }
158 };
159 
160 
162 template<class T>
163 ArtsOut& operator<<(ArtsOut& aos, const T& t)
164 {
165  extern ofstream report_file;
166 
167  // cout << "Printing object of type: " << typeid(t).name() << "\n";
168 
169  // If we are not in the main agenda, then the condition for agenda
170  // output must be fulfilled in addition to the condition for
171  // screen or file.
172 
173  if (aos.sufficient_priority_agenda())
174  {
175  // We are marking the actual output operations as omp
176  // critical, to somewhat reduce the mess when several threads
177  // output simultaneously.
178 
179  // This works well if the output operations themselves are
180  // atomic, that is if a string is prepared beforehand and then
181  // put to outx with a single << operation.
182 
183  if (aos.sufficient_priority_screen())
184  {
185 #pragma omp critical (ArtsOut_screen)
186  {
187  if (aos.get_priority() == 0)
188  cerr << t << flush;
189  else
190  cout << t << flush;
191  }
192  }
193 
194  if (aos.sufficient_priority_file())
195  {
196 #pragma omp critical (ArtsOut_file)
197  {
198  // if (report_file) // Check if report file is good
199  report_file << t << flush;
200  // The flush here is necessary to make the output really
201  // appear in the report file. We are not producing a huge
202  // amount of output to the report file, so I think the
203  // performance penalty here is acceptable.
204  }
205  }
206  }
207 
208  return aos;
209 }
210 
211 #define CREATE_OUT0 ArtsOut0 out0(verbosity)
212 #define CREATE_OUT1 ArtsOut1 out1(verbosity)
213 #define CREATE_OUT2 ArtsOut2 out2(verbosity)
214 #define CREATE_OUT3 ArtsOut3 out3(verbosity)
215 
216 #define CREATE_OUTS \
217 ArtsOut0 out0(verbosity); \
218 ArtsOut1 out1(verbosity); \
219 ArtsOut2 out2(verbosity); \
220 ArtsOut3 out3(verbosity)
221 
222 #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
Are we in the main agenda?
Definition: messages.h:130
operator<<
ArtsOut & operator<<(ArtsOut &aos, const T &t)
Output operator for ArtsOut.
Definition: messages.h:163
Verbosity::Verbosity
Verbosity()
Definition: messages.h:52
ArtsOut::sufficient_priority
bool sufficient_priority() const
Does the current message have sufficient priority for output?
Definition: messages.h:97
ArtsOut::priority
int priority
Definition: messages.h:137
Verbosity::Verbosity
Verbosity(Index vagenda, Index vscreen, Index vfile)
Definition: messages.h:54
ArtsOut1::ArtsOut1
ArtsOut1(const Verbosity &v)
Definition: messages.h:147
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:114
array.h
This file contains the definition of Array.
ArtsOut3
Definition: messages.h:155
ArtsOut::verbosity
Verbosity verbosity
Definition: messages.h:136
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:140
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:157
ArtsOut0::ArtsOut0
ArtsOut0(const Verbosity &v)
Definition: messages.h:142
ArtsOut1
Definition: messages.h:145
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:35
ArtsOut2
Definition: messages.h:150
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:152
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:122
ArtsOut::sufficient_priority_agenda
bool sufficient_priority_agenda() const
Does the current message have sufficient priority for agenda?
Definition: messages.h:106
arts.h
The global header file for ARTS.