gstreamer
Loading...
Searching...
No Matches
gstreamerROOTFactory.cc
Go to the documentation of this file.
1// gstreamer
2#include "gRootTree.h"
4
5// keeps the include independent of TROOT
6#include <ROOT/RConfig.hxx>
7
8// Implementation summary:
9// Enable ROOT thread safety at plugin load time and provide lazy tree-creation helpers.
10
11namespace {
12 struct EnableRootTS
13 {
14 EnableRootTS() {
15 ROOT::EnableThreadSafety();
16 std::cout << "GstreamerRootFactory: ROOT thread safety enabled" << std::endl;
17 }
18 };
19
20 static EnableRootTS _enableROOTLocks;
21}
22
23// Implementation summary:
24// Return the event-header tree, creating it on first use.
25const std::unique_ptr<GRootTree>& GstreamerRootFactory::getOrInstantiateHeaderTree(
26 [[maybe_unused]] const std::unique_ptr<GEventHeader>& event_header) {
27 rootfile->cd();
28
29 if (!log) {
30 std::cerr << "FATAL: log is null in GstreamerRootFactory::getOrInstantiateHeaderTree" << std::endl;
31 std::terminate();
32 }
33
34 if (!event_header) {
35 log->error(ERR_PUBLISH_ERROR, "event header is null in GstreamerRootFactory::getOrInstantiateHeaderTree");
36 }
37
38 // operator[] either returns the existing entry or creates an empty one.
39 auto& treePtr = gRootTrees[EVENTHEADERTREENAME];
40 if (!treePtr) {
41 log->info(2, "GstreamerRootFactory", "Creating ROOT", EVENTHEADERTREENAME, " tree");
42 treePtr = std::make_unique<GRootTree>(event_header, log);
43 }
44
45 return treePtr;
46}
47
48// Implementation summary:
49// Return the run-header tree, creating it on first use.
50const std::unique_ptr<GRootTree>& GstreamerRootFactory::getOrInstantiateHeaderTree(
51 [[maybe_unused]] const std::unique_ptr<GRunHeader>& run_header) {
52 rootfile->cd();
53
54 if (!log) {
55 std::cerr << "FATAL: log is null in GstreamerRootFactory::getOrInstantiateHeaderTree" << std::endl;
56 std::terminate();
57 }
58
59 if (!run_header) {
60 log->error(ERR_PUBLISH_ERROR, "run header is null in GstreamerRootFactory::getOrInstantiateHeaderTree");
61 }
62
63 auto& treePtr = gRootTrees[RUNHEADERTREENAME];
64 if (!treePtr) {
65 log->info(2, "GstreamerRootFactory", "Creating ROOT", RUNHEADERTREENAME, " tree");
66 treePtr = std::make_unique<GRootTree>(run_header, log);
67 }
68
69 return treePtr;
70}
71
72// Implementation summary:
73// Return the true-information detector tree, creating it lazily from the first sample hit.
74const std::unique_ptr<GRootTree>& GstreamerRootFactory::getOrInstantiateTrueInfoDataTree(
75 const std::string& detectorName,
76 const GTrueInfoData* gdata) {
77 std::string treeName = TRUEINFONAMEPREFIX + detectorName;
78
79 auto& treePtr = gRootTrees[treeName];
80 if (!treePtr) {
81 log->info(2, "GstreamerRootFactory", "Creating GTrueInfoData ROOT tree for ", detectorName);
82 treePtr = std::make_unique<GRootTree>(treeName, gdata, log);
83 }
84
85 return treePtr;
86}
87
88// Implementation summary:
89// Return the digitized detector tree, creating it lazily from the first sample hit.
90const std::unique_ptr<GRootTree>& GstreamerRootFactory::getOrInstantiateDigitizedDataTree(
91 const std::string& detectorName,
92 const GDigitizedData* gdata) {
93 std::string treeName = DIGITIZEDNAMEPREFIX + detectorName;
94
95 auto& treePtr = gRootTrees[treeName];
96 if (!treePtr) {
97 log->info(2, "GstreamerRootFactory", "Creating GDigitizedData ROOT tree for ", detectorName);
98 treePtr = std::make_unique<GRootTree>(treeName, gdata, log);
99 }
100
101 return treePtr;
102}
103
104
105// Implementation summary:
106// Export the factory symbol required by the plugin loader.
107extern "C" GStreamer* GStreamerFactory(const std::shared_ptr<GOptions>& g) {
108 return static_cast<GStreamer*>(new GstreamerRootFactory(g));
109}
std::shared_ptr< GLogger > log
void info(int level, Args &&... args) const
void error(int exit_code, Args &&... args) const
Abstract base class for all gstreamer output plugins.
Definition gstreamer.h:77
ROOT plugin writing event and run content into TTree objects stored in one TFile.
ROOT tree adapter used internally by the ROOT gstreamer plugin.
#define EVENTHEADERTREENAME
Definition gRootTree.h:14
#define RUNHEADERTREENAME
Definition gRootTree.h:15
#define DIGITIZEDNAMEPREFIX
Definition gRootTree.h:17
#define TRUEINFONAMEPREFIX
Definition gRootTree.h:16
#define ERR_PUBLISH_ERROR
Publish sequence encountered invalid state or invalid input data.
GStreamer * GStreamerFactory(const std::shared_ptr< GOptions > &g)
ROOT streamer plugin declarations.