How to write a TClonesArray to a TTree
The following tests can be run Interactive tests
Root > .x tree123_clonesarray.C
Root > .x tree123_clonesarray.C(1)
Root > .x tree123_clonesarray.C++
Root > .x tree123_clonesarray.C++(1)
Batch tests: same as above but with no graphics
root -b -q tree123_clonesarray.C
root -b -q tree123_clonesarray.C++
root -b -q "tree123_clonesarray.C(1)"
root -b -q "tree123_clonesarray.C++(1)"
void write_clonesarray(
Int_t split)
{
TFile f(
"clonesarray.root",
"recreate");
f.SetCompressionLevel(1);
TTree T(
"T",
"test clonesarray");
T.Branch("tcl", &arr, 256000, split);
for (
Int_t ev=0; ev<10000; ev++) {
if(nlines < 0)
nlines = 1;
for (
Int_t i=0;i<nlines;i++) {
new(ar[i])
TLine(x1, y1, x2, y2);
}
T.Fill();
}
T.Print();
T.Write();
}
void read_clonesarray()
{
auto f =
new TFile(
"clonesarray.root");
auto h2 =
new TH2F(
"h2",
"center of lines", 40, 0, 1, 40, 0, 1);
T->GetBranch(
"tcl")->SetAutoDelete(
kFALSE);
T->SetBranchAddress("tcl", &arr);
T->GetEntry(ev);
for (
Int_t i=0; i<nlines; i++) {
}
}
}
void tree123_clonesarray(
Int_t split = 0)
{
write_clonesarray(split);
read_clonesarray();
}
int Int_t
Signed integer 4 bytes (int).
long long Long64_t
Portable signed long integer 8 bytes.
float Float_t
Float 4 bytes (float).
externTBenchmark * gBenchmark
An array of clone (identical) objects.
void BypassStreamer(Bool_t bypass=kTRUE)
When the kBypassStreamer bit is set, the automatically generated Streamer can call directly TClass::W...
void Clear(Option_t *option="") override
Clear the clones array.
A file, usually with extension .root, that stores data and code in the form of serialized objects in ...
2-D histogram with a float per channel (see TH1 documentation)
Use the TLine constructor to create a simple line.
Int_t GetEntriesFast() const
TObject * At(Int_t idx) const override
A TTree represents a columnar dataset.
virtual Int_t Fill()
Fill all branches.
void Draw(Option_t *opt) override
Default Draw method for all objects.
- Author
- Rene Brun
Definition in file tree123_clonesarray.C.