Skip to content

Commit

Permalink
Merge pull request #36737 from civanch/fixed_static_analyzer_warn
Browse files Browse the repository at this point in the history
Fixed static analyzer warnings in SimG4Core/Notification and clean-up Alignment/LaserAlignmentSimulation
  • Loading branch information
cmsbuild authored Jan 24, 2022
2 parents f15f659 + a4ef2e9 commit 2d12409
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ void LaserOpticalPhysicsList::ConstructProcess() {
pManager->AddDiscreteProcess(theBoundaryProcess);
pManager->AddDiscreteProcess(theWLSProcess);

theScintProcess->SetScintillationYieldFactor(1.);
theScintProcess->SetTrackSecondariesFirst(true);

G4ParticleTable *table = G4ParticleTable::GetParticleTable();
Expand Down
7 changes: 4 additions & 3 deletions SimG4Core/Notification/src/GenParticleInfoExtractor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@

const GenParticleInfo &GenParticleInfoExtractor::operator()(const G4PrimaryParticle *p) const {
G4VUserPrimaryParticleInformation *up = p->GetUserInformation();
if (up == nullptr)
GenParticleInfo *gpi = dynamic_cast<GenParticleInfo *>(up);
if (up == nullptr) {
G4Exception("SimG4Core/Notification",
"mc001",
FatalException,
"GenParticleInfoExtractor: G4PrimaryParticle has no user information");
GenParticleInfo *gpi = dynamic_cast<GenParticleInfo *>(up);
if (gpi == nullptr)
} else if (gpi == nullptr) {
G4Exception("SimG4Core/Notification",
"mc001",
FatalException,
"GenParticleInfoExtractor: user information in G4PrimaryParticle is not of GenParticleInfo type");
}
return *gpi;
}
26 changes: 10 additions & 16 deletions SimG4Core/Notification/src/NewTrackAction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

#include "G4Track.hh"

//#define DebugLog

NewTrackAction::NewTrackAction() {}

void NewTrackAction::primary(const G4Track *aTrack) const { primary(const_cast<G4Track *>(aTrack)); }
Expand All @@ -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 {
Expand All @@ -44,13 +42,9 @@ 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) {
Expand Down
14 changes: 8 additions & 6 deletions SimG4Core/Notification/src/TrackInformationExtractor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,23 @@

const TrackInformation &TrackInformationExtractor::operator()(const G4Track &gtk) const {
G4VUserTrackInformation *gui = gtk.GetUserInformation();
if (gui == nullptr)
missing(gtk);
const TrackInformation *tkInfo = dynamic_cast<const TrackInformation *>(gui);
if (tkInfo == nullptr)
if (gui == nullptr) {
missing(gtk);
} else if (tkInfo == nullptr) {
wrongType();
}
return *tkInfo;
}

TrackInformation &TrackInformationExtractor::operator()(G4Track &gtk) const {
G4VUserTrackInformation *gui = gtk.GetUserInformation();
if (gui == nullptr)
missing(gtk);
TrackInformation *tkInfo = dynamic_cast<TrackInformation *>(gui);
if (tkInfo == nullptr)
if (gui == nullptr) {
missing(gtk);
} else if (tkInfo == nullptr) {
wrongType();
}
return *tkInfo;
}

Expand Down

0 comments on commit 2d12409

Please sign in to comment.