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 // $Id: ContainerMask.h,v 1.1 2011/12/01 13:02:17 vlimant Exp $
21 //
22 
23 // system include files
24 #include <vector>
25 #include <cassert>
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  assert(iIndex<m_mask.size());
46  return m_mask[iIndex];
47  }
48  bool mask(const typename ContainerMaskTraits<T>::value_type *);
49  void applyOrTo( std::vector<bool>&) const;
50  void copyMaskTo( std::vector<bool>&) const;
51 
52 
53  size_t size() const { return m_mask.size();}
54 
55  const edm::RefProd<T>& refProd() const {return m_prod;}
56  // ---------- static member functions --------------------
57 
58  // ---------- member functions ---------------------------
59  void swap(ContainerMask<T>& iOther);
60 
61  //Used by ROOT storage
63 
64  private:
65  //ContainerMask(const ContainerMask&); // stop default
66 
67  //const ContainerMask& operator=(const ContainerMask&); // stop default
68 
69  // ---------- member data --------------------------------
70  edm::RefProd<T> m_prod;
71  std::vector<bool> m_mask;
72  };
73 
74  template<typename T>
75  ContainerMask<T>::ContainerMask(const edm::RefProd<T>& iProd, const std::vector<bool>& iMask):
76  m_prod(iProd), m_mask(iMask) {
77  assert(iMask.size() == ContainerMaskTraits<T>::size(m_prod.product()));
78  }
79 
80 
81  template<typename T>
83  {
84  unsigned int index = ContainerMaskTraits<T>::indexFor(iElement,m_prod.product());
85  return this->mask(index);
86  }
87 
88  template<typename T>
89  void ContainerMask<T>::copyMaskTo(std::vector<bool>& iTo) const {
90  iTo.assign(m_mask.begin(),m_mask.end());
91  }
92 
93  template<typename T>
94  void ContainerMask<T>::applyOrTo(std::vector<bool>& iTo) const {
95  assert(iTo.size()==m_mask.size());
96  std::transform(m_mask.begin(),m_mask.end(),iTo.begin(), iTo.begin(),std::logical_or<bool>());
97  }
98 
99  template<typename T>
101  m_prod.swap(iOther.m_prod);
102  std::swap(m_mask,iOther.m_mask);
103  }
104 }
105 
106 #endif
std::vector< bool > m_mask
Definition: ContainerMask.h:71
edm::RefProd< T > m_prod
Definition: ContainerMask.h:70
#define CMS_CLASS_VERSION(_version_)
void copyMaskTo(std::vector< bool > &) const
Definition: ContainerMask.h:89
bool mask(unsigned int iIndex) const
Definition: ContainerMask.h:44
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
size_t size() const
Definition: ContainerMask.h:53
static size_t size(const T *iContainer)
const edm::RefProd< T > & refProd() const
Definition: ContainerMask.h:55
static unsigned int indexFor(const value_type *iElement, const T *iContainer)
string const
Definition: compareJSON.py:14
#define private
Definition: FWFileEntry.h:18
void applyOrTo(std::vector< bool > &) const
Definition: ContainerMask.h:94
void swap(ContainerMask< T > &iOther)
long double T
def template
Definition: svgfig.py:520