@@ -338,6 +338,60 @@ void DataProcessingHelpers::routeForwardedMessages(FairMQDeviceProxy& proxy, std
338338 }
339339}
340340
341+ void DataProcessingHelpers::cleanForwardedMessages (std::span<fair::mq::MessagePtr>& messages, bool consume)
342+ {
343+ size_t pi = 0 ;
344+ while (pi < messages.size ()) {
345+ auto & header = messages[pi];
346+
347+ // If is now possible that the record is not complete when
348+ // we forward it, because of a custom completion policy.
349+ // this means that we need to skip the empty entries in the
350+ // record for being forwarded.
351+ if (header->GetData () == nullptr ||
352+ o2::header::get<DomainInfoHeader*>(header->GetData ()) ||
353+ o2::header::get<SourceInfoHeader*>(header->GetData ())) {
354+ pi += 2 ;
355+ continue ;
356+ }
357+
358+ auto dph = o2::header::get<DataProcessingHeader*>(header->GetData ());
359+ auto dh = o2::header::get<o2::header::DataHeader*>(header->GetData ());
360+
361+ if (dph == nullptr || dh == nullptr ) {
362+ // Complain only if this is not an out-of-band message
363+ LOGP (error, " Data is missing {}{}{}" ,
364+ dph ? " DataProcessingHeader" : " " , dph || dh ? " and" : " " , dh ? " DataHeader" : " " );
365+ pi += 2 ;
366+ continue ;
367+ }
368+
369+ // At least one payload.
370+ auto & payload = messages[pi + 1 ];
371+ // Calculate the number of messages which should be handled together
372+ // all in one go.
373+ size_t numberOfMessages = 0 ;
374+ if (dh->splitPayloadParts > 0 && dh->splitPayloadParts == dh->splitPayloadIndex ) {
375+ // Sequence of (header, payload[0], ... , payload[splitPayloadParts - 1]) pairs belonging together.
376+ numberOfMessages = dh->splitPayloadParts + 1 ; // one is for the header
377+ } else {
378+ // Sequence of splitPayloadParts (header, payload) pairs belonging together.
379+ // In case splitPayloadParts = 0, we consider this as a single message pair
380+ numberOfMessages = (dh->splitPayloadParts > 0 ? dh->splitPayloadParts : 1 ) * 2 ;
381+ }
382+
383+ if (payload.get () == nullptr && consume == true ) {
384+ // If the payload is not there, it means we already
385+ // processed it with ConsumeExisiting. Therefore we
386+ // need to do something only if this is the last consume.
387+ header.reset (nullptr );
388+ }
389+
390+ // Nothing to forward go to the next messageset
391+ pi += numberOfMessages;
392+ }
393+ }
394+
341395auto DataProcessingHelpers::routeForwardedMessageSet (FairMQDeviceProxy& proxy,
342396 std::vector<MessageSet>& currentSetOfInputs,
343397 const bool copyByDefault, bool consume) -> std::vector<fair::mq::Parts>
0 commit comments