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 <algorithm>
26 
27 // user include files
31 
32 // forward declarations
33 namespace edm {
34  template< typename T>
35  class ContainerMask {
36 
37  public:
39  ContainerMask(const edm::RefProd<T>& iProd, const std::vector<bool>& iMask);
40  //virtual ~ContainerMask();
41 
42  // ---------- const member functions ---------------------
43  bool mask(unsigned int iIndex) const {
44  if(iIndex<m_mask.size()) {
45  return m_mask[iIndex];
46  }
47  return false;
48  }
49  bool mask(const typename ContainerMaskTraits<T>::value_type *);
50  void applyOrTo( std::vector<bool>&) const;
51  void copyMaskTo( std::vector<bool>&) const;
52 
53 
54  size_t size() const { return m_mask.size();}
55 
56  const edm::RefProd<T>& refProd() const {return m_prod;}
57  // ---------- static member functions --------------------
58 
59  // ---------- member functions ---------------------------
60  void swap(ContainerMask<T>& iOther);
61 
62  //Used by ROOT storage
64 
65  private:
66  //ContainerMask(const ContainerMask&); // stop default
67 
68  //const ContainerMask& operator=(const ContainerMask&); // stop default
69 
70  // ---------- member data --------------------------------
72  std::vector<bool> m_mask;
73  };
74 
75  template<typename T>
76  ContainerMask<T>::ContainerMask(const edm::RefProd<T>& iProd, const std::vector<bool>& iMask):
77  m_prod(iProd), m_mask(iMask) {
78  assert(iMask.size() <= ContainerMaskTraits<T>::size(m_prod.product()));
79  }
80 
81 
82  template<typename T>
84  {
85  unsigned int index = ContainerMaskTraits<T>::indexFor(iElement,m_prod.product());
86  return this->mask(index);
87  }
88 
89  template<typename T>
90  void ContainerMask<T>::copyMaskTo(std::vector<bool>& iTo) const {
91  iTo.assign(m_mask.begin(),m_mask.end());
92  }
93 
94  template<typename T>
95  void ContainerMask<T>::applyOrTo(std::vector<bool>& iTo) const {
96  assert(iTo.size()==m_mask.size());
97  std::transform(m_mask.begin(),m_mask.end(),iTo.begin(), iTo.begin(),std::logical_or<bool>());
98  }
99 
100  template<typename T>
102  m_prod.swap(iOther.m_prod);
103  std::swap(m_mask,iOther.m_mask);
104  }
105 }
106 
107 #endif
std::vector< bool > m_mask
Definition: ContainerMask.h:72
edm::RefProd< T > m_prod
Definition: ContainerMask.h:71
#define CMS_CLASS_VERSION(_version_)
Definition: classes.h:31
void copyMaskTo(std::vector< bool > &) const
Definition: ContainerMask.h:90
bool mask(unsigned int iIndex) const
Definition: ContainerMask.h:43
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:54
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:520
static size_t size(const T *iContainer)
const edm::RefProd< T > & refProd() const
Definition: ContainerMask.h:56
static unsigned int indexFor(const value_type *iElement, const T *iContainer)
HLT enums.
void applyOrTo(std::vector< bool > &) const
Definition: ContainerMask.h:95
void swap(ContainerMask< T > &iOther)
long double T