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

Hold thinning decisions for one container. More...

#include <ThinningDecision.h>

Inheritance diagram for SG::ThinningDecision:
Collaboration diagram for SG::ThinningDecision:

Public Types

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

Public Member Functions

 ThinningDecision (const DataLink< SG::AuxVectorBase > &link)
 Constructor. More...
 
 ThinningDecision (const std::string &key)
 Constructor. More...
 
const DataLink< SG::AuxVectorBase > & link () const
 Return link to object being thinned. More...
 
virtual void lock () override
 Called when the object is locked in SG. 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 thin (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 thin (const ThinningDecisionBase &other, Op op=Op::Set)
 Set the thinning state for the container from a bitmask. More...
 
void keep (size_t ndx)
 Mark that index ndx in the container should be kept (not thinned away). More...
 
void keep (size_t ndx, bool flag, Op op=Op::Set)
 Set thinning state for one element. More...
 
void keep (const std::vector< bool > &v, 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

DataLink< SG::AuxVectorBasem_link
 Link to the object being thinned. More...
 
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 essentially holds a bitmap of the elements to be thinned from the container, as well as the mapping of indices before and after thinning (the latter available only after the container has been locked in SG). See the base class ThinningDecisionBase for further details.

Definition at line 38 of file ThinningDecision.h.

Member Enumeration Documentation

◆ Op

enum SG::ThinningDecisionBase::Op
stronginherited
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

◆ ThinningDecision() [1/2]

SG::ThinningDecision::ThinningDecision ( const DataLink< SG::AuxVectorBase > &  link)

Constructor.

Parameters
linkLink to the container being thinned.

Initialized with all elements kept.

Definition at line 24 of file ThinningDecision.cxx.

25  : m_link (link)
26 {
27  if (!m_link.isValid()) {
29  }
30  resize (m_link->size_v());
31 }

◆ ThinningDecision() [2/2]

SG::ThinningDecision::ThinningDecision ( const std::string &  key)

Constructor.

Parameters
keySG key of the container being thinned.

Initialized with all elements kept.

Definition at line 40 of file ThinningDecision.cxx.

Member Function Documentation

◆ buildIndexMap()

void SG::ThinningDecisionBase::buildIndexMap ( )
inherited

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
inherited

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 
)
inherited

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 
)
inherited

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)
inherited

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 
)
inherited

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 ( )
inherited

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

Definition at line 60 of file ThinningDecisionBase.cxx.

61 {
62  m_mask.reset();
63 }

◆ link()

const DataLink< SG::AuxVectorBase > & SG::ThinningDecision::link ( ) const

Return link to object being thinned.

Definition at line 49 of file ThinningDecision.cxx.

50 {
51  return m_link;
52 }

◆ lock()

void SG::ThinningDecision::lock ( )
overridevirtual

Called when the object is locked in SG.

Build the index map.

Implements ILockable.

Definition at line 60 of file ThinningDecision.cxx.

61 {
62  buildIndexMap();
63 }

◆ resize()

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

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
inherited

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 
)
inherited

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 
)
inherited

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)
inherited

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 
)
inherited

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 ( )
inherited

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
inherited

Return true if element ndx should be thinned.

◆ thinnedSize()

size_t SG::ThinningDecisionBase::thinnedSize ( ) const
inherited

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
privateinherited

Mapping from original indices to thinned indices.

Definition at line 207 of file ThinningDecisionBase.h.

◆ m_link

DataLink<SG::AuxVectorBase> SG::ThinningDecision::m_link
private

Link to the object being thinned.

Definition at line 76 of file ThinningDecision.h.

◆ m_mask

boost::dynamic_bitset SG::ThinningDecisionBase::m_mask
privateinherited

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)
staticinherited

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::resize
void resize(const size_t size)
Change the number of elements.
Definition: ThinningDecisionBase.cxx:33
SG::ThinningDecision::m_link
DataLink< SG::AuxVectorBase > m_link
Link to the object being thinned.
Definition: ThinningDecision.h:76
SG::ThinningDecisionBase::m_indexMap
std::vector< size_t > m_indexMap
Mapping from original indices to thinned indices.
Definition: ThinningDecisionBase.h:207
SG::ExcInvalidThinningTarget
Exception — ThinningHandle target does not exist.
Definition: Control/AthContainers/AthContainers/exceptions.h:438
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::ThinningDecision::link
const DataLink< SG::AuxVectorBase > & link() const
Return link to object being thinned.
Definition: ThinningDecision.cxx:49
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::buildIndexMap
void buildIndexMap()
Build the index map.
Definition: ThinningDecisionBase.cxx:240
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
SG::ThinningDecision::ThinningDecision
ThinningDecision(const DataLink< SG::AuxVectorBase > &link)
Constructor.
Definition: ThinningDecision.cxx:24
SG::AuxVectorData::size_v
virtual size_t size_v() const =0
Return the size of the container.
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37