CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  assert(iIndex<m_mask.size());
45  return m_mask[iIndex];
46  }
47  bool mask(const typename ContainerMaskTraits<T>::value_type *);
48  void applyOrTo( std::vector<bool>&) const;
49  void copyMaskTo( std::vector<bool>&) const;
50 
51 
52  size_t size() const { return m_mask.size();}
53 
54  const edm::RefProd<T>& refProd() const {return m_prod;}
55  // ---------- static member functions --------------------
56 
57  // ---------- member functions ---------------------------
58  void swap(ContainerMask<T>& iOther);
59 
60  //Used by ROOT storage
62 
63  private:
64  //ContainerMask(const ContainerMask&); // stop default
65 
66  //const ContainerMask& operator=(const ContainerMask&); // stop default
67 
68  // ---------- member data --------------------------------
69  edm::RefProd<T> m_prod;
70  std::vector<bool> m_mask;
71  };
72 
73  template<typename T>
74  ContainerMask<T>::ContainerMask(const edm::RefProd<T>& iProd, const std::vector<bool>& iMask):
75  m_prod(iProd), m_mask(iMask) {
76  assert(iMask.size() == ContainerMaskTraits<T>::size(m_prod.product()));
77  }
78 
79 
80  template<typename T>
82  {
83  unsigned int index = ContainerMaskTraits<T>::indexFor(iElement,m_prod.product());
84  return this->mask(index);
85  }
86 
87  template<typename T>
88  void ContainerMask<T>::copyMaskTo(std::vector<bool>& iTo) const {
89  iTo.assign(m_mask.begin(),m_mask.end());
90  }
91 
92  template<typename T>
93  void ContainerMask<T>::applyOrTo(std::vector<bool>& iTo) const {
94  assert(iTo.size()==m_mask.size());
95  std::transform(m_mask.begin(),m_mask.end(),iTo.begin(), iTo.begin(),std::logical_or<bool>());
96  }
97 
98  template<typename T>
100  m_prod.swap(iOther.m_prod);
101  std::swap(m_mask,iOther.m_mask);
102  }
103 }
104 
105 #endif
std::vector< bool > m_mask
Definition: ContainerMask.h:70
edm::RefProd< T > m_prod
Definition: ContainerMask.h:69
#define CMS_CLASS_VERSION(_version_)
void copyMaskTo(std::vector< bool > &) const
Definition: ContainerMask.h:88
bool mask(unsigned int iIndex) const
Definition: ContainerMask.h:43
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
size_t size() const
Definition: ContainerMask.h:52
static size_t size(const T *iContainer)
const edm::RefProd< T > & refProd() const
Definition: ContainerMask.h:54
static unsigned int indexFor(const value_type *iElement, const T *iContainer)
string const
Definition: compareJSON.py:14
#define private
Definition: FWFileEntry.h:17
void applyOrTo(std::vector< bool > &) const
Definition: ContainerMask.h:93
void swap(ContainerMask< T > &iOther)
Definition: ContainerMask.h:99
long double T
def template
Definition: svgfig.py:520