Skip to content
Snippets Groups Projects
Commit eb63b07d authored by Adam Edward Barton's avatar Adam Edward Barton :speech_balloon:
Browse files

Merge branch 'MaterialEffectsUpdator_boost_thread_specific' into 'master'

move to boost::thread_specific_ptr for the TLS part

See merge request atlas/athena!14566

Former-commit-id: 0163d42a
parents 81f3fec8 b8532a99
No related branches found
No related tags found
No related merge requests found
...@@ -184,47 +184,6 @@ class MaterialEffectsUpdator : public AthAlgTool, ...@@ -184,47 +184,6 @@ class MaterialEffectsUpdator : public AthAlgTool,
return; return;
} }
private:
/*
* Each instance (out of N) needs a have cache in order to accumulate calculation
* between calls to its methods. In a Multi Thread environment we will
* have pontially M threads running. So we need MxN cache instance.
*
* The solution adopted here is an effort to implement
* "Schmidt, Douglas & Pryce, Nat & H. Harrison, Timothy. (1998).
* Thread-Specific Storage for C/C++ - An Object
* Behavioral Pattern for Accessing per-Thread State Efficiently."
* Published in "More C++ Gems (SIGS Reference Library)".
* The solution in Figure 5 is adopted here. One could also adopt Figure 4 as
* an alternative
*
* We have M thread_local ptr to vectors. So one vector for each thread.
* For the lookup each object needs a uniqueID. This is created in the initialize
* by hashing the unique's instance full name.
*
* Following https://google.github.io/styleguide/cppguide.html#thread_local
* the thread local is only exposed from inside a function.
*
* Using thread_local unique_ptr<T> achieves
* the same behaviour as boost::thread_specific_ptr<T>
*/
Cache& getTLSCache() const{
typedef std::vector<Cache> TLSCollection;
/* Initialize a unique ptr to default constructed TLSCollection*/
thread_local std::unique_ptr<TLSCollection> s_cacheStore= std::make_unique<TLSCollection>();
/* Resize the vector, to the requested number of Caches
* Default constructs elements
*/
if (m_uniqueID>s_cacheStore->size()) {
s_cacheStore->resize(m_uniqueID);
}
size_t index= m_uniqueID-1;
return s_cacheStore->operator[](index);
}
public: public:
/* /*
* Public methods using the TLS cache. * Public methods using the TLS cache.
...@@ -359,7 +318,6 @@ class MaterialEffectsUpdator : public AthAlgTool, ...@@ -359,7 +318,6 @@ class MaterialEffectsUpdator : public AthAlgTool,
bool m_landauMode; //!< If in Landau mode, error propagation is done as for landaus bool m_landauMode; //!< If in Landau mode, error propagation is done as for landaus
int m_validationDirection; //!< validation direction int m_validationDirection; //!< validation direction
// ------------------------------ // ------------------------------
std::size_t m_uniqueID; //!< UniqueID Hash based on the unique instance name
double m_momentumCut; //!< Minimal momentum cut for update double m_momentumCut; //!< Minimal momentum cut for update
double m_momentumMax; //!< Maximal momentum cut for update double m_momentumMax; //!< Maximal momentum cut for update
double m_forcedMomentum; //!< Forced momentum value double m_forcedMomentum; //!< Forced momentum value
...@@ -368,6 +326,27 @@ class MaterialEffectsUpdator : public AthAlgTool, ...@@ -368,6 +326,27 @@ class MaterialEffectsUpdator : public AthAlgTool,
ToolHandle< IMultipleScatteringUpdator > m_msUpdator; //!< AlgoTool for MultipleScatterin effects ToolHandle< IMultipleScatteringUpdator > m_msUpdator; //!< AlgoTool for MultipleScatterin effects
// the material mapper for the validation process // the material mapper for the validation process
ToolHandle< IMaterialMapper > m_materialMapper; //!< the material mapper for recording the layer material ToolHandle< IMaterialMapper > m_materialMapper; //!< the material mapper for recording the layer material
/*
* TLS part
* The solution adopted here is an effort to implement
* "Schmidt, Douglas & Pryce, Nat & H. Harrison, Timothy. (1998).
* Thread-Specific Storage for C/C++ - An Object
* Behavioral Pattern for Accessing per-Thread State Efficiently."
* Published in "More C++ Gems (SIGS Reference Library)".
* Adopted here via boost::thread_specific_ptr
*/
mutable boost::thread_specific_ptr<Cache> m_cache_tls;
Cache& getTLSCache() const{
Cache* cache = m_cache_tls.get();
if (!cache) {
cache = new Cache();
m_cache_tls.reset( cache );
}
return *cache;
}
}; };
} // end of namespace } // end of namespace
......
...@@ -50,7 +50,6 @@ Trk::MaterialEffectsUpdator::MaterialEffectsUpdator(const std::string &t, const ...@@ -50,7 +50,6 @@ Trk::MaterialEffectsUpdator::MaterialEffectsUpdator(const std::string &t, const
m_validationIgnoreUnmeasured(true), m_validationIgnoreUnmeasured(true),
m_landauMode(false), m_landauMode(false),
m_validationDirection(1), m_validationDirection(1),
m_uniqueID{1},
m_momentumCut(50. * Gaudi::Units::MeV), m_momentumCut(50. * Gaudi::Units::MeV),
m_momentumMax(10. * Gaudi::Units::TeV), m_momentumMax(10. * Gaudi::Units::TeV),
m_forcedMomentum(2000. * Gaudi::Units::MeV), m_forcedMomentum(2000. * Gaudi::Units::MeV),
...@@ -89,23 +88,6 @@ Trk::MaterialEffectsUpdator::~MaterialEffectsUpdator() { ...@@ -89,23 +88,6 @@ Trk::MaterialEffectsUpdator::~MaterialEffectsUpdator() {
StatusCode StatusCode
Trk::MaterialEffectsUpdator::initialize() { Trk::MaterialEffectsUpdator::initialize() {
/*
* Create a unique_ID (in range 1 ... N) based on the unique AlgTool name
* Initialize is a non-const method. We expect a small vector
* and the initialize to run only a few times
*/
size_t NameID=std::hash<std::string>{}(this->name());
static std::unique_ptr< std::vector<size_t> > s_vectorNamedIDs
=std::make_unique<std::vector<size_t>>();
auto iter= std::find(s_vectorNamedIDs->begin(),s_vectorNamedIDs->end(),NameID);
if(iter==s_vectorNamedIDs->end()){
s_vectorNamedIDs->push_back(NameID);
m_uniqueID=s_vectorNamedIDs->size();
}else{
m_uniqueID = std::distance(s_vectorNamedIDs->begin(),iter) +1;
}
ATH_MSG_INFO("Minimal momentum cut for material update : " << m_momentumCut << " MeV"); ATH_MSG_INFO("Minimal momentum cut for material update : " << m_momentumCut << " MeV");
// retrieve the EnergyLoss Updator and Material Effects updator // retrieve the EnergyLoss Updator and Material Effects updator
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment