From 4186dd33a472c75a97a5320370a16d4f3c49849d Mon Sep 17 00:00:00 2001
From: Stewart Martin-Haugh <smh@cern.ch>
Date: Fri, 14 Aug 2020 17:35:14 +0200
Subject: [PATCH] Make all T2TrackManager methods const

---
 .../TrigT2BeamSpot/src/T2TrackManager.cxx     | 39 ++++++-------------
 .../TrigT2BeamSpot/src/T2TrackManager.h       | 26 +++----------
 2 files changed, 16 insertions(+), 49 deletions(-)

diff --git a/Trigger/TrigAlgorithms/TrigT2BeamSpot/src/T2TrackManager.cxx b/Trigger/TrigAlgorithms/TrigT2BeamSpot/src/T2TrackManager.cxx
index eb52dabe40b5..f4d3d44de7d1 100644
--- a/Trigger/TrigAlgorithms/TrigT2BeamSpot/src/T2TrackManager.cxx
+++ b/Trigger/TrigAlgorithms/TrigT2BeamSpot/src/T2TrackManager.cxx
@@ -29,26 +29,11 @@ using std::abs;
 using namespace PESA;
 
 
-// Not much to do here now, will eventually init the config parameters
-T2TrackManager::T2TrackManager( int nSplit, Algorithm alg )
-  // Fill the defaults
-  : m_nSplit      ( nSplit )
-  , m_alg         ( alg    )
-  , m_altKey      ( -1     )
-  //, m_ordKey      ( 0      )
-{
-}
-
-
-// Will have to clean up after myself here
-T2TrackManager::~T2TrackManager()
-{
-}
-
 // The meat of the class, return a vector of split clusters
 std::vector< ConstDataVector<TrackCollection> >
-T2TrackManager::split( const TrackCollection& cluster )
+T2TrackManager::split( const TrackCollection& cluster, const EventContext& ctx ) const
 {
+  int key = ctx.eventID().event_number() %2 -1;
   const int nEntries = cluster.size();
 
   //std::cout << "Reserve space" << std::endl;
@@ -69,9 +54,9 @@ T2TrackManager::split( const TrackCollection& cluster )
     // tracks in the 1st collection
     int nPos = 0;
     if (m_alg == Alternating)
-      nPos = alternatingSplit();
+      nPos = alternatingSplit(key);
     else if (m_alg == Pt)
-      nPos = orderedSplit(nEntries);
+      nPos = orderedSplit(key, nEntries);
 
     // Add the track to the appropriate collection
     trackCollections[nPos].push_back(*c_itr);
@@ -82,18 +67,16 @@ T2TrackManager::split( const TrackCollection& cluster )
 }
 
 
-int
-T2TrackManager::alternatingSplit()
+constexpr int T2TrackManager::alternatingSplit(int key) const
 {
-  ++m_altKey;
-  m_altKey %= m_nSplit;
-  return m_altKey;
+  ++key;
+  key %= m_nSplit;
+  return key;
 }
 
 
-int
-T2TrackManager::orderedSplit(const int nEntries)
+constexpr int T2TrackManager::orderedSplit(int key, const int nEntries) const
 {
-  ++m_altKey;
-  return m_altKey * m_nSplit / nEntries;
+  ++key;
+  return key * m_nSplit / nEntries;
 }
diff --git a/Trigger/TrigAlgorithms/TrigT2BeamSpot/src/T2TrackManager.h b/Trigger/TrigAlgorithms/TrigT2BeamSpot/src/T2TrackManager.h
index 1a2c44aa5a8d..d7a238629b90 100644
--- a/Trigger/TrigAlgorithms/TrigT2BeamSpot/src/T2TrackManager.h
+++ b/Trigger/TrigAlgorithms/TrigT2BeamSpot/src/T2TrackManager.h
@@ -37,34 +37,18 @@ namespace PESA
     // List of the splitter algorithms
     enum Algorithm { Alternating, Pt, Phi, NorthSouth, Charge };
 
-    // Constructor/Destructor
-    T2TrackManager( int nSplit = 2, Algorithm alg = Alternating );
-
-    ~T2TrackManager();
-
     // Return a vector of sub-clusters
-    std::vector< ConstDataVector<TrackCollection> >          split( const TrackCollection& cluster);
+    std::vector< ConstDataVector<TrackCollection> > split(const TrackCollection& cluster, const EventContext& ctx) const;
 
-    // Get and Set parameters
-    //    int GetNSplit() {return m_nSplit;}
-    //    int GetAlg() {return m_alg;}
-    //    void SetNSplit(int nSplit) {m_nSplit = nSplit;}
-    //    void SetAlg(int alg) {m_alg = alg;}
-    void ResetKey(int key = -1) { m_altKey = key;}
-    
   private:
     
     // The splitter algorithms
-    int alternatingSplit();         // 1 for me, 1 for you, 2 for me, ...
-    int orderedSplit(int nEntries); // 1, 2, 3 for me, 1, 2, 3 for you ...
+    constexpr int alternatingSplit(int key) const;         // 1 for me, 1 for you, 2 for me, ...
+    constexpr int orderedSplit(int key, int nEntries) const; // 1, 2, 3 for me, 1, 2, 3 for you ...
     
     /// Data members
-    int m_nSplit;      // How many output clusters
-    int m_alg;         // Which algorithm to use
-    
-    /// Algorithm helper objects
-    int m_altKey;     // Alternating split key
-    //int m_ordKey;     // Ordered split key
+    int m_nSplit = 2;      // How many output clusters
+    int m_alg = Alternating;         // Which algorithm to use
   };
 
 } //PESA
-- 
GitLab