Skip to content

Commit

Permalink
Allocate on heap
Browse files Browse the repository at this point in the history
  • Loading branch information
sfegan committed Oct 1, 2024
1 parent 42cb246 commit cfdb4f2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 36 deletions.
4 changes: 2 additions & 2 deletions include/iact_data/zfits_acada_data_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class ZFITSSingleFileACADACameraEventDataSource:
data_stream_type* get_data_stream() override;

static config_type default_config();
const config_type& config() const { return config_; }
config_type config() const { return config_; }

private:
std::string filename_;
Expand Down Expand Up @@ -137,7 +137,7 @@ class ZFITSACADACameraEventDataSource:
void set_next_index(uint64_t next_index) override;

static config_type default_config();
const config_type& config() const { return config_; }
config_type config() const { return config_; }

protected:
using BaseDataSource::source_;
Expand Down
17 changes: 11 additions & 6 deletions src/iact_data/parallel_event_dispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,28 +255,33 @@ void ParallelEventDispatcher::
process_cta_zfits_run(const std::string& filename,
const calin::ix::iact_data::event_dispatcher::EventDispatcherConfig& config)
{
CTAZFITSDataSource cta_file(filename, config.decoder(), config.zfits());
TelescopeRunConfiguration* run_config = cta_file.get_run_configuration();
auto* cta_file = new CTAZFITSDataSource (filename, config.decoder(), config.zfits());
TelescopeRunConfiguration* run_config = cta_file->get_run_configuration();

unsigned nfragments = cta_file.num_fragments();
unsigned nfragments = cta_file->num_fragments();
unsigned nthread = std::min(std::max(config.nthread(), 1U), nfragments);

if(nthread == 1) {
try {
process_src(&cta_file, run_config, config.log_frequency());
process_src(cta_file, run_config, config.log_frequency());
} catch(...) {
delete cta_file;
delete run_config;
throw;
}
} else {
auto* src_factory = new CTAZFITSDataSourceFactory(cta_file);
try {
CTAZFITSDataSourceFactory src_factory(&cta_file);
process_src_factory(&src_factory, run_config, config.log_frequency(), nthread);
process_src_factory(src_factory, run_config, config.log_frequency(), nthread);
} catch(...) {
delete src_factory;
delete cta_file;
delete run_config;
throw;
}
delete src_factory;
}
delete cta_file;
delete run_config;
}

Expand Down
34 changes: 6 additions & 28 deletions src/iact_data/zfits_acada_data_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,29 +482,7 @@ ZFITSACADACameraEventDataSource(const std::string& filename, const config_type&
filename, config), true),
config_(config), run_header_(nullptr)
{
if(source_) {
run_header_ = source_->get_run_header();
data_stream_ = source_->get_data_stream();
}
if((run_header_ == nullptr
or (is_message_type<data_stream_type>() and data_stream_ == nullptr))
and opener_->num_sources() > 1) {
// In this case the first file fragment is missing the RunHeader or DataStream, search
// for it in later fragments then reopen the first fragment

while((run_header_ == nullptr or data_stream_ == nullptr) and isource_ < opener_->num_sources())
{
++isource_;
open_file();
if(run_header_ == nullptr)
run_header_ = source_ ? source_->get_run_header() : nullptr;
if(data_stream_ == nullptr)
data_stream_ = source_ ? source_->get_data_stream() : nullptr;
}

isource_ = 0;
open_file();
}
// nothing to see here
}

template<typename MessageSet>
Expand All @@ -530,14 +508,14 @@ void ZFITSACADACameraEventDataSource<MessageSet>::load_run_header()
}
while((run_header_ == nullptr
or (is_message_type<data_stream_type>() and data_stream_ == nullptr))
and isource_<opener_->num_sources()-1)
and (isource_+1)<opener_->num_sources())
{
++isource_;
open_file();
if(run_header_ == nullptr)
run_header_ = source_ ? source_->get_run_header() : nullptr;
if(data_stream_ == nullptr)
data_stream_ = source_ ? source_->get_data_stream() : nullptr;
if(source_) {
if(run_header_ == nullptr)run_header_ = source_->get_run_header();
if(data_stream_ == nullptr)data_stream_ = source_->get_data_stream();
}
}
if(isource_ != saved_isource) {
isource_ = saved_isource;
Expand Down

0 comments on commit cfdb4f2

Please sign in to comment.