Download presentation
Presentation is loading. Please wait.
Published byMadeline Stokes Modified over 8 years ago
1
ROOT – úvodní přednáška a cvičení Jiří Chudoba, 18.3.2009
2
Úvod ● Motivace pro ROOT ● Historie ● Vývojový model ● Framework ● CINT
3
Zdroje informací ● Zde pouze nástin možností ● Bohaté zdroje na www – root.cern.ch – roottalk a RootTalk ● Přednášky z FNAL
4
Instalace a spuštění ● Aktuální verze 5.22 ● Binární distribuce ● Kompilace dlouhá ● Předinstalováno několik verzí ● Nastavení proměnných – $PATH, $ROOTSYS, $LD_LIBRARY_PATH ● Spustit – Novější verze:. bin/thisroot.sh
5
9/30/2016ROOT Day 2, Suzanne Panacek5 Environment Settings ● Environment setting file: ● $ROOTSYS/etc/system.rootrc – looks first in current directory for.rootrc – second in $HOME/.rootrc – third in $ROOTSYS/etc/system.rootrc ● Find the current settings – root[] gEnv->Print()
6
9/30/2016ROOT Day 2, Suzanne Panacek6 Environment Settings (cont.) The.rootrc file: The Macro Path Unix.*.Root.MacroPath:.:$(HOME)/myRootMacros Options in.rootrc Root.ShowPath: false History File $HOME/.root_hist Automatically Executing Macros rootlogon.C rootlogoff.C rootalias.C
7
9/30/2016ROOT Day 2, Suzanne Panacek7 Command Line Options > root -/? Usage: root [-l] [-b] [-n] [-q] [file1.C... fileN.C] Options: -b : run in batch mode without graphics -n : do not execute logon and logoff macros as specified in.rootrc -q : exit after processing command line macro files -l : do not show splash screen
8
9/30/2016ROOT Day1, Suzanne Panacek8 ROOT's Services/Utilities Histogramming and Fitting Graphics (2D, 3D) I/O to file or socket: specialized for histograms, Ntuples (Trees) Collection Classes and Run Time Type Identification ● User Interface GUI: Browsers, Panels, Tree Viewer Command Line interface: C++ interpreter CINT Script Processor (C++ compiled C++ interpreted)
9
9/30/2016ROOT Day 2, Suzanne Panacek9 Three Types of Commands 1. CINT commands start with “.” root[0].? this command will list all the CINT commands root[1].X [filename] load [filename] and execute function [filename] root[2].L [filename] load [filename] 2. SHELL commands start with “.!” for example: root[3].! ls
10
9/30/2016ROOT Day 2, Suzanne Panacek10 Three Types of Commands 3. C++ syntax (almost) root [0] TBrowser *b = new TBrowser() or root [0] TBrowser *b = new TBrowser(); The optional Semicolon: Leave off the semicolon to see the return value of the command. root [0] 23+5 // show return value (int)28 root [1] 23+5; // no return value root [2]
11
9/30/2016ROOT Day 2, Suzanne Panacek11 Command Line Help ● Use the Tab feature to get help … root [0] b = new TB root [1] b = new TBrow root [2] b = new TBrowser( ● Find List of Methods ● Find Parameter list
12
9/30/2016ROOT Day 2, Suzanne Panacek12 Coding Conventions Based on Taligent ● Classes begin with T TTree, TBrowser ● Non-class types end with _t Int_t ● Data members begin with ffTree ● Member functions begin with a capital Loop() ● Constants begin with k kInitialSize, kRed ● Static variables begin with g gEnv ● Static data members begin with fg fgTokenClient
13
9/30/2016ROOT Day 2, Suzanne Panacek13 CINT Types
14
9/30/2016ROOT Day 2, Suzanne Panacek14 CINT Extensions to C++ 1. Declaration can be omitted f = new TFile("Example.root") 2. "." notation rather than "->" f.ls() 3. Search for an object by its name TH1F *smallHisto = new TH1F (" small ","fPx 100",100,-5,5); small ->Draw(); Warning: These will not work in compiled code!
15
9/30/2016ROOT Day 2, Suzanne Panacek15 CINT Commands [expression] evaluates the expression root[3] 3*4 (int)12 ●.files show loaded source files ●.class [name] show class definition ●.g prints all objects in the root session ●.ls ls on current directory ●.pwdlist the current directory, canvas, and style.
16
9/30/2016ROOT Day 2, Suzanne Panacek16 Demo on CINT Commands.class root [0].L $ROOTSYS/test/libEvent.so root [1].class Event.g root [2].g... 0x104c7560 Event e, size=56 0x0 private: Int_t fNtrack 0x0 private: Int_t fNseg 0x0 private: Int_t fNvertex...
17
9/30/2016ROOT Day 2, Suzanne Panacek17 CINT Multi-line Command Start with "{" For example: root [] { end with '}'> Int_t j = 0; end with '}'> for (Int_t i = 0; i < 3; i++) end with '}'> { end with '}'> j= j + i; end with '}'> cout <<"i = " <<i<<", j = " <<j<<endl; end with '}'> } i = 0, j = 0 i = 1, j = 1 i = 2, j = 3
18
9/30/2016ROOT Day 2, Suzanne Panacek18 Global Variables gRandom gRandom->Gaus(1,2) You can replace the random generator with your own: delete gRandom; gRandom = new TRandom2(0); //seed=0 gFile gFile->GetName() gDirectory gDirectory->GetName() ● gSystem gSystem->HostName()
19
9/30/2016ROOT Day 2, Suzanne Panacek19 gROOT ● global ROOT session object ● gROOT->GetListOf (); ● gROOT->LoadMacro(); ● gROOT->Time(); ● gROOT->ProcessLine()
20
9/30/2016ROOT Day 2, Suzanne Panacek20 gROOT->FindObject() TH1F *smallHisto = new TH1F ("small","fPx 100",100,-5,5); ● "small" is the Object Name gROOT->FindObject("small") (class TObject*)0x104c7528 ● "smallHisto" is the Variable Name gROOT->FindObject("smallHisto") (class TObject*)0x0 // null pointer ● FindObject needs the Object Name.
21
9/30/2016ROOT Day 2, Suzanne Panacek21 gROOT->FindObject() ++ FindObject returns a pointer to TObject. This generates an error: gROOT->FindObject("small")->GetBinContent(2) This is OK: gROOT->FindObject("small")->ClassName() TH1F* histo=(TH1F*) gROOT->FindObject("small") histo->GetBinContent(2)
22
9/30/2016ROOT Day 2, Suzanne Panacek22 gROOT->FindObject() cont. Due to CINT magic this is also OK: TH1F *smallHisto = new TH1F ("small","fPx 100",100,-5,5); small->GetBinContent(2); CINT implicitly executes a FindObject("small") Casts it to the correct class Creates a variable called "small" of the correct class Warning: This will not work in compiled code!
23
9/30/2016ROOT Day 2, Suzanne Panacek23 Demonstration: FindObject FindObject(): root [3] f = TFile("Example.root") root [4].ls root [5] gROOT->FindObject("myTree") root [6] myTree
24
9/30/2016ROOT Day 2, Suzanne Panacek24 TObject: The Mother of all Root objects ● Defines protocol and default behavior for all objects in ROOT. – I/O – Drawing/Painting – TObjects can be stored in collection classes. – Introspection, Reflection, Runt Time Type Identification
25
9/30/2016ROOT Day 2, Suzanne Panacek25 TObject RTTI ● RTTI = the ability of a class to reflect upon itself or to "look inside itself" at run time. ● TClass implement RTTI ● To get the TClass from a TObject descendent: obj->Class() ● TClass can find the: – Methods – Data members – Base classes
26
9/30/2016ROOT Day 2, Suzanne Panacek26 Summary (Command Line) ● Environment Settings ● Command types ● CINT Commands ● Global Variables ● TObject
27
Cvičení ● Spusťte root v $ROOTSYS/tutorials ●.x demos.C ● Podívejte se na zdrojové kódy maker – demos.C – hsimple.C ● Vyhledat dokumentaci na root.cern.ch
28
9/30/2016ROOT Day 2, Suzanne Panacek28 Writing Scripts ● Named and Un-named Scripts ● Debugging ● ACLiC
29
9/30/2016ROOT Day 2, Suzanne Panacek29 Scripts Un-named Script Start with "{" and end with "}" All variables are in the global scope No class definitions No function declarations No parameters Named Script C++ functions Scope rules follow standard C++ Function with the same name as the file is executed with a.x Parameters Class definitions (derived from a compiled class at your own risk)
30
9/30/2016ROOT Day 2, Suzanne Panacek30 Scripts Examples ● Un-named Script: hello.C { cout << "Hello" << endl; } ● Named Script:say.C void say(char * what = "Hello") { cout << what << endl; } ● Executing the Named Script root [3].x say.C Hello root [4].x say.C("Hi there") Hi there
31
9/30/2016ROOT Day 2, Suzanne Panacek31 Resetting the Environment ● gROOT->Reset() – Calls destructors of all objects created on the stack – Objects on Heap are not deleted, but pointer variable is disassociated
32
9/30/2016ROOT Day 2, Suzanne Panacek32 Debugging: Stepping.s set the step mode to step into function.S set the step mode to go over function or loop.e continue to end of the function.c continue to next breakpoint.c 45 continue to line 45.p print the value of var
33
9/30/2016ROOT Day 2, Suzanne Panacek33 Debugging: Breakpoints.trace MyClass prints the executing code to window.deltrace MyClass removes the trace.break MyClass breaks at each method of MyClass.delbreak MyClass removes the break.b 34 sets a break point at line 34.db 34 removes the break point at line 34
34
9/30/2016ROOT Day 2, Suzanne Panacek34 Debugging: Inspecting DrawClass() Graphic list of methods including ancestors Inspect() Draw the current contents of an object Dump() Lists the current contents of an object gDebug = 1 Prints debugging information
35
9/30/2016ROOT Day 2, Suzanne Panacek35 Tracking Memory Leaks ● Counting Objects and Memory use – In the.rootrc or system.rootrc file: Root.MemStat: 1 Root.ObjectStat:1 ● Print the Object count and Memory use gObjectTable->Print();
36
9/30/2016ROOT Day 2, Suzanne Panacek36 Tracking Memory Leaks+ ● Example output: Before.x FirstContour.C: count on heap size total size heap size Total: 1,079 1,046 3,160 49,992 45,824 After: Total: 1,783 1,749 17,920 118,912 114,568 ● Put gObjectTable->Print() before and after code segment in your script to find memory leaks.
37
9/30/2016ROOT Day 2, Suzanne Panacek37 ACLiC: Automatic Compiler of Libraries for CINT ● Use an external compiler to create a shared library from a macro. ● Use root [0].L MyMacro.C++ Always recompile root [0].L MyMacro.C+ Recompile as needed
38
9/30/2016ROOT Day 2, Suzanne Panacek38 ACLiC Use Restriction: can not use path name with.L.L../root_base/MyMacro.C+ Instead do: gSystem->cd("../directory"); gSystem->CompileMacro("MyMacro.C") Options are: k : keep the shared library after the session end. f : force recompilation. To set the Include path:.include "-I$HOME/mypackage/include";
39
9/30/2016ROOT Day 2, Suzanne Panacek39 ACLiC Advantages Advantages : syntax checking about five times faster full C++ feature set Disadvantage: On KCC, you can load each C++ shared library only once
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.