Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Added section on exceptions in user modules

...

Code Block
# import is necessary to use return codes
import pyana

class ExampleModule(object):
  
    def event(self, evt, env):

        ...

        if pixelsAboveThreshold < 1000:
            # This event is not worth looking at, skip it
            return pyana.Skip

        if self.nGoodEvents > 1000:
           // we collected enough data, can stop now and go to endjob()
           return pyana.Stop

        if temperatureKelvin < 0:
            # data is junk, stop right here and don't call endJob()
            return pyana.Terminate

Anchor
ExceptionHandling
ExceptionHandling

Exception Handling

Pyana does not do anything special to handle exceptions which happen in user modules, main reason for this is that it is not safe in general to continue after unknown exception was raised. If user code knows which exception can be raised and is prepared to handle those exception then corresponding code should be added to the user module.

If user module generates an exception and does not handle it the whole job is terminated immediately. In single-process mode the standard traceback will printed by the interpreter and you should see clearly the reason and location of the exception. In multi-process mode (see #Multi-processing) the job will still fail but failure will look more complex. The original exception will cause termination of only a single worker process, the standard traceback for that exception will be printed as usual. The termination of one worker process will cause communication failure inside the main process which will terminate immediately with error message (Broken pipe). This in turn will cause exceptional failures of other worker processes which will print their own tracebacks. So instead of one single traceback for an exception there will be more than one error message appearing in the output.

Anchor
Configuration
Configuration

...

Short

Long

Config File

Option type

Default

Description

-v

--verbose

verbose

integer

0

Command line options do not need any values but can be repeated multiple times, configuration file option accepts single integer number.

-c file

--config=file

 

path

pyana.cfg

Name of the configuration file.

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="53488971cc8e5ab2-04f95f1b-4a4e4eef-a386951c-c4e7bf6134ebd13f7fe53b6f"><ac:plain-text-body><![CDATA[

-C name

--config-name=name

 

string

 

If non-empty string is given then configuration will be read from section [pyana.name] in addition to [pyana].

]]></ac:plain-text-body></ac:structured-macro>

-l file

--file-list=file

file-list

path

 

The list of input data files will be read form a given file which must contain one file name per line.

-n number

--num-events=number

num-events

integer

0

Maximum number of events to process, this counter will include damaged events too.

-s number

--skip-events=number

skip-events

integer

0

number of events to skip

-j name

--job-name=name

job-name

string

 

Sets job name which is accessible to user code via environment method. Default name is based on the input file names.

-m name

--module=name

modules

string

 

User analysis module(s). Command line options can be repeated several times, configuration file option accepts space-separated list of names.

-p number

--num-cpu=number

num-cpu

integer

1

Number of processes to run, if greater than 1 then multi-processing mode will be used.

...