1 #ifndef artdaq_DAQrate_detail_FragCounter_hh
2 #define artdaq_DAQrate_detail_FragCounter_hh
4 #include <unordered_map>
39 void incSlot(
size_t slot,
size_t inc);
46 void setSlot(
size_t slot,
size_t val);
81 mutable std::mutex receipts_mutex_;
82 std::unordered_map<size_t, std::atomic<size_t>> receipts_;
103 std::unique_lock<std::mutex> lk(receipts_mutex_);
104 receipts_[slot].fetch_add(inc);
112 std::unique_lock<std::mutex> lk(receipts_mutex_);
113 receipts_[slot] = val;
121 std::unique_lock<std::mutex> lk(receipts_mutex_);
122 return receipts_.size();
130 std::unique_lock<std::mutex> lk(receipts_mutex_);
132 for (
auto& it : receipts_)
144 std::unique_lock<std::mutex> lk(receipts_mutex_);
145 return receipts_.count(slot) ? receipts_.at(slot).load() : 0;
153 std::unique_lock<std::mutex> lk(receipts_mutex_);
154 size_t min = std::numeric_limits<size_t>::max();
155 for (
auto& it : receipts_)
157 if (it.second < min) min = it.second;
size_t operator[](size_t slot) const
Get the current count for the requested slot.
Keep track of the count of Fragments received from a set of sources.
void setSlot(size_t slot, size_t val)
Set the given slot to the given value.
void incSlot(size_t slot)
Increment the given slot by one.
size_t nSlots() const
Get the number of slots this FragCounter instance is tracking.
size_t slotCount(size_t slot) const
Get the current count for the requested slot.
size_t minCount() const
Get the minimum slot count.
FragCounter()
Default Constructor.
size_t count() const
Get the total number of Fragments received.