ATLAS Offline Software
Public Types | Public Member Functions | Static Public Attributes | Private Attributes | List of all members
SG::ThinningDecisionBase Class Reference

Hold thinning decisions for one container. More...

#include <ThinningDecisionBase.h>

Inheritance diagram for SG::ThinningDecisionBase:
Collaboration diagram for SG::ThinningDecisionBase:

Public Types

enum  Op { Op::Set = 0, Op::And = 1, Op::Or = 2 }
 

Public Member Functions

 ThinningDecisionBase (size_t sz=0)
 Constructor. More...
 
void resize (const size_t size)
 Change the number of elements. More...
 
bool thinned (size_t ndx) const
 Return true if element ndx should be thinned. More...
 
size_t size () const
 Return the total size of the container being thinned. More...
 
size_t thinnedSize () const
 Return the size of the container being thinned after thinning. More...
 
void thinAll ()
 Mark that all elements should be thinned away. More...
 
void keepAll ()
 Mark that all elements should be kept (not thinned). More...
 
void thin (size_t ndx)
 Mark that index ndx in the container should be thinned away. More...
 
void keep (size_t ndx)
 Mark that index ndx in the container should be kept (not thinned away). More...
 
void thin (size_t ndx, bool flag, Op op=Op::Set)
 Set thinning state for one element. More...
 
void keep (size_t ndx, bool flag, Op op=Op::Set)
 Set thinning state for one element. More...
 
void thin (const std::vector< bool > &v, Op op=Op::Set)
 Set the thinning state for the container from a bitmask. More...
 
void keep (const std::vector< bool > &v, Op op=Op::Set)
 Set the thinning state for the container from a bitmask. More...
 
void thin (const ThinningDecisionBase &other, Op op=Op::Set)
 Set the thinning state for the container from a bitmask. More...
 
void keep (const ThinningDecisionBase &other, Op op=Op::Set)
 Set the thinning state for the container from a bitmask. More...
 
void buildIndexMap ()
 Build the index map. More...
 
size_t index (size_t ndxOrig) const
 Return the index corresponding to ndxOrig after thinning. More...
 

Static Public Attributes

static const std::size_t RemovedIdx = static_cast<std::size_t>(-1)
 Flag used to show that an index has been thinned away. More...
 

Private Attributes

boost::dynamic_bitset m_mask
 Thinning map. Set to 1 for thinned elements. More...
 
std::vector< size_t > m_indexMap
 Mapping from original indices to thinned indices. More...
 

Detailed Description

Hold thinning decisions for one container.

This class is a wrapper around a bitmap that holds a set of thinning decisions for one container. If bit i is set in the map, then element i of the container has been thinned.

This class also holds a mapping of container indices before and after thinning. However, this is not available until @ buildIndexMap() has been called (which usually happens implicitly when the derived ThinningDecision object is recorded in StoreGate).

Definition at line 38 of file ThinningDecisionBase.h.

Member Enumeration Documentation

◆ Op

Enumerator
Set 
And 
Or 

Definition at line 44 of file ThinningDecisionBase.h.

44  {
45  Set = 0,
46  And = 1,
47  Or = 2
48  };

Constructor & Destructor Documentation

◆ ThinningDecisionBase()

SG::ThinningDecisionBase::ThinningDecisionBase ( size_t  sz = 0)

Constructor.

Parameters
szNumber of elements in the container.

Initialized with all elements kept.

Parameters
szNumber of elements in the container.

Definition at line 23 of file ThinningDecisionBase.cxx.

24  : m_mask (sz)
25 {
26 }

Member Function Documentation

◆ buildIndexMap()

void SG::ThinningDecisionBase::buildIndexMap ( )

Build the index map.

Definition at line 240 of file ThinningDecisionBase.cxx.

241 {
242  assert (m_indexMap.empty());
243  size_t sz = m_mask.size();
244  m_indexMap.resize (sz);
245  size_t pos = 0;
246  for (size_t i = 0; i < sz; i++) {
247  m_indexMap[i] = thinned(i) ? RemovedIdx : pos++ ;
248  }
249 }

◆ index()

size_t SG::ThinningDecisionBase::index ( size_t  ndxOrig) const

Return the index corresponding to ndxOrig after thinning.

Parameters
ndxOrigOriginal container index.

Returns the index at which element ndxOrig ends up after thinning. If the element was thinned away, returns RemovedIdx.

This information is available only after buildIndexMap has been called.

◆ keep() [1/4]

void SG::ThinningDecisionBase::keep ( const std::vector< bool > &  v,
Op  op = Op::Set 
)

Set the thinning state for the container from a bitmask.

Parameters
vThinning state mask; should have the same size as the container. Element ndx should be kept if bit ndx is set in the map.
opLogical operation for combining with existing thinning state. Set — Keep if flag is true. And — Keep if flag is true and element was originally kept, else not. Or — Keep if flag is true or element was originally kept, else not.

Definition at line 172 of file ThinningDecisionBase.cxx.

173 {
174  size_t sz = m_mask.size();
175  if (sz != v.size()) {
176  throw std::out_of_range ("ThinningDecisionBase::keep(): inconsistent vector sizes.");
177  }
178  for (size_t i = 0; i < sz; i++) {
179  bool flag = v[i];
180  if (op == Op::And)
181  flag &= !m_mask[i];
182  else if (op == Op::Or)
183  flag |= !m_mask[i];
184  m_mask.set (i, !flag);
185  }
186 }

◆ keep() [2/4]

void SG::ThinningDecisionBase::keep ( const ThinningDecisionBase other,
Op  op = Op::Set 
)

Set the thinning state for the container from a bitmask.

Parameters
otherThinning state mask; should have the same size as the container. Element ndx should be kept if bit ndx is set in the map.
opLogical operation for combining with existing thinning state. Set — Keep if flag is true. And — Keep if flag is true and element was originally kept, else not. Or — Keep if flag is true or element was originally kept, else not.

Definition at line 222 of file ThinningDecisionBase.cxx.

223 {
224  size_t sz = m_mask.size();
225  if (sz != other.size()) {
226  throw std::out_of_range ("ThinningDecisionBase::keep(): inconsistent vector sizes.");
227  }
228  if (op == Op::And)
229  m_mask |= ~other.m_mask;
230  else if (op == Op::Or)
231  m_mask &= ~other.m_mask;
232  else
233  m_mask = ~other.m_mask;
234 }

◆ keep() [3/4]

void SG::ThinningDecisionBase::keep ( size_t  ndx)

Mark that index ndx in the container should be kept (not thinned away).

Parameters
ndxIndex of element to keep.

Definition at line 84 of file ThinningDecisionBase.cxx.

85 {
86  if (ndx >= m_mask.size()) {
87  throw std::out_of_range ("ThinningDecisionBase::thin");
88  }
89  m_mask.set (ndx, false);
90 }

◆ keep() [4/4]

void SG::ThinningDecisionBase::keep ( size_t  ndx,
bool  flag,
Op  op = Op::Set 
)

Set thinning state for one element.

Parameters
ndxIndex of element to alter.
flagIf true, keep this element; if false, thin it it.
opLogical operation for combining with existing thinning state. Set — Keep if flag is true. And — Keep if flag is true and element was originally kept, else not. Or — Keep if flag is true or element was originally kept, else not.

Definition at line 124 of file ThinningDecisionBase.cxx.

125 {
126  if (ndx >= m_mask.size()) {
127  throw std::out_of_range ("ThinningDecisionBase::thin");
128  }
129  if (op == Op::And)
130  flag &= !m_mask[ndx];
131  else if (op == Op::Or)
132  flag |= !m_mask[ndx];
133  m_mask.set (ndx, !flag);
134 }

◆ keepAll()

void SG::ThinningDecisionBase::keepAll ( )

Mark that all elements should be kept (not thinned).

Definition at line 60 of file ThinningDecisionBase.cxx.

61 {
62  m_mask.reset();
63 }

◆ resize()

void SG::ThinningDecisionBase::resize ( const size_t  size)

Change the number of elements.

Parameters
sizeThe new number of elements.

Definition at line 33 of file ThinningDecisionBase.cxx.

34 {
35  m_mask.resize (size);
36 }

◆ size()

size_t SG::ThinningDecisionBase::size ( ) const

Return the total size of the container being thinned.

◆ thin() [1/4]

void SG::ThinningDecisionBase::thin ( const std::vector< bool > &  v,
Op  op = Op::Set 
)

Set the thinning state for the container from a bitmask.

Parameters
vThinning state mask; should have the same size as the container. Element ndx should be thinned if bit ndx is set in the map.
opLogical operation for combining with existing thinning state. Set — Thin if flag is true. And — Thin if flag is true and element was originally thinned, else not. Or — Thin if flag is true or element was originally thinned, else not.

Definition at line 146 of file ThinningDecisionBase.cxx.

147 {
148  size_t sz = m_mask.size();
149  if (sz != v.size()) {
150  throw std::out_of_range ("ThinningDecisionBase::thin(): inconsistent vector sizes.");
151  }
152  for (size_t i = 0; i < sz; i++) {
153  bool flag = v[i];
154  if (op == Op::And)
155  flag &= m_mask[i];
156  else if (op == Op::Or)
157  flag |= m_mask[i];
158  m_mask.set (i, flag);
159  }
160 }

◆ thin() [2/4]

void SG::ThinningDecisionBase::thin ( const ThinningDecisionBase other,
Op  op = Op::Set 
)

Set the thinning state for the container from a bitmask.

Parameters
otherThinning state mask; should have the same size as the container. Element ndx should be thinned if bit ndx is set in the map.
opLogical operation for combining with existing thinning state. Set — Thin if flag is true. And — Thin if flag is true and element was originally thinned, else not. Or — Thin if flag is true or element was originally thinned, else not.

Definition at line 198 of file ThinningDecisionBase.cxx.

199 {
200  size_t sz = m_mask.size();
201  if (sz != other.size()) {
202  throw std::out_of_range ("ThinningDecisionBase::thin(): inconsistent vector sizes.");
203  }
204  if (op == Op::And)
205  m_mask &= other.m_mask;
206  else if (op == Op::Or)
207  m_mask |= other.m_mask;
208  else
209  m_mask = other.m_mask;
210 }

◆ thin() [3/4]

void SG::ThinningDecisionBase::thin ( size_t  ndx)

Mark that index ndx in the container should be thinned away.

Parameters
ndxIndex of element to thin.

Definition at line 70 of file ThinningDecisionBase.cxx.

71 {
72  if (ndx >= m_mask.size()) {
73  throw std::out_of_range ("ThinningDecisionBase::thin");
74  }
75  m_mask.set (ndx, true);
76 }

◆ thin() [4/4]

void SG::ThinningDecisionBase::thin ( size_t  ndx,
bool  flag,
Op  op = Op::Set 
)

Set thinning state for one element.

Parameters
ndxIndex of element to alter.
flagIf true, thin this element; if false, keep it.
opLogical operation for combining with existing thinning state. Set — Thin if flag is true. And — Thin if flag is true and element was originally thinned, else not. Or — Thin if flag is true or element was originally thinned, else not.

Definition at line 102 of file ThinningDecisionBase.cxx.

103 {
104  if (ndx >= m_mask.size()) {
105  throw std::out_of_range ("ThinningDecisionBase::thin");
106  }
107  if (op == Op::And)
108  flag &= m_mask[ndx];
109  else if (op == Op::Or)
110  flag |= m_mask[ndx];
111  m_mask.set (ndx, flag);
112 }

◆ thinAll()

void SG::ThinningDecisionBase::thinAll ( )

Mark that all elements should be thinned away.

Definition at line 51 of file ThinningDecisionBase.cxx.

52 {
53  m_mask.set();
54 }

◆ thinned()

bool SG::ThinningDecisionBase::thinned ( size_t  ndx) const

Return true if element ndx should be thinned.

◆ thinnedSize()

size_t SG::ThinningDecisionBase::thinnedSize ( ) const

Return the size of the container being thinned after thinning.

Definition at line 42 of file ThinningDecisionBase.cxx.

43 {
44  return m_mask.size() - m_mask.count();
45 }

Member Data Documentation

◆ m_indexMap

std::vector<size_t> SG::ThinningDecisionBase::m_indexMap
private

Mapping from original indices to thinned indices.

Definition at line 207 of file ThinningDecisionBase.h.

◆ m_mask

boost::dynamic_bitset SG::ThinningDecisionBase::m_mask
private

Thinning map. Set to 1 for thinned elements.

Definition at line 204 of file ThinningDecisionBase.h.

◆ RemovedIdx

const std::size_t SG::ThinningDecisionBase::RemovedIdx = static_cast<std::size_t>(-1)
static

Flag used to show that an index has been thinned away.

Definition at line 42 of file ThinningDecisionBase.h.


The documentation for this class was generated from the following files:
fitman.sz
sz
Definition: fitman.py:527
SG::ThinningDecisionBase::m_indexMap
std::vector< size_t > m_indexMap
Mapping from original indices to thinned indices.
Definition: ThinningDecisionBase.h:207
SG::ThinningDecisionBase::thinned
bool thinned(size_t ndx) const
Return true if element ndx should be thinned.
lumiFormat.i
int i
Definition: lumiFormat.py:85
SG::ThinningDecisionBase::Op::And
@ And
master.flag
bool flag
Definition: master.py:29
SG::ThinningDecisionBase::RemovedIdx
static const std::size_t RemovedIdx
Flag used to show that an index has been thinned away.
Definition: ThinningDecisionBase.h:42
Set
struct _Set Set
Represents a set of values.
Definition: set.h:59
SG::ThinningDecisionBase::m_mask
boost::dynamic_bitset m_mask
Thinning map. Set to 1 for thinned elements.
Definition: ThinningDecisionBase.h:204
SG::ThinningDecisionBase::size
size_t size() const
Return the total size of the container being thinned.
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
python.PyAthena.v
v
Definition: PyAthena.py:154
SG::ThinningDecisionBase::Op::Or
@ Or
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16