Working through the example in this wiki page, the plugins works with hd_root as advertised. If a ROOT class is declared in the header file outside the class definition, as a file-scope static variable, things are fine. If declared as a class member variable, at run time, the reference to the ROOT library cannot be resolved.
An illustration is the pi0_pol plugin. The error is:
hd_root -PJANA:BATCH_MODE=1 -PPLUGINS=monitoring_hists,danarest,pi0_pol_plugin hdgeant_smeared.hddm
JANA >>OUTPUT_FILENAME: hd_root.root
JANA >>Initializing plugin "/data/gluex/gluex_top/halld_recon/halld_recon-4.31.1/Linux_Fedora35-x86_64-gcc11.2.1/plugins/monitoring_hists.so" ...
JANA >>Initializing plugin "/data/gluex/gluex_top/halld_recon/halld_recon-4.31.1/Linux_Fedora35-x86_64-gcc11.2.1/plugins/danarest.so" ...
JANA ERROR>>
JANA ERROR>>***ERROR : Couldn't find plugin "pi0_pol_plugin"!***
JANA ERROR>>*** make sure the JANA_PLUGIN_PATH environment variable is set correctly.
JANA ERROR>>*** To see paths checked, set PRINT_PLUGIN_PATHS config. parameter
make: *** [/home/marki/git/pi0_pol/Makefile:24: hd_root.root] Error 255
Here is the diff between non-working and working versions:
[marki@markdesk5 pi0_pol_plugin]$ diff -u JEventProcessor_pi0_pol_plugin.h.does_not_work JEventProcessor_pi0_pol_plugin.h.works
--- JEventProcessor_pi0_pol_plugin.h.does_not_work 2022-02-03 16:10:20.392147774 -0500
+++ JEventProcessor_pi0_pol_plugin.h.works 2022-02-03 16:06:24.421874896 -0500
@@ -12,6 +12,9 @@
#include <TFile.h>
#include <TH1F.h>
+static TFile* mFile;
+static TH1F* mH1;
+
class JEventProcessor_pi0_pol_plugin:public jana::JEventProcessor{
public:
JEventProcessor_pi0_pol_plugin();
@@ -19,8 +22,6 @@
const char* className(void){return "JEventProcessor_pi0_pol_plugin";}
private:
- static TFile* mFile;
- static TH1F* mH1;
jerror_t init(void); ///< Called once at program start.
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber); ///< Called everytime a new run number is detected.
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber); ///< Called every event.
If the -PPRINT_PLUGIN_PATHS=1 switch is thrown the output contains:
JANA >>Looking for "/home/marki/halld_my/Linux_Fedora35-x86_64-gcc11.2.1/plugins/pi0_pol_plugin.so" ....found.
JANA ERROR>>/home/marki/halld_my/Linux_Fedora35-x86_64-gcc11.2.1/plugins/pi0_pol_plugin.so: undefined symbol: _ZN30JEventProcessor_pi0_pol_plugin5mFileE
Note that ROOT is in the LD_LIBRARY_PATH:
[marki@markdesk5 pprun]$ showpath.pl -l | grep -i root
/data/gluex/gluex_top/gluex_root_analysis/gluex_root_analysis-1.20.0^hdr4311/Linux_Fedora35-x86_64-gcc11.2.1/lib
/data/gluex/gluex_top/root/root-6.24.04/lib