CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/DataFormats/Common/src/DataFrameContainer.cc

Go to the documentation of this file.
00001 #include "DataFormats/Common/interface/DataFrameContainer.h"
00002 
00003 #include <boost/iterator/permutation_iterator.hpp>
00004 
00005 #include <algorithm>
00006 #include <numeric>
00007 #include <cstdlib>
00008 #include <cstring>
00009 
00010 namespace edm {
00011   namespace {
00012     struct TypeCompare {
00013        typedef DataFrameContainer::id_type id_type;
00014        std::vector<id_type> const& ids_;
00015        TypeCompare(std::vector<id_type> const& iType): ids_(iType) {}
00016         bool operator()(id_type const& iLHS, id_type const& iRHS) const {
00017           return ids_[iLHS] < ids_[iRHS];
00018         }
00019     };
00020   }
00021 
00022   void DataFrameContainer::sort() {
00023     if (size()<2) return;
00024     std::vector<int> indices(size(),1);
00025     indices[0]=0;
00026     std::partial_sum(indices.begin(),indices.end(),indices.begin());
00027     std::sort(indices.begin(), indices.end(), TypeCompare(m_ids));
00028     {
00029       IdContainer tmp(m_ids.size());
00030       std::copy(
00031                 boost::make_permutation_iterator( m_ids.begin(), indices.begin() ),
00032                 boost::make_permutation_iterator( m_ids.end(), indices.end() ),
00033                 tmp.begin());
00034       tmp.swap(m_ids);
00035     }
00036     {
00037       //      std::transform(indices.begin(),indices.end(),indices.begin(),
00038       //             boost::bind(std::multiplies<int>(),m_stride,_1));
00039       DataContainer tmp(m_data.size());
00040       size_type s = m_stride*sizeof(data_type);
00041       for(size_type j=0, i=0; i!=indices.size(); ++i, j+=m_stride)
00042         ::memcpy(&tmp[j], &m_data[indices[i]*m_stride], s);
00043       tmp.swap(m_data);
00044     }
00045     
00046   }
00047   
00048 }