From 14d9bf54815b2d79e3c1e024af11f161df944095 Mon Sep 17 00:00:00 2001 From: Giovanni Marchiori Date: Wed, 12 Jun 2024 23:11:28 +0200 Subject: [PATCH 1/5] fix crash if input clusters do not have shapeParameters, and fix calibration code crash with new ONNX runtime --- .../src/components/AugmentClustersFCCee.cpp | 7 +++---- .../src/components/AugmentClustersFCCee.h | 4 ++-- .../src/components/CalibrateCaloClusters.cpp | 13 ++++++++++--- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/RecFCCeeCalorimeter/src/components/AugmentClustersFCCee.cpp b/RecFCCeeCalorimeter/src/components/AugmentClustersFCCee.cpp index f648b968..b108c9ec 100644 --- a/RecFCCeeCalorimeter/src/components/AugmentClustersFCCee.cpp +++ b/RecFCCeeCalorimeter/src/components/AugmentClustersFCCee.cpp @@ -67,8 +67,9 @@ 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 emptyVector; + std::vector showerShapeDecorations = m_inShapeParameterHandle.get(emptyVector); for (size_t k = 0; k < m_detectorNames.size(); k++) { const char *detector = m_detectorNames[k].c_str(); @@ -91,8 +92,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..36e6f9ed 100644 --- a/RecFCCeeCalorimeter/src/components/CalibrateCaloClusters.cpp +++ b/RecFCCeeCalorimeter/src/components/CalibrateCaloClusters.cpp @@ -97,7 +97,8 @@ 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 emptyVector; + std::vector shapeParameters = m_inShapeParameterHandle.get(emptyVector); shapeParameters.push_back("rawE"); m_outShapeParameterHandle.put(shapeParameters); @@ -241,7 +242,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 +267,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++) From 400aba3b5e9afb047c201fd2fe88cfdf27a83387 Mon Sep 17 00:00:00 2001 From: Giovanni Marchiori Date: Fri, 14 Jun 2024 10:19:31 +0200 Subject: [PATCH 2/5] simplify call to metadatahandle get method --- RecFCCeeCalorimeter/src/components/AugmentClustersFCCee.cpp | 3 +-- RecFCCeeCalorimeter/src/components/CalibrateCaloClusters.cpp | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/RecFCCeeCalorimeter/src/components/AugmentClustersFCCee.cpp b/RecFCCeeCalorimeter/src/components/AugmentClustersFCCee.cpp index b108c9ec..921298c3 100644 --- a/RecFCCeeCalorimeter/src/components/AugmentClustersFCCee.cpp +++ b/RecFCCeeCalorimeter/src/components/AugmentClustersFCCee.cpp @@ -68,8 +68,7 @@ StatusCode AugmentClustersFCCee::initialize() // initialise the list of metadata for the clusters // append to the metadata of the input clusters (if any) - std::vector emptyVector; - std::vector showerShapeDecorations = m_inShapeParameterHandle.get(emptyVector); + std::vector showerShapeDecorations = m_inShapeParameterHandle.get({}); for (size_t k = 0; k < m_detectorNames.size(); k++) { const char *detector = m_detectorNames[k].c_str(); diff --git a/RecFCCeeCalorimeter/src/components/CalibrateCaloClusters.cpp b/RecFCCeeCalorimeter/src/components/CalibrateCaloClusters.cpp index 36e6f9ed..2963d1cf 100644 --- a/RecFCCeeCalorimeter/src/components/CalibrateCaloClusters.cpp +++ b/RecFCCeeCalorimeter/src/components/CalibrateCaloClusters.cpp @@ -97,8 +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 emptyVector; - std::vector shapeParameters = m_inShapeParameterHandle.get(emptyVector); + std::vector shapeParameters = m_inShapeParameterHandle.get({}); shapeParameters.push_back("rawE"); m_outShapeParameterHandle.put(shapeParameters); From 490e05bfbd7d9baefc9fd8448ef68d6277556c52 Mon Sep 17 00:00:00 2001 From: Giovanni Marchiori Date: Mon, 17 Jun 2024 10:47:45 +0200 Subject: [PATCH 3/5] further fixes --- RecCalorimeter/src/components/CreateCaloCells.cpp | 6 +++++- .../src/components/CreateCaloCellPositionsFCCee.cpp | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/RecCalorimeter/src/components/CreateCaloCells.cpp b/RecCalorimeter/src/components/CreateCaloCells.cpp index 59139bc5..36a42e75 100644 --- a/RecCalorimeter/src/components/CreateCaloCells.cpp +++ b/RecCalorimeter/src/components/CreateCaloCells.cpp @@ -67,7 +67,11 @@ StatusCode CreateCaloCells::initialize() { } // Copy over the CellIDEncoding string from the input collection to the output collection - m_cellsCellIDEncoding.put(m_hitsCellIDEncoding.get()); + std::string hitsEncoding = m_hitsCellIDEncoding.get({}); + if (hitsEncoding == "") { + warning() << "Missing cellID encoding for input collection" << endmsg; + } + m_cellsCellIDEncoding.put(hitsEncoding); return StatusCode::SUCCESS; } diff --git a/RecFCCeeCalorimeter/src/components/CreateCaloCellPositionsFCCee.cpp b/RecFCCeeCalorimeter/src/components/CreateCaloCellPositionsFCCee.cpp index 4f19b705..6407bf1c 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; } From 4509cbcacf4ceb4a37a51cbc1962975861ae7e2e Mon Sep 17 00:00:00 2001 From: Giovanni Marchiori Date: Tue, 18 Jun 2024 01:47:52 +0200 Subject: [PATCH 4/5] throw an error if cellID encoding is missing in input --- RecCalorimeter/src/components/CreateCaloCells.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/RecCalorimeter/src/components/CreateCaloCells.cpp b/RecCalorimeter/src/components/CreateCaloCells.cpp index 36a42e75..f84af922 100644 --- a/RecCalorimeter/src/components/CreateCaloCells.cpp +++ b/RecCalorimeter/src/components/CreateCaloCells.cpp @@ -69,7 +69,8 @@ StatusCode CreateCaloCells::initialize() { // Copy over the CellIDEncoding string from the input collection to the output collection std::string hitsEncoding = m_hitsCellIDEncoding.get({}); if (hitsEncoding == "") { - warning() << "Missing cellID encoding for input collection" << endmsg; + error () << "Missing cellID encoding for input collection" << endmsg; + return StatusCode::FAILURE; } m_cellsCellIDEncoding.put(hitsEncoding); From 22b9cff6b4bafab40e95e545ba8bf0845fd2f206 Mon Sep 17 00:00:00 2001 From: Giovanni Marchiori Date: Fri, 21 Jun 2024 10:50:12 +0200 Subject: [PATCH 5/5] implement suggestion from review --- RecCalorimeter/src/components/CreateCaloCells.cpp | 6 +++--- .../src/components/CreateCaloCellPositionsFCCee.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/RecCalorimeter/src/components/CreateCaloCells.cpp b/RecCalorimeter/src/components/CreateCaloCells.cpp index f84af922..62c5e550 100644 --- a/RecCalorimeter/src/components/CreateCaloCells.cpp +++ b/RecCalorimeter/src/components/CreateCaloCells.cpp @@ -67,12 +67,12 @@ StatusCode CreateCaloCells::initialize() { } // Copy over the CellIDEncoding string from the input collection to the output collection - std::string hitsEncoding = m_hitsCellIDEncoding.get({}); - if (hitsEncoding == "") { + 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); + m_cellsCellIDEncoding.put(hitsEncoding.value()); return StatusCode::SUCCESS; } diff --git a/RecFCCeeCalorimeter/src/components/CreateCaloCellPositionsFCCee.cpp b/RecFCCeeCalorimeter/src/components/CreateCaloCellPositionsFCCee.cpp index 6407bf1c..a29793ca 100644 --- a/RecFCCeeCalorimeter/src/components/CreateCaloCellPositionsFCCee.cpp +++ b/RecFCCeeCalorimeter/src/components/CreateCaloCellPositionsFCCee.cpp @@ -35,7 +35,7 @@ StatusCode CreateCaloCellPositionsFCCee::initialize() { } // Copy over the CellIDEncoding string from the input collection to the output collection - std::string hitsEncoding = m_hitsCellIDEncoding.get({}); + std::string hitsEncoding = m_hitsCellIDEncoding.get(""); if (hitsEncoding == "") { warning() << "Missing cellID encoding for input collection" << endmsg; }