Outline
Introduction to the Python language Work our way through a typical job cong Input, modules and services, paths, output Available tools Not going back to refer back to old congs (some backup slides for that though)
Widely used language Object-oriented Nice syntax Lots of extensions Interfaces with C++ (boost, SWIG) Will be the only cong supported in upcoming CMSSW_2_1_0 Adds a lot of exibility for the user. So for you as well :-)
No C++ style memory management needed (has garbage collection) Things are usually passed by reference - Except native numbers and strings - Be careful about this Control ow based on indentation Comments start with a sharp (#) Will be the only cong supported in upcoming CMSSW_2_1_0
but lets forget about programming Python for now and see how the new congurations look like...
Most of the objects youll create will be of a CMS-specic type. To make them known to the interpreter you do:
!"#.$%&'().*%+,!"# $%&'() *%+,!"#" #$%&' /)&01 8/)&01 /)&@A 8/)&@A 7(8C=, C((= -&3/)D $#,& F)+8&*9D 52,)&F6 B/=,F)$9&' ()*%)'+#&' 2/)&01 28/)&01 2/)&@A 28/)&@A 27(8C=, 2-&3/)D E$#,& EF)+8&*9D E52,)&F6 &,&(-#+). $3(4,-#,;8,)4, $9&' 5)7$9&' #4',78=, #,;8,)4,$=94, '(=7,3 ' =7 *)!-/&' 56$3(784,3 56<)9=%>,3 56B/=&,3 5#$3(784,3 5##(834, #(834, #,4#(834, G((+,3 #,32/4, H8&+8&"(78=,
@
Conguration les I
Denition of terms: python module
A python le that is meant to be included by other les Placed in Subsystem/Package/python/ or a subdirectory of it CMS le name convention: Denition of a single framework object: _cfi.py A fragment of conguration commands: _cff.py A full process denition: _cfg.py To make your module visible to other python modules: Be sure your SCRAM environment is set up Go to your package and do scram b or scram b python Needed only once Correctness of python cong les is checked on a basic level every time scram gets used. Currently only counting as warnings try Configuration/StandardSequences
Conguration les II
Denition of a cfg le
Controls the nal job to be run Contains a cms.Process object named process File name convention: _cfg.py Usually placed in a packages python/or test/ Can be checked for completeness (from the cong point of view) doing
python myExample_cfg.py
cmsRun myExample_cfg.py
Process
process = cms.Process(RECO)
An input source
process.photons = cms.EDProducer(JetProducer)
Some services
process.tracer = cms.Service(Tracer)
Some execution paths
process.out = cms.OutputModule(...
Even full processes can be imported from elsewhere
10
To fetch all modules from some other module into local namespace
import Subsystem.Package.Foo_cff as foo With foo.a and foo.b you can now access the objects
Dont forget that all imports create references, not copies: changing an object at one place changes the object at other places
11
Cloning
Sometimes you need to add a module which has almost the same parameter as another one You can copy the module and change the parameters that need to be modied
Changing while cloning should be preferred wrt clone + later replace as it is a much safer practice.
12
To load everything from a python module into your process object you can say:
process.load(Subsystem.Package.Foo_cff)
13
Framework Modules
EDProducer - add objects into the event EDAnalyzer - analyze objects from the event EDFilter - can stop an execution path and put objects into the event EDLooper - For multi-pass loopng over events OutputModule - Write events to a le. Can use lter decisions
14
Framework Services
Examples of Framework Services are - geometry, calibration, MessageLogger Types are: - ESSource Provides data which have an IOV (Interval of Validity) - ESProducer Creates Products when IOV changes - Service Not IOV dependend. E.g. MessageLogger In case of conicts preference can be changed with ESPrefer:
es_prefer_trackerAlignment = cms.ESPrefer("PoolDBESSource","trackerAlignment")
15
Give the PSet name directly after module type Has to happen before the named parameters
16
Path
EndPath A list of analyzers or output modules to be run after all paths have been run
outpath = cms.EndPath(myOutput)
Schedule Denes the execution order of paths. If not given rst all paths, then all endpaths.
process.schedule = cms.Schedule(process.p1, process.outpath)
17
Sequence operators
+ as follows Use if the input of the previous module/sequence is not required
* as depends on
18
Filters in Paths
When an EDFilter is in a path, returning False will cause the path to terminate Two operators ~ and - can modify this. ~ means not. The lter will only continue if the lter returns False. Text - means to ignore the result of the lter and proceed regardless jet500_1000 = cms.Path( ~jet1000filter + jet500filter + jetAnalysis )
19
Tracked / Untracked
Tracked parameters Parameters that change the content of the event Will be saved in the event data provenance
Cannot be optional - if asked for and not found, exception will be thrown - constructs to circumvent this policy are highly discouraged
a = cms.double(3.0)
Untracked parameters Parameters that dont affect the results, e.g. debug level Can have default values - So theyre used for optional parameters, but not really considered safe practice.
a = cms.untracked.double(3.0)
20
Modifying parameters
process.foo.threshold = 4.0
If the right hand side of the expression is a CMS type, a new parameter can be created
# this line will fail because g4.SimHits.useMagmeticField = # this line will create a new # with wrong name g4.SimHits.useMagmeticField =
21
Standard congs in the release have been translated centrally In FWCore/ParameterSet/python there are
translate.py
- creates a python le based on your cong le - creates any included les which may be needed
comments.py
Another tool is edmTestCfgTranslation - translates your cong - tests whether the old and the new ParameterSets as read in by the SW framework match
22
Tools I
edmPythonSearch
23
Tools II
edmPythonTree
Gives an indended dump of which les are included by which les (initial version for the old congs by Karoly Banicz and Sue Anne Koay)
24
Tools III
python
The Python interpreter helps you inspecting your congs > python -i Reconstruction_cff
Try it out!
25
Look at what the automatic translation spits out There is a twiki page in the SWGuide:
https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideAboutPythonConfigFile
In case of questions and comments send an e-mail to hn-cms-edmFramework Experts are distributed over different time zones Have fun!
26
Backup
27
Plugin types
old cong
source
python cong
Source EDAnalyzer
module
Reminder: Since 1_5_0 there are stricter rules what kind of modules are allowed in Paths and EndPaths!
28
old cfg
29
include "RecoJets/JetProducers/data/CaloTowerSchemeB.cfi"
no data
30
Using blocks
old cong
block Record = { untracked string composer = Beethoven }
Python cong
Record = cms.PSet( composer = cms.untracked.string( Beethoven ) )
31
A basic example
old cong
process = foo { [...] module udsfilter = JetFilter{ ...} module jets = JetReco{ ...} process.jets = cms.EDProducer("JetReco",...) [...] replace udsfilter.jetType = 2 [...] path mypath = (jets, udsfilter) [...] process.udsfilter.jetType = 2 [...] process.mypath = cms.Path(process.jets*udsfilter)
python cong
process = cms.Process("foo") [...] udsfilter = cms.EDFilter("JetFilter",...) process.udsfilter = udsfilter
$ cmsRun config.cfg
$ cmsRun config_cfg.py
32
Replace statements
old cong
module udsfilter = JetFilter{ ...} replace udsfilter.jetType = 2
python cong
udsfilter = cms.EDFilter("JetFilter",...) udsfilter.jetType = 2
33
module foo = SomeFilter { double MeanX = double MeanY = double MeanZ = untracked bool
0. 0. 0. log = true}
34
Module conguration
old cong
type name = value
Python
name = type( value )
foo = EDFilter(FooFilter)
process.foo = EDFilter("SomeFilter", MeanX = double(0), MeanY = double(0), MeanZ = double(0), log = untracked.bool(True))
module foo = SomeFilter { double MeanX = double MeanY = double MeanZ = untracked bool
0 0 0 log = true}
35