OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
MultiColumnSeriesFile.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2//
3// Copyright 2026 Caleb Buahin
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
53
54#ifndef OPENSWMM_ENGINE_MULTI_COLUMN_SERIES_FILE_HPP
55#define OPENSWMM_ENGINE_MULTI_COLUMN_SERIES_FILE_HPP
56
57#include <string>
58#include <string_view>
59#include <unordered_map>
60#include <vector>
61
62namespace openswmm::input {
63
73 std::vector<std::string> headers;
74
76 std::vector<double> dates;
77
79 std::vector<std::vector<double>> columns;
80
82 double first_date = 0.0, last_date = 0.0;
83
84 // Per-column statistics over the WHOLE file (index-aligned with
85 // `headers`; entry 0 unused). These preserve the "Rainfall File
86 // Summary" values a per-gage scan used to produce.
87 std::vector<double> col_first_date;
88 std::vector<double> col_last_date;
89 std::vector<long> col_periods_precip;
90 std::vector<long> col_unparsed_cells;
91
93 long unparsed_rows = 0;
94
100 int find_column(std::string_view name) const;
101
103 int first_data_column() const {
104 return headers.size() > 1 ? 1 : -1;
105 }
106};
107
114
129bool parse_series_datetime(const std::string& cell, double& out);
130
142bool parse_multicolumn_series_file(const std::string& abs_path,
143 ParsedSeriesFile& out,
144 std::vector<std::string>& errors,
145 SeriesFileStatus* status = nullptr);
146
156bool looks_like_multicolumn_series_file(const std::string& abs_path);
157
185bool split_series_file_token(std::string_view token,
186 std::string& path_out,
187 std::string& column_out);
188
198public:
207 const ParsedSeriesFile* get_or_parse(const std::string& abs_path,
208 std::vector<std::string>& errors,
209 SeriesFileStatus* status = nullptr);
210
212 int parse_count() const noexcept { return parse_count_; }
213
214private:
215 struct Entry {
217 ParsedSeriesFile file;
218 };
219 std::unordered_map<std::string, Entry> files_;
220 int parse_count_ = 0;
221};
222
230long multicolumn_parse_count_total() noexcept;
231
232} /* namespace openswmm::input */
233
234#endif /* OPENSWMM_ENGINE_MULTI_COLUMN_SERIES_FILE_HPP */
Per-resolve-pass cache keyed by resolved path.
Definition MultiColumnSeriesFile.hpp:197
int parse_count() const noexcept
Number of actual parse attempts (test hook for the single-read assertion).
Definition MultiColumnSeriesFile.hpp:212
const ParsedSeriesFile * get_or_parse(const std::string &abs_path, std::vector< std::string > &errors, SeriesFileStatus *status=nullptr)
Return the parsed file, parsing it on first request.
Definition MultiColumnSeriesFile.cpp:371
Definition CatchmentHandler.cpp:69
bool parse_multicolumn_series_file(const std::string &abs_path, ParsedSeriesFile &out, std::vector< std::string > &errors, SeriesFileStatus *status)
Parse a multi-column series file (format auto-detected).
Definition MultiColumnSeriesFile.cpp:244
bool parse_series_datetime(const std::string &cell, double &out)
Parse a full datetime cell.
Definition MultiColumnSeriesFile.cpp:148
bool looks_like_multicolumn_series_file(const std::string &abs_path)
Cheap content sniff: does this file look multi-column?
Definition MultiColumnSeriesFile.cpp:186
SeriesFileStatus
Why a parse failed (or that it did not).
Definition MultiColumnSeriesFile.hpp:109
@ OPEN_FAILED
file could not be opened
Definition MultiColumnSeriesFile.hpp:111
@ FORMAT_FAILED
no header / no data columns
Definition MultiColumnSeriesFile.hpp:112
@ OK
parsed (possibly zero data rows)
Definition MultiColumnSeriesFile.hpp:110
bool split_series_file_token(std::string_view token, std::string &path_out, std::string &column_out)
Split a path[:column] FILE token into its path and column parts.
Definition MultiColumnSeriesFile.cpp:215
long multicolumn_parse_count_total() noexcept
Process-wide count of multi-column file parses (test hook).
Definition MultiColumnSeriesFile.cpp:386
One fully parsed multi-column series file (raw file-unit values).
Definition MultiColumnSeriesFile.hpp:71
std::vector< std::vector< double > > columns
columns[i] (i >= 1) aligned to dates; columns[0] is unused/empty.
Definition MultiColumnSeriesFile.hpp:79
double last_date
Definition MultiColumnSeriesFile.hpp:82
long unparsed_rows
Data rows whose datetime cell failed to parse (skipped entirely).
Definition MultiColumnSeriesFile.hpp:93
std::vector< double > col_last_date
Definition MultiColumnSeriesFile.hpp:88
int first_data_column() const
First data column (1) when one exists, else -1.
Definition MultiColumnSeriesFile.hpp:103
int find_column(std::string_view name) const
Case-insensitive column lookup by header name.
Definition MultiColumnSeriesFile.cpp:137
std::vector< long > col_unparsed_cells
value-parse failures
Definition MultiColumnSeriesFile.hpp:90
std::vector< std::string > headers
Header names; index 0 is the time-column label and never matches.
Definition MultiColumnSeriesFile.hpp:73
std::vector< long > col_periods_precip
cells with value > 0
Definition MultiColumnSeriesFile.hpp:89
std::vector< double > col_first_date
Definition MultiColumnSeriesFile.hpp:87
std::vector< double > dates
Row datetimes (SWMM OADate, whole file, ascending).
Definition MultiColumnSeriesFile.hpp:76
double first_date
Whole-file first/last datetime (0 when the file has no data rows).
Definition MultiColumnSeriesFile.hpp:82