Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
HEPdataanalysisusingROOT week4 § Compilingbinariesandlibraries § ROOTasadependency § Bindingstootherlanguages Week4 • Compilingbinariesandlibraries – fastercode – opAmalTTree::Branch()-ing • ROOTasadependency – includingROOTinyourowncode • Bindingstootherlanguages – PyROOT – theothers macroscompiledasbinaries • Ranacompiledmacrolastweek – usethe‘+’decoraAon $ root mathcoreVectorCollection.C+ Time for new Vector 0.113157 0.12 ****************************************************************************** *Tree :t1 : Tree with new LorentzVector * *Entries : 10000 : Total = 1854232 bytes File Size = 1667895 * • fromthecommandline(asabove) – orfromCINT root [1] .x mathcoreVectorCollectionC+ Compilinglibraries • CompilaAonproducesasharedobjectlibrary – youcanlinkanycodeagainstit • LibrariescanbeloadedintoCINT – andthemethodscalled root [0] gSystem->Load("mathcoreVectorCollection_C.so"); root [1] mathcoreVectorCollection() Time for new Vector 0.177571 0.12 ****************************************************************************** *Tree :t1 : Tree with new LorentzVector * *Entries : 10000 : Total = 1854232 bytes File Size = 1667862 * * : : Tree compression factor = 1.11 * Vectorbenchmarkingexample • WhatistheoverheadofusingSTLvectors and/orROOTcontainers? – comparedtousingbarearrays • TofillSTLvectorswithnonbasicdatatypes – mustcompiletheuserobject • Takealookat hTp://www.hep.shef.ac.uk/people/perkin/ containerBenchmarking.C Vectorbenchmarkingexample • Results array minimal TLVec array minimal TLVec array minimal TLVec minimal TLVec array array array vec vec vec vec push_back vec push_back vec push_back TClonesArray TClonesArray : : : : : : : : : : : Real Real Real Real Real Real Real Real Real Real Real Time Time Time Time Time Time Time Time Time Time Time = = = = = = = = = = = 0.03 0.05 0.08 0.03 0.03 0.04 0.04 0.04 0.04 0.12 0.11 seconds seconds seconds seconds seconds seconds seconds seconds seconds seconds seconds Cpu Cpu Cpu Cpu Cpu Cpu Cpu Cpu Cpu Cpu Cpu Time Time Time Time Time Time Time Time Time Time Time = = = = = = = = = = = 0.03 0.04 0.08 0.03 0.03 0.04 0.03 0.05 0.03 0.11 0.12 seconds seconds seconds seconds seconds seconds seconds seconds seconds seconds seconds • Now,fillaTTreewithresultsovermanytrials – howtodoit? BacktoTTree::Branch() • ROOTexpects… wriAngauserobject • Verylightweightexample – ‘PlainOldData’class Vectorbenchmarkingexample • Filluserobjectforeachtrial Vectorbenchmarkingexample • Filluserobjectforeachtrial Vectorbenchmarkingexample cpu time (s) • Results 10 10 3 2 arr m T a m T a m T m T ay inima LVec rray inima LVec rray inima LVec inima LVec l l l arr arr arr vec vec vec vec vec vec l TCl TCl ay ay ay pus pus pus ones ones h_b h_b h_b Arr Arr ack ack ack ay ay Aside:TTree::MakeClass • Reallyusefulmethod – AutomaAcallywritescodetoreadanyTTree root [4] benchTree->MakeClass() Info in <TTreePlayer::MakeClass>: Files: benchTree.h and benchTree.C generated from TTree: benchTree (Int_t)0 root [5] .q • Takealookat/runthefilesproduced – commentsinstructonusage • CancopewithmorecomplexTTreestoo Aside:TTree::MakeClass ROOTasadependency • i.e.compileabinarythatcallsROOT – useroot-config! • providespathtoincludesandlibraries – toseeallROOTconfiguraAons perkair:testMacros perkin$ root-config –config --prefix=/Users/perkin/t2k/ROOT/v5r34p18n02/Darwin-x86_64 --etcdir=/Users/perkin/t2k/ROOT/ v5r34p18n02/Darwin-x86_64 --disable-afs --disable-alien --disable-builtin-afterimage --enablebuiltin-ftgl --enable-builtin-freetype --enable-builtin-pcre --enable-builtin-zlib --disablecastor --disable-chirp --disable-cintex --disable-explicitlink --disable-fftw3 --enable-gdml -disable-gfal --disable-globus --disable-krb5 --disable-ldap --disable-monalisa --with-mysqlincdir=/Users/perkin/t2k/MYSQL/v5r051an01/Darwin-x86_64/include/mysql --with-mysql-libdir=/ Users/perkin/t2k/MYSQL/v5r051an01/Darwin-x86_64/lib/mysql --disable-odbc --disable-oracle -disable-pgsql --disable-pythia6 --disable-qt --disable-qtgsi --disable-reflex --enable-roofit --enable-minuit2 --disable-ruby --disable-rfio --disable-rpath --disable-sapdb --disableshadowpw --enable-soversion --disable-srp --disable-ssl --disable-table --enable-unuran -disable-winrtdebug --enable-gsl-shared --with-gsl-incdir=/Users/perkin/t2k/GSL/v1r15p0n00/ Darwin-x86_64/include --with-gsl-libdir=/Users/perkin/t2k/GSL/v1r15p0n00/Darwin-x86_64/lib HelloWorld perkair:testMacros perkin$ c++ $(root-config --cflags) -I$ROOTSYS/include -o dependencyTest.o -c dependencyTest.cxx perkair:testMacros perkin$ c++ $(root-config --cflags) $(root-config --libs) -I $ROOTSYS/include -o depTest dependencyTest.o clang: warning: argument unused during compilation: '-pthread' perkair:testMacros perkin$ ./depTest Hello World! Here's a random number: 0.977113 IllustraAvemakefile IllustraAvemakefile IllustraAvemakefile Bindingstootherlanguages • SofarhaveworkedwithC++bindingstoROOT – withcaveatofCINTisms/ROOTish • Whatotherbindingsareavailable – Fortran(legacy) – Python(whatIuseforanalysis) – Ruby – R pythoncompaAbility • Languagesupportnotenabledbydefault – pythonenabledforthisversiononhepcluster $ source /usr/local/root/5.32-00-py26/bin/thisroot.sh • CannowcallROOTfrominsidepython $ python Python 2.6.6 (r266:84292, Jul 22 2015, 16:47:47) [GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import ROOT >>> ROOT.gRandom.Rndm() 0.999741748906672 PyROOT • Whybother?! – implicittypingandgenerallymoreelegantsyntax – stringmanipulaAon • Easeofuseforplo]ngdata – TTree::Drawbasedcutsallstringbased • lessefficientforcodeexecuAon – but,pythonisagluinglanguage • shouldsAllruncompiledC/Fortran/MATLAB/whateverunderneath • HandlingofTClonesArraysofuserobjectsmuchneaterin python – variablesareuntyped • hence,notypedefs(totruncatethelong,longnames) • ordynamiccasAngs(ofretrievedobjects)arerequired PyROOTsnippets • pythonlistscancontainanything – andhaveneaterindexing >>> import ROOT >>> ROOT.gRandom.Rndm() 0.999741748906672 >>> myList = ['abc', 123, ROOT.gRandom] >>> print myList ['abc', 123, <ROOT.TRandom* object ("Random3") at 0x7fd04fdaedc0>] >>> myList[-1].Rndm() 0.16290987539105117 PyROOTsnippets • EasysorAng >>> myList.sort(key=lambda x : type(x)) >>> print(myList) [<ROOT.TRandom* object ("Random3") at 0x7fd04fdaedc0>, 123, 'abc'] >>> for l in myList: ... print type(l) ... <class 'ROOT.TRandom'> <type 'int'> <type 'str'> PyROOTsnippets • Argumentunpacking >>> def cat(a='',b=''): ... ... return a+b ... >>> s = ["abc","def"] >>> c = cat(*s) >>> c 'abcdef' >>> – neat! PyROOTsnippets • PyROOTknowstypeofobjects – don’thavetorecastTObjectintoderivedtype >>> import ROOT >>> f = ROOT.TFile.Open("containerBenchmarkingLoops.root") TClass::TClass:0: RuntimeWarning: no dictionary for class BenchmarkBranch is available >>> t = f.Get("benchTree") >>> type(t) <class 'ROOT.TTree'> >>> • Many,manymoreexamplesoutthere – takealook Closingremarks • Whistle-stoptourof – compilaAon,dependenciesandPyROOT • I’llemailoutmylinux/command-line cheatsheetlatertoday – usefuloneliners • AnyquesAons? end backups