epicsarchiver.retrieval.pb
Handle retrieval of data in the Archiver Appliance PB file format.
The file format is described on this page: https://slacmshankar.github.io/epicsarchiver_docs/pb_pbraw.html
The data can be parsed in the same way whether retrieved using the Rest API or whether reading files directly from disk. In either case, it is important to treat the data as binary data - a stream of bytes. The Google Protobuf library handles converting the stream of bytes into the objects defined by the EPICSEvent.proto file.
The Archiver Appliance escapes certain characters as described on the page above, which allows one to deduce the number of events in the binary file using tools such as wc.
The unescape_bytes() method handles unescaping these characters before handing the interpretation over to the Google Protobuf library.
Note: due to the way the protobuf objects are constructed, pylint can’t correctly deduce some properties, so I have manually disabled some warnings.
Attributes
Functions
|
Replace specific sub-sequences in a bytes sequence. |
|
Replace specific sub-sequences in a bytes sequence. |
|
Converts from protobuf event time format to python datetime. |
|
Converts from protobuf event time format to python datetime. |
From a unescaped protobuf line create a function to get datetime. |
|
|
Break up raw data into chunks by year. |
|
Get an ArchiveEvent from this line. |
|
Turn raw PB data into an ArchiveData object. |
|
Returns an ISO-formatted timestamp string for the given event. |
|
Read an unescaped protobuf file and produce a list of events from file. |
|
From the protobuf variant. |
Module Contents
- epicsarchiver.retrieval.pb.LOG: logging.Logger[source]
- epicsarchiver.retrieval.pb.unescape_bytes(byte_seq: bytes) bytes[source]
Replace specific sub-sequences in a bytes sequence.
This escaping is defined as part of the Archiver Appliance raw file format: https://slacmshankar.github.io/epicsarchiver_docs/pb_pbraw.html
- Parameters:
byte_seq – any byte sequence
- Returns:
the byte sequence unescaped according to the AA file format rules
- epicsarchiver.retrieval.pb.escape_bytes(byte_seq: bytes) bytes[source]
Replace specific sub-sequences in a bytes sequence.
This escaping is defined as part of the Archiver Appliance raw file format: https://slacmshankar.github.io/epicsarchiver_docs/pb_pbraw.html
- Parameters:
byte_seq – any byte sequence
- Returns:
the byte sequence escaped according to the AA file format rules
- epicsarchiver.retrieval.pb.event_pd_timestamp(year: int, event: EeEvent) pandas.Timestamp[source]
Converts from protobuf event time format to python datetime.
- Parameters:
year (int) – year of event
event (EeEvent) – input event
- Returns:
Output datetime
- Return type:
pydt
- epicsarchiver.retrieval.pb.event_timestamp(year: int, event: EeEvent) datetime.datetime[source]
Converts from protobuf event time format to python datetime.
- Parameters:
year (int) – year of event
event (EeEvent) – input event
- Returns:
Output datetime
- Return type:
pydt
- epicsarchiver.retrieval.pb.get_timestamp_from_line_function(chunk_info: epicsarchiver.retrieval.EPICSEvent_pb2.PayloadInfo) collections.abc.Callable[[bytes], datetime.datetime][source]
From a unescaped protobuf line create a function to get datetime.
- Parameters:
chunk_info (ee.PayloadInfo) – Payload info of protobuf file
- Returns:
Function to provide event time
- Return type:
Callable[[bytes], pydt]
- epicsarchiver.retrieval.pb._break_up_chunks(raw_data: bytes) collections.OrderedDict[int, tuple[epicsarchiver.retrieval.EPICSEvent_pb2.PayloadInfo, list[bytes]]][source]
Break up raw data into chunks by year.
- Parameters:
raw_data – Raw data from file
- Returns:
keys are years; values are lists of chunks
- Return type:
- epicsarchiver.retrieval.pb._event_from_line(line: bytes, pv: str, year: int, event_type: int) epicsarchiver.retrieval.archive_event.ArchiveEvent[source]
Get an ArchiveEvent from this line.
- Parameters:
line – A line of chunks of data
pv – Name of the PV
year – Year of interest
event_type – Need to know the type of the event as key of TYPE_MAPPINGS
- Returns:
ArchiveEvent
- epicsarchiver.retrieval.pb.parse_pb_data(raw_data: bytes) list[epicsarchiver.retrieval.archive_event.ArchiveEvent][source]
Turn raw PB data into an ArchiveData object.
- Parameters:
raw_data – The raw data
- Returns:
An ArchiveData object
- epicsarchiver.retrieval.pb.get_iso_timestamp_for_event(year: int, event: EeEvent) str[source]
Returns an ISO-formatted timestamp string for the given event.
- epicsarchiver.retrieval.pb.read_pb_file(filename: str) list[epicsarchiver.retrieval.archive_event.ArchiveEvent][source]
Read an unescaped protobuf file and produce a list of events from file.
- Parameters:
filename (str) – location of file
- Returns:
list of events in file
- Return type:
- epicsarchiver.retrieval.pb.to_field_value(f: epicsarchiver.retrieval.EPICSEvent_pb2.FieldValue) epicsarchiver.retrieval.archive_event.FieldValue[source]
From the protobuf variant.
- Parameters:
f (ee.FieldValue) – protobuf field value
- Returns:
Basic Field Value
- Return type: