Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Include Page
PSDM:Related_Topics_Div_Open
PSDM:Related_Topics_Div_Open

Recommended Next Topics

Include Page
PSDM:Related_Topics_Div_Close
PSDM:Related_Topics_Div_Close
Include Page
PSDMPSDMInternal:PageMenuBeginPSDMInternal
PSDM:PageMenuBegin
Table of Contents
Include Page
PSDMInternalPSDM:PageMenuEndPSDMInternal
PSDM:PageMenuEnd

Introduction

Offline analysis software for LCLS data historically pass a few stages;

Data types and access methods

...

Constructor arguments and configuration data

Pyana

Original pyana design used constructor arguments to pass configuration parameters to user modules. Typical user module defined its __init__ method with a number of arguments with many or all of them having default values:

Difference in configuration file

Configuration file in both frameworks is starting from section pyana or psana modules followed by the list of parameters. The list of parameters is different for historical reasons. When python modules are designed to support both frameworks, both sections may be presented in the same configuration file. Alien section is ignored at run time of each framework. Example of these sections in the same configuration file:

Code Block
bgColor#AAFFFF

[pyana]
files  = /reg/d/psdm/xcs/xcs72913/xtc/e265-r0049-s00-c00.xtc /reg/d/psdm/xcs/xcs72913/xtc/e265-r0049-s04-c00.xtc /reg/d/psdm/xcs/xcs72913/xtc/e265-r0049-s05-c00.xtc
num-events = 500
#skip-events = 0
#num-cpu = 1
verbose = 1
modules = py_img_algos.tahometer py_img_algos.cspad_arr_producer py_img_algos.cspad_image_producer py_img_algos.image_save_in_file

[psana]
files = exp=xcs72913:run=49
events = 500
Code Block

class user_module(object):

    def __init__(self, source, threshold="0.25", max_count="1000"):
        self.source = source
        self.threshold = float(threshold)
          
#skip-events =  self.max_count = int(max_count)

The arguments that do not provide default values must be specified in the configuration file, arguments with the default values can be overriden by the values from configuration file. Suppose that configuration files contains this:

Code Block

[user_package.user_module]
source = SrcString
threshold = 1.25

Then psana will instantiate user module with the parameters user_module(source="SrcString", threshold="1.25") and max_count argument will use default value from method declaration. Note that all arguments are passed as string values, no conversion to integers or floating point numbers is performed.

Starting with the release ana-0.9.6 pyana was modified to support different style of access to configuration information. In addition to receiving configuration parameters through constructor arguments one can also use few special methods of the module class to obtain the values of the parameters. These methods are:

0
modules = py_img_algos.tahometer py_img_algos.cspad_arr_producer py_img_algos.cspad_image_producer py_img_algos.image_save_in_file

A few differences can be clearly seen:

  • psana accepts both forms for files, pyana - only explicit list of files.
  • Parameter for number of events has different name events and num-events for psana and pyana, respectively.
  • verbose mode currently works for pyana only. Logger does not have interface in psana yet.
  • psana currently does not support multiprocessor mode num-cpu.

Constructor arguments and configuration data

Pyana

Original pyana design used constructor arguments to pass configuration parameters to user modules. Typical user module defined its __init__ method with a number of arguments with many or all of them having default values:

Code Block

class user_module(object):

    def __init__(self, source, threshold="0.25", max_count="1000"):
        self.source = source
        self.threshold = float(threshold)
        self.max_count = int(max_count)

The arguments that do not provide default values must be specified in the configuration file, arguments with the default values can be overriden by the values from configuration file. Suppose that configuration files contains this:

Code Block

[user_package.user_module]
source = SrcString
threshold = 1.25

Then psana will instantiate user module with the parameters user_module(source="SrcString", threshold="1.25") and max_count argument will use default value from method declaration. Note that all arguments are passed as string values, no conversion to integers or floating point numbers is performed.

Starting with the release ana-0.9.6 pyana was modified to support different style of access to configuration information. In addition to receiving configuration parameters through constructor arguments one can also use few special methods of the module class to obtain the values of the parameters. These methods are:

self.configBool(param_name[,default])

returns value of parameter as a boolean value, strings "yes", "true", "True", "on", "1" represent true value, strings "no", "false", "False", "off", "0" represent false value, any other string will raise exception. If parameter is not defined in a file then default value is returned without conversion, if default value was not given then exception is raised.

self.configInt

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="6c0f501d-eee6-46eb-b14a-20d6185c6bb6"><ac:plain-text-body><![CDATA[

self.configBool(param_name[,default])

returns value of parameter as a boolean value, strings "yes", "true", "True", "on", "1" represent true value, strings "no", "false", "False", "off", "0" represent false value, any other string will raise exception. If parameter is not defined in a file then default value is returned without conversion, if default value was not given then exception is raised.

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

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="70b6bfd6-f47a-4b77-972f-ed40ad100cac"><ac:plain-text-body><![CDATA[

self.configInt(param_name[,default])

returns value of parameter as integer value. If parameter is not defined in a file then default value is returned without conversion, if default value was not given then exception is raised. If conversion from string to integer fails the standard exception is raised.

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

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="362fce22-1b6a-4ea6-a642-d9f7a9dcd51d"><ac:plain-text-body><![CDATA[

self.configFloat(param_name[,default])

returns value of parameter as floating point integer value. If parameter is not defined in a file then default value is returned without conversion, if default value was not given then exception is raised. If conversion from string to floating point integer fails the standard exception is raised.

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

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="7d53ec72-7fbc-46fb-b71e-5a0cf9251a63"><ac:plain-text-body><![CDATA[

self.configStrconfigFloat(param_name[,default])

returns value of parameter as stringfloating point value. If parameter is not defined in a file then default value is returned without conversion, if default value was not given then exception is raised.

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

If conversion from string to floating point fails the standard exception is raised.

self.configStr(param_name[,default])

returns value of parameter as string. If parameter is not defined in a file then default value is returned without conversion, if default value was not given then exception is raised. <ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="8be64a20-d113-4f98-94af-2305c55fa2f6"><ac:plain-text-body><![CDATA[

self.configSrc(param_name[,default])

returns value of parameter as "source address" string. If parameter is not defined in a file then default value is returned without conversion, if default value was not given then exception is raised. This method does the same as self.configStr but it may also check correctness of the source string format. ]]></ac:plain-text-body></ac:structured-macro>string format.

self.configListBool(param_name)

returns value of parameter as a list of boolean values. If parameter is not defined in a file then empty list is returned, otherwise every word in a parameter value is converted to boolean (according to same rules as defined for self.configBool) and all values are returned in one list.

self.configListInt(param_name)

returns value of parameter as a list of integers. If parameter is not defined in a file then empty list is returned, otherwise every word in a parameter value is converted to integers and all numbers are returned in one list. Conversion errors will raise exception.

self.configListFloat(param_name)

returns value of parameter as a list of floating point numbers. If parameter is not defined in a file then empty list is returned, otherwise every word in a parameter value is converted to float and all numbers are returned in one list. Conversion errors will raise exception.

self.configListStr(param_name)

returns value of parameter as a list of strings. If parameter is not defined in a file then empty list is returned, otherwise parameter value is split into words which are returned in one list.

self.configListSrc(param_name)

returns value of parameter as a list of "source address" strings. If parameter is not defined in a file then empty list is returned, otherwise parameter value is split into words which are returned in one list.

...

  1. evt.get(typeId:int, address:string) which takes integer number for the first argument and "source address" string for second argument. Integer number is an XTC TypeId value such as xtc.TypeId.Type.Id_Frame. This method retrieves detector data of the type corresponding to the TypeId coming from a device that matches source address.unmigrated-wiki-markup
  2. {{evt.get(key:string\[, default=None\])}} which takes a string for the first argument and optionally any object for second argument. This method retrieves "user data" object from event which was stored in the event by user module with by calling {{evt.put(object, key)}} with the same string key.

Best way to access event data in pyana is to use generic evt.get() method and not specialized methods, it would be much easier to migrate this code later to psana. Here is an example of this:

...

Psana does not provide any specialized methods for retrieving individual data types, instead it provides generic evt.get() method whose interface is much closer to that of C++ class, though it also provides few overloads for pyana compatibility. There are several "overloads" of this method depending on the number and types of parameters:

  1. Wiki Markup{{evt.get(type, src\[, key:string\])}} where {{type}} is python class corresponding to the data type (or list of classes), e.g. {{psana.Camera.FrameV1}}. The {{src}} argument must be an instance of {{psana.Source}} type which provides a match for device address, {{psana.Source}} is returned from {{self.configSrc(...)}} method. If {{key}} argument is provided then it must be a string, missing key argument is identical to empty string.unmigrated-wiki-markup
  2. {{evt.get(type\[, key:string\])}} - variation of the above method without source argument. This method is used to retrieve data which is not associated with any device but is a property of the event as a whole. Good example of this kind of data is the {{psana.EventId}} object.
  3. self.get(typeId:int, addr:string) - this is pyana-compatibility method and should only be used during migration or in the code which is supposed to run in both pyana and psana. This method is equivalent to pyana method evt.get(TypeId, address). Note that in psana there will be data types which do not have corresponding TypeId, this method cannot be used with those types (TypeId is a property of XTC data types, other data types do not have TypeId).
  4. self.get(key:string) - this is pyana-compatibility method and should only be used during migration or in the code which is supposed to run in both pyana and psana. This method is equivalent to pyana method evt.get(key, None) and is used to retrieve data stored with evt.put(object, key).

...

Just like event class the environment class in pyana provides a number of specific method for individual data types and a generic method which works for any data type. Specific methods should not be used frequently, one should prefer to use generic method. Generic method has this definition:

...

:

  • env.getConfig(typeId:int

...

  • [,

...

  • address=None

...

  • ])

...

  • -

...

  • takes

...

  • integer

...

  • number

...

  • for

...

  • the

...

  • first

...

  • argument

...

  • and

...

  • optional

...

  • string

...

  • for

...

  • second.

...

  • Integer

...

  • number

...

  • is

...

  • an

...

  • XTC

...

  • TypeId

...

  • value

...

  • such

...

  • as

...

  • xtc

...

  • .

...

  • TypeId.Type.Id_AcqConfig (note that TypeId values for event data and configuration data are different). This method retrieves configuration data of the type corresponding to the TypeId coming from a device that matches source address.

An example:

Code Block
from pypdsdata import xtc
......
        src = self.configSrc('source', '')
        config = env.getConfig(xtc.TypeId.Type.Id_AcqConfig, src)
        if config:
            print "config.nbrChannels =", config.nbrChannels()

...

  1. store.get(type, src) where type is python class corresponding to the configuration data type (or list of classes), e.g. psana.Acqiris.Config. src argument must be an instance of psana.Source type which provides a match for device address.unmigrated-wiki-markup
  2. {{self.get(typeId:int\[, address:string=""\])}} - this is pyana-compatibility method and should only be used in the code which is supposed to run in both pyana and psana. This method is equivalent to pyana method {{env.getConfig(TypeId, address)}}.

For pyana compatibility environment also defines evt.getConfig(...) method which is a shortcut for env.configStore().get(...), this method should only be used in a code which should run in both pyana and psana.

...

pyana

psana

_pdsdata.cspad

Psana.CsPad

config = env.getConfig(TypeId.Type.Id_CspadConfig, self.m_src)

config = env.configStore().get(CsPad.Config, self.m_src)

quads = evt.get(TypeId.Type.Id_CspadElement, self.m_src)

data = evt.get(CsPad.Data, self.m_src)

for q in quads : data = q.data() # image data as 3-dimentional array of the shape (N, 185, 388)

 

(CsPad.Data, self.m_src)

for q in quads : data = q.data() # image data as 3-dimentional array of the shape (N, 185, 388)

 

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="8e69ee5b-6a96-4915-88eb-f67e7a2aec48"><ac:plain-text-body><![CDATA[

list_of_masks = [config.roiMask(q) for q in range(4)]

list_of_masks = [config.roiMask(q) for q in range(4)]

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

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="2e1c1032-dbb0-4a85-92f3-ad4b04198926"><ac:plain-text-body><![CDATA[list_of_masks = [config.roiMask(q) for q in range(4)]

print " numQuads =", config.numQuads();

nQuads = data.quads_shape()[0] # etc. ]]></ac:plain-text-body></ac:structured-macro>

for i in range(nQuads): q = data.quads(i); data_arr = q.data() # etc.

for i in range(nQuads): q = data.quads(i); data_arr = q.data() # etc.

...

pyana

psana

_pdsdata.cspad2x2

Psana.CsPad2x2

config = env.getConfig(xtc.TypeId.Type.Id_Cspad2x2Config_Cspad2x2Config, self.m_src)

(works the same) config = env.getConfig(CsPad2x2Config, self.m_src) {{}}

print " roiMask =", config.roiMask()

{{}} roiMask = config.roiMask()

elem = evt.get(xtc.TypeId.Type.Id_Cspad2x2Element, self.m_src)

{{}} elem = evt.get(CsPad2x2.Element, self.m_src)

data = elem.data() # image data as 3-dimentional array of the shape (185, 388, 2)

{{}} data = elem.data()

{{}}

{{}}

EPICS

pyana

psana

_pdsdata.epics

Psana.Epics

{{}}

{{}}

...

ples: https://pswww.slac.stanford.edu/trac/psdm/browser/psdm/psana_examples#trunk/src