Skip to content

Commit

Permalink
Using filesystem path 2 [ANT-1999] (#2454)
Browse files Browse the repository at this point in the history
following #2435
  • Loading branch information
payetvin authored Oct 16, 2024
1 parent 6f0499e commit 0bb9b9a
Show file tree
Hide file tree
Showing 67 changed files with 392 additions and 476 deletions.
4 changes: 0 additions & 4 deletions src/analyzer/atsp/cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@

#include "atsp.h"

using namespace Yuni;

#define SEP Yuni::Core::IO::Separator

namespace Antares
{
void ATSP::cacheCreate()
Expand Down
2 changes: 0 additions & 2 deletions src/libs/antares/memory/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@

using namespace Yuni;

#define SEP Yuni::IO::Separator

namespace Antares
{
/*extern*/
Expand Down
11 changes: 0 additions & 11 deletions src/libs/antares/paths/include/antares/paths/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,6 @@ class PathList
return item.empty();
}

template<class StringT>
size_t sizeOnDisk(const StringT& sourceFolder) const
{
if (item.empty())
{
return 0;
}
pTmp = sourceFolder;
return (!pTmp) ? 0 : internalSizeOnDisk();
}

size_t totalSizeInBytes() const;

template<class StringT>
Expand Down
18 changes: 1 addition & 17 deletions src/libs/antares/paths/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,6 @@ void PathList::clear()
item.clear();
}

size_t PathList::internalSizeOnDisk() const
{
size_t size = 0;
Clob buffer;

const ItemList::const_iterator end = item.end();
for (ItemList::const_iterator i = item.begin(); i != end; ++i)
{
if (!(i->second.options & pathListOptFolder))
{
buffer.clear() << pTmp << SEP << i->first;
size += (size_t)IO::File::Size(pTmp);
}
}
return size;
}

size_t PathList::totalSizeInBytes() const
{
size_t size = 0;
Expand All @@ -70,6 +53,7 @@ size_t PathList::totalSizeInBytes() const
return size;
}

// TODO VP: remove with tools
uint PathList::internalDeleteAllEmptyFolders()
{
if (!pTmp || item.empty())
Expand Down
8 changes: 2 additions & 6 deletions src/libs/antares/series/series.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@

#include <antares/antares/constants.h>

using namespace Yuni;

#define SEP IO::Separator

namespace Antares::Data
{
void TimeSeriesNumbers::registerSeries(const TimeSeries* s, std::string label)
Expand Down Expand Up @@ -135,8 +131,8 @@ int TimeSeries::saveToFolder(const std::string& areaID,
const std::string& folder,
const std::string& prefix) const
{
Clob buffer;
buffer.clear() << folder << SEP << prefix << areaID << ".txt";
Yuni::Clob buffer;
buffer.clear() << folder << Yuni::IO::Separator << prefix << areaID << ".txt";
return timeSeries.saveToCSVFile(buffer, 0);
}

Expand Down
50 changes: 22 additions & 28 deletions src/libs/antares/study/area/links.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ namespace fs = std::filesystem;

#define SEP (IO::Separator)

namespace
{
const YString DIRECTORY_NAME_FOR_TRANSMISSION_CAPACITIES = "ntc";
}

namespace Antares
{
namespace Data
Expand Down Expand Up @@ -78,15 +73,14 @@ AreaLink::~AreaLink()
{
}

bool AreaLink::linkLoadTimeSeries_for_version_below_810(const AnyString& folder)
bool AreaLink::linkLoadTimeSeries_for_version_below_810(const fs::path& folder)
{
String buffer;
buffer.clear() << folder << SEP << with->id << ".txt";
fs::path path = folder / static_cast<std::string>(with->id + ".txt");

// Load link's data
Matrix<> tmpMatrix;
const uint matrixWidth = 8;
if (!tmpMatrix.loadFromCSVFile(buffer,
if (!tmpMatrix.loadFromCSVFile(path.string(),
matrixWidth,
HOURS_PER_YEAR,
Matrix<>::optFixedSize | Matrix<>::optImmediate))
Expand All @@ -110,26 +104,28 @@ bool AreaLink::linkLoadTimeSeries_for_version_below_810(const AnyString& folder)
return true;
}

bool AreaLink::linkLoadTimeSeries_for_version_820_and_later(const AnyString& folder)
bool AreaLink::linkLoadTimeSeries_for_version_820_and_later(const fs::path& folder)
{
String capacitiesFolder;
capacitiesFolder << folder << SEP << "capacities";

String filename;
bool success = true;

// Read link's parameters times series
filename.clear() << folder << SEP << with->id << "_parameters.txt";
success = parameters.loadFromCSVFile(filename, fhlMax, HOURS_PER_YEAR, Matrix<>::optFixedSize)
std::string paramId = with->id + "_parameters.txt";
fs::path path = folder / paramId;
success = parameters.loadFromCSVFile(path.string(),
fhlMax,
HOURS_PER_YEAR,
Matrix<>::optFixedSize)
&& success;

fs::path capacitiesFolder = folder / "capacities";

// Read link's direct capacities time series
filename.clear() << capacitiesFolder << SEP << with->id << "_direct.txt";
success = directCapacities.loadFromFile(filename.c_str(), false) && success;
path = capacitiesFolder / static_cast<std::string>(with->id + "_direct.txt");
success = directCapacities.loadFromFile(path, false) && success;

// Read link's indirect capacities time series
filename.clear() << capacitiesFolder << SEP << with->id << "_indirect.txt";
success = indirectCapacities.loadFromFile(filename.c_str(), false) && success;
path = capacitiesFolder / static_cast<std::string>(with->id + "_indirect.txt");
success = indirectCapacities.loadFromFile(path, false) && success;

return success;
}
Expand Down Expand Up @@ -173,7 +169,7 @@ void AreaLink::overrideTransmissionCapacityAccordingToGlobalParameter(
}
}

bool AreaLink::loadTimeSeries(const StudyVersion& version, const AnyString& folder)
bool AreaLink::loadTimeSeries(const StudyVersion& version, const fs::path& folder)
{
if (version < StudyVersion(8, 2))
{
Expand All @@ -187,14 +183,12 @@ bool AreaLink::loadTimeSeries(const StudyVersion& version, const AnyString& fold

void AreaLink::storeTimeseriesNumbers(Solver::IResultWriter& writer) const
{
Clob path;
std::string buffer;

path << "ts-numbers" << SEP << DIRECTORY_NAME_FOR_TRANSMISSION_CAPACITIES << SEP << from->id
<< SEP << with->id << ".txt";
std::string filename = with->id + ".txt";
fs::path path = fs::path("ts-numbers") / "ntc" / from->id.to<std::string>() / filename;

std::string buffer;
timeseriesNumbers.saveToBuffer(buffer);
writer.addEntryFromBuffer(path.c_str(), buffer);
writer.addEntryFromBuffer(path, buffer);
}

void AreaLink::detach()
Expand Down Expand Up @@ -527,7 +521,7 @@ bool AreaLinksLoadFromFolder(Study& study, AreaList* areaList, Area* area, const
link.comments.clear();
link.displayComments = true;

ret = link.loadTimeSeries(study.header.version, folder.string()) && ret;
ret = link.loadTimeSeries(study.header.version, folder) && ret;

// Checks on loaded link's data
if (study.usedByTheSolver)
Expand Down
92 changes: 44 additions & 48 deletions src/libs/antares/study/area/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace Antares::Data
{
namespace // anonymous
{
static bool AreaListLoadThermalDataFromFile(AreaList& list, const Clob& filename)
static bool AreaListLoadThermalDataFromFile(AreaList& list, const fs::path& filename)
{
// Reset to 0
list.each(
Expand Down Expand Up @@ -776,38 +776,39 @@ bool AreaList::saveToFolder(const AnyString& folder) const
return ret;
}

template<class StringT>
static void readAdqPatchMode(Study& study, Area& area, StringT& buffer)
static void readAdqPatchMode(Study& study, Area& area)
{
if (study.header.version >= StudyVersion(8, 3))
if (study.header.version < StudyVersion(8, 3))
{
return;
}

fs::path adqPath = study.folderInput / "areas" / area.id.to<std::string>()
/ "adequacy_patch.ini";
IniFile ini;
if (ini.open(adqPath))
{
buffer.clear() << study.folderInput << SEP << "areas" << SEP << area.id << SEP
<< "adequacy_patch.ini";
IniFile ini;
if (ini.open(buffer))
auto* section = ini.find("adequacy-patch");
for (auto* p = section->firstProperty; p; p = p->next)
{
auto* section = ini.find("adequacy-patch");
for (auto* p = section->firstProperty; p; p = p->next)
CString<30, false> tmp;
tmp = p->key;
tmp.toLower();
if (tmp == "adequacy-patch-mode")
{
CString<30, false> tmp;
tmp = p->key;
tmp.toLower();
if (tmp == "adequacy-patch-mode")
{
auto value = (p->value).toLower();
auto value = (p->value).toLower();

if (value == "virtual")
{
area.adequacyPatchMode = Data::AdequacyPatch::virtualArea;
}
else if (value == "inside")
{
area.adequacyPatchMode = Data::AdequacyPatch::physicalAreaInsideAdqPatch;
}
else
{
area.adequacyPatchMode = Data::AdequacyPatch::physicalAreaOutsideAdqPatch;
}
if (value == "virtual")
{
area.adequacyPatchMode = Data::AdequacyPatch::virtualArea;
}
else if (value == "inside")
{
area.adequacyPatchMode = Data::AdequacyPatch::physicalAreaInsideAdqPatch;
}
else
{
area.adequacyPatchMode = Data::AdequacyPatch::physicalAreaOutsideAdqPatch;
}
}
}
Expand Down Expand Up @@ -899,7 +900,7 @@ static bool AreaListLoadFromFolderSingleArea(Study& study,
{
// if changes are required, please update reloadXCastData()
fs::path loadPath = study.folderInput / "load" / "prepro" / area.id.to<std::string>();
ret = area.load.prepro->loadFromFolder(loadPath.string()) && ret;
ret = area.load.prepro->loadFromFolder(loadPath) && ret;
}
if (!options.loadOnlyNeeded || !area.load.prepro) // Series
{
Expand All @@ -916,7 +917,7 @@ static bool AreaListLoadFromFolderSingleArea(Study& study,
{
// if changes are required, please update reloadXCastData()
fs::path solarPath = study.folderInput / "solar" / "prepro" / area.id.to<std::string>();
ret = area.solar.prepro->loadFromFolder(solarPath.string()) && ret;
ret = area.solar.prepro->loadFromFolder(solarPath) && ret;
}
if (!options.loadOnlyNeeded || !area.solar.prepro) // Series
{
Expand All @@ -940,7 +941,7 @@ static bool AreaListLoadFromFolderSingleArea(Study& study,
{
// if changes are required, please update reloadXCastData()
fs::path hydroPrepro = pathHydro / "prepro";
ret = area.hydro.prepro->loadFromFolder(study, area.id, hydroPrepro.string()) && ret;
ret = area.hydro.prepro->loadFromFolder(study, area.id, hydroPrepro) && ret;
ret = area.hydro.prepro->validate(area.id) && ret;
}

Expand Down Expand Up @@ -972,7 +973,7 @@ static bool AreaListLoadFromFolderSingleArea(Study& study,
{
// if changes are required, please update reloadXCastData()
fs::path windPath = study.folderInput / "wind" / "prepro" / area.id.to<std::string>();
ret = area.wind.prepro->loadFromFolder(windPath.string()) && ret;
ret = area.wind.prepro->loadFromFolder(windPath) && ret;
}
if (!options.loadOnlyNeeded || !area.wind.prepro) // Series
{
Expand Down Expand Up @@ -1016,7 +1017,7 @@ static bool AreaListLoadFromFolderSingleArea(Study& study,
}

// Adequacy patch
readAdqPatchMode(study, area, buffer);
readAdqPatchMode(study, area);

// Nodal Optimization
fs::path nodalPath = study.folderInput / "areas" / area.id.to<std::string>()
Expand Down Expand Up @@ -1160,21 +1161,18 @@ bool AreaList::loadFromFolder(const StudyLoadOptions& options)
// Thermal data, specific to areas
{
logs.info() << "Loading thermal clusters...";
buffer.clear() << pStudy.folderInput << SEP << "thermal" << SEP << "areas.ini";
ret = AreaListLoadThermalDataFromFile(*this, buffer) && ret;
fs::path thermalPath = pStudy.folderInput / "thermal";
fs::path areaIniPath = thermalPath / "areas.ini";
ret = AreaListLoadThermalDataFromFile(*this, areaIniPath) && ret;

// The cluster list must be loaded before the method
// ensureDataIsInitialized is called
// The cluster list must be loaded before the method ensureDataIsInitialized is called
// in order to allocate data with all thermal clusters.
CString<30, false> thermalPlant;
thermalPlant << SEP << "thermal" << SEP << "clusters" << SEP;

auto end = areas.end();
for (auto i = areas.begin(); i != end; ++i)
{
Area& area = *(i->second);
buffer.clear() << pStudy.folderInput << thermalPlant << area.id;
ret = area.thermal.list.loadFromFolder(pStudy, buffer.c_str(), &area) && ret;
fs::path areaPath = thermalPath / "clusters" / area.id.to<std::string>();
ret = area.thermal.list.loadFromFolder(pStudy, areaPath, &area) && ret;
ret = area.thermal.list.validateClusters(pStudy.parameters) && ret;
}
}
Expand Down Expand Up @@ -1203,18 +1201,16 @@ bool AreaList::loadFromFolder(const StudyLoadOptions& options)
// Renewable data, specific to areas
if (studyVersion >= StudyVersion(8, 1))
{
// The cluster list must be loaded before the method
// ensureDataIsInitialized is called
// The cluster list must be loaded before the method ensureDataIsInitialized is called
// in order to allocate data with all renewable clusters.
CString<30, false> renewablePlant;
renewablePlant << SEP << "renewables" << SEP << "clusters" << SEP;
fs::path renewClusterPath = pStudy.folderInput / "renewables" / "clusters";

auto end = areas.end();
for (auto i = areas.begin(); i != end; ++i)
{
Area& area = *(i->second);
buffer.clear() << pStudy.folderInput << renewablePlant << area.id;
ret = area.renewable.list.loadFromFolder(buffer.c_str(), &area) && ret;
fs::path areaPath = renewClusterPath / area.id.to<std::string>();
ret = area.renewable.list.loadFromFolder(areaPath, &area) && ret;
ret = area.renewable.list.validateClusters() && ret;
}
}
Expand Down
Loading

0 comments on commit 0bb9b9a

Please sign in to comment.