ATLAS Offline Software
Loading...
Searching...
No Matches
ClusterMessage Class Reference

A class describing a message sent between nodes in a cluster. More...

#include <ClusterMessage.h>

Collaboration diagram for ClusterMessage:

Classes

struct  WorkerStatus
struct  DataDescr

Public Types

using WireMsgHdr = std::array<std::uint32_t, 3>
using WireMsgBody = std::array<std::uint32_t, 10>
using WireMsg = std::tuple<WireMsgHdr, std::optional<WireMsgBody>>
using Payload_t = std::variant<std::monostate, int, WorkerStatus, DataDescr>

Public Member Functions

 ClusterMessage ()
 ClusterMessage (ClusterMessageType mType)
 ClusterMessage (ClusterMessageType mType, int payload)
 ClusterMessage (ClusterMessageType mType, WorkerStatus payload)
 ClusterMessage (ClusterMessageType mType, DataDescr &&payload)
 ClusterMessage (const WireMsg &)
WireMsg wire_msg () const

Public Attributes

int source = -1
ClusterMessageType messageType {ClusterMessageType::EMPTY}
Payload_t payload {}

Detailed Description

A class describing a message sent between nodes in a cluster.

Definition at line 31 of file ClusterMessage.h.

Member Typedef Documentation

◆ Payload_t

using ClusterMessage::Payload_t = std::variant<std::monostate, int, WorkerStatus, DataDescr>

Definition at line 83 of file ClusterMessage.h.

◆ WireMsg

using ClusterMessage::WireMsg = std::tuple<WireMsgHdr, std::optional<WireMsgBody>>

Definition at line 41 of file ClusterMessage.h.

◆ WireMsgBody

using ClusterMessage::WireMsgBody = std::array<std::uint32_t, 10>

Definition at line 39 of file ClusterMessage.h.

◆ WireMsgHdr

using ClusterMessage::WireMsgHdr = std::array<std::uint32_t, 3>

Definition at line 37 of file ClusterMessage.h.

Constructor & Destructor Documentation

◆ ClusterMessage() [1/6]

ClusterMessage::ClusterMessage ( )
default

◆ ClusterMessage() [2/6]

ClusterMessage::ClusterMessage ( ClusterMessageType mType)

Definition at line 83 of file ClusterMessage.cxx.

83 : messageType(mType) {
84 switch (mType) {
85 case ClusterMessageType::RequestEvent:
86 case ClusterMessageType::EventsDone:
87 case ClusterMessageType::EmergencyStop:
88 // OK
89 break;
90 default:
91 throw std::logic_error{std::format(
92 "Incorrect ClusterMessage constructor used for message type {}",
93 mType)};
94 }
95}
ClusterMessageType messageType

◆ ClusterMessage() [3/6]

ClusterMessage::ClusterMessage ( ClusterMessageType mType,
int payload )

Definition at line 65 of file ClusterMessage.cxx.

66 : messageType(mType), payload(payload) {
67 if (mType != ClusterMessageType::ProvideEvent) {
68 throw std::logic_error{std::format(
69 "Incorrect ClusterMessage constructor used for message type {}",
70 mType)};
71 }
72}
Payload_t payload

◆ ClusterMessage() [4/6]

ClusterMessage::ClusterMessage ( ClusterMessageType mType,
WorkerStatus payload )

Definition at line 55 of file ClusterMessage.cxx.

56 : messageType(mType), payload(payload) {
57 if (mType != ClusterMessageType::FinalWorkerStatus &&
58 mType != ClusterMessageType::WorkerError) {
59 throw std::logic_error{std::format(
60 "Incorrect ClusterMessage constructor used for message type {}",
61 mType)};
62 }
63}

◆ ClusterMessage() [5/6]

ClusterMessage::ClusterMessage ( ClusterMessageType mType,
DataDescr && payload )

Definition at line 74 of file ClusterMessage.cxx.

75 : messageType(mType), payload(std::move(payload)) {
76 if (mType != ClusterMessageType::Data) {
77 throw std::logic_error{std::format(
78 "Incorrect ClusterMessage constructor used for message type {}",
79 mType)};
80 }
81}

◆ ClusterMessage() [6/6]

ClusterMessage::ClusterMessage ( const WireMsg & wire_msg)

Definition at line 99 of file ClusterMessage.cxx.

99 {
100 const auto& [header, body] = wire_msg;
101 messageType = static_cast<ClusterMessageType>(header[0]);
102 source = header[1];
103 if (body.has_value()) {
104 const auto& body_2 = *body;
105 if (messageType == ClusterMessageType::Data) {
106 payload = DataDescr(body_2);
107 } else {
109 status.status = StatusCode(body_2[0]);
110 status.createdEvents = body_2[1];
111 status.finishedEvents = body_2[2];
112 status.skippedEvents = body_2[3];
113 payload = status;
114 }
115 } else {
116 if (messageType == ClusterMessageType::ProvideEvent) {
117 payload = int(header[2]);
118 }
119 }
120}
ClusterMessageType
::StatusCode StatusCode
StatusCode definition for legacy code.
status
Definition merge.py:16
WireMsg wire_msg() const

Member Function Documentation

◆ wire_msg()

ClusterMessage::WireMsg ClusterMessage::wire_msg ( ) const
nodiscard

Definition at line 122 of file ClusterMessage.cxx.

122 {
123 constexpr int max_tag = 16383;
124 constexpr std::uint64_t lower32 = 0xFFFFFFFF;
125
126 static thread_local int next_msg =
127 1; // This is only ever called from one thread per process
129 header[0] = std::uint32_t(messageType);
130 header[1] = source;
131 if (payload.index() == 3) {
132 next_msg = (next_msg % max_tag) + 1;
133 header[2] = next_msg;
134 WireMsgBody body{};
135 const auto& payload_local = std::get<DataDescr>(payload);
136 body[0] = std::uint32_t(std::uint64_t(payload_local.ptr) >> 32);
137 body[1] = std::uint32_t(std::uint64_t(payload_local.ptr) & lower32);
138 body[2] = std::uint32_t(std::uint64_t(payload_local.len) >> 32);
139 body[3] = std::uint32_t(std::uint64_t(payload_local.len) & lower32);
140 body[4] = std::uint32_t(std::uint64_t(payload_local.align) >> 32);
141 body[5] = std::uint32_t(std::uint64_t(payload_local.align) & lower32);
142 body[6] = std::uint32_t(std::uint64_t(payload_local.evtNumber) >> 32);
143 body[7] = std::uint32_t(std::uint64_t(payload_local.evtNumber) & lower32);
144 body[8] = std::uint32_t(std::uint64_t(payload_local.fileNumber) >> 32);
145 body[9] = std::uint32_t(std::uint64_t(payload_local.fileNumber) & lower32);
146 WireMsg msg{header, std::make_optional(body)};
147 return msg;
148 }
149 if (payload.index() == 2) {
150 next_msg = (next_msg % max_tag) + 1;
151 header[2] = next_msg;
152 WireMsgBody body{};
153 const auto& payload_local = std::get<WorkerStatus>(payload);
154 body[0] = static_cast<int>(payload_local.status.getCode());
155 body[1] = payload_local.createdEvents;
156 body[2] = payload_local.finishedEvents;
157 body[3] = payload_local.skippedEvents;
158 body[4] = body[5] = body[6] = body[7] = body[8] = body[9] = 0;
159 WireMsg msg{header, std::make_optional(body)};
160 return msg;
161 }
162 // else
163 if (payload.index() == 1) { // if we have an int payload
164 header[2] = std::get<int>(payload);
165 } else {
166 header[2] = 0;
167 }
168 WireMsg msg{header, std::nullopt};
169 return msg;
170}
std::tuple< WireMsgHdr, std::optional< WireMsgBody > > WireMsg
std::array< std::uint32_t, 3 > WireMsgHdr
std::array< std::uint32_t, 10 > WireMsgBody
MsgStream & msg
Definition testRead.cxx:32

Member Data Documentation

◆ messageType

ClusterMessageType ClusterMessage::messageType {ClusterMessageType::EMPTY}

Definition at line 44 of file ClusterMessage.h.

44{ClusterMessageType::EMPTY};

◆ payload

Payload_t ClusterMessage::payload {}

Definition at line 84 of file ClusterMessage.h.

84{};

◆ source

int ClusterMessage::source = -1

Definition at line 43 of file ClusterMessage.h.


The documentation for this class was generated from the following files: