350 likes | 508 Views
Using SCons for DAMPE software. Chi Wang ( chiwang@mail.ustc.edu.cn ) Ruirui Fan( fanrr@ihep.ac.cn ) Xin Wu( Xin.Wu@cern.ch ) 8/5/2013. What is SCons. SCons ( S oftware Cons truction ) a software construction tool a superior alternative to the “Make” build tool.
E N D
Using SCons for DAMPE software Chi Wang (chiwang@mail.ustc.edu.cn) RuiruiFan(fanrr@ihep.ac.cn) XinWu(Xin.Wu@cern.ch) 8/5/2013
What is SCons • SCons(Software Construction) • a software construction tool • a superior alternative to the “Make” build tool. • written using Python • created in 2000 by Steven Knight Steven Knight DAMPE software meeting
Why we use SCons SCons - Basic language: python - Execute the command: scons - at where there is a file : SConstruct - Noneed to define a “clean” target! scons -c Make - Basic language: shell - Execute the command: make - at where there is a file : Makefile Or GNUmakefile - Need to define “clean” target make clean Example: 2 files in ${PWD} SConstruct Helloworld.cc just one line in SConstruct : Program(‘main’,‘Helloworld.cc’) Run: scons will create the executable file main powerful and flexible Anything that can be done in a Python script can be done in an SCons script DAMPE software meeting
How to Install SCons • Requirement Install python ( version 2.4 or later) • Then install SCons • Download at http://www.scons.org/download.php • Untar it, and install it refer to README.txt DAMPE software meeting
Key Concepts of SCons • Hierarchical builds (**how to build a big project) • Environment (important) • Create executable file • Create and use shared library • File System Manipulation • Install our software goals Install Example: /WhereIsDAMPESW/Simulation/SConstruct /WhereIsDAMPESW/SConstruct DAMPE software meeting
Key Concepts of SCons • Hierarchical builds (**) • Environment • Create executable file • Create and use shared library • File System Manipulation • Install our software DAMPE software meeting
Hierarchical builds (a) • SCons: Hierarchical builds • Execute begins from the file named “SConstruct” (unique name) at current directory. • Could call “SConscript” (any name) in subdirectory • Example, add this line in SConstruct: SConscript([‘’subdir1/SConscript,’subdir2/SConscript’]) • Two ways to build DAMPE software • Whole DMPSW • Use SConstruct at top-level directory of DAMPE software • Will call SConscript at each module • Then call SConscript at each sub-detector • Certain Module of DMPSW • Use SConstruct at top-level diectroy of each module • Will call SConscriptat each sub-detector DAMPE software meeting
Hierarchical builds (a) DAMPE software meeting
Hierarchical builds (b) • Structure of DAMPE software • Key points: • (1) Module independent, only data exchange between different modules Whole DMPSW execute command “scons”at here Green(DmpRDC): create executable file in /prefix/install/bin/ Brown(Geometry): file only as input, copy into /prefix/install/share/ Light brown(Callibration): create shared library in /prefix/install/lib/ copy all need header file into /prefix/install/include/ DAMPE software meeting
Hierarchical builds (c) • Structure of DAMPE software • Key points: • (2) All sub-detectors in each module are independent to each other Simulation module of DMPSW execute command “scons”at here create executable file DmpSimulationin /prefix/install/bin/ DAMPE software meeting
Key Concepts of SCons • Hierarchical builds (**) • Environment • Create executable file • Create and use shared library • File System Manipulation • Install our software DAMPE software meeting
Environment • External Environment • the set of variables in the user‘s environment • Linux variables ($PATH) or command (ls //executable file in $PATH) • Construction Environment • decides what action to use to build a target (where is the include files?) • Execution Environment • the values that SCons sets when executing an external command (such as a compiler or linker) DAMPE software meeting
Environment (a) • External Environment • Create a new Environment Import os SimuEnv=Environment(ENV=os.envrion) # name this environment. Support multi-environment in one file • Environment variables of linux g4sys=os.environ[‘G4INSTALL’] # comment begin of # • Linux command SimuEnv.ParseConfig(‘geant4-config --cflags --libs’) #execute command “geant4-config –-c… --libs “, and output as as Construction environment • Construction Environment • Execution Environment DAMPE software meeting
Environment (b) • External Environment • Construction Environment for key in [‘Dmp’,’Psd’,’Stk’,’Bgo’,’Nud’]: includeDir=key+’Simulation/include’ #begin with a table in for SimuEnv.Prepend(CPPPATH=[includeDir]) # add all header files of sub-detector • Execution Environment DAMPE software meeting
Environment (c) • External Environment • Environment variables of linux g4sys=os.environ[‘G4INSTALL’] • Construction Environment • Execution Environment SimuEnv.PrependENVPath(‘PATH’,g4sys+/’bin’) # add new path to $PATH temporary DAMPE software meeting
Key Concepts of SCons • Hierarchical builds (**) • Environment • Create executable file • Create and use shared library • File System Manipulation • Install our software DAMPE software meeting
Create executable file or shared library • Create executable file execute=SimuEnv.Program(‘DmpSimu’,Glob(‘./*/src/*.cc’)) # wildcard * for all sub-detector • Create shared library sharedlibs=env.SharedLibrary(‘DmpRec’,Glob(’./*/src/*.cc’)) # create the libDmpRec.so • Use created library Env.Append(LIBPATH=‘/whereIsDMPSW/lib’) # where can find lib Env.Append(LIBS=‘DmpRec’) # which lib DAMPE software meeting
Key Concepts of SCons • Hierarchical builds (**) • Environment • Create executable file • Create and use shared library • File System Manipulation • Install our software DAMPE software meeting
File System Manipulation • Install DMPE software • Where and What will install 1) Install in the directory “Install” (untar DAMPE software you will see it, at where Simulation module is). Just for convenience. We can separate Install path from develop path future. 2) What :ls -R /prefix/Install/ bin (dmpsw-configDmpSimulationDmpRDCDmpEventDisplay) Include (all needed header files) lib (libDmpReconstructionlibDmpCalibration other Lib) share (Geometry or_others) database (hex raw rec caldst) • How to install (more details in README in your untared directory of DAMPE software) • Mkdir() subDir=[] # using list is better than using string for key in [‘bin’,’lib’,’include’,’share’]: subDir=subDir+[‘Install’+key] Execute(Mkdir(subDir)) DAMPE software meeting
Key Concepts of SCons • Hierarchical builds (**) • Environment • Create executable file • Create and use shared library • File System Manipulation • Install our software DAMPE software meeting
Install our software • Install (into prefix (where has sub-directory like p8)) SimuEnv.Install(‘/prefix/bin’,execute) # execute was defined in p17 • InstallAs • If the directory where you want to install execute file is a subdirectory of the directory where you run command scons, use SimuEnv.InstallAs(‘/prefix/bin/DmpSimulation’,execute) is OK. If not, use this: Default(SimuEnv.InstallAs(‘/prefix/bin/DmpSimulation’,execute)) DAMPE software meeting
Install our software (REAMDE in top-level directory of DMPSW) • 1) Requirement • 2) source setup • source thisdmpsw.sh • 3) Install • 3.1 install ALL modules the first time execute command "scons" at current directory(there's a file named SConstruct) • 3.2 install certain module while developing cd into certain module directory execute "scons" //re-install certain module • 4) Set environment variables (not need to do 2) every time) • Add following lines into your .bashrc(OR .zshrc) #+ Set DAMPE software environment if [ ! $DMPSWSYS ];then export DMPSWSYS="where/you/untar/OpenDmpSoftware“ export PATH=$DMPSWSYS/Install/bin:$PATH export LD_LIBRARY_PATH=$DMPSWSYS/Install/lib:$LD_LIBRARY_PATH fi #+ DAMPE software meeting
using of DMPSW (future) • Same as Root(or Geant4) • dmpsw-config file in /prefix/Install/bin • After sourcing thisdmpsw.sh, you can • Use dmpsw-configas the same of using root-config(or geant4-config) • Env.ParseConfig("root-config --cflags --libs") • Env.ParseConfig("geant4-config --cflags --libs") • Env.ParseConfig(“dmpsw-config--cflags --libs") # set construction environment of using dmpsw, one day we will use our libraries. DAMPE software meeting
Summary • Introduction of SCons • DAMPE software structure (current) and how we set multi-level of SCons files • Some important syntax of SCons file • Environment • Create executable file • Create and use shared library • File System Manipulation • Simple installment design of our software • Refer to README in top-level directory ofDMPSW DAMPE software meeting
Where to find more details • User guide http://www.scons.org/doc/HTML/scons-user.html Chapter 2 (simple example) Chapter 4 (create and use library) Chapter 7 (environment) Chapter 14 (Hierarchical builds ) Chapter 12 (File system manipulation) Chapter 15 (Separate temporary files) • FAQ http://www.scons.org/wiki/FrequentlyAskedQuestions • Google • SCons files to build DAMPE software http://dpnc.unige.ch/SVNDAMPE/DAMPE/OpenDmpSoftware/trunk/ DAMPE software meeting
Develop modules with red line DAMPE software meeting
Long term plan? • If we want to use DMPSW for the next whole system cosmic test or beam test, then we should care about the situation of the hardware. • Each sub-detector system • Schedule (hardware)? • Event format of detector ouput? • Event format of RDC output? • Example of BGO (for both compression mode and non-compression mode) Int_tfNSignal; //max=2016=(22+2)*3*2*7*2=(barNb+refBarNb)*DyNb*SideNb*PlaneNb*Layer Float_tfADC[fNSignal]; Short_tfLayerID[fNSignal]; Short_tfBarID[fNSignal]; Short_tfSideID[fNSignal]; Short_tfDyID[fNSignal]; • Event format for distribution? DAMPE software meeting
Other questions • The confirmed output of each module • For example, Generation part: • what’s the output of Generator? • How will it be used by Simulation (interface)? DAMPE software meeting
Thank you DAMPE software meeting
Backup DAMPE software meeting
DAMPE software modules DAMPE software Geometry Simulation (DmpSimulation) Calibration Generation Reconstruction Visualization (DmpEventDisplay) Distribution data Detector Data Raw Data Conversion (DmpRDC) Analysis environment DAMPE Meeting, Beijing, 28-29/07/2013
Simulation module Geometry Simulation (DmpSimulation) Generation DmpSimulation PsdSimulation StkSimulation BgoSimulation NudSimulation DAMPE software meeting