WarpX
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 
131  void debug_read_warnings_from_input(amrex::ParmParse& params);
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 ;
193  bool m_always_warn_immediately = false ;
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_
WarnPriority
Definition: WarnManager.H:26
WarnManager & GetWMInstance()
Helper function to abbreviate the call to get a WarnManager instance.
Definition: WarnManager.cpp:300
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:305
Definition: WarnManager.H:48
Definition: WarnManager.H:19