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
edm::RefProd< T >
RefProd.h
edm::ContainerMask::ContainerMask
ContainerMask()
Definition: ContainerMask.h:38
edm::ContainerMask::swap
void swap(ContainerMask< T > &iOther)
Definition: ContainerMask.h:98
edm
HLT enums.
Definition: AlignableModifier.h:19
cms::cuda::assert
assert(be >=bs)
edm::ContainerMask
Definition: ContainerMask.h:36
ContainerMaskTraits.h
watchdog.const
const
Definition: watchdog.py:83
edm::ContainerMask::m_prod
edm::RefProd< T > m_prod
Definition: ContainerMask.h:70
std::swap
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Definition: DataFrameContainer.h:209
edm::ContainerMaskTraits::indexFor
static unsigned int indexFor(const value_type *iElement, const T *iContainer)
Definition: ContainerMaskTraits.h:34
edm::ContainerMask::m_mask
std::vector< bool > m_mask
Definition: ContainerMask.h:71
HcalDetIdTransform::transform
unsigned transform(const HcalDetId &id, unsigned transformCode)
Definition: HcalDetIdTransform.cc:7
CMS_CLASS_VERSION
#define CMS_CLASS_VERSION(_version_)
Definition: CMS_CLASS_VERSION.h:30
edm::RefProd::product
product_type const * product() const
Definition: RefProd.h:110
edm::RefProd::swap
void swap(RefProd< C > &)
Definition: RefProd.h:173
edm::ContainerMaskTraits::size
static size_t size(const T *iContainer)
Definition: ContainerMaskTraits.h:33
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
edm::ContainerMask::refProd
const edm::RefProd< T > & refProd() const
Definition: ContainerMask.h:55
svgfig.template
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
edm::ContainerMask::size
size_t size() const
Definition: ContainerMask.h:53
std
Definition: JetResolutionObject.h:76
CMS_CLASS_VERSION.h
edm::ContainerMask::copyMaskTo
void copyMaskTo(std::vector< bool > &) const
Definition: ContainerMask.h:87
T
long double T
Definition: Basic3DVectorLD.h:48
edm::ContainerMask::applyOrTo
void applyOrTo(std::vector< bool > &) const
Definition: ContainerMask.h:92
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
edm::ContainerMask::mask
bool mask(unsigned int iIndex) const
Definition: ContainerMask.h:43
edm::ContainerMaskTraits::value_type
T::value_type value_type
Definition: ContainerMaskTraits.h:31