From 3259c68c1c827d016e26b593e1f221c17b7c05a7 Mon Sep 17 00:00:00 2001 From: Shahzad Malik Muzaffar Date: Thu, 3 Oct 2024 17:50:03 +0200 Subject: [PATCH] [SIMULATION] [Clang]Cleanup clang-analyzer warnings --- SimCalorimetry/EcalElectronicsEmulation/bin/GenABIO.cc | 6 ++---- .../HcalTestBeam/src/HcalTB02HcalNumberingScheme.cc | 10 ++++------ SimG4Core/CustomPhysics/src/CMSSQNeutronAnnih.cc | 2 +- SimG4Core/Geometry/src/CMSG4CheckOverlap.cc | 2 ++ SimG4Core/Notification/src/GenParticleInfoExtractor.cc | 3 ++- .../Notification/src/TrackInformationExtractor.cc | 6 ++++-- .../src/CMSEmStandardPhysicsTrackingManager.cc | 4 ++-- .../PrintGeomInfo/plugins/PrintMaterialBudgetInfo.cc | 2 +- .../PileupInformation/plugins/GenPUProtonProducer.cc | 4 +--- .../src/TMultiDimFet.cc | 1 + 10 files changed, 20 insertions(+), 20 deletions(-) diff --git a/SimCalorimetry/EcalElectronicsEmulation/bin/GenABIO.cc b/SimCalorimetry/EcalElectronicsEmulation/bin/GenABIO.cc index 8faa324f1fcfb..d0161e105387a 100644 --- a/SimCalorimetry/EcalElectronicsEmulation/bin/GenABIO.cc +++ b/SimCalorimetry/EcalElectronicsEmulation/bin/GenABIO.cc @@ -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" diff --git a/SimG4CMS/HcalTestBeam/src/HcalTB02HcalNumberingScheme.cc b/SimG4CMS/HcalTestBeam/src/HcalTB02HcalNumberingScheme.cc index fff44a51c3d9c..de703022f7012 100644 --- a/SimG4CMS/HcalTestBeam/src/HcalTB02HcalNumberingScheme.cc +++ b/SimG4CMS/HcalTestBeam/src/HcalTB02HcalNumberingScheme.cc @@ -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); diff --git a/SimG4Core/CustomPhysics/src/CMSSQNeutronAnnih.cc b/SimG4Core/CustomPhysics/src/CMSSQNeutronAnnih.cc index 3a95b79e19c1d..880ee82ed3b3b 100644 --- a/SimG4Core/CustomPhysics/src/CMSSQNeutronAnnih.cc +++ b/SimG4Core/CustomPhysics/src/CMSSQNeutronAnnih.cc @@ -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; diff --git a/SimG4Core/Geometry/src/CMSG4CheckOverlap.cc b/SimG4Core/Geometry/src/CMSG4CheckOverlap.cc index e8ee9dc99950f..68a2a9112ce4c 100644 --- a/SimG4Core/Geometry/src/CMSG4CheckOverlap.cc +++ b/SimG4Core/Geometry/src/CMSG4CheckOverlap.cc @@ -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::iterator rootLVItr = reg->GetRootLogicalVolumeIterator(); diff --git a/SimG4Core/Notification/src/GenParticleInfoExtractor.cc b/SimG4Core/Notification/src/GenParticleInfoExtractor.cc index 0546198f3f35c..a5f401853889b 100644 --- a/SimG4Core/Notification/src/GenParticleInfoExtractor.cc +++ b/SimG4Core/Notification/src/GenParticleInfoExtractor.cc @@ -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; } diff --git a/SimG4Core/Notification/src/TrackInformationExtractor.cc b/SimG4Core/Notification/src/TrackInformationExtractor.cc index b19e024bdc644..e6b0cc8120374 100644 --- a/SimG4Core/Notification/src/TrackInformationExtractor.cc +++ b/SimG4Core/Notification/src/TrackInformationExtractor.cc @@ -10,7 +10,8 @@ const TrackInformation &TrackInformationExtractor::operator()(const G4Track >k } 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 >k) const { @@ -21,7 +22,8 @@ TrackInformation &TrackInformationExtractor::operator()(G4Track >k) 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 { diff --git a/SimG4Core/PhysicsLists/src/CMSEmStandardPhysicsTrackingManager.cc b/SimG4Core/PhysicsLists/src/CMSEmStandardPhysicsTrackingManager.cc index 1f6673be0cde7..d2c0a4df58713 100644 --- a/SimG4Core/PhysicsLists/src/CMSEmStandardPhysicsTrackingManager.cc +++ b/SimG4Core/PhysicsLists/src/CMSEmStandardPhysicsTrackingManager.cc @@ -418,7 +418,7 @@ void CMSEmStandardPhysicsTrackingManager::TrackElectron(G4Track *aTrack) { particleChange = electron.ioni->PostStepDoIt(track, step); break; } - + assert(particleChange); particleChange->UpdateStepForPostStep(&step); step.UpdateTrack(); @@ -588,7 +588,7 @@ void CMSEmStandardPhysicsTrackingManager::TrackPositron(G4Track *aTrack) { particleChange = positron.ioni->PostStepDoIt(track, step); break; } - + assert(particleChange); particleChange->UpdateStepForPostStep(&step); step.UpdateTrack(); diff --git a/SimG4Core/PrintGeomInfo/plugins/PrintMaterialBudgetInfo.cc b/SimG4Core/PrintGeomInfo/plugins/PrintMaterialBudgetInfo.cc index f3ade17144fe3..b116b1e48c1a4 100644 --- a/SimG4Core/PrintGeomInfo/plugins/PrintMaterialBudgetInfo.cc +++ b/SimG4Core/PrintGeomInfo/plugins/PrintMaterialBudgetInfo.cc @@ -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(); diff --git a/SimGeneral/PileupInformation/plugins/GenPUProtonProducer.cc b/SimGeneral/PileupInformation/plugins/GenPUProtonProducer.cc index 0196bd2bc65ce..0b76b273d6a21 100644 --- a/SimGeneral/PileupInformation/plugins/GenPUProtonProducer.cc +++ b/SimGeneral/PileupInformation/plugins/GenPUProtonProducer.cc @@ -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) { @@ -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; diff --git a/SimTransport/TotemRPProtonTransportParametrization/src/TMultiDimFet.cc b/SimTransport/TotemRPProtonTransportParametrization/src/TMultiDimFet.cc index 146655d61292b..256ecc97b2aa0 100644 --- a/SimTransport/TotemRPProtonTransportParametrization/src/TMultiDimFet.cc +++ b/SimTransport/TotemRPProtonTransportParametrization/src/TMultiDimFet.cc @@ -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'