LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
lar::CountersMap< KEY, COUNTER, SIZE, ALLOC, SUBCOUNTERS > Class Template Reference

Map storing counters in a compact way. More...

#include "CountersMap.h"

Inheritance diagram for lar::CountersMap< KEY, COUNTER, SIZE, ALLOC, SUBCOUNTERS >:
cluster::HoughTransformCounters< KEY, COUNTER, SIZE, ALLOC, SUBCOUNTERS >

Classes

class  const_iterator
 
struct  CounterKey_t
 Structure with the index of the counter, split as needed. More...
 

Public Types

using Key_t = KEY
 type of counter key in the map More...
 
using Counter_t = COUNTER
 type of the single counter More...
 
using Allocator_t = ALLOC
 type of the single counter More...
 
using CounterMap_t = CountersMap< KEY, COUNTER, SIZE, ALLOC, SUBCOUNTERS >
 This class. More...
 
using SubCounter_t = Counter_t
 Type of the subcounter (that is, the actual counter) More...
 
using CounterBlock_t = typename Traits_t::CounterBlock_t
 
using BaseMap_t = typename Traits_t::template BaseMap_t< typename std::allocator_traits< Allocator_t >::template rebind_alloc< typename Traits_t::MapValue_t >>
 Type of the map used in the implementation. More...
 
using value_type = std::pair< const Key_t, SubCounter_t >
 
STL type definitions
using mapped_type = SubCounter_t
 type of the single counter More...
 
using allocator_type = Allocator_t
 type of the single counter More...
 

Public Member Functions

 CountersMap ()
 Default constructor (empty map) More...
 
 CountersMap (Allocator_t alloc)
 Constructor, specifies an allocator. More...
 
SubCounter_t operator[] (Key_t key) const
 Read-only access to an element; returns 0 if no counter is present. More...
 
SubCounter_t set (Key_t key, SubCounter_t value)
 Sets the specified counter to a count. More...
 
SubCounter_t increment (Key_t key)
 Increments by 1 the specified counter. More...
 
SubCounter_t decrement (Key_t key)
 Decrements by 1 the specified counter. More...
 
bool empty () const
 Returns whether the map has no counters. More...
 
std::make_unsigned< Key_t >::type n_counters () const
 Returns the number of allocated counters. More...
 
template<typename OALLOC >
bool is_equal (const std::map< Key_t, SubCounter_t, std::less< Key_t >, OALLOC > &to, Key_t &first_difference) const
 Returns whether the counters in this map are equivalent to another. More...
 
template<typename OALLOC >
bool is_equal (const std::map< Key_t, SubCounter_t, std::less< Key_t >, OALLOC > &to) const
 Returns whether the counters in this map are equivalent to another. More...
 
Iterators (experimental)
const_iterator begin () const
 Returns an iterator to the begin of the counters. More...
 
const_iterator end () const
 Returns an iterator past-the-end of the counters. More...
 

Static Public Attributes

static constexpr size_t NCounters = Traits_t::NCounters
 Number of counters in one counter block. More...
 
static constexpr size_t NSubcounters = NCounters * SUBCOUNTERS
 Number of subcounters in one counter block. More...
 

Protected Types

using BlockKey_t = Key_t
 type of block key More...
 
using CounterIndex_t = typename std::make_unsigned< Key_t >::type
 type of index in the block More...
 

Protected Member Functions

Counter_t GetCounter (CounterKey_t key) const
 Returns the value of the counter at the specified split key. More...
 
SubCounter_t GetSubCounter (CounterKey_t key) const
 Returns the value of the subcounter at the specified split key. More...
 
Counter_tGetOrCreateCounter (CounterKey_t key)
 Returns the counter at the specified split key. More...
 

Static Protected Member Functions

static CounterKey_t SplitKey (Key_t key)
 Returns a split key corresponding to the specified key. More...
 
static const_iterator make_const_iterator (typename BaseMap_t::const_iterator it, size_t ix)
 Creates a const_iterator (useful in derived classes) More...
 

Protected Attributes

BaseMap_t counter_map
 the actual data structure for counters More...
 

Private Types

using Traits_t = details::CountersMapTraits< KEY, COUNTER, SIZE >
 Set of data types pertaining this counter. More...
 

Private Member Functions

SubCounter_t unchecked_set (CounterKey_t key, SubCounter_t delta)
 Sets the specified counter to a value (no check on value range) More...
 
SubCounter_t unchecked_add (CounterKey_t key, SubCounter_t delta)
 Adds a delta to the specified counter (no check on underflow/overflow) More...
 

Detailed Description

template<typename KEY, typename COUNTER, size_t SIZE, typename ALLOC = typename details::CountersMapTraits<KEY, COUNTER, SIZE>::DefaultAllocator_t, unsigned int SUBCOUNTERS = 1>
class lar::CountersMap< KEY, COUNTER, SIZE, ALLOC, SUBCOUNTERS >

Map storing counters in a compact way.

Parameters
KEYthe type of the key of the counters map
COUNTERthe type of a basic counter (can be signed or unsigned)
BLOCKSIZEthe number of counters in a cluster
ALLOCallocator for the underlying STL map
SUBCOUNTERSsplit each counter in subcounters (not implemented yet)

This class is designed for the need of a vast number of counters with a integral numerical key, when the counter keys are usually clustered. This can be more or less efficient than a straight counters STL map according to how often the counters are clustered (if that does not happen often, CountersMap can have considerable memory overhead).

Counters are allocated in contiguous blocks of BLOCKSIZE counters. The selling point here is that a map node has some overhead (typically at least 3 pointers) and dynamically allocating it costs a lot (40 bytes have been observed). If you need a counter with a range of 100 (1 byte), that's far from optimal in many aspects (memory allocation also takes time).

The requirement of the key to be numerical is so that the concept of "next counter" is well defined and we can store contiguous counters in a fixed structure.

Subcounters

The idea behind subcounters is that you migt want to split a counter into subcounters to save memory if the maximum counter value is smaller than the range of the counter type. The implementation is delayed since in the end the same effect can be achieved by using a small counter type (e.g. signed char), unless the range is smaller that 16 (or 4, or 2), in which case the character can be split into bits. That will cause some overhead for increment and decrement instructions.

Definition at line 130 of file CountersMap.h.

Member Typedef Documentation

template<typename KEY, typename COUNTER, size_t SIZE, typename ALLOC = typename details::CountersMapTraits<KEY, COUNTER, SIZE>::DefaultAllocator_t, unsigned int SUBCOUNTERS = 1>
using lar::CountersMap< KEY, COUNTER, SIZE, ALLOC, SUBCOUNTERS >::Allocator_t = ALLOC

type of the single counter

Definition at line 140 of file CountersMap.h.

template<typename KEY, typename COUNTER, size_t SIZE, typename ALLOC = typename details::CountersMapTraits<KEY, COUNTER, SIZE>::DefaultAllocator_t, unsigned int SUBCOUNTERS = 1>
using lar::CountersMap< KEY, COUNTER, SIZE, ALLOC, SUBCOUNTERS >::allocator_type = Allocator_t

type of the single counter

Definition at line 171 of file CountersMap.h.

template<typename KEY, typename COUNTER, size_t SIZE, typename ALLOC = typename details::CountersMapTraits<KEY, COUNTER, SIZE>::DefaultAllocator_t, unsigned int SUBCOUNTERS = 1>
using lar::CountersMap< KEY, COUNTER, SIZE, ALLOC, SUBCOUNTERS >::BaseMap_t = typename Traits_t::template BaseMap_t<typename std::allocator_traits< Allocator_t>::template rebind_alloc<typename Traits_t::MapValue_t>>

Type of the map used in the implementation.

Definition at line 158 of file CountersMap.h.

template<typename KEY, typename COUNTER, size_t SIZE, typename ALLOC = typename details::CountersMapTraits<KEY, COUNTER, SIZE>::DefaultAllocator_t, unsigned int SUBCOUNTERS = 1>
using lar::CountersMap< KEY, COUNTER, SIZE, ALLOC, SUBCOUNTERS >::BlockKey_t = Key_t
protected

type of block key

Definition at line 270 of file CountersMap.h.

template<typename KEY, typename COUNTER, size_t SIZE, typename ALLOC = typename details::CountersMapTraits<KEY, COUNTER, SIZE>::DefaultAllocator_t, unsigned int SUBCOUNTERS = 1>
using lar::CountersMap< KEY, COUNTER, SIZE, ALLOC, SUBCOUNTERS >::Counter_t = COUNTER

type of the single counter

Definition at line 139 of file CountersMap.h.

template<typename KEY, typename COUNTER, size_t SIZE, typename ALLOC = typename details::CountersMapTraits<KEY, COUNTER, SIZE>::DefaultAllocator_t, unsigned int SUBCOUNTERS = 1>
using lar::CountersMap< KEY, COUNTER, SIZE, ALLOC, SUBCOUNTERS >::CounterBlock_t = typename Traits_t::CounterBlock_t

Definition at line 154 of file CountersMap.h.

template<typename KEY, typename COUNTER, size_t SIZE, typename ALLOC = typename details::CountersMapTraits<KEY, COUNTER, SIZE>::DefaultAllocator_t, unsigned int SUBCOUNTERS = 1>
using lar::CountersMap< KEY, COUNTER, SIZE, ALLOC, SUBCOUNTERS >::CounterIndex_t = typename std::make_unsigned<Key_t>::type
protected

type of index in the block

Definition at line 272 of file CountersMap.h.

template<typename KEY, typename COUNTER, size_t SIZE, typename ALLOC = typename details::CountersMapTraits<KEY, COUNTER, SIZE>::DefaultAllocator_t, unsigned int SUBCOUNTERS = 1>
using lar::CountersMap< KEY, COUNTER, SIZE, ALLOC, SUBCOUNTERS >::CounterMap_t = CountersMap<KEY, COUNTER, SIZE, ALLOC, SUBCOUNTERS>

This class.

Definition at line 143 of file CountersMap.h.

template<typename KEY, typename COUNTER, size_t SIZE, typename ALLOC = typename details::CountersMapTraits<KEY, COUNTER, SIZE>::DefaultAllocator_t, unsigned int SUBCOUNTERS = 1>
using lar::CountersMap< KEY, COUNTER, SIZE, ALLOC, SUBCOUNTERS >::Key_t = KEY

type of counter key in the map

Definition at line 138 of file CountersMap.h.

template<typename KEY, typename COUNTER, size_t SIZE, typename ALLOC = typename details::CountersMapTraits<KEY, COUNTER, SIZE>::DefaultAllocator_t, unsigned int SUBCOUNTERS = 1>
using lar::CountersMap< KEY, COUNTER, SIZE, ALLOC, SUBCOUNTERS >::mapped_type = SubCounter_t

type of the single counter

Definition at line 170 of file CountersMap.h.

template<typename KEY, typename COUNTER, size_t SIZE, typename ALLOC = typename details::CountersMapTraits<KEY, COUNTER, SIZE>::DefaultAllocator_t, unsigned int SUBCOUNTERS = 1>
using lar::CountersMap< KEY, COUNTER, SIZE, ALLOC, SUBCOUNTERS >::SubCounter_t = Counter_t

Type of the subcounter (that is, the actual counter)

Definition at line 152 of file CountersMap.h.

template<typename KEY, typename COUNTER, size_t SIZE, typename ALLOC = typename details::CountersMapTraits<KEY, COUNTER, SIZE>::DefaultAllocator_t, unsigned int SUBCOUNTERS = 1>
using lar::CountersMap< KEY, COUNTER, SIZE, ALLOC, SUBCOUNTERS >::Traits_t = details::CountersMapTraits<KEY, COUNTER, SIZE>
private

Set of data types pertaining this counter.

Definition at line 135 of file CountersMap.h.

template<typename KEY, typename COUNTER, size_t SIZE, typename ALLOC = typename details::CountersMapTraits<KEY, COUNTER, SIZE>::DefaultAllocator_t, unsigned int SUBCOUNTERS = 1>
using lar::CountersMap< KEY, COUNTER, SIZE, ALLOC, SUBCOUNTERS >::value_type = std::pair<const Key_t, SubCounter_t>

Definition at line 175 of file CountersMap.h.

Constructor & Destructor Documentation

template<typename KEY, typename COUNTER, size_t SIZE, typename ALLOC = typename details::CountersMapTraits<KEY, COUNTER, SIZE>::DefaultAllocator_t, unsigned int SUBCOUNTERS = 1>
lar::CountersMap< KEY, COUNTER, SIZE, ALLOC, SUBCOUNTERS >::CountersMap ( )
inline

Default constructor (empty map)

Definition at line 181 of file CountersMap.h.

181 {}
template<typename KEY, typename COUNTER, size_t SIZE, typename ALLOC = typename details::CountersMapTraits<KEY, COUNTER, SIZE>::DefaultAllocator_t, unsigned int SUBCOUNTERS = 1>
lar::CountersMap< KEY, COUNTER, SIZE, ALLOC, SUBCOUNTERS >::CountersMap ( Allocator_t  alloc)
inline

Constructor, specifies an allocator.

Definition at line 184 of file CountersMap.h.

184 : BaseMap_t(alloc) {}
typename Traits_t::template BaseMap_t< typename std::allocator_traits< Allocator_t >::template rebind_alloc< typename Traits_t::MapValue_t >> BaseMap_t
Type of the map used in the implementation.
Definition: CountersMap.h:158

Member Function Documentation

template<typename K , typename C , size_t S, typename A , unsigned int SUB>
CountersMap< K, C, S, A, SUB >::const_iterator lar::CountersMap< K, C, S, A, SUB >::begin ( ) const
inline

Returns an iterator to the begin of the counters.

Definition at line 525 of file CountersMap.h.

527  {
528  return const_iterator{counter_map.begin(), 0};
529  }
BaseMap_t counter_map
the actual data structure for counters
Definition: CountersMap.h:358
template<typename K , typename C , size_t S, typename A , unsigned int SUB>
CountersMap< K, C, S, A, SUB >::SubCounter_t lar::CountersMap< K, C, S, A, SUB >::decrement ( Key_t  key)
inline

Decrements by 1 the specified counter.

Parameters
keykey of the counter to be decreased
Returns
new value of the counter

Definition at line 519 of file CountersMap.h.

520  {
521  return unchecked_add(CounterKey_t(key), -1);
522  }
SubCounter_t unchecked_add(CounterKey_t key, SubCounter_t delta)
Adds a delta to the specified counter (no check on underflow/overflow)
Definition: CountersMap.h:644
template<typename KEY, typename COUNTER, size_t SIZE, typename ALLOC = typename details::CountersMapTraits<KEY, COUNTER, SIZE>::DefaultAllocator_t, unsigned int SUBCOUNTERS = 1>
bool lar::CountersMap< KEY, COUNTER, SIZE, ALLOC, SUBCOUNTERS >::empty ( ) const
inline

Returns whether the map has no counters.

Definition at line 228 of file CountersMap.h.

228 { return counter_map.empty(); }
BaseMap_t counter_map
the actual data structure for counters
Definition: CountersMap.h:358
template<typename K , typename C , size_t S, typename A , unsigned int SUB>
CountersMap< K, C, S, A, SUB >::const_iterator lar::CountersMap< K, C, S, A, SUB >::end ( ) const
inline

Returns an iterator past-the-end of the counters.

Definition at line 532 of file CountersMap.h.

534  {
535  return const_iterator{counter_map.end(), 0};
536  }
BaseMap_t counter_map
the actual data structure for counters
Definition: CountersMap.h:358
template<typename K , typename C , size_t S, typename A , unsigned int SUB>
CountersMap< K, C, S, A, SUB >::Counter_t lar::CountersMap< K, C, S, A, SUB >::GetCounter ( CounterKey_t  key) const
inlineprotected

Returns the value of the counter at the specified split key.

Definition at line 607 of file CountersMap.h.

References lar::CountersMap< KEY, COUNTER, SIZE, ALLOC, SUBCOUNTERS >::CounterKey_t::block, and lar::CountersMap< KEY, COUNTER, SIZE, ALLOC, SUBCOUNTERS >::CounterKey_t::counter.

609  {
610  typename BaseMap_t::const_iterator iBlock = counter_map.find(key.block);
611  return (iBlock == counter_map.end()) ? 0 : iBlock->second[key.counter];
612  } // CountersMap<>::GetCounter() const
intermediate_table::const_iterator const_iterator
BaseMap_t counter_map
the actual data structure for counters
Definition: CountersMap.h:358
template<typename K , typename C , size_t S, typename A , unsigned int SUB>
CountersMap< K, C, S, A, SUB >::Counter_t & lar::CountersMap< K, C, S, A, SUB >::GetOrCreateCounter ( CounterKey_t  key)
inlineprotected

Returns the counter at the specified split key.

Definition at line 616 of file CountersMap.h.

References lar::CountersMap< KEY, COUNTER, SIZE, ALLOC, SUBCOUNTERS >::CounterKey_t::block, and lar::CountersMap< KEY, COUNTER, SIZE, ALLOC, SUBCOUNTERS >::CounterKey_t::counter.

617  {
618  return counter_map[key.block][key.counter];
619  }
BaseMap_t counter_map
the actual data structure for counters
Definition: CountersMap.h:358
template<typename KEY, typename COUNTER, size_t SIZE, typename ALLOC = typename details::CountersMapTraits<KEY, COUNTER, SIZE>::DefaultAllocator_t, unsigned int SUBCOUNTERS = 1>
SubCounter_t lar::CountersMap< KEY, COUNTER, SIZE, ALLOC, SUBCOUNTERS >::GetSubCounter ( CounterKey_t  key) const
inlineprotected

Returns the value of the subcounter at the specified split key.

Definition at line 365 of file CountersMap.h.

365 { return GetCounter(key); }
Counter_t GetCounter(CounterKey_t key) const
Returns the value of the counter at the specified split key.
Definition: CountersMap.h:607
template<typename K , typename C , size_t S, typename A , unsigned int SUB>
CountersMap< K, C, S, A, SUB >::SubCounter_t lar::CountersMap< K, C, S, A, SUB >::increment ( Key_t  key)
inline

Increments by 1 the specified counter.

Parameters
keykey of the counter to be increased
Returns
new value of the counter

Definition at line 512 of file CountersMap.h.

513  {
514  return unchecked_add(CounterKey_t(key), +1);
515  }
SubCounter_t unchecked_add(CounterKey_t key, SubCounter_t delta)
Adds a delta to the specified counter (no check on underflow/overflow)
Definition: CountersMap.h:644
template<typename K , typename C , size_t S, typename A , unsigned int SUB>
template<typename OALLOC >
bool lar::CountersMap< K, C, S, A, SUB >::is_equal ( const std::map< Key_t, SubCounter_t, std::less< Key_t >, OALLOC > &  to,
Key_t first_difference 
) const

Returns whether the counters in this map are equivalent to another.

Parameters
toa STL map
first_differencekey of the first difference
Returns
whether the counters are equivalent

The maps are considered equal if all keys in each are present in the other, and their counters have the same value, with one exception: counters in CountersMap can not to exist in the other map, but only if their count is 0 (these should be plenty of them since counters are created in blocks).

If there is a key in one map but not in the other, first_difference stores that key; if a counter is present in both maps but with a different count, first_difference reports the key of that counter. If no difference is found, first_difference is left untouched.

Definition at line 540 of file CountersMap.h.

543  {
544  // this function is not optimised
545  using CompMap_t = const std::map<Key_t, SubCounter_t, std::less<Key_t>, OALLOC>;
546  typename CompMap_t::const_iterator to_iter = to.begin(), to_end = to.end();
547  for (const typename const_iterator::value_type& p : *this) {
548 
549  if (to_iter != to_end) { // we have still counters to find
550  // if counter is already beyond the next non-empty one froml STL map,
551  // then we are missing some
552  if (p.first > to_iter->first) {
553  first_difference = to_iter->first;
554  return false;
555  }
556  // while (p.first > to_iter->first) {
557  // ++nMissingKeys;
558  // std::cout << "ERROR missing key " << to_iter->first << std::endl;
559  // if (++to_iter == to_end) break;
560  // } // while
561  // } // if
562  //
563  // if (to_iter != to_end) { // we have still counters to find
564  if (p.first == to_iter->first) {
565  // if the counter is in SLT map, the two counts must match
566  // std::cout << " " << p.first << " " << p.second << std::endl;
567  if (to_iter->second != p.second) {
568  // std::cout << "ERROR wrong counter value " << p.second
569  // << ", expected " << to_iter->second << std::endl;
570  // ++nMismatchValue;
571  first_difference = to_iter->first;
572  return false;
573  }
574  ++to_iter; // done with it
575  }
576  else if (p.first < to_iter->first) {
577  // if the counter is not in STL map, then it must be 0
578  if (p.second != 0) {
579  // ++nExtraKeys;
580  // std::cout << "ERROR extra key " << p.first << " (" << p.second << ")"
581  // << std::endl;
582  first_difference = p.first;
583  return false;
584  }
585  // else {
586  // std::cout << " " << p.first << " " << p.second << " (not in STL)"
587  // << std::endl;
588  // }
589  }
590  }
591  else { // if we are at the end of compared map
592  // no more keys in STL map
593  if (p.second != 0) {
594  // ++nExtraKeys;
595  // std::cout << "ERROR extra key " << p.first << " (" << p.second << ")"
596  // << std::endl;
597  first_difference = p.first;
598  return false;
599  }
600  }
601  } // for element in map
602 
603  return true;
604  } // CountersMap<>::is_equal()
intermediate_table::const_iterator const_iterator
template<typename KEY, typename COUNTER, size_t SIZE, typename ALLOC = typename details::CountersMapTraits<KEY, COUNTER, SIZE>::DefaultAllocator_t, unsigned int SUBCOUNTERS = 1>
template<typename OALLOC >
bool lar::CountersMap< KEY, COUNTER, SIZE, ALLOC, SUBCOUNTERS >::is_equal ( const std::map< Key_t, SubCounter_t, std::less< Key_t >, OALLOC > &  to) const
inline

Returns whether the counters in this map are equivalent to another.

Parameters
toa STL map
Returns
whether the counters are equivalent

Definition at line 263 of file CountersMap.h.

264  {
265  Key_t dummy;
266  return is_equal(to, dummy);
267  }
KEY Key_t
type of counter key in the map
Definition: CountersMap.h:138
bool is_equal(const std::map< Key_t, SubCounter_t, std::less< Key_t >, OALLOC > &to, Key_t &first_difference) const
Returns whether the counters in this map are equivalent to another.
Definition: CountersMap.h:540
template<typename KEY, typename COUNTER, size_t SIZE, typename ALLOC = typename details::CountersMapTraits<KEY, COUNTER, SIZE>::DefaultAllocator_t, unsigned int SUBCOUNTERS = 1>
static const_iterator lar::CountersMap< KEY, COUNTER, SIZE, ALLOC, SUBCOUNTERS >::make_const_iterator ( typename BaseMap_t::const_iterator  it,
size_t  ix 
)
inlinestaticprotected

Creates a const_iterator (useful in derived classes)

Definition at line 374 of file CountersMap.h.

375  {
376  return {it, ix};
377  }
template<typename KEY, typename COUNTER, size_t SIZE, typename ALLOC = typename details::CountersMapTraits<KEY, COUNTER, SIZE>::DefaultAllocator_t, unsigned int SUBCOUNTERS = 1>
std::make_unsigned<Key_t>::type lar::CountersMap< KEY, COUNTER, SIZE, ALLOC, SUBCOUNTERS >::n_counters ( ) const
inline

Returns the number of allocated counters.

Definition at line 231 of file CountersMap.h.

232  {
233  return counter_map.size() * NSubcounters;
234  }
BaseMap_t counter_map
the actual data structure for counters
Definition: CountersMap.h:358
static constexpr size_t NSubcounters
Number of subcounters in one counter block.
Definition: CountersMap.h:149
template<typename KEY, typename COUNTER, size_t SIZE, typename ALLOC = typename details::CountersMapTraits<KEY, COUNTER, SIZE>::DefaultAllocator_t, unsigned int SUBCOUNTERS = 1>
SubCounter_t lar::CountersMap< KEY, COUNTER, SIZE, ALLOC, SUBCOUNTERS >::operator[] ( Key_t  key) const
inline

Read-only access to an element; returns 0 if no counter is present.

Definition at line 187 of file CountersMap.h.

References util::begin(), util::end(), and value.

187 { return GetSubCounter(key); }
SubCounter_t GetSubCounter(CounterKey_t key) const
Returns the value of the subcounter at the specified split key.
Definition: CountersMap.h:365
template<typename K , typename C , size_t S, typename A , unsigned int SUB>
CountersMap< K, C, S, A, SUB >::SubCounter_t lar::CountersMap< K, C, S, A, SUB >::set ( Key_t  key,
SubCounter_t  value 
)
inline

Sets the specified counter to a count.

Parameters
keykey of the counter to be increased
valuecount value to be set
Returns
new value of the counter

Given the complex underlying structure (especially when subcounters are involved), a special method is used to set the value of a counter. This is equivalent to map's operator[] in non-constant version, but the creation of a new counter is explicit.

Definition at line 503 of file CountersMap.h.

506  {
507  return unchecked_set(CounterKey_t(key), value);
508  }
double value
Definition: spectrum.C:18
SubCounter_t unchecked_set(CounterKey_t key, SubCounter_t delta)
Sets the specified counter to a value (no check on value range)
Definition: CountersMap.h:622
template<typename KEY, typename COUNTER, size_t SIZE, typename ALLOC = typename details::CountersMapTraits<KEY, COUNTER, SIZE>::DefaultAllocator_t, unsigned int SUBCOUNTERS = 1>
static CounterKey_t lar::CountersMap< KEY, COUNTER, SIZE, ALLOC, SUBCOUNTERS >::SplitKey ( Key_t  key)
inlinestaticprotected

Returns a split key corresponding to the specified key.

Definition at line 371 of file CountersMap.h.

371 { return key; }
template<typename K , typename C , size_t S, typename A , unsigned int SUB>
CountersMap< K, C, S, A, SUB >::SubCounter_t lar::CountersMap< K, C, S, A, SUB >::unchecked_add ( CounterKey_t  key,
SubCounter_t  delta 
)
private

Adds a delta to the specified counter (no check on underflow/overflow)

Definition at line 644 of file CountersMap.h.

References lar::CountersMap< KEY, COUNTER, SIZE, ALLOC, SUBCOUNTERS >::CounterKey_t::block, and lar::CountersMap< KEY, COUNTER, SIZE, ALLOC, SUBCOUNTERS >::CounterKey_t::counter.

647  {
648  // take it low level here
649  // first get the iterator to the block
650  typename BaseMap_t::iterator iBlock = counter_map.lower_bound(key.block);
651  if (iBlock != counter_map.end()) {
652  if (iBlock->first == key.block) { // sweet, we have that counter already
653  return iBlock->second[key.counter] += delta;
654  }
655  }
656  // no counter there yet: create one;
657  // hint to insert before the block in the position we jave already found
658  // (this is optimal in STL map for C++11);
659  // create a block using the special constructor;
660  // the temporary value created here is moved to the map
661  counter_map.insert(iBlock, {key.block, {key.counter, delta}});
662  return delta;
663  } // CountersMap<>::unchecked_add() const
intermediate_table::iterator iterator
BaseMap_t counter_map
the actual data structure for counters
Definition: CountersMap.h:358
template<typename K , typename C , size_t S, typename A , unsigned int SUB>
CountersMap< K, C, S, A, SUB >::SubCounter_t lar::CountersMap< K, C, S, A, SUB >::unchecked_set ( CounterKey_t  key,
SubCounter_t  delta 
)
private

Sets the specified counter to a value (no check on value range)

Definition at line 622 of file CountersMap.h.

References lar::CountersMap< KEY, COUNTER, SIZE, ALLOC, SUBCOUNTERS >::CounterKey_t::block, lar::CountersMap< KEY, COUNTER, SIZE, ALLOC, SUBCOUNTERS >::CounterKey_t::counter, and value.

625  {
626  // take it low level here
627  // first get the iterator to the block
628  typename BaseMap_t::iterator iBlock = counter_map.lower_bound(key.block);
629  if (iBlock != counter_map.end()) {
630  if (iBlock->first == key.block) { // sweet, we have that counter already
631  return iBlock->second[key.counter] = value;
632  }
633  }
634  // no counter there yet: create one;
635  // hint to insert before the block in the position we jave already found
636  // (this is optimal in STL map for C++11);
637  // create a block using the special constructor;
638  // the temporary value created here is moved to the map
639  counter_map.insert(iBlock, {key.block, {key.counter, value}});
640  return value;
641  } // CountersMap<>::unchecked_add() const
intermediate_table::iterator iterator
double value
Definition: spectrum.C:18
BaseMap_t counter_map
the actual data structure for counters
Definition: CountersMap.h:358

Member Data Documentation

template<typename KEY, typename COUNTER, size_t SIZE, typename ALLOC = typename details::CountersMapTraits<KEY, COUNTER, SIZE>::DefaultAllocator_t, unsigned int SUBCOUNTERS = 1>
BaseMap_t lar::CountersMap< KEY, COUNTER, SIZE, ALLOC, SUBCOUNTERS >::counter_map
protected

the actual data structure for counters

Definition at line 358 of file CountersMap.h.

template<typename KEY, typename COUNTER, size_t SIZE, typename ALLOC = typename details::CountersMapTraits<KEY, COUNTER, SIZE>::DefaultAllocator_t, unsigned int SUBCOUNTERS = 1>
constexpr size_t lar::CountersMap< K, C, S, A, SUB >::NCounters = Traits_t::NCounters
static

Number of counters in one counter block.

Definition at line 146 of file CountersMap.h.

template<typename KEY, typename COUNTER, size_t SIZE, typename ALLOC = typename details::CountersMapTraits<KEY, COUNTER, SIZE>::DefaultAllocator_t, unsigned int SUBCOUNTERS = 1>
constexpr size_t lar::CountersMap< K, C, S, A, SUB >::NSubcounters = NCounters * SUBCOUNTERS
static

Number of subcounters in one counter block.

Definition at line 149 of file CountersMap.h.


The documentation for this class was generated from the following file: