Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed static analyzer warnings in SimG4Core/Notification and clean-up Alignment/LaserAlignmentSimulation #36737

Merged
merged 3 commits into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.);
civanch marked this conversation as resolved.
Show resolved Hide resolved
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;
civanch marked this conversation as resolved.
Show resolved Hide resolved
}
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 {
// [email protected]: 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