Versions Compared

Key

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

Recommended Next Topics

Include Page
PSDMInternal:Related_Topics_Div_ClosePSDMInternal:
Related_Topics_Div_Close
Include Page
PSDMInternal:PageMenuBeginPSDMInternal:
PageMenuBegin
Table of Contents
Include Page
PSDMInternal:PageMenuEndPSDMInternal:
PageMenuEnd

Introduction

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

Data types and access methods

...

Configuration file in both frameworks is starting from section pyana or (deprecated) 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:

...

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", "

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="d660d43d-a8e4-431c-94bc-dd1fbf90ebcd"><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="713f5f44-335e-4152-a06a-e766bdc1bfdc"><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>

self.configInt(param_name[,default])

returns value of parameter as integer

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="2f3048fc-eef5-4494-80c8-a71b74de7393"><ac:plain-text-body><![CDATA[

self.configFloat(param_name[,default])

returns value of parameter as floating 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. 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="49e5c35f-5536-405f-95e9-6dea52ac87e2"><ac:plain-text-body><![CDATA[raised.

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="58f4befe-fb8c-48bd-93b2-bb3ce5cb29ab"><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>check correctness of the source 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: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.

...

Code Block
import psana
......
        src = self.configSrc('source', '')..
        configsrc = envself.configStore().get(psana.Acqiris.Config, src)
        if config:
    configSrc('source', '')
        print "config.nbrChannels =", configenv.nbrChannels()

Previous pyana example is supposed to work in psana without change.

Differences in data classes

Tables below provide summary of differences between data objects inside pyana and psana.

For pyana the pieces of code imply that following import statement appears somewhere in the module file:

Code Block

from pypdsdata import xtc

for psana this import should be replaced with

Code Block

from psana import *

In pyana evt.get() and env.getConfig() accept string for source argument while in psana the type of the argument must be psana.Source. In both pyana and psana the source address can be set with self.configSrc() as this method returns correct type in each framework:

Code Block

        self.m_src = self.configSrc('source', '')

As it is discussed above pyana code can be run inside psana in compatibility mode. In this case the code needs changes only if data classes provide different interfaces.

Acqiris

pyana

psana

_pdsdata.acqiris

Psana.Acqiris

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

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

acqData = evt.get(xtc.TypeId.Type.Id_AcqWaveform, self.m_src)

acqData = evt.get(Acqiris.DataDesc, self.m_src)

access to data also differs...

 

Bld

configStore().get(psana.Acqiris.Config, src)
        if config:
            print "config.nbrChannels =", config.nbrChannels()

Previous pyana example is supposed to work in psana without change.

Differences in data classes

Tables below provide summary of differences between data objects inside pyana and psana.

For pyana the pieces of code imply that following import statement appears somewhere in the module file:

Code Block

from pypdsdata import xtc

for psana this import should be replaced with

Code Block

from psana import *

In pyana evt.get() and env.getConfig() accept string for source argument while in psana the type of the argument must be psana.Source. In both pyana and psana the source address can be set with self.configSrc() as this method returns correct type in each framework:

Code Block

        self.m_src = self.configSrc('source', '')

As it is discussed above pyana code can be run inside psana in compatibility mode. In this case the code needs changes only if data classes provide different interfaces.

Acqiris

pyana

psana

_pdsdata.bld

Psana.Bld

data = evt.get(xtc.TypeId.Type.Id_FEEGasDetEnergy, self.m_src)

data = evt.get(Bld.BldDataFEEGasDetEnergy, self.m_src)

acqiris

Psana.Acqiris

config = env.getConfigdata = evt.get(xtc.TypeId.Type.Id_EBeamAcqConfig, self.m_src)

data = evtconfig = env.configStore().get(BldAcqiris.BldDataEBeamConfig, self.m_src)

data acqData = evt.get(xtc.TypeId.Type.Id_PhaseCavityAcqWaveform, self.m_src)

data acqData = evt.get(BldAcqiris.BldDataPhaseCavityDataDesc, self.m_src)

access to data also differs...

 

Bld

pyana

psana

_pdsdata.bld

Psana.Bld

data = evt.get(xtc.TypeId.Type.Id_GMDFEEGasDetEnergy, self.m_src)

data = evt.get(Bld.BldDataGMDBldDataFEEGasDetEnergy, self.m_src)

CsPad

.m_src)

data = evt.get(xtc.

pyana

psana

_pdsdata.cspad

Psana.CsPad

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

config = env.configStore()data = evt.get(CsPadBld.ConfigBldDataEBeam, self.m_src)

quads data = evt.get(xtc.TypeId.Type.Id_CspadElementPhaseCavity, self.m_src)

data = evt.get(CsPadBld.DataBldDataPhaseCavity, self.m_src)

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

 

get(xtc.TypeId.Type.Id_GMD, self.m_src)

data = evt.get(Bld.BldDataGMD, self.m_src)

CsPad

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)

 

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

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

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="aa9517ab-42f9-41ae-931f-09c9dc0633a4"><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="20c5ae9f-54cc-483c-975a-ab7758e8ca5a"><ac:plain-text-body><![CDATA[

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.

...