Root6 tree branch with class

I am trying to create a very simple tree with root 6.05.02. I can get it to work under rootcling interpreter, i can compile the code to a so lib and load it in rootcling and run test(), it is fine. but with a standalone executable it core dumps.

Here’s the class def:

[code]//// header
#include <TObject.h>
class AVP : public TObject {
ClassDef(AVP, 1);
virtual ~AVP() {
int v = 0;
double p = 0;
void test();

//// source
#include "header.h"
void test() {
TTree* tree = new TTree(“Tree”, “Tree”);
AVP* buffer = new AVP;
const char* cn = buffer->Class_Name(); // this is fine.
// const char* cn = buffer->ClassName(); // this causes core dump. it works for root5. why?
tree->Branch(“VP”, &buffer); // this line causes core dump!!!

int main() {

the error msgs has lots of clang::CodeGen::CodeGenTypes related things. any idea what’s wrong?



the reason for this crash is that you do not have dictionaries available for AVP. In the ACliC case, you do: when running a macro with commands like .x myMacro.C+ or .L myMacro.C+, dictionaries are always generated, not only shared libraries.
If you want to generate dictionaries for the AVP class, you could use the genreflex program with a command like:

genreflex AVP.h -s selection.xml --rootmap libavp.rootmap --rootmap-lib
g++ -o -shared -fPIC AVP_dictrflx.cxx `root-config --cflags --libs`

where the selection.xml is

<class name = "AVP" />

You will end up with a library which is equivalent to the one you created with ACLiC.
A last point: you use the ClassImp macro: unless you want to produce documentation with THtml, this macro is not needed (ClassDef is on the other hand crucial :slight_smile: )



thx for the reply and the tip on the ClassImp.

i remember genreflex is not recommended? Anyway, i do have dictionary files. i generate it with rootcling

here’s the link def file i have:

//// LinkDef.h #if defined(__CLING__) || defined(__CINT__) #pragma link C++ defined_in AVP.hpp ; #endif

below is how i generate the dictionary and compile it:

rootcling -v -f LinkDef.cpp -c -p AVP.h LinkDef.h g++ -c -o LinkDef.o LinkDef.cpp `root-config --cflags --libs`

I can either create the shared lib or executable as long as i link against the LinkDef.o. If i don’t link with the LinkDef.o there will be missing symbols for dictionary. The problem is I can gSystem->Load the so file and add branch to tree and fill and save/read tree w/o issue, but i can’t do it with the executable, it will just core dump when adding branch and return those error msgs. I placed the source/header/LinkDef/dictionary/pcm/so/executable… all in the same directory just in case it’s because of the missing pcm, or header, or other things. I do have a ROOT_INCLUDE env variable that doesn’t contains the directory where i put all those test codes in but that shouldn’t matter, right?

I did try to use the genreflex to generate the dictionary and compile the . The only “real” difference I see is this line:

genreflex has it, rootcling doesn’t.

// Function generating the singleton type initializer static TGenericClassInfo *GenerateInitInstanceLocal(const ::AVP*) { ::AVP *ptr = 0; static ::TVirtualIsAProxy* isa_proxy = new ::TInstrumentedIsAProxy< ::AVP >(0); static ::ROOT::TGenericClassInfo instance("AVP", ::AVP::Class_Version(), "invalid", 26, typeid(::AVP), ::ROOT::Internal::DefineBehavior(ptr, ptr), &::AVP::Dictionary, isa_proxy, 16, sizeof(::AVP) ); instance.SetNew(&new_AVP); instance.SetNewArray(&newArray_AVP); instance.SetDelete(&delete_AVP); instance.SetDeleteArray(&deleteArray_AVP); instance.SetDestructor(&destruct_AVP); instance.SetStreamerFunc(&streamer_AVP); return &instance; }

is genreflex is really needed? it wasn’t for root5…

ok found out the cause of the coredump. it’s the google c++ unit test lib. if I remove link against libCppUTest.a then the executable is fine in both root 5 and root 6. If i add that lib, root 5 is fine, root6 will cause core dump with the adding branch to tree line. weird. maybe llvm/clang is not handling static lib well?

the so lib doesn’t have that linkage, so that’s why it works under root6.

anyway we can mark this as resolved now i guess. the genreflex is not really need. just use rootcling/rootcint to generate the dictionary file is good enough.



Great to see that this is solved.
Just a remark about genreflex in root6. Gernreflex and rootcling are a faade to the same dictionary generation engine. The choice is a matter of taste or amount of already existing code, like in the case of some Lhc experiments.
If you also want to get rid to the anual loading of libraries, hou can use rootmap files. You find all the details about their generation typing rootcling -h or genreflex -h.