1 / 62

Introduction to ROOT: Graphics, Histograms, Input/Output, Networking, Threads

Learn about the ROOT system, an object-oriented framework for large-scale data handling applications. Explore features such as efficient hierarchical databases, statistical analysis, visualization tools, and more.

julialucas
Download Presentation

Introduction to ROOT: Graphics, Histograms, Input/Output, Networking, Threads

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ROOT TutorialsRT2003 Montreal19 May 2003 Introduction Graphics & Histograms Input/Output Networking Threads René Brun, CERN http://root.cern.ch/root/RT2003.html ROOT Tutorials - Session 1

  2. ROOT Tutorials Introduction to ROOT ROOT Tutorials - Session 1

  3. What is ROOT? • The ROOT system is an Object Oriented framework for large scale data handling applications • Written in C++ • Provides, among others, • An efficient hierarchical OO database • A C++ interpreter • Advanced statistical analysis (multi dimensional histogramming, fitting, minimization and cluster finding algorithms) • Visualization tools • And much, much more • The user interacts with ROOT via a graphical user interface, the command line or batch scripts • The command and scripting language is C++, thanks to the embedded CINT C++ interpreter and large scripts can be compiled and dynamically loaded Introduction to ROOT

  4. Prehistory • In the beginning there was PAW • HBOOK • ZEBRA • KUIP • COMIS • SIGMA • Mini/Micro-DST analysis was done using Ntuples • Ntuples are basically simple tables • Only basic types • No data structures • No cross reference between Ntuples • Successful because simple and efficient • Dead-end • No way to grow to more complex data structures • Difficult to extend • Expensive to maintain • Too many languages: Fortran, KUIP, SIGMA Introduction to ROOT

  5. Main Goals • Being able to support full data analysis chain • Raw data, DSTs, mini-DSTs, micro-DSTs • Being able to handle complex structures • Complete objects • Object hierarchies • Support at least the PAW data analysis functionality • Histogramming • Fitting • Visualization • Only one language • C++ • Better maintainable • Use OOP • Make the system extensible • Use OO framework technology Introduction to ROOT

  6. The Core ROOT Team Introduction to ROOT

  7. Project History • Jan 95: Thinking/writing/rewriting/??? • November 95: Public seminar, show Root 0.5 • Spring 96: decision to use CINT • Jan 97: Root version 1.0 • Jan 98: Root version 2.0 • Mar 99: Root version 2.21/08 (1st Root workshop FNAL) • Feb 00: Root version 2.23/12 (2nd Root workshop CERN) • Mar 01: Root version 3.00/06 • Jun 01: Root version 3.01/05(3rd Root workshop FNAL) • Jan 02: Root version 3.02/07 (LCG project starts: RTAGs) • Oct 02: Root version 3.03/09 (4th Root workshop CERN) • May 03: Root version 3.05/05 8 years !! Introduction to ROOT

  8. Trends Parallelism on the GRID Batch/Interactive Access to Catalogs Resource Brokers Process migration Progress Monitors Proxies/caches Virtual data sets More and more GRID oriented data analysis More and more experiment-independent software Efficient Access to large and structured event collections Interaction with user & experiment classes Histogram Ntuple viewers Data Presenters Introduction to ROOT

  9. ROOT Statistics –Supported Platforms • 3 major type of OS’es • Unix, Windows, Mac OS X • 10 different CPU’s • IA-32, IA-64, Sparc, Alpha, PA-RISC, PowerPC, MIPS, ARM • 11 different compilers • Gcc, kcc, ecc, icc, CC, cc, VC++, … • 41 Makefiles • ./configure<arch>; make Introduction to ROOT

  10. ROOT Statistics –Available Binaries • 27 binary • tar balls Introduction to ROOT

  11. ROOT Statistics –Distributions and Number of Users 205,000 binaries downloaded >1,000,000 clicks per month 60,000 docs in 2 years 3000 registered users 950 users subscribed to roottalk Introduction to ROOT

  12. ROOT Development Process • We follow an Open Source development model • “Release early, release often” • Major releases 3-4 times per year • Minor releases every 2-3 weeks • Daily/nightly builds + regression testing + benchmarking (rootmarks) • “Let user feedback drive the development” • Bug reporting system • Roottalk mailing list • Annual workshop • Open cvs repository • Let users become developers Introduction to ROOT

  13. ROOT Directory Organization Introduction to ROOT

  14. Schematic View of ROOT Alice Introduction to ROOT

  15. Fundamental Features of an Object-Oriented Data Analysis Framework • Object Persistency • Must be simple for simple applications: histograms, simple simulations, test beams • Must be efficient for Terabytes of data • User Interface, must have • Command and script mode • Interpreted code <===> compiled code • GUI and browsers • RTTI is the vital element Introduction to ROOT

  16. ROOT: a Framework and a Library • User classes • User can define new classes interactively • Either using calling API or sub-classing API • These classes can inherit from ROOT classes • Dynamic linking • Interpreted code can call compiled code • Compiled code can call interpreted code • Macros can be dynamically compiled & linked This is the normal operation mode Interesting feature for GUIs & event displays Script Compiler root > .x file.C++ Introduction to ROOT

  17. Dynamic Linking • A Shared Library can be linked dynamically to a running executable module • either via explicit loading,- or automatically via plug-in manager Experiment libraries A Shared Library facilitates the development and maintenance phases User libraries General libraries Application Executable Module Introduction to ROOT

  18. ROOT Library Structure • ROOT libraries are a layered structure • The CORE classes are always required (support for RTTI, basic I/O and interpreter) • The optional libraries (you load only what you use) Separation between data objects and the high level classes acting on these objects. Example, a batch job uses only the histogram library, no need to link histogram painter library. • Shared libraries reduce the application link time • Shared libraries reduce the application size • ROOT shared libraries can be used with other class libraries Introduction to ROOT

  19. The Libraries • Over 700 classes • 950,000 lines of code • CORE (10 Mbytes) • CINT (3 Mbytes) • Green libraries linked on demand via plug-in manager (only a subset shown) Introduction to ROOT

  20. ROOT libs R O O T CERNLIB ls -l $ROOTSYS/lib ls -l /cern/pro/lib 203856 libASImage.so 1273308 libCint.so 5658143 libCore.so 419481 libEG.so 152912 libEGPythia.so 160874 libEGPythia6.so 162181 libEGVenus.so 326000 libGX11.so 183065 libGX11TTF.so 2306421 libGeom.so 158895 libGeomPainter.so 1019977 libGpad.so 1602106 libGraf.so 1028762 libGraf3d.so 3669409 libGui.so 1605344 libHbook.so 1940222 libHist.so 332268 libHistPainter.so 114970 libHtml.so 167670 libMC.so 580851 libMatrix.so 319945 libMinuit.so 268321 libMySQL.so 21981 libNew.so 88438 libPgSQL.so 336736 libPhysics.so 196318 libPostscript.so 576691 libProof.so 681086 libRFIO.so 2017467 libRGL.so 177657 libRint.so 35410 libSRPAuth.so 1120731 libTable.so 312785 libThread.so 1067715 libTree.so 356186 libTreePlayer.so 409350 libTreeViewer.so 155664 libX3d.so 1434404 libgrafX11.a 1046944 libgraflib.a 4981896 libkernlib.a 2002460 libmathlib.a 11849762 libpacklib.a 4350440 libpawlib.a TOTAL = 25.2 MBytes TOTAL = 30.7 MBytes Introduction to ROOT

  21. ROOT Abstract Interfaces • The abstract interfaces have two main functions: • define a standard protocol • enhance modularity by minimizing dependencies between classes and shared libraries • On last count ROOT has 21 abstract interfaces Introduction to ROOT

  22. Example of Abstract Interfaces TVirtualPad TVirtualPS TVirtuaX TPad TPostScript TSVG TGX11 TGWin32 TGQt TVirtualTreePlayer TVirtualHistPainter TVirtualFitter TFitter TMinuit TFumili TTreePlayer THistPainter TSystem TInterpreter TGrid TWinNTSystem TUnixSystem TCINT TAlien TVDT Introduction to ROOT

  23. CINT Interpreter ROOT Tutorials - Session 1

  24. CINT • CINT is a C and C++ interpreter • Written by Masaharu Goto and available under an Open Source license • It implements about 95% of ANSI C and 90% of ANSI C++ • It is robust and complete enough to interpret itself (90000 lines of C, 5000 lines of C++) • Has good debugging facilities • Has a byte code compiler • In many cases it is faster than tcl, perl and python Introduction to ROOT

  25. CINT in ROOT • CINT is used in ROOT: • As command line interpreter • As script interpreter • To generate class dictionaries • To generate function/method calling stubs • The command line, script and programming language become the same • Large scripts can be compiled for optimal performance Introduction to ROOT

  26. CINT as Interpreter • CINT is used as command line interpreter: • And as script interpreter: root[0] for (int i = 0; i < 10; i++) printf(“Hello\n”) root[1] TF1 *f = new TF1(“f”, “sin(x)/x”, 0, 10) root[2] f->Draw() bash$ vi script.C { for (int i = 0; i < 10; i++) printf(“Hello\n”); TF1 *f = new TF1(“f”, “sin(x)/x”, 0, 10); f->Draw(); } root[0] .x script.C Introduction to ROOT

  27. The Command Line • The CINT/ROOT command line support emacs style editing • ctrl-a, ctrl-e, ctrl-d, left/right arrow keys, etc. • Important feature: <TAB> expansion to expand class names, method names, file names, etc. • Command history is retained between sessions in the file ~/.root_hist • Navigation: ctrl-p, ctrl-n, up/down arrow keys • Everything you type at the prompt is C++ • Except for interpreter escape commands, like • .x, .L, .q, .?, etc. • Do .? to see all interpreter commands Introduction to ROOT

  28. Introduction to ROOT

  29. Dictionary Generation ROOT Tutorials - Session 1

  30. What Are Dictionaries Used For • Dictionaries are used for: • Generation of Streamer() methods (I/O) • Generation of ShowMember() methods (run-time object inspection) • Generation of context sensitive popup menus • Generation of hyperized documentation (via THtml class) • Generation of class diagrams and inheritance trees • Providing extended RTTI TClass *TObject::IsA() Bool_t TObject::InheritsFrom() const char *TObject::ClassName() Introduction to ROOT

  31. rootcint dictionary generator dictionary.cxx compile and link ROOT based application ROOT Environment and Tools C++ application header files LinkDef.h file C++ application source files user libraries ROOT libraries C++ macro files Introduction to ROOT

  32. Providing Interactive Access • To provide interactive access to your classes from CINT you only need to generate a dictionary for your classes • No other instrumentation is needed Introduction to ROOT

  33. rootcint –f MyDict.cxx –c MyClass.h MyDict.h MyDict.cxx compile and link libMyClass.so Generating a Dictionary MyClass.h MyClass.cxx Introduction to ROOT

  34. Exercise 1 • Write simple class, call it MyClass and store it in MyClass.h and MyClass.cxx • Generate dictionary: • Compile MyClass.cxx and mydict.cxx into a shared library: rootcint –f MyDict.cxx –c MyClass.h g++ -shared –fPIC `root-config -–cflags` -o libMyClass.so MyClass.cxx MyDict.cxx Introduction to ROOT

  35. Exercise 1 (cont.) • Start ROOT, load libMyClass.so: • Create and play with MyClass object: $ root root [0] gSystem->Load(“libMyClass”) root [1] MyClass a root [2] a.Print() root [3] … Introduction to ROOT

  36. Linking Class to ROOT RTTI • To link a class to the ROOT RTTI system two macros need to be added to MyClass: • ClassDef(class name, version id) • ClassImp(class name) // MyClass.h class MyClass { public: . . . ClassDef(MyClass,1) // analyse my data }; // MyClass.cxx #include “MyClass.h” ClassImp(MyClass) Introduction to ROOT

  37. ClassDef and ClassImp • These macros provide: • Several static methods to obtain reflection/meta class information • Inspection and Streamer (I/O) methods • Methods returning header and source file name • Small class and static object to register class to ROOT when library is loaded static TClass *Class(); static const char *Class_Name(); virtual TClass *IsA() const; virtual void ShowMembers(TMemberInspector &insp, char *parent); static Version_t Class_Version() { return id; } virtual void Streamer(TBuffer &b); friend TBuffer &operator>>(TBuffer &buf, name *&obj); Introduction to ROOT

  38. Exercise 2 • Add ClassDef() and ClassImp() macros to MyClass • And also add: #include <Rtypes.h>to MyClass.h • Repeat same steps as in exercise 1: rootcint –f MyDict.cxx –c MyClass.h g++ -shared –fPIC `root-config -–cflags` -o libMyClass.so MyClass.cxx MyDict.cxx $ root root [0] gSystem->Load(“libMyClass”) root [1] MyClass a root [2] a.Print() root [3] a.P<TAB> works now Introduction to ROOT

  39. Full Integration into ROOT • To make your class a fully ROOT supported class, with full I/O capabilities, just add derivation from TObject to MyClass // MyClass.h class MyClass : public TObject { public: . . . ClassDef(MyClass,1) // analyse my data }; Introduction to ROOT

  40. Exercise 3 • Add public derivation from TObject to your class • Replace the Rtypes.h include by TObject.h • Repeat same two build steps as in the previous exercises • Create object of MyClass and Dump() its run time contents: root [1] MyClass a root [2] a.Dump() Root [3] … Introduction to ROOT

  41. Exercise 3 (cont.) • Open a file and write the object: • Open a file and read the object: root [1] MyClass a root [2] TFile f(“test.root”, “recreate”) root [3] a.Write(“a1”) root [4] f.Close() root [1] TFile f(“test.root”) root [2] MyClass *a = (MyClass*) f.Get(“a1”) root [3] f.Close() root [4] a->Dump() Introduction to ROOT

  42. ROOT Reflection Classes • Using the following meta or reflection classes you can find out everything about an object at run-time: Introduction to ROOT

  43. Using Reflection Classes root [0] TLine line root [1] TClass *c = line.IsA() root [2] TList *mlist = c->GetListOfMethods() root [3] TIter next(mlist) root [4] TMethod *m root [5] while (m = (TMethod*)next()) printf(“%s\n”, m->GetName()) root [6] mlist = c->GetListOfDataMembers() root [7] . . . Introduction to ROOT

  44. ROOT Beans { TLine *line = new TLine; line->SetX2(10); line->SetY2(20); line->Draw(); } { TClass *cl = gROOT->GetClass("TLine"); void *line = cl->New(); TMethod *m; m = (TMethod*) cl->GetListOfMethods()->FindObject("SetX2"); if (m) { // use m->GetListOfMethodArgs() to check argument types TMethodCall mc(cl, "SetX2", "10.0"); mc.Execute(line); } m = (TMethod*)cl->GetListOfMethods()->FindObject("SetY2"); if (m) { TMethodCall mc(cl, "SetY2", "20.0"); mc.Execute(line); } TMethodCall mc(cl, "Draw", ""); mc.Execute(line); } Introduction to ROOT

  45. ROOT Infrastructure & Basic Services ROOT Tutorials - Session 1

  46. The TObject Base Class • The TObject class provides default behavior and protocol for almost all objects in the ROOT system • It provides protocol for: • persistency (object I/O) • error handling • inspection • drawing, printing • sorting, hashing Introduction to ROOT

  47. The TROOT Class • The TROOT object is the main entry point to the system • It is created as soon as the Core library is being loaded • It initializes the ROOT system • It is a singleton, accessible via the global pointer gROOT • Via gROOT you can find basically every object created by the system • Provides many global services TH1F *hpx = (TH1F*) gROOT->FindObject(“hpx”) Introduction to ROOT

  48. ROOT Run Configuration File • When TROOT is created it also reads the rootrc files: • $ROOTSYS/etc/system.rootrc • ~/.rootrc • ./.rootrc • The local one overrides the less local one • It has the format of a typical “resource” file with a simple syntax • Have a look at $ROOTSYS/etc/system.rootrc to see what resources are supported Introduction to ROOT

  49. Operating System Interface • The underlying OS is abstracted via the TSystem abstract base class • Accessible via the gSystem singleton • It allows all ROOT and user codeto be OS independent Introduction to ROOT

  50. TSystem Services • TSystem provides: • System event handling • event processing and dispatching • signal handling (TSignalHandler) • file and socket handling (TFileHandler) • timer handling (sync, async) (TTimer) • Process control • fork, exec, wait, … • File system access • file creation and manipulation • directory creation, reading, manipulation Introduction to ROOT

More Related