Skip to content

Commit

Permalink
fix crash due to wrong treatment of pointers in ONNX-related code, an…
Browse files Browse the repository at this point in the history
…d remove one photon-ID variable from decorations when not needed (#108)

* fix crash due to wrong treatment of pointers (see #104 (comment))

* simplify code
  • Loading branch information
giovannimarchiori committed Aug 29, 2024
1 parent 24fc6e0 commit 952997a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
4 changes: 2 additions & 2 deletions RecFCCeeCalorimeter/src/components/AugmentClustersFCCee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ StatusCode AugmentClustersFCCee::initialize()
showerShapeDecorations.push_back(Form("energy_fraction_%s_layer_%d", detector, layer));
showerShapeDecorations.push_back(Form("theta_%s_layer_%d", detector, layer));
showerShapeDecorations.push_back(Form("phi_%s_layer_%d", detector, layer));
showerShapeDecorations.push_back(Form("maxcell_E_%s_layer_%d", detector, layer));
// pi0/photon shape var only calculated in EMB
if (m_do_photon_shapeVar && m_systemIDs[k] == systemID_EMB) {
showerShapeDecorations.push_back(Form("maxcell_E_%s_layer_%d", detector, layer));
showerShapeDecorations.push_back(Form("width_theta_%s_layer_%d", detector, layer));
showerShapeDecorations.push_back(Form("width_module_%s_layer_%d", detector, layer));
showerShapeDecorations.push_back(Form("Ratio_E_max_2ndmax_%s_layer_%d", detector, layer));
Expand Down Expand Up @@ -651,7 +651,7 @@ StatusCode AugmentClustersFCCee::execute([[maybe_unused]] const EventContext &ev
return StatusCode::FAILURE;
}
width_theta[layer+startPositionToFill] = (sumEnLayer[layer+startPositionToFill] > 0.) ? std::sqrt(std::fabs(w_theta2)) : 0. ;
}
}
double w_module2 = module2_E_layer[layer+startPositionToFill] / sumEnLayer[layer+startPositionToFill] - std::pow(module_E_layer[layer+startPositionToFill] / sumEnLayer[layer+startPositionToFill], 2);
// Very small but negative values caused by computational precision are allowed,
// otherwise crash.
Expand Down
12 changes: 11 additions & 1 deletion RecFCCeeCalorimeter/src/components/CalibrateCaloClusters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,22 @@ StatusCode CalibrateCaloClusters::finalize()
{
if (m_ortSession)
delete m_ortSession;

if (m_ortEnv)
delete m_ortEnv;

for (auto& name : m_input_names) {
delete name;
}

for (auto& name : m_output_names) {
delete name;
}

return Gaudi::Algorithm::finalize();
}


edm4hep::ClusterCollection *CalibrateCaloClusters::initializeOutputClusters(
const edm4hep::ClusterCollection *inClusters) const
{
Expand Down Expand Up @@ -271,7 +281,7 @@ StatusCode CalibrateCaloClusters::readCalibrationFile(const std::string &calibra
#if ORT_API_VERSION < 13
m_output_names.emplace_back(AllocatedStringPtr(m_ortSession->GetOutputName(i, allocator), allocDeleter).release());
#else
m_output_names.emplace_back(m_ortSession->GetOutputNameAllocated(i, allocator).get());
m_output_names.emplace_back(m_ortSession->GetOutputNameAllocated(i, allocator).release());
#endif
m_output_shapes = m_ortSession->GetOutputTypeInfo(i).GetTensorTypeAndShapeInfo().GetShape();
debug() << "\t" << m_output_names.at(i) << " : ";
Expand Down
11 changes: 10 additions & 1 deletion RecFCCeeCalorimeter/src/components/PhotonIDTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,18 @@ StatusCode PhotonIDTool::finalize()
{
if (m_ortSession)
delete m_ortSession;

if (m_ortEnv)
delete m_ortEnv;

for (auto& name : m_input_names) {
delete name;
}

for (auto& name : m_output_names) {
delete name;
}

return Gaudi::Algorithm::finalize();
}

Expand Down Expand Up @@ -341,7 +350,7 @@ StatusCode PhotonIDTool::readMVAFiles(const std::string& mvaInputsFileName,
#if ORT_API_VERSION < 13
m_output_names.emplace_back(AllocatedStringPtr(m_ortSession->GetOutputName(i, allocator), allocDeleter).release());
#else
m_output_names.emplace_back(m_ortSession->GetOutputNameAllocated(i, allocator).get());
m_output_names.emplace_back(m_ortSession->GetOutputNameAllocated(i, allocator).release());
#endif

m_output_shapes = m_ortSession->GetOutputTypeInfo(i).GetTensorTypeAndShapeInfo().GetShape();
Expand Down

0 comments on commit 952997a

Please sign in to comment.