Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:35:38

0001 #ifndef ECAL_CONDTOWER_OBJECT_CONTAINER_HH
0002 #define ECAL_CONDTOWER_OBJECT_CONTAINER_HH
0003 
0004 #include "CondFormats/Serialization/interface/Serializable.h"
0005 
0006 #include "DataFormats/EcalDetId/interface/EcalContainer.h"
0007 #include "DataFormats/EcalDetId/interface/EcalTrigTowerDetId.h"
0008 #include "DataFormats/EcalDetId/interface/EcalScDetId.h"
0009 
0010 // #include <cstdio>
0011 
0012 template <typename T>
0013 class EcalCondTowerObjectContainer {
0014 public:
0015   typedef T Item;
0016   typedef Item value_type;
0017   typedef EcalCondTowerObjectContainer<T> self;
0018   typedef typename std::vector<Item> Items;
0019   typedef typename std::vector<Item>::const_iterator const_iterator;
0020   typedef typename std::vector<Item>::iterator iterator;
0021 
0022   EcalCondTowerObjectContainer() {
0023     size_t ebsize = (size_t)EcalTrigTowerDetId::kEBTowersPerSM * 18 * 2;
0024     eb_.checkAndResize(ebsize);
0025     size_t eesize = (size_t)632;
0026     ee_.checkAndResize(eesize);
0027   };
0028   ~EcalCondTowerObjectContainer() {}
0029 
0030   inline const Items &barrelItems() const { return eb_.items(); };
0031 
0032   inline const Items &endcapItems() const { return ee_.items(); };
0033 
0034   inline const Item &barrel(size_t hashedIndex) const { return eb_.item(hashedIndex); }
0035 
0036   inline const Item &endcap(size_t hashedIndex) const { return ee_.item(hashedIndex); }
0037 
0038   inline void insert(std::pair<uint32_t, Item> const &a) {
0039     DetId id(a.first);
0040     if (id.subdetId() == EcalBarrel || id.subdetId() == EcalTriggerTower) {
0041       eb_.insert(a);
0042     } else if (id.subdetId() == EcalEndcap) {
0043       ee_.insert(a);
0044     } else {
0045       //            std::cout <<"*** ERROR it is not barrel nor endcap tower"<< std::endl;
0046     }
0047   }
0048 
0049   inline const_iterator find(uint32_t rawId) const {
0050     DetId id(rawId);
0051     if (id.subdetId() == EcalBarrel || id.subdetId() == EcalTriggerTower) {
0052       const_iterator it = eb_.find(rawId);
0053       if (it != eb_.end()) {
0054         return it;
0055       } else {
0056         return ee_.end();
0057       }
0058     } else if (id.subdetId() == EcalEndcap) {
0059       return ee_.find(rawId);
0060     } else {
0061       return ee_.end();
0062     }
0063   }
0064 
0065   inline const_iterator begin() const { return eb_.begin(); }
0066 
0067   inline const_iterator end() const { return ee_.end(); }
0068 
0069   inline void setValue(const uint32_t id, const Item &item) { (*this)[id] = item; }
0070 
0071   inline const self &getMap() const { return *this; }
0072 
0073   inline size_t size() const { return eb_.size() + ee_.size(); }
0074   // add coherent operator++, not needed now -- FIXME
0075 
0076   inline Item &operator[](uint32_t rawId) {
0077     DetId id(rawId);
0078     return ((id.subdetId() == EcalBarrel) || (id.subdetId() == EcalTriggerTower)) ? eb_[rawId] : ee_[rawId];
0079   }
0080 
0081   inline Item operator[](uint32_t rawId) const {
0082     DetId id(rawId);
0083 
0084     if (id.subdetId() == EcalBarrel || id.subdetId() == EcalTriggerTower) {
0085       return eb_[rawId];
0086     } else if (id.subdetId() == EcalEndcap) {
0087       return ee_[rawId];
0088     } else {
0089       return Item();
0090     }
0091   }
0092 
0093 private:
0094   EcalContainer<EcalTrigTowerDetId, Item> eb_;
0095   EcalContainer<EcalScDetId, Item> ee_;
0096 
0097   COND_SERIALIZABLE;
0098 };
0099 
0100 typedef EcalCondTowerObjectContainer<float> EcalTowerFloatCondObjectContainer;
0101 #endif