Skip to content

Commit

Permalink
Merge pull request #314 from gipert/raw
Browse files Browse the repository at this point in the history
`raw.orca` cleanup
  • Loading branch information
jasondet authored Jul 21, 2022
2 parents 87e11e5 + 5806ee1 commit 8673620
Show file tree
Hide file tree
Showing 12 changed files with 353 additions and 407 deletions.
File renamed without changes.
130 changes: 130 additions & 0 deletions attic/pygama/raw/orca_flashcam.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import copy
import gc
import logging
from typing import Any

import numpy as np

from pygama.raw.fc.fc_event_decoder import fc_decoded_values
from pygama.raw.orca.orca_base import OrcaDecoder
from pygama.raw.orca.orca_header import OrcaHeader
from pygama.raw.orca.orca_packet import OrcaPacket
from pygama.raw.raw_buffer import RawBufferLibrary

log = logging.getLogger(__name__)


class ORFlashCamListenerStatusDecoder(OrcaDecoder):
"""
Decoder for FlashCam status packets written by ORCA
Some of the card level status data contains an array of values
(temperatures for instance) for each card. Since lh5 currently only
supports a 1d vector of 1d vectors, this (card,value) data has to be
flattened before populating the lh5 table.
"""

def __init__(self, *args, **kwargs):

self.decoder_name = 'ORFlashCamListenerStatusDecoder'
self.orca_class_name = 'ORFlashCamListenerModel'
self.nOtherErrors = np.uint32(5)
self.nEnvMonitors = np.uint32(16)
self.nCardTemps = np.uint32(5)
self.nCardVoltages = np.uint32(6)
self.nADCTemps = np.uint32(2)
self.nCTILinks = np.uint32(4)
self.nCards = np.uint32(1)

self.decoded_values = {
'readout_id': { 'dtype': 'uint16', },
'listener_id': { 'dtype': 'uint16', },
'cards': { 'dtype': 'int32', },
'status': { 'dtype': 'int32', },
'statustime': { 'dtype': 'float64', 'units': 's', },
'cputime': { 'dtype': 'float64', 'units': 's', },
'startoffset': { 'dtype': 'float64', 'units': 's', },
'card_fcio_id': {
'dtype': 'uint32',
'datatype': 'array<1>{array<1>{real}}',
'length_guess': self.nCards, },
'card_status': {
'dtype': 'uint32',
'datatype': 'array<1>{array<1>{real}}',
'length_guess': self.nCards, },
'card_event_number': {
'dtype': 'uint32',
'datatype': 'array<1>{array<1>{real}}',
'length_guess': self.nCards, },
'card_pps_count': {
'dtype': 'uint32',
'datatype': 'array<1>{array<1>{real}}',
'length_guess': self.nCards, },
'card_tick_count': {
'dtype': 'uint32',
'datatype': 'array<1>{array<1>{real}}',
'length_guess': self.nCards, },
'card_max_ticks': {
'dtype': 'uint32',
'datatype': 'array<1>{array<1>{real}}',
'length_guess': self.nCards, },
'card_total_errors': {
'dtype': 'uint32',
'datatype': 'array<1>{array<1>{real}}',
'length_guess': self.nCards, },
'card_env_errors': {
'dtype': 'uint32',
'datatype': 'array<1>{array<1>{real}}',
'length_guess': self.nCards, },
'card_cti_errors': {
'dtype': 'uint32',
'datatype': 'array<1>{array<1>{real}}',
'length_guess': self.nCards, },
'card_link_errors': {
'dtype': 'uint32',
'datatype': 'array<1>{array<1>{real}}',
'length_guess': self.nCards, },
'card_other_errors': {
'dtype': 'uint32',
'datatype': 'array<1>{array<1>{real}}',
'length_guess': self.nCards * self.nOtherErrors, },
'card_temp': {
'dtype': 'uint32',
'datatype': 'array<1>{array<1>{real}}',
'length_guess': self.nCards * self.nCardTemps,
'units': 'mC', },
'card_voltage': {
'dtype': 'uint32',
'datatype': 'array<1>{array<1>{real}}',
'length_guess': self.nCards * self.nCardVoltages,
'units': 'mV', },
'card_current': {
'dtype': 'uint32',
'datatype': 'array<1>{array<1>{real}}',
'length_guess': self.nCards,
'units': 'mA', },
'card_humidity': {
'dtype': 'uint32',
'datatype': 'array<1>{array<1>{real}}',
'length_guess': self.nCards,
'units': 'o/oo', },
'card_adc_temp': {
'dtype': 'uint32',
'datatype': 'array<1>{array<1>{real}}',
'length_guess': self.nCards * self.nADCTemps,
'units': 'mC', },
'card_cti_link': {
'dtype': 'uint32',
'datatype': 'array<1>{array<1>{real}}',
'length_guess': self.nCards * self.nCTILinks, },
'card_card_link_state': {
'dtype': 'uint32',
'datatype': 'array<1>{array<1>{real}}',
'length_guess': self.nCards * self.nCards, },
}

# arrays to temporarily store card-level decoded data
self.cdata = {}
self.resize_card_data(ncards=self.nCards)

super().__init__(args, kwargs)
File renamed without changes.
13 changes: 3 additions & 10 deletions src/pygama/raw/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,8 @@
Currently we support the following hardware:
* FlashCam (requires `pyfcutils <https://github.com/legend-exp/pyfcutils>`_)
* SIS3302 read out with `ORCA <https://github.com/unc-enap/Orca>`_
* GRETINA digitizer (Majorana firmware) read out with ORCA
Partial support is in place but requires updating for
* SIS3316 read out with ORCA
* SIS3316 read out with LLaMA-DAQ
* CAEN DT57XX digitizers read out with CoMPASS
* FlashCam ADC (requires `fcutils <https://github.com/legend-exp/pyfcutils>`_)
* FlashCam ADC read out with `ORCA <https://github.com/unc-enap/Orca>`_
"""

from .build_raw import build_raw
from pygama.raw.build_raw import build_raw
2 changes: 1 addition & 1 deletion src/pygama/raw/data_streamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def open_stream(self, stream_name: str, rb_lib: RawBufferLibrary = None,
if '*' in rb_lib: rb_lib.pop('*')
for dec_name in rb_lib.keys():
if dec_name not in dec_names:
log.warning("no decoder named {dec_name} requested by rb_lib")
log.warning(f"no decoder named '{dec_name}' requested by rb_lib")

def close_stream(self) -> None:
"""Close this data stream.
Expand Down
28 changes: 16 additions & 12 deletions src/pygama/raw/orca/orca_base.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,38 @@
from ..data_decoder import *
from __future__ import annotations

from pygama.raw.data_decoder import DataDecoder
from pygama.raw.orca.orca_header import OrcaHeader


class OrcaDecoder(DataDecoder):
""" Base class for ORCA decoders.
"""Base class for ORCA decoders.
Mostly here to provide a standard interface for setting the header in init
Mostly here to provide a standard interface for setting the header during
initialization.
"""
def __init__(self, header=None, **kwargs):
def __init__(self, header: OrcaHeader = None, **kwargs) -> None:
super().__init__(**kwargs)
self.header = None
if header: self.set_header(header) # allow for derived class function to be called

if header:
self.set_header(header) # allow for derived class function to be called

def set_header(self, header):
''' Setter for headers. Overload to set card parameters, etc. '''
def set_header(self, header: OrcaHeader) -> None:
"""Setter for headers. Overload to set card parameters, etc."""
self.header = header


# define a standard hash for crate, card, channel <--> integer
def get_ccc(crate, card, channel):
def get_ccc(crate: int, card: int, channel: int) -> int:
return (crate << 9) + ((card & 0x1f) << 4) + (channel & 0xf)


def get_crate(ccc):
def get_crate(ccc: int) -> int:
return ccc >> 9


def get_card(ccc):
def get_card(ccc: int) -> int:
return (ccc >> 4) & 0x1f


def get_channel(ccc):
def get_channel(ccc: int) -> int:
return ccc & 0xf
Loading

0 comments on commit 8673620

Please sign in to comment.