Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
Message.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_Message
13#define ROOT_ROOFIT_MultiProcess_Message
14
15#include <cstddef>
16#include <cstring>
17#include <iterator>
18#include <ostream>
19#include <vector>
20
21namespace RooFit {
22namespace MultiProcess {
23
24/// A contiguous byte buffer used as the unit of interprocess communication.
25///
26/// This is the plain replacement for zmq::message_t: Job implementations
27/// build a Message on the sending side (e.g. from a struct or an array of
28/// doubles) and read it out via the typed data<T>() accessors on the
29/// receiving side.
30class Message {
31public:
32 Message() = default;
33 explicit Message(std::size_t size) : buf_(size) {}
34
35 /// Create a message by copying the bytes of the elements in the range
36 /// [first, last), like the equivalent zmq::message_t constructor.
37 template <typename ForwardIt>
39 {
40 using value_t = typename std::iterator_traits<ForwardIt>::value_type;
41 buf_.resize(sizeof(value_t) * std::distance(first, last));
42 char *out = buf_.data();
43 for (ForwardIt it = first; it != last; ++it) {
44 value_t const &item = *it;
45 std::memcpy(out, &item, sizeof(value_t));
46 out += sizeof(value_t);
47 }
48 }
49
50 void *data() { return buf_.data(); }
51 const void *data() const { return buf_.data(); }
52
53 template <typename T>
54 T *data()
55 {
56 return reinterpret_cast<T *>(buf_.data());
57 }
58 template <typename T>
59 const T *data() const
60 {
61 return reinterpret_cast<const T *>(buf_.data());
62 }
63
64 /// Size of the message in bytes.
65 std::size_t size() const { return buf_.size(); }
66
67private:
68 std::vector<char> buf_;
69};
70
71// for debug printing in the Messenger
72inline std::ostream &operator<<(std::ostream &out, const Message &msg)
73{
74 return out << "Message(" << msg.size() << " bytes)";
75}
76
77} // namespace MultiProcess
78} // namespace RooFit
79
80#endif // ROOT_ROOFIT_MultiProcess_Message
A contiguous byte buffer used as the unit of interprocess communication.
Definition Message.h:30
std::size_t size() const
Size of the message in bytes.
Definition Message.h:65
std::vector< char > buf_
Definition Message.h:68
Message(ForwardIt first, ForwardIt last)
Create a message by copying the bytes of the elements in the range [first, last), like the equivalent...
Definition Message.h:38
const void * data() const
Definition Message.h:51
const T * data() const
Definition Message.h:59
Message(std::size_t size)
Definition Message.h:33
std::ostream & operator<<(std::ostream &out, const Message &msg)
Definition Message.h:72
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition CodegenImpl.h:73