Commit 4b5f7897 authored by Vakhtang Tsulaia's avatar Vakhtang Tsulaia
Browse files

Merge branch 'IMaterialEffectsUpdator_non_virtual_no_alloc' into 'master'

Since we now have only one IMaterialEffects implementation, we can avoid a polymorphic ICache and relevant dynamic memory allocations

See merge request atlas/athena!48829
parents 3366a446 f9291f41
......@@ -55,33 +55,36 @@ public:
}
/**
* Abstract cache class to allow passing information to/between calls.
* Cache class to allow passing information to/between calls.
* This can be particular useful in Athena MT
* re-entrant algorithms
*/
class ICache
{
public:
/* we can make this concrete
* if we do not need a Dummy
* Material Effects updator
*/
enum MaterialCacheType
{
MaterialEffects = 0,
DummyMaterialEffects = 1
};
virtual MaterialCacheType type() const = 0;
virtual ~ICache() = default;
protected:
ICache() = default;
ICache()
: validationLayer{ nullptr }
, validationSteps{ 0 }
, validationPhi{ 0. }
, validationEta{ 0. }
, accumulatedElossSigma{ 0. }
{}
~ICache() = default;
//!< layer in the current validation step
const Trk::Layer* validationLayer{ nullptr };
int validationSteps{ 0 }; //!< number of validation steps
double validationPhi{ 0. }; //!< theta
double validationEta{ 0. }; //!< eta
//!< Sigma of the eloss accumulated so far in the extrapolation. Used in
//!< Landau mode
double accumulatedElossSigma{ 0. };
};
/**
* Creates an instance of the cache to be used.
* by the client.
*/
virtual std::unique_ptr<ICache> getCache() const = 0;
virtual ICache getCache() const { return {}; }
/** Updator interface (full update for a layer):
The parameters are given as a pointer owned by the caller.
......
......@@ -363,7 +363,7 @@ private:
//!< return helper for parameters and boundary
ParametersNextVolume m_parametersAtBoundary;
//!< Caches per MaterialUpdator
std::vector<std::unique_ptr<Trk::IMaterialEffectsUpdator::ICache>> m_MaterialUpCache;
std::vector<Trk::IMaterialEffectsUpdator::ICache> m_MaterialUpCache;
//!< internal switch for resolved configuration
bool m_dense = false;
//!< Flag the recall solution
......
......@@ -43,7 +43,7 @@ inline IMaterialEffectsUpdator::ICache&
Extrapolator::subMaterialEffectsUpdatorCache(Cache& cache,
const TrackingVolume& tvol) const
{
return *(cache.m_MaterialUpCache[tvol.geometrySignature()]);
return cache.m_MaterialUpCache[tvol.geometrySignature()];
}
inline void
......
......@@ -73,50 +73,17 @@ class MaterialEffectsUpdator : public AthAlgTool,
* The concrete cache class for this specialization of the IMaterialEffectsUpdator
*/
typedef IMaterialEffectsUpdator::ICache ICache;
class Cache : public ICache
{
public:
Cache()
: validationLayer{ nullptr }
, validationSteps{ 0 }
, validationPhi{ 0. }
, validationEta{ 0. }
, accumulatedElossSigma{ 0. }
{}
virtual MaterialCacheType type() const override final
{
return ICache::MaterialEffects;
}
//!< layer in the current validation step
const Trk::Layer* validationLayer{ nullptr };
int validationSteps{ 0 }; //!< number of validation steps
double validationPhi{ 0. }; //!< theta
double validationEta{ 0. }; //!< eta
//!< Sigma of the eloss accumulated so far in the extrapolation. Used in Landau mode
double accumulatedElossSigma{ 0. };
};
virtual std::unique_ptr<ICache> getCache() const override final
{
return std::make_unique<Cache>();
}
/** Updator interface (full update for a layer)
---> ALWAYS pointer to new TrackParameters is returned
*/
virtual std::unique_ptr<TrackParameters> update(
ICache& icache,
ICache& cache,
const TrackParameters* parm,
const Layer& sf,
PropDirection dir=alongMomentum,
ParticleHypothesis particle=pion,
MaterialUpdateMode matupmode=addNoise
) const override {
if(icache.type()!=ICache::MaterialEffects){
ATH_MSG_WARNING("Wrong cache Type");
return nullptr;
}
Cache& cache= static_cast<Cache&> (icache);
return updateImpl(cache,parm,sf,dir,particle,matupmode);
}
/** Updator interface (full update for a layer) according to user
......@@ -124,17 +91,12 @@ class MaterialEffectsUpdator : public AthAlgTool,
---> ALWAYS pointer to new TrackParameters is returned
*/
virtual std::unique_ptr<TrackParameters> update(
ICache& icache,
ICache& cache,
const TrackParameters* parm,
const MaterialEffectsOnTrack& meff,
Trk::ParticleHypothesis particle = pion,
MaterialUpdateMode matupmode = addNoise
) const override {
if (icache.type() != ICache::MaterialEffects) {
ATH_MSG_WARNING("Wrong cache Type");
return nullptr;
}
Cache& cache = static_cast<Cache&>(icache);
return updateImpl(cache, parm, meff, particle, matupmode);
}
......@@ -142,18 +104,13 @@ class MaterialEffectsUpdator : public AthAlgTool,
---> ALWAYS pointer to new TrackParameters is returned
*/
virtual std::unique_ptr<TrackParameters> preUpdate(
ICache& icache,
ICache& cache,
const TrackParameters* parm,
const Layer& sf,
PropDirection dir = alongMomentum,
ParticleHypothesis particle = pion,
MaterialUpdateMode matupmode = addNoise
) const override {
if (icache.type() != ICache::MaterialEffects) {
ATH_MSG_WARNING("Wrong cache Type");
return nullptr;
}
Cache& cache = static_cast<Cache&>(icache);
return preUpdateImpl(cache, parm, sf, dir, particle, matupmode);
}
......@@ -162,23 +119,18 @@ class MaterialEffectsUpdator : public AthAlgTool,
if no postUpdate is to be done : return nullptr
*/
virtual std::unique_ptr<TrackParameters> postUpdate(
ICache& icache,
ICache& cache,
const TrackParameters& parm,
const Layer& sf,
PropDirection dir = alongMomentum,
ParticleHypothesis particle = pion,
MaterialUpdateMode matupmode = addNoise
) const override final {
if (icache.type() != ICache::MaterialEffects) {
ATH_MSG_WARNING("Wrong cache Type");
return nullptr;
}
Cache& cache = static_cast<Cache&>(icache);
return postUpdateImpl(cache, parm, sf, dir, particle, matupmode);
}
/** Dedicated Updator interface:-> create new track parameters*/
virtual std::unique_ptr<TrackParameters> update(
ICache& icache,
ICache& cache,
const TrackParameters& parm,
const MaterialProperties& mprop,
double pathcorrection,
......@@ -186,34 +138,20 @@ class MaterialEffectsUpdator : public AthAlgTool,
ParticleHypothesis particle = pion,
MaterialUpdateMode matupmode = addNoise
) const override final {
if (icache.type() != ICache::MaterialEffects) {
ATH_MSG_WARNING("Wrong cache Type");
return nullptr;
}
Cache& cache = static_cast<Cache&>(icache);
return updateImpl(cache, parm, mprop, pathcorrection, dir, particle, matupmode);
}
/** Validation Action - calls the writing and resetting of the TTree variables */
virtual void validationAction(ICache& icache) const override final
virtual void validationAction(ICache& cache) const override final
{
if (icache.type() != ICache::MaterialEffects) {
ATH_MSG_WARNING("Wrong cache Type");
}
Cache& cache = static_cast<Cache&>(icache);
validationActionImpl(cache);
}
/** Only has an effect if m_landauMode == true.
Resets mutable variables used for non-local calculation of energy loss if
parm == 0. Otherwise, modifies parm with the final update of the covariance matrix*/
virtual void modelAction(ICache& icache, const TrackParameters* parm = nullptr) const override final
virtual void modelAction(ICache& cache, const TrackParameters* parm = nullptr) const override final
{
if (icache.type() != ICache::MaterialEffects) {
ATH_MSG_WARNING("Wrong cache Type");
}
Cache& cache = static_cast<Cache&>(icache);
modelActionImpl(cache, parm);
}
......@@ -229,7 +167,7 @@ class MaterialEffectsUpdator : public AthAlgTool,
MaterialUpdateMode matupmode = addNoise
) const override final {
Cache& cache = getTLSCache();
ICache& cache = getTLSCache();
return updateImpl(cache, parm, sf, dir, particle, matupmode);
}
......@@ -239,7 +177,7 @@ class MaterialEffectsUpdator : public AthAlgTool,
Trk::ParticleHypothesis particle = pion,
MaterialUpdateMode matupmode = addNoise
) const override final {
Cache& cache = getTLSCache();
ICache& cache = getTLSCache();
return updateImpl(cache, parm, meff, particle, matupmode);
}
......@@ -250,7 +188,7 @@ class MaterialEffectsUpdator : public AthAlgTool,
ParticleHypothesis particle = pion,
MaterialUpdateMode matupmode = addNoise
) const override final {
Cache& cache = getTLSCache();
ICache& cache = getTLSCache();
return preUpdateImpl(cache, parm, sf, dir, particle, matupmode);
}
......@@ -261,7 +199,7 @@ class MaterialEffectsUpdator : public AthAlgTool,
ParticleHypothesis particle = pion,
MaterialUpdateMode matupmode = addNoise
) const override final {
Cache& cache = getTLSCache();
ICache& cache = getTLSCache();
return postUpdateImpl(cache, parm, sf, dir, particle, matupmode);
}
......@@ -273,20 +211,20 @@ class MaterialEffectsUpdator : public AthAlgTool,
ParticleHypothesis particle = pion,
MaterialUpdateMode matupmode = addNoise
) const override final {
Cache& cache = getTLSCache();
ICache& cache = getTLSCache();
return updateImpl(cache, parm, mprop, pathcorrection, dir, particle, matupmode);
}
virtual void validationAction() const override final
{
Cache& cache = getTLSCache();
ICache& cache = getTLSCache();
validationActionImpl(cache);
}
virtual void modelAction(
const TrackParameters* parm = nullptr) const override final
{
Cache& cache = getTLSCache();
ICache& cache = getTLSCache();
modelActionImpl(cache, parm);
}
......@@ -294,7 +232,7 @@ class MaterialEffectsUpdator : public AthAlgTool,
/* The acutal implementation methods using the tool's
* concrete Cache*/
std::unique_ptr<TrackParameters> updateImpl(
Cache& cache,
ICache& cache,
const TrackParameters* parm,
const Layer& sf,
PropDirection dir = alongMomentum,
......@@ -303,7 +241,7 @@ class MaterialEffectsUpdator : public AthAlgTool,
) const;
std::unique_ptr<TrackParameters> updateImpl(
Cache& cache,
ICache& cache,
const TrackParameters* parm,
const MaterialEffectsOnTrack& meff,
Trk::ParticleHypothesis particle = pion,
......@@ -311,7 +249,7 @@ class MaterialEffectsUpdator : public AthAlgTool,
) const;
std::unique_ptr<TrackParameters> preUpdateImpl(
Cache& cache,
ICache& cache,
const TrackParameters* parm,
const Layer& sf,
PropDirection dir = alongMomentum,
......@@ -320,7 +258,7 @@ class MaterialEffectsUpdator : public AthAlgTool,
) const;
std::unique_ptr<TrackParameters> postUpdateImpl(
Cache& cache,
ICache& cache,
const TrackParameters& parm,
const Layer& sf,
PropDirection dir = alongMomentum,
......@@ -329,7 +267,7 @@ class MaterialEffectsUpdator : public AthAlgTool,
) const;
std::unique_ptr<TrackParameters> updateImpl(
Cache& cache,
ICache& cache,
const TrackParameters* parm,
const MaterialProperties& mprop,
double pathcorrection,
......@@ -339,7 +277,7 @@ class MaterialEffectsUpdator : public AthAlgTool,
) const;
std::unique_ptr<TrackParameters> updateImpl(
Cache& cache,
ICache& cache,
const TrackParameters& parm,
const MaterialProperties& mprop,
double pathcorrection,
......@@ -348,9 +286,9 @@ class MaterialEffectsUpdator : public AthAlgTool,
MaterialUpdateMode matupmode = addNoise
) const;
static void validationActionImpl(Cache& cache) ;
static void validationActionImpl(ICache& cache) ;
static void modelActionImpl(Cache& cache, const TrackParameters* parm = nullptr) ;
static void modelActionImpl(ICache& cache, const TrackParameters* parm = nullptr) ;
/** A simple check method for the 'removeNoise' update model */
bool checkCovariance(AmgSymMatrix(5)& updated) const ;
......@@ -393,11 +331,11 @@ class MaterialEffectsUpdator : public AthAlgTool,
* Done here via boost::thread_specific_ptr
*/
mutable boost::thread_specific_ptr<Cache> m_cache_tls;
Cache& getTLSCache() const{
Cache* cache = m_cache_tls.get();
mutable boost::thread_specific_ptr<ICache> m_cache_tls;
ICache& getTLSCache() const{
ICache* cache = m_cache_tls.get();
if (!cache) {
cache = new Cache();
cache = new ICache();
m_cache_tls.reset( cache );
}
return *cache;
......
......@@ -963,7 +963,7 @@ Trk::Extrapolator::extrapolateToNextMaterialLayer(const EventContext& ctx,
nextPar->position(), nextPar->momentum(), nextPar->charge())));
//
auto mefot =
std::make_unique<Trk::MaterialEffectsOnTrack>(dInX0, std::move(newsa), eloss, cvlTP->associatedSurface());
std::make_unique<Trk::MaterialEffectsOnTrack>(dInX0, newsa, eloss, cvlTP->associatedSurface());
cache.m_matstates->push_back(new TrackStateOnSurface(nullptr, std::move(cvlTP), nullptr, std::move(mefot)));
if (cache.m_extrapolationCache) {
if (m_dumpCache) {
......@@ -1296,7 +1296,7 @@ Trk::Extrapolator::extrapolateToNextMaterialLayer(const EventContext& ctx,
nextPar->position(), nextPar->momentum(), nextPar->charge())));
auto mefot =
std::make_unique<const Trk::MaterialEffectsOnTrack>(dInX0, std::move(newsa), eloss, cvlTP->associatedSurface());
std::make_unique<const Trk::MaterialEffectsOnTrack>(dInX0, newsa, eloss, cvlTP->associatedSurface());
cache.m_matstates->push_back(new TrackStateOnSurface(nullptr, std::move(cvlTP), nullptr, std::move(mefot)));
......@@ -1423,7 +1423,7 @@ Trk::Extrapolator::extrapolateToNextMaterialLayer(const EventContext& ctx,
std::unique_ptr<const Trk::TrackParameters> cvlTP(replaceTrkParm(new Trk::CurvilinearParameters(
nextPar->position(), nextPar->momentum(), nextPar->charge())));
auto mefot =
std::make_unique<const Trk::MaterialEffectsOnTrack>(dInX0, std::move(newsa), eloss, cvlTP->associatedSurface());
std::make_unique<const Trk::MaterialEffectsOnTrack>(dInX0, newsa, eloss, cvlTP->associatedSurface());
if (cache.m_extrapolationCache) {
if (checkCache(cache, " mat states extrapolateToNextMaterialLayer thin")) {
if (m_dumpCache) {
......@@ -1575,7 +1575,7 @@ Trk::Extrapolator::extrapolateToNextMaterialLayer(const EventContext& ctx,
std::unique_ptr<const Trk::TrackParameters> cvlTP(replaceTrkParm(new Trk::CurvilinearParameters(
nextPar->position(), nextPar->momentum(), nextPar->charge())));
auto mefot =
std::make_unique<const Trk::MaterialEffectsOnTrack>(dInX0, std::move(newsa), eloss, cvlTP->associatedSurface());
std::make_unique<const Trk::MaterialEffectsOnTrack>(dInX0, newsa, eloss, cvlTP->associatedSurface());
if (cache.m_extrapolationCache) {
if (checkCache(cache, " mat states extrapolateToNextMaterialLayer thin")) {
if (m_dumpCache) {
......@@ -2482,8 +2482,8 @@ Trk::Extrapolator::extrapolateImpl(const EventContext& ctx,
{
// set the model action of the material effects updaters
for (unsigned int imueot = 0; imueot < m_subupdaters.size(); ++imueot) {
if(m_subupdaters[imueot] && cache.m_MaterialUpCache[imueot]){
m_subupdaters[imueot]->modelAction(*(cache.m_MaterialUpCache[imueot]));
if(m_subupdaters[imueot]){
m_subupdaters[imueot]->modelAction((cache.m_MaterialUpCache[imueot]));
}
}
......@@ -2697,8 +2697,8 @@ Trk::Extrapolator::extrapolateImpl(const EventContext& ctx,
// destination reached : indicated through result parameters
// set the model action of the material effects updaters
for (unsigned int imueot = 0; imueot < m_subupdaters.size(); ++imueot) {
if(m_subupdaters[imueot] && cache.m_MaterialUpCache[imueot]){
m_subupdaters[imueot]->modelAction(*(cache.m_MaterialUpCache[imueot]));
if(m_subupdaters[imueot]){
m_subupdaters[imueot]->modelAction((cache.m_MaterialUpCache[imueot]));
}
}
// return the parameters at destination
......@@ -4675,7 +4675,7 @@ Trk::Extrapolator::addMaterialEffectsOnTrack(const EventContext& ctx,
ScatteringAngles(0, 0, sigmaMS / std::sin(parsOnLayer->parameters()[Trk::theta]), sigmaMS);
auto meot = std::make_unique<const Trk::MaterialEffectsOnTrack>(
tInX0, std::move(scatAngles), energyLoss, *lay.surfaceRepresentation().baseSurface());
tInX0, scatAngles, energyLoss, *lay.surfaceRepresentation().baseSurface());
// push it to the material states
cache.m_matstates->push_back(
new TrackStateOnSurface(nullptr, parsOnLayer.to_unique(), nullptr, std::move(meot)));
......@@ -5395,7 +5395,7 @@ Trk::Extrapolator::extrapolateToVolumeWithPathLimit(const EventContext& ctx,
<< eloss->deltaE());
auto mefot = std::make_unique<const Trk::MaterialEffectsOnTrack>(
dInX0, std::move(newsa), eloss, *((nextPar->associatedSurface()).baseSurface()));
dInX0, newsa, eloss, *((nextPar->associatedSurface()).baseSurface()));
cache.m_matstates->push_back(
new TrackStateOnSurface(nullptr, ManagedTrackParmPtr(nextPar).to_unique(), nullptr, std::move(mefot)));
......
......@@ -138,7 +138,7 @@ Trk::MaterialEffectsUpdator::initialize()
std::unique_ptr<Trk::TrackParameters>
Trk::MaterialEffectsUpdator::updateImpl(
Cache& cache,
ICache& cache,
const TrackParameters* parm,
const Layer& lay,
PropDirection dir,
......@@ -184,7 +184,7 @@ Trk::MaterialEffectsUpdator::updateImpl(
std::unique_ptr<Trk::TrackParameters>
Trk::MaterialEffectsUpdator::updateImpl(
Cache& cache,
ICache& cache,
const TrackParameters* parm,
const MaterialEffectsOnTrack& meff,
ParticleHypothesis particle,
......@@ -367,7 +367,7 @@ Trk::MaterialEffectsUpdator::updateImpl(
std::unique_ptr<Trk::TrackParameters>
Trk::MaterialEffectsUpdator::preUpdateImpl(
Cache& cache,
ICache& cache,
const TrackParameters* parm,
const Layer& lay,
PropDirection dir,
......@@ -421,7 +421,7 @@ Trk::MaterialEffectsUpdator::preUpdateImpl(
std::unique_ptr<Trk::TrackParameters>
Trk::MaterialEffectsUpdator::postUpdateImpl(
Cache& cache,
ICache& cache,
const TrackParameters& parm,
const Layer& lay,
PropDirection dir,
......@@ -477,7 +477,7 @@ Trk::MaterialEffectsUpdator::postUpdateImpl(
// actual update method - manipulation
std::unique_ptr<Trk::TrackParameters>
Trk::MaterialEffectsUpdator::updateImpl(
Cache& cache,
ICache& cache,
const TrackParameters* parm,
const MaterialProperties& matprop,
double pathcorrection,
......@@ -654,7 +654,7 @@ Trk::MaterialEffectsUpdator::updateImpl(
// actual update method
std::unique_ptr<Trk::TrackParameters>
Trk::MaterialEffectsUpdator::updateImpl(
Cache& cache,
ICache& cache,
const TrackParameters& parm,
const MaterialProperties& matprop,
double pathcorrection,
......@@ -819,7 +819,7 @@ Trk::MaterialEffectsUpdator::updateImpl(
}
void
Trk::MaterialEffectsUpdator::validationActionImpl(Cache& cache)
Trk::MaterialEffectsUpdator::validationActionImpl(ICache& cache)
{
cache.validationEta = 0.;
cache.validationPhi = 0.;
......@@ -827,7 +827,7 @@ Trk::MaterialEffectsUpdator::validationActionImpl(Cache& cache)
}
void
Trk::MaterialEffectsUpdator::modelActionImpl(Cache& cache, const Trk::TrackParameters* /*parm*/)
Trk::MaterialEffectsUpdator::modelActionImpl(ICache& cache, const Trk::TrackParameters* /*parm*/)
{
cache.accumulatedElossSigma = 0;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment