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  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  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 --------------------------------
71  std::vector<bool> m_mask;
72  };
73 
74  template <typename T>
76  : m_prod(iProd), m_mask(iMask) {
78  }
79 
80  template <typename T>
82  unsigned int index = ContainerMaskTraits<T>::indexFor(iElement, m_prod.product());
83  return this->mask(index);
84  }
85 
86  template <typename T>
87  void ContainerMask<T>::copyMaskTo(std::vector<bool>& iTo) const {
88  iTo.assign(m_mask.begin(), m_mask.end());
89  }
90 
91  template <typename T>
92  void ContainerMask<T>::applyOrTo(std::vector<bool>& iTo) const {
93  assert(iTo.size() == m_mask.size());
94  std::transform(m_mask.begin(), m_mask.end(), iTo.begin(), iTo.begin(), std::logical_or<bool>());
95  }
96 
97  template <typename T>
99  m_prod.swap(iOther.m_prod);
100  std::swap(m_mask, iOther.m_mask);
101  }
102 } // namespace edm
103 
104 #endif
std::vector< bool > m_mask
Definition: ContainerMask.h:71
void applyOrTo(std::vector< bool > &) const
Definition: ContainerMask.h:92
void copyMaskTo(std::vector< bool > &) const
Definition: ContainerMask.h:87
edm::RefProd< T > m_prod
Definition: ContainerMask.h:70
#define CMS_CLASS_VERSION(_version_)
assert(be >=bs)
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
void swap(RefProd< C > &)
Definition: RefProd.h:173
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:55
static unsigned int indexFor(const value_type *iElement, const T *iContainer)
HLT enums.
void swap(ContainerMask< T > &iOther)
Definition: ContainerMask.h:98
bool mask(unsigned int iIndex) const
Definition: ContainerMask.h:43
size_t size() const
Definition: ContainerMask.h:53
long double T
product_type const * product() const
Definition: RefProd.h:110
unsigned transform(const HcalDetId &id, unsigned transformCode)