Skip to content

Commit

Permalink
* improve comments for the readBytes function
Browse files Browse the repository at this point in the history
* remove unnecessary class member
* allow zero-copy event reading because EventHeader and EventMessage consist of byte and byte array variables and non-aligned casting is safe
  • Loading branch information
smorovic committed Aug 19, 2022
1 parent 3db4eed commit 8ad3ecd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
2 changes: 0 additions & 2 deletions IOPool/Streamer/interface/StreamerInputFile.h
Expand Up @@ -87,8 +87,6 @@ namespace edm {

edm::propagate_const<std::shared_ptr<EventSkipperByID>> eventSkipperByID_;

unsigned int prefetchMBytes_;

uint32 currRun_;
uint32 currProto_;

Expand Down
14 changes: 6 additions & 8 deletions IOPool/Streamer/src/StreamerInputFile.cc
Expand Up @@ -33,7 +33,6 @@ namespace edm {
currentFileName_(),
currentFileOpen_(false),
eventSkipperByID_(eventSkipperByID),
prefetchMBytes_(prefetchMBytes),
currRun_(0),
currProto_(0),
newHeader_(false),
Expand Down Expand Up @@ -62,7 +61,6 @@ namespace edm {
currentFileName_(),
currentFileOpen_(false),
eventSkipperByID_(eventSkipperByID),
prefetchMBytes_(prefetchMBytes),
currRun_(0),
currProto_(0),
newHeader_(false),
Expand Down Expand Up @@ -124,10 +122,11 @@ namespace edm {
bool zeroCopy,
unsigned int skippedHdr) {
storage::IOSize n = 0;
//returned pointer should point to the beginning of the header
//even if we read event payload that comes afterwards
char* ptr = buf - skippedHdr;
try {
if (prefetchMBytes_) {
//assert(tempPos_ > tempLen_);
if (!tempBuf_.empty()) {
if (tempPos_ == tempLen_) {
n = storage_->read(&tempBuf_[0], tempBuf_.size());
tempPos_ = 0;
Expand All @@ -136,11 +135,12 @@ namespace edm {
return std::pair<storage::IOSize, char*>(0, ptr);
}
if (nBytes <= tempLen_ - tempPos_) {
//zero-copy can't done when header start address is in the previous buffer
if (!zeroCopy || skippedHdr > tempPos_) {
memcpy(buf, &tempBuf_[0] + tempPos_, nBytes);
tempPos_ += nBytes;
} else {
//pass pointer to the prebuffer address (zero copy)
//pass pointer to the prebuffer address (zero copy) at the beginning of the header
ptr = &tempBuf_[0] + tempPos_ - skippedHdr;
tempPos_ += nBytes;
}
Expand Down Expand Up @@ -312,9 +312,7 @@ namespace edm {
if (eventBuf_.size() < eventSize)
eventBuf_.resize(eventSize);

//set the pointer again as it can be changed by resize
//eventPtr = &eventBuf_[0];
auto res = readBytes(&eventBuf_[sizeof(EventHeader)], nWant, false, sizeof(EventHeader));
auto res = readBytes(&eventBuf_[sizeof(EventHeader)], nWant, true, sizeof(EventHeader));
if (res.first != nWant) {
throw Exception(errors::FileReadError, "StreamerInputFile::readEventMessage")
<< "Failed reading streamer file, second read in readEventMessage\n"
Expand Down

0 comments on commit 8ad3ecd

Please sign in to comment.