CMS 3D CMS Logo

EcalContainer.h

Go to the documentation of this file.
00001 #ifndef ECALDETID_ECALCONTAINER_H
00002 #define ECALDETID_ECALCONTAINER_H
00003 
00004 #include "DataFormats/DetId/interface/DetId.h"
00005 #include <vector>
00006 #include <utility>
00007 #include <algorithm>
00008 
00009 
00010 /* a generic container for ecal items
00011  * provides access by hashedIndex and by DetId...
00012  */
00013 
00014 template<typename DetId, typename T>
00015 class EcalContainer {
00016 
00017         public:
00018 
00019                 typedef EcalContainer<DetId, T> self;
00020                 typedef T Item;
00021                 typedef Item value_type;
00022                 typedef typename std::vector<Item> Items; 
00023                 typedef typename std::vector<Item>::const_iterator const_iterator;
00024                 typedef typename std::vector<Item>::iterator iterator;
00025 
00026                 void insert(std::pair<uint32_t, Item> const &a) {
00027                         (*this)[a.first] = a.second;
00028                 }
00029 
00030                 inline const Item & item(size_t hashid) const {
00031                         return m_items[hashid];
00032                 }
00033 
00034                 inline const Items & items() const {
00035                         return m_items;
00036                 }
00037 
00038                 inline Item & operator[](uint32_t rawId) {
00039                         if (m_items.empty()) {
00040                                 m_items.resize(DetId::SIZE_HASH);
00041                         }
00042                         static Item dummy;
00043                         DetId id(rawId);
00044                         if ( !isValidId(id) ) return dummy;
00045                         return m_items[id.hashedIndex()];
00046                 }
00047 
00048                 inline Item const & operator[](uint32_t rawId) const {
00049                         static Item dummy;
00050                         DetId id(rawId);
00051                         if ( !isValidId(id) ) return dummy;
00052                         return m_items[id.hashedIndex()];
00053                 }
00054 
00055                 inline const_iterator find(uint32_t rawId) const {
00056                         DetId ib(rawId);
00057                         if ( !isValidId(ib) ) return m_items.end();
00058                         return m_items.begin() + ib.hashedIndex();
00059                 }
00060 
00061                 inline const_iterator begin() const {
00062                         return m_items.begin();
00063                 }
00064 
00065                 inline const_iterator end() const {
00066                         return m_items.end();
00067                 }
00068 
00069                 inline size_t size() const {
00070                         return m_items.size();
00071                 }
00072 
00073         private:
00074 
00075                 // not protected on EB <--> EE swap -- FIXME?
00076                 inline bool isValidId(const DetId id) const {
00077                         return id.det() == ::DetId::Ecal;
00078                 };
00079 
00080                 std::vector<Item> m_items;
00081 
00082 };
00083 
00084 
00085 
00086 #endif // ECALCONTAINER

Generated on Tue Jun 9 17:30:41 2009 for CMSSW by  doxygen 1.5.4