Unknown type name Event

Hi,

I tried to run copytree.C but i got an error “unknown type name Event” : Event *event = new Event;

[code]void copytree() {
// Example of Root macro to copy a subset of a Tree to a new Tree
// The input file has been generated by the program in $ROOTSYS/test/Event
// with Event 1000 1 1 1
//Author: Rene Brun

gSystem->Load("$ROOTSYS/test/libEvent.so");

//Get old file, old tree and set top branch address
TFile *oldfile = new TFile("$ROOTSYS/test/Event.root");
TTree oldtree = (TTree)oldfile->Get(“T”);
Event event = new Event();
oldtree->SetBranchAddress(“event”,&event);
oldtree->SetBranchStatus("
",0);
oldtree->SetBranchStatus(“event”,1);
oldtree->SetBranchStatus(“fNtrack”,1);
oldtree->SetBranchStatus(“fNseg”,1);
oldtree->SetBranchStatus(“fH”,1);

//Create a new file + a clone of old tree in new file
TFile *newfile = new TFile(“small.root”,“recreate”);
TTree *newtree = oldtree->CloneTree();

newtree->Print();
newfile->Write();
delete oldfile;
delete newfile;
}

[/code]

How does it fix ?

Cheers,
Ersel

Check that you really have two files:
${ROOTSYS}/test/libEvent.so
${ROOTSYS}/test/Event.root
and if not, then you need to run “make” in the “${ROOTSYS}/test” subdirectory and afterwards you need to execute there “./Event 1000 1 1 1”.

Ok,Done Thanks.

It didn’t has an execution permissions…

Cheers,
Ersel

Unfortunately I still have problem decribed in this post. "unknown type name ‘Event’ ". I havent had those two files (Event.root and libEvent.so both in …test directory) but I wrote “make” command in terminal in this directory and later “./Event 1000 1 1 1” as well in this directory. Now I have those files (and many others) but still root doesnt know Event type :confused:

The tutorial requires a rootmap file for libEvent (which exist in the same directory).

To make the script location agnostic, add the line

R__LOAD_LIBRARY($ROOTSYS/test/libEvent.so)

at the beginning of the script.

Cheers,
Philippe.

Hi, Pepe

I try to run this example,

I have the file :
/opt/root6/test/libEvent.so
/opt/root6/test/Event.root

void copytree3() {
   gSystem->Load("/opt/root6/test/libEvent");
   //Get old file, old tree and set top branch address
   TFile *oldfile;
   TString dir = "/opt/root6/test/Event.root";
   gSystem->ExpandPathName(dir);
   if (!gSystem->AccessPathName(dir))
       {oldfile = new TFile("/opt/root6/test/Event.root");}
   else {oldfile = new TFile("./Event.root");}
   TTree *oldtree = (TTree*)oldfile->Get("T");
   Event *event   = new Event();
   oldtree->SetBranchAddress("event",&event);
   oldtree->SetBranchStatus("*",0);
   oldtree->SetBranchStatus("event",1);
   oldtree->SetBranchStatus("fNtrack",1);
   oldtree->SetBranchStatus("fNseg",1);
   oldtree->SetBranchStatus("fH",1);
   //Create a new file + a clone of old tree in new file
   TFile *newfile = new TFile("small.root","recreate");
   TTree *newtree = oldtree->CloneTree();
   newtree->Print();
   newfile->Write();
   delete oldfile;
   delete newfile;
}

But, yet still not working…
error: unknown type name ‘Event’ Event *event = new Event();

the location (gSystem->Load("/opt/root6/test) is right?

thanks,
best regards
Andre

gSystem->Load("/opt/root6/test/libEvent.so");

Hi, Wile

Thanks for the answer, this help a lot!

After the created the file (LibEvent.so and Event.root) in the root/test

I run the macro copytree3.C

R__LOAD_LIBRARY(/opt/root6/test/libEvent.so)


void copytree3() {
   gSystem->Load("/opt/root6/test/libEvent.so");
   //Get old file, old tree and set top branch address
   TFile *oldfile;
   TString dir = "/opt/root6/test/Event.root";
   gSystem->ExpandPathName(dir);
   if (!gSystem->AccessPathName(dir))
       {oldfile = new TFile("/opt/root6/test/Event.root");}
   else {oldfile = new TFile("./Event.root");}
   TTree *oldtree = (TTree*)oldfile->Get("T");
   Event *event   = new Event();
   oldtree->SetBranchAddress("event",&event);
   oldtree->SetBranchStatus("*",0);
   oldtree->SetBranchStatus("event",1);
   oldtree->SetBranchStatus("fNtrack",1);
   oldtree->SetBranchStatus("fNseg",1);
   oldtree->SetBranchStatus("fH",1);
   //Create a new file + a clone of old tree in new file
   TFile *newfile = new TFile("small.root","recreate");
   TTree *newtree = oldtree->CloneTree();
   newtree->Print();
   newfile->Write();
   delete oldfile;
   delete newfile;
}

Now is working very well,

Cheers,
Andre.

Note: in ROOT 5 you need “gSystem->Load(…);”, while in ROOT 6 you need “R__LOAD_LIBRARY(…)”.

@axel @pcanal It seems to me that ROOT 6 tutorials which use “gSystem->Load(…);” need inspections.

Hi Wile,

Actually thanks to autoloading of library based on symbols/class names, most of the gSystem->Load are actually (now) redundant. So we indeed need to review each one of them to select whether to remove or replace …

Thanks,
Philippe.

I created https://sft.its.cern.ch/jira/browse/ROOT-8938 so we don’t forget.