FERS 1.0.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
output_metadata.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-only
2//
3// Copyright (c) 2026-present FERS Contributors (see AUTHORS.md).
4//
5// See the GNU GPLv2 LICENSE file in the FERS project root for more information.
6
7#include "output_metadata.h"
8
9#include <nlohmann/json.hpp>
10#include <utility>
11
12#include "core/parameters.h"
13
14namespace core
15{
16 namespace
17 {
18 nlohmann::json chunkToJson(const PulseChunkMetadata& chunk)
19 {
20 return {{"chunk_index", chunk.chunk_index},
21 {"i_dataset", chunk.i_dataset},
22 {"q_dataset", chunk.q_dataset},
23 {"start_time", chunk.start_time},
24 {"sample_count", chunk.sample_count},
25 {"sample_start", chunk.sample_start},
26 {"sample_end_exclusive", chunk.sample_end_exclusive}};
27 }
28
29 nlohmann::json cwSegmentToJson(const CwSegmentMetadata& segment)
30 {
31 return {{"start_time", segment.start_time},
32 {"end_time", segment.end_time},
33 {"sample_count", segment.sample_count},
34 {"sample_start", segment.sample_start},
35 {"sample_end_exclusive", segment.sample_end_exclusive}};
36 }
37
38 nlohmann::json fileToJson(const OutputFileMetadata& file)
39 {
40 nlohmann::json chunks = nlohmann::json::array();
41 for (const auto& chunk : file.chunks)
42 {
43 chunks.push_back(chunkToJson(chunk));
44 }
45
46 nlohmann::json cw_segments = nlohmann::json::array();
47 for (const auto& segment : file.cw_segments)
48 {
49 cw_segments.push_back(cwSegmentToJson(segment));
50 }
51
52 return {{"receiver_id", file.receiver_id},
53 {"receiver_name", file.receiver_name},
54 {"mode", file.mode},
55 {"path", file.path},
56 {"total_samples", file.total_samples},
57 {"sample_start", file.sample_start},
58 {"sample_end_exclusive", file.sample_end_exclusive},
59 {"pulse_count", file.pulse_count},
60 {"min_pulse_length_samples", file.min_pulse_length_samples},
61 {"max_pulse_length_samples", file.max_pulse_length_samples},
62 {"uniform_pulse_length", file.uniform_pulse_length},
63 {"chunks", chunks},
64 {"cw_segments", cw_segments}};
65 }
66
67 nlohmann::json metadataToJson(const OutputMetadata& metadata)
68 {
69 nlohmann::json files = nlohmann::json::array();
70 for (const auto& file : metadata.files)
71 {
72 files.push_back(fileToJson(file));
73 }
74
75 return {{"schema_version", metadata.schema_version},
76 {"simulation_name", metadata.simulation_name},
77 {"output_directory", metadata.output_directory},
78 {"start_time", metadata.start_time},
79 {"end_time", metadata.end_time},
80 {"sampling_rate", metadata.sampling_rate},
81 {"oversample_ratio", metadata.oversample_ratio},
82 {"files", files}};
83 }
84 }
85
87 {
88 _metadata.output_directory = std::move(output_dir);
90 _metadata.start_time = params::startTime();
91 _metadata.end_time = params::endTime();
92 _metadata.sampling_rate = params::rate();
94 }
95
97 {
98 std::scoped_lock lock(_mutex);
99 _metadata.files.push_back(std::move(file_metadata));
100 }
101
103 {
104 std::scoped_lock lock(_mutex);
105 return _metadata;
106 }
107
109 {
110 return fileToJson(metadata).dump(2);
111 }
112
113 std::string outputMetadataToJsonString(const OutputMetadata& metadata) { return metadataToJson(metadata).dump(2); }
114}
void addFile(OutputFileMetadata file_metadata)
OutputMetadataCollector(std::string output_dir)
OutputMetadata snapshot() const
std::string outputFileMetadataToJsonString(const OutputFileMetadata &metadata)
std::string outputMetadataToJsonString(const OutputMetadata &metadata)
RealType endTime() noexcept
Get the end time for the simulation.
Definition parameters.h:109
RealType rate() noexcept
Get the rendering sample rate.
Definition parameters.h:121
RealType startTime() noexcept
Get the start time for the simulation.
Definition parameters.h:103
unsigned oversampleRatio() noexcept
Get the oversampling ratio.
Definition parameters.h:151
Parameters params
Definition parameters.h:85
Defines the Parameters struct and provides methods for managing simulation parameters.
std::uint64_t sample_end_exclusive
std::uint64_t max_pulse_length_samples
std::vector< PulseChunkMetadata > chunks
std::uint64_t sample_end_exclusive
std::uint64_t min_pulse_length_samples
std::vector< CwSegmentMetadata > cw_segments
std::vector< OutputFileMetadata > files
std::string output_directory
std::string simulation_name
std::uint64_t sample_end_exclusive
std::string simulation_name
The name of the simulation, from the XML.
Definition parameters.h:74