Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:21:26

0001 #ifndef JetMETCorrections_FFTJetObjects_FFTJetDict_h
0002 #define JetMETCorrections_FFTJetObjects_FFTJetDict_h
0003 
0004 //
0005 // This template provides a variation of std::map with
0006 // subscripting operator which does not automatically
0007 // insert default values
0008 //
0009 // I. Volobouev
0010 // 08/03/2012
0011 
0012 #include <map>
0013 #include "FWCore/Utilities/interface/Exception.h"
0014 
0015 template <class Key, class T, class Compare = std::less<Key>, class Allocator = std::allocator<std::pair<const Key, T> > >
0016 struct FFTJetDict : public std::map<Key, T, Compare, Allocator> {
0017   inline T& operator[](const Key&);
0018   inline const T& operator[](const Key&) const;
0019 };
0020 
0021 template <class Key, class T, class Compare, class Allocator>
0022 T& FFTJetDict<Key, T, Compare, Allocator>::operator[](const Key& key) {
0023   typename FFTJetDict<Key, T, Compare, Allocator>::const_iterator it = this->find(key);
0024   if (it == std::map<Key, T, Compare, Allocator>::end())
0025     throw cms::Exception("KeyNotFound") << "FFTJetDict: key \"" << key << "\" not found\n";
0026   return const_cast<T&>(it->second);
0027 }
0028 
0029 template <class Key, class T, class Compare, class Allocator>
0030 const T& FFTJetDict<Key, T, Compare, Allocator>::operator[](const Key& key) const {
0031   typename FFTJetDict<Key, T, Compare, Allocator>::const_iterator it = this->find(key);
0032   if (it == std::map<Key, T, Compare, Allocator>::end())
0033     throw cms::Exception("KeyNotFound") << "FFTJetDict: key \"" << key << "\" not found\n";
0034   return it->second;
0035 }
0036 #endif  // JetMETCorrections_FFTJetObjects_FFTJetDict_h