IDS peak ICV v1.3.0
Loading...
Searching...
No Matches
pipeline_base.py
Go to the documentation of this file.
1from __future__ import annotations
2
3from abc import ABC
4from typing import Any
5
6from ids_peak_common.exceptions import IOException
7from ids_peak_common.pipeline.ipipeline import IPipeline
8
9
10class PipelineBase(IPipeline, ABC):
11 """!
12 @brief
13 Base class for implementing a custom pipeline.
14
15 Provides a partial implementation of the IPipeline interface.
16 Can be used as a foundation for creating custom pipeline behavior.
17
18 @since ids_peak_common 1.1
19 @ingroup ids_peak_common_python_pipeline
20 """
21
22 def export_settings_to_file(self, file_path: str) -> None:
23 """!
24 @brief
25 Saves the current settings of the pipeline and its modules to a file.
26
27 This base implementation calls `export_settings_to_string()` and
28 writes the resulting string to the specified file path.
29 """
30 try:
31 with open(file_path, "w", encoding="utf-8") as f:
32 f.write(self.export_settings_to_string())
33 except OSError as e:
34 raise IOException(
35 f"Saving settings to the file {file_path} failed: {e}") from e
36
37 def import_settings_from_file(self, file_path: str) -> None:
38 """!
39 @brief
40 Loads the settings of the pipeline and its modules from a file.
41
42 This base implementation reads the file contents and passes them to
43 `import_settings_from_string()` to restore the pipeline state.
44 """
45 try:
46 with open(file_path, "r", encoding="utf-8") as f:
47 settings = f.read()
48 self.import_settings_from_string(settings)
49 except OSError as e:
50 raise IOException(
51 f"Loading settings from the file {file_path} failed: {e}"
52 ) from e
53
54 def process(self, data: Any) -> Any:
55 """!
56 @brief
57 Processes the input data through all pipeline modules
58 and returns the result.
59
60 This base implementation iterates over all modules returned
61 by `get_modules()`, calling each module's `process()` method in
62 sequence and passing the result along.
63
64 @param data: The input data to process.
65
66 @return The processed input.
67 """
68 for module in self._modules:
69 data = module.process(data)
70
71 return data
Base class for implementing a custom pipeline.
None import_settings_from_file(self, str file_path)
Loads the settings of the pipeline and its modules from a file.
Any process(self, Any data)
Processes the input data through all pipeline modules and returns the result.
None export_settings_to_file(self, str file_path)
Saves the current settings of the pipeline and its modules to a file.