Skip to content

Commit ad3a0b7

Browse files
Razvan Aguridandsarmany
Razvan Aguridan
authored andcommitted
MUL-132: Populate the (e)ORCA UID cache without reading the grids
1 parent 21f7728 commit ad3a0b7

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

src/multio/action/encode/GridDownloader.cc

+22-5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "GribEncoder.h"
1414

15+
#include "atlas/grid/SpecRegistry.h"
1516
#include "atlas/grid/Grid.h"
1617
#include "atlas/grid/Iterator.h"
1718
#include "atlas/library.h"
@@ -79,6 +80,10 @@ AtlasInstance& AtlasInstance::instance() {
7980
GridDownloader::GridDownloader(const config::ComponentConfiguration& compConf) :
8081
encoder_(createEncoder(compConf)), templateMetadata_(), gridCoordinatesCache_(), gridUIDCache_() {
8182

83+
ScopedAtlasInstance scopedAtlasInstance;
84+
85+
populateUIDCache(compConf);
86+
8287
if (encoder_ != nullptr) {
8388
initTemplateMetadata();
8489

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

117+
void GridDownloader::populateUIDCache(const config::ComponentConfiguration& compConf) {
118+
if (compConf.parsedConfig().has("unstructured-grid-type")) {
119+
atlas::mpi::Scope mpi_scope("self");
120+
121+
const auto baseGridName = compConf.parsedConfig().getString("unstructured-grid-type");
122+
for (auto const& unstructuredGridSubtype : {"T", "U", "V", "W", "F"}) {
123+
const auto completeGridName = baseGridName + "_" + unstructuredGridSubtype;
124+
125+
const auto gridSpec = atlas::grid::SpecRegistry::get(completeGridName);
126+
const auto gridUID = gridSpec.getString("uid");
127+
128+
gridUIDCache_.emplace(std::piecewise_construct, std::tuple(std::string(unstructuredGridSubtype) + " grid"),
129+
std::tuple(gridUID));
130+
}
131+
}
132+
}
133+
112134
void GridDownloader::initTemplateMetadata() {
113135
templateMetadata_.set("step", 0);
114136
templateMetadata_.set("typeOfLevel", "oceanSurface");
@@ -133,8 +155,6 @@ multio::message::Metadata GridDownloader::createMetadataFromCoordsData(size_t gr
133155
}
134156

135157
void GridDownloader::downloadOrcaGridCoordinates(const config::ComponentConfiguration& compConf) {
136-
ScopedAtlasInstance scopedAtlasInstance;
137-
138158
const auto baseGridName = compConf.parsedConfig().getString("unstructured-grid-type");
139159
for (auto const& unstructuredGridSubtype : {"T", "U", "V", "W", "F"}) {
140160
const auto completeGridName = baseGridName + "_" + unstructuredGridSubtype;
@@ -147,9 +167,6 @@ void GridDownloader::downloadOrcaGridCoordinates(const config::ComponentConfigur
147167

148168
const auto gridUID = grid.uid();
149169

150-
gridUIDCache_.emplace(std::piecewise_construct, std::tuple(std::string(unstructuredGridSubtype) + " grid"),
151-
std::tuple(gridUID));
152-
153170
if (encoder_ != nullptr) {
154171
const auto gridSize = grid.size();
155172

src/multio/action/encode/GridDownloader.h

+2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ class GridDownloader : eckit::NonCopyable {
7676
using GridCoordinateCache = std::unordered_map<DomainType, GridCoordinates>;
7777
using GridUIDCache = std::unordered_map<DomainType, GridUIDType>;
7878

79+
void populateUIDCache(const config::ComponentConfiguration& compConf);
80+
7981
void initTemplateMetadata();
8082
multio::message::Metadata createMetadataFromCoordsData(size_t gridSize, const std::string& unstructuredGridSubtype,
8183
const std::string& gridUID, int paramId);

0 commit comments

Comments
 (0)