ARTEMIS
WarnManager.H
Go to the documentation of this file.
1 /* Copyright 2022 Luca Fedeli
2  *
3  * This file is part of WarpX.
4  *
5  * License: BSD-3-Clause-LBNL
6  */
7 
8 #ifndef ABLASTR_WARN_MANAGER_H_
9 #define ABLASTR_WARN_MANAGER_H_
10 
12 
13 #include <AMReX_ParmParse.H>
14 
15 #include <memory>
16 #include <optional>
17 #include <string>
18 
20 {
21 
26  enum class WarnPriority
27  {
31  low,
35  medium,
40  high
41  };
42 
49  {
50  public:
51 
55  WarnManager(WarnManager &other) = delete;
56 
60  void operator=(const WarnManager &) = delete;
61 
62  static WarnManager& GetInstance();
63 
71  void RecordWarning(
72  std::string topic,
73  std::string text,
75 
83  std::string PrintLocalWarnings(
84  const std::string& when) const;
85 
93  std::string PrintGlobalWarnings(
94  const std::string& when) const;
95 
101  void SetAlwaysWarnImmediately(bool always_warn_immediately);
102 
108  bool GetAlwaysWarnImmediatelyFlag() const;
109 
116  void SetAbortThreshold(std::optional<WarnPriority> abort_threshold);
117 
123  std::optional<WarnPriority> GetAbortThreshold() const;
124 
132 
133  static const int warn_line_size = 80 ;
134  static const int warn_tab_size = 5 ;
135 
136  private:
137 
141  WarnManager();
142 
151  std::string PrintWarnMsg(
152  const ablastr::utils::msg_logger::MsgWithCounter& msg_with_counter) const;
153 
162  std::string PrintWarnMsg(
163  const ablastr::utils::msg_logger::MsgWithCounterAndRanks& msg_with_counter_and_ranks) const;
164 
173  static std::string GetHeader(
174  const std::string& when,
175  const int line_size,
176  const bool is_global);
177 
186  static std::string MsgFormatter(
187  const std::string& msg,
188  const int line_size,
189  const int tab_size);
190 
191  int m_rank = 0 ;
192  std::unique_ptr<ablastr::utils::msg_logger::Logger> m_p_logger ;
194  std::optional<WarnPriority> m_abort_on_warning_threshold = std::nullopt ;
195  };
196 
203 
212  void WMRecordWarning(
213  std::string topic,
214  std::string text,
216 }
217 
218 #endif //ABLASTR_WARN_MANAGER_H_
Definition: WarnManager.H:49
static std::string MsgFormatter(const std::string &msg, const int line_size, const int tab_size)
This function formats each line of a warning message text.
Definition: WarnManager.cpp:283
WarnManager(WarnManager &other)=delete
std::string PrintWarnMsg(const ablastr::utils::msg_logger::MsgWithCounter &msg_with_counter) const
This function generates a string for a single entry of the warning list for a MessageWithCounter stru...
Definition: WarnManager.cpp:211
void SetAlwaysWarnImmediately(bool always_warn_immediately)
Setter for the m_always_warn_immediately.
Definition: WarnManager.cpp:155
std::unique_ptr< ablastr::utils::msg_logger::Logger > m_p_logger
Definition: WarnManager.H:192
std::string PrintLocalWarnings(const std::string &when) const
This function prints all the warning messages collected on the present MPI rank (i....
Definition: WarnManager.cpp:99
bool GetAlwaysWarnImmediatelyFlag() const
Getter for the m_always_warn_immediately.
Definition: WarnManager.cpp:160
static std::string GetHeader(const std::string &when, const int line_size, const bool is_global)
This function generates the header of the warning messages list.
Definition: WarnManager.cpp:258
static const int warn_tab_size
Definition: WarnManager.H:134
void RecordWarning(std::string topic, std::string text, WarnPriority priority=WarnPriority::medium)
This function records a warning message (recording a warning message is thread-safe)
Definition: WarnManager.cpp:52
std::optional< WarnPriority > m_abort_on_warning_threshold
Definition: WarnManager.H:194
int m_rank
Definition: WarnManager.H:191
std::optional< WarnPriority > GetAbortThreshold() const
Getter for the m_abort_on_warning_threshold flag.
Definition: WarnManager.cpp:170
void operator=(const WarnManager &)=delete
bool m_always_warn_immediately
Definition: WarnManager.H:193
void debug_read_warnings_from_input(amrex::ParmParse &params)
This function reads warning messages from the inputfile. It is intended for debug&testing purposes.
Definition: WarnManager.cpp:175
WarnManager()
Definition: WarnManager.cpp:47
static WarnManager & GetInstance()
Definition: WarnManager.cpp:42
static const int warn_line_size
Definition: WarnManager.H:133
void SetAbortThreshold(std::optional< WarnPriority > abort_threshold)
Setter for the m_abort_on_warning_threshold flag (pass std::nullopt in order to never abort)
Definition: WarnManager.cpp:165
std::string PrintGlobalWarnings(const std::string &when) const
This function prints all the warning messages collected by all the MPI ranks (i.e....
Definition: WarnManager.cpp:124
Definition: WarnManager.H:20
void WMRecordWarning(std::string topic, std::string text, WarnPriority priority=WarnPriority::medium)
Helper function to abbreviate the call to WarnManager::GetInstance().RecordWarning (recording a warni...
Definition: WarnManager.cpp:306
WarnManager & GetWMInstance()
Helper function to abbreviate the call to get a WarnManager instance.
Definition: WarnManager.cpp:301
WarnPriority
Definition: WarnManager.H:27