diff --git a/Tracking/TrkDetDescr/TrkDetDescrUtils/TrkDetDescrUtils/BinnedArray1D.h b/Tracking/TrkDetDescr/TrkDetDescrUtils/TrkDetDescrUtils/BinnedArray1D.h index 2c8369b47c174269968516a1bdfcfb79a4e39b93..d7a4a33e90fae655b8410fa3378edcd9adbdcb2f 100644 --- a/Tracking/TrkDetDescr/TrkDetDescrUtils/TrkDetDescrUtils/BinnedArray1D.h +++ b/Tracking/TrkDetDescr/TrkDetDescrUtils/TrkDetDescrUtils/BinnedArray1D.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 */ /////////////////////////////////////////////////////////////////// @@ -28,6 +28,7 @@ namespace Trk { given by the BinUtitlity. @author Andreas.Salzburger@cern.ch + @author Christos Anastopoulos (Athena MT modifications) */ template<class T> @@ -38,30 +39,35 @@ public: /**Default Constructor - needed for inherited classes */ BinnedArray1DT() : BinnedArrayT<T>() - , m_array(0) + , m_array{} , m_arrayObjects(nullptr) - , m_binUtility(0) + , m_binUtility(nullptr) {} - /**Constructor with std::vector and a BinUtility - reference counted, will delete objects at the end, - if this deletion should be turned off, the boolean deletion should be switched to false - the global position is given by object */ - BinnedArray1DT(const std::vector<std::pair<SharedObject<T>, Amg::Vector3D>>& tclassvector, BinUtility* bingen) + /**Constructor with std::vector and a BinUtility - reference counted, will + delete objects at the end, if this deletion should be turned off, the + boolean deletion should be switched to false the global position is given + by object */ + BinnedArray1DT( + const std::vector<std::pair<SharedObject<T>, Amg::Vector3D>>& tclassvector, + BinUtility* bingen) : BinnedArrayT<T>() - , m_array(0) + , m_array{} , m_arrayObjects(nullptr) , m_binUtility(bingen) { // prepare the binned Array if (bingen) { size_t vecsize = tclassvector.size(); - m_array = new std::vector<SharedObject<T>>(vecsize); + m_array.resize(vecsize); for (size_t ivec = 0; ivec < vecsize; ++ivec) { const Amg::Vector3D currentGlobal(((tclassvector[ivec]).second)); if (bingen->inside(currentGlobal)) { - (*m_array)[bingen->bin(currentGlobal, 0)] = ((tclassvector)[ivec]).first; + m_array[bingen->bin(currentGlobal, 0)] = ((tclassvector)[ivec]).first; } else - throw GaudiException("BinnedArray1DT constructor", "Object outside bounds", StatusCode::FAILURE); + throw GaudiException("BinnedArray1DT constructor", + "Object outside bounds", + StatusCode::FAILURE); } } } @@ -69,15 +75,15 @@ public: /**Copy Constructor - copies only pointers !*/ BinnedArray1DT(const BinnedArray1DT& barr) : BinnedArrayT<T>() - , m_array(0) + , m_array{} , m_arrayObjects(nullptr) - , m_binUtility(0) + , m_binUtility(nullptr) { - m_binUtility = (barr.m_binUtility) ? barr.m_binUtility->clone() : 0; + m_binUtility = (barr.m_binUtility) ? barr.m_binUtility->clone() : nullptr; if (m_binUtility) { - m_array = new std::vector<SharedObject<T>>(barr.m_array->size()); - for (unsigned int ient = 0; ient < barr.m_array->size(); ++ient) { - (*m_array)[ient] = (*barr.m_array)[ient]; + m_array.resize(barr.m_array.size()); + for (unsigned int ient = 0; ient < barr.m_array.size(); ++ient) { + m_array[ient] = (barr.m_array)[ient]; } } } @@ -85,17 +91,16 @@ public: BinnedArray1DT& operator=(const BinnedArray1DT& barr) { if (this != &barr) { - - delete m_array; + m_array.clear(); m_arrayObjects.release(); delete m_binUtility; // now refill m_binUtility = (barr.m_binUtility) ? barr.m_binUtility->clone() : 0; - // -------------------------------------------------------------------------- + if (m_binUtility) { - m_array = new std::vector<SharedObject<T>>(barr.m_array->size()); - for (unsigned int ient = 0; ient < barr.m_array->size(); ++ient) { - (*m_array)[ient] = (*barr.m_array)[ient]; + m_array.resize(barr.m_array.size()); + for (unsigned int ient = 0; ient < barr.m_array.size(); ++ient) { + m_array[ient] = (barr.m_array)[ient]; } } } @@ -105,48 +110,56 @@ public: BinnedArray1DT* clone() const { return new BinnedArray1DT(*this); } /**Virtual Destructor*/ - ~BinnedArray1DT() - { - delete m_array; - delete m_binUtility; - } + ~BinnedArray1DT() { delete m_binUtility; } /** Returns the pointer to the templated class object from the BinnedArrayT, it returns 0 if not defined; */ T* object(const Amg::Vector2D& lp) const { - if (m_binUtility->inside(lp)) - return ((*m_array)[m_binUtility->bin(lp, 0)]).get(); - return 0; + if (m_binUtility->inside(lp)) { + return (m_array[m_binUtility->bin(lp, 0)]).get(); + } + return nullptr; } /** Returns the pointer to the templated class object from the BinnedArrayT it returns 0 if not defined; */ - T* object(const Amg::Vector3D& gp) const { return ((*m_array)[m_binUtility->bin(gp, 0)]).get(); } + T* object(const Amg::Vector3D& gp) const + { + return (m_array[m_binUtility->bin(gp, 0)]).get(); + } - /** Returns the pointer to the templated class object from the BinnedArrayT - entry point*/ - T* entryObject(const Amg::Vector3D& gp) const { return ((*m_array)[m_binUtility->entry(gp, 0)]).get(); } + /** Returns the pointer to the templated class object from the BinnedArrayT - + * entry point*/ + T* entryObject(const Amg::Vector3D& gp) const + { + return (m_array[m_binUtility->entry(gp, 0)]).get(); + } /** Returns the pointer to the templated class object from the BinnedArrayT */ - T* nextObject(const Amg::Vector3D& gp, const Amg::Vector3D& mom, bool associatedResult = true) const + T* nextObject(const Amg::Vector3D& gp, + const Amg::Vector3D& mom, + bool associatedResult = true) const { // the bins - size_t bin = associatedResult ? m_binUtility->bin(gp, 0) : m_binUtility->next(gp, mom, 0); - return ((*m_array)[bin]).get(); + size_t bin = associatedResult ? m_binUtility->bin(gp, 0) + : m_binUtility->next(gp, mom, 0); + return (m_array[bin]).get(); } /** Return all objects of the Array */ const std::vector<T*>& arrayObjects() const { if (!m_arrayObjects) { - std::unique_ptr<std::vector<T*>> arrayObjects = std::make_unique<std::vector<T*>>(); + std::unique_ptr<std::vector<T*>> arrayObjects = + std::make_unique<std::vector<T*>>(); auto bins = m_binUtility->bins(0); arrayObjects->reserve(bins); for (size_t ill = 0; ill < bins; ++ill) { - arrayObjects->push_back(((*m_array)[ill]).get()); + arrayObjects->push_back((m_array[ill]).get()); } m_arrayObjects.set(std::move(arrayObjects)); } @@ -160,12 +173,15 @@ public: const BinUtility* binUtility() const { return (m_binUtility); } private: - std::vector<SharedObject<T>>* m_array; //!< vector of pointers to the class T - CxxUtils::CachedUniquePtr<std::vector<T*>> m_arrayObjects; //!< forced 1D vector of pointers to class T - BinUtility* m_binUtility; //!< binUtility for retrieving and filling the Array + //!< vector of pointers to the class T + std::vector<SharedObject<T>> m_array; + //!< forced 1D vector of pointers to class T + CxxUtils::CachedUniquePtr<std::vector<T*>> m_arrayObjects; + //!< binUtility for retrieving and filling the Array + BinUtility* m_binUtility; }; -template <class T> +template<class T> using BinnedArray1D = BinnedArray1DT<const T>; } // end of namespace Trk diff --git a/Tracking/TrkDetDescr/TrkDetDescrUtils/TrkDetDescrUtils/BinnedArrayArray.h b/Tracking/TrkDetDescr/TrkDetDescrUtils/TrkDetDescrUtils/BinnedArrayArray.h index 51a255e1aac6f3929ad35ae74d40944a47d4f18e..98eb72538f36747da6b93324f94308d8b9e26003 100644 --- a/Tracking/TrkDetDescr/TrkDetDescrUtils/TrkDetDescrUtils/BinnedArrayArray.h +++ b/Tracking/TrkDetDescr/TrkDetDescrUtils/TrkDetDescrUtils/BinnedArrayArray.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 */ /////////////////////////////////////////////////////////////////// @@ -39,7 +39,7 @@ public: /**Default Constructor */ BinnedArrayArrayT(const std::vector<std::pair<BinnedArrayT<T>*, Amg::Vector3D>>& tbas, BinUtility* bUtility) : m_binUtility(bUtility) - , m_binnedArrays(bUtility->bins(0), NULL) + , m_binnedArrays(bUtility->bins(0), nullptr) , m_arrayObjects() { // the array objects @@ -97,7 +97,7 @@ public: if (ba) return ba->object(lp); } - return 0; + return nullptr; } /** Returns the pointer to the templated class object from the BinnedArrayArrayT @@ -109,7 +109,7 @@ public: if (ba) return ba->object(gp); } - return 0; + return nullptr; } /** Returns the pointer to the templated class object from the BinnedArrayArrayT - entry point*/