CMS 3D CMS Logo

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

#include <FedRawDataInputSource.h>

Public Member Functions

bool advance (unsigned char *&dataPosition, const size_t size)
 
int64_t fileSizeLeft () 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, uint32_t nChunks=0, int nEvents=0, FedRawDataInputSource *parent=nullptr)
 
 InputFile (std::string &name)
 
void moveToPreviousChunk (const size_t size, const size_t offset)
 
void rewindChunk (const size_t size)
 
void unsetDeleteFile ()
 
bool waitForChunk (unsigned int chunkid)
 
 ~InputFile ()
 

Public Attributes

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

Detailed Description

Definition at line 211 of file FedRawDataInputSource.h.

Constructor & Destructor Documentation

◆ InputFile() [1/2]

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,
uint32_t  nChunks = 0,
int  nEvents = 0,
FedRawDataInputSource parent = nullptr 
)
inline

Definition at line 230 of file FedRawDataInputSource.h.

References chunks_, and mps_fire::i.

240  : parent_(parent),
241  status_(status),
242  lumi_(lumi),
243  fileName_(name),
244  deleteFile_(deleteFile),
245  rawFd_(rawFd),
246  fileSize_(fileSize),
247  rawHeaderSize_(rawHeaderSize),
248  nChunks_(nChunks),
249  nEvents_(nEvents),
250  nProcessed_(0) {
251  for (unsigned int i = 0; i < nChunks; i++)
252  chunks_.push_back(nullptr);
253  }
unsigned int lumi_
evf::EvFDaqDirector::FileStatus status_
uint16_t rawHeaderSize_
FedRawDataInputSource * parent_
unsigned int nProcessed_
std::string fileName_
tbb::concurrent_vector< InputChunk * > chunks_

◆ ~InputFile()

InputFile::~InputFile ( )

Definition at line 1479 of file FedRawDataInputSource.cc.

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

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

◆ InputFile() [2/2]

InputFile::InputFile ( std::string &  name)
inline

Definition at line 256 of file FedRawDataInputSource.h.

256 : fileName_(name) {}
std::string fileName_

Member Function Documentation

◆ advance()

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

Definition at line 1424 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().

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

◆ fileSizeLeft()

int64_t InputFile::fileSizeLeft ( ) const
inline

Definition at line 266 of file FedRawDataInputSource.h.

References bufferPosition_, and fileSize_.

266 { return (int64_t)fileSize_ - (int64_t)bufferPosition_; }
uint32_t bufferPosition_

◆ moveToPreviousChunk()

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

Definition at line 1465 of file FedRawDataInputSource.cc.

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

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

◆ rewindChunk()

void InputFile::rewindChunk ( const size_t  size)
inline

Definition at line 1474 of file FedRawDataInputSource.cc.

References bufferPosition_, chunkPosition_, and findQualityFiles::size.

1474  {
1475  chunkPosition_ -= size;
1476  bufferPosition_ -= size;
1477 }
size
Write out results.
uint32_t chunkPosition_
uint32_t bufferPosition_

◆ unsetDeleteFile()

void InputFile::unsetDeleteFile ( )
inline

Definition at line 265 of file FedRawDataInputSource.h.

References deleteFile_.

265 { deleteFile_ = false; }

◆ waitForChunk()

bool InputFile::waitForChunk ( unsigned int  chunkid)
inline

Definition at line 258 of file FedRawDataInputSource.h.

References chunks_.

Referenced by advance().

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

Member Data Documentation

◆ bufferPosition_

uint32_t InputFile::bufferPosition_ = 0

Definition at line 226 of file FedRawDataInputSource.h.

Referenced by advance(), fileSizeLeft(), moveToPreviousChunk(), and rewindChunk().

◆ chunkPosition_

uint32_t InputFile::chunkPosition_ = 0

Definition at line 227 of file FedRawDataInputSource.h.

Referenced by advance(), moveToPreviousChunk(), and rewindChunk().

◆ chunks_

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

Definition at line 224 of file FedRawDataInputSource.h.

Referenced by advance(), InputFile(), moveToPreviousChunk(), and waitForChunk().

◆ currentChunk_

unsigned int InputFile::currentChunk_ = 0

Definition at line 228 of file FedRawDataInputSource.h.

Referenced by advance(), and moveToPreviousChunk().

◆ deleteFile_

bool InputFile::deleteFile_

Definition at line 216 of file FedRawDataInputSource.h.

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

◆ fileName_

std::string InputFile::fileName_

Definition at line 215 of file FedRawDataInputSource.h.

Referenced by ~InputFile().

◆ fileSize_

uint64_t InputFile::fileSize_

Definition at line 218 of file FedRawDataInputSource.h.

Referenced by fileSizeLeft().

◆ lumi_

unsigned int InputFile::lumi_

Definition at line 214 of file FedRawDataInputSource.h.

◆ nChunks_

uint32_t InputFile::nChunks_

Definition at line 220 of file FedRawDataInputSource.h.

◆ nEvents_

int InputFile::nEvents_

Definition at line 221 of file FedRawDataInputSource.h.

◆ nProcessed_

unsigned int InputFile::nProcessed_

Definition at line 222 of file FedRawDataInputSource.h.

◆ parent_

FedRawDataInputSource* InputFile::parent_

Definition at line 212 of file FedRawDataInputSource.h.

Referenced by advance().

◆ rawFd_

int InputFile::rawFd_

Definition at line 217 of file FedRawDataInputSource.h.

Referenced by ~InputFile().

◆ rawHeaderSize_

uint16_t InputFile::rawHeaderSize_

Definition at line 219 of file FedRawDataInputSource.h.

◆ status_

evf::EvFDaqDirector::FileStatus InputFile::status_

Definition at line 213 of file FedRawDataInputSource.h.