cait.readers

We provide readers TextFile for text file such as .par-files, and BinaryFile for binary data files of arbitrary data type. These two classes are wrappers that automatically handle local and remote files: To access files on a locally mounted drive, just use regular/file/paths.txt. If you prefix file paths with <protocol>://server.data.at/, the file is read from remote. Currently, we support the dcap, https (WebDav), and root (XRootD) protocol and we highly recommend using root wherever possible.

class cait.readers.BinaryFile(path: str, dtype: dtype, offset: int = 0, count: int = -1)[source]

Bases: object

A class that can be used to open binary files (e.g. rdt or stream files) which also supports reading from dcache.

Parameters:
  • path (str) – The full path (including file extension) to the file of interest. If the path starts with dcap://, https:// or root://, reading with the respective protocol is attempted.

  • dtype (np.dtype) – The numpy (structured) dtype to use when interpreting the contents of the file.

  • offset (int, optional) – The offset (in bytes) for reading the file, defaults to 0.

  • count (int, optional) – The number of items (of size given by dtype) to read. If -1, the entire file is read, defaults to -1.

The file URL can contain additional arguments used for the request. Example: When using the WebDav protocol, additional keyword arguments for webdav4.client.Client (https://skshetry.github.io/webdav4/reference/client.html) can be supplied. This can be achieved through URLs like https://domain.com/file.txt;{kwarg: value}.

Example:

import numpy as np
from cait.readers import BinaryFile
from cait.versatile import Line

rdt_file = "path/to/file.rdt"
dtype = np.dtype([ ('detector_nmbr', 'i4'), ('coincide_pulses', 'i4'),
                   ('trig_count', 'i4'), ('trig_delay', 'i4'),
                   ('abs_time_s', 'i4'), ('abs_time_mus', 'i4'),
                   ('delay_ch_tp', 'i4', (1,)), ('time_low', 'i4'),
                   ('time_high', 'i4'), ('qcd_events', 'i4'),
                   ('hours', 'f4'), ('dead_time', 'f4'),
                   ('test_pulse_amplitude', 'f4'), ('dac_output', 'f4'),
                   ('samples', 'i2', 16384),
                  ])

with BinaryFile(rdt_file, dtype=dtype) as f:
    first_event = np.array(f[0]["samples"])

Line(first_event)
class cait.readers.TextFile(path: str)[source]

Bases: object

A class that can be used to open text files (e.g. par files) which also supports reading via the Dcap, WebDav, and Root protocol.

Parameters:

path (str) – The full path (including file extension) to the file of interest. If the path starts with dcap://, https:// or root://, reading with the respective protocol is attempted.

The file URL can contain additional arguments used for the request. Example: When using the WebDav protocol, additional keyword arguments for webdav4.client.Client (https://skshetry.github.io/webdav4/reference/client.html) can be supplied. This can be achieved through URLs like https://domain.com/file.txt;{kwarg: value}.

Example:

from cait.readers import TextFile

par_file = "path/to/file.par"

with TextFile(par_file) as f:
    print(f.read())