Skip to content

Hardware Link (caen.readout)

caen.readout

Binary MBLT buffer decoding for CAEN DT5780 DPP-PHA Board and Channel Aggregates.

Board_Aggregate

Decoder for the 4-word DPP-PHA Board Aggregate header.

Validates the 0xA magic header nibble and board-fail status bit, and extracts aggregate size, counter, and active channel mask.

Attributes:

Name Type Description
consistent bool

True if header magic nibble is 0xA and board fail bit is 0.

AggrSize int

Total Board Aggregate size in 32-bit words.

AggrCntr int

23-bit sequential aggregate counter.

Channels list[int]

Active channel indices present in this aggregate (e.g., [0, 1]).

Source code in caen/readout.py
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
class Board_Aggregate: # Board Aggregate Format
    """Decoder for the 4-word DPP-PHA Board Aggregate header.

    Validates the ``0xA`` magic header nibble and board-fail status bit, and
    extracts aggregate size, counter, and active channel mask.

    Attributes:
        consistent (bool): ``True`` if header magic nibble is ``0xA`` and board fail bit is ``0``.
        AggrSize (int): Total Board Aggregate size in 32-bit words.
        AggrCntr (int): 23-bit sequential aggregate counter.
        Channels (list[int]): Active channel indices present in this aggregate (e.g., ``[0, 1]``).
    """
    AggrSize, AggrCntr, Channels = 0, 0, []
    def __init__(self, BUFF):
        self.consistent  = (BUFF[0]>>28  ==  0xA) # 0b1010 in bits [31:28]
        self.consistent &= (BUFF[1]>>26 & 1 == 0) # board fail flag
        self.AggrSize = BUFF[0] & 0xFFFFFFF
        self.AggrCntr = BUFF[2] & 0x7FFFFF
        mask = BUFF[1] & 0xFF
        self.Channels = [i for i in (0,1) if mask>>i & 1]

Channel_Aggregate

Decoder for the 2-word DPP-PHA Channel Aggregate header.

Parses format flags (dual trace, waveform, energy, time-tag presence), waveform sample count, and derives the number of events in the block.

Attributes:

Name Type Description
consistent bool

True if header format bit is valid and SZ is divisible by EventSize.

SZ int

Channel payload size in 32-bit words (excluding the 2-word header).

DT int

Dual-trace mode flag (1 if two analog traces are packed).

WF int

Waveform recording enabled flag.

EN int

Energy word enabled flag.

TT int

Time-tag word enabled flag.

NS int

Number of 32-bit waveform sample pairs per event.

NumEvents int

Number of complete events in this channel aggregate.

EventSize int

Size of a single event record in 32-bit words.

Source code in caen/readout.py
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
class Channel_Aggregate: # Channel Aggregate Format
    """Decoder for the 2-word DPP-PHA Channel Aggregate header.

    Parses format flags (dual trace, waveform, energy, time-tag presence),
    waveform sample count, and derives the number of events in the block.

    Attributes:
        consistent (bool): ``True`` if header format bit is valid and ``SZ`` is divisible by ``EventSize``.
        SZ (int): Channel payload size in 32-bit words (excluding the 2-word header).
        DT (int): Dual-trace mode flag (``1`` if two analog traces are packed).
        WF (int): Waveform recording enabled flag.
        EN (int): Energy word enabled flag.
        TT (int): Time-tag word enabled flag.
        NS (int): Number of 32-bit waveform sample pairs per event.
        NumEvents (int): Number of complete events in this channel aggregate.
        EventSize (int): Size of a single event record in 32-bit words.
    """
    SZ, DT, WF, EN, TT, NS = 0, 0, 0, 0, 0, 0
    def __init__(self, BUFF):
        if BUFF:
            self.consistent = BUFF[0]>>31 == 1 # Format Info in Channel Aggregate
            self.SZ = (BUFF[0] & 0x1FFFFF) - 2 # aggr. size without a header
            self.DT = BUFF[1]>>31 & 1    # Dual Trace
            self.WF = BUFF[1]>>30 & 1    # WaveForms
            self.EN = BUFF[1]>>29 & 1    # Energy
            self.TT = BUFF[1]>>28 & 1    # Time Tag
            self.NS = BUFF[1] & 0xFFFF   # N Samples
            EventSize = self.EN + self.TT + self.NS
            self.consistent &= EventSize>0
        else:
            self.consistent = False
        if self.consistent:
            NumEvents = self.SZ / EventSize
            self.consistent &= NumEvents == int(NumEvents)
            if self.consistent:
                self.NumEvents = int(NumEvents)
                self.EventSize = EventSize
            else:
                print(f"W:{self.NS} + E:{self.EN} + T:{self.TT} = S:{self.SZ}")

Event

Decoder for a single DPP-PHA event record within a Channel Aggregate.

Extracts the 30-bit hardware trigger timestamp, optional dual analog/digital oscilloscope traces, full 15-bit energy amplitude, and 12-bit EXTRAS flags.

Attributes:

Name Type Description
KEYS tuple[str, ...]

Bit-ordered labels for the 12-bit EXTRAS status word.

AT tuple[list[int], list[int]]

Decoded analog trace samples (trace_0, trace_1).

DT tuple[list[int], list[int]]

Decoded digital virtual probe samples (probe_0, probe_1).

TimeTag int

30-bit trigger timestamp in clock ticks.

Energy int

15-bit pulse height (0 .. 32767 LSB).

Extras int

12-bit EXTRAS status bitmask.

Source code in caen/readout.py
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
class Event:
    """Decoder for a single DPP-PHA event record within a Channel Aggregate.

    Extracts the 30-bit hardware trigger timestamp, optional dual analog/digital
    oscilloscope traces, full 15-bit energy amplitude, and 12-bit ``EXTRAS`` flags.

    Attributes:
        KEYS (tuple[str, ...]): Bit-ordered labels for the 12-bit ``EXTRAS`` status word.
        AT (tuple[list[int], list[int]]): Decoded analog trace samples ``(trace_0, trace_1)``.
        DT (tuple[list[int], list[int]]): Decoded digital virtual probe samples ``(probe_0, probe_1)``.
        TimeTag (int): 30-bit trigger timestamp in clock ticks.
        Energy (int): 15-bit pulse height (``0 .. 32767`` LSB).
        Extras (int): 12-bit ``EXTRAS`` status bitmask.
    """
    KEYS = ("Dead Time",
            "Roll Over",
            "TT Reset",
            "Fake Event",
            "Input Saturation",
            "Lost Trigger",
            "Total Trigger",
            "Reserved 7",
            "Reserved 8",
            "Reserved 9",
            "Pile Up",
            "Saturation Protection Time")

    def __init__(self, FORMAT, BUFF):
        self.AT, self.DT   = ([], []), ([], []) # Analog & Digital Traces
        addr = 0
        if FORMAT.TT:   # Time Tag
            #self.RollOver = bool(BUFF[addr]>>31)
            self.TimeTag  = BUFF[addr] & 0x3FFFFFFF
            addr += 1
        if FORMAT.WF:   # Waveform
            i = 1 if FORMAT.DT else 0
            try:
                for s in range(FORMAT.NS):
                    self.AT[i].append(BUFF[addr] & 0x3FFF)
                    self.DT[1].append(BUFF[addr]>>14 & 1)
                    self.DT[0].append(BUFF[addr]>>15 & 1)
                    self.AT[0].append(BUFF[addr]>>16 & 0x3FFF)
                    self.DT[1].append(BUFF[addr]>>30 & 1)
                    self.DT[0].append(BUFF[addr]>>31 & 1)
                    addr += 1
            except IndexError:
                pass
        if FORMAT.EN:   # Energy
            self.Energy = BUFF[addr] & 0x7FFF
#            self.PileUp = BUFF[addr]>>15 & 1
        self.Extras = BUFF[addr]>>16 & 0xFFF

ReadOut(device, DEBUG=True)

Read an MBLT data block from the digitizer and decode all channel events.

Parameters:

Name Type Description Default
device TheBoard

Connected digitizer instance with an active ReadOutBuffer.

required
DEBUG bool

Print diagnostic messages on malformed aggregates or truncated blocks.

True

Returns:

Type Description
tuple[list, list] | None

Two-element tuple (events_ch0, events_ch1) of :class:Event lists, or None if a Board Aggregate header is inconsistent.

Source code in caen/readout.py
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
def ReadOut(device, DEBUG = True) -> tuple[list, list] | None:
    """Read an MBLT data block from the digitizer and decode all channel events.

    Args:
        device (TheBoard): Connected digitizer instance with an active ``ReadOutBuffer``.
        DEBUG (bool): Print diagnostic messages on malformed aggregates or truncated blocks.

    Returns:
        Two-element tuple ``(events_ch0, events_ch1)`` of :class:`Event` lists, or ``None`` if a Board Aggregate header is inconsistent.
    """
    newl = lambda x: print(x) if DEBUG else False
    nonl = lambda x: print(x, end=" ") if DEBUG else False
    nw   = device.ReadData()      # number of 32-bit words read from device
    buff = device.ReadOutBuffer   # ReadOut buffer
    newl(f"Read {nw} words of data {device.BufferSize}")
    Events = ([], [])
    NAgg, addr = 0, 0
    while addr < nw:
        BA = Board_Aggregate(buff[addr: addr+4])
        if BA.consistent:
            NAgg +=1
            addr += 4
            newl(f"Aggregate {BA.AggrCntr+1} size {BA.AggrSize}")
            for ch in BA.Channels:
                CA = Channel_Aggregate(buff[addr: addr+2])
                addr += 2
                if CA.consistent and addr < nw:
                    newl(f"Channel {ch} Nevents = {CA.NumEvents}")
                    for e in range(CA.NumEvents):
                        if addr < nw:
                            Events[ch].append(Event(CA, buff[addr:addr + CA.EventSize]))
                            addr += CA.EventSize
                        else:
                            newl(f"event num: {e}")
                            break
                if addr >= nw:
                    newl(f"break readout {ch}!")
                    break
        else:
            newl(f"Board Aggregate Inconsistent")
            return None
#    print(f"CH0 Ne: {len(Events[0])}, CH1 Ne: {len(Events[1])}")
#    print(f"N_Aggr: {NAgg}", end=" ")
    return Events