From 9dae0ae6be63ed5f2aaa1b641847a976736d58af Mon Sep 17 00:00:00 2001 From: Stephen Fegan Date: Tue, 24 Sep 2024 05:55:53 +0200 Subject: [PATCH] Change decoder config types --- .../nectarcam_acada_event_decoder.hpp | 20 +++++----- include/iact_data/nectarcam_data_source.hpp | 34 +++++++++++++++- src/iact_data/cta_data_source.cpp | 14 ++++++- .../nectarcam_acada_event_decoder_r1v1.cpp | 24 +++++++++++- src/iact_data/nectarcam_data_source.cpp | 39 ++++++++++++++++++- 5 files changed, 118 insertions(+), 13 deletions(-) diff --git a/include/iact_data/nectarcam_acada_event_decoder.hpp b/include/iact_data/nectarcam_acada_event_decoder.hpp index aa3a6a79..6596ab81 100644 --- a/include/iact_data/nectarcam_acada_event_decoder.hpp +++ b/include/iact_data/nectarcam_acada_event_decoder.hpp @@ -221,8 +221,8 @@ class NectarCam_ACADACameraEventDecoder_R1v1: public calin::iact_data::unified_acada_event_decoder::Unified_ACADACameraEventDecoder_R1v1 { public: - CALIN_TYPEALIAS(config_type, - calin::iact_data::unified_acada_event_decoder::Unified_ACADACameraEventDecoder_R1v1::config_type); + CALIN_TYPEALIAS(config_type, calin::ix::iact_data:: + nectarcam_data_source::NectarCamCameraEventDecoderConfig); CALIN_TYPEALIAS(message_set_type, calin::iact_data::acada_data_source::ACADA_MessageSet_R1v1); CALIN_TYPEALIAS(event_type, calin::iact_data::acada_data_source::ACADA_MessageSet_R1v1::event_type); @@ -244,17 +244,19 @@ class NectarCam_ACADACameraEventDecoder_R1v1: NectarCam_ACADACameraEventDecoder_R1v1* clone() const override; - static calin::ix::iact_data::cta_data_source::UnifiedCameraEventDecoderConfig default_config() { - return force_nectarcam_camera_type(Unified_ACADACameraEventDecoder_R1v1::default_config()); - } + calin::ix::iact_data::nectarcam_data_source::NectarCamCameraEventDecoderConfig config() const; -protected: - static inline calin::ix::iact_data::cta_data_source::UnifiedCameraEventDecoderConfig force_nectarcam_camera_type( - config_type config) { - config.set_camera_type(calin::ix::iact_data::cta_data_source::NECTARCAM); + static calin::ix::iact_data::nectarcam_data_source::NectarCamCameraEventDecoderConfig default_config() { + config_type config = config_type::default_instance(); + // config.set_nmc_xml_suffix(".NMC.xml"); + config.set_separate_channel_waveforms(true); return config; } +protected: + static inline calin::ix::iact_data::cta_data_source::UnifiedCameraEventDecoderConfig unified_decoder_config( + config_type config); + }; diff --git a/include/iact_data/nectarcam_data_source.hpp b/include/iact_data/nectarcam_data_source.hpp index a514780a..a579d43b 100644 --- a/include/iact_data/nectarcam_data_source.hpp +++ b/include/iact_data/nectarcam_data_source.hpp @@ -131,7 +131,7 @@ class NectarCamZFITSDataSource_R1v0: const config_type& config = default_config()); virtual ~NectarCamZFITSDataSource_R1v0(); private: - nectarcam_acada_event_decoder::NectarCam_ACADACameraEventDecoder_R1v0* decoder_; + calin::iact_data::nectarcam_acada_event_decoder::NectarCam_ACADACameraEventDecoder_R1v0* decoder_; }; /* @@ -156,6 +156,38 @@ class NectarCamZFITSDataSource_R1v0: */ +class NectarCamZFITSDataSource_R1v1: + public calin::iact_data::zfits_data_source::ZFITSDataSource< + calin::iact_data::acada_data_source::ACADA_MessageSet_R1v1> +{ +public: + CALIN_TYPEALIAS(config_type, + ZFITSDataSource::config_type); + CALIN_TYPEALIAS(decoder_config_type, + calin::ix::iact_data::nectarcam_data_source::NectarCamCameraEventDecoderConfig); + + calin::ix::iact_data::nectarcam_data_source::NectarCamCameraEventDecoderConfig decoder_config() const { + return decoder_->config(); } + + static calin::ix::iact_data::nectarcam_data_source::NectarCamCameraEventDecoderConfig default_decoder_config() { + return calin::iact_data::nectarcam_acada_event_decoder::NectarCam_ACADACameraEventDecoder_R1v1::default_config(); + } + + NectarCamZFITSDataSource_R1v1(const std::string& filename, + calin::iact_data::zfits_acada_data_source:: + ZFITSACADACameraEventDataSource* acada_zfits, + const decoder_config_type& decoder_config = default_decoder_config(), + bool adopt_acada_zfits = false); + NectarCamZFITSDataSource_R1v1(const std::string& filename, + const config_type& config, + const decoder_config_type& decoder_config = default_decoder_config()); + NectarCamZFITSDataSource_R1v1(const std::string& filename, + const decoder_config_type& decoder_config = default_decoder_config(), + const config_type& config = default_config()); + virtual ~NectarCamZFITSDataSource_R1v1(); +private: + calin::iact_data::nectarcam_acada_event_decoder::NectarCam_ACADACameraEventDecoder_R1v1* decoder_; +}; /* diff --git a/src/iact_data/cta_data_source.cpp b/src/iact_data/cta_data_source.cpp index d30808b7..56ce4578 100644 --- a/src/iact_data/cta_data_source.cpp +++ b/src/iact_data/cta_data_source.cpp @@ -219,6 +219,16 @@ CTAZFITSDataSource::construct_delegate(std::string filename, "CTAZFITSDataSource::construct_delegate: R1v0 data format not supported with camera type: " + CameraType_Name(decoder_config.camera_type())); } + } else if(config.data_model() == calin::ix::iact_data::zfits_data_source::ACADA_DATA_MODEL_R1V1) { + if(decoder_config.camera_type() == AUTO_DETECT) { + return new NectarCamZFITSDataSource_R1v1(filename, config, decoder_config.nectarcam()); + } else if(decoder_config.camera_type() == NECTARCAM) { + return new NectarCamZFITSDataSource_R1v1(filename, config, decoder_config.nectarcam()); + } else { + throw std::runtime_error( + "CTAZFITSDataSource::construct_delegate: R1v1 data format not supported with camera type: " + + CameraType_Name(decoder_config.camera_type())); + } } else { throw std::runtime_error( "CTAZFITSDataSource::construct_delegate: unsupported data format: " @@ -237,7 +247,9 @@ CTAZFITSDataSource::copy_base_data_source( throw std::runtime_error( "CTAZFITSDataSource::copy_base_data_source: File not found: " + filename); - if(auto* zfits = dynamic_cast(base_data_source->delegate())) { + if(auto* zfits = dynamic_cast(base_data_source->delegate())) { + return new zfits_data_source::ZFITSDataSource_R1v1(filename, zfits, config); + } else if(auto* zfits = dynamic_cast(base_data_source->delegate())) { return new zfits_data_source::ZFITSDataSource_R1v0(filename, zfits, config); }else if(auto* zfits = dynamic_cast(base_data_source->delegate())) { return new zfits_data_source::ZFITSDataSource_L0(filename, zfits, config); diff --git a/src/iact_data/nectarcam_acada_event_decoder_r1v1.cpp b/src/iact_data/nectarcam_acada_event_decoder_r1v1.cpp index ceb15e66..29322e75 100644 --- a/src/iact_data/nectarcam_acada_event_decoder_r1v1.cpp +++ b/src/iact_data/nectarcam_acada_event_decoder_r1v1.cpp @@ -65,7 +65,7 @@ NectarCam_ACADACameraEventDecoder_R1v1:: NectarCam_ACADACameraEventDecoder_R1v1(const std::string& filename, const config_type& config): calin::iact_data::unified_acada_event_decoder::Unified_ACADACameraEventDecoder_R1v1( - filename, force_nectarcam_camera_type(config)) + filename, unified_decoder_config(config)) { // nothing to see here } @@ -308,3 +308,25 @@ NectarCam_ACADACameraEventDecoder_R1v1* NectarCam_ACADACameraEventDecoder_R1v1:: { return new NectarCam_ACADACameraEventDecoder_R1v1(*this); } + +calin::ix::iact_data::cta_data_source::UnifiedCameraEventDecoderConfig +NectarCam_ACADACameraEventDecoder_R1v1::unified_decoder_config(config_type config) { + auto unified_config = + calin::iact_data::unified_acada_event_decoder::Unified_ACADACameraEventDecoder_R1v1::default_config(); + unified_config.set_camera_type(calin::ix::iact_data::cta_data_source::NECTARCAM); + unified_config.set_separate_channel_waveforms(config.separate_channel_waveforms()); + unified_config.set_include_serialized_raw_data(config.separate_channel_waveforms()); + return unified_config; +} + +calin::ix::iact_data::nectarcam_data_source::NectarCamCameraEventDecoderConfig +NectarCam_ACADACameraEventDecoder_R1v1::config() const +{ + calin::ix::iact_data::nectarcam_data_source::NectarCamCameraEventDecoderConfig config; + auto unified_config = + calin::iact_data::unified_acada_event_decoder::Unified_ACADACameraEventDecoder_R1v1::config(); + config.set_camera_type(calin::ix::iact_data::nectarcam_data_source::NectarCamCameraEventDecoderConfig::NECTARCAM); + config.set_separate_channel_waveforms(unified_config.separate_channel_waveforms()); + config.set_include_serialized_raw_data(unified_config.separate_channel_waveforms()); + return config; +} \ No newline at end of file diff --git a/src/iact_data/nectarcam_data_source.cpp b/src/iact_data/nectarcam_data_source.cpp index 1accf76f..aa5ff0f1 100644 --- a/src/iact_data/nectarcam_data_source.cpp +++ b/src/iact_data/nectarcam_data_source.cpp @@ -171,6 +171,43 @@ NectarCamZFITSDataSource_R1v0::~NectarCamZFITSDataSource_R1v0() */ +NectarCamZFITSDataSource_R1v1:: +NectarCamZFITSDataSource_R1v1(const std::string& filename, + calin::iact_data::zfits_acada_data_source:: + ZFITSACADACameraEventDataSource* acada_zfits, + const decoder_config_type& decoder_config, bool adopt_acada_zfits): + calin::iact_data::zfits_data_source::ZFITSDataSource_R1v1( + acada_zfits, + decoder_ = new NectarCam_ACADACameraEventDecoder_R1v1(filename, decoder_config), + adopt_acada_zfits, /* adopt_decoder_= */ false) +{ + // nothing to see here +} + +NectarCamZFITSDataSource_R1v1:: +NectarCamZFITSDataSource_R1v1(const std::string& filename, + const config_type& config, const decoder_config_type& decoder_config): + calin::iact_data::zfits_data_source::ZFITSDataSource_R1v1(filename, + decoder_ = new NectarCam_ACADACameraEventDecoder_R1v1(filename, decoder_config), + /* adopt_decoder_= */ false /* we delete it! */, config) +{ + // nothing to see here +} + + +NectarCamZFITSDataSource_R1v1:: +NectarCamZFITSDataSource_R1v1(const std::string& filename, + const decoder_config_type& decoder_config, const config_type& config): + NectarCamZFITSDataSource_R1v1(filename, config, decoder_config) +{ + // nothing to see here +} + +NectarCamZFITSDataSource_R1v1::~NectarCamZFITSDataSource_R1v1() +{ + delete decoder_; +} + /* AAA tttt @@ -257,7 +294,7 @@ NectarCamZFITSDataSource::construct_delegate(std::string filename, case calin::ix::iact_data::zfits_data_source::ACADA_DATA_MODEL_R1V0: return new NectarCamZFITSDataSource_R1v0(filename, config, decoder_config); case calin::ix::iact_data::zfits_data_source::ACADA_DATA_MODEL_R1V1: - throw std::runtime_error("NectarCamZFITSDataSource::construct_delegate: R1v1 not supported yet"); + return new NectarCamZFITSDataSource_R1v1(filename, config, decoder_config); default: throw std::runtime_error("NectarCamZFITSDataSource::construct_delegate: Requested data model not known"); }