Compiling App using Trees

Hi

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 libEventData.so 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.

Tobias

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

Hi,

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

Philippe.

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 http://root.cern.ch/drupal/faq#n676.

Event.h

[code]
#ifndef EVENT_H_
#define EVENT_H_

#include “TObject.h”

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

 ClassDef(Event, 1);

};[/code]

Event.cpp

[code]#include
#include “Event.h”

void Event::print() {
std::cout << "Class output: " << data << std::endl;
}[/code]

Event_LinkDef.h:

[code]
#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;
#endif[/code]

I compiled this to libEvent.so, using:

rootcint -f EventDict.cpp -c Event.h Event_LinkDef.h
g++ -shared -o libEvent.so 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:

[code]
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++) {
	treeout->GetEntry(i);
	cout << event->data << endl;
	event->print();
}

delete treeout;
delete fileout;[/code]

Don’t forget to link libEvent.so.

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

Tobias