Download presentation
Presentation is loading. Please wait.
1
Zooming on ROOT files and Containers
CMS-ROOT meeting CERN- December 5 René Brun ftp://root.cern.ch/root/ZoomFiles.ppt ZOOM on ROOT files & Containers
2
Keys in a TDirectory/TFile
tr Keys in a TDirectory/TFile Key in directory in memory Key on file record header Obj.Write(“key”) File Streamed data of obj CMS 5 Dec Rene Brun ZOOM on ROOT files & Containers
3
Memory <--> Tree The Tree entry serial number
T.GetEntry(6) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 T.Fill() 18 T CMS 5 Dec Rene Brun ZOOM on ROOT files & Containers
4
T.BuildIndex(“Run”,”Event”)
tr Entry number and Index T.BuildIndex(“Run”,”Event”) 1 2 3 Index(45,12) = 0 4 5 6 7 Index(45,78) = 8 8 9 10 11 12 Index(45,95) = 18 13 14 15 16 17 18 T.GetEntry(8) T.GetEntryWithIndex(45,78) T CMS 5 Dec Rene Brun ZOOM on ROOT files & Containers
5
Entry number and EventList
TEventList el; el.Enter(3); el.Enter(9); el.Enter(15); 1 2 3 4 T.GetEntry(0); returns entry 0 T.SetEventList(el); T.GetEntry(0); returns entry 3 5 6 7 8 9 10 11 12 13 14 15 16 17 18 T CMS 5 Dec Rene Brun ZOOM on ROOT files & Containers
6
ZOOM on ROOT files & Containers
tr Tree Friends Entry # 8 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 Public read User Write Public read CMS 5 Dec Rene Brun ZOOM on ROOT files & Containers
7
Binary search in table above ch.GetEntryWithIndex(12,567);
Chains of Trees f0 f1 f2 f3 f4 f5 f6 f7 2 4 4 5 5 4 7 11 12 17 23 26 32 37 45 49 1 2 3 4 5 6 7 TChain ch(“T”); ch.Add(“f0.root”); ch.Add(“f1.root”); ch.Add(“f2.root”); ch.Add(“f3.root”); ch.Add(“f4.root”); ch.Add(“f5.root”); ch.Add(“f6.root”); ch.Add(“f7.root”); Binary search in table above find slot 4, local entry 2 T.GetEntry(2) in f4.root ch.GetEntry(28); ch.GetEntryWithIndex(12,567); CMS 5 Dec Rene Brun ZOOM on ROOT files & Containers
8
Binary search in table above ch.GetEntryWithIndex(12,567);
Chains of Trees f0 f1 f2 f3 f4 f5 f6 f7 This chain definition should be generated on the fly from the catalog 2 4 4 5 5 4 7 11 12 17 23 26 32 37 45 49 1 2 3 4 5 6 7 TChain ch(“T”); ch.Add(“f0.root”); ch.Add(“f1.root”); ch.Add(“f2.root”); ch.Add(“f3.root”); ch.Add(“f4.root”); ch.Add(“f5.root”); ch.Add(“f6.root”); ch.Add(“f7.root”); Binary search in table above find slot 4, local entry 2 T.GetEntry(2) in f4.root ch.GetEntry(28); ch.GetEntryWithIndex(12,567); CMS 5 Dec Rene Brun ZOOM on ROOT files & Containers
9
Status with Persistent pointers
C++ persistent pointers In all versions of ROOT since day1 TRef, TRefArray implemented in dev version 3.02/00 TRef with Action on Demand implemented in 3.02/04 TRef simplification & extensions implemented in 3.02/05 CMS 5 Dec Rene Brun ZOOM on ROOT files & Containers
10
Normal Streaming mode References using TRef pointers
TBuffer b1; A.Streamer(b1) TBuffer b2; B.Streamer(b2) Objects in blue are only in b1 C++ pointer TRef A B Bz z Set pointer to z with: TRef Bz = z; Get pointer to z with: z = Bz.GetObject() CMS 5 Dec Rene Brun ZOOM on ROOT files & Containers
11
ZOOM on ROOT files & Containers
Setting a TRef pointer Assuming obj = pointer to a TObject* TRef ref = obj; TRef is itself a TObject If the obj::kIsReferenced bit is not yet set, the obj::fUniqueID is set to the CurrentNumber+1 and obj::kIsReferenced is set to 1. Its fUniqueID is set to obj::fUniqueID CurrentNumber is managed by TProcessID fObjs[CurrentNumber] is set to obj in fPID Class TObject { unsigned int fBits; unsigned int fUniqueID; Class TRef : public TObject { TProcessID *fPID; //!pointer to process id CMS 5 Dec Rene Brun ZOOM on ROOT files & Containers
12
ZOOM on ROOT files & Containers
TRef example: Event.h class Event : public TObject { private: char fType[20]; //event type char *fEventName; //run+event number in character format int fNtrack; //Number of tracks int fNseg; //Number of track segments int fNvertex; int fMeasures[10]; float fMatrix[4][4]; float *fClosestDistance; //[fNvertex] EventHeader fEvtHdr; TClonesArray *fTracks; //->array with all tracks TRefArray *fHighPt; //array of High Pt tracks only TRefArray *fMuons; //array of Muon tracks only TRef fLastTrack; //reference pointer to last track TRef fWebHistogram; //EXEC:GetWebHistogram TH1F *fH; //-> public: ... TH1F *GetHistogram() const {return fH;} TH1F *GetWebHistogram(Bool_t reload=kFALSE) const { return (TH1F*)fWebHistogram.GetObject(reload);} CMS 5 Dec Rene Brun ZOOM on ROOT files & Containers
13
Writing Referenced objects
A referenced object is written by obj->Streamer This Streamer at some point calls its TObject::Streamer In TObject::Streamer, if the kIsReferenced bit is set in fBits, the following additional info is also written: pid (4 bytes) = TProcessID of current process Average overhead in memory = 0 bytes Average overhead on disk (no comp) = 2 bytes Average overhead on disk (comp) = 2.4 bytes (0.4) A Referenced object may be written multiple times in the same file as the TRef or in other files CMS 5 Dec Rene Brun ZOOM on ROOT files & Containers
14
Writing TRefs to a buffer
A TRef is written by TRef::Streamer Writes uid(4 bytes) + pid(4 bytes) uid = object unique identifier uid = ref::fUniqueID = obj::fUniqueID = current object nr pid = Process identifier Each process has a unique pid (TProcessID) A file contains the pids of all processes that have written objects to it. TRef memory size = 16 bytes TRef size on disk (no comp) = 8 bytes TRef size on disk (comp) = 2.4 bytes CMS 5 Dec Rene Brun ZOOM on ROOT files & Containers
15
Reading Referenced objects
A referenced object is read by obj->Streamer This Streamer at some point calls its TObject::Streamer In TObject::Streamer, if the kIsReferenced bit is set in fBits, the following additional info is also read: pid (4 bytes) = TProcessID of current process In TProcessID::fObjs fObjs[fUniqueID] = obj When obj is deleted, fObjs[fUniqueID] = 0; CMS 5 Dec Rene Brun ZOOM on ROOT files & Containers
16
Reading TRefs from a buffer
A TRef object is read by TRef::Streamer The pair uid,pid is read the fUniqueID of TRef is set to uid The transient pointer fPID is set to the TProcessID corresponding to pid The bit 1 of fBits is set CMS 5 Dec Rene Brun ZOOM on ROOT files & Containers
17
ZOOM on ROOT files & Containers
A TRef use case Session 3 Session 1 Session 2 TFile f3(“f3.root”); TRef *r2; r2 = (TRef*)f3.Get(“r2”); r2->GetObject(); = 0 TFile f1(“f1.root”); Myclass *obj1; obj1 = (Myclass*)f1.Get(“obj1”); r2->GetObject(); --> obj1 Myclass *obj1; TRef r1 = obj1; TFile f1(“f1.root”,”new”); obj1->Write(“obj1”); TFile f2(“f2.root”,”new”); r1.Write(“r1”); TFile f2(“f2.root”); TRef *r1; r1 = (TRef*)f2.Get(“r1”); TFile f3(“f3.root”,”new”); TRef r2 = *r1; r2.Write(“r2”) obj1 r1 r1 r2 r2 obj1 obj1 r1 r2 f1.root f3.root f2.root CMS 5 Dec Rene Brun ZOOM on ROOT files & Containers
18
Returns obj = fUniqueID + gSystem
Using a TRef To get a pointer to the referenced object, do: Myclass *obj = (Myclass*)ref.GetObject() =0 Returns obj = fUniqueID + gSystem GetObject fBits[1] fPID = 0 or fPID>GetObjectWithUniqueID() = 0 =1 execid = fBits[8/8] YES NO Set fBits[1]=0 return obj YES return null execid = 0 NO Execute TExec with execid Obj = 0 YES CMS 5 Dec Rene Brun ZOOM on ROOT files & Containers
19
TRef & Action on Demand When the keyword “EXEC:” is found in the comments of the data member as in: TRef fWebHistogram; //EXEC:GetWebHistogram The information in the comment field is kept in the dictionary. Execid is saved in TStreamerElement When the TRef object is read, the execid is stored in the fBits on one byte (from TStreamerElement). When TRef::GetObject is called, TObjArray *lexecs = gROOT->GetListOfExecs(); TExec *exec = (TExec*)lexecs[execid]; exec->Exec(); Action on Demand is Persistent fWebHistogram.GetObject() executes the action GetWebHistogram CMS 5 Dec Rene Brun ZOOM on ROOT files & Containers
20
ZOOM on ROOT files & Containers
What a TExec can do TExec is a CORE ROOT class that can be used to execute: a call to a compiled or interpreted function example: Exec:LoadHits() an interpreted script example: Exec:GetWebHistogram If GetWebHistogram is not a function (compiled or interpreted), then TExec::Exec will try to execute the script GetWebHistogram.C void GetWebHistogram(){ // example of script called from an Action on Demand when a TRef object // is dereferenced. See Event.h, member fWebHistogram TFile *f= TFile::Open(" TH1 *h6 = (TH1*)f->Get("h6"); h6->SetDirectory(0); delete f; Tref::SetObject(h6); } CMS 5 Dec Rene Brun ZOOM on ROOT files & Containers
21
ZOOM on ROOT files & Containers
A Working Example Action.C { gSystem.Load("libEvent"); TFile f("Event.root"); Event *event=0; T.SetBranchAddress("event",&event); T.GetEntry(45); event->GetWebHistogram()->Draw(); } Root > .x Action.C GetWebHistogram.C void GetWebHistogram(){ // example of script called from an Action on Demand when a TRef object // is dereferenced. See Event.h, member fWebHistogram TFile *f= TFile::Open(" TH1 *h6 = (TH1*)f->Get("h6"); h6->SetDirectory(0); delete f; TRef::SetObject(h6); } CMS 5 Dec Rene Brun ZOOM on ROOT files & Containers
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.