CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes
InputFile Class Reference

#include <FedRawDataInputSource.h>

Inheritance diagram for InputFile:
RawInputFile

Public Member Functions

bool advance (unsigned char *&dataPosition, const size_t size)
 
void appendFile (std::string const &name, uint64_t size)
 
uint64_t currentChunkSize () const
 
 InputFile (evf::EvFDaqDirector::FileStatus status, unsigned int lumi=0, std::string const &name=std::string(), bool deleteFile=true, int rawFd=-1, uint64_t fileSize=0, uint16_t rawHeaderSize=0, uint16_t nChunks=0, int nEvents=0, FedRawDataInputSource *parent=nullptr)
 
void moveToPreviousChunk (const size_t size, const size_t offset)
 
void randomizeOrder (std::default_random_engine &rng)
 
void rewindChunk (const size_t size)
 
void setChunks (uint16_t nChunks)
 
void unsetDeleteFile ()
 
bool waitForChunk (unsigned int chunkid)
 
virtual ~InputFile ()
 

Public Attributes

std::vector< uint64_t > bufferOffsets_
 
uint32_t bufferPosition_ = 0
 
uint32_t chunkPosition_ = 0
 
tbb::concurrent_vector< InputChunk * > chunks_
 
unsigned int currentChunk_ = 0
 
bool deleteFile_
 
std::vector< uint64_t > diskFileSizes_
 
std::string fileName_
 
std::vector< std::string > fileNames_
 
std::vector< unsigned int > fileOrder_
 
uint64_t fileSize_
 
std::vector< uint64_t > fileSizes_
 
unsigned int lumi_
 
uint16_t nChunks_
 
int nEvents_
 
unsigned int nProcessed_
 
uint16_t numFiles_
 
FedRawDataInputSourceparent_
 
int rawFd_
 
uint16_t rawHeaderSize_
 
evf::EvFDaqDirector::FileStatus status_
 

Detailed Description

Definition at line 224 of file FedRawDataInputSource.h.

Constructor & Destructor Documentation

◆ InputFile()

InputFile::InputFile ( evf::EvFDaqDirector::FileStatus  status,
unsigned int  lumi = 0,
std::string const &  name = std::string(),
bool  deleteFile = true,
int  rawFd = -1,
uint64_t  fileSize = 0,
uint16_t  rawHeaderSize = 0,
uint16_t  nChunks = 0,
int  nEvents = 0,
FedRawDataInputSource parent = nullptr 
)
inline

Definition at line 251 of file FedRawDataInputSource.h.

References bufferOffsets_, chunks_, diskFileSizes_, fileNames_, fileOrder_, fileSizes_, mps_fire::i, Skims_PA_cff::name, and nChunks_.

261  : parent_(parent),
262  status_(status),
263  lumi_(lumi),
264  fileName_(name),
265  deleteFile_(deleteFile),
266  rawFd_(rawFd),
267  fileSize_(fileSize),
268  rawHeaderSize_(rawHeaderSize),
269  nChunks_(nChunks),
270  numFiles_(1),
271  nEvents_(nEvents),
272  nProcessed_(0) {
273  fileNames_.push_back(name);
274  fileOrder_.push_back(fileOrder_.size());
275  diskFileSizes_.push_back(fileSize);
276  fileSizes_.push_back(0);
277  bufferOffsets_.push_back(0);
278  chunks_.reserve(nChunks_);
279  for (unsigned int i = 0; i < nChunks; i++)
280  chunks_.push_back(nullptr);
281  }
std::vector< uint64_t > fileSizes_
std::vector< std::string > fileNames_
FedRawDataInputSource * parent_
std::vector< uint64_t > bufferOffsets_
uint16_t rawHeaderSize_
evf::EvFDaqDirector::FileStatus status_
tbb::concurrent_vector< InputChunk * > chunks_
unsigned int nProcessed_
unsigned int lumi_
std::vector< unsigned int > fileOrder_
std::vector< uint64_t > diskFileSizes_
std::string fileName_

◆ ~InputFile()

InputFile::~InputFile ( )
virtual

Definition at line 1481 of file FedRawDataInputSource.cc.

References deleteFile_, cppFunctionSkipper::exception, MillePedeFileConverter_cfg::fileName, fileNames_, dt4ml_dqm_sourceclient-live_cfg::filePath, LogDebug, castor_dqm_sourceclient_file_cfg::path, rawFd_, and MatrixUtil::remove().

1481  {
1482  if (rawFd_ != -1)
1483  close(rawFd_);
1484 
1485  if (deleteFile_) {
1486  for (auto& fileName : fileNames_) {
1487  if (!fileName.empty()) {
1489  try {
1490  //sometimes this fails but file gets deleted
1491  LogDebug("FedRawDataInputSource:InputFile") << "Deleting input file -:" << fileName;
1493  continue;
1494  } catch (const std::filesystem::filesystem_error& ex) {
1495  edm::LogError("FedRawDataInputSource:InputFile")
1496  << " - deleteFile BOOST FILESYSTEM ERROR CAUGHT -: " << ex.what() << ". Trying again.";
1497  } catch (std::exception& ex) {
1498  edm::LogError("FedRawDataInputSource:InputFile")
1499  << " - deleteFile std::exception CAUGHT -: " << ex.what() << ". Trying again.";
1500  }
1502  }
1503  }
1504  }
1505 }
std::vector< std::string > fileNames_
Log< level::Error, false > LogError
def remove(d, key, TELL=False)
Definition: MatrixUtil.py:223
#define LogDebug(id)

Member Function Documentation

◆ advance()

bool InputFile::advance ( unsigned char *&  dataPosition,
const size_t  size 
)
inline

Definition at line 1427 of file FedRawDataInputSource.cc.

References cms::cuda::assert(), bufferPosition_, chunkPosition_, chunks_, currentChunk_, FedRawDataInputSource::exceptionState(), evf::FastMonState::inChunkReceived, evf::FastMonState::inWaitChunk, parent_, FedRawDataInputSource::setMonState(), findQualityFiles::size, FedRawDataInputSource::threadError(), and waitForChunk().

1427  {
1428  //wait for chunk
1429 
1430  while (!waitForChunk(currentChunk_)) {
1432  usleep(100000);
1434  if (parent_->exceptionState())
1435  parent_->threadError();
1436  }
1437 
1438  dataPosition = chunks_[currentChunk_]->buf_ + chunkPosition_;
1439  size_t currentLeft = chunks_[currentChunk_]->size_ - chunkPosition_;
1440 
1441  if (currentLeft < size) {
1442  //we need next chunk
1443  while (!waitForChunk(currentChunk_ + 1)) {
1445  usleep(100000);
1447  if (parent_->exceptionState())
1448  parent_->threadError();
1449  }
1450  //copy everything to beginning of the first chunk
1451  dataPosition -= chunkPosition_;
1452  assert(dataPosition == chunks_[currentChunk_]->buf_);
1453  memmove(chunks_[currentChunk_]->buf_, chunks_[currentChunk_]->buf_ + chunkPosition_, currentLeft);
1454  memcpy(chunks_[currentChunk_]->buf_ + currentLeft, chunks_[currentChunk_ + 1]->buf_, size - currentLeft);
1455  //set pointers at the end of the old data position
1456  bufferPosition_ += size;
1457  chunkPosition_ = size - currentLeft;
1458  currentChunk_++;
1459  return true;
1460  } else {
1461  chunkPosition_ += size;
1462  bufferPosition_ += size;
1463  return false;
1464  }
1465 }
size
Write out results.
FedRawDataInputSource * parent_
assert(be >=bs)
bool waitForChunk(unsigned int chunkid)
void setMonState(evf::FastMonState::InputState state)
tbb::concurrent_vector< InputChunk * > chunks_
uint32_t chunkPosition_
unsigned int currentChunk_
uint32_t bufferPosition_

◆ appendFile()

void InputFile::appendFile ( std::string const &  name,
uint64_t  size 
)
inline

Definition at line 292 of file FedRawDataInputSource.h.

References bufferOffsets_, diskFileSizes_, fileNames_, fileOrder_, fileSizes_, Skims_PA_cff::name, numFiles_, and findQualityFiles::size.

292  {
293  size_t prevOffset = bufferOffsets_.back();
294  size_t prevSize = diskFileSizes_.back();
295  numFiles_++;
296  fileNames_.push_back(name);
297  fileOrder_.push_back(fileOrder_.size());
298  diskFileSizes_.push_back(size);
299  fileSizes_.push_back(0);
300  bufferOffsets_.push_back(prevOffset + prevSize);
301  }
size
Write out results.
std::vector< uint64_t > fileSizes_
std::vector< std::string > fileNames_
std::vector< uint64_t > bufferOffsets_
std::vector< unsigned int > fileOrder_
std::vector< uint64_t > diskFileSizes_

◆ currentChunkSize()

uint64_t InputFile::currentChunkSize ( ) const
inline

Definition at line 314 of file FedRawDataInputSource.h.

References chunks_, and currentChunk_.

314 { return chunks_[currentChunk_]->size_; }
tbb::concurrent_vector< InputChunk * > chunks_
unsigned int currentChunk_

◆ moveToPreviousChunk()

void InputFile::moveToPreviousChunk ( const size_t  size,
const size_t  offset 
)

Definition at line 1467 of file FedRawDataInputSource.cc.

References cms::cuda::assert(), bufferPosition_, chunkPosition_, chunks_, currentChunk_, hltrates_dqm_sourceclient-live_cfg::offset, and findQualityFiles::size.

1467  {
1468  //this will fail in case of events that are too large
1470  assert(size - offset < chunks_[currentChunk_]->size_);
1471  memcpy(chunks_[currentChunk_ - 1]->buf_ + offset, chunks_[currentChunk_]->buf_ + chunkPosition_, size);
1472  chunkPosition_ += size;
1473  bufferPosition_ += size;
1474 }
size
Write out results.
assert(be >=bs)
tbb::concurrent_vector< InputChunk * > chunks_
uint32_t chunkPosition_
unsigned int currentChunk_
uint32_t bufferPosition_

◆ randomizeOrder()

void InputFile::randomizeOrder ( std::default_random_engine &  rng)
inline

Definition at line 311 of file FedRawDataInputSource.h.

References fileOrder_, and emtf::shuffle().

311  {
312  std::shuffle(std::begin(fileOrder_), std::end(fileOrder_), rng);
313  }
std::vector< unsigned int > fileOrder_
bidiiter shuffle(bidiiter begin, bidiiter end, size_t num_random)
Definition: Utilities.h:27

◆ rewindChunk()

void InputFile::rewindChunk ( const size_t  size)

Definition at line 1476 of file FedRawDataInputSource.cc.

References bufferPosition_, chunkPosition_, and findQualityFiles::size.

1476  {
1477  chunkPosition_ -= size;
1478  bufferPosition_ -= size;
1479 }
size
Write out results.
uint32_t chunkPosition_
uint32_t bufferPosition_

◆ setChunks()

void InputFile::setChunks ( uint16_t  nChunks)
inline

Definition at line 284 of file FedRawDataInputSource.h.

References chunks_, mps_fire::i, and nChunks_.

284  {
285  nChunks_ = nChunks;
286  chunks_.clear();
287  chunks_.reserve(nChunks_);
288  for (unsigned int i = 0; i < nChunks_; i++)
289  chunks_.push_back(nullptr);
290  }
tbb::concurrent_vector< InputChunk * > chunks_

◆ unsetDeleteFile()

void InputFile::unsetDeleteFile ( )
inline

Definition at line 310 of file FedRawDataInputSource.h.

References deleteFile_.

310 { deleteFile_ = false; }

◆ waitForChunk()

bool InputFile::waitForChunk ( unsigned int  chunkid)
inline

Definition at line 303 of file FedRawDataInputSource.h.

References chunks_.

Referenced by RawInputFile::advance(), and advance().

303  {
304  //some atomics to make sure everything is cache synchronized for the main thread
305  return chunks_[chunkid] != nullptr && chunks_[chunkid]->readComplete_;
306  }
tbb::concurrent_vector< InputChunk * > chunks_

Member Data Documentation

◆ bufferOffsets_

std::vector<uint64_t> InputFile::bufferOffsets_

Definition at line 233 of file FedRawDataInputSource.h.

Referenced by appendFile(), and InputFile().

◆ bufferPosition_

uint32_t InputFile::bufferPosition_ = 0

◆ chunkPosition_

uint32_t InputFile::chunkPosition_ = 0

◆ chunks_

tbb::concurrent_vector<InputChunk*> InputFile::chunks_

◆ currentChunk_

unsigned int InputFile::currentChunk_ = 0

◆ deleteFile_

bool InputFile::deleteFile_

Definition at line 236 of file FedRawDataInputSource.h.

Referenced by unsetDeleteFile(), and ~InputFile().

◆ diskFileSizes_

std::vector<uint64_t> InputFile::diskFileSizes_

Definition at line 232 of file FedRawDataInputSource.h.

Referenced by appendFile(), and InputFile().

◆ fileName_

std::string InputFile::fileName_

Definition at line 229 of file FedRawDataInputSource.h.

◆ fileNames_

std::vector<std::string> InputFile::fileNames_

Definition at line 231 of file FedRawDataInputSource.h.

Referenced by appendFile(), InputFile(), and ~InputFile().

◆ fileOrder_

std::vector<unsigned int> InputFile::fileOrder_

Definition at line 235 of file FedRawDataInputSource.h.

Referenced by appendFile(), InputFile(), and randomizeOrder().

◆ fileSize_

uint64_t InputFile::fileSize_

Definition at line 238 of file FedRawDataInputSource.h.

◆ fileSizes_

std::vector<uint64_t> InputFile::fileSizes_

Definition at line 234 of file FedRawDataInputSource.h.

Referenced by appendFile(), and InputFile().

◆ lumi_

unsigned int InputFile::lumi_

Definition at line 228 of file FedRawDataInputSource.h.

◆ nChunks_

uint16_t InputFile::nChunks_

Definition at line 240 of file FedRawDataInputSource.h.

Referenced by InputFile(), and setChunks().

◆ nEvents_

int InputFile::nEvents_

Definition at line 242 of file FedRawDataInputSource.h.

◆ nProcessed_

unsigned int InputFile::nProcessed_

Definition at line 243 of file FedRawDataInputSource.h.

◆ numFiles_

uint16_t InputFile::numFiles_

Definition at line 241 of file FedRawDataInputSource.h.

Referenced by appendFile().

◆ parent_

FedRawDataInputSource* InputFile::parent_

Definition at line 226 of file FedRawDataInputSource.h.

Referenced by advance().

◆ rawFd_

int InputFile::rawFd_

Definition at line 237 of file FedRawDataInputSource.h.

Referenced by ~InputFile().

◆ rawHeaderSize_

uint16_t InputFile::rawHeaderSize_

Definition at line 239 of file FedRawDataInputSource.h.

◆ status_

evf::EvFDaqDirector::FileStatus InputFile::status_

Definition at line 227 of file FedRawDataInputSource.h.