src/DataManager/DataManager.hpp
src/DataManager/DataManager.hpp
Namespaces
| Name |
|---|
| Neuralyzer |
| Neuralyzer::Entity |
| Neuralyzer::Entity::Lineage |
Classes
| Name | |
|---|---|
| class | DataManager |
Types
| Name | |
|---|---|
| using std::uint64_t | GroupId Unique identifier for user-defined groups of entities. |
| using std::function< bool(int current, int total, std::string const &message)> | JsonLoadProgressCallback Progress callback function type for JSON config loading. |
| using std::function< bool(nlohmann::json const &python_config, std::string &error_message)> | JsonPythonEnvironmentConfigurator Optional callback used to configure embedded Python before JSON data loading. |
Functions
| Name | |
|---|---|
| void | setJsonPythonEnvironmentConfigurator(JsonPythonEnvironmentConfigurator configurator) |
| void | clearJsonPythonEnvironmentConfigurator() |
| bool | ensureDefaultTimeFrameFallback(DataManager & dm) Populate the default timeTimeFrame when it is still empty after JSON loading. |
| std::vector< DataInfo > | load_data_from_json_config(DataManager * dm, std::string const & json_filepath) |
| std::vector< DataInfo > | load_data_from_json_config(DataManager * dm, std::string const & json_filepath, JsonLoadProgressCallback const & progress_callback) |
| std::vector< DataInfo > | load_data_from_json_config(DataManager * dm, nlohmann::json const & j, std::string const & base_path) |
| std::vector< DataInfo > | load_data_from_json_config(DataManager * dm, nlohmann::json const & j, std::string const & base_path, JsonLoadProgressCallback const & progress_callback) |
| std::string | convert_data_type_to_string(DM_DataType type) |
Types Documentation
using GroupId
using GroupId = std::uint64_t;Unique identifier for user-defined groups of entities.
Re-declare GroupId (defined in EntityGroupManager.hpp as std::uint64_t) to avoid pulling the full header into DataManager.hpp.
using JsonLoadProgressCallback
using JsonLoadProgressCallback = std::function<bool(int current, int total, std::string const & message)>;Progress callback function type for JSON config loading.
Parameters:
- current Current item index (0-based)
- total Total number of items to load
- message Description of current operation (e.g., “Loading points from file.json”)
Return: true to continue loading, false to cancel
using JsonPythonEnvironmentConfigurator
using JsonPythonEnvironmentConfigurator = std::function<bool(nlohmann::json const & python_config,
std::string & error_message)>;Optional callback used to configure embedded Python before JSON data loading.
Parameters:
- python_config Top-level JSON object from
python. - error_message Filled with a user-facing error when the callback returns false.
Return: true if loading may continue.
Applications that provide Python-backed loaders can install a configurator so a top-level JSON python block can activate a venv/conda environment before registry loaders run. Core DataManager remains independent of PythonRuntime.
Functions Documentation
function setJsonPythonEnvironmentConfigurator
void setJsonPythonEnvironmentConfigurator(
JsonPythonEnvironmentConfigurator configurator
)function clearJsonPythonEnvironmentConfigurator
void clearJsonPythonEnvironmentConfigurator()function ensureDefaultTimeFrameFallback
bool ensureDefaultTimeFrameFallback(
DataManager & dm
)Populate the default timeTimeFrame when it is still empty after JSON loading.
Parameters:
- dm DataManager to update.
Return: true if a new timeTimeFrame was created.
Scans all loaded [MediaData](/api_generated/Classes/classMediaData.md) keys with a positive frame count and builds an identity [TimeFrame](/api_generated/Classes/classTimeFrame.md)```[0, N-1] onTimeKey("time"). Does nothing iftime` already has samples or no suitable media exists.
function load_data_from_json_config
std::vector< DataInfo > load_data_from_json_config(
DataManager * dm,
std::string const & json_filepath
)function load_data_from_json_config
std::vector< DataInfo > load_data_from_json_config(
DataManager * dm,
std::string const & json_filepath,
JsonLoadProgressCallback const & progress_callback
)function load_data_from_json_config
std::vector< DataInfo > load_data_from_json_config(
DataManager * dm,
nlohmann::json const & j,
std::string const & base_path
)function load_data_from_json_config
std::vector< DataInfo > load_data_from_json_config(
DataManager * dm,
nlohmann::json const & j,
std::string const & base_path,
JsonLoadProgressCallback const & progress_callback
)function convert_data_type_to_string
std::string convert_data_type_to_string(
DM_DataType type
)Source code
#ifndef DATAMANAGER_HPP
#define DATAMANAGER_HPP
#include "DataManagerTypes.hpp"
#include "Commands/MutationGuard.hpp"
#include "Entity/EntityTypes.hpp"
#include "Observer/Observer_Data.hpp"
#include "TimeFrame/StrongTimeTypes.hpp"
#include "TimeFrame/TimeFrameIndex.hpp"
#include <functional> // std::function
#include <memory> // std::shared_ptr
#include <optional> // std::optional
#include <string> // std::string
#include <unordered_map>// std::unordered_map
#include <variant> // std::variant
#include <vector> // std::vector
#include "nlohmann/json_fwd.hpp"
// Forward declarations for identity
class EntityRegistry;
class EntityGroupManager;
using GroupId = std::uint64_t;
class TableRegistry;
struct TableEvent;
class TimeFrame;
namespace Neuralyzer::Entity::Lineage {
class LineageRegistry;
}
class DataManager {
public:
DataManager();
~DataManager();
// ======= Table Registry access =======
TableRegistry * getTableRegistry();
TableRegistry const * getTableRegistry() const;
// ======= Table observer channel (separate from data observers) =======
using TableObserver = std::function<void(TableEvent const &)>;
[[nodiscard]] int addTableObserver(TableObserver callback);
bool removeTableObserver(int callback_id);
bool setTime(TimeKey const & key, std::shared_ptr<TimeFrame> timeframe, bool overwrite = false);
[[nodiscard]] std::shared_ptr<TimeFrame> getTime();
[[nodiscard]] std::shared_ptr<TimeFrame> getTime(TimeKey const & key);
bool removeTime(TimeKey const & key);
bool setTimeKey(std::string const & data_key, TimeKey const & time_key);
[[nodiscard]] TimeKey getTimeKey(std::string const & data_key);
[[nodiscard]] std::vector<TimeKey> getTimeFrameKeys();
void reset();
using ObserverCallback = std::function<void()>;
[[nodiscard]] int addCallbackToData(std::string const & key, ObserverCallback callback);
bool removeCallbackFromData(std::string const & key, int callback_id);
int addObserver(ObserverCallback callback, std::string name = "Anonymous");
void removeObserver(int callback_id);
[[nodiscard]] std::vector<std::string> getAllKeys() const;
template<typename T>
[[nodiscard]] std::vector<std::string> getKeys() const {
std::vector<std::string> keys;
for (auto const & [key, value]: _data) {
if (std::holds_alternative<std::shared_ptr<T>>(value)) {
keys.push_back(key);
}
}
return keys;
}
std::optional<DataTypeVariant> getDataVariant(std::string const & key);
template<typename T>
std::shared_ptr<T> getData(std::string const & key) {
auto it = _data.find(key);
if (it != _data.end()) {
if (std::holds_alternative<std::shared_ptr<T>>(it->second)) {
return std::get<std::shared_ptr<T>>(it->second);
}
}
return nullptr;
}
template<typename T>
void setData(std::string const & key, TimeKey const & time_key) {
setData(key, std::make_shared<T>(), time_key);
}
void setData(std::string const & key, DataTypeVariant data, TimeKey const & time_key);
template<typename T>
void setData(std::string const & key, std::shared_ptr<T> data, TimeKey const & time_key) {
setData(key, DataTypeVariant{std::move(data)}, time_key);
}
bool deleteData(std::string const & key);
[[nodiscard]] DM_DataType getType(std::string const & key) const;
void setOutputPath(std::string const & output_path) { _output_path = output_path; };
[[nodiscard]] std::string const & getOutputPath() const {
return _output_path;
}
void notifyTableObservers(TableEvent const & ev);
// ======= Time Entity helpers =======
[[nodiscard]] EntityId ensureTimeEntityId(TimeKey const & time_key, TimeFrameIndex index);
[[nodiscard]] std::vector<EntityId> ensureTimeEntityIds(
TimeKey const & time_key, TimeFrameIndex start, TimeFrameIndex end);
[[nodiscard]] std::optional<std::pair<TimeKey, TimeFrameIndex>>
resolveTimeEntity(EntityId id) const;
[[nodiscard]] std::vector<TimeFrameIndex>
getTimeIndicesInGroup(GroupId group_id, TimeKey const & time_key) const;
[[nodiscard]] std::vector<TimeFrameIndex>
getTimeIndicesInGroupConverted(GroupId group_id, TimeKey const & target_key) const;
[[nodiscard]] EntityRegistry * getEntityRegistry() const { return _entity_registry.get(); }
[[nodiscard]] EntityGroupManager * getEntityGroupManager() const { return _entity_group_manager.get(); }
[[nodiscard]] Neuralyzer::Entity::Lineage::LineageRegistry * getLineageRegistry() const {
return _lineage_registry.get();
}
private:
std::unordered_map<TimeKey, std::shared_ptr<TimeFrame>> _times;
ObserverData _manager_observers = ObserverData("DataManager");
std::unordered_map<std::string, DataTypeVariant>
_data;
std::unordered_map<std::string, TimeKey> _time_frames;
std::string _output_path;
void _notifyObservers();
void _removeLineageForKey(std::string const & key);
// ======= Table Registry and observer internals =======
std::unique_ptr<TableRegistry> _table_registry;
std::unordered_map<int, TableObserver> _table_observers;
int _next_table_observer_id{1};
// ======= Identity / Entity registry =======
std::unique_ptr<EntityRegistry> _entity_registry;
std::unique_ptr<EntityGroupManager> _entity_group_manager;
// ======= Lineage registry =======
std::unique_ptr<Neuralyzer::Entity::Lineage::LineageRegistry> _lineage_registry;
};
using JsonLoadProgressCallback = std::function<bool(int current, int total, std::string const & message)>;
using JsonPythonEnvironmentConfigurator = std::function<bool(nlohmann::json const & python_config,
std::string & error_message)>;
void setJsonPythonEnvironmentConfigurator(JsonPythonEnvironmentConfigurator configurator);
void clearJsonPythonEnvironmentConfigurator();
bool ensureDefaultTimeFrameFallback(DataManager & dm);
std::vector<DataInfo> load_data_from_json_config(DataManager *, std::string const & json_filepath);
std::vector<DataInfo> load_data_from_json_config(DataManager *, std::string const & json_filepath, JsonLoadProgressCallback const & progress_callback);
std::vector<DataInfo> load_data_from_json_config(DataManager * dm, nlohmann::json const & j, std::string const & base_path);
std::vector<DataInfo> load_data_from_json_config(DataManager * dm, nlohmann::json const & j, std::string const & base_path, JsonLoadProgressCallback const & progress_callback);
std::string convert_data_type_to_string(DM_DataType type);
extern template std::shared_ptr<AnalogTimeSeries> DataManager::getData<AnalogTimeSeries>(std::string const & key);
extern template void DataManager::setData<AnalogTimeSeries>(std::string const & key, TimeKey const & time_key);
extern template void DataManager::setData<AnalogTimeSeries>(std::string const & key, std::shared_ptr<AnalogTimeSeries> data, TimeKey const & time_key);
extern template std::shared_ptr<DigitalEventSeries> DataManager::getData<DigitalEventSeries>(std::string const & key);
extern template void DataManager::setData<DigitalEventSeries>(std::string const & key, TimeKey const & time_key);
extern template void DataManager::setData<DigitalEventSeries>(std::string const & key, std::shared_ptr<DigitalEventSeries> data, TimeKey const & time_key);
extern template std::shared_ptr<DigitalIntervalSeries> DataManager::getData<DigitalIntervalSeries>(std::string const & key);
extern template void DataManager::setData<DigitalIntervalSeries>(std::string const & key, TimeKey const & time_key);
extern template void DataManager::setData<DigitalIntervalSeries>(std::string const & key, std::shared_ptr<DigitalIntervalSeries> data, TimeKey const & time_key);
extern template std::shared_ptr<LineData> DataManager::getData<LineData>(std::string const & key);
extern template void DataManager::setData<LineData>(std::string const & key, TimeKey const & time_key);
extern template void DataManager::setData<LineData>(std::string const & key, std::shared_ptr<LineData> data, TimeKey const & time_key);
extern template std::shared_ptr<MaskData> DataManager::getData<MaskData>(std::string const & key);
extern template void DataManager::setData<MaskData>(std::string const & key, TimeKey const & time_key);
extern template void DataManager::setData<MaskData>(std::string const & key, std::shared_ptr<MaskData> data, TimeKey const & time_key);
extern template std::shared_ptr<MediaData> DataManager::getData<MediaData>(std::string const & key);
extern template std::shared_ptr<PointData> DataManager::getData<PointData>(std::string const & key);
extern template void DataManager::setData<PointData>(std::string const & key, TimeKey const & time_key);
extern template void DataManager::setData<PointData>(std::string const & key, std::shared_ptr<PointData> data, TimeKey const & time_key);
extern template std::shared_ptr<TensorData> DataManager::getData<TensorData>(std::string const & key);
extern template void DataManager::setData<TensorData>(std::string const & key, TimeKey const & time_key);
extern template void DataManager::setData<TensorData>(std::string const & key, std::shared_ptr<TensorData> data, TimeKey const & time_key);
#endif// DATAMANAGER_HPPUpdated on 2026-11-13 at 20:25:43 +0000