gstreamer
Loading...
Searching...
No Matches
gstreamerJSONFactory.h
Go to the documentation of this file.
1#pragma once
2
3// gstreamer
4#include "gstreamer.h"
6
7// c++
8#include <fstream>
9#include <sstream>
10#include <string>
11#include <vector>
12
43public:
46
51
52private:
61 bool openConnection() override;
62
68 bool closeConnectionImpl() override;
69
78 bool startEventImpl(const std::shared_ptr<GEventDataCollection>& event_data) override;
79
86 bool endEventImpl(const std::shared_ptr<GEventDataCollection>& event_data) override;
87
94 bool publishEventHeaderImpl(const std::unique_ptr<GEventHeader>& gevent_header) override;
95
103 bool publishEventTrueInfoDataImpl(const std::string& detectorName,
104 const std::vector<const GTrueInfoData*>& trueInfoData) override;
105
113 bool publishEventDigitizedDataImpl(const std::string& detectorName,
114 const std::vector<const GDigitizedData*>& digitizedData) override;
115
126 bool publishEventGeneratedParticlesImpl(const std::string& bankName,
127 const GGeneratedParticleBank& particles) override;
128
130 bool publishEventAncestorsImpl(const GAncestorBank& ancestors) override;
131
138 bool startStreamImpl(const GFrameDataCollection* frameRunData) override;
139
146 bool endStreamImpl(const GFrameDataCollection* frameRunData) override;
147
154 bool publishFrameHeaderImpl(const GFrameHeader* gframeHeader) override;
155
162 bool publishPayloadImpl(const std::vector<GIntegralPayload*>* payload) override;
163
164private:
166 std::ofstream ofile;
167
169 bool is_file_initialized = false;
170
172 bool wrote_first_top_level_entry = false;
173
175 std::string top_level_type;
176
178 bool is_building_event = false;
179
181 std::ostringstream current_event;
182
184 bool current_event_has_header = false;
185
187 bool current_event_has_any_detector = false;
188
190 bool current_event_has_generated = false;
191
195 std::vector<std::string> current_event_digitized_entries;
196
198 bool is_building_frame = false;
199
201 std::ostringstream current_frame;
202
204 bool current_frame_has_header = false;
205
207 bool current_frame_has_payload = false;
208
210 std::string timestamp;
211
213 int event_number = -1;
214
216 int thread_id = -1;
217
218private:
224 [[nodiscard]] std::string filename() const override { return gstreamer_definitions.rootname + ".json"; }
225
226private:
227 // Private helper utilities. These remain undocumented by cross-reference on purpose.
228 static std::string jsonEscape(const std::string& s);
229 void ensureFileInitializedForType(const std::string& type);
230 void writeTopLevelEntry(const std::string& entry_json);
231 void closeTopLevelObjectIfNeeded();
232};
Abstract base class for all gstreamer output plugins.
Definition gstreamer.h:78
GStreamer(const std::shared_ptr< GOptions > &g)
Construct the streamer base and initialize module logging.
Definition gstreamer.h:85
GStreamerDefinition gstreamer_definitions
Output definition currently bound to this streamer instance.
Definition gstreamer.h:207
JSON plugin writing structured event or frame output into a single JSON document.
GstreamerJsonFactory(GstreamerJsonFactory &&)=delete
GstreamerJsonFactory(const GstreamerJsonFactory &)=delete
GstreamerJsonFactory & operator=(GstreamerJsonFactory &&)=delete
GstreamerJsonFactory & operator=(const GstreamerJsonFactory &)=delete
std::vector< GAncestorData > GAncestorBank
std::vector< GGeneratedParticleData > GGeneratedParticleBank
Shared constants and error codes for the gstreamer module.
Core streaming interface and helper utilities for the gstreamer module.
std::string rootname
Base output filename without extension, optionally specialized by thread id.