1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
/* Copyright 2021 Luca Fedeli
*
* This file is part of WarpX.
*
* License: BSD-3-Clause-LBNL
*/
#ifndef WARPX_WARN_MANAGER_H_
#define WARPX_WARN_MANAGER_H_
#include "WarnManager_fwd.H"
#include "MsgLogger/MsgLogger_fwd.H"
#include <AMReX_ParmParse.H>
#include <memory>
#include <string>
#include <vector>
namespace Utils
{
/**
* The class WarnManager manages warning messages in WarpX,
* providing methods to record warnings, and print warning
* lists.
*/
class WarnManager
{
public:
/**
* The constructor.
*/
WarnManager();
/**
* \brief This function records a warning message.
*
* @param[in] topic a string to identify the topic of the warning (e.g., "parallelization", "pbc", "particles"...)
* @param[in] text the text of the warning message
* @param[in] priority priority of the warning message ("medium" by default)
*/
void record_warning(
std::string topic,
std::string text,
MsgLogger::Priority priority);
/**
* \brief This function prints all the warning messages collected on the present MPI rank
* (i.e., this is not a collective call). This function is mainly intended for debug purposes.
*
* @param[in] when a string to mark when the warnings are printed out (it appears in the warning list)
* @return a string containing the "local" warning list
*/
std::string print_local_warnings(
const std::string& when) const;
/**
* \brief This function prints all the warning messages collected by all the MPI ranks
* (i.e., this is a collective call). Only the I/O rank prints the message.
*
* @param[in] when a string to mark when the warnings are printed out (it appears in the warning list)
* @return a string containing the "global" warning list
*/
std::string print_global_warnings(
const std::string& when) const;
/**
* \brief This function reads warning messages from the inputfile. It is intended for
* debug&testing purposes
*
* @param[in, out] params the inputfile parser
*/
void debug_read_warnings_from_input(amrex::ParmParse& params);
static const int warn_line_size = 80 /*! Maximum line length to be used in formatting warning list*/;
static const int warn_tab_size = 5 /*! Tabulation size to be used in formatting warning list*/;
private:
/**
* \brief This function generates the header of the warning messages list
*
* @param[in] when a string to mark when the warnings are printed out (it appears in the warning list)
* @param[in] line_size maximum line length to be used in formatting warning list
* @param[in] is_global flag: true if the header is for a global warning list, false otherwise
* @return a string containing the header of the warning list
*/
std::string get_header(
const std::string& when,
const int line_size,
const bool is_global) const;
/**
* \brief This function generates a string for a single entry of the warning list
* for a MessageWithCounter struct (i.e., a warning message paired with a counter storing
* how many times the warning has been raised)
*
* @param[in] msg_with_counter a MessageWithCounter
* @return a string containing the warning message
*/
std::string print_warn_msg(
const MsgLogger::MsgWithCounter& msg_with_counter) const;
/**
* \brief This function generates a string for a single entry of the warning list
* for a MsgWithCounterAndRanks struct (i.e., a warning message paired with a counter storing
* how many times the warning has been raised and info on which ranks have raised the warning)
*
* @param[in] msg_with_counter_and_ranks a MsgWithCounterAndRanks
* @return a string containing the warning message
*/
std::string print_warn_msg(
const MsgLogger::MsgWithCounterAndRanks& msg_with_counter_and_ranks) const;
/**
* \brief This function formats each line of a warning message text
*
* @param[in] msg the warning message text
* @param[in] line_size maximum line length to be used in formatting warning list
* @param[in] tab_size tabulation size to be used in formatting warning list
* @return a string containing the formatted warning message text
*/
std::string msg_formatter(
const std::string& msg,
const int line_size,
const int tab_size) const;
int m_rank = 0 /*! MPI rank (appears in the warning list)*/;
std::unique_ptr<MsgLogger::Logger> m_p_logger /*! The Logger stores all the warning messages*/;
};
}
#endif //WARPX_WARN_MANAGER_H_
|