Skip to content

Commit 6688f2d

Browse files
authored
Merge pull request #49312 from smorovic/160x-buffer-size-fix
[DAQ] large input source buffer fix
2 parents f587f6e + 4340463 commit 6688f2d

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

EventFilter/Utilities/interface/FedRawDataInputSource.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ class FedRawDataInputSource : public edm::RawInputSource {
8888

8989
std::string defPath_;
9090

91+
unsigned int paramChunkSize_; // chunk size in MB
92+
unsigned int paramBlockSize_; // read/write block size in MB
9193
unsigned int eventChunkSize_; // for buffered read-ahead
9294
unsigned int eventChunkBlock_; // how much read(2) asks at the time
9395
unsigned int readBlocks_;

EventFilter/Utilities/interface/SourceRawFile.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ class InputFile {
107107

108108
tbb::concurrent_vector<InputChunk*> chunks_;
109109

110-
uint32_t bufferPosition_ = 0;
111-
uint32_t chunkPosition_ = 0;
110+
uint64_t bufferPosition_ = 0;
111+
uint64_t chunkPosition_ = 0;
112112
unsigned int currentChunk_ = 0;
113113

114114
InputFile(evf::EvFDaqDirector::FileStatus status,

EventFilter/Utilities/src/FedRawDataInputSource.cc

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ using namespace edm::streamer;
5353
FedRawDataInputSource::FedRawDataInputSource(edm::ParameterSet const& pset, edm::InputSourceDescription const& desc)
5454
: edm::RawInputSource(pset, desc),
5555
defPath_(pset.getUntrackedParameter<std::string>("buDefPath", "")),
56-
eventChunkSize_(pset.getUntrackedParameter<unsigned int>("eventChunkSize", 32) * 1048576),
57-
eventChunkBlock_(pset.getUntrackedParameter<unsigned int>("eventChunkBlock", 32) * 1048576),
56+
paramChunkSize_(pset.getUntrackedParameter<unsigned int>("eventChunkSize", 32)),
57+
paramBlockSize_(pset.getUntrackedParameter<unsigned int>("eventChunkBlock", 32)),
5858
numConcurrentReads_(pset.getUntrackedParameter<int>("numConcurrentReads", -1)),
5959
numBuffers_(pset.getUntrackedParameter<unsigned int>("numBuffers", 2)),
6060
maxBufferedFiles_(pset.getUntrackedParameter<unsigned int>("maxBufferedFiles", 2)),
@@ -77,6 +77,17 @@ FedRawDataInputSource::FedRawDataInputSource(edm::ParameterSet const& pset, edm:
7777
eventsThisLumi_(0) {
7878
char thishost[256];
7979
gethostname(thishost, 255);
80+
81+
//ensure 32-bit buffer limits
82+
if (paramChunkSize_ > 4095)
83+
throw cms::Exception("FedRawDataInputSource::fillFEDRawDataCollection")
84+
<< "Invalid chunk size of " << paramChunkSize_ << " MB. Only less than 4GB is supported.";
85+
if (paramBlockSize_ > 4095)
86+
throw cms::Exception("FedRawDataInputSource::fillFEDRawDataCollection")
87+
<< "Invalid block size of " << paramBlockSize_ << " MB. Only less than 4GB is supported.";
88+
eventChunkSize_ = paramChunkSize_ << 20;
89+
eventChunkBlock_ = paramBlockSize_ << 20;
90+
8091
edm::LogInfo("FedRawDataInputSource") << "Construction. read-ahead chunk size -: " << std::endl
8192
<< (eventChunkSize_ / 1048576) << " MB on host " << thishost;
8293

@@ -476,6 +487,13 @@ inline evf::EvFDaqDirector::FileStatus FedRawDataInputSource::getNextEvent() {
476487
//advance buffer position to skip file header (chunk will be acquired later)
477488
currentFile_->chunkPosition_ += currentFile_->rawHeaderSize_;
478489
currentFile_->bufferPosition_ += currentFile_->rawHeaderSize_;
490+
491+
if (currentFile_->chunkPosition_ > UINT32_MAX)
492+
throw cms::Exception("FedRawDataInputSource::getNextEvent")
493+
<< "chunkPosition_ overflow " << currentFile_->chunkPosition_;
494+
if (currentFile_->bufferPosition_ > UINT32_MAX)
495+
throw cms::Exception("FedRawDataInputSource::getNextEvent")
496+
<< "bufferPosition_ overflow " << currentFile_->bufferPosition_;
479497
}
480498

481499
//file is too short
@@ -532,7 +550,12 @@ inline evf::EvFDaqDirector::FileStatus FedRawDataInputSource::getNextEvent() {
532550
chunkIsFree_ = true;
533551
} else {
534552
//header was contiguous, but check if payload fits the chunk
535-
if (eventChunkSize_ - currentFile_->chunkPosition_ < msgSize) {
553+
554+
if (currentFile_->chunkPosition_ > UINT32_MAX)
555+
throw cms::Exception("FedRawDataInputSource::getNextEvent")
556+
<< "chunkPosition_ overflow " << currentFile_->chunkPosition_;
557+
558+
if (eventChunkSize_ - (uint32_t)currentFile_->chunkPosition_ < msgSize) {
536559
//rewind to header start position
537560
currentFile_->rewindChunk(FRDHeaderVersionSize[detectedFRDversion_]);
538561
//copy event to a chunk start and move pointers
@@ -1528,12 +1551,17 @@ void FedRawDataInputSource::readNextChunkIntoBuffer(InputFile* file) {
15281551
}
15291552
} else {
15301553
//event didn't fit in last chunk, so leftover must be moved to the beginning and completed
1531-
uint32_t existingSizeLeft = eventChunkSize_ - file->chunkPosition_;
1554+
1555+
if (file->chunkPosition_ > UINT32_MAX)
1556+
throw cms::Exception("FedRawDataInputSource::readNextChunkIntoBuffer")
1557+
<< "chunkPosition_ overflow " << file->chunkPosition_;
1558+
1559+
uint32_t existingSizeLeft = eventChunkSize_ - (uint32_t)file->chunkPosition_;
15321560
memmove((void*)file->chunks_[0]->buf_, file->chunks_[0]->buf_ + file->chunkPosition_, existingSizeLeft);
15331561

15341562
//calculate amount of data that can be added
1535-
const uint32_t blockcount = file->chunkPosition_ / eventChunkBlock_;
1536-
const uint32_t leftsize = file->chunkPosition_ % eventChunkBlock_;
1563+
const uint32_t blockcount = (uint32_t)file->chunkPosition_ / eventChunkBlock_;
1564+
const uint32_t leftsize = (uint32_t)file->chunkPosition_ % eventChunkBlock_;
15371565

15381566
for (uint32_t i = 0; i < blockcount; i++) {
15391567
const ssize_t last =

0 commit comments

Comments
 (0)