From 88d26d2f73c21f0d533b99780869a158ff43761b Mon Sep 17 00:00:00 2001 From: Christian Tacke <58549698+ChristianTackeGSI@users.noreply.github.com> Date: Sat, 24 Dec 2022 18:53:14 +0100 Subject: [PATCH] fix(Ex1Processor): Handle nullptr, cleanup fix part of #1286: The result of ROOT's deserializer should be checked. (cherry picked from commit edb765742d48111c78282938c60c5c1f45ae0c22) --- .../MQ/serialization/1-simple/Ex1Processor.h | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/examples/MQ/serialization/1-simple/Ex1Processor.h b/examples/MQ/serialization/1-simple/Ex1Processor.h index 74dab6910d..7495aa1688 100644 --- a/examples/MQ/serialization/1-simple/Ex1Processor.h +++ b/examples/MQ/serialization/1-simple/Ex1Processor.h @@ -21,7 +21,8 @@ class Ex1Processor : public fair::mq::Device { public: - Ex1Processor() {} + Ex1Processor() = default; + ~Ex1Processor() override = default; void Run() override { @@ -35,8 +36,11 @@ class Ex1Processor : public fair::mq::Device receivedMsgs++; // Deserialize - std::unique_ptr digis(nullptr); - RootSerializer().Deserialize(*msgIn, digis); + auto digis = RootSerializer().DeserializeTo(*msgIn); + if (!digis) { + LOG(warn) << "Deserialization FAILED, skipping"; + continue; + } // Compute TClonesArray hits = FindHits(*digis); @@ -54,22 +58,21 @@ class Ex1Processor : public fair::mq::Device LOG(info) << "Received " << receivedMsgs << " and sent " << sentMsgs << " messages!"; } + private: // do some random dummy task TClonesArray FindHits(const TClonesArray& digis) { TClonesArray hits("MyHit"); + const TVector3 dpos(1 / TMath::Sqrt(12), 1 / TMath::Sqrt(12), 1 / TMath::Sqrt(12)); + const Int_t fDetID = 0; + const Int_t fMCIndex = 0; for (int i = 0; i < digis.GetEntriesFast(); i++) { - TVector3 pos; - TVector3 dpos; // Double_t timestamp = 0; // Double_t timestampErr = 0; - Int_t fDetID = 0; - Int_t fMCIndex = 0; - MyDigi* digi = static_cast(digis.At(i)); - pos.SetXYZ(digi->GetX() + 0.5, digi->GetY() + 0.5, digi->GetZ() + 0.5); - dpos.SetXYZ(1 / TMath::Sqrt(12), 1 / TMath::Sqrt(12), 1 / TMath::Sqrt(12)); - MyHit* hit = new ((hits)[i]) MyHit(fDetID, fMCIndex, pos, dpos); + auto digi = static_cast(digis.At(i)); + const TVector3 pos(digi->GetX() + 0.5, digi->GetY() + 0.5, digi->GetZ() + 0.5); + auto hit = new ((hits)[i]) MyHit(fDetID, fMCIndex, pos, dpos); hit->SetTimeStamp(digi->GetTimeStamp()); hit->SetTimeStampError(digi->GetTimeStampError()); }