From ee1e5f5e9b1424538e040e25bdb778ae664cb9d5 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Fri, 22 Dec 2023 17:22:24 +0100 Subject: [PATCH] Clean thermal lists : simplifying added(...) function (common list class) and consequences --- .../antares/study/parts/common/cluster_list.cpp | 10 ++-------- .../antares/study/parts/common/cluster_list.h | 2 +- .../study/parts/renewable/cluster_list.cpp | 8 +------- .../antares/study/parts/thermal/cluster_list.cpp | 12 +++--------- .../antares/study/parts/thermal/container.cpp | 15 ++++----------- src/tests/end-to-end/utils/utils.cpp | 4 ++-- 6 files changed, 13 insertions(+), 38 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index bc5f8e5aa5..de4896d6bd 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -114,18 +114,12 @@ void ClusterList::rebuildIndex() } template -typename ClusterList::SharedPtr ClusterList::add( - const ClusterList::SharedPtr newcluster) +void ClusterList::add(const SharedPtr newcluster) { - if (!newcluster) - return nullptr; - if (exists(newcluster->id())) - return newcluster; - + return; clusters.push_back(newcluster); rebuildIndex(); - return newcluster; } template diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index 9f3899aa8b..d92c77c36a 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -51,7 +51,7 @@ class ClusterList ** \param t The cluster to add ** \return True if the cluster has been added, false otherwise */ - SharedPtr add(const SharedPtr clusters); + void add(const SharedPtr clusters); /*! ** \brief Try to find a cluster from its id (const) diff --git a/src/libs/antares/study/parts/renewable/cluster_list.cpp b/src/libs/antares/study/parts/renewable/cluster_list.cpp index e23f84fe2a..5e202470dc 100644 --- a/src/libs/antares/study/parts/renewable/cluster_list.cpp +++ b/src/libs/antares/study/parts/renewable/cluster_list.cpp @@ -160,13 +160,7 @@ bool RenewableClusterList::loadFromFolder(const AnyString& folder, Area* area) cluster->integrityCheck(); // adding the renewable cluster - if (not add(cluster)) - { - // This error should never happen - logs.error() << "Impossible to add the renewable cluster '" << cluster->name() - << "'"; - continue; - } + add(cluster); } } diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index 3867bfeca4..07d68055e9 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -136,16 +136,10 @@ bool ThermalClusterList::loadFromFolder(Study& study, const AnyString& folder, A cluster->integrityCheck(); // adding the thermal cluster - auto added = add(cluster); - if (not added) - { - // This error should never happen - logs.error() << "Impossible to add the thermal cluster '" << cluster->name() - << "'"; - continue; - } + add(cluster); + // keeping track of the cluster - mapping[cluster->id()] = added; + mapping[cluster->id()] = cluster; } return ret; diff --git a/src/libs/antares/study/parts/thermal/container.cpp b/src/libs/antares/study/parts/thermal/container.cpp index a88bdf1e72..4b4fc84215 100644 --- a/src/libs/antares/study/parts/thermal/container.cpp +++ b/src/libs/antares/study/parts/thermal/container.cpp @@ -106,17 +106,10 @@ uint PartThermal::prepareClustersInMustRunMode() if (!cluster->enabled) continue; // ...and attaching it into the second list - if (!mustrunList.add(cluster)) - { - logs.error() << "Impossible to prepare the thermal cluster in 'must-run' mode: " - << cluster->parentArea->name << "::" << cluster->name(); - } - else - { - ++count; - logs.info() << "enabling 'must-run' mode for the cluster " - << cluster->parentArea->name << "::" << cluster->name(); - } + mustrunList.add(cluster); + ++count; + logs.info() << "enabling 'must-run' mode for the cluster " + << cluster->parentArea->name << "::" << cluster->name(); // the iterator has been invalidated, loop again mustContinue = true; diff --git a/src/tests/end-to-end/utils/utils.cpp b/src/tests/end-to-end/utils/utils.cpp index 70920b7ca3..c760e4f511 100644 --- a/src/tests/end-to-end/utils/utils.cpp +++ b/src/tests/end-to-end/utils/utils.cpp @@ -23,9 +23,9 @@ std::shared_ptr addClusterToArea(Area* area, const std::string& cluster->setName(clusterName); cluster->reset(); - auto added = area->thermal.list.add(cluster); + area->thermal.list.add(cluster); - area->thermal.list.mapping[cluster->id()] = added; + area->thermal.list.mapping[cluster->id()] = cluster; area->thermal.prepareAreaWideIndexes(); return cluster;