How to store my class into TTree?

[size=100]I want to store my class objects into a TTree. The simplifed example is the attachment try.cpp. And the Makefile is also attached. I can compile without error, but whenever I run the program I have errors as following:
Error in TTree::Bronch: Cannot find class:LEP
Error in TTree::Bronch: Cannot find class:LEP

What is Bronch? And how can I solve the problem? Thank you very much!

My Makefile is:
CC = /usr/bin/g++
cc = /usr/bin/gcc

ROOTSYS = /usr/local/root
ROOTINC = (ROOTSYS)/include ROOTLIB = (ROOTSYS)/lib
ROOTCFLAGS := (shell root-config --cflags) ROOTLIBS := (shell root-config --libs)
ROOTGLIBS := (shell root-config --glibs) HASTHREAD := (shell root-config --has-thread)

LIBS = (ROOTLIBS) (SYSLIBS)
GLIBS = (ROOTGLIBS) (SYSLIBS)

try: try.o
{CC} -o try try.o {LIBS}

try.o: try.cpp
(CC) -I(ROOTINC) -c try.cpp[/size][/size]
try.cpp (1.02 KB)

Hi,

you are missing the dictionary. Instead of all this complicated setup, just load your code into a ROOT session. Rename main() to try(), and run “.x try.cpp+” and it will just work. No Makefile, no need for you to create a dictionary by hand.

Your code is not valid, by the way; you cannot call LEP *leps1 = new LEP(); LEP *leps2 = new LEP();Instead, initialize them to 0 and create the objects when you set up the branches, or create a class that contains them (and wheel) as members, and put their initialization into the constructor.

Cheers, Axel.

Hi,

Thank you very much, Alex.

But I have to compile them because I have a lot of data to handle. Interpretation in Cint is too slow for me to handle those data. I tried both Cint and compilation, and I think compilation is at least 10 times faster than interpretation. Could you please teach me how to add the dictionaries into the compilation? Thank you very much!

Best,
Jing

I read the other’s posts about how to add the user’s own classes. So now I changed my program into the following ones:

LEP.h

#include “Rtypes.h”
#include “TTree.h”
#include “TBranch.h”
#include “TROOT.h”
#include “TObjArray.h”
#include “TObject.h”
#include “TKey.h”
#include “TSystem.h”
#include “TMapFile.h”

#ifndef LEP
#define LEP

class LEP
{

private:
UShort_t rawE;
static double lelf_co[2][3];

public:
LEP():rawE(0){};
~LEP(){};
void writeE(UShort_t data1);
void reset();
//ClassDef(LEP, 1);

};

#endif

LEP.cpp

#include
#include
#include “LEP.h”

//methods for LEP
Double_t LEP::lelf_co[2][3];

void LEP::writeE(UShort_t data1)
{
rawE = data1;
}

void LEP::reset()
{
rawE = 0;
}


doit.cpp

#include “LEP.h”
//#include “CLOVER.h”

LEP *leps1 = new LEP();
UShort_t wheel;

void tree_init(TTree * );

int main ()
{
TTree *data;
data = new TTree(“data”, “data”);
tree_init(data);
cout<<“OK”<<endl;
return 0;
}

void tree_init(TTree* data)
{

data->Branch ("leps1", "LEP", &leps1);
data->Branch ("wheel", &wheel, "wheel/s");

}

And I used the following commands to compile them:
rootcint -f trydict.cpp -c LEP.h+
g++ -g root-config --cflags -c trydict.cpp LEP.cpp
g++ -g -Wl,-soname,LEP.so -shared trydict.o LEP.o -o LEP.so
g++ -o doit doit.cpp root-config --cflags --libs LEP.so

Then I can compile them without errors. And I also got the executable doit. However, when I execute doit, I got the following errors:

doit: error while loading shared libraries: LEP.so: cannot restore segment prot after reloc: Permission denied

What did I do wrong? Thank you very much!

Hi,

“.x try.cpp+” compiles your code. Look for “ACLIC” in the Users guide. There is no difference between code compiled by a Makefile and code compiled by ACLIC (i.e. adding a “+” at the end). Only ACLIC is a lot simpler to use.

The error you get reminds me of a problem with selinux; you should check google and post your solution.

Cheers, Axel.