Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
a-zakir committed Jul 1, 2024
1 parent 0d047fb commit 5292428
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ namespace Antares
class HydroErrorsCollector
{
public:
struct AreaSingleErrorMessage
{
std::string message = "";
unsigned int message_number = 0;
};

class AreaReference
{
public:
Expand All @@ -44,23 +38,23 @@ class HydroErrorsCollector
AreaReference& operator<<(const T& msg);

private:
AreaSingleErrorMessage& areaSingleErrorMessage_;
std::string& areaSingleErrorMessage_;
};

AreaReference operator()(const std::string& name);
HydroErrorsCollector() = default;
void CheckForErrors() const;

private:
std::multimap<std::string, AreaSingleErrorMessage> areasErrorMap_;
std::multimap<std::string, std::string> areasErrorMap_;
};

template<class T>
HydroErrorsCollector::AreaReference& HydroErrorsCollector::AreaReference::operator<<(const T& msg)
{
std::ostringstream strfy;
strfy << msg;
areaSingleErrorMessage_.message += strfy.str();
areaSingleErrorMessage_ += strfy.str();
return *this;
}

Expand Down
22 changes: 13 additions & 9 deletions src/solver/hydro/management/HydroErrorsCollector.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "antares/solver/hydro/management/HydroErrorsCollector.h"

#include <ranges>

#include <yuni/core/logs.h>

#include "antares/antares/fatal-error.h"
Expand All @@ -11,23 +13,25 @@ void HydroErrorsCollector::CheckForErrors() const
{
if (!areasErrorMap_.empty())
{
for (const auto& [area_name, area_msg]: areasErrorMap_)
for (const auto& key: areasErrorMap_ | std::views::keys)
{
logs.error() << "In Area " << area_name << area_msg.message;
auto first_elements = areasErrorMap_
| std::views::filter([&key](const auto& p)
{ return p.first == key; })
| std::views::take(10);

for (const auto& value: first_elements)
{
logs.error() << "In Area " << value.first << ": " << value.second << " ";
}
}
throw FatalError("Hydro validation has failed !");
}
}

HydroErrorsCollector::AreaReference::AreaReference(HydroErrorsCollector* collector,
const std::string& name):
areaSingleErrorMessage_(
collector->areasErrorMap_
.insert(

{name,
{.message = "", .message_number = (unsigned int)collector->areasErrorMap_.count(name)}})
->second)
areaSingleErrorMessage_(collector->areasErrorMap_.insert({name, ""})->second)
{
}

Expand Down

0 comments on commit 5292428

Please sign in to comment.