From d6f39d1b143884590c918178a534ac0dac74713d Mon Sep 17 00:00:00 2001
From: abarton <adam.edward.barton@cern.ch>
Date: Tue, 10 Oct 2017 17:53:09 +0100
Subject: [PATCH] Add cache hit counts for Trigger use

---
 .../SiTrackerSpacePointFinder.h               |  3 +++
 .../src/SiTrackerSpacePointFinder.cxx         | 20 ++++++++++++++++++-
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/InnerDetector/InDetRecAlgs/SiSpacePointFormation/SiSpacePointFormation/SiTrackerSpacePointFinder.h b/InnerDetector/InDetRecAlgs/SiSpacePointFormation/SiSpacePointFormation/SiTrackerSpacePointFinder.h
index c0f66f96694..7313827e5a3 100755
--- a/InnerDetector/InDetRecAlgs/SiSpacePointFormation/SiSpacePointFormation/SiTrackerSpacePointFinder.h
+++ b/InnerDetector/InDetRecAlgs/SiSpacePointFormation/SiSpacePointFormation/SiTrackerSpacePointFinder.h
@@ -155,6 +155,9 @@ namespace InDet {
     mutable std::atomic<int> m_numberOfEvents;
     mutable std::atomic<int> m_numberOfPixel;
     mutable std::atomic<int> m_numberOfSCT;
+    mutable std::atomic<int> m_sctCacheHits;
+    mutable std::atomic<int> m_pixCacheHits;
+    bool m_cachemode; //used for online MT counters
     const InDetDD::SCT_DetectorManager* m_manager; 
     // const InDetDD::PixelDetectorManager* m_managerPixel;     // unused
     const SCT_ID* m_idHelper;
diff --git a/InnerDetector/InDetRecAlgs/SiSpacePointFormation/src/SiTrackerSpacePointFinder.cxx b/InnerDetector/InDetRecAlgs/SiSpacePointFormation/src/SiTrackerSpacePointFinder.cxx
index 894c5c1cdb6..b06223456b8 100755
--- a/InnerDetector/InDetRecAlgs/SiSpacePointFormation/src/SiTrackerSpacePointFinder.cxx
+++ b/InnerDetector/InDetRecAlgs/SiSpacePointFormation/src/SiTrackerSpacePointFinder.cxx
@@ -59,6 +59,8 @@ const SiElementPropertiesTable* SiTrackerSpacePointFinder::s_properties = nullpt
     m_zVertex(0.),
     m_iBeamCondSvc("BeamCondSvc",name),
     m_numberOfEvents(0), m_numberOfPixel(0), m_numberOfSCT(0),
+    m_sctCacheHits(0), m_pixCacheHits(0),
+    m_cachemode(false),
     m_manager(0),
     m_idHelper(nullptr),
     m_idHelperPixel(nullptr),
@@ -172,6 +174,7 @@ StatusCode SiTrackerSpacePointFinder::initialize()
 
   ATH_CHECK(m_SpacePointCache_SCTKey.initialize(!m_SpacePointCache_SCTKey.key().empty()));
   ATH_CHECK(m_SpacePointCache_PixKey.initialize(!m_SpacePointCache_PixKey.key().empty()));
+  m_cachemode = !m_SpacePointCache_SCTKey.key().empty() || !m_SpacePointCache_PixKey.key().empty();
 
   ATH_MSG_INFO( "SiTrackerSpacePointFinder::initialized for package version " << PACKAGE_VERSION );
   return StatusCode::SUCCESS;
@@ -185,7 +188,6 @@ StatusCode SiTrackerSpacePointFinder::execute_r (const EventContext& ctx) const
 
   ++m_numberOfEvents;
   SPFCache r_cache(ctx);
-
   if (! m_overrideBS){
     r_cache.vertex = m_iBeamCondSvc->beamVtx().position();
   } else {
@@ -226,6 +228,9 @@ StatusCode SiTrackerSpacePointFinder::execute_r (const EventContext& ctx) const
 
   ATH_MSG_DEBUG( "Container '" << spacepointoverlapCollection.name() << "' initialised" );
 
+  int sctCacheCount = 0;
+  int pixCacheCount = 0;
+
   if (m_selectSCTs){
 
     // retrieve SCT cluster container
@@ -252,6 +257,7 @@ StatusCode SiTrackerSpacePointFinder::execute_r (const EventContext& ctx) const
       IdentifierHash idHash = colNext->identifyHash();
       if(spacePointContainer_SCT->tryFetch(idHash)){
           ATH_MSG_DEBUG("SCT Hash " << idHash << " is already in cache");
+          ++sctCacheCount;
           continue; //Skip if already present in cache
       }
 
@@ -302,6 +308,7 @@ StatusCode SiTrackerSpacePointFinder::execute_r (const EventContext& ctx) const
 
       if(spacePointContainerPixel->tryFetch(idHash)){
           ATH_MSG_DEBUG("pixel Hash " << idHash << " is already in cache");
+          ++pixCacheCount;
           continue;
       }
       // Create SpacePointCollection
@@ -348,6 +355,11 @@ StatusCode SiTrackerSpacePointFinder::execute_r (const EventContext& ctx) const
   }
   m_numberOfPixel += spacePointContainerPixel->numberOfCollections();
   m_numberOfSCT   += spacePointContainer_SCT->numberOfCollections();
+  if(m_cachemode)//Prevent unnecessary atomic counting
+  {
+     m_sctCacheHits  += sctCacheCount;
+     m_pixCacheHits  += pixCacheCount;
+  }
   return StatusCode::SUCCESS;
 }
 
@@ -358,6 +370,12 @@ StatusCode SiTrackerSpacePointFinder::finalize()
   ATH_MSG_INFO( m_numberOfEvents << " events processed" );
   ATH_MSG_INFO( m_numberOfPixel << " pixel collections processed" );
   ATH_MSG_INFO( m_numberOfSCT << " sct collections processed" );
+  if(m_cachemode){
+    //These are debug messages because they can be indeterminate in an MT environment and it could
+    //lead to confusing log comparisons.
+    ATH_MSG_DEBUG( m_sctCacheHits << " sct cache hits" );
+    ATH_MSG_DEBUG( m_pixCacheHits << " pix cache hits" );
+  }
   if(s_properties){
      delete s_properties; s_properties = nullptr;
   }
-- 
GitLab