podio package

Submodules

podio.base_reader module

Python module for defining the basic reader interface that is used by the backend specific bindings

class podio.base_reader.BaseReaderMixin

Bases: object

Mixin class the defines the base interface of the readers.

The backend specific readers inherit from here and have to initialize the following members: - _reader: The actual reader that is able to read frames

Initialize common members.

In inheriting classes this needs to be called after the _reader has been setup.

property categories

Get the available categories from this reader.

Returns:

The names of the available categories from this reader

Return type:

tuple(str)

property datamodel_definitions

Get the available datamodel definitions from this reader.

Returns:

The names of the available datamodel definitions

Return type:

tuple(str)

get(category)

Get an iterator with access functionality for a given category.

Parameters:

category (str) – The name of the desired category

Returns:

The iterator granting access to all Frames of the

desired category

Return type:

FrameCategoryIterator

get_datamodel_definition(edm_name)

Get the datamodel definition as JSON string.

Parameters:

str – The name of the datamodel

Returns:

The complete model definition in JSON format. Use, e.g. json.loads

to convert it into a python dictionary.

Return type:

str

property is_legacy

Whether this is a legacy file reader or not.

Returns:

True if this is a legacy file reader

Return type:

bool

podio.base_writer module

Python module for defining the basic writer interface that is used by the backend specific bindings

class podio.base_writer.AllWriters

Bases: object

Class to manage all writers in the program so that they can be properly finished at the end of the program

add(writer)

Add a writer to the list of managed writers

finish()

Finish all managed writers

writers = []
class podio.base_writer.BaseWriterMixin

Bases: object

Mixin class that defines the base interface of the writers.

The backend specific writers inherit from here and have to initialize the following members:

  • _writer: The actual writer that is able to write frames

Initialize the writer

write_frame(frame, category, collections=None)

Write the given frame under the passed category, optionally limiting the collections that are written.

Parameters:
  • frame (podio.frame.Frame) – The Frame to write

  • category (str) – The category name

  • collections (optional, default=None) – The subset of collections to write. If None, all collections are written

podio.frame module

Module for the python bindings of the podio::Frame

class podio.frame.Frame(data=None)

Bases: object

Frame class that serves as a container of collection and meta data.

Create a Frame.

Parameters:

data (FrameData, optional) – Almost arbitrary FrameData, e.g. from file

property collections

Get the currently available collection (names) from this Frame.

Returns:

The names of the available collections from this Frame.

Return type:

tuple(str)

get(name)

Get a collection from the Frame by name.

Parameters:

name (str) – The name of the desired collection

Returns:

The collection stored in the Frame

Return type:

collection (podio.CollectionBase)

Raises:

KeyError – If the collection with the name is not available

getAvailableCollections()

Get the currently available collection (names) from this Frame.

Returns:

The names of the available collections from this Frame.

Return type:

tuple(str)

get_param_info(name)

Get the parameter type information stored under the given name.

Parameters:

name (str) – The parameter name

Returns:

int): The c++-type(s) of the stored parameter and the number of

parameters

Return type:

dict (str

Raises:

KeyError – If no parameter is stored under the given name

get_parameter(name, as_type=None)

Get the parameter stored under the given name.

Parameters:
  • name (str) – The name of the parameter

  • as_type (str, optional) – Type specifier to disambiguate between parameters with the same name but different types. If there is only one parameter with a given name, this argument is ignored

Returns:

The value of the stored parameter

Return type:

int, float, str or list of those

Raises:
  • KeyError – If no parameter is stored under the given name

  • ValueError – If there are multiple parameters with the same name, but multiple types and no type specifier to disambiguate between them has been passed.

get_parameters()

Get the complete podio::GenericParameters object stored in this Frame.

NOTE: This is mainly intended for dumping things, for actually obtaining parameters please use get_parameter

Returns:

The stored generic parameters

Return type:

podio.GenericParameters

property parameters

Get the currently available parameter names from this Frame.

Returns:

The names of the available parameters from this Frame.

Return type:

tuple (str)

put(collection, name)

Put the collection into the frame

The passed collection is “moved” into the Frame, i.e. it cannot be used any longer after a call to this function. This also means that only objects that were in the collection at the time of calling this function will be available afterwards.

Parameters:
  • collection (podio.CollectionBase) – The collection to put into the Frame

  • name (str) – The name of the collection

Returns:

The reference to the collection that has been put

into the Frame. NOTE: That mutating this collection is not allowed.

Return type:

podio.CollectionBase

Raises:

ValueError – If collection is not actually a podio.CollectionBase

put_parameter(key, value, as_type=None)

Put a parameter into the Frame.

Puts a parameter into the Frame after doing some (incomplete) type checks. If a list is passed the parameter type is determined from looking at the first element of the list only. Additionally, since python doesn’t differentiate between floats and doubles, floats will always be stored as doubles by default, use the as_type argument to change this if necessary.

Parameters:
  • key (str) – The name of the parameter

  • value (int, float, str or list of these) – The parameter value

  • as_type (str, optional) – Explicitly specify the type that should be used to put the parameter into the Frame. Python types (e.g. “str”) will be converted to c++ types. This will override any automatic type deduction that happens otherwise. Note that this will be taken at pretty much face-value and there are only limited checks for this.

Raises:

ValueError – If a non-supported parameter type is passed

podio.frame_iterator module

Module defining the Frame iterator used by the Reader interface

class podio.frame_iterator.FrameCategoryIterator(reader, category)

Bases: object

Iterator for iterating over all Frames of a given category available from a reader as well as accessing specific entries

Construct the iterator from the reader and the category.

Parameters:
  • reader (Reader) – Any podio reader offering access to Frames

  • category (str) – The category name of the Frames to be iterated over

podio.reading module

Module for general reading functionality.

class podio.reading.RootFileFormat

Bases: object

Enum to specify the ROOT file format

LEGACY = 2
RNTUPLE = 1
TTREE = 0
podio.reading.get_reader(filename)

Get an appropriate reader for the passed file.

Parameters:

filename (str) – The input file

Returns:

an initialized reader that

is able to process the input file.

Return type:

root_io.[Legacy]Reader, sio_io.[Legacy]Reader

Raises:

ValueError – If the file cannot be recognized, or if podio has not been built with the necessary backend I/O support

podio.root_io module

Python module for reading root files containing podio Frames

class podio.root_io.LegacyReader(filenames)

Bases: BaseReaderMixin

Reader class for reading legacy podio root files.

This reader can be used to read files that have not yet been written using Frame based I/O into Frames for a more seamless transition.

Create a reader that reads from the passed file(s).

Parameters:

filenames (str or list[str]) – file(s) to open and read data from

class podio.root_io.RNTupleReader(filenames)

Bases: BaseReaderMixin

Reader class for reading podio RNTuple root files.

Create an RNTuple reader that reads from the passed file(s).

Parameters:

filenames (str or list[str]) – file(s) to open and read data from

class podio.root_io.RNTupleWriter(filename)

Bases: BaseWriterMixin

Writer class for writing podio root files

Create a writer for writing files

Parameters:

filename (str) – The name of the output file

class podio.root_io.Reader(filenames)

Bases: BaseReaderMixin

Reader class for reading podio root files.

Create a reader that reads from the passed file(s).

Parameters:

filenames (str or list[str]) – file(s) to open and read data from

class podio.root_io.Writer(filename)

Bases: BaseWriterMixin

Writer class for writing podio root files

Create a writer for writing files

Parameters:

filename (str) – The name of the output file

podio.sio_io module

Python module for reading sio files containing podio Frames

class podio.sio_io.LegacyReader(filename)

Bases: BaseReaderMixin

Reader class for reading legacy podio sio files.

This reader can be used to read files that have not yet been written using the Frame based I/O into Frames for a more seamless transition.

Create a reader that reads from the passed file.

Parameters:

filename (str) – File to open and read data from

class podio.sio_io.Reader(filename)

Bases: BaseReaderMixin

Reader class for reading podio SIO files.

Create a reader that reads from the passed file.

Parameters:

filename (str) – File to open and read data from

class podio.sio_io.Writer(filename)

Bases: BaseWriterMixin

Writer class for writing podio root files

Create a writer for writing files

Parameters:

filename (str) – The name of the output file

Module contents

Python module for the podio EDM toolkit and its utilities

class podio.Frame(data=None)

Bases: object

Frame class that serves as a container of collection and meta data.

Create a Frame.

Parameters:

data (FrameData, optional) – Almost arbitrary FrameData, e.g. from file

property collections

Get the currently available collection (names) from this Frame.

Returns:

The names of the available collections from this Frame.

Return type:

tuple(str)

get(name)

Get a collection from the Frame by name.

Parameters:

name (str) – The name of the desired collection

Returns:

The collection stored in the Frame

Return type:

collection (podio.CollectionBase)

Raises:

KeyError – If the collection with the name is not available

getAvailableCollections()

Get the currently available collection (names) from this Frame.

Returns:

The names of the available collections from this Frame.

Return type:

tuple(str)

get_param_info(name)

Get the parameter type information stored under the given name.

Parameters:

name (str) – The parameter name

Returns:

int): The c++-type(s) of the stored parameter and the number of

parameters

Return type:

dict (str

Raises:

KeyError – If no parameter is stored under the given name

get_parameter(name, as_type=None)

Get the parameter stored under the given name.

Parameters:
  • name (str) – The name of the parameter

  • as_type (str, optional) – Type specifier to disambiguate between parameters with the same name but different types. If there is only one parameter with a given name, this argument is ignored

Returns:

The value of the stored parameter

Return type:

int, float, str or list of those

Raises:
  • KeyError – If no parameter is stored under the given name

  • ValueError – If there are multiple parameters with the same name, but multiple types and no type specifier to disambiguate between them has been passed.

get_parameters()

Get the complete podio::GenericParameters object stored in this Frame.

NOTE: This is mainly intended for dumping things, for actually obtaining parameters please use get_parameter

Returns:

The stored generic parameters

Return type:

podio.GenericParameters

property parameters

Get the currently available parameter names from this Frame.

Returns:

The names of the available parameters from this Frame.

Return type:

tuple (str)

put(collection, name)

Put the collection into the frame

The passed collection is “moved” into the Frame, i.e. it cannot be used any longer after a call to this function. This also means that only objects that were in the collection at the time of calling this function will be available afterwards.

Parameters:
  • collection (podio.CollectionBase) – The collection to put into the Frame

  • name (str) – The name of the collection

Returns:

The reference to the collection that has been put

into the Frame. NOTE: That mutating this collection is not allowed.

Return type:

podio.CollectionBase

Raises:

ValueError – If collection is not actually a podio.CollectionBase

put_parameter(key, value, as_type=None)

Put a parameter into the Frame.

Puts a parameter into the Frame after doing some (incomplete) type checks. If a list is passed the parameter type is determined from looking at the first element of the list only. Additionally, since python doesn’t differentiate between floats and doubles, floats will always be stored as doubles by default, use the as_type argument to change this if necessary.

Parameters:
  • key (str) – The name of the parameter

  • value (int, float, str or list of these) – The parameter value

  • as_type (str, optional) – Explicitly specify the type that should be used to put the parameter into the Frame. Python types (e.g. “str”) will be converted to c++ types. This will override any automatic type deduction that happens otherwise. Note that this will be taken at pretty much face-value and there are only limited checks for this.

Raises:

ValueError – If a non-supported parameter type is passed