CMS 3D CMS Logo

DataFrameContainer.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_DataFrameContainer_h
2 #define DataFormats_Common_DataFrameContainer_h
3 
6 
7 #include <boost/iterator/transform_iterator.hpp>
8 #include <boost/iterator/counting_iterator.hpp>
9 
10 #include <vector>
11 #include <algorithm>
12 #include <cstddef> // for size_t
13 #include <utility> // for pair
14 
15 class TestDataFrame;
16 
17 template <typename DigiCollection>
19 
20 namespace edm {
21 
34  public:
35  typedef unsigned int size_type; // for persistency
36  typedef unsigned int id_type;
37  typedef unsigned short data_type;
38  typedef std::vector<id_type> IdContainer;
39  typedef std::vector<data_type> DataContainer;
40  typedef std::vector<id_type>::iterator IdIter;
41  typedef std::vector<data_type>::iterator DataIter;
42  typedef std::pair<IdIter, DataIter> IterPair;
43  typedef std::vector<id_type>::const_iterator const_IdIter;
44  typedef std::vector<data_type>::const_iterator const_DataIter;
45  typedef std::pair<const_IdIter, const_DataIter> const_IterPair;
46 
47  struct IterHelp {
50 
51  DataFrame const& operator()(int i) const {
52  frame.set(v, i);
53  return frame;
54  }
55 
56  private:
59  };
60 
61  typedef boost::transform_iterator<IterHelp, boost::counting_iterator<int> > const_iterator;
62 
64 
65  explicit DataFrameContainer(size_t istride, int isubdet = 0, size_t isize = 0)
66  : m_subdetId(isubdet), m_stride(istride), m_ids(isize), m_data(isize * m_stride) {}
67 
71  m_ids.swap(rh.m_ids);
72  m_data.swap(rh.m_data);
73  }
74 
77  this->swap(temp);
78  return *this;
79  }
80 
81  void swap(IdContainer& iic, DataContainer& idc) {
82  m_ids.swap(iic);
83  m_data.swap(idc);
84  }
85 
86  void reserve(size_t isize) {
87  m_ids.reserve(isize);
88  m_data.reserve(isize * m_stride);
89  }
90 
91  void resize(size_t isize) {
92  m_ids.resize(isize);
93  m_data.resize(isize * m_stride);
94  }
95 
96  void sort();
97 
98  // FIXME not sure what the best way to add one cell to cont
99  void push_back(id_type iid, data_type const* idata) {
100  m_ids.push_back(iid);
101  size_t cs = m_data.size();
102  m_data.resize(m_data.size() + m_stride);
103  std::copy(idata, idata + m_stride, m_data.begin() + cs);
104  }
105  //make space for it
106  void push_back(id_type iid) {
107  m_ids.push_back(iid);
108  m_data.resize(m_data.size() + m_stride);
109  }
110  // overwrite back (very ad hoc interface...)
111  void set_back(id_type iid, data_type const* idata) {
112  m_ids.back() = iid;
113  size_t cs = m_data.size() - m_stride;
114  std::copy(idata, idata + m_stride, m_data.begin() + cs);
115  }
116  void set_back(id_type iid) { m_ids.back() = iid; }
117  void set_back(data_type const* idata) {
118  size_t cs = m_data.size() - m_stride;
119  std::copy(idata, idata + m_stride, m_data.begin() + cs);
120  }
121 
122  DataFrame back() { return DataFrame(*this, size() - 1); }
123 
124  void pop_back() {
125  m_ids.resize(m_ids.size() - 1);
126  m_data.resize(m_data.size() - m_stride);
127  }
128 
129  //---------------------------------------------------------
130 
131  IterPair pair(size_t i) { return IterPair(m_ids.begin() + i, m_data.begin() + i * m_stride); }
132 
133  const_IterPair pair(size_t i) const { return const_IterPair(m_ids.begin() + i, m_data.begin() + i * m_stride); }
134 
135  DataFrame operator[](size_t i) { return DataFrame(*this, i); }
136 
137  DataFrame operator[](size_t i) const { return DataFrame(*this, i); }
138 
142  const_IdIter p = std::lower_bound(m_ids.begin(), m_ids.end(), i);
143  return (p == m_ids.end() || (*p) != i)
144  ? end()
145  : boost::make_transform_iterator(boost::counting_iterator<int>(p - m_ids.begin()), IterHelp(*this));
146  }
147 
150  return boost::make_transform_iterator(boost::counting_iterator<int>(0), IterHelp(*this));
151  }
152  const_iterator end() const {
153  return boost::make_transform_iterator(boost::counting_iterator<int>(size()), IterHelp(*this));
154  }
155 
156  int subdetId() const { return m_subdetId; }
157 
158  size_type stride() const { return m_stride; }
159 
160  bool empty() const { return m_ids.empty(); }
161 
162  size_type size() const { return m_ids.size(); }
163 
164  data_type operator()(size_t cell, size_t frame) const { return m_data[cell * m_stride + frame]; }
165 
166  data_type const* frame(size_t cell) const { return &m_data[cell * m_stride]; }
167 
168  id_type id(size_t cell) const { return m_ids[cell]; }
169 
170  IdContainer const& ids() const { return m_ids; }
171  DataContainer const& data() const { return m_data; }
172 
173  private:
174  //for testing
175  friend class ::TestDataFrame;
176 
177  template <typename DigiCollection>
178  friend class ::TestEcalDigi;
179 
180  // subdetector id (as returned by DetId::subdetId())
182 
183  // can be a enumerator, or a template argument
185 
188  };
189 
191  : m_id(icont.id(i)), m_data(icont.frame(i)), m_size(icont.stride()) {}
192 
193  inline void DataFrame::set(DataFrameContainer const& icont, size_type i) {
194  m_id = icont.id(i);
195  m_data = icont.frame(i);
196  m_size = icont.stride();
197  }
198 
199  // Free swap function
200  inline void swap(DataFrameContainer& lhs, DataFrameContainer& rhs) { lhs.swap(rhs); }
201 
202 } // namespace edm
203 
204 // The standard allows us to specialize std::swap for non-templates.
205 // This ensures that DataFrameContainer::swap() will be used in algorithms.
206 
207 namespace std {
208  template <>
210  lhs.swap(rhs);
211  }
212 } // namespace std
213 
214 #endif // DataFormats_Common_DataFrameContainer_h
edm::DataFrameContainer::m_data
DataContainer m_data
Definition: DataFrameContainer.h:187
TestEcalDigi
Definition: DataFrameContainer.h:18
edm::DataFrameContainer::IterPair
std::pair< IdIter, DataIter > IterPair
Definition: DataFrameContainer.h:42
mps_fire.i
i
Definition: mps_fire.py:428
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
edm::DataFrameContainer::const_iterator
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
Definition: DataFrameContainer.h:61
edm::DataFrame::set
void set(DataFrameContainer const &icont, size_type i)
Definition: DataFrameContainer.h:193
edm::DataFrameContainer::IdContainer
std::vector< id_type > IdContainer
Definition: DataFrameContainer.h:38
edm::DataFrameContainer::sort
void sort()
Definition: DataFrameContainer.cc:19
fwrapper::cs
unique_ptr< ClusterSequence > cs
Definition: fastjetfortran_madfks.cc:47
edm
HLT enums.
Definition: AlignableModifier.h:19
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
gpuVertexFinder::iv
int32_t *__restrict__ iv
Definition: gpuClusterTracksDBSCAN.h:42
edm::swap
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:117
edm::DataFrameContainer::subdetId
int subdetId() const
Definition: DataFrameContainer.h:156
edm::DataFrameContainer::DataIter
std::vector< data_type >::iterator DataIter
Definition: DataFrameContainer.h:41
edm::DataFrameContainer::pair
IterPair pair(size_t i)
Definition: DataFrameContainer.h:131
edm::DataFrameContainer::pop_back
void pop_back()
Definition: DataFrameContainer.h:124
edm::DataFrameContainer::const_IterPair
std::pair< const_IdIter, const_DataIter > const_IterPair
Definition: DataFrameContainer.h:45
edm::DataFrameContainer::set_back
void set_back(id_type iid, data_type const *idata)
Definition: DataFrameContainer.h:111
edm::DataFrameContainer::set_back
void set_back(id_type iid)
Definition: DataFrameContainer.h:116
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
CMS_SA_ALLOW
#define CMS_SA_ALLOW
Definition: thread_safety_macros.h:5
edm::DataFrameContainer::m_subdetId
int m_subdetId
Definition: DataFrameContainer.h:181
edm::DataFrameContainer::IterHelp::IterHelp
IterHelp(DataFrameContainer const &iv)
Definition: DataFrameContainer.h:49
edm::DataFrameContainer::back
DataFrame back()
Definition: DataFrameContainer.h:122
edm::DataFrameContainer::operator[]
DataFrame operator[](size_t i) const
Definition: DataFrameContainer.h:137
edm::DataFrameContainer::IterHelp::operator()
DataFrame const & operator()(int i) const
Definition: DataFrameContainer.h:51
edm::DataFrameContainer::operator[]
DataFrame operator[](size_t i)
Definition: DataFrameContainer.h:135
edm::DataFrameContainer::frame
data_type const * frame(size_t cell) const
Definition: DataFrameContainer.h:166
edm::DataFrameContainer::ids
IdContainer const & ids() const
Definition: DataFrameContainer.h:170
std::swap
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Definition: DataFrameContainer.h:209
edm::DataFrame::m_data
const data_type * m_data
Definition: DataFrame.h:52
edm::DataFrameContainer::IterHelp::frame
DataFrame frame
Definition: DataFrameContainer.h:58
edm::DataFrameContainer::empty
bool empty() const
Definition: DataFrameContainer.h:160
edm::DataFrameContainer::pair
const_IterPair pair(size_t i) const
Definition: DataFrameContainer.h:133
edm::DataFrameContainer::const_IdIter
std::vector< id_type >::const_iterator const_IdIter
Definition: DataFrameContainer.h:43
edm::DataFrameContainer::operator=
DataFrameContainer & operator=(DataFrameContainer const &rhs)
Definition: DataFrameContainer.h:75
edm::DataFrameContainer::DataContainer
std::vector< data_type > DataContainer
Definition: DataFrameContainer.h:39
edm::DataFrameContainer::IdIter
std::vector< id_type >::iterator IdIter
Definition: DataFrameContainer.h:40
edm::DataFrameContainer::id_type
unsigned int id_type
Definition: DataFrameContainer.h:36
edm::DataFrameContainer::reserve
void reserve(size_t isize)
Definition: DataFrameContainer.h:86
edm::DataFrame::size_type
unsigned int size_type
Definition: DataFrame.h:17
edm::DataFrameContainer::swap
void swap(DataFrameContainer &rh)
Definition: DataFrameContainer.h:68
DataFrame.h
pfDeepBoostedJetPreprocessParams_cfi.lower_bound
lower_bound
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:15
edm::DataFrameContainer::m_ids
IdContainer m_ids
Definition: DataFrameContainer.h:186
edm::DataFrameContainer::stride
size_type stride() const
Definition: DataFrameContainer.h:158
edm::DataFrameContainer::id
id_type id(size_t cell) const
Definition: DataFrameContainer.h:168
thread_safety_macros.h
edm::DataFrameContainer::IterHelp
Definition: DataFrameContainer.h:47
edm::DataFrame::m_id
id_type m_id
Definition: DataFrame.h:51
edm::DataFrameContainer::begin
const_iterator begin() const
The iterator returned can not safely be used across threads.
Definition: DataFrameContainer.h:149
edm::DataFrameContainer::find
const_iterator find(id_type i) const
Definition: DataFrameContainer.h:141
edm::DataFrameContainer::swap
void swap(IdContainer &iic, DataContainer &idc)
Definition: DataFrameContainer.h:81
edm::DataFrameContainer::set_back
void set_back(data_type const *idata)
Definition: DataFrameContainer.h:117
edm::DataFrameContainer::data_type
unsigned short data_type
Definition: DataFrameContainer.h:37
edm::DataFrame
Definition: DataFrame.h:15
edm::DataFrameContainer::push_back
void push_back(id_type iid)
Definition: DataFrameContainer.h:106
edm::DataFrameContainer::DataFrameContainer
DataFrameContainer()
Definition: DataFrameContainer.h:63
edm::DataFrameContainer::operator()
data_type operator()(size_t cell, size_t frame) const
Definition: DataFrameContainer.h:164
std
Definition: JetResolutionObject.h:76
edm::DataFrameContainer::data
DataContainer const & data() const
Definition: DataFrameContainer.h:171
edm::DataFrameContainer::DataFrameContainer
DataFrameContainer(size_t istride, int isubdet=0, size_t isize=0)
Definition: DataFrameContainer.h:65
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
amptDefault_cfi.frame
frame
Definition: amptDefault_cfi.py:12
edm::DataFrameContainer::IterHelp::result_type
DataFrame result_type
Definition: DataFrameContainer.h:48
edm::DataFrameContainer::push_back
void push_back(id_type iid, data_type const *idata)
Definition: DataFrameContainer.h:99
edm::DataFrame::DataFrame
constexpr DataFrame()
Definition: DataFrame.h:23
edm::DataFrameContainer::size_type
unsigned int size_type
Definition: DataFrameContainer.h:35
edm::DataFrameContainer::m_stride
size_type m_stride
Definition: DataFrameContainer.h:184
edm::DataFrameContainer
Definition: DataFrameContainer.h:33
edm::DataFrameContainer::IterHelp::v
DataFrameContainer const & v
Definition: DataFrameContainer.h:57
edm::DataFrameContainer::resize
void resize(size_t isize)
Definition: DataFrameContainer.h:91
edm::DataFrameContainer::end
const_iterator end() const
Definition: DataFrameContainer.h:152
edm::DataFrame::m_size
size_type m_size
Definition: DataFrame.h:53
edm::DataFrameContainer::const_DataIter
std::vector< data_type >::const_iterator const_DataIter
Definition: DataFrameContainer.h:44
gpuPixelDoublets::stride
auto stride
Definition: gpuPixelDoubletsAlgos.h:80
edm::DataFrameContainer::size
size_type size() const
Definition: DataFrameContainer.h:162