Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
WithFallback.h
Go to the documentation of this file.
1// #ifndef __WITHFALLBACK_H__
2// #define __WITHFALLBACK_H__
3
4// #include "IContourExtractor.h"
5// #include "Logger.h"
6
7// class WithFallback : public IContourExtractor {
8// public:
9// WithFallback(std::shared_ptr<IContourExtractor> primary, std::shared_ptr<IContourExtractor> fallback) : primary(std::move(primary)), fallback(std::move(fallback)) {}
10
11// Contour extract(const ScalarField2D& field, const ContourRequest& cr) override {
12// auto res = primary->extract(field, cr);
13// if (!res.success) {
14// LOG_WARN("Primary contour extraction method failed, falling back.");
15// res = fallback->extract(field, cr);
16// }
17// return res;
18// }
19
20// private:
21// std::shared_ptr<IContourExtractor> primary;
22// std::shared_ptr<IContourExtractor> fallback;
23// };
24
25// #endif // __WITHFALLBACK_H__
26//for segfault
27
28#ifndef WITHFALLBACK_H
29#define WITHFALLBACK_H
30
31#include <exception>
32
33#include "IContourExtractor.h"
34#include "Logger.h"
35
53public:
61 WithFallback(std::shared_ptr<IContourExtractor> primary, std::shared_ptr<IContourExtractor> fallback)
62 : primary(std::move(primary)), fallback(std::move(fallback)) {}
63
75 Contour extract(const ScalarField2D& field, const ContourRequest& cr) override {
76 Contour res;
77 bool primary_returned = false;
78
79 try {
80 res = primary->extract(field, cr);
81 primary_returned = true;
82 } catch (const std::exception& e) {
83 LOG_WARN("Primary contour extraction threw, falling back: ", e.what());
84 } catch (...) {
85 LOG_WARN("Primary contour extraction threw unknown exception, falling back.");
86 }
87
88 if (!primary_returned || !res.success) {
89 LOG_WARN("Primary contour extraction method failed or returned no contour, falling back.");
90 res = fallback->extract(field, cr);
91 }
92
93 return res;
94 }
95
96private:
97 std::shared_ptr<IContourExtractor> primary;
98 std::shared_ptr<IContourExtractor> fallback;
99};
100
101#endif // WITHFALLBACK_H
Common data structures and interface for 2D contour extraction.
#define LOG_WARN(...)
Macro for logging warning messages.
Definition Logger.h:40
Abstract interface for algorithms extracting 2D contour paths.
Tries a primary contour extractor and falls back to another extractor on failure.
Contour extract(const ScalarField2D &field, const ContourRequest &cr) override
Extracts a contour using the primary extractor, then fallback if needed.
WithFallback(std::shared_ptr< IContourExtractor > primary, std::shared_ptr< IContourExtractor > fallback)
Constructs a fallback contour extractor wrapper.
std::function< double(double, double)> ScalarField2D
Definition contour.h:17
Hash specialization for SymbolId<Tag>.
Definition BlockName.h:353
Input configuration for a two-dimensional contour extraction.
Output of a contour extraction algorithm.
bool success
Whether extraction produced a valid contour.