From cea7bc283c0fba54228ac4bebc173ad405e8c19c Mon Sep 17 00:00:00 2001 From: Julian Wollrath Date: Wed, 12 Aug 2026 16:30:13 +0200 Subject: [PATCH] Use nullptr (C++) instead of NULL (C) --- include/F04GlobalField.hh | 2 +- src/F04ElementField.cc | 2 +- src/musrDetectorMessenger.cc | 2 +- src/musrErrorMessage.cc | 2 +- src/musrMuonium.cc | 2 +- src/musrParameters.cc | 4 ++-- src/musrPhysicsList.cc | 9 +++++---- src/musrPrimaryGeneratorAction.cc | 8 ++++---- src/musrRunAction.cc | 2 +- src/musrScintSD.cc | 8 ++++---- src/musrSteppingAction.cc | 12 ++++++------ src/musrSteppingVerbose.cc | 2 +- 12 files changed, 28 insertions(+), 27 deletions(-) diff --git a/include/F04GlobalField.hh b/include/F04GlobalField.hh index bca5a3e..d4e4d27 100644 --- a/include/F04GlobalField.hh +++ b/include/F04GlobalField.hh @@ -88,7 +88,7 @@ public: static F04GlobalField* getObject(); // - static G4bool Exists() {if (object==NULL) {return false;} else {return true;}; } + static G4bool Exists() {if (object==nullptr) {return false;} else {return true;}; } /// GetFieldValue() returns the field value at a given point[]. /// field is really field[6]: Bx,By,Bz,Ex,Ey,Ez. diff --git a/src/F04ElementField.cc b/src/F04ElementField.cc index c8efed9..6a70aa2 100644 --- a/src/F04ElementField.cc +++ b/src/F04ElementField.cc @@ -150,7 +150,7 @@ void F04ElementField::construct() G4VisAttributes *F04ElementField::getVisAttribute(G4String color) { - G4VisAttributes *p = NULL; + G4VisAttributes *p = nullptr; if (color.size() > 0 && (isdigit(color.c_str()[0]) || color.c_str()[0] == '.')) { G4double red = 0.0, green = 0.0, blue = 0.0; if (sscanf(color.c_str(), "%lf,%lf,%lf", &red, &green, &blue) == 3) { diff --git a/src/musrDetectorMessenger.cc b/src/musrDetectorMessenger.cc index c14a629..34135b2 100644 --- a/src/musrDetectorMessenger.cc +++ b/src/musrDetectorMessenger.cc @@ -120,7 +120,7 @@ void musrDetectorMessenger::SetNewValue(G4UIcommand *command, G4String newValue) G4cout << "*** Random Seed set by the system time ***" << G4endl; G4cout << "******************************************" << G4endl; long seeds[2]; - time_t systime = time(NULL); + time_t systime = time(nullptr); seeds[0] = (long)systime; seeds[1] = (long)(systime * G4UniformRand()); G4cout << "seed1: " << seeds[0] << "; seed2: " << seeds[1] << G4endl; diff --git a/src/musrErrorMessage.cc b/src/musrErrorMessage.cc index 60286be..fa3f0a0 100644 --- a/src/musrErrorMessage.cc +++ b/src/musrErrorMessage.cc @@ -34,7 +34,7 @@ musrErrorMessage::musrErrorMessage():nErrors(1) musrErrorMessage::~musrErrorMessage() {} -musrErrorMessage* musrErrorMessage::pointerToErrors=NULL; +musrErrorMessage* musrErrorMessage::pointerToErrors=nullptr; musrErrorMessage* musrErrorMessage::GetInstance() { return pointerToErrors; } diff --git a/src/musrMuonium.cc b/src/musrMuonium.cc index 6ff0f5d..9ea2e37 100644 --- a/src/musrMuonium.cc +++ b/src/musrMuonium.cc @@ -55,7 +55,7 @@ musrMuonium* musrMuonium::Definition() 1, 0, 0, 0, 0, 0, "lepton", -1, 0, -1313, - false, 2197.03*CLHEP::ns, NULL, + false, 2197.03*CLHEP::ns, nullptr, false, "mu" ); // Bohr magnetron of Muonium - T. Shiroka diff --git a/src/musrParameters.cc b/src/musrParameters.cc index d5d964c..9b82514 100644 --- a/src/musrParameters.cc +++ b/src/musrParameters.cc @@ -45,7 +45,7 @@ musrParameters::musrParameters(G4String steeringFileName) // (and therefore the parameters can not be read in in the musrDetectorConstruction.cc class). FILE *fSteeringFile=fopen(steeringFileName.c_str(),"r"); - if (fSteeringFile==NULL) { + if (fSteeringFile==nullptr) { G4cout<<"musrParameters::musrParameters: steeringFileName=\""< //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... @@ -288,7 +289,7 @@ void musrPhysicsList::ConstructEM() // cks 2008.08.22. - Adding the possibility to define the processes from the steering file: char charSteeringFileName[1000]; strcpy(charSteeringFileName,(musrParameters::mySteeringFileName).c_str()); FILE *fSteeringFile=fopen(charSteeringFileName,"r"); - if (fSteeringFile==NULL) { + if (fSteeringFile==nullptr) { sprintf(eMessage,"musrPhysicsList::ConstructEM(): Failed to open macro file \"%s\" .",charSteeringFileName); musrErrorMessage::GetInstance()->musrError(FATAL,eMessage,false); } @@ -312,7 +313,7 @@ void musrPhysicsList::ConstructEM() G4String stringParticleName = charParticleName; G4ParticleDefinition* particleDefinition = G4ParticleTable::GetParticleTable() -> FindParticle(stringParticleName); // G4cout<<"particleDefinition of "<musrError(INFO, "musrPhysicsList: Ignoring optical photon process definition because G4OpticalPhotons in *.mac file is set to false",false); @@ -447,7 +448,7 @@ void musrPhysicsList::ConstructEM() sscanf(&line[0],"%*s %*s %*s %*s %*s %s %d",charModelName,&modelPriority); G4String stringModelName = charModelName; G4cout<<" Adding model "<musrError(FATAL,eMessage,false); @@ -640,7 +641,7 @@ void musrPhysicsList::ReportProblemWithProcessDefinition(char myString[501]) { G4Region* musrPhysicsList::FindG4Region(G4String regionName, char* lineOfSteeringFile) { G4Region* myRegion = G4RegionStore::GetInstance()->GetRegion(regionName,false); - if( myRegion != NULL ) { // G4Region found + if( myRegion != nullptr ) { // G4Region found return myRegion; } else { // G4Region not found diff --git a/src/musrPrimaryGeneratorAction.cc b/src/musrPrimaryGeneratorAction.cc index eb358cd..a515d67 100644 --- a/src/musrPrimaryGeneratorAction.cc +++ b/src/musrPrimaryGeneratorAction.cc @@ -48,7 +48,7 @@ G4bool musrPrimaryGeneratorAction::setRandomNrSeedFromFile_RNDM=0; G4int musrPrimaryGeneratorAction::nRndmEventToSaveSeeds=-2; G4int musrPrimaryGeneratorAction::lastEventID_in_pointerToSeedVector=0; -std::vector * musrPrimaryGeneratorAction::pointerToSeedVector=NULL; +std::vector * musrPrimaryGeneratorAction::pointerToSeedVector=nullptr; std::vector * musrPrimaryGeneratorAction::GetPointerToSeedVector() { return pointerToSeedVector; } @@ -451,7 +451,7 @@ void musrPrimaryGeneratorAction::SetMuonDecayTimeLimits(G4ThreeVector decayTimeL void musrPrimaryGeneratorAction::SetTurtleInput(G4String turtleFileName) { takeMuonsFromTurtleFile = true; fTurtleFile = fopen(turtleFileName.c_str(),"r"); - if (fTurtleFile==NULL) { + if (fTurtleFile==nullptr) { G4cout << "E R R O R : Failed to open TURTLE input file \"" << turtleFileName <<"\"."<< G4endl; G4cout << "S T O P F O R C E D" << G4endl; @@ -462,7 +462,7 @@ void musrPrimaryGeneratorAction::SetTurtleInput(G4String turtleFileName) { //=============================================================================== void musrPrimaryGeneratorAction::SetTurtleInputFileToEventNo(G4int lineNumberOfTurtleFile) { - if (fTurtleFile==NULL) { + if (fTurtleFile==nullptr) { G4cout << "musrPrimaryGeneratorAction::SetTurtleInputFileToEventNo:" <<" TURTLE input file not found - line number can not be set."<FindParticle(particleName); - if (particule!=NULL) { + if (particule!=nullptr) { G4cout<<" musrPrimaryGeneratorAction::SetPrimaryParticleMuMinus(): USING " <SetParticleDefinition(particule); diff --git a/src/musrRunAction.cc b/src/musrRunAction.cc index 6b06ee1..45f684d 100644 --- a/src/musrRunAction.cc +++ b/src/musrRunAction.cc @@ -99,7 +99,7 @@ void musrRunAction::EndOfRunAction(const G4Run* aRun) { if (F04GlobalField::Exists()) { F04GlobalField* myGlobalField = F04GlobalField::getObject(); //Was causing seg. fault when called here - if (myGlobalField!=NULL) {delete myGlobalField;} + if (myGlobalField!=nullptr) {delete myGlobalField;} } musrErrorMessage::GetInstance()->PrintErrorSummary(); diff --git a/src/musrScintSD.cc b/src/musrScintSD.cc index 3d726fd..e596152 100644 --- a/src/musrScintSD.cc +++ b/src/musrScintSD.cc @@ -139,7 +139,7 @@ musrScintSD::musrScintSD(G4String name) musrScintSD::~musrScintSD(){ } -musrScintSD* musrScintSD::pointer=NULL; +musrScintSD* musrScintSD::pointer=nullptr; musrScintSD* musrScintSD::GetInstance() {return pointer;} //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... @@ -260,7 +260,7 @@ void musrScintSD::ProcessOpticalPhoton(G4Step* aStep) { // } G4OpBoundaryProcessStatus boundaryStatus=Undefined; - static G4OpBoundaryProcess* boundaryProc=NULL; + static G4OpBoundaryProcess* boundaryProc=nullptr; //find the boundary process only once if(!boundaryProc){ G4ProcessManager* pm = aStep->GetTrack()->GetDefinition()->GetProcessManager(); @@ -644,7 +644,7 @@ void musrScintSD::EndOfEvent_OptiacalPhotons() { G4double OPSA_CFD_ampl = -1000; G4int iHistNr = -1; G4int iHistNrSUM = -1; - // TF1* poiss = NULL; + // TF1* poiss = nullptr; for (optHitDetectorMapType::const_iterator it2 = optHitDetectorMap->begin(); it2 != optHitDetectorMap->end(); it2++ ) { //delete G4cout<<"KAMIL: Nr of optHitDetectorMap->size()="<size()<musrError(FATAL,"musrScintSD: pulse shape data file not found !",false); } diff --git a/src/musrSteppingAction.cc b/src/musrSteppingAction.cc index f63e9a0..ab5b805 100644 --- a/src/musrSteppingAction.cc +++ b/src/musrSteppingAction.cc @@ -53,7 +53,7 @@ musrSteppingAction::musrSteppingAction() { boolMuonEventReweighting = false; boolCalculateFieldIntegral = false; myRootOutput = musrRootOutput::GetRootInstance(); - if (myRootOutput == NULL) { + if (myRootOutput == nullptr) { musrErrorMessage::GetInstance()->musrError(FATAL, "musrSteppingAction::musrSteppingAction(): pointer to the musrRootOutput class not found! ==> EXECUTION STOPPED",true); } @@ -184,8 +184,8 @@ void musrSteppingAction::UserSteppingAction(const G4Step* aStep) { // Save info about the old tracks, if the user wishes to have Vvv info in the output Root Tree. if (boolIsVvvInfoRequested) { G4VPhysicalVolume* nextVolume = aTrack->GetNextVolume(); - if (nextVolume!=NULL) { - if ((nextVolume->GetLogicalVolume()->GetSensitiveDetector()!=NULL)||(actualLogicalVolume->GetSensitiveDetector()!=NULL)) { + if (nextVolume!=nullptr) { + if ((nextVolume->GetLogicalVolume()->GetSensitiveDetector()!=nullptr)||(actualLogicalVolume->GetSensitiveDetector()!=nullptr)) { G4int trackID = aTrack->GetTrackID(); std::map::iterator itr; itr = myOldTracksMap.find(trackID); @@ -199,7 +199,7 @@ void musrSteppingAction::UserSteppingAction(const G4Step* aStep) { vertexKine_oldTrack[indexOfOldTrack] = aTrack->GetVertexKineticEnergy(); vertexPosition_oldTrack[indexOfOldTrack] = aTrack->GetVertexPosition(); vertexLogVol_oldTrack[indexOfOldTrack] = aTrack->GetLogicalVolumeAtVertex()->GetName(); - if ((aTrack->GetCreatorProcess())!=NULL) { vertexProcess_oldTrack[indexOfOldTrack] = aTrack->GetCreatorProcess()->GetProcessName();} + if ((aTrack->GetCreatorProcess())!=nullptr) { vertexProcess_oldTrack[indexOfOldTrack] = aTrack->GetCreatorProcess()->GetProcessName();} else { vertexProcess_oldTrack[indexOfOldTrack] = "initialParticle";} } else { @@ -326,7 +326,7 @@ void musrSteppingAction::UserSteppingAction(const G4Step* aStep) { // Pick up process "DecayWithSpin": const G4VProcess* process = postStepPoint->GetProcessDefinedStep(); - if (process!=NULL) { + if (process!=nullptr) { G4String processName = process->GetProcessName(); if (processName=="DecayWithSpin") { // std::cout<<"musrSteppingAction: DecayWithSpin"<GetFieldManager(); // G4cout<<"Debug 1"<DoesFieldChangeEnergy()) { //then we have a magnetic field // G4cout<<"Debug 3"<GetPostStepPoint()->GetProcessDefinedStep() != NULL){ + if(fStep->GetPostStepPoint()->GetProcessDefinedStep() != nullptr){ G4cout << " " << std::setw(10) << fStep->GetPostStepPoint()->GetProcessDefinedStep() ->GetProcessName();