Skip to content

psana.datasource

DataSource(*args, **kwargs) is the entry point of psana2. It is a function, not a class: it looks at the keyword arguments (checked in the order shmem, exp, files, drp) and returns an instance of one of the data source classes, all derived from DataSourceBase:

Keyword Returned class Module
shmem= ShmemDataSource (NullDataSource on the first PS_SRV_NODES MPI ranks) psana.psexp.shmem_ds, psana.psexp.null_ds
exp= (and run=) SerialDataSource when PS_PARALLEL=none or only one MPI rank; otherwise MPIDataSource on smd0/eb/bd ranks and NullDataSource on the other ranks psana.psexp.serial_ds, psana.psexp.mpi_ds, psana.psexp.null_ds
files= SingleFileDataSource psana.psexp.singlefile_ds
drp= DrpDataSource (its constructor currently raises AttributeError; see drp_ds) psana.psexp.drp_ds

PS_PARALLEL is read in psana/psana/psexp/tools.py (default "mpi"). If none of these keywords is given, InvalidDataSource is raised. With exp= in MPI mode with one rank, DataSource creates the SerialDataSource inside a try: only if that raises FileNotFoundError does it log the error and call sys.exit(1). With PS_PARALLEL=none there is no such try, and the exception reaches the caller. The docstring below says the same thing in a shorter form. Importing this module also sets the environment variable PS_PROMETHEUS_JOBID.

See DataSource, Run and the event loop for how the returned object is used.

psana.datasource

The DataSource factory, which returns the psana data source object that matches its keyword arguments, and the InvalidDataSource exception.

On import it sets the environment variable PS_PROMETHEUS_JOBID: in MPI mode to the process id of rank 0 (broadcast to all ranks), otherwise to this process's id.

InvalidDataSource

Bases: Exception

Exception raised by DataSource for unsupported arguments or parallel mode.

Raised when none of the keywords exp, shmem, files or drp is given, or when exp is given and psana.psexp.tools.mode is neither "mpi" nor "none".

DataSource

DataSource(*args, **kwargs)

Create and return the data source object that matches the keyword arguments.

Calls gc.collect() first and converts positional arguments to str; all arguments are passed on to the chosen class. The keywords are checked in the order shmem, exp, files, drp.

Returns:

Type Description
object
  • shmem given: ShmemDataSource. With more than one MPI rank, smalldata_kwargs with server and client groups is added and ranks below PS_SRV_NODES get a NullDataSource (RuntimeError if PS_SRV_NODES equals the number of ranks).
  • exp given: for experiment names starting with "mfx", PS_EB_NODES, PS_SMD_N_EVENTS and batch_size defaults are adjusted first. In MPI mode with one rank, SerialDataSource (a FileNotFoundError is logged and the process exits with status 1); with several ranks, Communicators are built and smd0/eb/bd ranks get MPIDataSource, other ranks NullDataSource. With mode "none", SerialDataSource.
  • files given: SingleFileDataSource.
  • drp given: DrpDataSource.

Raises:

Type Description
InvalidDataSource

If none of these keywords is given, or exp is given with a mode other than "mpi" or "none".