From 78655558563af33d153f60a8e6aa7db9b1b86dd9 Mon Sep 17 00:00:00 2001 From: Christian Tacke <58549698+ChristianTackeGSI@users.noreply.github.com> Date: Mon, 30 Sep 2024 21:17:29 +0200 Subject: [PATCH 1/2] chore(templates/Stack): Add override --- .../MyProjData/MyProjStack.h | 106 +++++++++--------- .../MyProjData/MyProjStack.h | 106 +++++++++--------- 2 files changed, 106 insertions(+), 106 deletions(-) diff --git a/templates/project_root_containers/MyProjData/MyProjStack.h b/templates/project_root_containers/MyProjData/MyProjStack.h index 0430411a16..89e76e34d2 100644 --- a/templates/project_root_containers/MyProjData/MyProjStack.h +++ b/templates/project_root_containers/MyProjData/MyProjStack.h @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * Copyright (C) 2014-2024 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * * * * This software is distributed under the terms of the * * GNU Lesser General Public Licence (LGPL) version 3, * @@ -55,7 +55,7 @@ class MyProjStack : public FairGenericStack MyProjStack(Int_t size = 100); /** Destructor **/ - virtual ~MyProjStack(); + ~MyProjStack() override; /** Add a TParticle to the stack. ** Declared in TVirtualMCStack @@ -72,93 +72,93 @@ class MyProjStack : public FairGenericStack *@param weight Particle weight *@param is Generation status code (whatever that means) **/ - virtual void PushTrack(Int_t toBeDone, - Int_t parentID, - Int_t pdgCode, - Double_t px, - Double_t py, - Double_t pz, - Double_t e, - Double_t vx, - Double_t vy, - Double_t vz, - Double_t time, - Double_t polx, - Double_t poly, - Double_t polz, - TMCProcess proc, - Int_t& ntr, - Double_t weight, - Int_t is); - - virtual void PushTrack(Int_t toBeDone, - Int_t parentID, - Int_t pdgCode, - Double_t px, - Double_t py, - Double_t pz, - Double_t e, - Double_t vx, - Double_t vy, - Double_t vz, - Double_t time, - Double_t polx, - Double_t poly, - Double_t polz, - TMCProcess proc, - Int_t& ntr, - Double_t weight, - Int_t is, - Int_t secondParentId); + void PushTrack(Int_t toBeDone, + Int_t parentID, + Int_t pdgCode, + Double_t px, + Double_t py, + Double_t pz, + Double_t e, + Double_t vx, + Double_t vy, + Double_t vz, + Double_t time, + Double_t polx, + Double_t poly, + Double_t polz, + TMCProcess proc, + Int_t& ntr, + Double_t weight, + Int_t is) override; + + void PushTrack(Int_t toBeDone, + Int_t parentID, + Int_t pdgCode, + Double_t px, + Double_t py, + Double_t pz, + Double_t e, + Double_t vx, + Double_t vy, + Double_t vz, + Double_t time, + Double_t polx, + Double_t poly, + Double_t polz, + TMCProcess proc, + Int_t& ntr, + Double_t weight, + Int_t is, + Int_t secondParentId) override; /** Get next particle for tracking from the stack. ** Declared in TVirtualMCStack *@param iTrack index of popped track (return) *@return Pointer to the TParticle of the track **/ - virtual TParticle* PopNextTrack(Int_t& iTrack); + TParticle* PopNextTrack(Int_t& iTrack) override; /** Get primary particle by index for tracking from stack ** Declared in TVirtualMCStack *@param iPrim index of primary particle *@return Pointer to the TParticle of the track **/ - virtual TParticle* PopPrimaryForTracking(Int_t iPrim); + TParticle* PopPrimaryForTracking(Int_t iPrim) override; /** Get total number of tracks ** Declared in TVirtualMCStack **/ - virtual Int_t GetNtrack() const { return fNParticles; } + Int_t GetNtrack() const override { return fNParticles; } /** Get number of primary tracks ** Declared in TVirtualMCStack **/ - virtual Int_t GetNprimary() const { return fNPrimaries; } + Int_t GetNprimary() const override { return fNPrimaries; } /** Get the current track's particle ** Declared in TVirtualMCStack **/ - virtual TParticle* GetCurrentTrack() const; + TParticle* GetCurrentTrack() const override; /** Get the track number of the parent of the current track ** Declared in TVirtualMCStack **/ - virtual Int_t GetCurrentParentTrackNumber() const; + Int_t GetCurrentParentTrackNumber() const override; /** Add a TParticle to the fParticles array **/ virtual void AddParticle(TParticle* part); /** Fill the MCTrack output array, applying filter criteria **/ - virtual void FillTrackArray(); + void FillTrackArray() override; /** Update the track index in the MCTracks and MCPoints **/ - virtual void UpdateTrackIndex(TRefArray* detArray = 0); + void UpdateTrackIndex(TRefArray* detArray = 0) override; /** Resets arrays and stack and deletes particles and tracks **/ - virtual void Reset(); + void Reset() override; /** Register the MCTrack array to the Root Manager **/ - virtual void Register(); + void Register() override; /** Output to screen **@param iVerbose: 0=events summary, 1=track info @@ -184,10 +184,10 @@ class MyProjStack : public FairGenericStack /** Accessors **/ TParticle* GetParticle(Int_t trackId) const; - TClonesArray* GetListOfParticles() { return fParticles; } + TClonesArray* GetListOfParticles() override { return fParticles; } /** Clone this object (used in MT mode only) */ - virtual FairGenericStack* CloneStack() const { return new MyProjStack(*this); } + FairGenericStack* CloneStack() const override { return new MyProjStack(*this); } private: /** STL stack (FILO) used to handle the TParticles for tracking **/ @@ -230,7 +230,7 @@ class MyProjStack : public FairGenericStack MyProjStack(const MyProjStack&); MyProjStack& operator=(const MyProjStack&); - ClassDef(MyProjStack, 1); + ClassDefOverride(MyProjStack, 1); }; #endif diff --git a/templates/project_stl_containers/MyProjData/MyProjStack.h b/templates/project_stl_containers/MyProjData/MyProjStack.h index 0430411a16..89e76e34d2 100644 --- a/templates/project_stl_containers/MyProjData/MyProjStack.h +++ b/templates/project_stl_containers/MyProjData/MyProjStack.h @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * Copyright (C) 2014-2024 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * * * * This software is distributed under the terms of the * * GNU Lesser General Public Licence (LGPL) version 3, * @@ -55,7 +55,7 @@ class MyProjStack : public FairGenericStack MyProjStack(Int_t size = 100); /** Destructor **/ - virtual ~MyProjStack(); + ~MyProjStack() override; /** Add a TParticle to the stack. ** Declared in TVirtualMCStack @@ -72,93 +72,93 @@ class MyProjStack : public FairGenericStack *@param weight Particle weight *@param is Generation status code (whatever that means) **/ - virtual void PushTrack(Int_t toBeDone, - Int_t parentID, - Int_t pdgCode, - Double_t px, - Double_t py, - Double_t pz, - Double_t e, - Double_t vx, - Double_t vy, - Double_t vz, - Double_t time, - Double_t polx, - Double_t poly, - Double_t polz, - TMCProcess proc, - Int_t& ntr, - Double_t weight, - Int_t is); - - virtual void PushTrack(Int_t toBeDone, - Int_t parentID, - Int_t pdgCode, - Double_t px, - Double_t py, - Double_t pz, - Double_t e, - Double_t vx, - Double_t vy, - Double_t vz, - Double_t time, - Double_t polx, - Double_t poly, - Double_t polz, - TMCProcess proc, - Int_t& ntr, - Double_t weight, - Int_t is, - Int_t secondParentId); + void PushTrack(Int_t toBeDone, + Int_t parentID, + Int_t pdgCode, + Double_t px, + Double_t py, + Double_t pz, + Double_t e, + Double_t vx, + Double_t vy, + Double_t vz, + Double_t time, + Double_t polx, + Double_t poly, + Double_t polz, + TMCProcess proc, + Int_t& ntr, + Double_t weight, + Int_t is) override; + + void PushTrack(Int_t toBeDone, + Int_t parentID, + Int_t pdgCode, + Double_t px, + Double_t py, + Double_t pz, + Double_t e, + Double_t vx, + Double_t vy, + Double_t vz, + Double_t time, + Double_t polx, + Double_t poly, + Double_t polz, + TMCProcess proc, + Int_t& ntr, + Double_t weight, + Int_t is, + Int_t secondParentId) override; /** Get next particle for tracking from the stack. ** Declared in TVirtualMCStack *@param iTrack index of popped track (return) *@return Pointer to the TParticle of the track **/ - virtual TParticle* PopNextTrack(Int_t& iTrack); + TParticle* PopNextTrack(Int_t& iTrack) override; /** Get primary particle by index for tracking from stack ** Declared in TVirtualMCStack *@param iPrim index of primary particle *@return Pointer to the TParticle of the track **/ - virtual TParticle* PopPrimaryForTracking(Int_t iPrim); + TParticle* PopPrimaryForTracking(Int_t iPrim) override; /** Get total number of tracks ** Declared in TVirtualMCStack **/ - virtual Int_t GetNtrack() const { return fNParticles; } + Int_t GetNtrack() const override { return fNParticles; } /** Get number of primary tracks ** Declared in TVirtualMCStack **/ - virtual Int_t GetNprimary() const { return fNPrimaries; } + Int_t GetNprimary() const override { return fNPrimaries; } /** Get the current track's particle ** Declared in TVirtualMCStack **/ - virtual TParticle* GetCurrentTrack() const; + TParticle* GetCurrentTrack() const override; /** Get the track number of the parent of the current track ** Declared in TVirtualMCStack **/ - virtual Int_t GetCurrentParentTrackNumber() const; + Int_t GetCurrentParentTrackNumber() const override; /** Add a TParticle to the fParticles array **/ virtual void AddParticle(TParticle* part); /** Fill the MCTrack output array, applying filter criteria **/ - virtual void FillTrackArray(); + void FillTrackArray() override; /** Update the track index in the MCTracks and MCPoints **/ - virtual void UpdateTrackIndex(TRefArray* detArray = 0); + void UpdateTrackIndex(TRefArray* detArray = 0) override; /** Resets arrays and stack and deletes particles and tracks **/ - virtual void Reset(); + void Reset() override; /** Register the MCTrack array to the Root Manager **/ - virtual void Register(); + void Register() override; /** Output to screen **@param iVerbose: 0=events summary, 1=track info @@ -184,10 +184,10 @@ class MyProjStack : public FairGenericStack /** Accessors **/ TParticle* GetParticle(Int_t trackId) const; - TClonesArray* GetListOfParticles() { return fParticles; } + TClonesArray* GetListOfParticles() override { return fParticles; } /** Clone this object (used in MT mode only) */ - virtual FairGenericStack* CloneStack() const { return new MyProjStack(*this); } + FairGenericStack* CloneStack() const override { return new MyProjStack(*this); } private: /** STL stack (FILO) used to handle the TParticles for tracking **/ @@ -230,7 +230,7 @@ class MyProjStack : public FairGenericStack MyProjStack(const MyProjStack&); MyProjStack& operator=(const MyProjStack&); - ClassDef(MyProjStack, 1); + ClassDefOverride(MyProjStack, 1); }; #endif From 5769b5af6587ba2928d8cbf6e03b32c74460c702 Mon Sep 17 00:00:00 2001 From: Christian Tacke <58549698+ChristianTackeGSI@users.noreply.github.com> Date: Mon, 30 Sep 2024 22:04:42 +0200 Subject: [PATCH 2/2] refactor(Stack): Use more GetParticle GetParticle is thin wrapper. Let's use it more. --- examples/common/mcstack/FairStack.cxx | 2 +- templates/project_root_containers/MyProjData/MyProjStack.cxx | 4 ++-- templates/project_stl_containers/MyProjData/MyProjStack.cxx | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/common/mcstack/FairStack.cxx b/examples/common/mcstack/FairStack.cxx index f964cca9d9..69d66289f9 100644 --- a/examples/common/mcstack/FairStack.cxx +++ b/examples/common/mcstack/FairStack.cxx @@ -167,7 +167,7 @@ TParticle* FairStack::PopPrimaryForTracking(Int_t iPrim) // Return the iPrim-th TParticle from the fParticle array. This should be // a primary. - TParticle* part = static_cast(fParticles->At(iPrim)); + TParticle* part = GetParticle(iPrim); if (!(part->GetMother(0) < 0)) { LOG(fatal) << "Not a primary track!" << iPrim; } diff --git a/templates/project_root_containers/MyProjData/MyProjStack.cxx b/templates/project_root_containers/MyProjData/MyProjStack.cxx index e5620198b9..f85d9e03b3 100644 --- a/templates/project_root_containers/MyProjData/MyProjStack.cxx +++ b/templates/project_root_containers/MyProjData/MyProjStack.cxx @@ -207,7 +207,7 @@ TParticle* MyProjStack::PopPrimaryForTracking(Int_t iPrim) // Return the iPrim-th TParticle from the fParticle array. This should be // a primary. - TParticle* part = (TParticle*)fParticles->At(iPrim); + TParticle* part = GetParticle(iPrim); if (!(part->GetMother(0) < 0)) { LOG(fatal) << "MyProjStack:: Not a primary track! " << iPrim; } @@ -425,7 +425,7 @@ TParticle* MyProjStack::GetParticle(Int_t trackID) const if (trackID < 0 || trackID >= fNParticles) { LOG(fatal) << "MyProjStack: Particle index " << trackID << " out of range."; } - return (TParticle*)fParticles->At(trackID); + return static_cast(fParticles->At(trackID)); } // ------------------------------------------------------------------------- diff --git a/templates/project_stl_containers/MyProjData/MyProjStack.cxx b/templates/project_stl_containers/MyProjData/MyProjStack.cxx index 3b6b16fa91..87bd685bd0 100644 --- a/templates/project_stl_containers/MyProjData/MyProjStack.cxx +++ b/templates/project_stl_containers/MyProjData/MyProjStack.cxx @@ -207,7 +207,7 @@ TParticle* MyProjStack::PopPrimaryForTracking(Int_t iPrim) // Return the iPrim-th TParticle from the fParticle array. This should be // a primary. - TParticle* part = (TParticle*)fParticles->At(iPrim); + TParticle* part = GetParticle(iPrim); if (!(part->GetMother(0) < 0)) { LOG(fatal) << "MyProjStack:: Not a primary track! " << iPrim; } @@ -430,7 +430,7 @@ TParticle* MyProjStack::GetParticle(Int_t trackID) const if (trackID < 0 || trackID >= fNParticles) { LOG(fatal) << "MyProjStack: Particle index " << trackID << " out of range."; } - return (TParticle*)fParticles->At(trackID); + return static_cast(fParticles->At(trackID)); } // -------------------------------------------------------------------------