Branch cannot find class in Geant4

Dear ROOT Experts,

I want to save a class named “PrimaryHits” in a Geant4 application.

In the run action class (named “MuRunAction.cc”), I create a branch as below:

phit = new PrimaryHits;
tree->Branch("event", "PrimaryHits", &phit);

The source file (“PrimaryHits.cc”) is placed in /src directory, and the header file and LinkDef file is placed in /include directory.

I generated libPrimaryHits.so in the /include directory with these commands:

`root-config --cxx --cflags` -fPIC -c ../src/PrimaryHits.cc
rootcint -f PrimaryHitsDict.cc -c -p PrimaryHits.hh LinkDef.hh
`root-config --cxx --cflags` -fPIC -c PrimaryHitsDict.cc
`root-config --cxx --cflags` -fPIC -shared -o libPrimaryHits.so PrimaryHits.o PrimaryHitsDict.o

Then i copied the generated libPrimaryHits.so and pcm file in directory /lib

I linked the libPrimaryHits.so in the cmake file with the command:

include_directories("/home/cihenp/g4proj/MuImag/include")
set(PrimaryHits_LIBRARIES "/home/cihenp/g4proj/MuImag/lib/libPrimaryHits.so")
target_link_libraries(MuImag ${PrimaryHits_LIBRARIES})

The Geant4 application compiles well, but when i execute it, an error occurs saying that:
Error in TTree::Bronch: Cannot find class:PrimaryHits

Does it mean the library has been loaded but the reflection process is not successful?
Is there anything wrong with the steps above?

Best,
Zhi Yu

Hi Zhi Yu,

I assume you are using ROOT6, if you are not, I encourage you to move to ROOT6.
Your procedure is correct. You just need to generate a rootmap file and put it next to libPrimaryHits.so in order to allow ROOT to autoload the class and its dictionary at runtime. To see how to generate the rootmap with the rootcint invocation, just type

rootcint -h

In a nutshell, your command should become

rootcint -f PrimaryHitsDict.cc -rmf libPrimaryHits.rootmap -rml libPrimaryHits.so -c -p PrimaryHits.hh LinkDef.hh

Cheers,
D

Hi dpiparo,

Yes, I am using ROOT6 and the problem has been solved thanks to your reply.:smiley:

Cheers,
Zhi Yu

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.