Compiling App using Trees


I’m writing a program and I want to use Root to create a Tree.

I made a class called EventData and I want to store Objects of EventData in an Branch. In the documentation (page 196) is an example how to do this. The problem is, that every example I found handling branches with the C++ interpreter, but I want to compile my programm with gcc and run it.

So the first question is, if this is generally possible, to use branches holding user defind objects in compiled projects?

I create my Branch like this:

[code]//create a new ROOT Tree
TTree* tree = new TTree(“T”, “test input”);

EventData* event = new EventData();

tree->Branch("Event Info", "EventData", &event, 32000, 0);[/code]

The Message I got is:
Error in TTree::Bronch: Cannot find class:EventData

The implementation of EventData is compiled into a shared library and linked successfully. I read something about dictionary but every example is for using CINT, what I don’t want.

I hope someone can give me any basic informations what I have to do or what I have to search for, to find a solution.

Thanks a lot and have a nice day.


PS: First I create the topic in a wrong forum [url]Compiling App with Trees The old one can be delete, sorry for that!


You are missing the dictionary for EventData, see the FAQ on how to generate a dictionary or the User’s Guide.


Hi Philippe

Thanks a lot for the dictionary hint. With this it works fine.

I summary the steps, maybe it helps other users:

First I built my Dictionary, explained in


#ifndef EVENT_H_
#define EVENT_H_

#include “TObject.h”

class Event: public TObject {
int data;
void print( void );

 ClassDef(Event, 1);



#include “Event.h”

void Event::print() {
std::cout << "Class output: " << data << std::endl;


#ifdef CINT

#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ nestedclasses;

#pragma link C++ class Event;

I compiled this to, using:

rootcint -f EventDict.cpp -c Event.h Event_LinkDef.h
g++ -shared -o root-config --ldflags -O2 -g -Wall -fmessage-length=0 EventDict.cpp

Now I can use my class Event in a TTree. For example, reading a Tree:

TFile* fileout = new TFile(“test.root”, “OPEN”);
TTree* treeout = (TTree*)fileout->Get(“T”);
Event* event = 0;

treeout->SetBranchAddress("EventInfo", &event);

int i = 0;
int n = treeout->GetEntries();

cout << "Number of entires: " << n << endl;

for(i = 0; i < n; i++) {
	cout << event->data << endl;

delete treeout;
delete fileout;[/code]

Don’t forget to link

Have a nice day, I will have it :slight_smile: