10 #include <framework/pcore/MsgHandler.h>
11 #include <framework/logging/Logger.h>
23 const static int c_maxObjectSizeBytes = 50000000;
26 MsgHandler::MsgHandler(
int complevel):
29 m_msg(new TMessage(kMESS_OBJECT))
35 TMessage::EnableSchemaEvolutionForAll();
36 m_msg->SetWriteMode();
49 m_msg->WriteObject(obj);
51 int len =
m_msg->Length();
52 char* buf =
m_msg->Buffer();
54 if (len > c_maxObjectSizeBytes) {
55 B2WARNING(
"MsgHandler: Object " << name <<
" is very large (" << len <<
" bytes), parallel processing may be slow.");
59 UInt_t nameLength = name.size() + 1;
60 m_buf.
add(&nameLength,
sizeof(nameLength));
70 if (rectype == MSG_TERMINATE) {
71 auto* eod =
new EvtMessage(
nullptr, 0, rectype);
77 unsigned int flags = 0;
85 int irep{0}, nin{(int)
m_buf.
size()}, nout{nin};
87 (ROOT::RCompressionSetting::EAlgorithm::EValues) algorithm);
90 if (irep > 0 && irep <= nin) {
100 auto* evtmsg =
new EvtMessage(buf->data(), buf->size(), rectype);
101 evtmsg->setMsgFlags(flags);
108 vector<string>& namelist)
110 const char* msgptr = msg->
msg();
111 const char* end = msgptr + msg->
msg_size();
116 int nzip{0}, nout{0};
118 auto* zipptr = (
unsigned char*) msgptr;
120 while (zipptr < (
unsigned char*)end) {
122 if (R__unzip_header(&nzip, zipptr, &nout) != 0) {
123 B2FATAL(
"Cannot uncompress message header");
127 if (std::distance(zipptr, (
unsigned char*) end) > nzip) {
128 B2FATAL(
"Not enough bytes left to uncompress");
135 R__unzip(&nzip, zipptr, &nout, (
unsigned char*)(
m_compBuf.
data() + old_size), &irep);
138 B2FATAL(
"Cannot uncompress message");
148 while (msgptr < end) {
151 memcpy(&nameLength, msgptr,
sizeof(nameLength));
152 msgptr +=
sizeof(nameLength);
153 if (nameLength == 0 || std::distance(msgptr, end) < nameLength)
154 B2FATAL(
"Buffer overrun while decoding object name, check length fields!");
157 namelist.emplace_back(msgptr, nameLength - 1);
158 msgptr += nameLength;
162 memcpy(&objlen, msgptr,
sizeof(objlen));
163 msgptr +=
sizeof(objlen);
164 if (objlen == 0 || std::distance(msgptr, end) < objlen)
165 B2FATAL(
"Buffer overrun while decoding object, check length fields!");