/
Tutorial for the 	 	SNiPER Framework Tutorial for the 	 	SNiPER Framework

Tutorial for the SNiPER Framework - PowerPoint Presentation

alis
alis . @alis
Follow
31 views
Uploaded On 2024-02-02

Tutorial for the SNiPER Framework - PPT Presentation

Zou Jiaheng Lin Tao Huang Xingtao Li Weidong 20180513 Content 2 General introduction Key concepts Running the HelloWorld Offline Software Environments Programming language hybrid programming of C and Python ID: 1044000

cmt task event data task cmt data event software algorithm juno python create ihep incident string run code execution

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "Tutorial for the SNiPER Framework" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

1. Tutorial for the SNiPER FrameworkZou Jiaheng, Lin Tao, Huang Xingtao, Li Weidong2018-05-13

2. Content2General introductionKey conceptsRunning the HelloWorld

3. Offline Software EnvironmentsProgramming language: hybrid programming of C++ and PythonVery popular in HEP fieldMost frequently used software is implemented in C++ (ROOT, Geant4 …)Job configuration interface: PythonVery flexibleEasy to glue different tools together (Job scheduling, Monitoring …)Packages management tool: CMT(Configuration Management Tool)Help developers to compile packages easilyHelp users to setup the environment for running the application easilySupported Operation System: LinuxOfficial recommendation: Scientific Linux 6 / CentOS 7Some colleagues compile successfully on Ubuntu, Debian …Codes Management: SVNKeep the history of code evolutionSynchronization and sharing between developersTag and release3

4. Overview of JUNO Offline Software4SNiPER (Software for Non-collider Physics ExpeRiment) GeneratorAnalysisSimulationCalibrationReconstructionoffline External Libraries (EI)Root CLHEP BoostGeant4 Python……JUNOSNiPER: the underlying FrameworkOffline: extension of SNiPER and applications for JUNOExternal Libraries(EI): very frequently used software and tools

5. Software FrameworkWhat’s an offline software framework?A framework helps users to write as less code as possible to achieve their goalsWhat does a framework provide?Management of Event DataInterfaces to define, read, access and write event dataManagement of data processingSequence and/or filtering of algorithmsCommon services and tools for data processingHistogramSvc, RandomSvc, DatabaseSvc …Friendly user interfaceSimple interfaces for coding: abstract base classes for algorithms and servicesSimple interfaces for running: configure jobs via text, python …5

6. Software Framework for JUNOSNiPER: Software for Non-collider Physics ExpeRimentMain goalsLightweight, less dependences on third-party software/libsFast and flexible executionEasy to learn and convenient to useDesign and developmentLearn a lot from other software frameworks, such as GaudiBased on the valuable experiences of Daya Bay ExperimentCoding from scratchCurrent StatusPerforms well for JUNO (and LHAASO, a cosmic ray exp. in China)Several other projects and potential users (CSNS, nEXO …)6

7. Key Functionalities of FrameworkDynamically loading packages and elementsUser’s packages can be executed as pluginsIt is easy to customize a jobFlexible executionTask, TopTask, IncidentVery useful for event splitting and mixingEvent management in memoryMultiple events within time windows accessibleVery convenient for events correlation analysisParallel computing (will come soon)7

8. Working with SNiPER8SNiPER In an User Algorithm:get data from memoryexecute calculationput results back to memoryI/O: disk, DB, network, grid…Collect algorithm resultsPrepare data to be processedfeatures such asgeometry …No need to care where the data comes fromNo need to care where the data will goUser’s Application LayerCore Software LayerPython UI Layerrun a batch job or interactively debug a module

9. Key ConceptsDLElement: Dynamically Loadable ElementAlgorithmServiceTaskToolData BufferIncidentPropertyLog (message output)9Each DLElement object has a unique string name

10. AlgorithmAn unit of codes for Data Processingthe calculation during event loopMost frequently used by usersAlgBase, the abstract base class in SNiPERUser’s algorithm must be inherited from AlgBaseIts constructor takes one std::string parameter3 abstract interfaces must be implemented, they are called by SNiPER automaticallybool initialize() : called once per Task (at the beginning of a Task)bool execute() : called once per Eventbool finalize() : called once per Task (at the end of Task)We will show how to create an algorithm later10

11. ServiceSimilar with AlgorithmAn Dynamically Loadable ElementOne Task probably composes of one or more servicesBut different from AlgorithmA piece of code for common use (RootIOSvc, GeometrySvc …)They are called by user’s request, not limited to event loopSvcBase, the abstract base class in SNiPERA new service must be inherited from SvcBaseIts constructor takes one std::string parameter2 abstract interfaces must be implementedbool initialize() : called once per Task (at the beginning of a Task)bool finalize() : called once per Task (at the end of Task)We will show how to create a service later11

12. TaskA lightweight traditional Application ManagerManagement of algorithms, services and tasksControlling the execution of algorithmsHas its own data memory managementHas its own I/O managementOne job can has more than one Tasks(e.g. event mixing)All DLEs are organized in a tree structure12TopTaskAlgorithmTaskServiceServiceServiceAlgorithmAlgorithmTaskTaskAlgorithmServiceServiceServiceAlgorithmAlgorithm

13. Data Processing with TaskTask means the event processing procedure (event loop)SubTask provides nested event loopIt will be executed on demandTask and SubTask provide more flexible executionMeet the requirements of Event Mixing and Event SplittingMulti-Thread Computing (run each task in an individual thread)Task is a FSM (finite-state machine)StartupReadyRunningFinalizedEndup13Algorithm 4Algorithm 5Executed on DemandAlgorithm 1Algorithm 2Algorithm 3Event LoopAlgorithm 6Executed on DemandTopTaskSubTaskSubTask

14. Task Status14

15. ToolTool is also a Dynamically Loadable ElementIt belongs to an algorithm and helps the algorithm to organize code more clearlyOne algorithm can have one or more toolsA tool can be accessed via its name15

16. Data BufferData Buffer is the dynamically allocated memory place to hold events data which are being processedApplications (in terms of algorithms) get events data from the buffer and update them after processing16

17. Data Buffer in Memory1701234567EvtNum: 0 1 2 3 4 5 6 7Exe NumCurrent eventEvent bufferOther eventsBuffer: a sequence of events in a time windowcorrelation analysis of events in buffer

18. Incident18Provides an additional degree of execution freedom: Incident: trigger the execution of corresponding handlers IncidentHandler: the wrapper of any specific procedureRegular execution procedure jumps to another extra procedureBack to the original procedure after all corresponding Handlers are executedIncidentstring name()fire()IIncidentHandlerhandle(Incident&)regist(string)IIncidentHandlerhandle(Incident&)regist(string)1, fire()2, handle()Regular ProcedureExtra ProcedureBoth Algorithms and Services can fire incidents according to their needs

19. Incident Management19Incidentstring name()fire()IIncidentHandlerhandle(Incident&)regist(string)handle(Incident&) HandlerHandlerHandlerHandlername1name2IncidentMgrIncident::name() IncidentMgr correlates incidents with their handlers Incidents are distinguished by its name, such as “BeginEvent”, “EndEvent” One IncidentHandler can be registered to several Incidents One Incident can be handled by several IncidentHandlersCurrently Event I/O and SubTask execution are based on incident mechanism

20. Property20Configurable variable at run timeDeclare a property in DLElement (C++ code)Configure a property in Python scriptThis mechanism is also used to create and load algorithms and services:Types can be declared as properties:scalar: C++ build in types and std::stringstd::vector with scalar element typestd::map with scalar key type and scalar value type

21. Log Mechanism21SniperLog: a simple log mechanism supports different output levels0: LogTest2: LogDebug3: LogInfo4: LogWarn5: LogError6: LogFatalEach DLElement has its own LogLevel and can be set at run time very helpful for debuggingThe output message includes more informationwhere it happensthe message levelThe message contents

22. HelloWorld (I)22The HelloWorld algorithm in SNiPER@ Examples/HelloWorldconfiguration of the Tasksvn co http://juno.ihep.ac.cn/svn/sniper/trunk/Examples/HelloWorld

23. HelloWorld (II)23Configuration of the algorithm properties

24. HelloWorld (III)24Run the Task

25. 25Create an Algorithm and a ServicePackage managementC++ and Python codingCMT configurationCompile and runAdvanced topic: a job with multiple-taskssvn co http://juno.ihep.ac.cn/svn/juno/people/zoujh/example/FirstToy

26. PreparationSetup the official release environment$ source ~/juno-dev/setup.shCreate your own project$ cmt create_project Tutorial$ cd Tutorial$ vi cmt/project.cmt ( use offline)$ vi cmt/version.cmt ( v0)Create your own package$ cmt create MyPackage v0$ source MyPackage/cmt/setup.sh26ExternalLibssniperofflineUser’s ownprojectOfficial Software ReleaseUsers’ own code (workspace)

27. Package ManagementCreate a new package with CMT$ cmt create TestAlg v0Orgnization of subdirectory and filesSubdirectory cmt/File requirements: tell CMT how to setup and compile this packageSubdirectory src/: the directory for source code (C++)Subdirectory FirstAlg: an optional directory for header files to shareSubdirectory python/: an optional directory for python codeSubdirectory share/: an optional directory for scripts of tutorialSubdirectory Linux-x86_64 or anything like this: the compiling results that automatically generated by CMT27

28. Coding and RunningFirstToy C++FirstAlg, our first algorithmShow different level of logsFirstSvc, our first serviceA string message as property (can be modified in python)An interface to print the string message (answer())SecondAlgCall the service in an algorithmFirstToy PythonComple and run the example$ cmt make ## in any subdirectory of the package (cmt/ recommended)$ python run.py ## details in run.py28vs.

29. CMT ConfigurationThe package name and authorpackage SecondAlgAuthor Zou Jiaheng <zoujh@ihep.ac.cn> ## optionalDependencies while compilinguse SniperKernel v*use FirstSvc v* FirstToyHow to generate the .so library filelibrary SecondAlg *.ccapply_pattern linker_library library=SecondAlg ##Whether load all dependencies automatically while loading this library. Some times it is not necessaryCopy C++ headers and Python into CMT InstallAreaapply_pattern install_more_includes more=FirstSvc ## unnecessary if no shared headersapply_pattern install_python_modules29

30. Advanced Topic: multiple-tasks jobThe DLElement Map of ThirdAlg + SecondAlg + FirstSvc + Task30[ThirdAlg]TomCatEvent Loop[SecondAlg]TomcatOdd execution of toy::TomCat[SecondAlg]TomcatEven execution of toy::TomCat[Task] toy[Task] GoTask[Task] ChessTaskSubTask(s) are executed on demandDetails can be found in ThirdAlg of FirstToy

31. 31Thanks !Any questions?

32. AccountsAFS (IHEP computer cluster) accounthttp://afsapply.ihep.ac.cn:86/ccapply/userapplyaction.actionJUNO SVN accountWe use subversion as the version control systemA public read only account: juno/jiangmenA personal account is necessary for updating purposeRegister an account in juno trac first: http://juno.ihep.ac.cn/trac/Send email to lintao@ihep.ac.cn or maqm@ihep.ac.cnYour user name in tracYour affiliation (institute or university)32

33. Possible Use Cases of Multi-Task Job331, Multi I/O streams, such as background mixing create a Task for each I/O stream each Task holds its own data memory each Task handles only one Input (and Output) stream I/O service can be much simplified 3, Multi-Thread Computing (run each task in an individual thread)2, Event amount changed, such as IBD simulation(Gen)Task(Sim)TaskGenAlgSimAlgTriggerGenAlgSimAlg…Incidentupdatene+ + N