Skip to content

Commit 35962b6

Browse files
committed
Continue updating FITS readers for ACADA
1 parent 5bfadcf commit 35962b6

8 files changed

+118
-81
lines changed

include/calin_global_config.hpp.in

-5
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@
3838
// Flags conditional compilation of GEANT4-specific code
3939
#cmakedefine CALIN_HAVE_GEANT4 1
4040

41-
// CALIN_HAVE_CTA_CAMERASTOACTL
42-
// Flags conditional compilation of code depending on (proprietary)
43-
// CTA CamerasToACTL package
44-
#cmakedefine CALIN_HAVE_CTA_CAMERASTOACTL 1
45-
4641
// Capture various CMake variables to pass to build system provenance class
4742
#define CALIN_BUILD_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}"
4843
#define CALIN_PROTO_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${CALIN_PROTO_INSTALL_DIR}"

include/iact_data/zfits_acada_data_source.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131

3232
namespace calin { namespace iact_data { namespace zfits_acada_data_source {
3333

34+
std::vector<std::string> get_zfits_table_names(std::string filename);
35+
std::vector<std::string> get_zfits_table_column_names(std::string filename, std::string tablename);
36+
std::vector<std::string> get_zfits_table_keys(std::string filename, std::string tablename);
37+
std::map<std::string,std::string> get_zfits_table_key_values(std::string filename, std::string tablename);
38+
3439
template<typename EventMessage, typename HeaderMessage>
3540
class ZFITSSingleFileACADACameraEventDataSource:
3641
public calin::iact_data::acada_data_source::

src/iact_data/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ set(CALIN_SOURCES algorithms.cpp
2626
nectarcam_ancillary_data.cpp
2727
acada_data_source.cpp zfits_acada_data_source.cpp
2828
acada_event_decoder.cpp
29+
nectarcam_acada_event_decoder_l0.cpp
2930
nectarcam_acada_event_decoder_r1v0.cpp
3031
zfits_data_source.cpp)
3132

src/iact_data/cta_acada_event_decoder_r1v0.cpp

-22
Original file line numberDiff line numberDiff line change
@@ -61,28 +61,6 @@ bool CTA_ACADACameraEventDecoder_R1v0::decode(
6161
const event_type* cta_event)
6262
{
6363
ensure_deligate(cta_event, nullptr);
64-
65-
if(this->delegate()==nullptr) {
66-
if((config_.camera_type() == CTACameraEventDecoderConfig::NECTARCAM) or
67-
((config_.camera_type() == CTACameraEventDecoderConfig::AUTO_DETECT) and
68-
(cta_event!=nullptr and cta_event->has_nectarcam())))
69-
this->set_delegate(new NectarCam_ACADACameraEventDecoder_R1v0(filename_, run_number_, config_.nectarcam()),true);
70-
else if((config_.camera_type() == CTACameraEventDecoderConfig::LSTCAM) or
71-
((config_.camera_type() == CTACameraEventDecoderConfig::AUTO_DETECT) and
72-
(cta_event!=nullptr and cta_event->has_lstcam())))
73-
this->set_delegate(new LSTCam_ACADACameraEventDecoder_R1v0(filename_, run_number_, config_.lstcam()),true);
74-
else
75-
throw std::runtime_error("CTA_ACADACameraEventDecoder_R1v0: event does not "
76-
"have NectarCAM or LSTCam extensions");
77-
} else if(config_.camera_type() == CTACameraEventDecoderConfig::AUTO_DETECT
78-
and dynamic_cast<LSTCam_ACADACameraEventDecoder_R1v0*>(this->delegate())
79-
and cta_event!=nullptr and cta_event->has_nectarcam()) {
80-
this->set_delegate(new NectarCam_ACADACameraEventDecoder_R1v0(filename_, run_number_, config_.nectarcam()),true);
81-
} else if(config_.camera_type() == CTACameraEventDecoderConfig::AUTO_DETECT
82-
and dynamic_cast<NectarCam_ACADACameraEventDecoder_R1v0*>(this->delegate())
83-
and cta_event!=nullptr and cta_event->has_lstcam()) {
84-
this->set_delegate(new LSTCam_ACADACameraEventDecoder_R1v0(filename_, run_number_, config_.lstcam()),true);
85-
}
8664
return this->delegate()->decode(event, cta_event);
8765
}
8866

src/iact_data/nectarcam_actl_l0_event_decoder.cpp src/iact_data/nectarcam_acada_event_decoder_l0.cpp

+31-50
Original file line numberDiff line numberDiff line change
@@ -25,38 +25,19 @@
2525
#include <memory>
2626
#include <numeric>
2727

28-
#if !defined(__clang__) and defined(__GNUC__) && __GNUC__<5
29-
namespace std {
30-
31-
inline void *align( std::size_t alignment, std::size_t size,
32-
void *&ptr, std::size_t &space ) {
33-
std::uintptr_t pn = reinterpret_cast< std::uintptr_t >( ptr );
34-
std::uintptr_t aligned = ( pn + alignment - 1 ) & - alignment;
35-
std::size_t padding = aligned - pn;
36-
if ( space < size + padding ) return nullptr;
37-
space -= padding;
38-
return ptr = reinterpret_cast< void * >( aligned );
39-
}
40-
41-
}
42-
#endif
43-
4428
#include <util/log.hpp>
4529
#include <util/file.hpp>
46-
#include <iact_data/nectarcam_actl_event_decoder.hpp>
30+
#include <iact_data/nectarcam_acada_event_decoder.hpp>
4731
#include <iact_data/nectarcam_layout.hpp>
4832
#include <iact_data/nectarcam_configuration.hpp>
4933
#include <provenance/system_info.hpp>
5034

51-
using namespace calin::iact_data::nectarcam_actl_event_decoder;
35+
using namespace calin::iact_data::nectarcam_acada_event_decoder;
5236
using namespace calin::ix::iact_data::telescope_event;
5337
using namespace calin::ix::iact_data::telescope_run_configuration;
5438
using namespace calin::ix::iact_data::nectarcam_data_source;
5539
using namespace calin::util::log;
5640

57-
#include <ProtobufIFits.h>
58-
#include <L0.pb.h>
59-
6041
#define TEST_ANYARRAY_TYPES 0
6142

6243
/*
@@ -80,10 +61,10 @@ using namespace calin::util::log;
8061
8162
*/
8263

83-
NectarCam_ACTL_L0_CameraEventDecoder::NectarCam_ACTL_L0_CameraEventDecoder(
64+
NectarCam_ACADACameraEventDecoder_L0::NectarCam_ACADACameraEventDecoder_L0(
8465
const std::string& filename,
8566
unsigned run_number, const config_type& config):
86-
actl_event_decoder::ACTL_L0_CameraEventDecoder(), config_(config),
67+
calin::iact_data::acada_event_decoder::ACADACameraEventDecoder_L0(), config_(config),
8768
filename_(filename), run_number_(run_number)
8869
{
8970
switch(config.exchange_gain_channels()) {
@@ -102,14 +83,14 @@ NectarCam_ACTL_L0_CameraEventDecoder::NectarCam_ACTL_L0_CameraEventDecoder(
10283
}
10384
}
10485

105-
NectarCam_ACTL_L0_CameraEventDecoder::~NectarCam_ACTL_L0_CameraEventDecoder()
86+
NectarCam_ACADACameraEventDecoder_L0::~NectarCam_ACADACameraEventDecoder_L0()
10687
{
10788
// nothing to see here
10889
}
10990

110-
bool NectarCam_ACTL_L0_CameraEventDecoder::decode(
91+
bool NectarCam_ACADACameraEventDecoder_L0::decode(
11192
calin::ix::iact_data::telescope_event::TelescopeEvent* calin_event,
112-
const DataModel::CameraEvent* cta_event)
93+
const event_type* cta_event)
11394
{
11495
calin_event->set_telescope_id(cta_event->telescopeid());
11596
calin_event->set_local_event_number(cta_event->eventnumber());
@@ -321,7 +302,7 @@ bool NectarCam_ACTL_L0_CameraEventDecoder::decode(
321302
if(cta_event->uctsdatapresence() and cta_event->has_uctsdata() and
322303
cta_event->uctsdata().has_data())
323304
{
324-
calin::iact_data::actl_event_decoder::decode_cdts_data(
305+
calin::iact_data::acada_event_decoder::decode_cdts_data(
325306
calin_event->mutable_cdts_data(), cta_event->uctsdata().data());
326307

327308
const auto& cdts = calin_event->cdts_data();
@@ -365,7 +346,7 @@ bool NectarCam_ACTL_L0_CameraEventDecoder::decode(
365346
if(cta_event->tibdatapresence() and cta_event->has_tibdata() and
366347
cta_event->tibdata().has_data())
367348
{
368-
calin::iact_data::actl_event_decoder::decode_tib_data(
349+
calin::iact_data::acada_event_decoder::decode_tib_data(
369350
calin_event->mutable_tib_data(), cta_event->tibdata().data());
370351

371352
const auto& tib = calin_event->tib_data();
@@ -428,11 +409,11 @@ bool NectarCam_ACTL_L0_CameraEventDecoder::decode(
428409

429410
if(calin_event->has_tib_data()) {
430411
calin_event->set_trigger_type(
431-
calin::iact_data::actl_event_decoder::determine_trigger_type(
412+
calin::iact_data::acada_event_decoder::determine_trigger_type(
432413
&calin_event->tib_data(), nullptr));
433414
} else if(calin_event->has_cdts_data()) {
434415
calin_event->set_trigger_type(
435-
calin::iact_data::actl_event_decoder::determine_trigger_type(
416+
calin::iact_data::acada_event_decoder::determine_trigger_type(
436417
nullptr, &calin_event->cdts_data()));
437418
} else {
438419
// Now what cat? Now what?
@@ -447,7 +428,7 @@ bool NectarCam_ACTL_L0_CameraEventDecoder::decode(
447428
if(config_.include_serialized_raw_data())
448429
{
449430
calin_event->set_serialized_raw_event_type(
450-
SerializedRawEventType::SERIALIZED_RAW_EVENT_ACTL_PROTOBUF);
431+
SerializedRawEventType::SERIALIZED_RAW_EVENT_ACADA_PROTOBUF);
451432
cta_event->SerializeToString(calin_event->mutable_serialized_raw_event());
452433
} else {
453434
calin_event->set_serialized_raw_event_type(
@@ -457,14 +438,14 @@ bool NectarCam_ACTL_L0_CameraEventDecoder::decode(
457438
return true;
458439
}
459440

460-
bool NectarCam_ACTL_L0_CameraEventDecoder::decode_run_config(
441+
bool NectarCam_ACADACameraEventDecoder_L0::decode_run_config(
461442
calin::ix::iact_data::telescope_run_configuration::
462443
TelescopeRunConfiguration* calin_run_config,
463-
const DataModel::CameraRunHeader* cta_run_header,
464-
const DataModel::CameraEvent* cta_event)
444+
const header_type* cta_run_header,
445+
const event_type* cta_event)
465446
{
466447
calin_run_config->set_data_transcoder(
467-
"calin::iact_data::nectarcam_actl_event_decoder::NectarCam_ACTL_L0_CameraEventDecoder");
448+
"calin::iact_data::nectarcam_acada_event_decoder::NectarCam_ACADACameraEventDecoder_L0");
468449
calin_run_config->set_filename(filename_);
469450
calin_run_config->add_fragment_filename(filename_);
470451
calin_run_config->set_run_number(run_number_);
@@ -576,13 +557,13 @@ bool NectarCam_ACTL_L0_CameraEventDecoder::decode_run_config(
576557
if(config_.demand_configured_module_id_size() != 0)
577558
{
578559
if(config_.demand_configured_module_id_size() != nmod)
579-
throw std::runtime_error("NectarCam_ACTL_L0_CameraEventDecoder::decode_run_config: "
560+
throw std::runtime_error("NectarCam_ACADACameraEventDecoder_L0::decode_run_config: "
580561
"Demand module list size must equal number of modules in data.");
581562
config_mod_id.clear();
582563
for(int imod=0;imod<nmod;imod++) {
583564
unsigned mod_id = config_.demand_configured_module_id(imod);
584565
if(mod_id >= nmod_camera)
585-
throw std::runtime_error("NectarCam_ACTL_L0_CameraEventDecoder::decode_run_config: "
566+
throw std::runtime_error("NectarCam_ACADACameraEventDecoder_L0::decode_run_config: "
586567
"Demand module id out of range: " + std::to_string(mod_id) + " >= " +
587568
std::to_string(nmod_camera));
588569
config_mod_id.insert(mod_id);
@@ -593,7 +574,7 @@ bool NectarCam_ACTL_L0_CameraEventDecoder::decode_run_config(
593574
for(int imod=0; imod<nmod; imod++) {
594575
unsigned mod_id = calin_run_config->nectarcam().module(imod).module_id();
595576
if(mod_id >= nmod_camera)
596-
throw std::runtime_error("NectarCam_ACTL_L0_CameraEventDecoder::decode_run_config: "
577+
throw std::runtime_error("NectarCam_ACADACameraEventDecoder_L0::decode_run_config: "
597578
"Demand module id out of range: " + std::to_string(mod_id) + " >= " +
598579
std::to_string(nmod_camera));
599580
config_mod_id.insert(mod_id);
@@ -679,7 +660,7 @@ bool NectarCam_ACTL_L0_CameraEventDecoder::decode_run_config(
679660
cta_event->uctsdata().has_data())
680661
{
681662
calin::ix::iact_data::telescope_event::CDTSData calin_cdts_data;
682-
calin::iact_data::actl_event_decoder::decode_cdts_data(
663+
calin::iact_data::acada_event_decoder::decode_cdts_data(
683664
&calin_cdts_data, cta_event->uctsdata().data());
684665

685666
if(calin_cdts_data.white_rabbit_status() == 1) {
@@ -697,7 +678,7 @@ bool NectarCam_ACTL_L0_CameraEventDecoder::decode_run_config(
697678
if(cta_run_header and config_.include_serialized_raw_data())
698679
{
699680
calin_run_config->set_serialized_raw_header_type(
700-
SerializedRawHeaderType::SERIALIZED_RAW_HEADER_ACTL_L0_PROTOBUF);
681+
SerializedRawHeaderType::SERIALIZED_RAW_HEADER_ACADA_L0_PROTOBUF);
701682
cta_run_header->SerializeToString(calin_run_config->mutable_serialized_raw_header());
702683
} else {
703684
calin_run_config->set_serialized_raw_header_type(
@@ -707,10 +688,10 @@ bool NectarCam_ACTL_L0_CameraEventDecoder::decode_run_config(
707688
return true;
708689
}
709690

710-
void NectarCam_ACTL_L0_CameraEventDecoder::
711-
copy_single_gain_integrals(const DataModel::CameraEvent* cta_event,
691+
void NectarCam_ACADACameraEventDecoder_L0::
692+
copy_single_gain_integrals(const event_type* cta_event,
712693
const calin::ix::iact_data::telescope_event::TelescopeEvent* calin_event,
713-
const DataModel::PixelsChannel& cta_image,
694+
const ProtoDataModel::PixelsChannel& cta_image,
714695
calin::ix::iact_data::telescope_event::DigitizedSkyImage* calin_image,
715696
const std::string& which_gain,
716697
calin::ix::iact_data::telescope_event::SignalType signal_type) const
@@ -752,10 +733,10 @@ copy_single_gain_integrals(const DataModel::CameraEvent* cta_event,
752733
}
753734
}
754735

755-
void NectarCam_ACTL_L0_CameraEventDecoder::
756-
copy_single_gain_waveforms(const DataModel::CameraEvent* cta_event,
736+
void NectarCam_ACADACameraEventDecoder_L0::
737+
copy_single_gain_waveforms(const event_type* cta_event,
757738
const calin::ix::iact_data::telescope_event::TelescopeEvent* calin_event,
758-
const DataModel::PixelsChannel& cta_image,
739+
const ProtoDataModel::PixelsChannel& cta_image,
759740
calin::ix::iact_data::telescope_event::DigitizedSkyImage* calin_image,
760741
const std::string& which_gain,
761742
calin::ix::iact_data::telescope_event::SignalType signal_type) const
@@ -838,8 +819,8 @@ copy_single_gain_waveforms(const DataModel::CameraEvent* cta_event,
838819
}
839820
}
840821

841-
unsigned NectarCam_ACTL_L0_CameraEventDecoder::
842-
get_nmod_from_event(const DataModel::CameraEvent* cta_event) const
822+
unsigned NectarCam_ACADACameraEventDecoder_L0::
823+
get_nmod_from_event(const event_type* cta_event) const
843824
{
844825
unsigned nmod = 0;
845826
if(cta_event->has_modulestatus() and
@@ -913,6 +894,6 @@ get_nmod_from_event(const DataModel::CameraEvent* cta_event) const
913894
return nmod;
914895
}
915896

916-
NectarCam_ACTL_L0_CameraEventDecoder* NectarCam_ACTL_L0_CameraEventDecoder::clone() const {
917-
return new NectarCam_ACTL_L0_CameraEventDecoder(*this);
897+
NectarCam_ACADACameraEventDecoder_L0* NectarCam_ACADACameraEventDecoder_L0::clone() const {
898+
return new NectarCam_ACADACameraEventDecoder_L0(*this);
918899
}

src/iact_data/zfits_acada_data_source.cpp

+75
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,81 @@ namespace {
6161
template<> std::string default_message_table_name<ACADA_EventMessage_R1v1>() { return "Events"; }
6262
} // anonymous namespace
6363

64+
std::vector<std::string> calin::iact_data::zfits_acada_data_source::
65+
get_zfits_table_names(std::string filename)
66+
{
67+
calin::util::file::expand_filename_in_place(filename);
68+
std::vector<std::string> tables;
69+
try {
70+
IFits ifits(filename, "", /* force= */ true);
71+
if(ifits) {
72+
tables.push_back(ifits.GetTable().name);
73+
}
74+
while(ifits.hasNextTable()) {
75+
ifits.openNextTable(/* force= */ true);
76+
tables.push_back(ifits.GetTable().name);
77+
}
78+
} catch(...) {
79+
throw std::runtime_error(std::string("Could not open ZFits file: ")+filename);
80+
}
81+
return tables;
82+
}
83+
84+
std::vector<std::string> calin::iact_data::zfits_acada_data_source::
85+
get_zfits_table_column_names(std::string filename, std::string tablename)
86+
{
87+
calin::util::file::expand_filename_in_place(filename);
88+
std::vector<std::string> columns;
89+
try {
90+
IFits ifits(filename, tablename, /* force= */ true);
91+
if(ifits) {
92+
for(const auto& col : ifits.GetColumns()) {
93+
columns.push_back(col.first);
94+
}
95+
}
96+
} catch(...) {
97+
throw std::runtime_error(std::string("Could not open ZFits file table: ")+filename + " -> " + tablename);
98+
}
99+
return columns;
100+
}
101+
102+
std::vector<std::string> calin::iact_data::zfits_acada_data_source::
103+
get_zfits_table_keys(std::string filename, std::string tablename)
104+
{
105+
calin::util::file::expand_filename_in_place(filename);
106+
std::vector<std::string> keys;
107+
try {
108+
IFits ifits(filename, tablename, /* force= */ true);
109+
if(ifits) {
110+
for(const auto& key : ifits.GetKeys()) {
111+
keys.push_back(key.first);
112+
}
113+
}
114+
} catch(...) {
115+
throw std::runtime_error(std::string("Could not open ZFits file table: ")+filename + " -> " + tablename);
116+
}
117+
return keys;
118+
}
119+
120+
std::map<std::string,std::string> calin::iact_data::zfits_acada_data_source::
121+
get_zfits_table_key_values(std::string filename, std::string tablename)
122+
{
123+
calin::util::file::expand_filename_in_place(filename);
124+
std::map<std::string,std::string> key_values;
125+
try {
126+
IFits ifits(filename, tablename, /* force= */ true);
127+
if(ifits) {
128+
for(const auto& key : ifits.GetKeys()) {
129+
key_values[key.first] = key.second.value;
130+
}
131+
}
132+
} catch(...) {
133+
throw std::runtime_error(std::string("Could not open ZFits file table: ")+filename + " -> " + tablename);
134+
}
135+
return key_values;
136+
}
137+
138+
64139
// =============================================================================
65140
// =============================================================================
66141
// =============================================================================

swig/calin_global_definitions.i

+6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727

2828
%{
2929
#include <iostream>
30+
#include <string>
31+
#include <vector>
32+
#include <map>
3033
#include "calin_global_definitions.hpp"
3134
#define SWIG_FILE_WITH_INIT
3235
%}
@@ -36,6 +39,7 @@
3639
%include <std_pair.i>
3740
%include <std_vector.i>
3841
%include <std_string.i>
42+
%include <std_map.i>
3943
%include "calin_stdint.i"
4044

4145
%init %{
@@ -66,4 +70,6 @@
6670
%template (PairUnsignedUnsigned) std::pair<unsigned,unsigned>;
6771
%template (VectorPairUnsignedUnsigned) std::vector<std::pair<unsigned,unsigned> >;
6872

73+
%template (MapStringString) std::map<std::string,std::string>;
74+
6975
%import "calin_global_definitions.hpp"

0 commit comments

Comments
 (0)