Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:51:09

0001 #ifndef CondFormats_HcalObjects_HcalObjectAddons
0002 #define CondFormats_HcalObjects_HcalObjectAddons
0003 
0004 #include <vector>
0005 #include <algorithm>
0006 
0007 // functions with common forms
0008 namespace HcalObjectAddons {
0009   template <class Item, class Less>
0010   const Item* findByT(const Item* target, const std::vector<const Item*>& itemsByT) {
0011     Less less;
0012     auto item = std::lower_bound(itemsByT.begin(), itemsByT.end(), target, less);
0013     if (item == itemsByT.end() || !less.equal(*item, target)) {
0014       return nullptr;
0015     }
0016     return *item;
0017   }
0018 
0019   //sorting
0020   template <class Item, class Less>
0021   static void sortByT(const std::vector<Item>& items, std::vector<const Item*>& itemsByT) {
0022     itemsByT.clear();
0023     itemsByT.reserve(items.size());
0024     Less less;
0025     for (const auto& i : items) {
0026       if (less.good(i))
0027         itemsByT.push_back(&i);
0028     }
0029     std::sort(itemsByT.begin(), itemsByT.end(), less);
0030   }
0031 
0032 }  // namespace HcalObjectAddons
0033 
0034 #endif