IO Management
-
class file_writer
Public Static Functions
-
static inline void write_testrun(const aggregated_payload &aggregate, const std::string ¶m_folder = "./params/runtime/", const std::string &payload_folder = "./params/payloads/")
Writes test run data and runtime parameters to JSON files.
This function serializes different payload states from an
aggregated_payloadinstance and writes them to separate JSON files in the specified payload folder. It also writes the overall runtime parameters to a JSON file in the specified parameter folder. Filenames are constructed using theaggregate.tagand a descriptive suffix corresponding to each payload state.- Parameters:
aggregate – The aggregated payload containing various data states to be saved.
param_folder – The directory path where the runtime parameters file will be saved. Defaults to “./params/runtime/”.
payload_folder – The directory path where the payload files will be saved. Defaults to “./params/payloads/”.
-
static inline void write_payload_to_file(const payload &payload, const std::string &filePath)
Serializes a payload object to a JSON file.
This function converts the contents of a
payloadstructure into a structured JSON document using RapidJSON, including frequency data, a data matrix, rotation phases, and a description object. The resulting JSON is written to the specified file path in a human-readable (pretty-printed) format.The function handles:
Converting
std::vectorfields to JSON arrays.Converting
Eigen::MatrixXdto a nested JSON array.Adding a
descriptionobject with pulsar and RFI metadata.Writing the entire document to a file.
If the file cannot be opened for writing, an error message is logged to
std::cerr.- Parameters:
payload – The data payload to be serialized to JSON.
filePath – The full path of the file where the JSON output will be saved.
-
static inline void write_runtime_to_file(const aggregated_payload &aggregate, const std::string &filePath)
Serializes runtime parameters from an aggregated payload to a JSON file.
This function extracts runtime configuration parameters from the
aggregated_payloadobject and writes them to a JSON file using RapidJSON. The output includes various simulation or processing parameters, such as spark configuration, drift velocity, dispersion measures, and scintillation indices. Values are structured in key-value pairs or JSON arrays as appropriate.The function performs the following:
Converts multiple
std::vector<double>fields to JSON arrays.Serializes scalar values like
drift_vel,dm_homogeneous, andstd_dm.Outputs a formatted, human-readable JSON document to the specified file path.
Logs an error to
std::cerrif the file cannot be opened.
- Parameters:
aggregate – The aggregated payload containing runtime parameters under
runtime_params.filePath – The full file path where the JSON document should be saved.
Private Static Functions
-
template<typename T>
static inline rapidjson::Value convert_vector_to_json(const std::vector<T> &vec, rapidjson::Document::AllocatorType &allocator) Converts a std::vector of values to a RapidJSON array.
This function takes a vector of elements and converts it into a RapidJSON
Valueof array type. Each element in the vector is added to the resulting JSON array using the provided allocator. The vector elements must be compatible with RapidJSON’sValue::PushBack, meaning they must be either RapidJSON values or types that can be implicitly converted to such.- Template Parameters:
T – The type of elements stored in the vector.
- Parameters:
vec – The input vector to be converted to a JSON array.
allocator – The RapidJSON allocator used for memory management during array construction.
- Returns:
rapidjson::Value A RapidJSON array containing the elements of the vector.
-
static inline rapidjson::Value convert_matrix_to_json(const Eigen::MatrixXd &mat, rapidjson::Document::AllocatorType &allocator)
Converts an Eigen::MatrixXd to a nested RapidJSON array.
This function serializes an Eigen dynamic-size double matrix (
Eigen::MatrixXd) into a RapidJSON array of arrays. Each row of the matrix is represented as a JSON array, resulting in a 2D JSON array structure that preserves the matrix layout.- Parameters:
mat – The Eigen matrix to be converted to a JSON array.
allocator – The RapidJSON allocator used for memory management during array construction.
- Returns:
rapidjson::Value A RapidJSON array representing the matrix as an array of row arrays.
-
static inline std::string convert_relative_path(const std::string &filepath)
Converts a relative file path to an absolute path string.
This function takes a file path and checks if it is relative. If so, it converts the path to an absolute form using the system’s current working directory and returns it as a formatted string. If the input path is already absolute, an empty string is returned.
- Parameters:
filepath – The file path to be evaluated and potentially converted.
- Returns:
std::string A string containing the absolute path prefixed with “Absolute path: “, or an empty string if the input path is already absolute.
-
static inline void write_testrun(const aggregated_payload &aggregate, const std::string ¶m_folder = "./params/runtime/", const std::string &payload_folder = "./params/payloads/")
-
class payload
- #include <payload.hpp>
Represents a data payload containing frequency-domain data and metadata.
The
payloadclass stores signal data across frequency channels, including the raw flux values in a matrix, corresponding frequencies, rotational phases, and a basic description. It provides methods to add new flux data and assign rotational phase information.Public Functions
-
inline payload(const std::vector<double> &freqs)
Constructs a payload with only frequency information.
- Parameters:
freqs – The frequency channels associated with this payload.
-
inline payload(std::vector<double> freqs, Eigen::MatrixXd dataframe, std::vector<double> rot_phases)
Adds a new flux data row to the dataframe after validating frequency alignment.
If the received frequencies match the existing ones, a new row is appended to the dataframe. Throws an exception if frequencies differ.
- Parameters:
radio_packet – A pair of vectors: (flux values, frequency values).
- Throws:
std::range_error – if frequency channels do not match.
-
inline void add_flux(const std::pair<std::vector<double>, std::vector<double>> &radio_packet)
Adds a new flux data row to the dataframe after validating frequency alignment.
If the received frequencies match the existing ones, a new row is appended to the dataframe. Throws an exception if frequencies differ.
- Parameters:
radio_packet – A pair of vectors: (flux values, frequency values).
- Throws:
std::range_error – if frequency channels do not match.
-
inline void assign_rot_phases(const std::vector<double> &rot_phases)
Assigns a vector of rotational phases to the payload.
- Parameters:
rot_phases – The rotational phase values to assign.
Public Members
-
std::vector<double> freqs
-
Eigen::MatrixXd dataframe
-
std::vector<double> rot_phases
-
description desc = description()
-
struct description
- #include <payload.hpp>
Struct to hold descriptive metadata for the payload.
Public Members
-
int Pulsar = 0
-
int NBRFI = 0
-
int BBRFI = 0
-
int Pulsar = 0
-
inline payload(const std::vector<double> &freqs)
-
class runtime
- #include <payload.hpp>
Stores simulation or signal runtime parameters.
The
runtimeclass encapsulates configuration parameters used for signal generation, processing, or simulation. These include properties of signal sources, propagation effects, and modeling assumptions.Public Members
-
std::vector<int> num_sparks
-
std::vector<double> conal_latitudes
-
Eigen::Vector2d spark_rotation_axis_polar_att0
-
double drift_vel
-
double spark_dimension
-
std::vector<double> spark_mid_freqs
-
std::vector<double> spark_flux_powers
-
Eigen::Vector3d direction
-
double dm_homogeneous
-
double scintillation_index_homogeneous
-
double std_dm
-
double std_scintillation_index
-
std::vector<int> num_sparks
-
class aggregated_payload
- #include <payload.hpp>
Container class that aggregates multiple payloads and runtime parameters.
This class is used to manage and organize multiple versions or stages of a data payload (e.g., raw, detected, processed), along with runtime configuration parameters. Each payload is associated with a
LOAD_STATE.Public Types
-
enum LOAD_STATE
Enumeration representing the state or type of a payload.
Values:
-
enumerator RAW
-
enumerator TO_BE_PROPAGATED
-
enumerator DETECTED
-
enumerator FLUX
-
enumerator RAW
Public Functions
-
inline aggregated_payload(std::string tag)
Constructs an aggregated payload with a custom tag.
- Parameters:
tag – The identifier or label for this payload instance.
-
inline void add(LOAD_STATE state, const payload &cargo)
Adds a payload to the appropriate state slot.
- Parameters:
state – The state corresponding to the type of payload.
cargo – The payload to insert.
-
enum LOAD_STATE