Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
Poller.h
Go to the documentation of this file.
1/*
2 * Project: RooFit
3 * Authors:
4 * Jonas Rembser, CERN 2026
5 *
6 * Copyright (c) 2026, CERN
7 *
8 * Redistribution and use in source and binary forms,
9 * with or without modification, are permitted according to the terms
10 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)
11 */
12#ifndef ROOT_ROOFIT_MultiProcess_Poller
13#define ROOT_ROOFIT_MultiProcess_Poller
14
16
17#include <cstddef>
18#include <stdexcept>
19#include <vector>
20
21namespace RooFit {
22namespace MultiProcess {
23
24/// \class Poller
25/// \brief Waits for input on a set of registered Channels
26///
27/// Replacement for the ZeroMQPoller: channels get a stable index in
28/// registration order, poll() returns the indices of the channels that have
29/// input available, and channels can be unregistered without changing the
30/// indices of the others.
31///
32/// The Poller stores plain pointers, so registered Channel objects must stay
33/// at their memory location while the Poller is in use.
34class Poller {
35public:
36 /// Register a channel for input polling; returns its stable index.
37 std::size_t register_channel(const Channel &channel)
38 {
39 entries_.emplace_back(next_index_++, &channel);
40 return entries_.back().first;
41 }
42
43 void unregister_channel(const Channel &channel)
44 {
45 for (auto it = entries_.begin(); it != entries_.end(); ++it) {
46 if (it->second == &channel) {
47 entries_.erase(it);
48 return;
49 }
50 }
51 throw std::runtime_error("Poller::unregister_channel: channel not registered");
52 }
53
54 std::size_t size() const { return entries_.size(); }
55
56 /// Wait for input; returns the registration indices of readable channels.
57 /// Throws ppoll_error_t with num() == EINTR when a SIGTERM was received.
58 std::vector<std::size_t> poll(int timeout_ms = -1) const
59 {
60 if (entries_.empty() && timeout_ms < 0) {
61 throw std::logic_error("Poller::poll: waiting without timeout on a poller with no registered channels");
62 }
63 std::vector<const Channel *> channels;
64 channels.reserve(entries_.size());
65 for (auto &entry : entries_) {
66 channels.push_back(entry.second);
67 }
68 std::vector<std::size_t> result;
69 for (std::size_t pos : Channel::wait(channels, timeout_ms)) {
70 result.push_back(entries_[pos].first);
71 }
72 return result;
73 }
74
75private:
76 std::vector<std::pair<std::size_t, const Channel *>> entries_;
77 std::size_t next_index_ = 0;
78};
79
80} // namespace MultiProcess
81} // namespace RooFit
82
83#endif // ROOT_ROOFIT_MultiProcess_Poller
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
One endpoint of a full-duplex interprocess message pipe.
Definition Channel.h:55
static std::vector< std::size_t > wait(const std::vector< const Channel * > &read_channels, int timeout_ms)
Wait until at least one of read_channels has input available, flushing the pending output of all live...
Definition Channel.cxx:264
Waits for input on a set of registered Channels.
Definition Poller.h:34
std::vector< std::pair< std::size_t, const Channel * > > entries_
Definition Poller.h:76
void unregister_channel(const Channel &channel)
Definition Poller.h:43
std::vector< std::size_t > poll(int timeout_ms=-1) const
Wait for input; returns the registration indices of readable channels.
Definition Poller.h:58
std::size_t size() const
Definition Poller.h:54
std::size_t register_channel(const Channel &channel)
Register a channel for input polling; returns its stable index.
Definition Poller.h:37
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition CodegenImpl.h:73