Skip to content

Commit 480cccb

Browse files
hahassan7shahor02
authored andcommitted
[EMCAL-650] carryOverMethod writing RCUtrailer only on last page
1 parent 28e1f2e commit 480cccb

File tree

1 file changed

+12
-23
lines changed

1 file changed

+12
-23
lines changed

Detectors/EMCAL/simulation/src/RawWriter.cxx

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -301,32 +301,21 @@ int RawWriter::carryOverMethod(const header::RDHAny* rdh, const gsl::span<char>
301301
const char* ptr, int maxSize, int splitID,
302302
std::vector<char>& trailer, std::vector<char>& header) const
303303
{
304-
int offs = ptr - &data[0]; // offset wrt the head of the payload
305-
// make sure ptr and end of the suggested block are within the payload
306-
assert(offs >= 0 && size_t(offs + maxSize) <= data.size());
307304

308-
// Read trailer template from the end of payload
305+
int bytesLeft = data.data() + data.size() - ptr;
306+
int leftAfterSplit = bytesLeft - maxSize;
307+
309308
gsl::span<const uint32_t> payloadwords(reinterpret_cast<const uint32_t*>(data.data()), data.size() / sizeof(uint32_t));
310309
auto rcutrailer = RCUTrailer::constructFromPayloadWords(payloadwords);
310+
int trailerSize = rcutrailer.getTrailerSize() * sizeof(uint32_t);
311+
312+
int Margin = 0;
311313

312-
int sizeNoTrailer = maxSize - rcutrailer.getTrailerSize() * sizeof(uint32_t);
313-
// calculate payload size for RCU trailer:
314-
// assume actualsize is in byte
315-
// Payload size is defined as the number of 32-bit payload words
316-
// -> actualSize to be converted to size of 32 bit words
317-
auto payloadsize = sizeNoTrailer / sizeof(uint32_t);
318-
rcutrailer.setPayloadSize(payloadsize);
319-
auto trailerwords = rcutrailer.encode();
320-
trailer.resize(trailerwords.size() * sizeof(uint32_t));
321-
memcpy(trailer.data(), trailerwords.data(), trailer.size());
322-
// Size to return differs between intermediate pages and last page
323-
// - intermediate page: Size of the trailer needs to be removed as the trailer gets appended
324-
// - last page: Size of the trailer needs to be included as the trailer gets replaced
325-
int bytesLeft = data.size() - (ptr - &data[0]);
326-
bool lastPage = bytesLeft <= maxSize;
327-
int actualSize = maxSize;
328-
if (!lastPage) {
329-
actualSize = sizeNoTrailer;
314+
if (leftAfterSplit < trailerSize + Margin) {
315+
316+
// 0 will force closing current page and carrying the rest on new one
317+
return std::max(0, bytesLeft - (trailerSize + Margin));
330318
}
331-
return actualSize;
319+
320+
return maxSize;
332321
}

0 commit comments

Comments
 (0)