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
191 std::vector<std::string> current_event_digitized_entries;
192
194 bool is_building_frame = false;
195
197 std::ostringstream current_frame;
198
200 bool current_frame_has_header = false;
201
203 bool current_frame_has_payload = false;
204
206 std::string timestamp;
207
209 int event_number = -1;
210
212 int thread_id = -1;
213
214private:
220 [[nodiscard]] std::string filename() const override { return gstreamer_definitions.rootname + ".json"; }
221
222private:
223 // Private helper utilities. These remain undocumented by cross-reference on purpose.
224 static std::string jsonEscape(const std::string& s);
225 void ensureFileInitializedForType(const std::string& type);
226 void writeTopLevelEntry(const std::string& entry_json);
227 void closeTopLevelObjectIfNeeded();
228};
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.