Skip to content

Commit

Permalink
MUL-132: Populate the (e)ORCA UID cache without reading the grids
Browse files Browse the repository at this point in the history
  • Loading branch information
Razvan Aguridan authored and dsarmany committed Jul 17, 2024
1 parent 37b60dd commit 51816f2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/multio/action/encode/GridDownloader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "GribEncoder.h"

#include "atlas/grid/SpecRegistry.h"
#include "atlas/grid/Grid.h"
#include "atlas/grid/Iterator.h"
#include "atlas/library.h"
Expand Down Expand Up @@ -79,6 +80,10 @@ AtlasInstance& AtlasInstance::instance() {
GridDownloader::GridDownloader(const config::ComponentConfiguration& compConf) :
encoder_(createEncoder(compConf)), templateMetadata_(), gridCoordinatesCache_(), gridUIDCache_() {

ScopedAtlasInstance scopedAtlasInstance;

populateUIDCache(compConf);

if (encoder_ != nullptr) {
initTemplateMetadata();

Expand Down Expand Up @@ -109,6 +114,23 @@ std::optional<GridCoordinates> GridDownloader::getGridCoords(const GridDownloade
return GridCoordinates{encodedLat, encodedLon};
}

void GridDownloader::populateUIDCache(const config::ComponentConfiguration& compConf) {
if (compConf.parsedConfig().has("unstructured-grid-type")) {
atlas::mpi::Scope mpi_scope("self");

const auto baseGridName = compConf.parsedConfig().getString("unstructured-grid-type");
for (auto const& unstructuredGridSubtype : {"T", "U", "V", "W", "F"}) {
const auto completeGridName = baseGridName + "_" + unstructuredGridSubtype;

const auto gridSpec = atlas::grid::SpecRegistry::get(completeGridName);
const auto gridUID = gridSpec.getString("uid");

gridUIDCache_.emplace(std::piecewise_construct, std::tuple(std::string(unstructuredGridSubtype) + " grid"),
std::tuple(gridUID));
}
}
}

void GridDownloader::initTemplateMetadata() {
templateMetadata_.set("step", 0);
templateMetadata_.set("typeOfLevel", "oceanSurface");
Expand All @@ -133,8 +155,6 @@ multio::message::Metadata GridDownloader::createMetadataFromCoordsData(size_t gr
}

void GridDownloader::downloadOrcaGridCoordinates(const config::ComponentConfiguration& compConf) {
ScopedAtlasInstance scopedAtlasInstance;

const auto baseGridName = compConf.parsedConfig().getString("unstructured-grid-type");
for (auto const& unstructuredGridSubtype : {"T", "U", "V", "W", "F"}) {
const auto completeGridName = baseGridName + "_" + unstructuredGridSubtype;
Expand All @@ -147,9 +167,6 @@ void GridDownloader::downloadOrcaGridCoordinates(const config::ComponentConfigur

const auto gridUID = grid.uid();

gridUIDCache_.emplace(std::piecewise_construct, std::tuple(std::string(unstructuredGridSubtype) + " grid"),
std::tuple(gridUID));

if (encoder_ != nullptr) {
const auto gridSize = grid.size();

Expand Down
2 changes: 2 additions & 0 deletions src/multio/action/encode/GridDownloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class GridDownloader : eckit::NonCopyable {
using GridCoordinateCache = std::unordered_map<DomainType, GridCoordinates>;
using GridUIDCache = std::unordered_map<DomainType, GridUIDType>;

void populateUIDCache(const config::ComponentConfiguration& compConf);

void initTemplateMetadata();
multio::message::Metadata createMetadataFromCoordsData(size_t gridSize, const std::string& unstructuredGridSubtype,
const std::string& gridUID, int paramId);
Expand Down

0 comments on commit 51816f2

Please sign in to comment.