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();
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”.
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
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?
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;
}
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 …