Error when trying to write to DB with empty Throughput Container

Summary

When I launch the throughput_calibrator tool with the option to write to the DB, but the provided muon data have no events for which optical efficiency can be calculated with the required quality, then the pipeline is crushed.

Steps to reproduce

Execute run_tool() for calibpipe/tools/throughput_calibrator.py with DB writing flag -w=True, but set quality cuts for muons tight enough that no events can pass these cuts.

What is the expected correct behavior?

Pipeline should not be crashed in such a situation. This happens because the MuonCalibrator returns empty ThroughputContainer, and then during updating DB the TableHandler tries to access timestamps from thisThroughputContainer, but these timestamps do not exist and this raises the error.

Relevant logs and/or screenshots


2024-01-26 13:59:03,330 ERROR [calibpipe.calibpipe-throughput-calibration] (tool.run): Caught unexpected exception: 'NoneType' object has no attribute 'c'
Traceback (most recent call last):
  File "/Users/vdk/mambaforge/envs/cta/lib/python3.11/site-packages/ctapipe/core/tool.py", line 426, in run
    self.start()
  File "/Users/vdk/Software/ctasoft/calibpipe/calibpipe/tools/throughput_calibrator.py", line 134, in start
    self.update_throughput_db(self.throughputs)
  File "/Users/vdk/Software/ctasoft/calibpipe/calibpipe/tools/throughput_calibrator.py", line 231, in update_throughput_db
    msg = TableHandler.update_tables_info(
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/vdk/Software/ctasoft/calibpipe/calibpipe/database/interfaces/table_handler.py", line 143, in update_tables_info
    sa.func.min(table.c.validity_start).label("min_time"),
                ^^^^^^^
AttributeError: 'NoneType' object has no attribute 'c'

Possible fixes

So I see two ways how to solve this, which depend on the fact - do we need to store in DB information that particular tel_id+obs_id gave us muon data that don't fit into our perceptions of muon quality cuts?

  • If we don't need to store this information, then we can add a condition to the throughput_calibrator tool, which checks if ThroughputContainer is not empty, and only in that case the tool executes function update_throughput_db
  • If we need to store this information, then we can add the method to the throughput_calibrator tool, which checks if ThroughputContainer is empty, and in the case of True, it updates DB with some template row that reports about this "not fitted data"
Edited by Vadym Voitsekhovskyi