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

Fix clang warnings in FastSimulation/SimplifiedGeometryPropagator #26429

Merged
merged 2 commits into from
Apr 12, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include "FWCore/Utilities/interface/Exception.h"
#include "FWCore/ParameterSet/interface/FileInPath.h"

#include "FWCore/Utilities/interface/thread_safety_macros.h"

// Fast Sim headers
#include "FastSimulation/SimplifiedGeometryPropagator/interface/Particle.h"
#include "FastSimulation/SimplifiedGeometryPropagator/interface/SimplifiedGeometry.h"
Expand Down Expand Up @@ -200,8 +202,8 @@ namespace fastsim
// TODO: Is this correct?
// Thread safety
static std::once_flag initializeOnce;
[[cms::thread_guard("initializeOnce")]] std::vector< std::vector<double> > NuclearInteraction::theRatiosMap;
[[cms::thread_guard("initializeOnce")]] std::map<int, int> NuclearInteraction::theIDMap;
CMS_THREAD_GUARD(initializeOnce) std::vector< std::vector<double> > NuclearInteraction::theRatiosMap;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Dr15Jones do you see what is different here wrt to the case of NuclearInteractionFTF ? I might simply restore the previous syntax removing the once_flag declaration, but I do not understand what is wrong here...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed the other possible solution works in case

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CMS_THREAD_GUARD(initializeOnce) does not actually use the variable initializeOnce, it just creates the string "initializeOnce". As far as I can tell, the variable is not actually used.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The varaibles theRatiosMap and theIDMap are not handled in a thread-safe way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Dr15Jones ok, in the case of NuclearInteractionFTF initializeOnce is then used by std::call_once, that is the difference

CMS_THREAD_GUARD(initializeOnce) std::map<int, int> NuclearInteraction::theIDMap;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include "FastSimulation/SimplifiedGeometryPropagator/interface/Constants.h"
#include "FastSimulation/Utilities/interface/RandomEngineAndDistribution.h"

#include "FWCore/Utilities/interface/thread_safety_macros.h"

// Math
#include "DataFormats/Math/interface/LorentzVector.h"

Expand Down Expand Up @@ -239,8 +241,8 @@ namespace fastsim
// Is this correct?
// Thread safety
static std::once_flag initializeOnce;
[[cms::thread_guard("initializeOnce")]] const G4ParticleDefinition* NuclearInteractionFTF::theG4Hadron[] = {nullptr};
[[cms::thread_guard("initializeOnce")]] int NuclearInteractionFTF::theId[] = {0};
CMS_THREAD_GUARD(initializeOnce) const G4ParticleDefinition* NuclearInteractionFTF::theG4Hadron[] = {nullptr};
CMS_THREAD_GUARD(initializeOnce) int NuclearInteractionFTF::theId[] = {0};
}

fastsim::NuclearInteractionFTF::NuclearInteractionFTF(const std::string & name,const edm::ParameterSet & cfg)
Expand Down Expand Up @@ -274,7 +276,7 @@ fastsim::NuclearInteractionFTF::NuclearInteractionFTF(const std::string & name,c
theDiffuseElastic = new G4DiffuseElastic();

// Geant4 particles and cross sections
std::call_once(initializeOnce, [this] () {
std::call_once(initializeOnce, [] () {
theG4Hadron[0] = G4Proton::Proton();
theG4Hadron[1] = G4Neutron::Neutron();
theG4Hadron[2] = G4PionPlus::PionPlus();
Expand Down