diff --git a/Calorimeter/CaloG4Sim/src/SimulationEnergies.cc b/Calorimeter/CaloG4Sim/src/SimulationEnergies.cc index 69b04c80883052805d43dfadea9d8bd0a1dd0c16..023d038f849e9acc85615d611ccb67778f2f2347 100644 --- a/Calorimeter/CaloG4Sim/src/SimulationEnergies.cc +++ b/Calorimeter/CaloG4Sim/src/SimulationEnergies.cc @@ -120,7 +120,10 @@ #include "G4TouchableHistory.hh" #include "G4ios.hh" +#include <mutex> +static std::once_flag warning1OnceFlag; +static std::once_flag warning2OnceFlag; namespace CaloG4 { @@ -564,17 +567,13 @@ namespace CaloG4 } // If we get here, the registry was never initialized for LAr. - // FIXME: thread-unsafe statics!!! - static G4bool errorDisplayed = false; - if ( ! errorDisplayed ) { - errorDisplayed = true; - G4cout << "SimulationEnergies::ProcessEscapedEnergy - " << G4endl - << " WARNING! CaloG4::EscapedEnergyRegistry was never initialized for 'LArG4::'" << G4endl - << " and LArG4Sim is the package with the code that handles CalibrationHits" << G4endl - << " in non-sensitive volumes. Not all energies deposited in this simulation" << G4endl - << " will be recorded." << G4endl; - } - + std::call_once(warning1OnceFlag, [](){ + G4cout << "SimulationEnergies::ProcessEscapedEnergy - " << G4endl + << " WARNING! CaloG4::EscapedEnergyRegistry was never initialized for 'LArG4::'" << G4endl + << " and LArG4Sim is the package with the code that handles CalibrationHits" << G4endl + << " in non-sensitive volumes. Not all energies deposited in this simulation" << G4endl + << " will be recorded." << G4endl; + }); return false; } else { @@ -588,17 +587,14 @@ namespace CaloG4 } // If we get here, the registry was never initialized for LAr. - // FIXME: thread-unsafe statics!!! - static G4bool errorDisplayed1 = false; - if ( ! errorDisplayed1 ) { - errorDisplayed1 = true; - G4cout << "SimulationEnergies::ProcessEscapedEnergy - " << G4endl - <<" WARNING! touchableHandle->GetVolume()==0 geometry problem ? and also" << G4endl - << " WARNING! CaloG4::EscapedEnergyRegistry was never initialized for 'LArG4::'" << G4endl - << " and LArG4Sim is the package with the code that handles CalibrationHits" << G4endl - << " in non-sensitive volumes. Not all energies deposited in this simulation" << G4endl - << " will be recorded." << G4endl; - } + std::call_once(warning2OnceFlag, [](){ + G4cout << "SimulationEnergies::ProcessEscapedEnergy - " << G4endl + <<" WARNING! touchableHandle->GetVolume()==0 geometry problem ? and also" << G4endl + << " WARNING! CaloG4::EscapedEnergyRegistry was never initialized for 'LArG4::'" << G4endl + << " and LArG4Sim is the package with the code that handles CalibrationHits" << G4endl + << " in non-sensitive volumes. Not all energies deposited in this simulation" << G4endl + << " will be recorded." << G4endl; + }); return false; } }