Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
tree131_clones_event.C File Reference

Detailed Description

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:

#ifndef CLONESA_EVENT_SECOND_RUN
{
std::string s1(__FILE__);
TString dir = gSystem->UnixPathName(s1.substr(0, s1.find_last_of("\\/")).c_str());
gROOT->ProcessLine(TString(".L ") + dir + "/clones_event.cxx+");
#define CLONESA_EVENT_SECOND_RUN yes
gROOT->ProcessLine("#include \"" __FILE__ "\"");
gROOT->ProcessLine("tree131_clones_event(true)");
}
#else
{
// protect against old ROOT versions
if ( gROOT->GetVersionInt() < 30503 ) {
std::cout << "Works only with ROOT version >= 3.05/03" << std::endl;
return;
}
if ( gROOT->GetVersionDate() < 20030406 ) {
std::cout << "Works only with ROOT CVS version after 5. 4. 2003" << std::endl;
return;
}
// write a Tree
auto hfile = TFile::Open("clones_event.root", "RECREATE", "Test TClonesArray");
auto TTree("clones_event", "An example of a ROOT tree");
auto event1 = new TUsrSevtData1();
auto event2 = new TUsrSevtData2();
event1, 8000, 99);
event2, 8000, 99);
for (Int_t ev = 0; ev < 10; ev++) {
std::cout << "event " << ev << std::endl;
event1->SetEvent(ev);
event2->SetEvent(ev);
tree->Fill();
if (ev <3)
ev);
}
tree->Write();
tree->Print();
delete hfile;
}
{
//read the Tree
auto hfile = TFile::Open("clones_event.root");
auto TTree>("clones_event");
event1);
event2);
for (Int_t ev = 0; ev < 8; ev++) {
ev);
std::cout << "Pileup event1: " << event1->GetPileup() << std::endl;
std::cout << "Pileup event2: " << event2->GetPileup() << std::endl;
event1->Clear();
event2->Clear();
// gObjectTable->Print(); // detect possible memory leaks
}
delete hfile;
}
void tree131_clones_event(bool /*secondrun*/)
{
// Embedding this load inside the first run of the script is not yet
// supported in v6
// gROOT->ProcessLine(".L clones_event.cxx+"); // compile shared lib
write_clones_event(); // write the tree
read_clones_event(); // read back the tree
}
#endif
#define s1(x)
Definition RSha256.hxx:91
int Int_t
Definition RtypesCore.h:45
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define gROOT
Definition TROOT.h:414
R__EXTERN TSystem * gSystem
Definition TSystem.h:572
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
Definition TFile.cxx:4131
Basic string class.
Definition TString.h:139
virtual const char * UnixPathName(const char *unixpathname)
Convert from a local pathname to a Unix pathname.
Definition TSystem.cxx:1075
A TTree represents a columnar dataset.
Definition TTree.h:84
Author
The ROOT Team

Definition in file tree131_clones_event.C.