Hi experts,
I use a compiled class, import it into ROOT, and try to branch from it. The dictionary generation goes just fine, and no errors anywhere. And I can instantiate the class with no problem. But when I try to branch from its, the class cannot be found. I get the error:
Error in TTree::Bronch: Cannot find class:myClass
What am I missing to make ROOT aware of my class?
Here is my header file:
ifndef ROOT_myClass
#define ROOT_myClass
#include <TClassTable.h>
#include <map>
#include "TObject.h"
#include "TSystem.h"
#include "TROOT.h"
#include "TPluginManager.h"
#include "TInterpreter.h"
class TDirectory;
class myClass : public TObject {
public :
Float_t energy;
Float_t time;
Float_t xpos;
Float_t ypos;
myClass();
virtual ~myClass();
void init(Option_t *option ="");
ClassDef(myClass,1);
};
#endif
And here is the c++ code:
#include <stdio.h>
#include <cstdlib>
#include <iostream>
#include "myClass.h"
#include "TSystem.h"
#include "TROOT.h"
#include "TPluginManager.h"
#include "TInterpreter.h"
using namespace std;
ClassImp(myClass);
myClass::myClass(){
cout << "Class instance created" << "\n";
}
myClass::~myClass(){
cout << "Class instance destroyed" << "\n";
}
void myClass::init(Option_t * /*option*/) {
}
The LinkDef file is trivial
#ifdef __CINT__
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ class myClass+;
#endif
Here is the executable code
#include "TTree.h"
#include "myClass.h"
int main(){
//make a tree
TTree t4("t4","A Tree with Events");
// create a pointer to myClass object
myClass *aEvent = new myClass();
t4.Branch("event_branch", "myClass", &aEvent,16000,2);
return 0;
}
And here is the makefile[code]
#-----------configure ROOT-----------#
ifdef ROOTSYS
include $(ROOTSYS)/etc/Makefile.arch
ROOTINC :=$(shell $(ROOTSYS)/bin/root-config --incdir)
ROOTLIBDIR :=$(shell $(ROOTSYS)/bin/root-config --libdir)
ROOTLDFLAGS :=$(shell $(ROOTSYS)/bin/root-config --ldflags)
ROOTCFLAGS :=$(shell $(ROOTSYS)/bin/root-config --cflags)
ROOTLIBS := $(shell $(ROOTSYS)/bin/root-config --libs)
ROOTLINK = $(ROOTLIBS) $(ROOTCFLAGS) $(ROOTLDFLAGS) -I$(ROOTINC)
else
@echo "NO ROOTSYS!"
endif
#--------configure compiler----------#
CXX = g++
CFLAGS = $(ROOTLINK)
CFLAGS += -O2 -Wall -Wno-write-strings
LIBS = -lm -lz -lutil -lnsl -lpthread
.SUFFIXES: .$(SrcSuf) .$(ObjSuf) .$(DllSuf)
#----------configure the Event class-----------#
EVENTO = myClass.$(ObjSuf) EventDict.$(ObjSuf)
EVENTS = myClass.$(SrcSuf) EventDict.$(SrcSuf)
EVENTSO = myClass.$(DllSuf)
EVENT = myClass$(ExeSuf)
EVENTLIB = $(shell pwd)/$(EVENTSO)
#MAINEVENTO = MainEvent.$(ObjSuf)
#MAINEVENTS = MainEvent.$(SrcSuf)
PROGRAMS= myApp
#--------object declaration----------#
OBJECTS := $(EVENTO)
#OBJECTS += $(MAINEVENTO)
SHAREDOBJECTS = $(EVENTSO)
default: all
all: $(PROGRAMS)
$(EVENTSO): $(EVENTO)
@echo “compiling $@”
$(LD) $(SOFLAGS) $(LDFLAGS) $^ $(OutPutOpt) $@ $(EXPLLINKLIBS)
@echo “$@ done”
@echo “----------------------------------”
$(EVENT): $(EVENTSO)
@echo “compiling $@”
$(LD) $(ROOTLINK) $(LDFLAGS) $(EVENTO) $(LIBS) $(OutPutOpt) $@ $(MT_EXE)
$(MT_EXE)
@echo “$@ done”
@echo “----------------------------------”
analyzerEvent.$(ObjSuf): myClass.h
EventDict.$(SrcSuf): myClass.h LinkDef.h
@echo “Generating dictionary $@…”
@rootcint -f $@ -c $^
@echo “$@ done”
@echo “-------------------------------”
.$(SrcSuf).$(ObjSuf):
@echo “Compiling $@”
$(CXX) $(CFLAGS) -c $<
@echo “-----------------------------------------------------”
myApp: myApp.cxx $(OBJECTS) $(SHAREDOBJECTS)
@echo “Comiling myApp”
$(CXX) $(CFLAGS) -o myApp myApp.cxx $(OBJECTS) $(SHAREDOBJECTS)
@echo “-----------------------------------------------------”
clean::
rm -f *.o ~ #
@rm -f $(OBJECTS) core
@rm -f $(SHAREDOBJECTS) core
rm -f $(PROGRAMS)
[/code]