Skip to content

Commit

Permalink
Decode SWAT data
Browse files Browse the repository at this point in the history
  • Loading branch information
sfegan committed Sep 20, 2024
1 parent 5a5533f commit cb87c72
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 2 deletions.
3 changes: 3 additions & 0 deletions include/iact_data/acada_event_decoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ void decode_cdts_data(calin::ix::iact_data::telescope_event::CDTSData* calin_cdt
void decode_tib_data(calin::ix::iact_data::telescope_event::TIBData* calin_tib_data,
const AnyArray& cta_array);

void decode_swat_data(calin::ix::iact_data::telescope_event::SWATData* calin_swat_data,
const AnyArray& cta_array);

calin::ix::iact_data::telescope_event::TriggerType determine_trigger_type(
const calin::ix::iact_data::telescope_event::TIBData* calin_tib_data,
const calin::ix::iact_data::telescope_event::CDTSData* calin_cdts_data);
Expand Down
54 changes: 54 additions & 0 deletions proto/iact_data/telescope_event.proto
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,62 @@ message TIBData {
(CFO).desc = "Busy trigger type bit set." ];
};

enum SwatTriggerType {
SWAT_TRIGGER_STORE_EXCLUDE = 0;
SWAT_TRIGGER_STORE_INCLUDE = 1;
SWAT_TRIGGER_ACADA_REQUEST = 2;
SWAT_TRIGGER_SWAT_DECTSION = 3;
};

message SWATData {
uint64 trigger_id = 1 [
(CFO).desc = "Needs documentation." ];
uint64 bunch_id = 2 [
(CFO).desc = "Needs documentation." ];
uint32 trigger_type_code = 3 [
(CFO).desc = "Needs documentation." ];
uint32 trigger_time_s = 4 [
(CFO).desc = "Needs documentation." ];
uint32 trigger_time_qns = 5 [
(CFO).desc = "Needs documentation." ];
bool readout_requested = 6 [
(CFO).desc = "Needs documentation." ];
bool data_available = 7 [
(CFO).desc = "Needs documentation." ];
uint32 hardware_stereo_trigger_mask = 8 [
(CFO).desc = "Needs documentation." ];

bool mono_trigger = 10 [
(CFO).desc = "Mono trigger mask bit set." ];
bool stereo_trigger = 11 [
(CFO).desc = "Stereo trigger mask bit set." ];
bool calibration_trigger = 12 [
(CFO).desc = "Calibration trigger mask bit set." ];
bool photo_electron_trigger = 13 [
(CFO).desc = "Photoelectron trigger mask bit set." ];
bool software_trigger = 14 [
(CFO).desc = "Software trigger mask bit set." ];
bool pedestal_trigger = 15 [
(CFO).desc = "Pedestal trigger mask bit set." ];
bool slow_control_trigger = 16 [
(CFO).desc = "Slow-control trigger mask bit set." ];
bool neighbour_1_trigger = 17 [
(CFO).desc = "Neighbour 1 trigger mask bit set." ];
bool neighbour_2_trigger = 18 [
(CFO).desc = "Neighbour 1 trigger mask bit set." ];
bool neighbour_3_trigger = 19 [
(CFO).desc = "Neighbour 1 trigger mask bit set." ];
bool neighbour_4_trigger = 20 [
(CFO).desc = "Neighbour 1 trigger mask bit set." ];
bool neighbour_5_trigger = 21 [
(CFO).desc = "Neighbour 1 trigger mask bit set." ];
bool neighbour_6_trigger = 22 [
(CFO).desc = "Neighbour 1 trigger mask bit set." ];
bool neighbour_7_trigger = 23 [
(CFO).desc = "Neighbour 1 trigger mask bit set." ];

SwatTriggerType trigger_type = 30 [
(CFO).desc = "Needs documentation." ];
};

enum SignalType {
Expand Down
50 changes: 50 additions & 0 deletions src/iact_data/acada_event_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,3 +525,53 @@ calin::iact_data::acada_event_decoder::determine_trigger_type(
}
return calin::ix::iact_data::telescope_event::TRIGGER_UNKNOWN;
}

void calin::iact_data::acada_event_decoder::
decode_swat_data(calin::ix::iact_data::telescope_event::SWATData* calin_swat_data,
const AnyArray& cta_array)
{
struct SWATMessageData {
uint64_t trigger_id;
uint64_t bunch_id;
uint32_t trigger_type;
uint32_t trigger_time_s;
uint32_t trigger_time_qns;
uint32_t readout_requested;
uint32_t data_available;
uint32_t hardware_stereo_trigger_mask;
} __attribute__((__packed__));

const auto& cta_swat_data = cta_array.data();
if(cta_swat_data.size() != sizeof(SWATMessageData))
throw std::runtime_error("SWAT data array not expected size : "
+ std::to_string(cta_swat_data.size()) + " != "
+ std::to_string(sizeof(SWATMessageData)));
const auto* swat_data =
reinterpret_cast<const SWATMessageData*>(&cta_swat_data.front());

calin_swat_data->set_trigger_id(swat_data->trigger_id);
calin_swat_data->set_bunch_id(swat_data->bunch_id);
calin_swat_data->set_trigger_type_code(swat_data->trigger_type);
calin_swat_data->set_trigger_time_s(swat_data->trigger_time_s);
calin_swat_data->set_trigger_time_qns(swat_data->trigger_time_qns);
calin_swat_data->set_readout_requested(swat_data->readout_requested);
calin_swat_data->set_data_available(swat_data->data_available);
calin_swat_data->set_hardware_stereo_trigger_mask(swat_data->hardware_stereo_trigger_mask);

calin_swat_data->set_mono_trigger(swat_data->trigger_type & 0x0001);
calin_swat_data->set_stereo_trigger(swat_data->trigger_type & 0x0002);
calin_swat_data->set_calibration_trigger(swat_data->trigger_type & 0x0004);
calin_swat_data->set_photo_electron_trigger(swat_data->trigger_type & 0x0008);
calin_swat_data->set_software_trigger(swat_data->trigger_type & 0x0010);
calin_swat_data->set_pedestal_trigger(swat_data->trigger_type & 0x0020);
calin_swat_data->set_slow_control_trigger(swat_data->trigger_type & 0x0040);
calin_swat_data->set_neighbour_1_trigger(swat_data->trigger_type & 0x0100);
calin_swat_data->set_neighbour_2_trigger(swat_data->trigger_type & 0x0200);
calin_swat_data->set_neighbour_3_trigger(swat_data->trigger_type & 0x0400);
calin_swat_data->set_neighbour_4_trigger(swat_data->trigger_type & 0x0800);
calin_swat_data->set_neighbour_5_trigger(swat_data->trigger_type & 0x1000);
calin_swat_data->set_neighbour_6_trigger(swat_data->trigger_type & 0x2000);
calin_swat_data->set_neighbour_7_trigger(swat_data->trigger_type & 0x4000);

calin_swat_data->set_trigger_type(calin::ix::iact_data::telescope_event::SwatTriggerType(swat_data->trigger_type));
}
39 changes: 37 additions & 2 deletions src/iact_data/unified_acada_event_decoder_r1v1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,39 @@ decode(calin::ix::iact_data::telescope_event::TelescopeEvent* calin_event,
calin_event->set_camera_clock_index(7,-1);
}

// **************************************************************************
// SWAT data
// **************************************************************************

if(cta_event->has_debug() and cta_event->debug().has_swat_data()
and cta_event->debug().swat_data().has_data())
{
calin::iact_data::acada_event_decoder::decode_swat_data(
calin_event->mutable_swat_data(), cta_event->debug().swat_data());

const auto& swat = calin_event->swat_data();

if(swat.trigger_id() != cta_event->event_id()) {
calin_event->clear_swat_data();
}
} else {
calin_event->clear_swat_data();
}

if(calin_event->has_swat_data()) {
const auto& swat = calin_event->swat_data();

calin_clock = (calin_event->camera_clock_size()>camera_clock_index) ?
calin_event->mutable_camera_clock(camera_clock_index) : calin_event->add_camera_clock();
calin_event->set_camera_clock_index(8,camera_clock_index++);
calin_clock->set_clock_id(8);
calin_clock->set_time_value(uint64_t(swat.trigger_time_s())*1000000000ULL + (swat.trigger_time_qns()>>2));
calin_clock->set_time_sequence_id(0);
} else {
calin_event->set_camera_clock_index(8,-1);
}


while(calin_event->camera_clock_size()>camera_clock_index) {
calin_event->mutable_camera_clock()->RemoveLast();
}
Expand Down Expand Up @@ -391,8 +424,10 @@ decode_run_config(
ADD_CAMERA_CLOCK("TIB pps counter", 1.0);
ADD_CAMERA_CLOCK("TIB combined 10MHz and pps counter", 1.0e7);

ncamera_clock_ = 8;
nmodule_clock_ = 0;
ADD_CAMERA_CLOCK("SWAT timestamp", 1.0e9);

ncamera_clock_ = calin_run_config->camera_layout().camera_clock_name_size();
nmodule_clock_ = calin_run_config->camera_layout().module_clock_name_size();

// **************************************************************************
// Build configured-module list
Expand Down

0 comments on commit cb87c72

Please sign in to comment.