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) {
36 "event header is null in GstreamerRootFactory::getOrInstantiateHeaderTree");
37 }
38
39 // operator[] either returns the existing entry or creates an empty one.
40 auto& treePtr = gRootTrees[gstreamer::root::EVENTHEADERTREENAME];
41 if (!treePtr) {
42 log->info(2, "GstreamerRootFactory", "Creating ROOT", gstreamer::root::EVENTHEADERTREENAME, " tree");
43 treePtr = std::make_unique<GRootTree>(event_header, log);
44 }
45
46 return treePtr;
47}
48
49// Implementation summary:
50// Return the run-header tree, creating it on first use.
51const std::unique_ptr<GRootTree>& GstreamerRootFactory::getOrInstantiateHeaderTree(
52 [[maybe_unused]] const std::unique_ptr<GRunHeader>& run_header) {
53 rootfile->cd();
54
55 if (!log) {
56 std::cerr << "FATAL: log is null in GstreamerRootFactory::getOrInstantiateHeaderTree" << std::endl;
57 std::terminate();
58 }
59
60 if (!run_header) {
62 "run header is null in GstreamerRootFactory::getOrInstantiateHeaderTree");
63 }
64
65 auto& treePtr = gRootTrees[gstreamer::root::RUNHEADERTREENAME];
66 if (!treePtr) {
67 log->info(2, "GstreamerRootFactory", "Creating ROOT", gstreamer::root::RUNHEADERTREENAME, " tree");
68 treePtr = std::make_unique<GRootTree>(run_header, log);
69 }
70
71 return treePtr;
72}
73
74// Implementation summary:
75// Return the true-information detector tree, creating it lazily from the first sample hit.
76const std::unique_ptr<GRootTree>& GstreamerRootFactory::getOrInstantiateTrueInfoDataTree(
77 const std::string& detectorName,
78 const GTrueInfoData* gdata) {
79 rootfile->cd();
80 std::string treeName = gstreamer::root::TRUEINFONAMEPREFIX + detectorName;
81
82 auto& treePtr = gRootTrees[treeName];
83 if (!treePtr) {
84 log->info(2, "GstreamerRootFactory", "Creating GTrueInfoData ROOT tree for ", detectorName);
85 treePtr = std::make_unique<GRootTree>(treeName, gdata, log);
86 }
87
88 return treePtr;
89}
90
91// Implementation summary:
92// Return the digitized detector tree, creating it lazily from the first sample hit.
93const std::unique_ptr<GRootTree>& GstreamerRootFactory::getOrInstantiateDigitizedDataTree(
94 const std::string& detectorName,
95 const GDigitizedData* gdata) {
96 rootfile->cd();
97 std::string treeName = gstreamer::root::DIGITIZEDNAMEPREFIX + detectorName;
98
99 auto& treePtr = gRootTrees[treeName];
100 if (!treePtr) {
101 log->info(2, "GstreamerRootFactory", "Creating GDigitizedData ROOT tree for ", detectorName);
102 treePtr = std::make_unique<GRootTree>(treeName, gdata, log);
103 }
104
105 return treePtr;
106}
107
108const std::unique_ptr<GRootTree>& GstreamerRootFactory::getOrInstantiateGeneratedParticleTree(
109 const std::string& treeName,
110 const GGeneratedParticleBank& particles) {
111 rootfile->cd();
112 auto& treePtr = gRootTrees[treeName];
113 if (!treePtr) {
114 log->info(2, "GstreamerRootFactory", "Creating generated-particle ROOT tree for ", treeName);
115 treePtr = std::make_unique<GRootTree>(treeName, particles, log);
116 }
117
118 return treePtr;
119}
120
121const std::unique_ptr<GRootTree>& GstreamerRootFactory::getOrInstantiateAncestorTree(
122 const GAncestorBank& ancestors) {
123 rootfile->cd();
124 auto& tree_ptr = gRootTrees[gstreamer::root::ANCESTORTREENAME];
125 if (!tree_ptr) {
126 log->info(2, "GstreamerRootFactory", "Creating ancestor ROOT tree");
127 tree_ptr = std::make_unique<GRootTree>(ancestors, log);
128 }
129 return tree_ptr;
130}
131
132
133// Implementation summary:
134// Export the factory symbol required by the plugin loader.
135extern "C" GStreamer* GStreamerFactory(const std::shared_ptr<GOptions>& g) {
136 return static_cast<GStreamer*>(new GstreamerRootFactory(g));
137}
std::shared_ptr< GLogger > log
Abstract base class for all gstreamer output plugins.
Definition gstreamer.h:78
ROOT plugin writing event and run content into TTree objects stored in one TFile.
std::vector< GAncestorData > GAncestorBank
std::vector< GGeneratedParticleData > GGeneratedParticleBank
ROOT tree adapter used internally by the ROOT gstreamer plugin.
GStreamer * GStreamerFactory(const std::shared_ptr< GOptions > &g)
ROOT streamer plugin declarations.
constexpr char TRUEINFONAMEPREFIX[]
Definition gRootTree.h:17
constexpr char RUNHEADERTREENAME[]
Definition gRootTree.h:16
constexpr char EVENTHEADERTREENAME[]
Definition gRootTree.h:15
constexpr char ANCESTORTREENAME[]
Definition gRootTree.h:20
constexpr char DIGITIZEDNAMEPREFIX[]
Definition gRootTree.h:18
constexpr int ERR_PUBLISH_ERROR
Publish sequence encountered invalid state or invalid input data.