Classes | Public Types | Public Member Functions | Static Public Attributes | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Private Types | Private Member Functions | List of all members
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
 
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 138 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 149 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 184 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 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 >::BlockKey_t = Key_t
protected

type of block key

Definition at line 290 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 148 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 165 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 292 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 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 >::Key_t = KEY

type of counter key in the map

Definition at line 147 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

Definition at line 183 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 162 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 144 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 188 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 195 of file CountersMap.h.

195 {}
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 198 of file CountersMap.h.

198 : 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:171

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 511 of file CountersMap.h.

512  { return const_iterator{ counter_map.begin(), 0 }; }
BaseMap_t counter_map
the actual data structure for counters
Definition: CountersMap.h:359
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 505 of file CountersMap.h.

506  { return unchecked_add(CounterKey_t(key), -1); }
def key(type, name=None)
Definition: graph.py:13
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:631
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 245 of file CountersMap.h.

245 { return counter_map.empty(); }
BaseMap_t counter_map
the actual data structure for counters
Definition: CountersMap.h:359
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 516 of file CountersMap.h.

517  { return const_iterator{ counter_map.end(), 0 }; }
BaseMap_t counter_map
the actual data structure for counters
Definition: CountersMap.h:359
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 592 of file CountersMap.h.

593  {
594  typename BaseMap_t::const_iterator iBlock = counter_map.find(key.block);
595  return (iBlock == counter_map.end())? 0: iBlock->second[key.counter];
596  } // CountersMap<>::GetCounter() const
intermediate_table::const_iterator const_iterator
def key(type, name=None)
Definition: graph.py:13
BaseMap_t counter_map
the actual data structure for counters
Definition: CountersMap.h:359
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 601 of file CountersMap.h.

602  { return counter_map[key.block][key.counter]; }
def key(type, name=None)
Definition: graph.py:13
BaseMap_t counter_map
the actual data structure for counters
Definition: CountersMap.h:359
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 367 of file CountersMap.h.

368  { return GetCounter(key); }
def key(type, name=None)
Definition: graph.py:13
Counter_t GetCounter(CounterKey_t key) const
Returns the value of the counter at the specified split key.
Definition: CountersMap.h:592
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 500 of file CountersMap.h.

501  { return unchecked_add(CounterKey_t(key), +1); }
def key(type, name=None)
Definition: graph.py:13
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:631
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 522 of file CountersMap.h.

525  {
526  // this function is not optimised
527  using CompMap_t
528  = const std::map<Key_t, SubCounter_t, std::less<Key_t>, OALLOC>;
529  typename CompMap_t::const_iterator to_iter = to.begin(), to_end = to.end();
530  for (const typename const_iterator::value_type& p: *this) {
531 
532  if (to_iter != to_end) { // we have still counters to find
533  // if counter is already beyond the next non-empty one froml STL map,
534  // then we are missing some
535  if (p.first > to_iter->first) {
536  first_difference = to_iter->first;
537  return false;
538  }
539  // while (p.first > to_iter->first) {
540  // ++nMissingKeys;
541  // std::cout << "ERROR missing key " << to_iter->first << std::endl;
542  // if (++to_iter == to_end) break;
543  // } // while
544  // } // if
545  //
546  // if (to_iter != to_end) { // we have still counters to find
547  if (p.first == to_iter->first) {
548  // if the counter is in SLT map, the two counts must match
549  // std::cout << " " << p.first << " " << p.second << std::endl;
550  if (to_iter->second != p.second) {
551  // std::cout << "ERROR wrong counter value " << p.second
552  // << ", expected " << to_iter->second << std::endl;
553  // ++nMismatchValue;
554  first_difference = to_iter->first;
555  return false;
556  }
557  ++to_iter; // done with it
558  }
559  else if (p.first < to_iter->first) {
560  // if the counter is not in STL map, then it must be 0
561  if (p.second != 0) {
562  // ++nExtraKeys;
563  // std::cout << "ERROR extra key " << p.first << " (" << p.second << ")"
564  // << std::endl;
565  first_difference = p.first;
566  return false;
567  }
568  // else {
569  // std::cout << " " << p.first << " " << p.second << " (not in STL)"
570  // << std::endl;
571  // }
572  }
573  }
574  else { // if we are at the end of compared map
575  // no more keys in STL map
576  if (p.second != 0) {
577  // ++nExtraKeys;
578  // std::cout << "ERROR extra key " << p.first << " (" << p.second << ")"
579  // << std::endl;
580  first_difference = p.first;
581  return false;
582  }
583  }
584  } // for element in map
585 
586  return true;
587  } // CountersMap<>::is_equal()
typename CounterMap_t::value_type value_type
value type: pair
Definition: CountersMap.h:441
intermediate_table::const_iterator const_iterator
p
Definition: test.py:223
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 284 of file CountersMap.h.

285  { Key_t dummy; return is_equal(to, dummy); }
KEY Key_t
type of counter key in the map
Definition: CountersMap.h:147
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:522
cet::LibraryManager dummy("noplugin")
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 379 of file CountersMap.h.

380  { return { it, ix }; }
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 249 of file CountersMap.h.

250  { return counter_map.size() * NSubcounters; }
BaseMap_t counter_map
the actual data structure for counters
Definition: CountersMap.h:359
static constexpr size_t NSubcounters
Number of subcounters in one counter block.
Definition: CountersMap.h:159
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 202 of file CountersMap.h.

202 { return GetSubCounter(key); }
def key(type, name=None)
Definition: graph.py:13
SubCounter_t GetSubCounter(CounterKey_t key) const
Returns the value of the subcounter at the specified split key.
Definition: CountersMap.h:367
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 495 of file CountersMap.h.

496  { return unchecked_set(CounterKey_t(key), value); }
def key(type, name=None)
Definition: graph.py:13
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:608
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 375 of file CountersMap.h.

375 { return key; }
def key(type, name=None)
Definition: graph.py:13
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 631 of file CountersMap.h.

632  {
633  // take it low level here
634  // first get the iterator to the block
635  typename BaseMap_t::iterator iBlock = counter_map.lower_bound(key.block);
636  if (iBlock != counter_map.end()) {
637  if (iBlock->first == key.block) { // sweet, we have that counter already
638  return iBlock->second[key.counter] += delta;
639  }
640  }
641  // no counter there yet: create one;
642  // hint to insert before the block in the position we jave already found
643  // (this is optimal in STL map for C++11);
644  // create a block using the special constructor;
645  // the temporary value created here is moved to the map
646  counter_map.insert(iBlock, { key.block, { key.counter, delta } } );
647  return delta;
648  } // CountersMap<>::unchecked_add() const
intermediate_table::iterator iterator
def key(type, name=None)
Definition: graph.py:13
BaseMap_t counter_map
the actual data structure for counters
Definition: CountersMap.h:359
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 608 of file CountersMap.h.

609  {
610  // take it low level here
611  // first get the iterator to the block
612  typename BaseMap_t::iterator iBlock = counter_map.lower_bound(key.block);
613  if (iBlock != counter_map.end()) {
614  if (iBlock->first == key.block) { // sweet, we have that counter already
615  return iBlock->second[key.counter] = value;
616  }
617  }
618  // no counter there yet: create one;
619  // hint to insert before the block in the position we jave already found
620  // (this is optimal in STL map for C++11);
621  // create a block using the special constructor;
622  // the temporary value created here is moved to the map
623  counter_map.insert(iBlock, { key.block, { key.counter, value } } );
624  return value;
625  } // CountersMap<>::unchecked_add() const
intermediate_table::iterator iterator
def key(type, name=None)
Definition: graph.py:13
BaseMap_t counter_map
the actual data structure for counters
Definition: CountersMap.h:359

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 359 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 156 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 159 of file CountersMap.h.


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