Zooming on ROOT files and Containers CMSROOT meeting

  • Slides: 21
Download presentation
Zooming on ROOT files and Containers CMS-ROOT meeting CERN- December 5 René Brun ftp:

Zooming on ROOT files and Containers CMS-ROOT meeting CERN- December 5 René Brun ftp: //root. cern. ch/root/Zoom. Files. ppt ZOOM on ROOT files & Containers 1

Keys in a TDirectory/TFile Key in directory in memory Key on file record header

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 2

Memory <--> Tree The Tree entry serial number Memory 0 T. Get. Entry(6) 1

Memory <--> Tree The Tree entry serial number Memory 0 T. Get. Entry(6) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 T. Fill() T CMS 5 Dec Rene Brun ZOOM on ROOT files & Containers 3

Entry number and Index T. Build. Index(“Run”, ”Event”) 0 1 2 3 4 Index(45,

Entry number and Index T. Build. Index(“Run”, ”Event”) 0 1 2 3 4 Index(45, 12) = 0 5 6 7 8 9 Index(45, 78) = 8 10 11 12 13 14 15 16 17 18 Index(45, 95) = 18 T. Get. Entry(8) T. Get. Entry. With. Index(45, 78) T CMS 5 Dec Rene Brun ZOOM on ROOT files & Containers 4

Entry number and Event. List TEvent. List el; 0 1 el. Enter(3); el. Enter(9);

Entry number and Event. List TEvent. List el; 0 1 el. Enter(3); el. Enter(9); el. Enter(15); 2 3 4 5 T. Get. Entry(0); returns entry 0 6 7 T. Set. Event. List(el); 8 9 T. Get. Entry(0); returns entry 3 10 11 12 13 14 15 16 17 18 T CMS 5 Dec Rene Brun ZOOM on ROOT files & Containers 5

Tree Friends 01 23 45 67 89 10 11 12 13 14 15 16

Tree Friends 01 23 45 67 89 10 11 12 13 14 15 16 17 18 0 1 2 3 4 5 6 7 8 Entry # 8 01 23 45 67 89 10 11 12 13 14 15 16 17 18 Public User read Write CMS 5 Dec Rene Brun ZOOM on ROOT files & Containers 6

Chains of Trees f 0 f 1 f 2 0 0 0 f 3

Chains of Trees f 0 f 1 f 2 0 0 0 f 3 f 4 0 f 5 0 0 5 f 7 0 2 4 f 6 0 4 5 4 7 11 0 12 0 17 1 TChain ch(“T”); ch. Add(“f 0. root”); ch. Add(“f 1. root”); ch. Add(“f 2. root”); ch. Add(“f 3. root”); ch. Add(“f 4. root”); ch. Add(“f 5. root”); ch. Add(“f 6. root”); ch. Add(“f 7. root”); CMS 5 Dec Rene Brun 23 2 26 3 32 4 37 5 45 6 49 7 Binary search in table above ch. Get. Entry(28); find slot 4, local entry 2 T. Get. Entry(2) in f 4. root ch. Get. Entry. With. Index(12, 567); ZOOM on ROOT files & Containers 7

Chains of Trees f 0 f 1 f 2 f 4 f 5 0

Chains of Trees f 0 f 1 f 2 f 4 f 5 0 This chain 0 definition 0 0 0 f 3 should be generated 2 5 fly from the on the 4 f 6 0 f 7 0 0 4 5 4 7 catalog 11 0 12 0 17 1 TChain ch(“T”); ch. Add(“f 0. root”); ch. Add(“f 1. root”); ch. Add(“f 2. root”); ch. Add(“f 3. root”); ch. Add(“f 4. root”); ch. Add(“f 5. root”); ch. Add(“f 6. root”); ch. Add(“f 7. root”); CMS 5 Dec Rene Brun 23 2 26 3 32 4 37 5 45 6 49 7 Binary search in table above ch. Get. Entry(28); find slot 4, local entry 2 T. Get. Entry(2) in f 4. root ch. Get. Entry. With. Index(12, 567); ZOOM on ROOT files & Containers 8

Status with Persistent pointers n C++ persistent pointers n n TRef, TRef. Array n

Status with Persistent pointers n C++ persistent pointers n n TRef, TRef. Array n n implemented in dev version 3. 02/00 TRef with Action on Demand n n In all versions of ROOT since day 1 implemented in 3. 02/04 TRef simplification & extensions n implemented in 3. 02/05 CMS 5 Dec Rene Brun ZOOM on ROOT files & Containers 9

Normal Streaming mode References using TRef pointers TBuffer b 1; A. Streamer(b 1) Objects

Normal Streaming mode References using TRef pointers TBuffer b 1; A. Streamer(b 1) Objects in blue TBuffer b 2; are only in b 1 B. Streamer(b 2) C++ pointer A Bz B TRef z Set pointer to z with: TRef Bz = z; Get pointer to z with: z = Bz. Get. Object() CMS 5 Dec Rene Brun ZOOM on ROOT files & Containers 10

Setting a TRef pointer n n n Assuming obj = pointer to a TObject*

Setting a TRef pointer n n n Assuming obj = pointer to a TObject* TRef ref = obj; Class TObject { TRef is itself a TObject unsigned int f. Bits; Class TRef : public TObject { unsigned int f. Unique. ID; TProcess. ID *f. PID; //!pointer to process id n n If the obj: : k. Is. Referenced bit is not yet set, the obj: : f. Unique. ID is set to the Current. Number+1 and obj: : k. Is. Referenced is set to 1. Its f. Unique. ID is set to obj: : f. Unique. ID Current. Number is managed by TProcess. ID f. Objs[Current. Number] is set to obj in f. PID CMS 5 Dec Rene Brun ZOOM on ROOT files & Containers 11

TRef example: Event. h class Event : public TObject { private: char int int

TRef example: Event. h class Event : public TObject { private: char int int float Event. Header TClones. Array TRef TH 1 F public: . . . TH 1 F CMS 5 Dec Rene Brun f. Type[20]; *f. Event. Name; f. Ntrack; f. Nseg; f. Nvertex; f. Measures[10]; f. Matrix[4][4]; *f. Closest. Distance; f. Evt. Hdr ; *f. Tracks; *f. High. Pt; *f. Muons; f. Last. Track; f. Web. Histogram ; *f. H; //event type //run+event number in character format //Number of tracks //Number of track segments //[f. Nvertex] //->array with all tracks //array of High Pt tracks only //array of Muon tracks only //reference pointer to last track //EXEC: Get. Web. Histogram //-> *Get. Histogram() const {return f. H; } *Get. Web. Histogram(Bool_t reload=k. FALSE) const { return (TH 1 F*)f. Web. Histogram. Get. Object(reload); } ZOOM on ROOT files & Containers 12

Writing Referenced objects n n n n A referenced object is written by obj->Streamer

Writing Referenced objects n n n n A referenced object is written by obj->Streamer This Streamer at some point calls its TObject: : Streamer In TObject: : Streamer, if the k. Is. Referenced bit is set in f. Bits, the following additional info is also written: pid (4 bytes) = TProcess. ID 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 13

Writing TRefs to a buffer n n n A TRef is written by TRef:

Writing TRefs to a buffer n n n A TRef is written by TRef: : Streamer Writes uid(4 bytes) + pid(4 bytes) uid = object unique identifier n n pid = Process identifier n n n uid = ref: : f. Unique. ID = obj: : f. Unique. ID = current object nr Each process has a unique pid (TProcess. ID) 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 14

Reading Referenced objects n n n A referenced object is read by obj->Streamer This

Reading Referenced objects n n n A referenced object is read by obj->Streamer This Streamer at some point calls its TObject: : Streamer In TObject: : Streamer, if the k. Is. Referenced bit is set in f. Bits, the following additional info is also read: pid (4 bytes) = TProcess. ID of current process In TProcess. ID: : f. Objs[f. Unique. ID] = obj When obj is deleted, f. Objs[f. Unique. ID] = 0; CMS 5 Dec Rene Brun ZOOM on ROOT files & Containers 15

Reading TRefs from a buffer n n n A TRef object is read by

Reading TRefs from a buffer n n n A TRef object is read by TRef: : Streamer The pair uid, pid is read the f. Unique. ID of TRef is set to uid The transient pointer f. PID is set to the TProcess. ID corresponding to pid The bit 1 of f. Bits is set CMS 5 Dec Rene Brun ZOOM on ROOT files & Containers 16

A TRef use case Session 3 Session 1 Session 2 Myclass *obj 1; TFile

A TRef use case Session 3 Session 1 Session 2 Myclass *obj 1; TFile f 2(“f 2. root”); TRef r 1 = obj 1; TRef *r 1; TFile f 1(“f 1. root”, ”new”); r 1 = (TRef*)f 2. Get(“r 1”); obj 1 ->Write(“obj 1”); TFile f 3(“f 3. root”, ”new”); TFile f 2(“f 2. root”, ”new”); TRef r 2 = *r 1; r 1. Write(“r 1”); r 2. Write(“r 2”) obj 1 r 1 TFile f 3(“f 3. root”); TRef *r 2; r 2 = (TRef*)f 3. Get(“r 2”); r 2 ->Get. Object(); = 0 TFile f 1(“f 1. root”); Myclass *obj 1; obj 1 = (Myclass*)f 1. Get(“obj 1”); r 2 ->Get. Object(); r 2 --> obj 1 f 1. root CMS 5 Dec Rene Brun r 1 r 2 f 2. root f 3. root ZOOM on ROOT files & Containers 17

Using a TRef n n To get a pointer to the referenced object, do:

Using a TRef n n To get a pointer to the referenced object, do: Myclass *obj = (Myclass*)ref. Get. Object() =0 Get. Object Returns obj = f. Unique. ID + g. System f. Bits[1] f. PID = 0 =1 execid = f. Bits[8/8] YES execid = 0 return null NO Execute TExec with execid CMS 5 Dec Rene Brun or f. PID>Get. Object. With. Unique. ID() = 0 Obj = 0 ZOOM on ROOT files & Containers NO Set f. Bits[1]=0 return obj YES 18

TRef & Action on Demand n When the keyword “EXEC: ” is found in

TRef & Action on Demand n When the keyword “EXEC: ” is found in the comments of the data member as in: n n TRef f. Web. Histogram; //EXEC: Get. Web. Histogram The information in the comment field is kept in the dictionary. Execid is saved in TStreamer. Element When the TRef object is read, the execid is stored in the f. Bits on one byte (from TStreamer. Element). When TRef: : Get. Object is called, n n n TObj. Array *lexecs = g. ROOT->Get. List. Of. Execs(); TExec *exec = (TExec*)lexecs[execid]; exec->Exec(); Action on Demand is Persistent f. Web. Histogram. Get. Object() executes the action Get. Web. Histogram CMS 5 Dec Rene Brun ZOOM on ROOT files & Containers 19

What a TExec can do n TExec is a CORE ROOT class that can

What a TExec can do n TExec is a CORE ROOT class that can be used to execute: n a call to a compiled or interpreted function n n example: Exec: Load. Hits() an interpreted script n n example: Exec: Get. Web. Histogram If Get. Web. Histogram is not a function (compiled or interpreted), then TExec: : Exec will try to execute the script Get. Web. Histogram. C void Get. Web. Histogram(){ // example of script called from an Action on Demand when a TRef object // is dereferenced. See Event. h, member f. Web. Histogram TFile *f= TFile: : Open("http: //root. cern. ch/files/pippa. root"); TH 1 *h 6 = (TH 1*)f->Get("h 6"); h 6 ->Set. Directory(0); delete f; Tref: : Set. Object(h 6); } CMS 5 Dec Rene Brun ZOOM on ROOT files & Containers 20

A Working Example Action. C { g. System. Load("lib. Event"); TFile f("Event. root"); Event

A Working Example Action. C { g. System. Load("lib. Event"); TFile f("Event. root"); Event *event=0; T. Set. Branch. Address("event", &event); T. Get. Entry(45); event->Get. Web. Histogram()->Draw(); Root >. x Action. C } Get. Web. Histogram. C void Get. Web. Histogram(){ // example of script called from an Action on Demand when a TRef object // is dereferenced. See Event. h, member f. Web. Histogram TFile *f= TFile: : Open("http: //root. cern. ch/files/pippa. root"); TH 1 *h 6 = (TH 1*)f->Get("h 6"); h 6 ->Set. Directory(0); delete f; TRef: : Set. Object(h 6); } CMS 5 Dec Rene Brun ZOOM on ROOT files & Containers 21