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