TOC PREV NEXT INDEX

Gaudi logo


Chapter 6
Scripting
6.1 Overview

Gaudi scripting support is available in prototype form.The functionality is likely to change rapidly, so users should check with the latest release notes for changes or new functionality that might not be documented here.

6.2 Python scripting service

In keeping with the design philosophy of GAUDI, scripting is defined by an abstract scripting service interface, with the possibility of there being several different implementations. A prototype implementation is available based upon the Python scripting language. The Python scripting language will not be described in detail here, but only a brief overview will be presented.

6.3 Python overview

This section is in preparation.

6.4 How to enable Python scripting

Two different mechanisms are available for enabling Python scripting.

1. Replace the job options text file by a Python script that is specified on the command line.
2. Use a job options text file which hands control over to the Python shell once the initial configuration has been established.
6.4.1 Using a Python script for configuration and control

The necessity for using a job options text file for configuration can be avoided by specifying a Python script as a command line argument as shown in Listing 6.1.
Listing 6.1 Using a Python script for job configuration
myjob MyPythonScript.py [1]

Notes:

1. The file extension .py is used to identify the job options file as a Python script.All other extensions are assumed to be job options text files.

This approach may be used in two modes. The first uses such a script to establish the configuration, but results in the job being left at the Python shell prompt. This supports interactive sessions. The second specifies a complete configuration and control sequence and thus supports a batch style of processing. The particular mode is controlled by the presence or absence of Gaudi-specific Python commands described in Section 6.8.

6.4.2 Using a job options text file for configuration with a Python interactive shell

Python scripting is enabled when using a job options text file for job configuration by adding the lines shown in Listing 6.2 to the job options file.
Listing 6.2 Job Options text file entries to enable Python scripting
ApplicationMgr.DLLs += { "SIPython" }; [1]
ApplicationMgr.ExtSvc += { "PythonScriptingSvc/ScriptingSvc" }; [2]

Notes:

1. This entry specifies the component library that implements Python scripting. Care should be taken to use the "+=" syntax in order not to overwrite other component libraries that might be specified elsewhere.
2. This entry specifies the Python scripting implementation of the abstract Scripting service. As with the previous line, care should be taken to use the "+=" syntax in order not to override other services that might be specified elsewhere.

Once the initial configuration has been established by the job options text file, control will be handed over to the Python shell.

It is possible to specify a specific job options configuration file at the command line as shown in Listing 6.3.
Listing 6.3 Specifying a job options file for application execution
myjob [job options file] [1]

Notes:

1. The job options text file command line argument is optional. The file jobOptions.txt is assumed by default.
2. The file extension .py is used to identify the job options file as a Python script. All other extensions are assumed to be job options text files. The use of a Python script for configuration and control is described in Section 6.4.1.
6.5 Prototype functionality

The functionality of the prototype is limited to the following capabilities. This list will be added to as new capabilities are added:

1. The ability to read and store basic Properties for framework components (Algorithms, Services, Auditors) and the main ApplicationMgr that controls the application. Basic properties are basic type data members (int, float, etc.) or SimpleProperties of the components that are declared as Properties via the declareProperty() function.
2. The ability to retrieve and store individual elements of array properties.
3. The ability to specify a new set of top level Algorithms.
4. The ability to add new services and component libraries and access their capabilities
5. The ability to specify a new set of members or branch members for Sequencer algorithms.
6. The ability to specify a new set of output streams.
7. The ability to specify a new set of "AcceptAlgs", "RequireAlgs", or "VetoAlgs" properties for output streams.
6.6 Property manipulation

An illustration of the use of the scripting language to display and set component properties is shown in Listing 6.4:
Listing 6.4 Property manipulation from the Python interactive shell
>>>Algorithm.names [1][2]
('TopSequence', 'Sequence1', 'Sequence2')

>>> Service.names [3]
('MessageSvc', 'JobOptionsSvc', 'EventDataSvc', 'EventPersistencySvc', 'DetectorDataSvc', 'DetectorPersistencySvc', 'HistogramDataSvc',
'NTupleSvc', 'IncidentSvc', 'ToolSvc', 'HistogramPersistencySvc', 'ParticlePropertySvc', 'ChronoStatSvc', 'RndmGenSvc', 'AuditorSvc', 'ScriptingSvc', 'RndmGenSvc.Engine')

>>> TopSequence.properties [4]
{'ErrorCount': 0, 'OutputLevel': 0, 'BranchMembers': [],
'AuditExecute': 1, 'AuditInitialize': 0, 'Members':
['Sequencer/Sequence1', 'Sequencer/Sequence2'], 'StopOverride': 1,
'Enable': 1, 'AuditFinalize': 0, 'ErrorMax': 1}

>>> TopSequence.OutputLevel [5]
'OutputLevel': 0

>>> TopSequence.OutputLevel=1 [6]

>>> TopSequence.Members=['Sequencer/NewSeq1', 'Sequencer/NewSeq1'] [7]

>>> TopSequence.properties
{'ErrorCount': 0, 'OutputLevel': 1, 'BranchMembers': [],
'AuditExecute': 1, 'AuditInitialize': 0, 'Members':
['Sequencer/NewSeq1', 'Sequencer/NewSeq1'], 'StopOverride': 1,
'Enable': 1, 'AuditFinalize': 0, 'ErrorMax': 1}

>>> theApp.properties [8]
{'JobOptionsType': 'FILE', 'EvtMax': 100, 'DetDbLocation': 'empty',
'Dlls': ['HbookCnv', 'SI_Python'], 'DetDbRootName': 'empty', 'JobOptionsPath': 'jobOptions.txt', 'OutStream': [],
'HistogramPersistency': 'HBOOK', 'EvtSel': 'NONE', 'ExtSvc': ['PythonScriptingSvc/ScriptingSvc'], 'DetStorageType': 0, 'TopAlg': ['Sequencer/TopSequence']}
>>>

Notes:

1. The ">>>" is the Python shell prompt.
2. The set of existing Algorithms is given by the Algorithm.names command.
3. The set of existing Services is given by the Service.names command.
4. The values of the properties for an Algorithm or Service may be displayed using the <name>.properties command, where <name> is the name of the desired Algorithm or Service.
5. The value of a single Property may be displayed (or used in a Python expression) using the <name>.<property> syntax, where <name> is the name of the desired Algorithm or Service, and <property> is the name of the desired Property.
6. Single valued properties (e.g. IntegerProperty) may be set using an assignment statement. Boolean properties use integer values of 0 (or FALSE) and 1 (or TRUE). Strings are enclosed in "'" characters (single-quotes) or """ characters (double-quotes).
7. Multi-valued properties (e.g. StringArrayProperty) are set using "[...]" as the array delimiters.
8. The theApp object corresponds to the ApplicationMgr and may be used to access its properties.
6.7 Synchronization between Python and Gaudi

It is possible to create new Algorithms or Services as a result of a scripting command. Examples of this are shown in Listing 6.5:
Listing 6.5 Examples of Python commands that create new Algorithms or Services
>>> theApp.ExtSvc = [ "ANewService" ]
>>> theApp.TopAlg = [ "TopSequencer/Sequencer" ]

If the specified Algorihm or Service already exists then its properties can immediately be accessed. However, in the prototype the properties of newly created objects cannot be accessed until an equivalent Python object is also created. This restriction will be removed in a future release.

This synchronization mechanism for creation of Python Algorithms and Services is illustrated in Listing 6.6:
Listing 6.6 Examples of Python commands that create new Algorithms or Services
>>> theApp.ExtSvc = [ "ANewService" ]
>>> ANewService = Service( "ANewService" ) [1]
>>> theApp.TopAlg = [ "TopSequencer/Sequencer" ]
>>> TopSequencer = Algorithm( "TopSequencer" ) [2]
>>> TopSequencer.properties

Notes:

1. This creates a new Python object of type Sequencer, having the same name as the newly created Gaudi Sequencer.
2. This creates a new Python object of type Algorithm, having the same name as the newly created Gaudi Algorithm.

The Python commands that might require a subsequent synchronization are shown in Listing 6.7:
Listing 6.7 Examples of Python commands that might create new Algorithms or Services
theApp.ExtSvc = [...]
theApp.TopAlg = [...]
Sequencer.Members = [...]
Sequencer.BranchMembers = [...]
OutStream.AcceptAlgs = [...]
OutStream.RequireAlgs = [...]
OutStream.VetoAlgs = [...]

6.8 Controlling job execution

This is very limited in the prototype, and will be replaced in a future release by the ability to call functions on the Python objects corresponding to the ApplicationMgr (theApp), Algorithms, and Services.

In the prototype, control is returned from the Python shell to the Gaudi environment by the command in Listing 6.8:
Listing 6.8 Python command to resume Gaudi execution
>>> theApp.Go [1]

Notes:

1. This is a temporary command that will be replaced in a future release by a more flexible ability to access more functions of the ApplicationMgr.

This will cause the currently configured event loop to be executed, after which control will be returned to the Python shell.

Typing Ctrl-D (holding down the Ctrl key while striking the D key) at the Python shell prompt will cause an orderly termination of the job. Althernatively, the command shown in Listing 6.9 will also cause an orderly application termination.
Listing 6.9 Python command to terminate Gaudi execution
>>> theApp.Exit [1]

This command, used in conjunction with the theApp.Go command, can be used to execute a Python script in batch rather than interactive mode. This provides equivalent functionality to a job options text file, but using the Python syntax. An example of such a batch Python script is shown in Listing 6.10:
Listing 6.10 Python batch script
>>> theApp.TopAlg = [ "HelloWorld" ]
[other configuration commands]
>>> theApp.Go
>>> theApp.Exit



Quadralay Corporation
http://www.webworks.com
Voice: (512) 719-3399
Fax: (512) 719-3606
sales@webworks.com
TOC PREV NEXT INDEX