From f269978aebdc641e1893b4a0031c5ae5fd37ab00 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Tue, 18 Jan 2022 18:22:48 +0100 Subject: [PATCH 1/3] Fixed static analyzer warnings --- .../src/LaserOpticalPhysicsList.cc | 1 - .../src/GenParticleInfoExtractor.cc | 17 ++++++----- SimG4Core/Notification/src/NewTrackAction.cc | 28 ++++++++----------- .../src/TrackInformationExtractor.cc | 20 +++++++------ 4 files changed, 34 insertions(+), 32 deletions(-) diff --git a/Alignment/LaserAlignmentSimulation/src/LaserOpticalPhysicsList.cc b/Alignment/LaserAlignmentSimulation/src/LaserOpticalPhysicsList.cc index d84a8ba8f0609..4ad7ded0e18a4 100644 --- a/Alignment/LaserAlignmentSimulation/src/LaserOpticalPhysicsList.cc +++ b/Alignment/LaserAlignmentSimulation/src/LaserOpticalPhysicsList.cc @@ -93,7 +93,6 @@ void LaserOpticalPhysicsList::ConstructProcess() { pManager->AddDiscreteProcess(theBoundaryProcess); pManager->AddDiscreteProcess(theWLSProcess); - theScintProcess->SetScintillationYieldFactor(1.); theScintProcess->SetTrackSecondariesFirst(true); G4ParticleTable *table = G4ParticleTable::GetParticleTable(); diff --git a/SimG4Core/Notification/src/GenParticleInfoExtractor.cc b/SimG4Core/Notification/src/GenParticleInfoExtractor.cc index fee005bfd4bab..4cc020dfd6a9f 100644 --- a/SimG4Core/Notification/src/GenParticleInfoExtractor.cc +++ b/SimG4Core/Notification/src/GenParticleInfoExtractor.cc @@ -3,16 +3,19 @@ const GenParticleInfo &GenParticleInfoExtractor::operator()(const G4PrimaryParticle *p) const { G4VUserPrimaryParticleInformation *up = p->GetUserInformation(); - if (up == nullptr) - G4Exception("SimG4Core/Notification", - "mc001", - FatalException, - "GenParticleInfoExtractor: G4PrimaryParticle has no user information"); GenParticleInfo *gpi = dynamic_cast(up); - if (gpi == nullptr) + if (up == nullptr) { G4Exception("SimG4Core/Notification", "mc001", FatalException, - "GenParticleInfoExtractor: user information in G4PrimaryParticle is not of GenParticleInfo type"); + "GenParticleInfoExtractor: G4PrimaryParticle has no user information"); + } else { + GenParticleInfo *gpi = dynamic_cast(up); + if (gpi == nullptr) + G4Exception("SimG4Core/Notification", + "mc001", + FatalException, + "GenParticleInfoExtractor: user information in G4PrimaryParticle is not of GenParticleInfo type"); + } return *gpi; } diff --git a/SimG4Core/Notification/src/NewTrackAction.cc b/SimG4Core/Notification/src/NewTrackAction.cc index 7cf90f9de1251..dd295aebb35bc 100644 --- a/SimG4Core/Notification/src/NewTrackAction.cc +++ b/SimG4Core/Notification/src/NewTrackAction.cc @@ -6,8 +6,6 @@ #include "G4Track.hh" -//#define DebugLog - NewTrackAction::NewTrackAction() {} void NewTrackAction::primary(const G4Track *aTrack) const { primary(const_cast(aTrack)); } @@ -19,18 +17,18 @@ void NewTrackAction::secondary(const G4Track *aSecondary, const G4Track &mother, } void NewTrackAction::secondary(G4Track *aSecondary, const G4Track &mother, int flag) const { - if (aSecondary->GetParentID() != mother.GetTrackID()) + if (aSecondary->GetParentID() != mother.GetTrackID()) { G4Exception("SimG4Core/Notification", "mc001", FatalException, "NewTrackAction: secondary parent ID does not match mother id"); - TrackInformationExtractor extractor; - const TrackInformation &motherInfo(extractor(mother)); - addUserInfoToSecondary(aSecondary, motherInfo, flag); -#ifdef DebugLog - LogDebug("SimTrackManager") << "NewTrackAction: Add track " << aSecondary->GetTrackID() << " from mother " - << mother.GetTrackID(); -#endif + } else { + TrackInformationExtractor extractor; + const TrackInformation &motherInfo(extractor(mother)); + addUserInfoToSecondary(aSecondary, motherInfo, flag); + LogDebug("SimTrackManager") << "NewTrackAction: Add track " << aSecondary->GetTrackID() << " from mother " + << mother.GetTrackID(); + } } void NewTrackAction::addUserInfoToPrimary(G4Track *aTrack) const { @@ -44,13 +42,11 @@ void NewTrackAction::addUserInfoToPrimary(G4Track *aTrack) const { } void NewTrackAction::addUserInfoToSecondary(G4Track *aTrack, const TrackInformation &motherInfo, int flag) const { - // ralf.ulrich@kit.edu: it is more efficient to use the constructor to copy all data and modify later only when needed - TrackInformation *trkInfo = new TrackInformation(); - // LogDebug("SimG4CoreApplication") << "NewTrackAction called for " - // << aTrack->GetTrackID() - // << " mother " << motherInfo.isPrimary() - // << " flag " << flag; + LogDebug("SimG4CoreApplication") << "NewTrackAction called for " + << aTrack->GetTrackID() + << " mother " << motherInfo.isPrimary() + << " flag " << flag; // Take care of cascade decays if (flag == 1) { diff --git a/SimG4Core/Notification/src/TrackInformationExtractor.cc b/SimG4Core/Notification/src/TrackInformationExtractor.cc index 894399666ff88..db47c19a2efc2 100644 --- a/SimG4Core/Notification/src/TrackInformationExtractor.cc +++ b/SimG4Core/Notification/src/TrackInformationExtractor.cc @@ -4,21 +4,25 @@ const TrackInformation &TrackInformationExtractor::operator()(const G4Track >k) const { G4VUserTrackInformation *gui = gtk.GetUserInformation(); - if (gui == nullptr) - missing(gtk); const TrackInformation *tkInfo = dynamic_cast(gui); - if (tkInfo == nullptr) - wrongType(); + if (gui == nullptr) { + missing(gtk); + } else { + if (tkInfo == nullptr) + wrongType(); + } return *tkInfo; } TrackInformation &TrackInformationExtractor::operator()(G4Track >k) const { G4VUserTrackInformation *gui = gtk.GetUserInformation(); - if (gui == nullptr) - missing(gtk); TrackInformation *tkInfo = dynamic_cast(gui); - if (tkInfo == nullptr) - wrongType(); + if (gui == nullptr) { + missing(gtk); + } else { + if (tkInfo == nullptr) + wrongType(); + } return *tkInfo; } From f4937385b766d7d65039c513f3f1295b022f877e Mon Sep 17 00:00:00 2001 From: Vladimir Date: Tue, 18 Jan 2022 18:35:21 +0100 Subject: [PATCH 2/3] code format --- SimG4Core/Notification/src/GenParticleInfoExtractor.cc | 6 +++--- SimG4Core/Notification/src/NewTrackAction.cc | 6 ++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/SimG4Core/Notification/src/GenParticleInfoExtractor.cc b/SimG4Core/Notification/src/GenParticleInfoExtractor.cc index 4cc020dfd6a9f..4a562dc58db24 100644 --- a/SimG4Core/Notification/src/GenParticleInfoExtractor.cc +++ b/SimG4Core/Notification/src/GenParticleInfoExtractor.cc @@ -13,9 +13,9 @@ const GenParticleInfo &GenParticleInfoExtractor::operator()(const G4PrimaryParti GenParticleInfo *gpi = dynamic_cast(up); if (gpi == nullptr) G4Exception("SimG4Core/Notification", - "mc001", - FatalException, - "GenParticleInfoExtractor: user information in G4PrimaryParticle is not of GenParticleInfo type"); + "mc001", + FatalException, + "GenParticleInfoExtractor: user information in G4PrimaryParticle is not of GenParticleInfo type"); } return *gpi; } diff --git a/SimG4Core/Notification/src/NewTrackAction.cc b/SimG4Core/Notification/src/NewTrackAction.cc index dd295aebb35bc..e6ed0dc397dcd 100644 --- a/SimG4Core/Notification/src/NewTrackAction.cc +++ b/SimG4Core/Notification/src/NewTrackAction.cc @@ -43,10 +43,8 @@ void NewTrackAction::addUserInfoToPrimary(G4Track *aTrack) const { void NewTrackAction::addUserInfoToSecondary(G4Track *aTrack, const TrackInformation &motherInfo, int flag) const { TrackInformation *trkInfo = new TrackInformation(); - LogDebug("SimG4CoreApplication") << "NewTrackAction called for " - << aTrack->GetTrackID() - << " mother " << motherInfo.isPrimary() - << " flag " << flag; + LogDebug("SimG4CoreApplication") << "NewTrackAction called for " << aTrack->GetTrackID() << " mother " + << motherInfo.isPrimary() << " flag " << flag; // Take care of cascade decays if (flag == 1) { From a4ef2e98d1a7ef784b2605a15bac1731626c06a1 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Fri, 21 Jan 2022 10:19:53 +0100 Subject: [PATCH 3/3] more clean code --- .../Notification/src/GenParticleInfoExtractor.cc | 12 +++++------- .../Notification/src/TrackInformationExtractor.cc | 10 ++++------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/SimG4Core/Notification/src/GenParticleInfoExtractor.cc b/SimG4Core/Notification/src/GenParticleInfoExtractor.cc index 4a562dc58db24..0546198f3f35c 100644 --- a/SimG4Core/Notification/src/GenParticleInfoExtractor.cc +++ b/SimG4Core/Notification/src/GenParticleInfoExtractor.cc @@ -9,13 +9,11 @@ const GenParticleInfo &GenParticleInfoExtractor::operator()(const G4PrimaryParti "mc001", FatalException, "GenParticleInfoExtractor: G4PrimaryParticle has no user information"); - } else { - GenParticleInfo *gpi = dynamic_cast(up); - if (gpi == nullptr) - G4Exception("SimG4Core/Notification", - "mc001", - FatalException, - "GenParticleInfoExtractor: user information in G4PrimaryParticle is not of GenParticleInfo type"); + } else if (gpi == nullptr) { + G4Exception("SimG4Core/Notification", + "mc001", + FatalException, + "GenParticleInfoExtractor: user information in G4PrimaryParticle is not of GenParticleInfo type"); } return *gpi; } diff --git a/SimG4Core/Notification/src/TrackInformationExtractor.cc b/SimG4Core/Notification/src/TrackInformationExtractor.cc index db47c19a2efc2..b19e024bdc644 100644 --- a/SimG4Core/Notification/src/TrackInformationExtractor.cc +++ b/SimG4Core/Notification/src/TrackInformationExtractor.cc @@ -7,9 +7,8 @@ const TrackInformation &TrackInformationExtractor::operator()(const G4Track >k const TrackInformation *tkInfo = dynamic_cast(gui); if (gui == nullptr) { missing(gtk); - } else { - if (tkInfo == nullptr) - wrongType(); + } else if (tkInfo == nullptr) { + wrongType(); } return *tkInfo; } @@ -19,9 +18,8 @@ TrackInformation &TrackInformationExtractor::operator()(G4Track >k) const { TrackInformation *tkInfo = dynamic_cast(gui); if (gui == nullptr) { missing(gtk); - } else { - if (tkInfo == nullptr) - wrongType(); + } else if (tkInfo == nullptr) { + wrongType(); } return *tkInfo; }