CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
gridConverters.h
Go to the documentation of this file.
1 //=========================================================================
2 // gridConverters.h
3 //
4 // Utility functions for combining Grid2d objects templated on different
5 // types
6 //
7 // I. Volobouev
8 // June 2011
9 //=========================================================================
10 
11 #ifndef RecoJets_FFTJetAlgorithms_gridConverters_h
12 #define RecoJets_FFTJetAlgorithms_gridConverters_h
13 
14 #include <cassert>
15 #include "fftjet/Grid2d.hh"
16 
17 namespace fftjetcms {
18  template<typename Numeric>
19  fftjet::Grid2d<float>* convert_Grid2d_to_float(
20  const fftjet::Grid2d<Numeric>& grid);
21 
22  template<typename Numeric>
23  fftjet::Grid2d<double>* convert_Grid2d_to_double(
24  const fftjet::Grid2d<Numeric>& grid);
25 
26  template<typename F1, typename F2>
27  void copy_Grid2d_data(
28  fftjet::Grid2d<F2>* to, const fftjet::Grid2d<F1>& from);
29 
30  template<typename F1, typename F2>
31  void add_Grid2d_data(
32  fftjet::Grid2d<F2>* to, const fftjet::Grid2d<F1>& from);
33 }
34 
36 //
37 // Implementation follows
38 //
40 
41 namespace fftjetcms {
42  template<typename F1, typename F2>
44  fftjet::Grid2d<F2>* to, const fftjet::Grid2d<F1>& from)
45  {
46  assert(to);
47  assert(from.nEta() == to->nEta());
48  assert(from.nPhi() == to->nPhi());
49  const unsigned len = from.nEta()*from.nPhi();
50  const F1* fromData = from.data();
51  F2* toData = const_cast<F2*>(to->data());
52  for (unsigned i=0; i<len; ++i)
53  toData[i] = fromData[i];
54  }
55 
56  template<typename F1, typename F2>
58  fftjet::Grid2d<F2>* to, const fftjet::Grid2d<F1>& from)
59  {
60  assert(to);
61  assert(from.nEta() == to->nEta());
62  assert(from.nPhi() == to->nPhi());
63  const unsigned len = from.nEta()*from.nPhi();
64  const F1* fromData = from.data();
65  F2* toData = const_cast<F2*>(to->data());
66  for (unsigned i=0; i<len; ++i)
67  toData[i] += fromData[i];
68  }
69 
70  template<typename Numeric>
71  fftjet::Grid2d<float>* convert_Grid2d_to_float(
72  const fftjet::Grid2d<Numeric>& grid)
73  {
74  fftjet::Grid2d<float>* to = new fftjet::Grid2d<float>(
75  grid.nEta(), grid.etaMin(), grid.etaMax(),
76  grid.nPhi(), grid.phiBin0Edge(), grid.title());
77  copy_Grid2d_data(to, grid);
78  return to;
79  }
80 
81  template<typename Numeric>
82  fftjet::Grid2d<double>* convert_Grid2d_to_double(
83  const fftjet::Grid2d<Numeric>& grid)
84  {
85  fftjet::Grid2d<double>* to = new fftjet::Grid2d<double>(
86  grid.nEta(), grid.etaMin(), grid.etaMax(),
87  grid.nPhi(), grid.phiBin0Edge(), grid.title());
88  copy_Grid2d_data(to, grid);
89  return to;
90  }
91 }
92 
93 #endif // RecoJets_FFTJetAlgorithms_gridConverters_h
int i
Definition: DBlmapReader.cc:9
fftjet::Grid2d< float > * convert_Grid2d_to_float(const fftjet::Grid2d< Numeric > &grid)
assert(m_qm.get())
void copy_Grid2d_data(fftjet::Grid2d< F2 > *to, const fftjet::Grid2d< F1 > &from)
fftjet::Grid2d< double > * convert_Grid2d_to_double(const fftjet::Grid2d< Numeric > &grid)
void add_Grid2d_data(fftjet::Grid2d< F2 > *to, const fftjet::Grid2d< F1 > &from)