1515#ifndef MDIO_COORDINATE_SELECTOR_H_
1616#define MDIO_COORDINATE_SELECTOR_H_
1717
18+ #include < map>
1819#include < string>
1920#include < tuple>
2021#include < utility>
@@ -80,17 +81,15 @@ inline constexpr bool is_sort_key_v = is_sort_key<std::decay_t<D>>::value;
8081class CoordinateSelector {
8182 public:
8283 // / Construct from an existing Dataset (captures its full domain).
83- explicit CoordinateSelector (Dataset& dataset)
84+ explicit CoordinateSelector (Dataset& dataset) // NOLINT (non-const)
8485 : dataset_(dataset), base_domain_(dataset.domain) {}
8586
86- template <typename ... OutTs, typename ... Ops>
87+ template <typename ... OutTs, typename ... Ops>
8788 Future<std::tuple<std::vector<OutTs>...>> ReadDataVariables (
88- std::vector<std::string> const & data_variables,
89- Ops const &... ops)
90- {
89+ std::vector<std::string> const & data_variables, Ops const &... ops) {
9190 if (data_variables.size () != sizeof ...(OutTs)) {
9291 return absl::InvalidArgumentError (
93- " ReadDataVariables: number of names must match number of OutTs" );
92+ " ReadDataVariables: number of names must match number of OutTs" );
9493 }
9594 // 1) apply all filters & sorts in order
9695 absl::Status st = absl::OkStatus ();
@@ -101,9 +100,7 @@ class CoordinateSelector {
101100 return _readMultiple<OutTs...>(data_variables);
102101 }
103102
104- void reset () {
105- kept_runs_.clear ();
106- }
103+ void reset () { kept_runs_.clear (); }
107104
108105 /* *
109106 * @brief Filter the Dataset by the given coordinate.
@@ -261,40 +258,33 @@ class CoordinateSelector {
261258 }
262259
263260 // helper: expands readSelection<OutTs>(vars[I])...
264- template <typename ... OutTs, std::size_t ... I>
261+ template <typename ... OutTs, std::size_t ... I>
265262 Future<std::tuple<std::vector<OutTs>...>> _readMultipleImpl (
266- std::vector<std::string> const & vars,
267- std::index_sequence<I...>)
268- {
263+ std::vector<std::string> const & vars, std::index_sequence<I...>) {
269264 // 1) start all reads
270- auto futs = std::make_tuple (
271- readSelection<OutTs>(vars[I])...
272- );
265+ auto futs = std::make_tuple (readSelection<OutTs>(vars[I])...);
273266
274267 // 2) wait on them in order
275268 absl::Status st = absl::OkStatus ();
276269 std::tuple<std::vector<OutTs>...> results;
277270 // fold over I...
278271 (
279- [&](){
280- if (!st.ok ()) return ;
281- auto & f = std::get<I>(futs);
282- st = f.status ();
283- if (st.ok ()) std::get<I>(results) = std::move (f.value ());
284- }(),
285- ...
286- );
272+ [&]() {
273+ if (!st.ok ()) return ;
274+ auto & f = std::get<I>(futs);
275+ st = f.status ();
276+ if (st.ok ()) std::get<I>(results) = std::move (f.value ());
277+ }(),
278+ ...);
287279 if (!st.ok ()) return st;
288280 return results;
289281 }
290282
291- template <typename ... OutTs>
283+ template <typename ... OutTs>
292284 Future<std::tuple<std::vector<OutTs>...>> _readMultiple (
293- std::vector<std::string> const & vars)
294- {
295- return _readMultipleImpl<OutTs...>(
296- vars, std::index_sequence_for<OutTs...>{}
297- );
285+ std::vector<std::string> const & vars) {
286+ return _readMultipleImpl<OutTs...>(vars,
287+ std::index_sequence_for<OutTs...>{});
298288 }
299289
300290 /*
@@ -315,28 +305,31 @@ class CoordinateSelector {
315305#ifdef MDIO_INTERNAL_PROFILING
316306 auto start = std::chrono::high_resolution_clock::now ();
317307#endif
318- MDIO_ASSIGN_OR_RETURN (auto var, dataset_. variables . at (
319- std::string (descriptor.label .label ())));
308+ MDIO_ASSIGN_OR_RETURN (
309+ auto var, dataset_. variables . at ( std::string (descriptor.label .label ())));
320310
321311 const T* data_ptr;
322312 Index offset;
323313 Index n_samples;
324314 MDIO_ASSIGN_OR_RETURN (auto intervals, var.get_intervals ());
325- if (cached_variables_.find (descriptor.label .label ()) == cached_variables_.end ()) {
315+ if (cached_variables_.find (descriptor.label .label ()) ==
316+ cached_variables_.end ()) {
326317 // TODO(BrianMichell): Ensure that the domain has not changed.
327318 std::cout << " Reading VariableData" << std::endl;
328319 auto fut = var.Read ();
329320 MDIO_ASSIGN_OR_RETURN (auto resolution, _resolve_future<void >(fut));
330321 auto dataToCache = std::get<0 >(resolution);
331- cached_variables_.insert_or_assign (descriptor.label .label (), std::move (dataToCache));
322+ cached_variables_.insert_or_assign (descriptor.label .label (),
323+ std::move (dataToCache));
332324 }
333325 auto it = cached_variables_.find (descriptor.label .label ());
334326 if (it == cached_variables_.end ()) {
335327 std::stringstream ss;
336- ss << " Cached variable not found for coordinate '" << descriptor.label .label () << " '" ;
328+ ss << " Cached variable not found for coordinate '"
329+ << descriptor.label .label () << " '" ;
337330 return absl::NotFoundError (ss.str ());
338331 }
339- auto & data = it->second ;
332+ auto & data = it->second ;
340333 data_ptr = static_cast <const T*>(data.get_data_accessor ().data ());
341334 offset = data.get_flattened_offset ();
342335 n_samples = data.num_samples ();
@@ -427,7 +420,6 @@ class CoordinateSelector {
427420 // until the Intervals are no longer needed.
428421 stored_intervals.reserve (kept_runs_.size ());
429422
430-
431423 bool is_first_run = true ;
432424
433425 for (const auto & desc : kept_runs_) {
0 commit comments