Skip to content

Commit

Permalink
Remove most uses of IResultWriter::Ptr, use ref instead (#1642)
Browse files Browse the repository at this point in the history
  • Loading branch information
flomnes authored Sep 22, 2023
1 parent f5be0da commit a87eb3a
Show file tree
Hide file tree
Showing 43 changed files with 132 additions and 150 deletions.
4 changes: 2 additions & 2 deletions src/libs/antares/study/area/links.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ bool AreaLink::loadTimeSeries(const Study& study, const AnyString& folder)
return linkLoadTimeSeries_for_version_820_and_later(folder);
}

void AreaLink::storeTimeseriesNumbers(Solver::IResultWriter::Ptr writer) const
void AreaLink::storeTimeseriesNumbers(Solver::IResultWriter& writer) const
{
Clob path;
TSNumbersPredicate predicate;
Expand All @@ -193,7 +193,7 @@ void AreaLink::storeTimeseriesNumbers(Solver::IResultWriter::Ptr writer) const
<< SEP << with->id << ".txt";

timeseriesNumbers.saveToBuffer(buffer, 0, true, predicate, true);
writer->addEntryFromBuffer(path.c_str(), buffer);
writer.addEntryFromBuffer(path.c_str(), buffer);
}

void AreaLink::detach()
Expand Down
2 changes: 1 addition & 1 deletion src/libs/antares/study/area/links.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class AreaLink final : public Yuni::NonCopyable<AreaLink>

bool loadTimeSeries(const Study& study, const AnyString& folder);

void storeTimeseriesNumbers(Solver::IResultWriter::Ptr writer) const;
void storeTimeseriesNumbers(Solver::IResultWriter& writer) const;

//! \name Area
//@{
Expand Down
18 changes: 9 additions & 9 deletions src/libs/antares/study/area/store-timeseries-numbers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct TSNumbersPredicate
};
} // anonymous namespace

static void genericStoreTimeseriesNumbers(Solver::IResultWriter::Ptr writer,
static void genericStoreTimeseriesNumbers(Solver::IResultWriter& writer,
const Matrix<uint32_t>& timeseriesNumbers,
const String& id,
const String& directory)
Expand All @@ -64,41 +64,41 @@ static void genericStoreTimeseriesNumbers(Solver::IResultWriter::Ptr writer,
predicate, // predicate
true); // save even if all coeffs are zero

writer->addEntryFromBuffer(path.c_str(), buffer);
writer.addEntryFromBuffer(path.c_str(), buffer);
}

void storeTimeseriesNumbersForLoad(Solver::IResultWriter::Ptr writer, const Area& area)
void storeTimeseriesNumbersForLoad(Solver::IResultWriter& writer, const Area& area)
{
genericStoreTimeseriesNumbers(writer, area.load.series->timeseriesNumbers, area.id, "load");
}

void storeTimeseriesNumbersForSolar(Solver::IResultWriter::Ptr writer, const Area& area)
void storeTimeseriesNumbersForSolar(Solver::IResultWriter& writer, const Area& area)
{
genericStoreTimeseriesNumbers(writer, area.solar.series->timeseriesNumbers, area.id, "solar");
}

void storeTimeseriesNumbersForHydro(Solver::IResultWriter::Ptr writer, const Area& area)
void storeTimeseriesNumbersForHydro(Solver::IResultWriter& writer, const Area& area)
{
genericStoreTimeseriesNumbers(writer, area.hydro.series->timeseriesNumbers, area.id, "hydro");
}

void storeTimeseriesNumbersForWind(Solver::IResultWriter::Ptr writer, const Area& area)
void storeTimeseriesNumbersForWind(Solver::IResultWriter& writer, const Area& area)
{
genericStoreTimeseriesNumbers(writer, area.wind.series->timeseriesNumbers, area.id, "wind");
}

void storeTimeseriesNumbersForThermal(Solver::IResultWriter::Ptr writer, const Area& area)
void storeTimeseriesNumbersForThermal(Solver::IResultWriter& writer, const Area& area)
{
area.thermal.list.storeTimeseriesNumbers(writer);
area.thermal.mustrunList.storeTimeseriesNumbers(writer);
}

void storeTimeseriesNumbersForRenewable(Solver::IResultWriter::Ptr writer, const Area& area)
void storeTimeseriesNumbersForRenewable(Solver::IResultWriter& writer, const Area& area)
{
area.renewable.list.storeTimeseriesNumbers(writer);
}

void storeTimeseriesNumbersForTransmissionCapacities(Solver::IResultWriter::Ptr writer, const Area& area)
void storeTimeseriesNumbersForTransmissionCapacities(Solver::IResultWriter& writer, const Area& area)
{
// No links originating from this area
// do not create an empty directory
Expand Down
18 changes: 9 additions & 9 deletions src/libs/antares/study/area/store-timeseries-numbers.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@
namespace Antares::Data
{
template<int TimeSeriesT>
void singleAreaStoreTimeseriesNumbers(Solver::IResultWriter::Ptr writer, const Area& area);
void singleAreaStoreTimeseriesNumbers(Solver::IResultWriter& writer, const Area& area);

template<int TimeSeriesT>
void storeTimeseriesNumbers(Solver::IResultWriter::Ptr writer, const AreaList& area);
void storeTimeseriesNumbers(Solver::IResultWriter& writer, const AreaList& area);

// Store time-series numbers
void storeTimeseriesNumbersForLoad(Solver::IResultWriter::Ptr writer, const Area& area);
void storeTimeseriesNumbersForSolar(Solver::IResultWriter::Ptr writer, const Area& area);
void storeTimeseriesNumbersForWind(Solver::IResultWriter::Ptr writer, const Area& area);
void storeTimeseriesNumbersForHydro(Solver::IResultWriter::Ptr writer, const Area& area);
void storeTimeseriesNumbersForThermal(Solver::IResultWriter::Ptr writer, const Area& area);
void storeTimeseriesNumbersForRenewable(Solver::IResultWriter::Ptr writer, const Area& area);
void storeTimeseriesNumbersForTransmissionCapacities(Solver::IResultWriter::Ptr writer, const Area& area);
void storeTimeseriesNumbersForLoad(Solver::IResultWriter& writer, const Area& area);
void storeTimeseriesNumbersForSolar(Solver::IResultWriter& writer, const Area& area);
void storeTimeseriesNumbersForWind(Solver::IResultWriter& writer, const Area& area);
void storeTimeseriesNumbersForHydro(Solver::IResultWriter& writer, const Area& area);
void storeTimeseriesNumbersForThermal(Solver::IResultWriter& writer, const Area& area);
void storeTimeseriesNumbersForRenewable(Solver::IResultWriter& writer, const Area& area);
void storeTimeseriesNumbersForTransmissionCapacities(Solver::IResultWriter& writer, const Area& area);

} //Antares::Data

Expand Down
4 changes: 2 additions & 2 deletions src/libs/antares/study/area/store-timeseries-numbers.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
namespace Antares::Data
{
template<int TimeSeriesT>
void singleAreaStoreTimeseriesNumbers(Solver::IResultWriter::Ptr writer, const Area& area)
void singleAreaStoreTimeseriesNumbers(Solver::IResultWriter& writer, const Area& area)
{
switch (TimeSeriesT)
{
Expand Down Expand Up @@ -69,7 +69,7 @@ void singleAreaStoreTimeseriesNumbers(Solver::IResultWriter::Ptr writer, const A
}

template<int TimeSeriesT>
void storeTimeseriesNumbers(Solver::IResultWriter::Ptr writer, const AreaList& area)
void storeTimeseriesNumbers(Solver::IResultWriter& writer, const AreaList& area)
{
// Each area in the list
area.each([&writer](const Area& a) { singleAreaStoreTimeseriesNumbers<TimeSeriesT>(writer, a); });
Expand Down
4 changes: 2 additions & 2 deletions src/libs/antares/study/parts/common/cluster_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ void ClusterList<ClusterT>::resizeAllTimeseriesNumbers(uint n)
#define SEP IO::Separator

template<class ClusterT>
void ClusterList<ClusterT>::storeTimeseriesNumbers(Solver::IResultWriter::Ptr writer) const
void ClusterList<ClusterT>::storeTimeseriesNumbers(Solver::IResultWriter& writer) const
{
if (cluster.empty())
return;
Expand All @@ -177,7 +177,7 @@ void ClusterList<ClusterT>::storeTimeseriesNumbers(Solver::IResultWriter::Ptr wr
<< cluster.id() << ".txt";
ts_content.clear(); // We must clear ts_content here, since saveToBuffer does not do it.
cluster.series->timeseriesNumbers.saveToBuffer(ts_content, 0, true, predicate, true);
writer->addEntryFromBuffer(path.c_str(), ts_content);
writer.addEntryFromBuffer(path.c_str(), ts_content);
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/libs/antares/study/parts/common/cluster_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class ClusterList
*/
void resizeAllTimeseriesNumbers(uint n);

void storeTimeseriesNumbers(Solver::IResultWriter::Ptr writer) const;
void storeTimeseriesNumbers(Solver::IResultWriter& writer) const;

//@}

Expand Down
4 changes: 2 additions & 2 deletions src/libs/antares/study/progression/progression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ Progression::~Progression()
pProgressMeter.stop();
}

bool Progression::saveToFile(const Yuni::String& filename, IResultWriter::Ptr writer)
bool Progression::saveToFile(const Yuni::String& filename, IResultWriter& writer)
{
Yuni::Clob buffer;
MutexLocker locker(pProgressMeter.mutex);
Expand All @@ -174,7 +174,7 @@ bool Progression::saveToFile(const Yuni::String& filename, IResultWriter::Ptr wr
}
}
}
writer->addEntryFromBuffer(filename.c_str(), buffer);
writer.addEntryFromBuffer(filename.c_str(), buffer);
logs.info() << LOG_UI_PROGRESSION_MAP << filename;
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libs/antares/study/progression/progression.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class Progression final

void add(Section section, int nbTicks);

bool saveToFile(const Yuni::String& filename, IResultWriter::Ptr writer);
bool saveToFile(const Yuni::String& filename, IResultWriter& writer);

void setNumberOfParallelYears(uint nb);

Expand Down
4 changes: 2 additions & 2 deletions src/libs/antares/study/simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ bool SimulationComments::saveToFolder(const AnyString& folder) const
return false;
}

void SimulationComments::saveUsingWriter(Solver::IResultWriter::Ptr writer,
void SimulationComments::saveUsingWriter(Solver::IResultWriter& writer,
const AnyString& folder) const
{
String b = folder;
b << SEP << "comments.txt";
std::string comments_copy = comments.c_str();
writer->addEntryFromBuffer(b.c_str(), comments_copy);
writer.addEntryFromBuffer(b.c_str(), comments_copy);
}

bool SimulationComments::loadFromFolder(const StudyLoadOptions& options)
Expand Down
2 changes: 1 addition & 1 deletion src/libs/antares/study/simulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class SimulationComments final
*/
bool saveToFolder(const AnyString& folder) const;

void saveUsingWriter(Solver::IResultWriter::Ptr writer, const AnyString& folder) const;
void saveUsingWriter(Solver::IResultWriter& writer, const AnyString& folder) const;

//! Get (in bytes) the amount of memory used by the class
uint64_t memoryUsage() const;
Expand Down
17 changes: 11 additions & 6 deletions src/libs/antares/study/study.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ void Study::saveAboutTheStudy()
path.reserve(1024);

path.clear() << "about-the-study";
simulationComments.saveUsingWriter(resultWriter, path);
simulationComments.saveUsingWriter(*resultWriter, path);

// Write the header as a reminder
{
Expand All @@ -711,7 +711,8 @@ void Study::saveAboutTheStudy()
std::string writeBuffer;
ini.saveToString(writeBuffer);

resultWriter->addEntryFromBuffer(path.c_str(), writeBuffer);
if (resultWriter)
resultWriter->addEntryFromBuffer(path.c_str(), writeBuffer);
}

// Write parameters.ini
Expand All @@ -720,7 +721,8 @@ void Study::saveAboutTheStudy()
dest << "about-the-study" << SEP << "parameters.ini";

buffer.clear() << folderSettings << SEP << "generaldata.ini";
resultWriter->addEntryFromFile(dest.c_str(), buffer.c_str());
if (resultWriter)
resultWriter->addEntryFromFile(dest.c_str(), buffer.c_str());
}

// antares-output.info
Expand All @@ -737,7 +739,8 @@ void Study::saveAboutTheStudy()
f << "\ntimestamp = " << pStartTime;
f << "\n\n";
auto output = f.str();
resultWriter->addEntryFromBuffer(path.c_str(), output);
if (resultWriter)
resultWriter->addEntryFromBuffer(path.c_str(), output);

if (usedByTheSolver and !parameters.noOutput)
{
Expand All @@ -751,15 +754,17 @@ void Study::saveAboutTheStudy()
buffer << "@ " << i->first << "\r\n";
}
areas.each([&](const Data::Area& area) { buffer << area.name << "\r\n"; });
resultWriter->addEntryFromBuffer(path.c_str(), buffer);
if (resultWriter)
resultWriter->addEntryFromBuffer(path.c_str(), buffer);
}

// Write all available links as a reminder
{
path.clear() << "about-the-study" << SEP << "links.txt";
Yuni::Clob buffer;
areas.saveLinkListToBuffer(buffer);
resultWriter->addEntryFromBuffer(path.c_str(), buffer);
if (resultWriter)
resultWriter->addEntryFromBuffer(path.c_str(), buffer);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libs/antares/study/study.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ inline bool Study::readonly() const
template<unsigned int TimeSeriesT>
inline void Study::storeTimeSeriesNumbers() const
{
storeTimeseriesNumbers<TimeSeriesT>(resultWriter, areas);
storeTimeseriesNumbers<TimeSeriesT>(*resultWriter, areas);
}

template<enum TimeSeries TS>
Expand Down
5 changes: 2 additions & 3 deletions src/solver/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ void Application::prepare(int argc, char* argv[])
{
auto& filename = pStudy->buffer;
filename.clear() << "about-the-study" << Yuni::IO::Separator << "map";
pStudy->progression.saveToFile(filename, pStudy->resultWriter);
pStudy->progression.saveToFile(filename, *pStudy->resultWriter);
pStudy->progression.start();
}
else
Expand Down Expand Up @@ -384,8 +384,7 @@ void Application::readDataForTheStudy(Data::StudyLoadOptions& options)
if (!pSettings.commentFile.empty())
{
auto writer = pStudy->resultWriter;
if (writer)
writer->addEntryFromFile(study.buffer.c_str(), pSettings.commentFile.c_str());
writer->addEntryFromFile(study.buffer.c_str(), pSettings.commentFile.c_str());

pSettings.commentFile.clear();
pSettings.commentFile.shrink();
Expand Down
1 change: 0 additions & 1 deletion src/solver/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "antares/infoCollection/StudyInfoCollector.h"

#include <antares/writer/i_writer.h>

#include <yuni/core/string.h>

namespace Antares::Solver
Expand Down
10 changes: 5 additions & 5 deletions src/solver/hydro/management/daily.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ struct DebugData
std::array<double, 12> CoutTotal{0};
std::array<double, 12> previousMonthWaste{0};

Solver::IResultWriter::Ptr pWriter;
Solver::IResultWriter& pWriter;
const TmpDataByArea& data;
const VENTILATION_HYDRO_RESULTS_BY_AREA& ventilationResults;
const InflowsType& srcinflows;
Expand All @@ -107,7 +107,7 @@ struct DebugData
const ReservoirLevelType& lowLevel;
const double reservoirCapacity;

DebugData(Solver::IResultWriter::Ptr writer,
DebugData(Solver::IResultWriter& writer,
const TmpDataByArea& data,
const VENTILATION_HYDRO_RESULTS_BY_AREA& ventilationResults,
const InflowsType& srcinflows,
Expand Down Expand Up @@ -150,7 +150,7 @@ struct DebugData
buffer << '\n';
}
auto buffer_str = buffer.str();
pWriter->addEntryFromBuffer(path.str(), buffer_str);
pWriter.addEntryFromBuffer(path.str(), buffer_str);
}

void writeDailyDebugData(const Date::Calendar& calendar,
Expand Down Expand Up @@ -218,7 +218,7 @@ struct DebugData
}
}
auto buffer_str = buffer.str();
pWriter->addEntryFromBuffer(path.str(), buffer_str);
pWriter.addEntryFromBuffer(path.str(), buffer_str);
}
};

Expand Down Expand Up @@ -260,7 +260,7 @@ inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::St

std::shared_ptr<DebugData> debugData(nullptr);

if (parameters_.hydroDebug && resultWriter_)
if (parameters_.hydroDebug)
{
debugData = std::make_shared<DebugData>(resultWriter_,
data,
Expand Down
2 changes: 1 addition & 1 deletion src/solver/hydro/management/management.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ HydroManagement::HydroManagement(const Data::AreaList& areas,
const Data::Parameters& params,
const Date::Calendar& calendar,
unsigned int maxNbYearsInParallel,
Solver::IResultWriter::Ptr resultWriter) :
Solver::IResultWriter& resultWriter) :
areas_(areas),
calendar_(calendar),
parameters_(params),
Expand Down
4 changes: 2 additions & 2 deletions src/solver/hydro/management/management.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class HydroManagement final
const Data::Parameters& params,
const Date::Calendar& calendar,
unsigned int maxNbYearsInParallel,
Solver::IResultWriter::Ptr resultWriter);
Solver::IResultWriter& resultWriter);

~HydroManagement();

Expand Down Expand Up @@ -172,7 +172,7 @@ class HydroManagement final
const Data::Parameters& parameters_;
MersenneTwister random_;
unsigned int maxNbYearsInParallel_ = 0;
Solver::IResultWriter::Ptr resultWriter_;
Solver::IResultWriter& resultWriter_;

ALL_HYDRO_VENTILATION_RESULTS ventilationResults_;
}; // class HydroManagement
Expand Down
4 changes: 2 additions & 2 deletions src/solver/hydro/management/monthly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ void HydroManagement::prepareMonthlyOptimalGenerations(double* random_reservoir_
assert(!Math::Infinite(data.MOL[realmonth]) && "infinite value detected for MOL");
}
#endif
if (parameters_.hydroDebug && resultWriter_)
if (parameters_.hydroDebug)
{
std::ostringstream buffer, path;
path << "debug" << SEP << "solver" << SEP << (1 + y) << SEP << "monthly." << area.name
Expand Down Expand Up @@ -292,7 +292,7 @@ void HydroManagement::prepareMonthlyOptimalGenerations(double* random_reservoir_
buffer << '\n';
}
auto content = buffer.str();
resultWriter_->addEntryFromBuffer(path.str(), content);
resultWriter_.addEntryFromBuffer(path.str(), content);
}
});
}
Expand Down
Loading

0 comments on commit a87eb3a

Please sign in to comment.