Example to write & read a Tree built with a complex class inheritance tree.
It demonstrates usage of inheritance and TClonesArrays This is simplified / stripped extract of an event structure which was used within the Marabou project.
To run this example, do:
root > .x clonesA_Event.C
#ifndef CLONESA_EVENT_SECOND_RUN
void clonesA_Event() {
gROOT->ProcessLine(
TString(
".L ")+dir+
"/clonesA_Event.cxx+");
#define CLONESA_EVENT_SECOND_RUN yes
gROOT->ProcessLine(
"#include \"" __FILE__
"\"");
gROOT->ProcessLine(
"clonesA_Event(true)");
}
#else
void clonesA_Event_w()
{
if (
gROOT->GetVersionInt() < 30503 ) {
cout << "Works only with ROOT version >= 3.05/03" << endl;
return;
}
if (
gROOT->GetVersionDate() < 20030406 ) {
cout << "Works only with ROOT CVS version after 5. 4. 2003" << endl;
return;
}
TFile *hfile =
new TFile(
"clonesA_Event.root",
"RECREATE",
"Test TClonesArray");
TTree *tree =
new TTree(
"clonesA_Event",
"An example of a ROOT tree");
tree->
Branch(
"top1",
"TUsrSevtData1",&event1,8000,99);
tree->
Branch(
"top2",
"TUsrSevtData2",&event2,8000,99);
for (
Int_t ev = 0; ev < 10; ev++) {
cout << "event " << ev << endl;
if (ev <3) tree->
Show(ev);
}
delete hfile;
}
void clonesA_Event_r()
{
for (
Int_t ev = 0; ev < 8; ev++) {
cout <<
"Pileup event1: " << event1->
GetPileup() << endl;
cout <<
"Pileup event2: " << event2->
GetPileup() << endl;
}
delete hfile;
}
void clonesA_Event(bool ) {
clonesA_Event_w();
clonesA_Event_r();
}
#endif
- Author
- The ROOT Team
Definition in file clonesA_Event.C.