From 450653273ea99c924d236a9d582e103b63ca9f0e Mon Sep 17 00:00:00 2001 From: Giovanni Marchiori <39376142+giovannimarchiori@users.noreply.github.com> Date: Fri, 21 Jun 2024 12:21:44 +0300 Subject: [PATCH] Fixes for two types of crashes in recent nightlies (#83) * fix crash if input clusters do not have shapeParameters, and fix calibration code crash with new ONNX runtime * simplify call to metadatahandle get method * further fixes * throw an error if cellID encoding is missing in input * implement suggestion from review --- RecCalorimeter/src/components/CreateCaloCells.cpp | 7 ++++++- .../src/components/AugmentClustersFCCee.cpp | 6 ++---- .../src/components/AugmentClustersFCCee.h | 4 ++-- .../src/components/CalibrateCaloClusters.cpp | 12 +++++++++--- .../src/components/CreateCaloCellPositionsFCCee.cpp | 6 +++++- 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/RecCalorimeter/src/components/CreateCaloCells.cpp b/RecCalorimeter/src/components/CreateCaloCells.cpp index 59139bc5..62c5e550 100644 --- a/RecCalorimeter/src/components/CreateCaloCells.cpp +++ b/RecCalorimeter/src/components/CreateCaloCells.cpp @@ -67,7 +67,12 @@ StatusCode CreateCaloCells::initialize() { } // Copy over the CellIDEncoding string from the input collection to the output collection - m_cellsCellIDEncoding.put(m_hitsCellIDEncoding.get()); + auto hitsEncoding = m_hitsCellIDEncoding.get_optional(); + if (!hitsEncoding.has_value()) { + error () << "Missing cellID encoding for input collection" << endmsg; + return StatusCode::FAILURE; + } + m_cellsCellIDEncoding.put(hitsEncoding.value()); return StatusCode::SUCCESS; } diff --git a/RecFCCeeCalorimeter/src/components/AugmentClustersFCCee.cpp b/RecFCCeeCalorimeter/src/components/AugmentClustersFCCee.cpp index f648b968..921298c3 100644 --- a/RecFCCeeCalorimeter/src/components/AugmentClustersFCCee.cpp +++ b/RecFCCeeCalorimeter/src/components/AugmentClustersFCCee.cpp @@ -67,8 +67,8 @@ StatusCode AugmentClustersFCCee::initialize() } // initialise the list of metadata for the clusters - // append to the metadata of the input clusters - std::vector showerShapeDecorations = m_inShapeParameterHandle.get(); + // append to the metadata of the input clusters (if any) + std::vector showerShapeDecorations = m_inShapeParameterHandle.get({}); for (size_t k = 0; k < m_detectorNames.size(); k++) { const char *detector = m_detectorNames[k].c_str(); @@ -91,8 +91,6 @@ StatusCode AugmentClustersFCCee::finalize() StatusCode AugmentClustersFCCee::execute([[maybe_unused]] const EventContext &evtCtx) const { - - // get the input collection with clusters const edm4hep::ClusterCollection *inClusters = m_inClusters.get(); diff --git a/RecFCCeeCalorimeter/src/components/AugmentClustersFCCee.h b/RecFCCeeCalorimeter/src/components/AugmentClustersFCCee.h index c96f0eb4..ee951f5c 100644 --- a/RecFCCeeCalorimeter/src/components/AugmentClustersFCCee.h +++ b/RecFCCeeCalorimeter/src/components/AugmentClustersFCCee.h @@ -67,12 +67,12 @@ class AugmentClustersFCCee : public Gaudi::Algorithm this, "systemNames", {"EMB"}, "Names of the detectors, corresponding to systemIDs"}; /// Numbers of layers of the detectors Gaudi::Property> m_numLayers{ - this, "numLayers", {12}, "Numbers of layers of the systems"}; + this, "numLayers", {11}, "Numbers of layers of the systems"}; /// Weights for each detector layer for theta position log-weighting Gaudi::Property>> m_thetaRecalcLayerWeights{ this, "thetaRecalcWeights", - {{-1, 3.0, 3.0, 3.0, 4.25, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0}}, + {{-1, 3.0, 3.0, 3.0, 4.25, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0}}, "Weights for each detector layer for theta position log-weighting. If negative use linear weight."}; /// Name of the detector readouts, corresponding to system IDs in m_systemIDs Gaudi::Property> m_readoutNames{ diff --git a/RecFCCeeCalorimeter/src/components/CalibrateCaloClusters.cpp b/RecFCCeeCalorimeter/src/components/CalibrateCaloClusters.cpp index e0043aee..2963d1cf 100644 --- a/RecFCCeeCalorimeter/src/components/CalibrateCaloClusters.cpp +++ b/RecFCCeeCalorimeter/src/components/CalibrateCaloClusters.cpp @@ -97,7 +97,7 @@ StatusCode CalibrateCaloClusters::initialize() } // read from the metadata the names of the shape parameters in the input clusters and append the total raw energy to the output - std::vector shapeParameters = m_inShapeParameterHandle.get(); + std::vector shapeParameters = m_inShapeParameterHandle.get({}); shapeParameters.push_back("rawE"); m_outShapeParameterHandle.put(shapeParameters); @@ -241,7 +241,10 @@ StatusCode CalibrateCaloClusters::readCalibrationFile(const std::string &calibra debug() << "Input Node Name/Shape (" << m_input_names.size() << "):" << endmsg; for (std::size_t i = 0; i < m_ortSession->GetInputCount(); i++) { - m_input_names.insert(m_input_names.end(), m_ortSession->GetInputNames().begin(), m_ortSession->GetInputNames().end()); + // for old ONNX runtime version + // m_input_names.emplace_back(m_ortSession->GetInputName(i, allocator)); + // for new runtime version + m_input_names.emplace_back(m_ortSession->GetInputNameAllocated(i, allocator).get()); m_input_shapes = m_ortSession->GetInputTypeInfo(i).GetTensorTypeAndShapeInfo().GetShape(); debug() << "\t" << m_input_names.at(i) << " : "; for (std::size_t k = 0; k < m_input_shapes.size() - 1; k++) @@ -263,7 +266,10 @@ StatusCode CalibrateCaloClusters::readCalibrationFile(const std::string &calibra debug() << "Output Node Name/Shape (" << m_output_names.size() << "):" << endmsg; for (std::size_t i = 0; i < m_ortSession->GetOutputCount(); i++) { - m_output_names.insert(m_output_names.end(), m_ortSession->GetOutputNames().begin(), m_ortSession->GetOutputNames().end()); + // for old ONNX runtime version + // m_output_names.emplace_back(m_ortSession->GetOutputName(i, allocator)); + // for new runtime version + m_output_names.emplace_back(m_ortSession->GetOutputNameAllocated(i, allocator).get()); m_output_shapes = m_ortSession->GetOutputTypeInfo(i).GetTensorTypeAndShapeInfo().GetShape(); debug() << "\t" << m_output_names.at(i) << " : "; for (std::size_t k = 0; k < m_output_shapes.size() - 1; k++) diff --git a/RecFCCeeCalorimeter/src/components/CreateCaloCellPositionsFCCee.cpp b/RecFCCeeCalorimeter/src/components/CreateCaloCellPositionsFCCee.cpp index 4f19b705..a29793ca 100644 --- a/RecFCCeeCalorimeter/src/components/CreateCaloCellPositionsFCCee.cpp +++ b/RecFCCeeCalorimeter/src/components/CreateCaloCellPositionsFCCee.cpp @@ -35,7 +35,11 @@ StatusCode CreateCaloCellPositionsFCCee::initialize() { } // Copy over the CellIDEncoding string from the input collection to the output collection - m_positionedHitsCellIDEncoding.put(m_hitsCellIDEncoding.get()); + std::string hitsEncoding = m_hitsCellIDEncoding.get(""); + if (hitsEncoding == "") { + warning() << "Missing cellID encoding for input collection" << endmsg; + } + m_positionedHitsCellIDEncoding.put(hitsEncoding); return StatusCode::SUCCESS; }