CMS 3D CMS Logo

ContainerMask.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_ContainerMask_h
2 #define DataFormats_Common_ContainerMask_h
3 // -*- C++ -*-
4 //
5 // Package: Common
6 // Class : ContainerMask
7 //
17 //
18 // Original Author:
19 // Created: Fri Sep 23 17:05:43 CDT 2011
20 //
21 
22 // system include files
23 #include <vector>
24 #include <cassert>
25 #include <cstddef>
26 #include <algorithm>
27 
28 // user include files
32 
33 // forward declarations
34 namespace edm {
35  template< typename T>
36  class ContainerMask {
37 
38  public:
40  ContainerMask(const edm::RefProd<T>& iProd, const std::vector<bool>& iMask);
41  //virtual ~ContainerMask();
42 
43  // ---------- const member functions ---------------------
44  bool mask(unsigned int iIndex) const {
45  if(iIndex<m_mask.size()) {
46  return m_mask[iIndex];
47  }
48  return false;
49  }
50  bool mask(const typename ContainerMaskTraits<T>::value_type *);
51  void applyOrTo( std::vector<bool>&) const;
52  void copyMaskTo( std::vector<bool>&) const;
53 
54 
55  size_t size() const { return m_mask.size();}
56 
57  const edm::RefProd<T>& refProd() const {return m_prod;}
58  // ---------- static member functions --------------------
59 
60  // ---------- member functions ---------------------------
61  void swap(ContainerMask<T>& iOther);
62 
63  //Used by ROOT storage
65 
66  private:
67  //ContainerMask(const ContainerMask&); // stop default
68 
69  //const ContainerMask& operator=(const ContainerMask&); // stop default
70 
71  // ---------- member data --------------------------------
73  std::vector<bool> m_mask;
74  };
75 
76  template<typename T>
77  ContainerMask<T>::ContainerMask(const edm::RefProd<T>& iProd, const std::vector<bool>& iMask):
78  m_prod(iProd), m_mask(iMask) {
79  assert(iMask.size() <= ContainerMaskTraits<T>::size(m_prod.product()));
80  }
81 
82 
83  template<typename T>
85  {
86  unsigned int index = ContainerMaskTraits<T>::indexFor(iElement,m_prod.product());
87  return this->mask(index);
88  }
89 
90  template<typename T>
91  void ContainerMask<T>::copyMaskTo(std::vector<bool>& iTo) const {
92  iTo.assign(m_mask.begin(),m_mask.end());
93  }
94 
95  template<typename T>
96  void ContainerMask<T>::applyOrTo(std::vector<bool>& iTo) const {
97  assert(iTo.size()==m_mask.size());
98  std::transform(m_mask.begin(),m_mask.end(),iTo.begin(), iTo.begin(),std::logical_or<bool>());
99  }
100 
101  template<typename T>
103  m_prod.swap(iOther.m_prod);
104  std::swap(m_mask,iOther.m_mask);
105  }
106 }
107 
108 #endif
std::vector< bool > m_mask
Definition: ContainerMask.h:73
edm::RefProd< T > m_prod
Definition: ContainerMask.h:72
#define CMS_CLASS_VERSION(_version_)
void copyMaskTo(std::vector< bool > &) const
Definition: ContainerMask.h:91
bool mask(unsigned int iIndex) const
Definition: ContainerMask.h:44
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
product_type const * product() const
Definition: RefProd.h:119
void swap(RefProd< C > &)
Definition: RefProd.h:190
size_t size() const
Definition: ContainerMask.h:55
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
static size_t size(const T *iContainer)
const edm::RefProd< T > & refProd() const
Definition: ContainerMask.h:57
static unsigned int indexFor(const value_type *iElement, const T *iContainer)
HLT enums.
void applyOrTo(std::vector< bool > &) const
Definition: ContainerMask.h:96
void swap(ContainerMask< T > &iOther)
long double T