1 #ifndef artdaq_DAQrate_detail_FragCounter_hh
2 #define artdaq_DAQrate_detail_FragCounter_hh
7 #include <unordered_map>
37 void incSlot(
size_t slot,
size_t inc);
44 void setSlot(
size_t slot,
size_t val);
79 mutable std::mutex receipts_mutex_;
80 std::unordered_map<size_t, std::atomic<size_t>> receipts_;
98 std::unique_lock<std::mutex> lk(receipts_mutex_);
99 receipts_[slot].fetch_add(inc);
106 std::unique_lock<std::mutex> lk(receipts_mutex_);
107 receipts_[slot] = val;
114 std::unique_lock<std::mutex> lk(receipts_mutex_);
115 return receipts_.size();
122 std::unique_lock<std::mutex> lk(receipts_mutex_);
124 for (
auto& it : receipts_)
135 std::unique_lock<std::mutex> lk(receipts_mutex_);
136 return receipts_.count(slot) ? receipts_.at(slot).load() : 0;
143 std::unique_lock<std::mutex> lk(receipts_mutex_);
144 size_t min = std::numeric_limits<size_t>::max();
145 for (
auto& it : receipts_)
147 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.