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
42public:
45
50
51private:
60 bool openConnection() override;
61
67 bool closeConnectionImpl() override;
68
77 bool startEventImpl(const std::shared_ptr<GEventDataCollection>& event_data) override;
78
85 bool endEventImpl(const std::shared_ptr<GEventDataCollection>& event_data) override;
86
93 bool publishEventHeaderImpl(const std::unique_ptr<GEventHeader>& gevent_header) override;
94
102 bool publishEventTrueInfoDataImpl(const std::string& detectorName,
103 const std::vector<const GTrueInfoData*>& trueInfoData) override;
104
112 bool publishEventDigitizedDataImpl(const std::string& detectorName,
113 const std::vector<const GDigitizedData*>& digitizedData) override;
114
125 bool publishEventGeneratedParticlesImpl(const std::string& bankName,
126 const GGeneratedParticleBank& particles) override;
127
134 bool startStreamImpl(const GFrameDataCollection* frameRunData) override;
135
142 bool endStreamImpl(const GFrameDataCollection* frameRunData) override;
143
150 bool publishFrameHeaderImpl(const GFrameHeader* gframeHeader) override;
151
158 bool publishPayloadImpl(const std::vector<GIntegralPayload*>* payload) override;
159
160private:
162 std::ofstream ofile;
163
165 bool is_file_initialized = false;
166
168 bool wrote_first_top_level_entry = false;
169
171 std::string top_level_type;
172
174 bool is_building_event = false;
175
177 std::ostringstream current_event;
178
180 bool current_event_has_header = false;
181
183 bool current_event_has_any_detector = false;
184
186 bool current_event_has_generated = false;
187
189 bool is_building_frame = false;
190
192 std::ostringstream current_frame;
193
195 bool current_frame_has_header = false;
196
198 bool current_frame_has_payload = false;
199
201 std::string timestamp;
202
204 int event_number = -1;
205
207 int thread_id = -1;
208
209private:
215 [[nodiscard]] std::string filename() const override { return gstreamer_definitions.rootname + ".json"; }
216
217private:
218 // Private helper utilities. These remain undocumented by cross-reference on purpose.
219 static std::string jsonEscape(const std::string& s);
220 void ensureFileInitializedForType(const std::string& type);
221 void writeTopLevelEntry(const std::string& entry_json);
222 void closeTopLevelObjectIfNeeded();
223};
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< 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.