Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-19 09:23:32

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2021 CERN for the benefit of the Acts project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include "Acts/Utilities/Logger.hpp"
0012 
0013 #include <sstream>
0014 #include <stdexcept>
0015 #include <vector>
0016 
0017 template <typename T>
0018 class MultiIndexedVector2D {
0019  private:
0020   std::size_t m_d1, m_d2;
0021   std::vector<T> m_data;
0022 
0023   /// Private access to the logging instance
0024   const Acts::Logger& logger() const { return *m_logger; }
0025 
0026   /// the logging instance
0027   std::unique_ptr<const Acts::Logger> m_logger;
0028 
0029  public:
0030   MultiIndexedVector2D() : m_d1(0), m_d2(0) {
0031     m_logger = Acts::getDefaultLogger("HoughVectors", Acts::Logging::ERROR);
0032   }
0033 
0034   MultiIndexedVector2D(std::size_t d1, std::size_t d2, T const& t = T())
0035       : m_d1(d1), m_d2(d2), m_data(d1 * d2, t) {
0036     m_logger = Acts::getDefaultLogger("HoughVectors", Acts::Logging::ERROR);
0037   }
0038 
0039   std::size_t size(int dim) const {
0040     if (dim == 0) {
0041       return m_d1;
0042     }
0043     if (dim == 1) {
0044       return m_d2;
0045     } else {
0046       ACTS_ERROR("MultiIndexedVector2D: Argument to size() must be 0 or 1");
0047       return 0;
0048     }
0049   }
0050 
0051   void resize(std::size_t x1, std::size_t x2, T const& t = T()) {
0052     m_d1 = x1;
0053     m_d2 = x2;
0054     m_data.resize(x1 * x2, t);
0055   }
0056 
0057   T& operator()(std::size_t i, std::size_t j) {
0058     if (i >= m_d1 || j >= m_d2) {
0059       std::stringstream s;
0060       s << "MultiIndexedVector2D out of bounds: request (" << i << "," << j
0061         << ") size (" << m_d1 << "," << m_d2 << ")";
0062       ACTS_ERROR(s.str());
0063     }
0064     return m_data[i * m_d2 + j];
0065   }
0066   inline T& operator()(std::pair<std::size_t, std::size_t> indices) {
0067     return operator()(indices.first, indices.second);
0068   }
0069 
0070   T const& operator()(std::size_t i, std::size_t j) const {
0071     if (i >= m_d1 || j >= m_d2) {
0072       std::stringstream s;
0073       s << "MultiIndexedVector2D out of bounds: request (" << i << "," << j
0074         << ") size (" << m_d1 << "," << m_d2 << ")";
0075       ACTS_ERROR(s.str());
0076     }
0077     return m_data[i * m_d2 + j];
0078   }
0079   inline T const& operator()(
0080       std::pair<std::size_t, std::size_t> indices) const {
0081     return operator()(indices.first, indices.second);
0082   }
0083 
0084   T* operator[](std::size_t i) {
0085     if (i >= m_d1) {
0086       std::stringstream s;
0087       s << "MultiIndexedVector2D out of bounds: request " << i << " size ("
0088         << m_d1 << "," << m_d2 << ")";
0089       ACTS_ERROR(s.str());
0090     }
0091     return m_data.data() + (i * m_d2);
0092   }
0093 
0094   const T* operator[](std::size_t i) const {
0095     if (i >= m_d1) {
0096       std::stringstream s;
0097       s << "MultiIndexedVector2D out of bounds: request " << i << " size ("
0098         << m_d1 << "," << m_d2 << ")";
0099       ACTS_ERROR(s.str());
0100     }
0101     return m_data.data() + (i * m_d2);
0102   }
0103 
0104   void reset(const T& t) { m_data.assign(m_data.size(), t); }
0105 
0106   T* data() { return m_data.data(); }
0107 
0108   const T* data() const { return m_data.data(); }
0109 };
0110 
0111 template <typename T>
0112 class MultiIndexedVector3D {
0113  private:
0114   std::size_t m_d1, m_d2, m_d3;
0115   std::vector<T> m_data;
0116   /// Private access to the logging instance
0117   const Acts::Logger& logger() const { return *m_logger; }
0118 
0119   /// the logging instance
0120   std::unique_ptr<const Acts::Logger> m_logger;
0121 
0122  public:
0123   MultiIndexedVector3D() : m_d1(0), m_d2(0), m_d3(0) {
0124     m_logger = Acts::getDefaultLogger("HoughVectors", Acts::Logging::ERROR);
0125   }
0126 
0127   MultiIndexedVector3D(std::size_t d1, std::size_t d2, std::size_t d3,
0128                        T const& t = T())
0129       : m_d1(d1), m_d2(d2), m_d3(d3), m_data(d1 * d2 * d3, t) {
0130     m_logger = Acts::getDefaultLogger("HoughVectors", Acts::Logging::ERROR);
0131   }
0132 
0133   T& operator()(std::size_t i, std::size_t j, std::size_t k) {
0134     if (i >= m_d1 || j >= m_d2 || k >= m_d3) {
0135       std::stringstream s;
0136       s << "MultiIndexedVector3D out of bounds: request (" << i << "," << j
0137         << "," << k << ") size (" << m_d1 << "," << m_d2 << "," << m_d3 << ")";
0138       ACTS_ERROR(s.str());
0139     }
0140     return m_data[i * m_d2 * m_d3 + j * m_d3 + k];
0141   }
0142 
0143   T const& operator()(std::size_t i, std::size_t j, std::size_t k) const {
0144     if (i >= m_d1 || j >= m_d2 || k >= m_d3) {
0145       std::stringstream s;
0146       s << "MultiIndexedVector3D out of bounds: request (" << i << "," << j
0147         << "," << k << ") size (" << m_d1 << "," << m_d2 << "," << m_d3 << ")";
0148       ACTS_ERROR(s.str());
0149     }
0150     return m_data[i * m_d2 * m_d3 + j * m_d3 + k];
0151   }
0152 
0153   void resize(std::size_t x1, std::size_t x2, std::size_t x3,
0154               T const& t = T()) {
0155     m_d1 = x1;
0156     m_d2 = x2;
0157     m_d3 = x3;
0158     m_data.resize(x1 * x2 * x3, t);
0159   }
0160 
0161   T* data() { return m_data.data(); }
0162 };