Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
a-zakir committed Jul 1, 2024
1 parent 37aac75 commit 18afdbb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,22 @@ class HydroErrorsCollector
void Collect(const std::string& area_name, const std::string& message);
void Collect(const std::string& message);
void CheckForFatalErrors() const;
template<class T>
std::ostream& operator<<(const T& obj);

private:
// for log
constexpr unsigned int TRHESHOLD_NUMBER_OF_ERRORS_FOR_ONE_AREA = 10;
std::map<std::string, unsigned int> area_errors_counter_;
bool errors_limit_reached_ = false;
bool stop_ = false;
// std::vector<std::string> fatal_errors_;
};

template<class T>
HydroErrorsCollector& HydroErrorsCollector::operator<<(const T& obj)
{
logs.error() << obj;
return *this;
}
} // namespace Antares
9 changes: 5 additions & 4 deletions src/solver/hydro/management/HydroErrorsCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ namespace Antares
void HydroErrorsCollector::Collect(const std::string& area_name, const std::string& message)
{
logs.error() << "In Area " << area_name << " " << message;
area_errors_counter_[area_name]++;
errors_limit_reached_ = area_errors_counter_[area_name] > 10;
auto error_count = area_errors_counter_[area_name]++;
errors_limit_reached_ = error_count > TRHESHOLD_NUMBER_OF_ERRORS_FOR_ONE_AREA;
stop_ = true;

if (errors_limit_reached_)
{
throw FatalError("Hydro validation has failed !");
logs.error() << "Hydro validation has failed !";
logs.error() << error_count << " errors found in Area " << area_name;
}
}

Expand All @@ -27,7 +28,7 @@ void HydroErrorsCollector::Collect(const std::string& message)

void HydroErrorsCollector::CheckForFatalErrors() const
{
if (stop_ || errors_limit_reached_)
if (stop_)
{
throw FatalError("Hydro validation has failed !");
}
Expand Down

0 comments on commit 18afdbb

Please sign in to comment.