CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/SimCalorimetry/CaloSimAlgos/interface/CaloDigiCollectionSorter.h

Go to the documentation of this file.
00001 #ifndef CaloDigiCollectionSorter_h
00002 #define CaloDigiCollectionSorter_h
00003 
00012 #include <vector>
00013 #include <algorithm>
00014 #include "DataFormats/Common/interface/SortedCollection.h"
00015 
00016 
00017 class CaloDigiCollectionSorter {
00018 public:
00019   CaloDigiCollectionSorter(int bin) : theMaxBin(bin) {}
00020 
00022   template<class T>
00023   class CaloDigiSortByMaxBin {
00024   public:
00025     CaloDigiSortByMaxBin(int bin) : theMaxBin(bin) {}
00026 
00027     bool operator()(const T & df1, const T & df2) const {
00028        // should work for HcalQIESamples & EcalMPGASamples
00029        // sort in reverse order, so highest bins come first
00030        return (df1[theMaxBin].raw() > df2[theMaxBin].raw());
00031     }
00032 
00033   private:
00034     int theMaxBin;
00035   };
00036 
00039   template<class T>
00040   std::vector<T> sortedVector(const edm::SortedCollection<T> & input) const {
00041      std::vector<T> result;
00042      result.reserve(input.size());
00043      for(unsigned int i = 0; i < input.size() ; ++i) 
00044      {
00045        result.push_back(input[i]);
00046      }
00047      // now sort
00048      std::sort(result.begin(), result.end(), CaloDigiSortByMaxBin<T>(theMaxBin));
00049      return result;
00050   }
00051 
00052 private:
00053   int theMaxBin;
00054 };
00055 
00056 #endif
00057