CMS 3D CMS Logo

Functions
precomputed_value_sort.h File Reference
#include <vector>
#include <algorithm>
#include <functional>

Go to the source code of this file.

Functions

template<class RandomAccessIterator , class Extractor , class Compare >
void precomputed_value_sort (RandomAccessIterator begin, RandomAccessIterator end, const Extractor &extr, const Compare &comp)
 
template<class RandomAccessIterator , class Extractor >
void precomputed_value_sort (RandomAccessIterator begin, RandomAccessIterator end, const Extractor &extr)
 

Detailed Description

Sort using precomputed values.

precomputed_value_sort behaves like std::sort, but pre-computes the values used in the sorting using an Extractor, so that the computation is performed only once per element.

Definition in file precomputed_value_sort.h.

Function Documentation

template<class RandomAccessIterator , class Extractor , class Compare >
void precomputed_value_sort ( RandomAccessIterator  begin,
RandomAccessIterator  end,
const Extractor &  extr,
const Compare &  comp 
)

Definition at line 17 of file precomputed_value_sort.h.

References a, b, AlCaHLTBitMon_QueryRunRegistry::comp, end, plotBeamSpotDB::first, mps_fire::i, eostools::move(), and jetUpdater_cfi::sort.

Referenced by MagGeoBuilderFromDDD::bLayer::bLayer(), MagGeoBuilderFromDDD::bRod::bRod(), MagGeoBuilderFromDDD::bSector::bSector(), MagGeoBuilderFromDDD::bSlab::bSlab(), MagGeoBuilderFromDDD::build(), MuonGEMDetLayerGeometryBuilder::buildLayer(), MuonME0DetLayerGeometryBuilder::buildLayer(), MuonRPCDetLayerGeometryBuilder::buildLayer(), MuonDTDetLayerGeometryBuilder::buildLayers(), BTLDetLayerGeometryBuilder::buildLayers(), MagGeoBuilderFromDDD::eLayer::eLayer(), MagGeoBuilderFromDDD::eSector::eSector(), ForwardDetRingOneZ::initialize(), DetRodOneR::initialize(), MuonRPCDetLayerGeometryBuilder::makeBarrelLayers(), MuonRPCDetLayerGeometryBuilder::makeBarrelRods(), ETLDetLayerGeometryBuilder::makeDetRing(), MuonCSCDetLayerGeometryBuilder::makeDetRing(), MuonGEMDetLayerGeometryBuilder::makeDetRing(), MuonME0DetLayerGeometryBuilder::makeDetRing(), MTDTrayBarrelLayer::MTDTrayBarrelLayer(), MuRodBarrelLayer::MuRodBarrelLayer(), PhiBorderFinder::PhiBorderFinder(), precomputed_value_sort(), RBorderFinder::RBorderFinder(), MTDDetLayerGeometry::sortLayers(), MuonDetLayerGeometry::sortLayers(), InOutConversionTrackFinder::tracks(), and OutInConversionTrackFinder::tracks().

19 {
21  using Scalar = decltype(extr(*begin));
22 
23  std::vector<std::pair<RandomAccessIterator,Scalar>> tmpvec;
24  tmpvec.reserve(end-begin);
25 
26  // tmpvec holds iterators - does not copy the real objects
27  for (RandomAccessIterator i=begin; i!=end; i++) tmpvec.emplace_back(i,extr(*i));
28 
29  std::sort(tmpvec.begin(), tmpvec.end(),[&comp](auto const& a, auto const& b){
30  return comp(a.second, b.second);
31  });
32 
33  // overwrite the input range with the sorted values
34  // copy of input container not necessary, but tricky to avoid
35  std::vector<Value> tmpcopy(begin,end);
36  for (unsigned int i=0; i < tmpvec.size(); i++) {
37  *(begin+i) = std::move(tmpcopy[tmpvec[i].first - begin]);
38  }
39 }
double Scalar
Definition: Definitions.h:27
reco::JetExtendedAssociation::JetExtendedData Value
#define end
Definition: vmac.h:39
double b
Definition: hdecay.h:120
#define begin
Definition: vmac.h:32
double a
Definition: hdecay.h:121
def move(src, dest)
Definition: eostools.py:511
template<class RandomAccessIterator , class Extractor >
void precomputed_value_sort ( RandomAccessIterator  begin,
RandomAccessIterator  end,
const Extractor &  extr 
)

Definition at line 42 of file precomputed_value_sort.h.

References precomputed_value_sort().

44 {
45  using Scalar = decltype(extr(*begin));
46  precomputed_value_sort(begin, end, extr, std::less<Scalar>());
47 }
double Scalar
Definition: Definitions.h:27
#define end
Definition: vmac.h:39
void precomputed_value_sort(RandomAccessIterator begin, RandomAccessIterator end, const Extractor &extr, const Compare &comp)
#define begin
Definition: vmac.h:32