Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:22:31

0001 #ifndef Grid3D_h
0002 #define Grid3D_h
0003 
0004 /** \class Grid3D
0005  *
0006  *  Implementation of a 3D regular grid.
0007  *
0008 *  \author T. Todorov
0009  */
0010 
0011 #include "DataFormats/GeometryVector/interface/Basic3DVector.h"
0012 // #include "DataFormats/Math/interface/SIMDVec.h"
0013 #include "Grid1D.h"
0014 #include <vector>
0015 #include "FWCore/Utilities/interface/Visibility.h"
0016 
0017 // the storage class
0018 // needed just because legacy software used () constructor
0019 struct BStorageArray {
0020   BStorageArray() {}
0021   BStorageArray(float x, float y, float z) : v{x, y, z} {}
0022 
0023   float const& operator[](int i) const { return v[i]; }
0024 
0025   float v[3];
0026 };
0027 
0028 class dso_internal Grid3D {
0029 public:
0030   // typedef double   Scalar;
0031   typedef float Scalar;
0032   typedef Basic3DVector<Scalar> ValueType;
0033   typedef ValueType ReturnType;
0034 
0035   using BVector = BStorageArray;
0036   //using BVector =  ValueType;
0037   using Container = std::vector<BVector>;
0038 
0039   Grid3D() {}
0040 
0041   Grid3D(const Grid1D& ga, const Grid1D& gb, const Grid1D& gc, std::vector<BVector>& data)
0042       : grida_(ga), gridb_(gb), gridc_(gc) {
0043     data_.swap(data);
0044     stride1_ = gridb_.nodes() * gridc_.nodes();
0045     stride2_ = gridc_.nodes();
0046   }
0047 
0048   //  Grid3D( const Grid1D& ga, const Grid1D& gb, const Grid1D& gc,
0049   //      std::vector<ValueType> const & data);
0050 
0051   int index(int i, int j, int k) const { return i * stride1_ + j * stride2_ + k; }
0052   int stride1() const { return stride1_; }
0053   int stride2() const { return stride2_; }
0054   int stride3() const { return 1; }
0055   ValueType operator()(int i) const { return ValueType(data_[i][0], data_[i][1], data_[i][2]); }
0056 
0057   ValueType operator()(int i, int j, int k) const { return (*this)(index(i, j, k)); }
0058 
0059   const Grid1D& grida() const { return grida_; }
0060   const Grid1D& gridb() const { return gridb_; }
0061   const Grid1D& gridc() const { return gridc_; }
0062 
0063   const Container& data() const { return data_; }
0064 
0065   void dump() const;
0066 
0067 private:
0068   Grid1D grida_;
0069   Grid1D gridb_;
0070   Grid1D gridc_;
0071 
0072   Container data_;
0073 
0074   int stride1_;
0075   int stride2_;
0076 };
0077 
0078 #endif