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 rootfile->cd();
78 std::string treeName = TRUEINFONAMEPREFIX + detectorName;
79
80 auto& treePtr = gRootTrees[treeName];
81 if (!treePtr) {
82 log->info(2, "GstreamerRootFactory", "Creating GTrueInfoData ROOT tree for ", detectorName);
83 treePtr = std::make_unique<GRootTree>(treeName, gdata, log);
84 }
85
86 return treePtr;
87}
88
89// Implementation summary:
90// Return the digitized detector tree, creating it lazily from the first sample hit.
91const std::unique_ptr<GRootTree>& GstreamerRootFactory::getOrInstantiateDigitizedDataTree(
92 const std::string& detectorName,
93 const GDigitizedData* gdata) {
94 rootfile->cd();
95 std::string treeName = DIGITIZEDNAMEPREFIX + detectorName;
96
97 auto& treePtr = gRootTrees[treeName];
98 if (!treePtr) {
99 log->info(2, "GstreamerRootFactory", "Creating GDigitizedData ROOT tree for ", detectorName);
100 treePtr = std::make_unique<GRootTree>(treeName, gdata, log);
101 }
102
103 return treePtr;
104}
105
106const std::unique_ptr<GRootTree>& GstreamerRootFactory::getOrInstantiateGeneratedParticleTree(
107 const std::string& treeName,
108 const GGeneratedParticleBank& particles) {
109 rootfile->cd();
110 auto& treePtr = gRootTrees[treeName];
111 if (!treePtr) {
112 log->info(2, "GstreamerRootFactory", "Creating generated-particle ROOT tree for ", treeName);
113 treePtr = std::make_unique<GRootTree>(treeName, particles, log);
114 }
115
116 return treePtr;
117}
118
119const std::unique_ptr<GRootTree>& GstreamerRootFactory::getOrInstantiateAncestorTree(
120 const GAncestorBank& ancestors) {
121 rootfile->cd();
122 auto& tree_ptr = gRootTrees[ANCESTORTREENAME];
123 if (!tree_ptr) {
124 log->info(2, "GstreamerRootFactory", "Creating ancestor ROOT tree");
125 tree_ptr = std::make_unique<GRootTree>(ancestors, log);
126 }
127 return tree_ptr;
128}
129
130
131// Implementation summary:
132// Export the factory symbol required by the plugin loader.
133extern "C" GStreamer* GStreamerFactory(const std::shared_ptr<GOptions>& g) {
134 return static_cast<GStreamer*>(new GstreamerRootFactory(g));
135}
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: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.
#define EVENTHEADERTREENAME
Definition gRootTree.h:14
#define RUNHEADERTREENAME
Definition gRootTree.h:15
#define DIGITIZEDNAMEPREFIX
Definition gRootTree.h:17
#define ANCESTORTREENAME
Definition gRootTree.h:19
#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.