CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/DataFormats/Common/interface/ContainerMask.h

Go to the documentation of this file.
00001 #ifndef DataFormats_Common_ContainerMask_h
00002 #define DataFormats_Common_ContainerMask_h
00003 // -*- C++ -*-
00004 //
00005 // Package:     Common
00006 // Class  :     ContainerMask
00007 // 
00017 //
00018 // Original Author:  
00019 //         Created:  Fri Sep 23 17:05:43 CDT 2011
00020 // $Id: ContainerMask.h,v 1.1 2011/12/01 13:02:17 vlimant Exp $
00021 //
00022 
00023 // system include files
00024 #include <vector>
00025 #include <cassert>
00026 #include <algorithm>
00027 
00028 // user include files
00029 #include "DataFormats/Common/interface/RefProd.h"
00030 #include "DataFormats/Common/interface/ContainerMaskTraits.h"
00031 #include "DataFormats/Common/interface/CMS_CLASS_VERSION.h"
00032 
00033 // forward declarations
00034 namespace edm {
00035    template< typename T>
00036    class ContainerMask {
00037 
00038    public:
00039       ContainerMask() {}
00040       ContainerMask(const edm::RefProd<T>& iProd, const std::vector<bool>& iMask);
00041       //virtual ~ContainerMask();
00042 
00043       // ---------- const member functions ---------------------
00044         bool mask(unsigned int iIndex) const {
00045          assert(iIndex<m_mask.size());
00046          return m_mask[iIndex];
00047         }
00048         bool mask(const typename ContainerMaskTraits<T>::value_type *);
00049         void applyOrTo( std::vector<bool>&) const;
00050         void copyMaskTo( std::vector<bool>&) const;
00051 
00052 
00053       size_t size() const { return m_mask.size();}
00054 
00055       const edm::RefProd<T>& refProd() const {return m_prod;}
00056       // ---------- static member functions --------------------
00057 
00058       // ---------- member functions ---------------------------
00059       void swap(ContainerMask<T>& iOther);
00060 
00061       //Used by ROOT storage
00062       CMS_CLASS_VERSION(10)
00063       
00064    private:
00065       //ContainerMask(const ContainerMask&); // stop default
00066 
00067       //const ContainerMask& operator=(const ContainerMask&); // stop default
00068 
00069       // ---------- member data --------------------------------
00070       edm::RefProd<T> m_prod;
00071       std::vector<bool> m_mask;
00072    };
00073 
00074    template<typename T>
00075    ContainerMask<T>::ContainerMask(const edm::RefProd<T>& iProd, const std::vector<bool>& iMask):
00076    m_prod(iProd), m_mask(iMask) {
00077       assert(iMask.size() == ContainerMaskTraits<T>::size(m_prod.product()));
00078    }
00079    
00080    
00081    template<typename T>
00082    bool ContainerMask<T>::mask(const typename ContainerMaskTraits<T>::value_type * iElement )
00083    {
00084       unsigned int index = ContainerMaskTraits<T>::indexFor(iElement,m_prod.product());
00085       return this->mask(index);
00086    }
00087    
00088    template<typename T>
00089    void ContainerMask<T>::copyMaskTo(std::vector<bool>& iTo) const {
00090       iTo.assign(m_mask.begin(),m_mask.end());
00091    }
00092    
00093    template<typename T>
00094    void ContainerMask<T>::applyOrTo(std::vector<bool>& iTo) const {
00095       assert(iTo.size()==m_mask.size());
00096       std::transform(m_mask.begin(),m_mask.end(),iTo.begin(), iTo.begin(),std::logical_or<bool>());
00097    }
00098    
00099    template<typename T>
00100    void ContainerMask<T>::swap(ContainerMask<T>& iOther) {
00101       m_prod.swap(iOther.m_prod);
00102       std::swap(m_mask,iOther.m_mask);
00103    }
00104 }
00105 
00106 #endif