File indexing completed on 2024-04-06 12:03:55
0001 #include "DataFormats/Common/interface/DataFrameContainer.h"
0002
0003 #include <boost/iterator/permutation_iterator.hpp>
0004
0005 #include <algorithm>
0006 #include <numeric>
0007 #include <cstring>
0008
0009 namespace edm {
0010 namespace {
0011 struct TypeCompare {
0012 typedef DataFrameContainer::id_type id_type;
0013 std::vector<id_type> const& ids_;
0014 TypeCompare(std::vector<id_type> const& iType) : ids_(iType) {}
0015 bool operator()(id_type const& iLHS, id_type const& iRHS) const { return ids_[iLHS] < ids_[iRHS]; }
0016 };
0017 }
0018
0019 void DataFrameContainer::sort() {
0020 if (size() < 2)
0021 return;
0022 std::vector<int> indices(size(), 1);
0023 indices[0] = 0;
0024 std::partial_sum(indices.begin(), indices.end(), indices.begin());
0025 std::sort(indices.begin(), indices.end(), TypeCompare(m_ids));
0026 {
0027 IdContainer tmp(m_ids.size());
0028 std::copy(boost::make_permutation_iterator(m_ids.begin(), indices.begin()),
0029 boost::make_permutation_iterator(m_ids.end(), indices.end()),
0030 tmp.begin());
0031 tmp.swap(m_ids);
0032 }
0033 {
0034
0035
0036 DataContainer tmp(m_data.size());
0037 size_type s = m_stride * sizeof(data_type);
0038 for (size_type j = 0, i = 0; i != indices.size(); ++i, j += m_stride)
0039 ::memcpy(&tmp[j], &m_data[indices[i] * m_stride], s);
0040 tmp.swap(m_data);
0041 }
0042 }
0043
0044 }