From f2c54fabe4f44743f94513eacb38a8674b55e9bd Mon Sep 17 00:00:00 2001
From: christos <christos@cern.ch>
Date: Wed, 22 Jul 2020 17:39:37 +0100
Subject: [PATCH] Replace CachedUniquePtr with value for the global Position

---
 .../InDetPrepRawData/SiCluster.h              | 221 +++++++--------
 .../InDetPrepRawData/src/SiCluster.cxx        | 265 +++++++++---------
 2 files changed, 233 insertions(+), 253 deletions(-)

diff --git a/InnerDetector/InDetRecEvent/InDetPrepRawData/InDetPrepRawData/SiCluster.h b/InnerDetector/InDetRecEvent/InDetPrepRawData/InDetPrepRawData/SiCluster.h
index 8d6785e6248..8570369965a 100755
--- a/InnerDetector/InDetRecEvent/InDetPrepRawData/InDetPrepRawData/SiCluster.h
+++ b/InnerDetector/InDetRecEvent/InDetPrepRawData/InDetPrepRawData/SiCluster.h
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
 */
 
 ///////////////////////////////////////////////////////////////////
@@ -16,8 +16,6 @@
 
 // Base class
 #include "TrkPrepRawData/PrepRawData.h"
-
-#include "CxxUtils/CachedUniquePtr.h"
 #include "Identifier/Identifier.h"
 #include "InDetPrepRawData/SiWidth.h"
 #include "InDetReadoutGeometry/SiDetectorElement.h" // cant be forward declared
@@ -36,138 +34,135 @@ class SCT_ClusterContainerCnv_p0;
 class SCT_ClusterContainerCnv_p1;
 class SiClusterCnv_p1;
 
-namespace InDet{
-
-class SiCluster :   public Trk::PrepRawData {
-        /**
-         * @name Friend class declarations
-         */
-        //@{
-  	friend class ::PixelClusterContainerCnv;
- 	friend class ::SCT_ClusterContainerCnv;
-        friend class ::PixelClusterContainerCnv_p2;
-        friend class PixelClusterContainerCnv_p1;
-        friend class ::PixelClusterContainerCnv_p0;
-        friend class SCT_ClusterContainerCnv_p1;
-        friend class ::SCT_ClusterContainerCnv_p0;
-        friend class ::SiClusterCnv_p1;
-        //@}
-
-	public:
-	
-	/// Constructor without parameter
-	SiCluster();
-        /// Copy constructor
-	SiCluster(const SiCluster &);
-        /// Move constructor
-	SiCluster(SiCluster &&);
-        /// Assignment operator
-	SiCluster &operator=(const SiCluster &);
-        /// Move assignment operator
-	SiCluster &operator=(SiCluster &&);
-	
-        /**
-         * Constructor with parameters using pointer of Amg::MatrixX.
-         * Last parameter might not be always filled and will be nullptr by default.
-         * The others including SiDetectorElement have to be given!
-         */
-        SiCluster( 
-                  const Identifier& RDOId,
-                  const Amg::Vector2D& locpos, 
-                  const std::vector<Identifier>& rdoList,
-                  const InDet::SiWidth& width,
-                  const InDetDD::SiDetectorElement* detEl,
-                  const Amg::MatrixX* locErrMat = nullptr
-                 );
- 
-        /**
-         * Constructor with parameters using unique_ptr of Amg::MatrixX.
-         * All parameters have to be given!
-         */
-        SiCluster( 
-                  const Identifier& RDOId,
-                  const Amg::Vector2D& locpos, 
-                  std::vector<Identifier>&& rdoList,
-                  const InDet::SiWidth& width,
-                  const InDetDD::SiDetectorElement* detEl,
-                  std::unique_ptr<const Amg::MatrixX> locErrMat
-                 );
-
-        /// Destructor:
-	virtual ~SiCluster();
-	
-        /**
-         * @name Virtual methods 
-         */
-	//@{
-	/// return width class reference
-	virtual const InDet::SiWidth&  width()  const;
-	
-	/// return global position reference
-	virtual const Amg::Vector3D& globalPosition() const;
-	
-	/// set the flag of this cluster containing a gangedPixel
-	virtual void setGangedPixel(bool ganged);
-	
-	/// return the flag of this cluster containing a gangedPixel
-	virtual bool gangedPixel() const;
-	
-	/// return the detector element corresponding to this PRD
-        /// The pointer will be zero if the det el is not defined (i.e. it was not passed in by the ctor)
-	virtual const InDetDD::SiDetectorElement* detectorElement() const;
-
-	/// dump information about the SiCluster
-	virtual MsgStream&    dump( MsgStream&    stream) const;
-	/// dump information about the SiCluster
-	virtual std::ostream& dump( std::ostream& stream) const;
-        //@}
-
-	private:
-        /// col, row, and width in mm
-	InDet::SiWidth m_width;
-        /// For lazy initialization CxxUtils::CachedUniquePtr is used.
-	CxxUtils::CachedUniquePtr<const Amg::Vector3D> m_globalPosition;
-	bool m_gangedPixel;
-	const InDetDD::SiDetectorElement* m_detEl;
+namespace InDet {
 
+class SiCluster : public Trk::PrepRawData
+{
+  /**
+   * @name Friend class declarations
+   */
+  //@{
+  friend class ::PixelClusterContainerCnv;
+  friend class ::SCT_ClusterContainerCnv;
+  friend class ::PixelClusterContainerCnv_p2;
+  friend class PixelClusterContainerCnv_p1;
+  friend class ::PixelClusterContainerCnv_p0;
+  friend class SCT_ClusterContainerCnv_p1;
+  friend class ::SCT_ClusterContainerCnv_p0;
+  friend class ::SiClusterCnv_p1;
+  //@}
+
+public:
+  SiCluster() = default;
+  /// Copy constructor
+  SiCluster(const SiCluster&);
+  /// Move constructor
+  SiCluster(SiCluster&&);
+  /// Assignment operator
+  SiCluster& operator=(const SiCluster&);
+  /// Move assignment operator
+  SiCluster& operator=(SiCluster&&);
+
+  /**
+   * Constructor with parameters using pointer of Amg::MatrixX.
+   * Last parameter might not be always filled and will be nullptr by
+   * default. The others including SiDetectorElement have to be given!
+   */
+  SiCluster(const Identifier& RDOId,
+            const Amg::Vector2D& locpos,
+            const std::vector<Identifier>& rdoList,
+            const InDet::SiWidth& width,
+            const InDetDD::SiDetectorElement* detEl,
+            const Amg::MatrixX* locErrMat = nullptr);
+
+  /**
+   * Constructor with parameters using unique_ptr of Amg::MatrixX.
+   * All parameters have to be given!
+   */
+  SiCluster(const Identifier& RDOId,
+            const Amg::Vector2D& locpos,
+            std::vector<Identifier>&& rdoList,
+            const InDet::SiWidth& width,
+            const InDetDD::SiDetectorElement* detEl,
+            std::unique_ptr<const Amg::MatrixX> locErrMat);
+
+  /// Destructor:
+  virtual ~SiCluster();
+
+  /**
+   * @name Virtual methods
+   */
+  //@{
+  /// return width class reference
+  virtual const InDet::SiWidth& width() const;
+
+  /// return global position reference
+  virtual const Amg::Vector3D& globalPosition() const;
+
+  /// set the flag of this cluster containing a gangedPixel
+  virtual void setGangedPixel(bool ganged);
+
+  /// return the flag of this cluster containing a gangedPixel
+  virtual bool gangedPixel() const;
+
+  /// return the detector element corresponding to this PRD
+  /// The pointer will be zero if the det el is not defined (i.e. it was
+  /// not passed in by the ctor)
+  virtual const InDetDD::SiDetectorElement* detectorElement() const;
+
+  /// dump information about the SiCluster
+  virtual MsgStream& dump(MsgStream& stream) const;
+  /// dump information about the SiCluster
+  virtual std::ostream& dump(std::ostream& stream) const;
+  //@}
+
+private:
+  /// col, row, and width in mm
+  Amg::Vector3D m_globalPosition = Amg::Vector3D::Zero();
+  InDet::SiWidth m_width{};
+  const InDetDD::SiDetectorElement* m_detEl = nullptr;
+  bool m_gangedPixel = false;
 };
 
- MsgStream&    operator << (MsgStream& stream,    const SiCluster& prd);
- std::ostream& operator << (std::ostream& stream, const SiCluster& prd);
-
+MsgStream&
+operator<<(MsgStream& stream, const SiCluster& prd);
+std::ostream&
+operator<<(std::ostream& stream, const SiCluster& prd);
 
 ///////////////////////////////////////////////////////////////////
 // Inline methods:
 ///////////////////////////////////////////////////////////////////
 // return width:
-inline const InDet::SiWidth&  SiCluster::width() const
+inline const InDet::SiWidth&
+SiCluster::width() const
 {
-	return m_width;
+  return m_width;
 }
 // return globalPosition:
-inline const Amg::Vector3D& SiCluster::globalPosition() const
+inline const Amg::Vector3D&
+SiCluster::globalPosition() const
 {
-  if (not m_globalPosition) {
-    m_globalPosition.set(std::unique_ptr<const Amg::Vector3D>(m_detEl->surface(identify()).localToGlobal(localPosition())));
-  }
-  return *m_globalPosition;
+  return m_globalPosition;
 }
 // set gangedPixel:
-inline void SiCluster::setGangedPixel(bool ganged){
-	m_gangedPixel = ganged;
+inline void
+SiCluster::setGangedPixel(bool ganged)
+{
+  m_gangedPixel = ganged;
 }
 // get gangedPixel:
-inline bool SiCluster::gangedPixel() const
+inline bool
+SiCluster::gangedPixel() const
 {
-	return m_gangedPixel;
+  return m_gangedPixel;
 }
 
-inline const InDetDD::SiDetectorElement* SiCluster::detectorElement() const
+inline const InDetDD::SiDetectorElement*
+SiCluster::detectorElement() const
 {
-	return m_detEl;
+  return m_detEl;
 }
 
-
 }
 
 #endif // TRKPREPRAWDATA_SICLUSTER_H
diff --git a/InnerDetector/InDetRecEvent/InDetPrepRawData/src/SiCluster.cxx b/InnerDetector/InDetRecEvent/InDetPrepRawData/src/SiCluster.cxx
index 03f781da266..3c5714c08ec 100755
--- a/InnerDetector/InDetRecEvent/InDetPrepRawData/src/SiCluster.cxx
+++ b/InnerDetector/InDetRecEvent/InDetPrepRawData/src/SiCluster.cxx
@@ -14,168 +14,153 @@
 #include "InDetPrepRawData/SiCluster.h"
 #include "GaudiKernel/MsgStream.h"
 
-namespace InDet{
-
+namespace InDet {
 
 // Constructor for EF:
-SiCluster::SiCluster(
-        const Identifier &RDOId,
-        const Amg::Vector2D& locpos, 
-        const std::vector<Identifier>& rdoList, 
-        const InDet::SiWidth& width,
-        const InDetDD::SiDetectorElement* detEl,
-        const Amg::MatrixX* locErrMat
-        ) :
-        PrepRawData(RDOId, locpos, rdoList, locErrMat), //call base class constructor
-        m_width(width),
-        m_globalPosition{},
-        m_gangedPixel(0),
-        m_detEl(detEl) {}
-
-SiCluster::SiCluster(
-        const Identifier &RDOId,
-        const Amg::Vector2D& locpos, 
-        std::vector<Identifier>&& rdoList, 
-        const InDet::SiWidth& width,
-        const InDetDD::SiDetectorElement* detEl,
-        std::unique_ptr<const Amg::MatrixX> locErrMat
-        ) :
-        PrepRawData(RDOId, locpos,
-                    std::move(rdoList),
-                    std::move(locErrMat)), //call base class constructor
-        m_width(width),
-        m_globalPosition{},
-        m_gangedPixel(0),
-        m_detEl(detEl) {}
+SiCluster::SiCluster(const Identifier& RDOId,
+                     const Amg::Vector2D& locpos,
+                     const std::vector<Identifier>& rdoList,
+                     const InDet::SiWidth& width,
+                     const InDetDD::SiDetectorElement* detEl,
+                     const Amg::MatrixX* locErrMat)
+  : // call base class constructor
+  PrepRawData(RDOId, locpos, rdoList, locErrMat)
+  , m_width(width)
+  , m_detEl(detEl)
+  , m_gangedPixel(false)
+{
+
+  m_globalPosition =
+    m_detEl->surface(identify()).localToGlobalPos(localPosition());
+}
+
+SiCluster::SiCluster(const Identifier& RDOId,
+                     const Amg::Vector2D& locpos,
+                     std::vector<Identifier>&& rdoList,
+                     const InDet::SiWidth& width,
+                     const InDetDD::SiDetectorElement* detEl,
+                     std::unique_ptr<const Amg::MatrixX> locErrMat)
+  : // call base class constructor
+  PrepRawData(RDOId, locpos, std::move(rdoList), std::move(locErrMat))
+  , m_width(width)
+  , m_detEl(detEl)
+  , m_gangedPixel(false)
+{
+  m_globalPosition =
+    m_detEl->surface(identify()).localToGlobalPos(localPosition());
+}
 
 // Destructor:
 SiCluster::~SiCluster()
 {
-	// do not delete m_detEl since owned by DetectorStore
+  // do not delete m_detEl since owned by DetectorStore
 }
 
-// Default constructor:
-SiCluster::SiCluster():
-	PrepRawData(),
-	m_globalPosition{},
-	m_gangedPixel(0),
-	m_detEl(0)
-{}
 
-//copy constructor:
-SiCluster::SiCluster(const SiCluster& RIO):
-	PrepRawData( RIO ),
-	m_width( RIO.m_width ),
-	m_globalPosition{},
-	m_gangedPixel( RIO.m_gangedPixel ),
-	m_detEl( RIO.m_detEl )
+// copy constructor:
+SiCluster::SiCluster(const SiCluster& RIO)
+   
 
-{
-        // copy only if it exists
-        if (RIO.m_globalPosition) {
-                m_globalPosition.store(std::make_unique<Amg::Vector3D>(*RIO.m_globalPosition));
-        }
-}
+= default;
 
-//move constructor:
-SiCluster::SiCluster(SiCluster&& RIO):
-        PrepRawData( std::move(RIO) ),
-	m_width( std::move(RIO.m_width) ),
-	m_globalPosition( std::move(RIO.m_globalPosition) ),
-	m_gangedPixel( RIO.m_gangedPixel ),
-	m_detEl( RIO.m_detEl )
+// move constructor:
+SiCluster::SiCluster(SiCluster&& RIO)
+  : PrepRawData(std::move(RIO))
+  , m_globalPosition(std::move(RIO.m_globalPosition))
+  , m_width(RIO.m_width)
+  , m_detEl(RIO.m_detEl)
+  , m_gangedPixel(RIO.m_gangedPixel)
 
+{}
+
+// assignment operator
+SiCluster&
+SiCluster::operator=(const SiCluster& RIO)
 {
+  if (&RIO != this) {
+    Trk::PrepRawData::operator=(RIO);
+    m_globalPosition = RIO.m_globalPosition;
+    m_width = RIO.m_width;
+    m_detEl = RIO.m_detEl;
+    m_gangedPixel = RIO.m_gangedPixel;
+  }
+  return *this;
 }
 
-//assignment operator
-SiCluster& SiCluster::operator=(const SiCluster& RIO){
-       if (&RIO !=this) {
-                Trk::PrepRawData::operator= (RIO);
-		m_width = RIO.m_width;
-		if (RIO.m_globalPosition) {
-                        m_globalPosition.store(std::make_unique<Amg::Vector3D>(*RIO.m_globalPosition));
-                } else if (m_globalPosition) {
-                        m_globalPosition.release().reset();
-                }
-		m_gangedPixel = RIO.m_gangedPixel;
-		m_detEl =  RIO.m_detEl ;
-       }
-       return *this;
-} 
-
-//move operator
-SiCluster& SiCluster::operator=(SiCluster&& RIO){
-      if (&RIO !=this) {
-                Trk::PrepRawData::operator= (std::move(RIO));
-                m_width = RIO.m_width;
-                m_globalPosition = std::move(RIO.m_globalPosition);
-                m_gangedPixel = RIO.m_gangedPixel;
-                m_detEl =  RIO.m_detEl ;
-       }
-       return *this;
-} 
-
-MsgStream& SiCluster::dump( MsgStream&    stream) const
+// move operator
+SiCluster&
+SiCluster::operator=(SiCluster&& RIO)
 {
-	stream << "SiCluster object"<<std::endl;
-	
-	// have to do a lot of annoying checking to make sure that PRD is valid. 
-	{
-		stream << "at global coordinates (x,y,z) = ("<<this->globalPosition().x()<<", "
-                       <<this->globalPosition().y()<<", "
-                       <<this->globalPosition().z()<<")"<<std::endl;
-	}
-	
-	if ( gangedPixel()==true ) 
-	{
-		stream << "and is a ganged pixel. "<<std::endl;
-	} else {
-		stream << "and is not a ganged pixel. "<<std::endl;
-	}
-
-        stream << "SiWidth: " << m_width << std::endl;
-
-        stream << "Base class (PrepRawData):" << std::endl;
-        this->PrepRawData::dump(stream);
-
-	return stream;
+  if (&RIO != this) {
+    Trk::PrepRawData::operator=(std::move(RIO));
+    m_globalPosition = std::move(RIO.m_globalPosition);
+    m_width = RIO.m_width;
+    m_detEl = RIO.m_detEl;
+    m_gangedPixel = RIO.m_gangedPixel;
+  }
+  return *this;
 }
 
-std::ostream& SiCluster::dump( std::ostream&    stream) const
+MsgStream&
+SiCluster::dump(MsgStream& stream) const
 {
-	stream << "SiCluster object"<<std::endl;
-	{
-		stream << "at global coordinates (x,y,z) = ("<<this->globalPosition().x()<<", "
-			<<this->globalPosition().y()<<", "
-			<<this->globalPosition().z()<<")"<<std::endl;
-	}
-	
-	if ( gangedPixel()==true ) 
-	{
-		stream << "and is a ganged pixel. "<<std::endl;
-	} else {
-		stream << "and is not a ganged pixel. "<<std::endl;
-	}
-
-        stream << "SiWidth: " << m_width << std::endl;
-
-       stream << "Base Class (PrepRawData): " << std::endl;
-       this->PrepRawData::dump(stream);
-
-	return stream;
+  stream << "SiCluster object" << std::endl;
+
+  // have to do a lot of annoying checking to make sure that PRD is valid.
+  {
+    stream << "at global coordinates (x,y,z) = (" << this->globalPosition().x()
+           << ", " << this->globalPosition().y() << ", "
+           << this->globalPosition().z() << ")" << std::endl;
+  }
+
+  if (gangedPixel()) {
+    stream << "and is a ganged pixel. " << std::endl;
+  } else {
+    stream << "and is not a ganged pixel. " << std::endl;
+  }
+
+  stream << "SiWidth: " << m_width << std::endl;
+
+  stream << "Base class (PrepRawData):" << std::endl;
+  this->PrepRawData::dump(stream);
+
+  return stream;
 }
 
+std::ostream&
+SiCluster::dump(std::ostream& stream) const
+{
+  stream << "SiCluster object" << std::endl;
+  {
+    stream << "at global coordinates (x,y,z) = (" << this->globalPosition().x()
+           << ", " << this->globalPosition().y() << ", "
+           << this->globalPosition().z() << ")" << std::endl;
+  }
+
+  if (gangedPixel()) {
+    stream << "and is a ganged pixel. " << std::endl;
+  } else {
+    stream << "and is not a ganged pixel. " << std::endl;
+  }
 
-    MsgStream&    operator << (MsgStream& stream,    const SiCluster& prd)
-    {
-        return prd.dump(stream);
-    }
+  stream << "SiWidth: " << m_width << std::endl;
 
-    std::ostream& operator << (std::ostream& stream, const SiCluster& prd)
-    {
-        return prd.dump(stream);
-    }
+  stream << "Base Class (PrepRawData): " << std::endl;
+  this->PrepRawData::dump(stream);
 
+  return stream;
+}
+
+MsgStream&
+operator<<(MsgStream& stream, const SiCluster& prd)
+{
+  return prd.dump(stream);
+}
+
+std::ostream&
+operator<<(std::ostream& stream, const SiCluster& prd)
+{
+  return prd.dump(stream);
+}
 
-}//end of ns
+} // end of ns
-- 
GitLab