Skip to content

Commit

Permalink
[SIMULATION] [Clang]Cleanup clang-analyzer warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
smuzaffar committed Oct 3, 2024
1 parent 6f0c989 commit 3259c68
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 20 deletions.
6 changes: 2 additions & 4 deletions SimCalorimetry/EcalElectronicsEmulation/bin/GenABIO.cc
Original file line number Diff line number Diff line change
Expand Up @@ -552,10 +552,8 @@ bool readSRF(FILE *f,
++line;
char *pos = buffer;
while (*pos == ' ' || *pos == '\t')
++pos; // skip spaces
if (*pos != '#' && *pos != '\n') { // not a comment line nor an empty line
// go back to beginning of line:
pos = buffer;
++pos; // skip spaces
if (*pos != '#' && *pos != '\n') { // not a comment line nor an empty line
if (iReadLine < nSupercrystalXBins) { // EE- reading
if (read - 1 != nSupercrystalYBins) {
cerr << "Error: line " << line << " of file " << srfFilename << " has incorrect length"
Expand Down
10 changes: 4 additions & 6 deletions SimG4CMS/HcalTestBeam/src/HcalTB02HcalNumberingScheme.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,22 @@ HcalTB02HcalNumberingScheme::~HcalTB02HcalNumberingScheme() {
//

int HcalTB02HcalNumberingScheme::getUnitID(const G4Step* aStep) const {
int scintID = 0;

G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
const G4ThreeVector& hitPoint = preStepPoint->GetPosition();
float hx = hitPoint.x();
float hy = hitPoint.y();
float hz = hitPoint.z();
float hr = std::sqrt(pow(hx, 2) + pow(hy, 2));

// Check if hit happened in first HO layer or second.

if ((hr > 3. * m) && (hr < 3.830 * m))
return scintID = 17;
return 17;
if (hr > 3.830 * m)
return scintID = 18;
return 18;

// Compute the scintID in the HB.

int scintID = 0;
float hz = hitPoint.z();
float hR = hitPoint.mag(); //sqrt( pow(hx,2)+pow(hy,2)+pow(hz,2) );
float htheta = (hR == 0. ? 0. : acos(std::max(std::min(hz / hR, float(1.)), float(-1.))));
float hsintheta = sin(htheta);
Expand Down
2 changes: 1 addition & 1 deletion SimG4Core/CustomPhysics/src/CMSSQNeutronAnnih.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ G4double CMSSQNeutronAnnih::momDistr(G4double x_in) {

//now interpolate the above points for x_in
G4double result = 9999;
for (int i = 0; i < n_entries; i++) {
for (int i = 1; i < n_entries; i++) {
if (x[i] > x_in) {
result = (CDF_k[i] - CDF_k[i - 1]) / (x[i] - x[i - 1]) * (x_in - x[i - 1]) + CDF_k[i - 1];
break;
Expand Down
2 changes: 2 additions & 0 deletions SimG4Core/Geometry/src/CMSG4CheckOverlap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ void CMSG4CheckOverlap::makeReportForOverlaps(std::ofstream& fout,
if (!reg) {
fout << "### NO G4Region found - EXIT"
<< "\n";
if (gdml)
delete gdml;
return;
}
std::vector<G4LogicalVolume*>::iterator rootLVItr = reg->GetRootLogicalVolumeIterator();
Expand Down
3 changes: 2 additions & 1 deletion SimG4Core/Notification/src/GenParticleInfoExtractor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ const GenParticleInfo &GenParticleInfoExtractor::operator()(const G4PrimaryParti
FatalException,
"GenParticleInfoExtractor: user information in G4PrimaryParticle is not of GenParticleInfo type");
}
return *gpi;
// Silence Clang analyzer warning: G4Exception will be thrown if gpi is null
[[clang::suppress]] return *gpi;
}
6 changes: 4 additions & 2 deletions SimG4Core/Notification/src/TrackInformationExtractor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const TrackInformation &TrackInformationExtractor::operator()(const G4Track &gtk
} else if (tkInfo == nullptr) {
wrongType();
}
return *tkInfo;
// Silence Clang analyzer warning: G4Exception will be thrown if tkInfo is null
[[clang::suppress]] return *tkInfo;
}

TrackInformation &TrackInformationExtractor::operator()(G4Track &gtk) const {
Expand All @@ -21,7 +22,8 @@ TrackInformation &TrackInformationExtractor::operator()(G4Track &gtk) const {
} else if (tkInfo == nullptr) {
wrongType();
}
return *tkInfo;
// Silence Clang analyzer warning: G4Exception will be thrown if tkInfo is null
[[clang::suppress]] return *tkInfo;
}

void TrackInformationExtractor::missing(const G4Track &) const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ void CMSEmStandardPhysicsTrackingManager::TrackElectron(G4Track *aTrack) {
particleChange = electron.ioni->PostStepDoIt(track, step);
break;
}

assert(particleChange);
particleChange->UpdateStepForPostStep(&step);
step.UpdateTrack();

Expand Down Expand Up @@ -588,7 +588,7 @@ void CMSEmStandardPhysicsTrackingManager::TrackPositron(G4Track *aTrack) {
particleChange = positron.ioni->PostStepDoIt(track, step);
break;
}

assert(particleChange);
particleChange->UpdateStepForPostStep(&step);
step.UpdateTrack();

Expand Down
2 changes: 1 addition & 1 deletion SimG4Core/PrintGeomInfo/plugins/PrintMaterialBudgetInfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ PrintMaterialBudgetInfo::PrintMaterialBudgetInfo(const edm::ParameterSet& p) {
PrintMaterialBudgetInfo::~PrintMaterialBudgetInfo() {}

void PrintMaterialBudgetInfo::update(const BeginOfRun* run) {
G4Random::setTheEngine(new CLHEP::RanecuEngine);
[[clang::suppress]] G4Random::setTheEngine(new CLHEP::RanecuEngine);
// Physical Volume
G4VPhysicalVolume* theTopPV =
G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume();
Expand Down
4 changes: 1 addition & 3 deletions SimGeneral/PileupInformation/plugins/GenPUProtonProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,6 @@ void GenPUProtonProducer::produce(StreamID, Event& evt, const EventSetup& es) co
if (find(bunchList_.begin(), bunchList_.end(), bunch) != bunchList_.end()) {
auto event = (*mixHepMC_itr).GetEvent();

size_t num_particles = event->particles_size();

// Fill output collection
unsigned int number_of_protons = 0;
for (auto p = event->particles_begin(); p != event->particles_end(); ++p) {
Expand All @@ -237,7 +235,7 @@ void GenPUProtonProducer::produce(StreamID, Event& evt, const EventSetup& es) co
}
}
LogDebug("GenPUProtonProducer") << "Idx : " << idx_mix << " Bunch : " << bunch
<< " Number of particles : " << num_particles
<< " Number of particles : " << event->particles_size()
<< " Number of protons : " << number_of_protons << endl;

total_number_of_protons += number_of_protons;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ void TMultiDimFet::MakeCandidates() {

// The temporary array to store the powers in. We don't need to
// initialize this array however.
assert(fNVariables > 0);
Int_t *powers = new Int_t[fNVariables * fMaxFunctions];

// store of `control variables'
Expand Down

0 comments on commit 3259c68

Please sign in to comment.