1 #ifndef ARTDAQ_DAQRATE_TOKEN_RECEIVER_HH
2 #define ARTDAQ_DAQRATE_TOKEN_RECEIVER_HH
4 #include "artdaq/DAQrate/StatisticsHelper.hh"
5 #include "artdaq/RoutingPolicies/RoutingManagerPolicy.hh"
7 #include "fhiclcpp/types/Atom.h"
8 #include "fhiclcpp/types/Comment.h"
9 #include "fhiclcpp/types/ConfigurationTable.h"
10 #include "fhiclcpp/types/Name.h"
12 #include <boost/thread.hpp>
14 #include <sys/epoll.h>
18 #include <unordered_map>
34 fhicl::Atom<int>
routing_token_port{fhicl::Name{
"routing_token_port"}, fhicl::Comment{
"Port to listen for routing tokens on"}, 355555};
45 explicit TokenReceiver(
const fhicl::ParameterSet& ps, std::shared_ptr<RoutingManagerPolicy> policy,
46 size_t update_interval_msec);
79 void setStatsHelper(std::shared_ptr<StatisticsHelper>
const& helper, std::string
const& stat_key)
81 statsHelperPtr_ = helper;
82 tokens_received_stat_key_ = stat_key;
103 void receiveTokensLoop_();
106 std::shared_ptr<RoutingManagerPolicy> policy_;
107 size_t update_interval_msec_;
109 int token_socket_{-1};
110 std::vector<epoll_event> receive_token_events_;
111 std::unordered_map<int, std::string> receive_token_addrs_;
112 int token_epoll_fd_{-1};
114 boost::thread token_thread_;
115 std::atomic<bool> thread_is_running_;
116 std::atomic<bool> reception_is_paused_;
117 std::atomic<bool> shutdown_requested_;
118 std::atomic<uint32_t> run_number_;
120 std::atomic<size_t> received_token_count_;
121 std::unordered_map<int, size_t> received_token_counter_;
122 std::shared_ptr<StatisticsHelper> statsHelperPtr_;
123 std::string tokens_received_stat_key_;
127 #endif // ARTDAQ_DAQRATE_TOKEN_RECEIVER_HH
Configuration of the TokenReceiver. May be used for parameter validation.
fhicl::WrappedTable< Config > Parameters
Used for ParameterSet validation (if desired)
Receives event builder "free buffer" tokens and adds them to a specified RoutingPolicy.
size_t getReceivedTokenCount() const
Returns the number of tokens that have been received.
void stopTokenReception(bool force=false)
Stops the reception of event builder tokens.
void setRunNumber(uint32_t run)
Sets the current run number.
fhicl::Atom< int > routing_token_port
"routing_token_port" (Default: 35555) : Port on which routing tokens will be received ...
TokenReceiver(const fhicl::ParameterSet &ps, std::shared_ptr< RoutingManagerPolicy > policy, size_t update_interval_msec)
TokenReceiver Constructor.
void startTokenReception()
Starts the reception of event builder tokens.
void setStatsHelper(std::shared_ptr< StatisticsHelper > const &helper, std::string const &stat_key)
Specifies a StatisticsHelper instance to use when gathering statistics.
virtual ~TokenReceiver()
TokenReceiver Destructor.
void pauseTokenReception()
Temporarily suspends the reception of event builder tokens.
void resumeTokenReception()
Resumes the reception of event builder tokens after a suspension.