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// Non-Doxygen implementation file: behavior is documented in the header.
9
10// enable root thread safety in a static call that
11// runs before control returns from dlopen() as soon as libGstreamerRootFactory.so is loaded.
12namespace {
13struct EnableRootTS
14{
15 EnableRootTS() {
16 ROOT::EnableThreadSafety();
17 std::cout << "GstreamerRootFactory: ROOT thread safety enabled" << std::endl;
18 }
19};
20
21static EnableRootTS _enableROOTLocks; // global object, static storage duration.
22} // unnamed namespace
23
24// Return the header tree pointer from the map. If it's not there, initialize the smart pointer.
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 // If the key does not exist, this inserts a new entry with a default value
39 // and returns a reference to it.
40 auto& treePtr = gRootTrees[HEADERTREENAME];
41 if (!treePtr) {
42 log->info(2, "GstreamerRootFactory", "Creating ROOT", HEADERTREENAME, " tree");
43 treePtr = std::make_unique<GRootTree>(event_header, log); // add the new tree to the map
44 }
45
46 return treePtr;
47}
48
49// gdata passed here is guaranteed not a nullptr
50const std::unique_ptr<GRootTree>& GstreamerRootFactory::getOrInstantiateTrueInfoDataTree(
51 const std::string& detectorName,
52 const GTrueInfoData* gdata) {
53 std::string treeName = TRUEINFONAMEPREFIX + detectorName;
54
55 auto& treePtr = gRootTrees[treeName];
56 if (!treePtr) {
57 log->info(2, "GstreamerRootFactory", "Creating GTrueInfoData ROOT tree for ", detectorName);
58 treePtr = std::make_unique<GRootTree>(treeName, gdata, log); // add the new tree to the map
59 }
60
61 return treePtr;
62}
63
64// gdata passed here is guaranteed not a nullptr
65const std::unique_ptr<GRootTree>& GstreamerRootFactory::getOrInstantiateDigitizedDataTree(
66 const std::string& detectorName,
67 const GDigitizedData* gdata) {
68 std::string treeName = DIGITIZEDNAMEPREFIX + detectorName;
69
70 auto& treePtr = gRootTrees[treeName];
71 if (!treePtr) {
72 log->info(2, "GstreamerRootFactory", "Creating GDigitizedData ROOT tree for ", detectorName);
73 treePtr = std::make_unique<GRootTree>(treeName, gdata, log); // add the new tree to the map
74 }
75
76 return treePtr;
77}
78
79
80// tells the DLL how to create a GStreamerFactory in each plugin .so/.dylib
81extern "C" GStreamer* GStreamerFactory(const std::shared_ptr<GOptions>& g) {
82 return static_cast<GStreamer*>(new GstreamerRootFactory(g));
83}
std::shared_ptr< GLogger > log
void info(int level, Args &&... args) const
void error(int exit_code, Args &&... args) const
Abstract base class for streaming GEMC event or frame data to output media.
Definition gstreamer.h:66
ROOT output gstreamer plugin writing event data into TTrees.
ROOT tree adapter used by the ROOT gstreamer plugin.
#define DIGITIZEDNAMEPREFIX
Definition gRootTree.h:17
#define HEADERTREENAME
Definition gRootTree.h:15
#define TRUEINFONAMEPREFIX
Definition gRootTree.h:16
#define ERR_PUBLISH_ERROR
Generic publish-time error (null pointers, invalid state).
GStreamer * GStreamerFactory(const std::shared_ptr< GOptions > &g)