diff --git a/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h b/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h index 4ff8b4a842..d6054f12b6 100644 --- a/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h +++ b/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h @@ -23,6 +23,7 @@ #include #include #include +#include namespace Antares { @@ -46,7 +47,8 @@ class HydroErrorsCollector void CheckForErrors() const; private: - std::multimap areasErrorMap_; + std::map> areasErrorMap_; + std::string& CurrentMessage(const std::string& name); }; template diff --git a/src/solver/hydro/management/HydroErrorsCollector.cpp b/src/solver/hydro/management/HydroErrorsCollector.cpp index 81429161d7..729726e14e 100644 --- a/src/solver/hydro/management/HydroErrorsCollector.cpp +++ b/src/solver/hydro/management/HydroErrorsCollector.cpp @@ -14,46 +14,21 @@ void HydroErrorsCollector::CheckForErrors() const { if (!areasErrorMap_.empty()) { - std::set uniqueKeys; - std::transform(areasErrorMap_.begin(), - areasErrorMap_.end(), - std::inserter(uniqueKeys, uniqueKeys.begin()), - [](const auto& pair) { return pair.first; }); - - for (const auto& key: uniqueKeys) + for (const auto& [key, values]: areasErrorMap_) { - for (const auto& value: - areasErrorMap_ - | std::views::filter([&key](const auto& p) { return p.first == key; }) - | std::views::take(10)) + for (const auto& value: values | std::views::take(10)) { - logs.error() << "In Area " << value.first << ": " << value.second << " "; + logs.error() << "In Area " << key << ": " << value << " "; } } - // for (auto value = areasErrorMap_.begin(); value != areasErrorMap_.end();) - // { - // const auto& key = value->first; - // const auto& rangeEnd = areasErrorMap_.upper_bound(key); - - // const auto& limit = std::min(value + 10, rangeEnd); - - // for (; value != limit; ++value) - // { - // logs.error() << "In Area " << value.first << ": " << value.second << " "; - // } - - // // Move iterator to the next key - // value = rangeEnd; - // } - throw FatalError("Hydro validation has failed !"); } } HydroErrorsCollector::AreaReference::AreaReference(HydroErrorsCollector* collector, const std::string& name): - areaSingleErrorMessage_(collector->areasErrorMap_.insert({name, ""})->second) + areaSingleErrorMessage_(collector->CurrentMessage(name)) { } @@ -62,4 +37,9 @@ HydroErrorsCollector::AreaReference HydroErrorsCollector::operator()(const std:: return AreaReference(this, name); } +std::string& HydroErrorsCollector::CurrentMessage(const std::string& name) +{ + auto& msgs = areasErrorMap_[name]; + return *msgs.insert(msgs.end(), ""); +} } // namespace Antares