CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | Friends
FedRawDataInputSource Class Reference

#include <FedRawDataInputSource.h>

Inheritance diagram for FedRawDataInputSource:
edm::RawInputSource edm::InputSource

Public Member Functions

 FedRawDataInputSource (edm::ParameterSet const &, edm::InputSourceDescription const &)
 
std::pair< bool, unsigned int > getEventReport (unsigned int lumi, bool erase)
 
 ~FedRawDataInputSource () override
 
- Public Member Functions inherited from edm::RawInputSource
 RawInputSource (ParameterSet const &pset, InputSourceDescription const &desc)
 
 ~RawInputSource () override
 
- Public Member Functions inherited from edm::InputSource
std::shared_ptr< ActivityRegistryactReg () const
 Accessor for Activity Registry. More...
 
std::shared_ptr< BranchIDListHelper const > branchIDListHelper () const
 Accessors for branchIDListHelper. More...
 
std::shared_ptr< BranchIDListHelper > & branchIDListHelper ()
 
void closeFile (FileBlock *, bool cleaningUpAfterException)
 close current file More...
 
void doBeginJob ()
 Called by framework at beginning of job. More...
 
virtual void doBeginLumi (LuminosityBlockPrincipal &lbp, ProcessContext const *)
 Called by framework at beginning of lumi block. More...
 
virtual void doBeginRun (RunPrincipal &rp, ProcessContext const *)
 Called by framework at beginning of run. More...
 
void doEndJob ()
 Called by framework at end of job. More...
 
void fillProcessBlockHelper ()
 Fill the ProcessBlockHelper with info for the current file. More...
 
ProcessingController::ForwardState forwardState () const
 
bool goToEvent (EventID const &eventID)
 
 InputSource (ParameterSet const &, InputSourceDescription const &)
 Constructor. More...
 
 InputSource (InputSource const &)=delete
 
void issueReports (EventID const &eventID, StreamID streamID)
 issue an event report More...
 
LuminosityBlockNumber_t luminosityBlock () const
 Accessor for current luminosity block number. More...
 
std::shared_ptr< LuminosityBlockAuxiliaryluminosityBlockAuxiliary () const
 Called by the framework to merge or insert lumi in principal cache. More...
 
int maxEvents () const
 
int maxLuminosityBlocks () const
 
ModuleDescription const & moduleDescription () const
 Accessor for 'module' description. More...
 
ItemType nextItemType ()
 Advances the source to the next item. More...
 
bool nextProcessBlock (ProcessBlockPrincipal &)
 Next process block, return false if there is none, sets the processName in the principal. More...
 
InputSourceoperator= (InputSource const &)=delete
 
std::shared_ptr< ProcessBlockHelper const > processBlockHelper () const
 Accessors for processBlockHelper. More...
 
std::shared_ptr< ProcessBlockHelper > & processBlockHelper ()
 
ProcessConfiguration const & processConfiguration () const
 Accessor for Process Configuration. More...
 
std::string const & processGUID () const
 Accessor for global process identifier. More...
 
ProcessHistoryRegistry const & processHistoryRegistry () const
 Accessors for process history registry. More...
 
ProcessHistoryRegistryprocessHistoryRegistry ()
 
ProcessingMode processingMode () const
 RunsLumisAndEvents (default), RunsAndLumis, or Runs. More...
 
std::shared_ptr< ProductRegistry const > productRegistry () const
 Accessors for product registry. More...
 
bool randomAccess () const
 
void readAndMergeLumi (LuminosityBlockPrincipal &lbp)
 Read next luminosity block (same as a prior lumi) More...
 
void readAndMergeRun (RunPrincipal &rp)
 Read next run (same as a prior run) More...
 
void readEvent (EventPrincipal &ep, StreamContext &)
 Read next event. More...
 
bool readEvent (EventPrincipal &ep, EventID const &, StreamContext &)
 Read a specific event. More...
 
std::shared_ptr< FileBlockreadFile ()
 Read next file. More...
 
void readLuminosityBlock (LuminosityBlockPrincipal &lumiPrincipal, HistoryAppender &historyAppender)
 Read next luminosity block (new lumi) More...
 
std::shared_ptr< LuminosityBlockAuxiliaryreadLuminosityBlockAuxiliary ()
 Read next luminosity block Auxilary. More...
 
void readProcessBlock (ProcessBlockPrincipal &)
 Read next process block. More...
 
void readRun (RunPrincipal &runPrincipal, HistoryAppender &historyAppender)
 Read next run (new run) More...
 
std::shared_ptr< RunAuxiliaryreadRunAuxiliary ()
 Read next run Auxiliary. More...
 
ProcessHistoryID const & reducedProcessHistoryID () const
 
virtual void registerProducts ()
 Register any produced products. More...
 
int remainingEvents () const
 
int remainingLuminosityBlocks () const
 
void repeat ()
 Reset the remaining number of events/lumis to the maximum number. More...
 
std::pair< SharedResourcesAcquirer *, std::recursive_mutex * > resourceSharedWithDelayedReader ()
 Returns nullptr if no resource shared between the Source and a DelayedReader. More...
 
ProcessingController::ReverseState reverseState () const
 
void rewind ()
 Begin again at the first event. More...
 
RunNumber_t run () const
 Accessor for current run number. More...
 
std::shared_ptr< RunAuxiliaryrunAuxiliary () const
 Called by the framework to merge or insert run in principal cache. More...
 
void setLuminosityBlockNumber_t (LuminosityBlockNumber_t lb)
 Set the luminosity block ID. More...
 
void setRunNumber (RunNumber_t r)
 Set the run number. More...
 
void skipEvents (int offset)
 
void switchTo (std::shared_ptr< ProductRegistry > iOther)
 switch to a different ProductRegistry. More...
 
std::shared_ptr< ThinnedAssociationsHelper const > thinnedAssociationsHelper () const
 Accessors for thinnedAssociationsHelper. More...
 
std::shared_ptr< ThinnedAssociationsHelper > & thinnedAssociationsHelper ()
 
Timestamp const & timestamp () const
 Accessor for the current time, as seen by the input source. More...
 
virtual ~InputSource () noexcept(false)
 Destructor. More...
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
- Static Public Member Functions inherited from edm::RawInputSource
static void fillDescription (ParameterSetDescription &description)
 
- Static Public Member Functions inherited from edm::InputSource
static const std::string & baseType ()
 
static void fillDescription (ParameterSetDescription &desc)
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 

Protected Member Functions

Next checkNext () override
 
void read (edm::EventPrincipal &eventPrincipal) override
 
void setMonState (evf::FastMonState::InputState state)
 
void setMonStateSup (evf::FastMonState::InputState state)
 
- Protected Member Functions inherited from edm::RawInputSource
void makeEvent (EventPrincipal &eventPrincipal, EventAuxiliary const &eventAuxiliary)
 
void setInputFileTransitionsEachEvent ()
 
- Protected Member Functions inherited from edm::InputSource
virtual void beginJob ()
 Begin protected makes it easier to do template programming. More...
 
void decreaseRemainingEventsBy (int iSkipped)
 
bool eventCached () const
 
bool newLumi () const
 
bool newRun () const
 
ProcessHistoryRegistryprocessHistoryRegistryForUpdate ()
 
ProductRegistryproductRegistryUpdate ()
 
void reset () const
 
void resetEventCached ()
 
void resetLuminosityBlockAuxiliary (bool isNewLumi=true) const
 
void resetNewLumi ()
 
void resetNewRun ()
 
void resetRunAuxiliary (bool isNewRun=true) const
 
void setEventCached ()
 Called by the framework to merge or ached() const {return eventCached_;}. More...
 
void setLuminosityBlockAuxiliary (LuminosityBlockAuxiliary *lbp)
 
void setNewLumi ()
 
void setNewRun ()
 
void setRunAuxiliary (RunAuxiliary *rp)
 
void setTimestamp (Timestamp const &theTime)
 To set the current time, as seen by the input source. More...
 
virtual void skip (int offset)
 
ItemType state () const
 

Private Types

typedef std::pair< InputFile *, InputChunk * > ReaderInfo
 

Private Member Functions

bool exceptionState ()
 
edm::Timestamp fillFEDRawDataCollection (FEDRawDataCollection &rawData, bool &tcdsInRange)
 
evf::EvFDaqDirector::FileStatus getFile (unsigned int &ls, std::string &nextFile, uint32_t &fsize, uint64_t &lockWaitTime)
 
evf::EvFDaqDirector::FileStatus getNextEvent ()
 
long initFileList ()
 
void maybeOpenNewLumiSection (const uint32_t lumiSection)
 
evf::EvFDaqDirector::FileStatus nextEvent ()
 
void readNextChunkIntoBuffer (InputFile *file)
 
void readSupervisor ()
 
void readWorker (unsigned int tid)
 
void reportEventsThisLumiInSource (unsigned int lumi, unsigned int events)
 
void rewind_ () override
 
void threadError ()
 

Private Attributes

const bool alwaysStartFromFirstLS_
 
uint32_t bufferInputRead_ = 0
 
unsigned int checkEvery_ = 10
 
bool chunkIsFree_ = false
 
std::unique_ptr< InputFilecurrentFile_
 
int currentFileIndex_ = -1
 
unsigned int currentLumiSection_
 
std::vector< std::unique_ptr< std::condition_variable > > cvReader_
 
std::condition_variable cvWakeup_
 
evf::EvFDaqDirectordaqDirector_ = nullptr
 
const edm::DaqProvenanceHelper daqProvenanceHelper_
 
std::string defPath_
 
uint16_t detectedFRDversion_ = 0
 
std::unique_ptr< FRDEventMsgViewevent_
 
unsigned int eventChunkBlock_
 
unsigned int eventChunkSize_
 
edm::EventID eventID_
 
uint32_t eventRunNumber_ = 0
 
unsigned int eventsThisLumi_
 
unsigned long eventsThisRun_ = 0
 
std::mutex fileDeleteLock_
 
int fileDescriptor_ = -1
 
unsigned int fileListIndex_ = 0
 
const bool fileListLoopMode_
 
const bool fileListMode_
 
std::vector< std::string > fileNames_
 
std::list< std::pair< int, std::string > > fileNamesToDelete_
 
tbb::concurrent_queue< std::unique_ptr< InputFile > > fileQueue_
 
std::list< std::pair< int, std::unique_ptr< InputFile > > > filesToDelete_
 
evf::FastMonitoringServicefms_ = nullptr
 
tbb::concurrent_queue< InputChunk * > freeChunks_
 
std::string fuOutputDir_
 
const bool getLSFromFilename_
 
uint32_t GTPEventID_ = 0
 
uint32_t L1EventID_ = 0
 
unsigned int loopModeIterationInc_ = 0
 
unsigned int maxBufferedFiles_
 
uint16_t MAXTCDSuTCAFEDID_ = FEDNumbering::MAXTCDSuTCAFEDID
 
uint16_t MINTCDSuTCAFEDID_ = FEDNumbering::MINTCDSuTCAFEDID
 
std::mutex monlock_
 
std::mutex mReader_
 
std::mutex mWakeup_
 
unsigned int numBuffers_
 
unsigned int numConcurrentReads_
 
edm::ProcessHistoryID processHistoryID_
 
std::atomic< bool > quit_threads_
 
unsigned int readBlocks_
 
std::atomic< unsigned int > readingFilesCount_
 
std::unique_ptr< std::thread > readSupervisorThread_
 
edm::RunNumber_t runNumber_
 
bool setExceptionState_ = false
 
bool singleBufferMode_
 
std::map< unsigned int, unsigned int > sourceEventsReport_
 
bool startedSupervisorThread_ = false
 
std::condition_variable startupCv_
 
std::mutex startupLock_
 
std::vector< int > streamFileTracker_
 
unsigned char * tcds_pointer_
 
const std::vector< unsigned int > testTCDSFEDRange_
 
std::vector< unsigned int > thread_quit_signal
 
std::atomic< bool > threadInit_
 
std::vector< unsigned int > tid_active_
 
bool useFileBroker_
 
const bool useL1EventID_
 
const bool verifyChecksum_
 
std::vector< ReaderInfoworkerJob_
 
tbb::concurrent_queue< unsigned int > workerPool_
 
std::vector< std::thread * > workerThreads_
 

Friends

struct InputChunk
 
struct InputFile
 

Additional Inherited Members

- Public Types inherited from edm::RawInputSource
enum  Next { Next::kEvent, Next::kFile, Next::kStop }
 
- Public Types inherited from edm::InputSource
enum  ItemType {
  IsInvalid, IsStop, IsFile, IsRun,
  IsLumi, IsEvent, IsRepeat, IsSynchronize
}
 
enum  ProcessingMode { Runs, RunsAndLumis, RunsLumisAndEvents }
 
- Public Attributes inherited from edm::InputSource
signalslot::Signal< void(StreamContext const &, ModuleCallingContext const &)> postEventReadFromSourceSignal_
 
signalslot::Signal< void(StreamContext const &, ModuleCallingContext const &)> preEventReadFromSourceSignal_
 

Detailed Description

Definition at line 40 of file FedRawDataInputSource.h.

Member Typedef Documentation

◆ ReaderInfo

Definition at line 138 of file FedRawDataInputSource.h.

Constructor & Destructor Documentation

◆ FedRawDataInputSource()

FedRawDataInputSource::FedRawDataInputSource ( edm::ParameterSet const &  pset,
edm::InputSourceDescription const &  desc 
)
explicit

Definition at line 51 of file FedRawDataInputSource.cc.

References cms::cuda::assert(), edm::Timestamp::beginOfTime(), crc32c_hw_test(), cvReader_, daqDirector_, edm::DaqProvenanceHelper::daqInit(), daqProvenanceHelper_, eventChunkBlock_, eventChunkSize_, Exception, fileDeleteLock_, fileListLoopMode_, fileListMode_, filesToDelete_, fms_, freeChunks_, mps_fire::i, evf::FastMonState::inInit, initFileList(), InputChunk, edm::Timestamp::invalidTimestamp(), MAXTCDSuTCAFEDID_, MINTCDSuTCAFEDID_, numBuffers_, numConcurrentReads_, Utilities::operator, processHistoryID_, edm::InputSource::processHistoryRegistryForUpdate(), edm::InputSource::productRegistryUpdate(), quit_threads_, readBlocks_, readingFilesCount_, readWorker(), edm::InputSource::runAuxiliary(), runNumber_, evf::EvFDaqDirector::setDeleteTracking(), evf::EvFDaqDirector::setFMS(), evf::FastMonitoringService::setInputSource(), evf::FastMonitoringService::setInState(), evf::FastMonitoringService::setInStateSup(), edm::InputSource::setNewRun(), edm::InputSource::setRunAuxiliary(), singleBufferMode_, startupCv_, startupLock_, testTCDSFEDRange_, thread_quit_signal, tid_active_, evf::EvFDaqDirector::useFileBroker(), useFileBroker_, workerJob_, and workerThreads_.

53  defPath_(pset.getUntrackedParameter<std::string>("buDefPath", "")),
54  eventChunkSize_(pset.getUntrackedParameter<unsigned int>("eventChunkSize", 32) * 1048576),
55  eventChunkBlock_(pset.getUntrackedParameter<unsigned int>("eventChunkBlock", 32) * 1048576),
56  numBuffers_(pset.getUntrackedParameter<unsigned int>("numBuffers", 2)),
57  maxBufferedFiles_(pset.getUntrackedParameter<unsigned int>("maxBufferedFiles", 2)),
58  getLSFromFilename_(pset.getUntrackedParameter<bool>("getLSFromFilename", true)),
59  alwaysStartFromFirstLS_(pset.getUntrackedParameter<bool>("alwaysStartFromFirstLS", false)),
60  verifyChecksum_(pset.getUntrackedParameter<bool>("verifyChecksum", true)),
61  useL1EventID_(pset.getUntrackedParameter<bool>("useL1EventID", false)),
63  pset.getUntrackedParameter<std::vector<unsigned int>>("testTCDSFEDRange", std::vector<unsigned int>())),
64  fileNames_(pset.getUntrackedParameter<std::vector<std::string>>("fileNames", std::vector<std::string>())),
65  fileListMode_(pset.getUntrackedParameter<bool>("fileListMode", false)),
66  fileListLoopMode_(pset.getUntrackedParameter<bool>("fileListLoopMode", false)),
69  eventID_(),
72  tcds_pointer_(nullptr),
73  eventsThisLumi_(0) {
74  char thishost[256];
75  gethostname(thishost, 255);
76  edm::LogInfo("FedRawDataInputSource") << "Construction. read-ahead chunk size -: " << std::endl
77  << (eventChunkSize_ / 1048576) << " MB on host " << thishost;
78 
79  if (!testTCDSFEDRange_.empty()) {
80  if (testTCDSFEDRange_.size() != 2) {
81  throw cms::Exception("FedRawDataInputSource::fillFEDRawDataCollection")
82  << "Invalid TCDS Test FED range parameter";
83  }
86  }
87 
88  long autoRunNumber = -1;
89  if (fileListMode_) {
90  autoRunNumber = initFileList();
91  if (!fileListLoopMode_) {
92  if (autoRunNumber < 0)
93  throw cms::Exception("FedRawDataInputSource::FedRawDataInputSource") << "Run number not found from filename";
94  //override run number
95  runNumber_ = (edm::RunNumber_t)autoRunNumber;
96  edm::Service<evf::EvFDaqDirector>()->overrideRunNumber((unsigned int)autoRunNumber);
97  }
98  }
99 
101  setNewRun();
102  //todo:autodetect from file name (assert if names differ)
104 
105  //make sure that chunk size is N * block size
110 
111  if (!numBuffers_)
112  throw cms::Exception("FedRawDataInputSource::FedRawDataInputSource")
113  << "no reading enabled with numBuffers parameter 0";
114 
117  readingFilesCount_ = 0;
118 
119  if (!crc32c_hw_test())
120  edm::LogError("FedRawDataInputSource::FedRawDataInputSource") << "Intel crc32c checksum computation unavailable";
121 
122  //get handles to DaqDirector and FastMonitoringService because getting them isn't possible in readSupervisor thread
123  if (fileListMode_) {
124  try {
126  } catch (cms::Exception const&) {
127  edm::LogInfo("FedRawDataInputSource") << "No FastMonitoringService found in the configuration";
128  }
129  } else {
131  if (!fms_) {
132  throw cms::Exception("FedRawDataInputSource") << "FastMonitoringService not found";
133  }
134  }
135 
137  if (!daqDirector_)
138  cms::Exception("FedRawDataInputSource") << "EvFDaqDirector not found";
139 
141  if (useFileBroker_)
142  edm::LogInfo("FedRawDataInputSource") << "EvFDaqDirector/Source configured to use file service";
143  //set DaqDirector to delete files in preGlobalEndLumi callback
145  if (fms_) {
147  fms_->setInputSource(this);
150  }
151  //should delete chunks when run stops
152  for (unsigned int i = 0; i < numBuffers_; i++) {
154  }
155 
156  quit_threads_ = false;
157 
158  //prepare data shared by threads
159  for (unsigned int i = 0; i < numConcurrentReads_; i++) {
160  thread_quit_signal.push_back(false);
161  workerJob_.push_back(ReaderInfo(nullptr, nullptr));
162  cvReader_.push_back(std::make_unique<std::condition_variable>());
163  tid_active_.push_back(0);
164  }
165 
166  //start threads
167  for (unsigned int i = 0; i < numConcurrentReads_; i++) {
168  //wait for each thread to complete initialization
169  std::unique_lock<std::mutex> lk(startupLock_);
170  workerThreads_.push_back(new std::thread(&FedRawDataInputSource::readWorker, this, i));
171  startupCv_.wait(lk);
172  }
173 
174  runAuxiliary()->setProcessHistoryID(processHistoryID_);
175 }
std::vector< std::string > fileNames_
std::shared_ptr< RunAuxiliary > runAuxiliary() const
Called by the framework to merge or insert run in principal cache.
Definition: InputSource.h:232
ProductRegistry & productRegistryUpdate()
Definition: InputSource.h:330
static Timestamp invalidTimestamp()
Definition: Timestamp.h:75
bool crc32c_hw_test()
Definition: crc32c.cc:354
bool useFileBroker() const
std::atomic< bool > quit_threads_
std::vector< ReaderInfo > workerJob_
std::pair< InputFile *, InputChunk * > ReaderInfo
assert(be >=bs)
ProcessHistoryID daqInit(ProductRegistry &productRegistry, ProcessHistoryRegistry &processHistoryRegistry) const
std::list< std::pair< int, std::unique_ptr< InputFile > > > filesToDelete_
static Timestamp beginOfTime()
Definition: Timestamp.h:77
const std::vector< unsigned int > testTCDSFEDRange_
edm::ProcessHistoryID processHistoryID_
const edm::DaqProvenanceHelper daqProvenanceHelper_
std::vector< std::thread * > workerThreads_
void setInputSource(FedRawDataInputSource *inputSource)
Log< level::Info, false > LogInfo
def getRunNumber(filename)
void setInStateSup(FastMonState::InputState inputState)
std::condition_variable startupCv_
ProcessHistoryRegistry & processHistoryRegistryForUpdate()
Definition: InputSource.h:331
evf::EvFDaqDirector * daqDirector_
void setRunAuxiliary(RunAuxiliary *rp)
Definition: InputSource.h:333
void readWorker(unsigned int tid)
std::vector< unsigned int > thread_quit_signal
std::atomic< unsigned int > readingFilesCount_
std::vector< std::unique_ptr< std::condition_variable > > cvReader_
evf::FastMonitoringService * fms_
std::vector< unsigned int > tid_active_
unsigned int RunNumber_t
void setDeleteTracking(std::mutex *fileDeleteLock, std::list< std::pair< int, std::unique_ptr< InputFile >>> *filesToDelete)
tbb::concurrent_queue< InputChunk * > freeChunks_
void setFMS(evf::FastMonitoringService *fms)
void setInState(FastMonState::InputState inputState)

◆ ~FedRawDataInputSource()

FedRawDataInputSource::~FedRawDataInputSource ( )
override

Definition at line 177 of file FedRawDataInputSource.cc.

References currentFile_, cvReader_, evf::FastMonitoringService::exceptionDetected(), filesToDelete_, fms_, mps_fire::i, evf::FastMonitoringService::isExceptionOnData(), mReader_, quit_threads_, readSupervisorThread_, startedSupervisorThread_, thread_quit_signal, and workerThreads_.

177  {
178  quit_threads_ = true;
179 
180  //delete any remaining open files
181  if (!fms_ || !fms_->exceptionDetected()) {
182  for (auto it = filesToDelete_.begin(); it != filesToDelete_.end(); it++)
183  it->second.reset();
184  } else {
185  //skip deleting files with exception
186  for (auto it = filesToDelete_.begin(); it != filesToDelete_.end(); it++) {
187  //it->second->unsetDeleteFile();
188  if (fms_->isExceptionOnData(it->second->lumi_))
189  it->second->unsetDeleteFile();
190  else
191  it->second.reset();
192  }
193  //disable deleting current file with exception
194  if (currentFile_.get())
195  if (fms_->isExceptionOnData(currentFile_->lumi_))
196  currentFile_->unsetDeleteFile();
197  }
198 
200  readSupervisorThread_->join();
201  } else {
202  //join aux threads in case the supervisor thread was not started
203  for (unsigned int i = 0; i < workerThreads_.size(); i++) {
204  std::unique_lock<std::mutex> lk(mReader_);
205  thread_quit_signal[i] = true;
206  cvReader_[i]->notify_one();
207  lk.unlock();
208  workerThreads_[i]->join();
209  delete workerThreads_[i];
210  }
211  }
212 }
std::atomic< bool > quit_threads_
std::unique_ptr< std::thread > readSupervisorThread_
bool isExceptionOnData(unsigned int ls)
std::list< std::pair< int, std::unique_ptr< InputFile > > > filesToDelete_
std::vector< std::thread * > workerThreads_
std::vector< unsigned int > thread_quit_signal
std::vector< std::unique_ptr< std::condition_variable > > cvReader_
evf::FastMonitoringService * fms_
std::unique_ptr< InputFile > currentFile_

Member Function Documentation

◆ checkNext()

edm::RawInputSource::Next FedRawDataInputSource::checkNext ( )
overrideprotectedvirtual

Implements edm::RawInputSource.

Definition at line 239 of file FedRawDataInputSource.cc.

References visDQMUpload::buf, evf::EvFDaqDirector::createProcessingNotificationMaybe(), currentLumiSection_, daqDirector_, event_, eventRunNumber_, eventsThisLumi_, fileListLoopMode_, fileListMode_, newFWLiteAna::found, evf::EvFDaqDirector::getEoLSFilePathOnBU(), evf::EvFDaqDirector::getEoLSFilePathOnFU(), evf::EvFDaqDirector::getEoRFilePathOnFU(), getLSFromFilename_, evf::FastMonState::inWaitInput, edm::RawInputSource::kEvent, edm::RawInputSource::kStop, L1EventID_, evf::EvFDaqDirector::lockFULocal2(), maybeOpenNewLumiSection(), evf::EvFDaqDirector::newLumi, nextEvent(), evf::EvFDaqDirector::noFile, readSupervisor(), readSupervisorThread_, reportEventsThisLumiInSource(), edm::InputSource::resetLuminosityBlockAuxiliary(), evf::EvFDaqDirector::runEnded, runNumber_, edm::InputSource::setEventCached(), setMonState(), startedSupervisorThread_, startupCv_, startupLock_, edm_modernize_messagelogger::stat, AlCaHLTBitMon_QueryRunRegistry::string, evf::EvFDaqDirector::unlockFULocal2(), and useFileBroker_.

239  {
241  //this thread opens new files and dispatches reading to worker readers
242  std::unique_lock<std::mutex> lk(startupLock_);
243  readSupervisorThread_ = std::make_unique<std::thread>(&FedRawDataInputSource::readSupervisor, this);
245  startupCv_.wait(lk);
246  }
247  //signal hltd to start event accounting
248  if (!currentLumiSection_)
251  switch (nextEvent()) {
253  //maybe create EoL file in working directory before ending run
254  struct stat buf;
255  if (!useFileBroker_ && currentLumiSection_ > 0) {
256  bool eolFound = (stat(daqDirector_->getEoLSFilePathOnBU(currentLumiSection_).c_str(), &buf) == 0);
257  if (eolFound) {
259  bool found = (stat(fuEoLS.c_str(), &buf) == 0);
260  if (!found) {
262  int eol_fd =
263  open(fuEoLS.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
264  close(eol_fd);
266  }
267  }
268  }
269  //also create EoR file in FU data directory
270  bool eorFound = (stat(daqDirector_->getEoRFilePathOnFU().c_str(), &buf) == 0);
271  if (!eorFound) {
272  int eor_fd = open(daqDirector_->getEoRFilePathOnFU().c_str(),
273  O_RDWR | O_CREAT,
274  S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
275  close(eor_fd);
276  }
278  eventsThisLumi_ = 0;
280  edm::LogInfo("FedRawDataInputSource") << "----------------RUN ENDED----------------";
281  return Next::kStop;
282  }
284  //this is not reachable
285  return Next::kEvent;
286  }
288  //std::cout << "--------------NEW LUMI---------------" << std::endl;
289  return Next::kEvent;
290  }
291  default: {
292  if (!getLSFromFilename_) {
293  //get new lumi from file header
294  if (event_->lumi() > currentLumiSection_) {
296  eventsThisLumi_ = 0;
298  }
299  }
302  else
303  eventRunNumber_ = event_->run();
304  L1EventID_ = event_->event();
305 
306  setEventCached();
307 
308  return Next::kEvent;
309  }
310  }
311 }
void maybeOpenNewLumiSection(const uint32_t lumiSection)
std::string getEoLSFilePathOnFU(const unsigned int ls) const
std::unique_ptr< std::thread > readSupervisorThread_
std::string getEoRFilePathOnFU() const
std::string getEoLSFilePathOnBU(const unsigned int ls) const
void setMonState(evf::FastMonState::InputState state)
void setEventCached()
Called by the framework to merge or ached() const {return eventCached_;}.
Definition: InputSource.h:362
void createProcessingNotificationMaybe() const
Log< level::Info, false > LogInfo
std::unique_ptr< FRDEventMsgView > event_
std::condition_variable startupCv_
void resetLuminosityBlockAuxiliary(bool isNewLumi=true) const
Definition: InputSource.h:345
evf::EvFDaqDirector * daqDirector_
void reportEventsThisLumiInSource(unsigned int lumi, unsigned int events)
evf::EvFDaqDirector::FileStatus nextEvent()

◆ exceptionState()

bool FedRawDataInputSource::exceptionState ( )
inlineprivate

Definition at line 68 of file FedRawDataInputSource.h.

References setExceptionState_.

Referenced by InputFile::advance().

◆ fillDescriptions()

void FedRawDataInputSource::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 214 of file FedRawDataInputSource.cc.

References edm::ConfigurationDescriptions::add(), and submitPVResolutionJobs::desc.

214  {
216  desc.setComment("File-based Filter Farm input source for reading raw data from BU ramdisk");
217  desc.addUntracked<unsigned int>("eventChunkSize", 32)->setComment("Input buffer (chunk) size");
218  desc.addUntracked<unsigned int>("eventChunkBlock", 32)
219  ->setComment("Block size used in a single file read call (must be smaller or equal to buffer size)");
220  desc.addUntracked<unsigned int>("numBuffers", 2)->setComment("Number of buffers used for reading input");
221  desc.addUntracked<unsigned int>("maxBufferedFiles", 2)
222  ->setComment("Maximum number of simultaneously buffered raw files");
223  desc.addUntracked<unsigned int>("alwaysStartFromfirstLS", false)
224  ->setComment("Force source to start from LS 1 if server provides higher lumisection number");
225  desc.addUntracked<bool>("verifyChecksum", true)
226  ->setComment("Verify event CRC-32C checksum of FRDv5 and higher or Adler32 with v3 and v4");
227  desc.addUntracked<bool>("useL1EventID", false)
228  ->setComment("Use L1 event ID from FED header if true or from TCDS FED if false");
229  desc.addUntracked<std::vector<unsigned int>>("testTCDSFEDRange", std::vector<unsigned int>())
230  ->setComment("[min, max] range to search for TCDS FED ID in test setup");
231  desc.addUntracked<bool>("fileListMode", false)
232  ->setComment("Use fileNames parameter to directly specify raw files to open");
233  desc.addUntracked<std::vector<std::string>>("fileNames", std::vector<std::string>())
234  ->setComment("file list used when fileListMode is enabled");
235  desc.setAllowAnything();
236  descriptions.add("source", desc);
237 }
void add(std::string const &label, ParameterSetDescription const &psetDescription)

◆ fillFEDRawDataCollection()

edm::Timestamp FedRawDataInputSource::fillFEDRawDataCollection ( FEDRawDataCollection rawData,
bool &  tcdsInRange 
)
private

Definition at line 708 of file FedRawDataInputSource.cc.

References cms::cuda::assert(), FEDRawData::data(), event_, evf::evtn::evm_board_sense(), Exception, l1tstage2_dqm_sourceclient-live_cfg::fedId, FEDTrailer::fragmentLength(), evf::evtn::get(), evf::evtn::getgpshigh(), evf::evtn::getgpslow(), evf::evtn::gtpe_board_sense(), evf::evtn::gtpe_get(), GTPEventID_, FEDHeader::length, FEDTrailer::length, FEDNumbering::MAXFEDID, FEDNumbering::MAXTCDSuTCAFEDID, MAXTCDSuTCAFEDID_, FEDNumbering::MINTCDSuTCAFEDID, MINTCDSuTCAFEDID_, FEDNumbering::MINTriggerEGTPFEDID, FEDNumbering::MINTriggerGTPFEDID, l1tstage2_dqm_sourceclient-live_cfg::rawData, FEDRawData::resize(), FEDHeader::sourceID(), tcds_pointer_, and protons_cff::time.

Referenced by read().

708  {
710  timeval stv;
711  gettimeofday(&stv, nullptr);
712  time = stv.tv_sec;
713  time = (time << 32) + stv.tv_usec;
714  edm::Timestamp tstamp(time);
715 
716  uint32_t eventSize = event_->eventSize();
717  unsigned char* event = (unsigned char*)event_->payload();
718  GTPEventID_ = 0;
719  tcds_pointer_ = nullptr;
720  tcdsInRange = false;
721  uint16_t selectedTCDSFed = 0;
722  while (eventSize > 0) {
723  assert(eventSize >= FEDTrailer::length);
724  eventSize -= FEDTrailer::length;
725  const FEDTrailer fedTrailer(event + eventSize);
726  const uint32_t fedSize = fedTrailer.fragmentLength() << 3; //trailer length counts in 8 bytes
727  assert(eventSize >= fedSize - FEDHeader::length);
728  eventSize -= (fedSize - FEDHeader::length);
729  const FEDHeader fedHeader(event + eventSize);
730  const uint16_t fedId = fedHeader.sourceID();
732  throw cms::Exception("FedRawDataInputSource::fillFEDRawDataCollection") << "Out of range FED ID : " << fedId;
733  } else if (fedId >= MINTCDSuTCAFEDID_ && fedId <= MAXTCDSuTCAFEDID_) {
734  if (!selectedTCDSFed) {
735  selectedTCDSFed = fedId;
736  tcds_pointer_ = event + eventSize;
738  tcdsInRange = true;
739  }
740  } else
741  throw cms::Exception("FedRawDataInputSource::fillFEDRawDataCollection")
742  << "Second TCDS FED ID " << fedId << " found. First ID: " << selectedTCDSFed;
743  }
745  if (evf::evtn::evm_board_sense(event + eventSize, fedSize))
746  GTPEventID_ = evf::evtn::get(event + eventSize, true);
747  else
748  GTPEventID_ = evf::evtn::get(event + eventSize, false);
749  //evf::evtn::evm_board_setformat(fedSize);
750  const uint64_t gpsl = evf::evtn::getgpslow(event + eventSize);
751  const uint64_t gpsh = evf::evtn::getgpshigh(event + eventSize);
752  tstamp = edm::Timestamp(static_cast<edm::TimeValue_t>((gpsh << 32) + gpsl));
753  }
754  //take event ID from GTPE FED
756  if (evf::evtn::gtpe_board_sense(event + eventSize)) {
757  GTPEventID_ = evf::evtn::gtpe_get(event + eventSize);
758  }
759  }
760  FEDRawData& fedData = rawData.FEDData(fedId);
761  fedData.resize(fedSize);
762  memcpy(fedData.data(), event + eventSize, fedSize);
763  }
764  assert(eventSize == 0);
765 
766  return tstamp;
767 }
unsigned int getgpshigh(const unsigned char *)
bool gtpe_board_sense(const unsigned char *p)
static const uint32_t length
Definition: FEDTrailer.h:57
unsigned int get(const unsigned char *, bool)
static const uint32_t length
Definition: FEDHeader.h:54
assert(be >=bs)
void resize(size_t newsize)
Definition: FEDRawData.cc:28
unsigned long long TimeValue_t
Definition: Timestamp.h:21
bool evm_board_sense(const unsigned char *p, size_t size)
unsigned long long uint64_t
Definition: Time.h:13
std::unique_ptr< FRDEventMsgView > event_
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
unsigned int gtpe_get(const unsigned char *)
unsigned int getgpslow(const unsigned char *)
Definition: event.py:1

◆ getEventReport()

std::pair< bool, unsigned int > FedRawDataInputSource::getEventReport ( unsigned int  lumi,
bool  erase 
)

Definition at line 1582 of file FedRawDataInputSource.cc.

References CommonMethods::lock(), monlock_, runTheMatrix::ret, and sourceEventsReport_.

Referenced by evf::FastMonitoringService::preGlobalEndLumi().

1582  {
1583  std::lock_guard<std::mutex> lock(monlock_);
1584  auto itr = sourceEventsReport_.find(lumi);
1585  if (itr != sourceEventsReport_.end()) {
1586  std::pair<bool, unsigned int> ret(true, itr->second);
1587  if (erase)
1588  sourceEventsReport_.erase(itr);
1589  return ret;
1590  } else
1591  return std::pair<bool, unsigned int>(false, 0);
1592 }
ret
prodAgent to be discontinued
std::map< unsigned int, unsigned int > sourceEventsReport_

◆ getFile()

evf::EvFDaqDirector::FileStatus FedRawDataInputSource::getFile ( unsigned int &  ls,
std::string &  nextFile,
uint32_t &  fsize,
uint64_t &  lockWaitTime 
)
private

Definition at line 1629 of file FedRawDataInputSource.cc.

References fileListIndex_, fileListLoopMode_, MillePedeFileConverter_cfg::fileName, fileNames_, loopModeIterationInc_, eostools::ls(), evf::EvFDaqDirector::newFile, castor_dqm_sourceclient_file_cfg::path, evf::EvFDaqDirector::runEnded, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by readSupervisor().

1632  {
1633  if (fileListIndex_ < fileNames_.size()) {
1634  nextFile = fileNames_[fileListIndex_];
1635  if (nextFile.find("file://") == 0)
1636  nextFile = nextFile.substr(7);
1637  else if (nextFile.find("file:") == 0)
1638  nextFile = nextFile.substr(5);
1639  std::filesystem::path fileName = nextFile;
1640  std::string fileStem = fileName.stem().string();
1641  if (fileStem.find("ls"))
1642  fileStem = fileStem.substr(fileStem.find("ls") + 2);
1643  if (fileStem.find('_'))
1644  fileStem = fileStem.substr(0, fileStem.find('_'));
1645 
1646  if (!fileListLoopMode_)
1647  ls = std::stoul(fileStem);
1648  else //always starting from LS 1 in loop mode
1649  ls = 1 + loopModeIterationInc_;
1650 
1651  //fsize = 0;
1652  //lockWaitTime = 0;
1653  fileListIndex_++;
1655  } else {
1656  if (!fileListLoopMode_)
1658  else {
1659  //loop through files until interrupted
1661  fileListIndex_ = 0;
1662  return getFile(ls, nextFile, fsize, lockWaitTime);
1663  }
1664  }
1665 }
std::vector< std::string > fileNames_
evf::EvFDaqDirector::FileStatus getFile(unsigned int &ls, std::string &nextFile, uint32_t &fsize, uint64_t &lockWaitTime)
def ls(path, rec=False)
Definition: eostools.py:349

◆ getNextEvent()

evf::EvFDaqDirector::FileStatus FedRawDataInputSource::getNextEvent ( )
inlineprivate

Definition at line 359 of file FedRawDataInputSource.cc.

References cms::cuda::assert(), bufferInputRead_, chunkIsFree_, crc32c(), currentFile_, currentFileIndex_, currentLumiSection_, cvWakeup_, daqDirector_, detectedFRDversion_, event_, eventChunkSize_, eventsThisLumi_, Exception, fileDeleteLock_, fileListMode_, fileQueue_, filesToDelete_, fms_, FRDHeaderMaxVersion, FRDHeaderVersionSize, freeChunks_, getLSFromFilename_, evf::FastMonState::inCachedEvent, evf::FastMonState::inChecksumEvent, evf::FastMonState::inChunkReceived, evf::FastMonState::inNewLumi, evf::FastMonState::inProcessingFile, evf::FastMonState::inRunEnd, evf::FastMonState::inWaitChunk, evf::FastMonState::inWaitInput, evf::EvFDaqDirector::isSingleStreamThread(), dttmaxenums::L, maybeOpenNewLumiSection(), eostools::move(), mWakeup_, evf::EvFDaqDirector::newFile, evf::EvFDaqDirector::newLumi, evf::EvFDaqDirector::noFile, readingFilesCount_, readNextChunkIntoBuffer(), reportEventsThisLumiInSource(), evf::EvFDaqDirector::runAbort, evf::EvFDaqDirector::runEnded, evf::EvFDaqDirector::sameFile, evf::FastMonitoringService::setExceptionDetected(), setExceptionState_, setMonState(), singleBufferMode_, mps_update::status, threadError(), mps_check::timeout, and verifyChecksum_.

Referenced by nextEvent().

359  {
360  if (setExceptionState_)
361  threadError();
362  if (!currentFile_.get()) {
365  if (!fileQueue_.try_pop(currentFile_)) {
366  //sleep until wakeup (only in single-buffer mode) or timeout
367  std::unique_lock<std::mutex> lkw(mWakeup_);
368  if (cvWakeup_.wait_for(lkw, std::chrono::milliseconds(100)) == std::cv_status::timeout || !currentFile_.get())
370  }
371  status = currentFile_->status_;
374  currentFile_.reset();
375  return status;
376  } else if (status == evf::EvFDaqDirector::runAbort) {
377  throw cms::Exception("FedRawDataInputSource::getNextEvent")
378  << "Run has been aborted by the input source reader thread";
379  } else if (status == evf::EvFDaqDirector::newLumi) {
381  if (getLSFromFilename_) {
382  if (currentFile_->lumi_ > currentLumiSection_) {
384  eventsThisLumi_ = 0;
386  }
387  } else { //let this be picked up from next event
389  }
390  currentFile_.reset();
391  return status;
392  } else if (status == evf::EvFDaqDirector::newFile) {
394  } else
395  assert(false);
396  }
398 
399  //file is empty
400  if (!currentFile_->fileSize_) {
402  //try to open new lumi
403  assert(currentFile_->nChunks_ == 0);
404  if (getLSFromFilename_)
405  if (currentFile_->lumi_ > currentLumiSection_) {
407  eventsThisLumi_ = 0;
409  }
410  //immediately delete empty file
411  currentFile_.reset();
413  }
414 
415  //file is finished
416  if (currentFile_->bufferPosition_ == currentFile_->fileSize_) {
418  //release last chunk (it is never released elsewhere)
419  freeChunks_.push(currentFile_->chunks_[currentFile_->currentChunk_]);
420  if (currentFile_->nEvents_ >= 0 && currentFile_->nEvents_ != int(currentFile_->nProcessed_)) {
421  throw cms::Exception("FedRawDataInputSource::getNextEvent")
422  << "Fully processed " << currentFile_->nProcessed_ << " from the file " << currentFile_->fileName_
423  << " but according to BU JSON there should be " << currentFile_->nEvents_ << " events";
424  }
425  //try to wake up supervisor thread which might be sleeping waiting for the free chunk
426  if (singleBufferMode_) {
427  std::unique_lock<std::mutex> lkw(mWakeup_);
428  cvWakeup_.notify_one();
429  }
430  bufferInputRead_ = 0;
432  //put the file in pending delete list;
433  std::unique_lock<std::mutex> lkw(fileDeleteLock_);
434  filesToDelete_.push_back(std::pair<int, std::unique_ptr<InputFile>>(currentFileIndex_, std::move(currentFile_)));
435  } else {
436  //in single-thread and stream jobs, events are already processed
437  currentFile_.reset();
438  }
440  }
441 
442  //handle RAW file header
443  if (currentFile_->bufferPosition_ == 0 && currentFile_->rawHeaderSize_ > 0) {
444  if (currentFile_->fileSize_ <= currentFile_->rawHeaderSize_) {
445  if (currentFile_->fileSize_ < currentFile_->rawHeaderSize_)
446  throw cms::Exception("FedRawDataInputSource::getNextEvent")
447  << "Premature end of input file while reading file header";
448 
449  edm::LogWarning("FedRawDataInputSource")
450  << "File with only raw header and no events received in LS " << currentFile_->lumi_;
451  if (getLSFromFilename_)
452  if (currentFile_->lumi_ > currentLumiSection_) {
454  eventsThisLumi_ = 0;
456  }
457  }
458 
459  //advance buffer position to skip file header (chunk will be acquired later)
460  currentFile_->chunkPosition_ += currentFile_->rawHeaderSize_;
461  currentFile_->bufferPosition_ += currentFile_->rawHeaderSize_;
462  }
463 
464  //file is too short
465  if (currentFile_->fileSize_ - currentFile_->bufferPosition_ < FRDHeaderVersionSize[detectedFRDversion_]) {
466  throw cms::Exception("FedRawDataInputSource::getNextEvent")
467  << "Premature end of input file while reading event header";
468  }
469  if (singleBufferMode_) {
470  //should already be there
472  while (!currentFile_->waitForChunk(currentFile_->currentChunk_)) {
473  usleep(10000);
474  if (currentFile_->parent_->exceptionState() || setExceptionState_)
475  currentFile_->parent_->threadError();
476  }
478 
479  unsigned char* dataPosition = currentFile_->chunks_[0]->buf_ + currentFile_->chunkPosition_;
480 
481  //conditions when read amount is not sufficient for the header to fit
485 
486  if (detectedFRDversion_ == 0) {
487  detectedFRDversion_ = *((uint16_t*)dataPosition);
489  throw cms::Exception("FedRawDataInputSource::getNextEvent")
490  << "Unknown FRD version -: " << detectedFRDversion_;
492  }
493 
494  //recalculate chunk position
495  dataPosition = currentFile_->chunks_[0]->buf_ + currentFile_->chunkPosition_;
497  throw cms::Exception("FedRawDataInputSource::getNextEvent")
498  << "Premature end of input file while reading event header";
499  }
500  }
501 
502  event_ = std::make_unique<FRDEventMsgView>(dataPosition);
503  if (event_->size() > eventChunkSize_) {
504  throw cms::Exception("FedRawDataInputSource::getNextEvent")
505  << " event id:" << event_->event() << " lumi:" << event_->lumi() << " run:" << event_->run()
506  << " of size:" << event_->size() << " bytes does not fit into a chunk of size:" << eventChunkSize_
507  << " bytes";
508  }
509 
510  const uint32_t msgSize = event_->size() - FRDHeaderVersionSize[detectedFRDversion_];
511 
512  if (currentFile_->fileSize_ - currentFile_->bufferPosition_ < msgSize) {
513  throw cms::Exception("FedRawDataInputSource::getNextEvent")
514  << "Premature end of input file while reading event data";
515  }
516  if (eventChunkSize_ - currentFile_->chunkPosition_ < msgSize) {
518  //recalculate chunk position
519  dataPosition = currentFile_->chunks_[0]->buf_ + currentFile_->chunkPosition_;
520  event_ = std::make_unique<FRDEventMsgView>(dataPosition);
521  }
522  currentFile_->bufferPosition_ += event_->size();
523  currentFile_->chunkPosition_ += event_->size();
524  //last chunk is released when this function is invoked next time
525 
526  }
527  //multibuffer mode:
528  else {
529  //wait for the current chunk to become added to the vector
531  while (!currentFile_->waitForChunk(currentFile_->currentChunk_)) {
532  usleep(10000);
533  if (setExceptionState_)
534  threadError();
535  }
537 
538  //check if header is at the boundary of two chunks
539  chunkIsFree_ = false;
540  unsigned char* dataPosition;
541 
542  //read header, copy it to a single chunk if necessary
544  throw cms::Exception("FedRawDataInputSource::getNextEvent")
545  << "Premature end of input file (missing:"
547  << ") while reading event data for next event header";
548  bool chunkEnd = currentFile_->advance(dataPosition, FRDHeaderVersionSize[detectedFRDversion_]);
549 
550  event_ = std::make_unique<FRDEventMsgView>(dataPosition);
551  if (event_->size() > eventChunkSize_) {
552  throw cms::Exception("FedRawDataInputSource::getNextEvent")
553  << " event id:" << event_->event() << " lumi:" << event_->lumi() << " run:" << event_->run()
554  << " of size:" << event_->size() << " bytes does not fit into a chunk of size:" << eventChunkSize_
555  << " bytes";
556  }
557 
558  const uint32_t msgSize = event_->size() - FRDHeaderVersionSize[detectedFRDversion_];
559 
560  if (currentFile_->fileSizeLeft() < msgSize) {
561  throw cms::Exception("FedRawDataInputSource::getNextEvent")
562  << "Premature end of input file (missing:" << (msgSize - currentFile_->fileSizeLeft())
563  << ") while reading event data for event " << event_->event() << " lumi:" << event_->lumi();
564  }
565 
566  if (chunkEnd) {
567  //header was at the chunk boundary, we will have to move payload as well
568  currentFile_->moveToPreviousChunk(msgSize, FRDHeaderVersionSize[detectedFRDversion_]);
569  chunkIsFree_ = true;
570  } else {
571  //header was contiguous, but check if payload fits the chunk
572  if (eventChunkSize_ - currentFile_->chunkPosition_ < msgSize) {
573  //rewind to header start position
575  //copy event to a chunk start and move pointers
576 
578 
579  chunkEnd = currentFile_->advance(dataPosition, FRDHeaderVersionSize[detectedFRDversion_] + msgSize);
580 
582 
583  assert(chunkEnd);
584  chunkIsFree_ = true;
585  //header is moved
586  event_ = std::make_unique<FRDEventMsgView>(dataPosition);
587  } else {
588  //everything is in a single chunk, only move pointers forward
589  chunkEnd = currentFile_->advance(dataPosition, msgSize);
590  assert(!chunkEnd);
591  chunkIsFree_ = false;
592  }
593  }
594  //sanity-check check that the buffer position has not exceeded file size after preparing event
595  if (currentFile_->fileSize_ < currentFile_->bufferPosition_) {
596  throw cms::Exception("FedRawDataInputSource::getNextEvent")
597  << "Exceeded file size by " << currentFile_->bufferPosition_ - currentFile_->fileSize_
598  << " after reading last event declared size of " << event_->size() << " bytes";
599  }
600  } //end multibuffer mode
602 
603  if (verifyChecksum_ && event_->version() >= 5) {
604  uint32_t crc = 0;
605  crc = crc32c(crc, (const unsigned char*)event_->payload(), event_->eventSize());
606  if (crc != event_->crc32c()) {
607  if (fms_)
609  throw cms::Exception("FedRawDataInputSource::getNextEvent")
610  << "Found a wrong crc32c checksum: expected 0x" << std::hex << event_->crc32c() << " but calculated 0x"
611  << crc;
612  }
613  } else if (verifyChecksum_ && event_->version() >= 3) {
614  uint32_t adler = adler32(0L, Z_NULL, 0);
615  adler = adler32(adler, (Bytef*)event_->payload(), event_->eventSize());
616 
617  if (adler != event_->adler32()) {
618  if (fms_)
620  throw cms::Exception("FedRawDataInputSource::getNextEvent")
621  << "Found a wrong Adler32 checksum: expected 0x" << std::hex << event_->adler32() << " but calculated 0x"
622  << adler;
623  }
624  }
626 
627  currentFile_->nProcessed_++;
628 
630 }
std::condition_variable cvWakeup_
constexpr size_t FRDHeaderMaxVersion
void setExceptionDetected(unsigned int ls)
void maybeOpenNewLumiSection(const uint32_t lumiSection)
tbb::concurrent_queue< std::unique_ptr< InputFile > > fileQueue_
int timeout
Definition: mps_check.py:53
assert(be >=bs)
std::list< std::pair< int, std::unique_ptr< InputFile > > > filesToDelete_
void setMonState(evf::FastMonState::InputState state)
uint32_t crc32c(uint32_t crc, const unsigned char *buf, size_t len)
Definition: crc32c.cc:340
std::unique_ptr< FRDEventMsgView > event_
evf::EvFDaqDirector * daqDirector_
std::atomic< unsigned int > readingFilesCount_
void reportEventsThisLumiInSource(unsigned int lumi, unsigned int events)
evf::FastMonitoringService * fms_
constexpr std::array< uint32, FRDHeaderMaxVersion+1 > FRDHeaderVersionSize
tbb::concurrent_queue< InputChunk * > freeChunks_
Log< level::Warning, false > LogWarning
void readNextChunkIntoBuffer(InputFile *file)
std::unique_ptr< InputFile > currentFile_
def move(src, dest)
Definition: eostools.py:511

◆ initFileList()

long FedRawDataInputSource::initFileList ( )
private

Definition at line 1594 of file FedRawDataInputSource.cc.

References a, b, mps_fire::end, cppFunctionSkipper::exception, MillePedeFileConverter_cfg::fileName, fileNames_, castor_dqm_sourceclient_file_cfg::path, jetUpdater_cfi::sort, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by FedRawDataInputSource().

1594  {
1595  std::sort(fileNames_.begin(), fileNames_.end(), [](std::string a, std::string b) {
1596  if (a.rfind('/') != std::string::npos)
1597  a = a.substr(a.rfind('/'));
1598  if (b.rfind('/') != std::string::npos)
1599  b = b.substr(b.rfind('/'));
1600  return b > a;
1601  });
1602 
1603  if (!fileNames_.empty()) {
1604  //get run number from first file in the vector
1606  std::string fileStem = fileName.stem().string();
1607  if (fileStem.find("file://") == 0)
1608  fileStem = fileStem.substr(7);
1609  else if (fileStem.find("file:") == 0)
1610  fileStem = fileStem.substr(5);
1611  auto end = fileStem.find('_');
1612 
1613  if (fileStem.find("run") == 0) {
1614  std::string runStr = fileStem.substr(3, end - 3);
1615  try {
1616  //get long to support test run numbers < 2^32
1617  long rval = std::stol(runStr);
1618  edm::LogInfo("FedRawDataInputSource") << "Autodetected run number in fileListMode -: " << rval;
1619  return rval;
1620  } catch (const std::exception&) {
1621  edm::LogWarning("FedRawDataInputSource")
1622  << "Unable to autodetect run number in fileListMode from file -: " << fileName;
1623  }
1624  }
1625  }
1626  return -1;
1627 }
std::vector< std::string > fileNames_
Log< level::Info, false > LogInfo
double b
Definition: hdecay.h:118
double a
Definition: hdecay.h:119
Log< level::Warning, false > LogWarning

◆ maybeOpenNewLumiSection()

void FedRawDataInputSource::maybeOpenNewLumiSection ( const uint32_t  lumiSection)
private

Definition at line 313 of file FedRawDataInputSource.cc.

References visDQMUpload::buf, evf::EvFDaqDirector::createBoLSFile(), currentLumiSection_, daqDirector_, newFWLiteAna::found, evf::EvFDaqDirector::getEoLSFilePathOnFU(), edm::Timestamp::invalidTimestamp(), evf::EvFDaqDirector::lockFULocal2(), edm::InputSource::luminosityBlock(), edm::InputSource::luminosityBlockAuxiliary(), processHistoryID_, edm::InputSource::resetLuminosityBlockAuxiliary(), edm::InputSource::run(), edm::InputSource::runAuxiliary(), edm::InputSource::setLuminosityBlockAuxiliary(), edm_modernize_messagelogger::stat, AlCaHLTBitMon_QueryRunRegistry::string, evf::EvFDaqDirector::unlockFULocal2(), and useFileBroker_.

Referenced by checkNext(), and getNextEvent().

313  {
314  if (!luminosityBlockAuxiliary() || luminosityBlockAuxiliary()->luminosityBlock() != lumiSection) {
315  if (!useFileBroker_) {
316  if (currentLumiSection_ > 0) {
318  struct stat buf;
319  bool found = (stat(fuEoLS.c_str(), &buf) == 0);
320  if (!found) {
322  int eol_fd =
323  open(fuEoLS.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
324  close(eol_fd);
325  daqDirector_->createBoLSFile(lumiSection, false);
327  }
328  } else
329  daqDirector_->createBoLSFile(lumiSection, true); //needed for initial lumisection
330  }
331 
332  currentLumiSection_ = lumiSection;
333 
335 
336  timeval tv;
337  gettimeofday(&tv, nullptr);
338  const edm::Timestamp lsopentime((unsigned long long)tv.tv_sec * 1000000 + (unsigned long long)tv.tv_usec);
339 
341  runAuxiliary()->run(), lumiSection, lsopentime, edm::Timestamp::invalidTimestamp());
342 
343  setLuminosityBlockAuxiliary(lumiBlockAuxiliary);
344  luminosityBlockAuxiliary()->setProcessHistoryID(processHistoryID_);
345 
346  edm::LogInfo("FedRawDataInputSource") << "New lumi section was opened. LUMI -: " << lumiSection;
347  }
348 }
std::shared_ptr< RunAuxiliary > runAuxiliary() const
Called by the framework to merge or insert run in principal cache.
Definition: InputSource.h:232
static Timestamp invalidTimestamp()
Definition: Timestamp.h:75
RunNumber_t run() const
Accessor for current run number.
Definition: InputSource.cc:457
std::string getEoLSFilePathOnFU(const unsigned int ls) const
void setLuminosityBlockAuxiliary(LuminosityBlockAuxiliary *lbp)
Definition: InputSource.h:337
edm::ProcessHistoryID processHistoryID_
Log< level::Info, false > LogInfo
void resetLuminosityBlockAuxiliary(bool isNewLumi=true) const
Definition: InputSource.h:345
LuminosityBlockNumber_t luminosityBlock() const
Accessor for current luminosity block number.
Definition: InputSource.cc:462
evf::EvFDaqDirector * daqDirector_
std::shared_ptr< LuminosityBlockAuxiliary > luminosityBlockAuxiliary() const
Called by the framework to merge or insert lumi in principal cache.
Definition: InputSource.h:235
void createBoLSFile(const uint32_t lumiSection, bool checkIfExists) const

◆ nextEvent()

evf::EvFDaqDirector::FileStatus FedRawDataInputSource::nextEvent ( )
inlineprivate

Definition at line 350 of file FedRawDataInputSource.cc.

References getNextEvent(), svgfig::load(), evf::EvFDaqDirector::noFile, edm::shutdown_flag, and mps_update::status.

Referenced by checkNext().

350  {
353  if (edm::shutdown_flag.load(std::memory_order_relaxed))
354  break;
355  }
356  return status;
357 }
volatile std::atomic< bool > shutdown_flag
def load(fileName)
Definition: svgfig.py:547
evf::EvFDaqDirector::FileStatus getNextEvent()

◆ read()

void FedRawDataInputSource::read ( edm::EventPrincipal eventPrincipal)
overrideprotectedvirtual

Implements edm::RawInputSource.

Definition at line 632 of file FedRawDataInputSource.cc.

References printConversionInfo::aux, edm::DaqProvenanceHelper::branchDescription(), checkEvery_, chunkIsFree_, runTheMatrix::const, currentFile_, currentFileIndex_, currentLumiSection_, daqProvenanceHelper_, edm::DaqProvenanceHelper::dummyProvenance(), event_, eventID_, eventRunNumber_, eventsThisLumi_, Exception, fileDeleteLock_, fileListLoopMode_, filesToDelete_, fillFEDRawDataCollection(), fms_, freeChunks_, GTPEventID_, mps_fire::i, evf::FastMonState::inNoRequest, evf::FastMonState::inReadCleanup, evf::FastMonState::inReadEvent, evf::FastMonitoringService::isExceptionOnData(), L1EventID_, FEDHeader::length, edm::RawInputSource::makeEvent(), evf::evtn::makeEventAuxiliary(), eostools::move(), edm::EventAuxiliary::PhysicsTrigger, edm::InputSource::processGUID(), processHistoryID_, edm::EventPrincipal::put(), l1tstage2_dqm_sourceclient-live_cfg::rawData, setMonState(), streamFileTracker_, edm::EventPrincipal::streamID(), AlCaHLTBitMon_QueryRunRegistry::string, tcds_pointer_, FEDHeader::triggerType(), and useL1EventID_.

Referenced by edmIntegrityCheck.PublishToFileSystem::get(), readNextChunkIntoBuffer(), and readWorker().

632  {
634  std::unique_ptr<FEDRawDataCollection> rawData(new FEDRawDataCollection);
635  bool tcdsInRange;
636  edm::Timestamp tstamp = fillFEDRawDataCollection(*rawData, tcdsInRange);
637 
638  if (useL1EventID_) {
641  aux.setProcessHistoryID(processHistoryID_);
642  makeEvent(eventPrincipal, aux);
643  } else if (tcds_pointer_ == nullptr) {
644  if (!GTPEventID_) {
645  throw cms::Exception("FedRawDataInputSource::read")
646  << "No TCDS or GTP FED in event with FEDHeader EID -: " << L1EventID_;
647  }
650  aux.setProcessHistoryID(processHistoryID_);
651  makeEvent(eventPrincipal, aux);
652  } else {
653  const FEDHeader fedHeader(tcds_pointer_);
654  tcds::Raw_v1 const* tcds = reinterpret_cast<tcds::Raw_v1 const*>(tcds_pointer_ + FEDHeader::length);
659  event_->isRealData(),
660  static_cast<edm::EventAuxiliary::ExperimentType>(fedHeader.triggerType()),
661  processGUID(),
663  !tcdsInRange);
664  aux.setProcessHistoryID(processHistoryID_);
665  makeEvent(eventPrincipal, aux);
666  }
667 
668  std::unique_ptr<edm::WrapperBase> edp(new edm::Wrapper<FEDRawDataCollection>(std::move(rawData)));
669 
671 
672  eventsThisLumi_++;
674 
675  //resize vector if needed
676  while (streamFileTracker_.size() <= eventPrincipal.streamID())
677  streamFileTracker_.push_back(-1);
678 
679  streamFileTracker_[eventPrincipal.streamID()] = currentFileIndex_;
680 
681  //this old file check runs no more often than every 10 events
682  if (!((currentFile_->nProcessed_ - 1) % (checkEvery_))) {
683  //delete files that are not in processing
684  std::unique_lock<std::mutex> lkw(fileDeleteLock_);
685  auto it = filesToDelete_.begin();
686  while (it != filesToDelete_.end()) {
687  bool fileIsBeingProcessed = false;
688  for (unsigned int i = 0; i < streamFileTracker_.size(); i++) {
689  if (it->first == streamFileTracker_.at(i)) {
690  fileIsBeingProcessed = true;
691  break;
692  }
693  }
694  if (!fileIsBeingProcessed && (!fms_ || !fms_->isExceptionOnData(it->second->lumi_))) {
695  std::string fileToDelete = it->second->fileName_;
696  it = filesToDelete_.erase(it);
697  } else
698  it++;
699  }
700  }
701  if (chunkIsFree_)
702  freeChunks_.push(currentFile_->chunks_[currentFile_->currentChunk_ - 1]);
703  chunkIsFree_ = false;
705  return;
706 }
static const uint32_t length
Definition: FEDHeader.h:54
edm::Timestamp fillFEDRawDataCollection(FEDRawDataCollection &rawData, bool &tcdsInRange)
StreamID streamID() const
bool isExceptionOnData(unsigned int ls)
edm::EventAuxiliary makeEventAuxiliary(const tcds::Raw_v1 *, unsigned int runNumber, unsigned int lumiSection, bool isRealData, const edm::EventAuxiliary::ExperimentType &, const std::string &processGUID, bool verifyLumiSection, bool suppressWarning)
std::list< std::pair< int, std::unique_ptr< InputFile > > > filesToDelete_
void put(BranchDescription const &bd, std::unique_ptr< WrapperBase > edp, ProductProvenance const &productProvenance) const
Definition: TCDSRaw.h:16
std::string const & processGUID() const
Accessor for global process identifier.
Definition: InputSource.h:197
std::vector< int > streamFileTracker_
ProductProvenance const & dummyProvenance() const
edm::ProcessHistoryID processHistoryID_
const edm::DaqProvenanceHelper daqProvenanceHelper_
void setMonState(evf::FastMonState::InputState state)
BranchDescription const & branchDescription() const
std::unique_ptr< FRDEventMsgView > event_
void makeEvent(EventPrincipal &eventPrincipal, EventAuxiliary const &eventAuxiliary)
evf::FastMonitoringService * fms_
tbb::concurrent_queue< InputChunk * > freeChunks_
std::unique_ptr< InputFile > currentFile_
def move(src, dest)
Definition: eostools.py:511

◆ readNextChunkIntoBuffer()

void FedRawDataInputSource::readNextChunkIntoBuffer ( InputFile file)
private

Definition at line 1502 of file FedRawDataInputSource.cc.

References bufferInputRead_, eventChunkBlock_, eventChunkSize_, Exception, geometryDiff::file, fileDescriptor_, mps_fire::i, dqmdumpme::last, LogDebug, read(), and readBlocks_.

Referenced by getNextEvent().

1502  {
1503  uint32_t existingSize = 0;
1504 
1505  if (fileDescriptor_ < 0) {
1506  bufferInputRead_ = 0;
1507  if (file->rawFd_ == -1) {
1508  fileDescriptor_ = open(file->fileName_.c_str(), O_RDONLY);
1509  if (file->rawHeaderSize_)
1510  lseek(fileDescriptor_, file->rawHeaderSize_, SEEK_SET);
1511  } else
1512  fileDescriptor_ = file->rawFd_;
1513 
1514  //skip header size in destination buffer (chunk position was already adjusted)
1515  bufferInputRead_ += file->rawHeaderSize_;
1516  existingSize += file->rawHeaderSize_;
1517 
1518  if (fileDescriptor_ >= 0)
1519  LogDebug("FedRawDataInputSource") << "opened file -: " << std::endl << file->fileName_;
1520  else {
1521  throw cms::Exception("FedRawDataInputSource:readNextChunkIntoBuffer")
1522  << "failed to open file " << std::endl
1523  << file->fileName_ << " fd:" << fileDescriptor_;
1524  }
1525  //fill chunk (skipping file header if present)
1526  for (unsigned int i = 0; i < readBlocks_; i++) {
1527  const ssize_t last = ::read(fileDescriptor_,
1528  (void*)(file->chunks_[0]->buf_ + existingSize),
1529  eventChunkBlock_ - (i == readBlocks_ - 1 ? existingSize : 0));
1531  existingSize += last;
1532  }
1533 
1534  } else {
1535  //continue reading
1536  if (file->chunkPosition_ == 0) { //in the rare case the last byte barely fit
1537  for (unsigned int i = 0; i < readBlocks_; i++) {
1538  const ssize_t last = ::read(fileDescriptor_, (void*)(file->chunks_[0]->buf_ + existingSize), eventChunkBlock_);
1540  existingSize += last;
1541  }
1542  } else {
1543  //event didn't fit in last chunk, so leftover must be moved to the beginning and completed
1544  uint32_t existingSizeLeft = eventChunkSize_ - file->chunkPosition_;
1545  memmove((void*)file->chunks_[0]->buf_, file->chunks_[0]->buf_ + file->chunkPosition_, existingSizeLeft);
1546 
1547  //calculate amount of data that can be added
1548  const uint32_t blockcount = file->chunkPosition_ / eventChunkBlock_;
1549  const uint32_t leftsize = file->chunkPosition_ % eventChunkBlock_;
1550 
1551  for (uint32_t i = 0; i < blockcount; i++) {
1552  const ssize_t last =
1553  ::read(fileDescriptor_, (void*)(file->chunks_[0]->buf_ + existingSizeLeft), eventChunkBlock_);
1555  existingSizeLeft += last;
1556  }
1557  if (leftsize) {
1558  const ssize_t last = ::read(fileDescriptor_, (void*)(file->chunks_[0]->buf_ + existingSizeLeft), leftsize);
1560  }
1561  file->chunkPosition_ = 0; //data was moved to beginning of the chunk
1562  }
1563  }
1564  if (bufferInputRead_ == file->fileSize_) { // no more data in this file
1565  if (fileDescriptor_ != -1) {
1566  LogDebug("FedRawDataInputSource") << "Closing input file -: " << std::endl << file->fileName_;
1567  close(fileDescriptor_);
1568  file->rawFd_ = fileDescriptor_ = -1;
1569  }
1570  }
1571 }
void read(edm::EventPrincipal &eventPrincipal) override
#define LogDebug(id)

◆ readSupervisor()

void FedRawDataInputSource::readSupervisor ( )
private

Definition at line 771 of file FedRawDataInputSource.cc.

References alwaysStartFromFirstLS_, cms::cuda::assert(), cvReader_, cvWakeup_, daqDirector_, relativeConstraints::empty, eventChunkSize_, fileListMode_, fileQueue_, fms_, freeChunks_, getFile(), getLSFromFilename_, evf::EvFDaqDirector::getLumisectionToStart(), evf::EvFDaqDirector::getNextFromFileBroker(), evf::EvFDaqDirector::getStartLumisectionFromEnv(), evf::EvFDaqDirector::grabNextJsonFileAndUnlock(), evf::EvFDaqDirector::grabNextJsonFromRaw(), mps_fire::i, dqmiodatasetharvest::inf, InputFile, evf::EvFDaqDirector::inputThrottled(), evf::FastMonState::inRunEnd, evf::FastMonState::inSupBusy, evf::FastMonState::inSupFileLimit, evf::FastMonState::inSupLockPolling, evf::FastMonState::inSupNewFile, evf::FastMonState::inSupNewFileWaitChunk, evf::FastMonState::inSupNewFileWaitChunkCopying, evf::FastMonState::inSupNewFileWaitThread, evf::FastMonState::inSupNewFileWaitThreadCopying, evf::FastMonState::inSupNoFile, evf::FastMonState::inSupWaitFreeChunk, evf::FastMonState::inSupWaitFreeChunkCopying, evf::FastMonState::inSupWaitFreeThread, evf::FastMonState::inSupWaitFreeThreadCopying, createfilelist::int, evf::FastMonState::inThrottled, dqmiolumiharvest::j, LogDebug, eostools::ls(), evf::EvFDaqDirector::lumisectionDiscarded(), maxBufferedFiles_, SiStripPI::min, eostools::move(), mReader_, mWakeup_, evf::EvFDaqDirector::newFile, evf::EvFDaqDirector::newLumi, evf::EvFDaqDirector::noFile, evf::EvFDaqDirector::numConcurrentLumis(), evf::EvFDaqDirector::parseFRDFileHeader(), castor_dqm_sourceclient_file_cfg::path, funct::pow(), quit_threads_, InputChunk::readComplete_, readingFilesCount_, evf::FastMonitoringService::reportLockWait(), InputChunk::reset(), evf::EvFDaqDirector::runAbort, evf::EvFDaqDirector::runEnded, setExceptionState_, setMonStateSup(), edm::shutdown_flag, singleBufferMode_, evf::FastMonitoringService::startedLookingForFile(), startupCv_, startupLock_, edm_modernize_messagelogger::stat, mps_update::status, evf::FastMonitoringService::stoppedLookingForFile(), AlCaHLTBitMon_QueryRunRegistry::string, thread_quit_signal, tid_active_, mps_check::timeout, evf::EvFDaqDirector::unlockFULocal(), evf::EvFDaqDirector::updateFuLock(), useFileBroker_, workerJob_, workerPool_, and workerThreads_.

Referenced by checkNext().

771  {
772  bool stop = false;
773  unsigned int currentLumiSection = 0;
774 
775  {
776  std::unique_lock<std::mutex> lk(startupLock_);
777  startupCv_.notify_one();
778  }
779 
780  uint32_t ls = 0;
781  uint32_t monLS = 1;
782  uint32_t lockCount = 0;
783  uint64_t sumLockWaitTimeUs = 0.;
784 
785  while (!stop) {
786  //wait for at least one free thread and chunk
787  int counter = 0;
788 
789  while ((workerPool_.empty() && !singleBufferMode_) || freeChunks_.empty() ||
791  //report state to monitoring
792  if (fms_) {
793  bool copy_active = false;
794  for (auto j : tid_active_)
795  if (j)
796  copy_active = true;
799  else if (freeChunks_.empty()) {
800  if (copy_active)
802  else
804  } else {
805  if (copy_active)
807  else
809  }
810  }
811  std::unique_lock<std::mutex> lkw(mWakeup_);
812  //sleep until woken up by condition or a timeout
813  if (cvWakeup_.wait_for(lkw, std::chrono::milliseconds(100)) == std::cv_status::timeout) {
814  counter++;
815  if (!(counter % 6000)) {
816  edm::LogWarning("FedRawDataInputSource")
817  << "No free chunks or threads. Worker pool empty:" << workerPool_.empty()
818  << ", free chunks empty:" << freeChunks_.empty() << ", number of files buffered:" << readingFilesCount_
819  << " / " << maxBufferedFiles_;
820  }
821  LogDebug("FedRawDataInputSource") << "No free chunks or threads...";
822  } else {
823  assert(!(workerPool_.empty() && !singleBufferMode_) || freeChunks_.empty());
824  }
825  if (quit_threads_.load(std::memory_order_relaxed) || edm::shutdown_flag.load(std::memory_order_relaxed)) {
826  stop = true;
827  break;
828  }
829  }
830  //if this is reached, there are enough buffers and threads to proceed or processing is instructed to stop
831 
832  if (stop)
833  break;
834 
835  //look for a new file
836  std::string nextFile;
837  uint32_t fileSizeIndex;
838  int64_t fileSizeFromMetadata;
839 
840  if (fms_) {
843  }
844 
846  uint16_t rawHeaderSize = 0;
847  uint32_t lsFromRaw = 0;
848  int32_t serverEventsInNewFile = -1;
849  int rawFd = -1;
850 
851  int backoff_exp = 0;
852 
853  //entering loop which tries to grab new file from ramdisk
855  //check if hltd has signalled to throttle input
856  counter = 0;
857  while (daqDirector_->inputThrottled()) {
858  if (quit_threads_.load(std::memory_order_relaxed) || edm::shutdown_flag.load(std::memory_order_relaxed))
859  break;
860 
861  unsigned int nConcurrentLumis = daqDirector_->numConcurrentLumis();
862  unsigned int nOtherLumis = nConcurrentLumis > 0 ? nConcurrentLumis - 1 : 0;
863  unsigned int checkLumiStart = currentLumiSection > nOtherLumis ? currentLumiSection - nOtherLumis : 1;
864  bool hasDiscardedLumi = false;
865  for (unsigned int i = checkLumiStart; i <= currentLumiSection; i++) {
867  edm::LogWarning("FedRawDataInputSource") << "Source detected that the lumisection is discarded -: " << i;
868  hasDiscardedLumi = true;
869  break;
870  }
871  }
872  if (hasDiscardedLumi)
873  break;
874 
876 
877  if (!(counter % 50))
878  edm::LogWarning("FedRawDataInputSource") << "Input throttled detected, reading files is paused...";
879  usleep(100000);
880  counter++;
881  }
882 
883  if (quit_threads_.load(std::memory_order_relaxed) || edm::shutdown_flag.load(std::memory_order_relaxed)) {
884  stop = true;
885  break;
886  }
887 
888  assert(rawFd == -1);
889  uint64_t thisLockWaitTimeUs = 0.;
891  if (fileListMode_) {
892  //return LS if LS not set, otherwise return file
893  status = getFile(ls, nextFile, fileSizeIndex, thisLockWaitTimeUs);
896  rawFd,
897  rawHeaderSize,
898  lsFromRaw,
899  serverEventsInNewFile,
900  fileSizeFromMetadata,
901  false,
902  false,
903  false) != 0) {
904  //error
905  setExceptionState_ = true;
906  stop = true;
907  break;
908  }
909  if (!getLSFromFilename_)
910  ls = lsFromRaw;
911  }
912  } else if (!useFileBroker_)
914  ls, nextFile, fileSizeIndex, rawHeaderSize, thisLockWaitTimeUs, setExceptionState_);
915  else {
916  status = daqDirector_->getNextFromFileBroker(currentLumiSection,
917  ls,
918  nextFile,
919  rawFd,
920  rawHeaderSize,
921  serverEventsInNewFile,
922  fileSizeFromMetadata,
923  thisLockWaitTimeUs);
924  }
925 
927 
928  //cycle through all remaining LS even if no files get assigned
929  if (currentLumiSection != ls && status == evf::EvFDaqDirector::runEnded)
931 
932  //monitoring of lock wait time
933  if (thisLockWaitTimeUs > 0.)
934  sumLockWaitTimeUs += thisLockWaitTimeUs;
935  lockCount++;
936  if (ls > monLS) {
937  monLS = ls;
938  if (lockCount)
939  if (fms_)
940  fms_->reportLockWait(monLS, sumLockWaitTimeUs, lockCount);
941  lockCount = 0;
942  sumLockWaitTimeUs = 0;
943  }
944 
945  //check again for any remaining index/EoLS files after EoR file is seen
948  usleep(100000);
949  //now all files should have appeared in ramdisk, check again if any raw files were left behind
951  ls, nextFile, fileSizeIndex, rawHeaderSize, thisLockWaitTimeUs, setExceptionState_);
952  if (currentLumiSection != ls && status == evf::EvFDaqDirector::runEnded)
954  }
955 
957  std::unique_ptr<InputFile> inf(new InputFile(evf::EvFDaqDirector::runEnded));
958  fileQueue_.push(std::move(inf));
959  stop = true;
960  break;
961  }
962 
963  //error from filelocking function
965  std::unique_ptr<InputFile> inf(new InputFile(evf::EvFDaqDirector::runAbort, 0));
966  fileQueue_.push(std::move(inf));
967  stop = true;
968  break;
969  }
970  //queue new lumisection
971  if (getLSFromFilename_) {
972  if (ls > currentLumiSection) {
973  if (!useFileBroker_) {
974  //file locking
975  //setMonStateSup(inSupNewLumi);
976  currentLumiSection = ls;
977  std::unique_ptr<InputFile> inf(new InputFile(evf::EvFDaqDirector::newLumi, currentLumiSection));
978  fileQueue_.push(std::move(inf));
979  } else {
980  //new file service
981  if (currentLumiSection == 0 && !alwaysStartFromFirstLS_) {
983  //start transitions from LS specified by env, continue if not reached
984  if (ls < daqDirector_->getStartLumisectionFromEnv()) {
985  //skip file if from earlier LS than specified by env
986  if (rawFd != -1) {
987  close(rawFd);
988  rawFd = -1;
989  }
991  continue;
992  } else {
993  std::unique_ptr<InputFile> inf(new InputFile(evf::EvFDaqDirector::newLumi, ls));
994  fileQueue_.push(std::move(inf));
995  }
996  } else if (ls < 100) {
997  //look at last LS file on disk to start from that lumisection (only within first 100 LS)
998  unsigned int lsToStart = daqDirector_->getLumisectionToStart();
999 
1000  for (unsigned int nextLS = std::min(lsToStart, ls); nextLS <= ls; nextLS++) {
1001  std::unique_ptr<InputFile> inf(new InputFile(evf::EvFDaqDirector::newLumi, nextLS));
1002  fileQueue_.push(std::move(inf));
1003  }
1004  } else {
1005  //start from current LS
1006  std::unique_ptr<InputFile> inf(new InputFile(evf::EvFDaqDirector::newLumi, ls));
1007  fileQueue_.push(std::move(inf));
1008  }
1009  } else {
1010  //queue all lumisections after last one seen to avoid gaps
1011  for (unsigned int nextLS = currentLumiSection + 1; nextLS <= ls; nextLS++) {
1012  std::unique_ptr<InputFile> inf(new InputFile(evf::EvFDaqDirector::newLumi, nextLS));
1013  fileQueue_.push(std::move(inf));
1014  }
1015  }
1016  currentLumiSection = ls;
1017  }
1018  }
1019  //else
1020  if (currentLumiSection > 0 && ls < currentLumiSection) {
1021  edm::LogError("FedRawDataInputSource")
1022  << "Got old LS (" << ls << ") file from EvFDAQDirector! Expected LS:" << currentLumiSection
1023  << ". Aborting execution." << std::endl;
1024  if (rawFd != -1)
1025  close(rawFd);
1026  rawFd = -1;
1027  std::unique_ptr<InputFile> inf(new InputFile(evf::EvFDaqDirector::runAbort, 0));
1028  fileQueue_.push(std::move(inf));
1029  stop = true;
1030  break;
1031  }
1032  }
1033 
1034  int dbgcount = 0;
1037  dbgcount++;
1038  if (!(dbgcount % 20))
1039  LogDebug("FedRawDataInputSource") << "No file for me... sleep and try again...";
1040  if (!useFileBroker_)
1041  usleep(100000);
1042  else {
1043  backoff_exp = std::min(4, backoff_exp); // max 1.6 seconds
1044  //backoff_exp=0; // disabled!
1045  int sleeptime = (int)(100000. * pow(2, backoff_exp));
1046  usleep(sleeptime);
1047  backoff_exp++;
1048  }
1049  } else
1050  backoff_exp = 0;
1051  }
1052  //end of file grab loop, parse result
1055  LogDebug("FedRawDataInputSource") << "The director says to grab -: " << nextFile;
1056 
1057  std::string rawFile;
1058  //file service will report raw extension
1059  if (useFileBroker_ || rawHeaderSize)
1060  rawFile = nextFile;
1061  else {
1062  std::filesystem::path rawFilePath(nextFile);
1063  rawFile = rawFilePath.replace_extension(".raw").string();
1064  }
1065 
1066  struct stat st;
1067  int stat_res = stat(rawFile.c_str(), &st);
1068  if (stat_res == -1) {
1069  edm::LogError("FedRawDataInputSource") << "Can not stat file (" << errno << "):-" << rawFile << std::endl;
1070  setExceptionState_ = true;
1071  break;
1072  }
1073  uint64_t fileSize = st.st_size;
1074 
1075  if (fms_) {
1079  }
1080  int eventsInNewFile;
1081  if (fileListMode_) {
1082  if (fileSize == 0)
1083  eventsInNewFile = 0;
1084  else
1085  eventsInNewFile = -1;
1086  } else {
1088  if (!useFileBroker_) {
1089  if (rawHeaderSize) {
1090  int rawFdEmpty = -1;
1091  uint16_t rawHeaderCheck;
1092  bool fileFound;
1093  eventsInNewFile = daqDirector_->grabNextJsonFromRaw(
1094  nextFile, rawFdEmpty, rawHeaderCheck, fileSizeFromMetadata, fileFound, 0, true);
1095  assert(fileFound && rawHeaderCheck == rawHeaderSize);
1097  } else
1098  eventsInNewFile = daqDirector_->grabNextJsonFileAndUnlock(nextFile);
1099  } else
1100  eventsInNewFile = serverEventsInNewFile;
1101  assert(eventsInNewFile >= 0);
1102  assert((eventsInNewFile > 0) ==
1103  (fileSize > rawHeaderSize)); //file without events must be empty or contain only header
1104  }
1105 
1106  if (!singleBufferMode_) {
1107  //calculate number of needed chunks
1108  unsigned int neededChunks = fileSize / eventChunkSize_;
1109  if (fileSize % eventChunkSize_)
1110  neededChunks++;
1111 
1112  std::unique_ptr<InputFile> newInputFile(new InputFile(evf::EvFDaqDirector::FileStatus::newFile,
1113  ls,
1114  rawFile,
1115  !fileListMode_,
1116  rawFd,
1117  fileSize,
1118  rawHeaderSize,
1119  neededChunks,
1120  eventsInNewFile,
1121  this));
1123  auto newInputFilePtr = newInputFile.get();
1124  fileQueue_.push(std::move(newInputFile));
1125 
1126  for (unsigned int i = 0; i < neededChunks; i++) {
1127  if (fms_) {
1128  bool copy_active = false;
1129  for (auto j : tid_active_)
1130  if (j)
1131  copy_active = true;
1132  if (copy_active)
1134  else
1136  }
1137  //get thread
1138  unsigned int newTid = 0xffffffff;
1139  while (!workerPool_.try_pop(newTid)) {
1140  usleep(100000);
1141  if (quit_threads_.load(std::memory_order_relaxed)) {
1142  stop = true;
1143  break;
1144  }
1145  }
1146 
1147  if (fms_) {
1148  bool copy_active = false;
1149  for (auto j : tid_active_)
1150  if (j)
1151  copy_active = true;
1152  if (copy_active)
1154  else
1156  }
1157  InputChunk* newChunk = nullptr;
1158  while (!freeChunks_.try_pop(newChunk)) {
1159  usleep(100000);
1160  if (quit_threads_.load(std::memory_order_relaxed)) {
1161  stop = true;
1162  break;
1163  }
1164  }
1165 
1166  if (newChunk == nullptr) {
1167  //return unused tid if we received shutdown (nullptr chunk)
1168  if (newTid != 0xffffffff)
1169  workerPool_.push(newTid);
1170  stop = true;
1171  break;
1172  }
1173  if (stop)
1174  break;
1176 
1177  std::unique_lock<std::mutex> lk(mReader_);
1178 
1179  unsigned int toRead = eventChunkSize_;
1180  if (i == neededChunks - 1 && fileSize % eventChunkSize_)
1181  toRead = fileSize % eventChunkSize_;
1182  newChunk->reset(i * eventChunkSize_, toRead, i);
1183 
1184  workerJob_[newTid].first = newInputFilePtr;
1185  workerJob_[newTid].second = newChunk;
1186 
1187  //wake up the worker thread
1188  cvReader_[newTid]->notify_one();
1189  }
1190  } else {
1191  if (!eventsInNewFile) {
1192  if (rawFd) {
1193  close(rawFd);
1194  rawFd = -1;
1195  }
1196  //still queue file for lumi update
1197  std::unique_lock<std::mutex> lkw(mWakeup_);
1198  //TODO: also file with only file header fits in this edge case. Check if read correctly in single buffer mode
1199  std::unique_ptr<InputFile> newInputFile(new InputFile(evf::EvFDaqDirector::FileStatus::newFile,
1200  ls,
1201  rawFile,
1202  !fileListMode_,
1203  rawFd,
1204  fileSize,
1205  rawHeaderSize,
1206  (rawHeaderSize > 0),
1207  0,
1208  this));
1210  fileQueue_.push(std::move(newInputFile));
1211  cvWakeup_.notify_one();
1212  break;
1213  }
1214  //in single-buffer mode put single chunk in the file and let the main thread read the file
1215  InputChunk* newChunk;
1216  //should be available immediately
1217  while (!freeChunks_.try_pop(newChunk)) {
1218  usleep(100000);
1219  if (quit_threads_.load(std::memory_order_relaxed))
1220  break;
1221  }
1222 
1223  std::unique_lock<std::mutex> lkw(mWakeup_);
1224 
1225  unsigned int toRead = eventChunkSize_;
1226  if (fileSize % eventChunkSize_)
1227  toRead = fileSize % eventChunkSize_;
1228  newChunk->reset(0, toRead, 0);
1229  newChunk->readComplete_ = true;
1230 
1231  //push file and wakeup main thread
1232  std::unique_ptr<InputFile> newInputFile(new InputFile(evf::EvFDaqDirector::FileStatus::newFile,
1233  ls,
1234  rawFile,
1235  !fileListMode_,
1236  rawFd,
1237  fileSize,
1238  rawHeaderSize,
1239  1,
1240  eventsInNewFile,
1241  this));
1242  newInputFile->chunks_[0] = newChunk;
1244  fileQueue_.push(std::move(newInputFile));
1245  cvWakeup_.notify_one();
1246  }
1247  }
1248  }
1250  //make sure threads finish reading
1251  unsigned numFinishedThreads = 0;
1252  while (numFinishedThreads < workerThreads_.size()) {
1253  unsigned tid = 0;
1254  while (!workerPool_.try_pop(tid)) {
1255  usleep(10000);
1256  }
1257  std::unique_lock<std::mutex> lk(mReader_);
1258  thread_quit_signal[tid] = true;
1259  cvReader_[tid]->notify_one();
1260  numFinishedThreads++;
1261  }
1262  for (unsigned int i = 0; i < workerThreads_.size(); i++) {
1263  workerThreads_[i]->join();
1264  delete workerThreads_[i];
1265  }
1266 }
std::condition_variable cvWakeup_
tbb::concurrent_queue< unsigned int > workerPool_
evf::EvFDaqDirector::FileStatus getFile(unsigned int &ls, std::string &nextFile, uint32_t &fsize, uint64_t &lockWaitTime)
volatile std::atomic< bool > shutdown_flag
tbb::concurrent_queue< std::unique_ptr< InputFile > > fileQueue_
std::atomic< bool > quit_threads_
std::vector< ReaderInfo > workerJob_
bool lumisectionDiscarded(unsigned int ls)
FileStatus getNextFromFileBroker(const unsigned int currentLumiSection, unsigned int &ls, std::string &nextFile, int &rawFd, uint16_t &rawHeaderSize, int32_t &serverEventsInNewFile_, int64_t &fileSize, uint64_t &thisLockWaitTimeUs)
Log< level::Error, false > LogError
unsigned int numConcurrentLumis() const
int timeout
Definition: mps_check.py:53
assert(be >=bs)
void reset(unsigned int newOffset, unsigned int toRead, unsigned int fileIndex)
static int parseFRDFileHeader(std::string const &rawSourcePath, int &rawFd, uint16_t &rawHeaderSize, uint32_t &lsFromHeader, int32_t &eventsFromHeader, int64_t &fileSizeFromHeader, bool requireHeader, bool retry, bool closeFile)
void setMonStateSup(evf::FastMonState::InputState state)
int grabNextJsonFileAndUnlock(std::filesystem::path const &jsonSourcePath)
std::vector< std::thread * > workerThreads_
std::atomic< bool > readComplete_
FileStatus updateFuLock(unsigned int &ls, std::string &nextFile, uint32_t &fsize, uint16_t &rawHeaderSize, uint64_t &lockWaitTime, bool &setExceptionState)
def ls(path, rec=False)
Definition: eostools.py:349
unsigned int getStartLumisectionFromEnv() const
int grabNextJsonFromRaw(std::string const &rawSourcePath, int &rawFd, uint16_t &rawHeaderSize, int64_t &fileSizeFromHeader, bool &fileFound, uint32_t serverLS, bool closeFile)
unsigned long long uint64_t
Definition: Time.h:13
std::condition_variable startupCv_
void stoppedLookingForFile(unsigned int lumi)
evf::EvFDaqDirector * daqDirector_
std::vector< unsigned int > thread_quit_signal
unsigned int getLumisectionToStart() const
std::atomic< unsigned int > readingFilesCount_
std::vector< std::unique_ptr< std::condition_variable > > cvReader_
evf::FastMonitoringService * fms_
std::vector< unsigned int > tid_active_
tbb::concurrent_queue< InputChunk * > freeChunks_
Log< level::Warning, false > LogWarning
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
def move(src, dest)
Definition: eostools.py:511
void reportLockWait(unsigned int ls, double waitTime, unsigned int lockCount)
#define LogDebug(id)

◆ readWorker()

void FedRawDataInputSource::readWorker ( unsigned int  tid)
private

Definition at line 1268 of file FedRawDataInputSource.cc.

References cms::cuda::assert(), InputChunk::buf_, cvReader_, detectedFRDversion_, change_name::diff, mps_fire::end, eventChunkBlock_, geometryDiff::file, InputChunk::fileIndex_, dqmdumpme::first, FRDHeaderMaxVersion, mps_fire::i, caHitNtupletGeneratorKernels::if(), dqmdumpme::last, LogDebug, SiStripPI::min, mReader_, submitPVValidationJobs::now, numConcurrentReads_, InputChunk::offset_, read(), readBlocks_, InputChunk::readComplete_, edm::second(), setExceptionState_, runEdmFileComparison::skipped, command_line::start, startupCv_, startupLock_, thread_quit_signal, tid_active_, InputChunk::usedSize_, workerJob_, and workerPool_.

Referenced by FedRawDataInputSource().

1268  {
1269  bool init = true;
1270 
1271  while (true) {
1272  tid_active_[tid] = false;
1273  std::unique_lock<std::mutex> lk(mReader_);
1274  workerJob_[tid].first = nullptr;
1275  workerJob_[tid].first = nullptr;
1276 
1277  assert(!thread_quit_signal[tid]); //should never get it here
1278  workerPool_.push(tid);
1279 
1280  if (init) {
1281  std::unique_lock<std::mutex> lk(startupLock_);
1282  init = false;
1283  startupCv_.notify_one();
1284  }
1285  cvReader_[tid]->wait(lk);
1286 
1287  if (thread_quit_signal[tid])
1288  return;
1289  tid_active_[tid] = true;
1290 
1291  InputFile* file;
1292  InputChunk* chunk;
1293 
1294  assert(workerJob_[tid].first != nullptr && workerJob_[tid].second != nullptr);
1295 
1296  file = workerJob_[tid].first;
1297  chunk = workerJob_[tid].second;
1298 
1299  //skip reading initial header size in first chunk if inheriting file descriptor (already set at appropriate position)
1300  unsigned int bufferLeft = (chunk->offset_ == 0 && file->rawFd_ != -1) ? file->rawHeaderSize_ : 0;
1301 
1302  //if only one worker thread exists, use single fd for all operations
1303  //if more worker threads exist, use rawFd_ for only the first read operation and then close file
1304  int fileDescriptor;
1305  bool fileOpenedHere = false;
1306 
1307  if (numConcurrentReads_ == 1) {
1308  fileDescriptor = file->rawFd_;
1309  if (fileDescriptor == -1) {
1310  fileDescriptor = open(file->fileName_.c_str(), O_RDONLY);
1311  fileOpenedHere = true;
1312  file->rawFd_ = fileDescriptor;
1313  }
1314  } else {
1315  if (chunk->offset_ == 0) {
1316  fileDescriptor = file->rawFd_;
1317  file->rawFd_ = -1;
1318  if (fileDescriptor == -1) {
1319  fileDescriptor = open(file->fileName_.c_str(), O_RDONLY);
1320  fileOpenedHere = true;
1321  }
1322  } else {
1323  fileDescriptor = open(file->fileName_.c_str(), O_RDONLY);
1324  fileOpenedHere = true;
1325  }
1326  }
1327 
1328  if (fileDescriptor < 0) {
1329  edm::LogError("FedRawDataInputSource") << "readWorker failed to open file -: " << file->fileName_
1330  << " fd:" << fileDescriptor << " error: " << strerror(errno);
1331  setExceptionState_ = true;
1332  continue;
1333  }
1334  if (fileOpenedHere) { //fast forward to this chunk position
1335  off_t pos = 0;
1336  pos = lseek(fileDescriptor, chunk->offset_, SEEK_SET);
1337  if (pos == -1) {
1338  edm::LogError("FedRawDataInputSource")
1339  << "readWorker failed to seek file -: " << file->fileName_ << " fd:" << fileDescriptor << " to offset "
1340  << chunk->offset_ << " error: " << strerror(errno);
1341  setExceptionState_ = true;
1342  continue;
1343  }
1344  }
1345 
1346  LogDebug("FedRawDataInputSource") << "Reader thread opened file -: TID: " << tid << " file: " << file->fileName_
1347  << " at offset " << lseek(fileDescriptor, 0, SEEK_CUR);
1348 
1349  unsigned int skipped = bufferLeft;
1351  for (unsigned int i = 0; i < readBlocks_; i++) {
1352  ssize_t last;
1353 
1354  //protect against reading into next block
1355  last = ::read(
1356  fileDescriptor, (void*)(chunk->buf_ + bufferLeft), std::min(chunk->usedSize_ - bufferLeft, eventChunkBlock_));
1357 
1358  if (last < 0) {
1359  edm::LogError("FedRawDataInputSource") << "readWorker failed to read file -: " << file->fileName_
1360  << " fd:" << fileDescriptor << " error: " << strerror(errno);
1361  setExceptionState_ = true;
1362  break;
1363  }
1364  if (last > 0)
1365  bufferLeft += last;
1366  if (last < eventChunkBlock_) { //last read
1367  //check if this is last block, then total read size must match file size
1368  if (!(chunk->usedSize_ - skipped == i * eventChunkBlock_ + last)) {
1369  edm::LogError("FedRawDataInputSource")
1370  << "readWorker failed to read file -: " << file->fileName_ << " fd:" << fileDescriptor << " last:" << last
1371  << " expectedChunkSize:" << chunk->usedSize_
1372  << " readChunkSize:" << (skipped + i * eventChunkBlock_ + last) << " skipped:" << skipped
1373  << " block:" << (i + 1) << "/" << readBlocks_ << " error: " << strerror(errno);
1374  setExceptionState_ = true;
1375  }
1376  break;
1377  }
1378  }
1379  if (setExceptionState_)
1380  continue;
1381 
1383  auto diff = end - start;
1384  std::chrono::milliseconds msec = std::chrono::duration_cast<std::chrono::milliseconds>(diff);
1385  LogDebug("FedRawDataInputSource") << " finished reading block -: " << (bufferLeft >> 20) << " MB"
1386  << " in " << msec.count() << " ms (" << (bufferLeft >> 20) / double(msec.count())
1387  << " GB/s)";
1388 
1389  if (chunk->offset_ + bufferLeft == file->fileSize_) { //file reading finished using same fd
1390  close(fileDescriptor);
1391  fileDescriptor = -1;
1392  if (numConcurrentReads_ == 1)
1393  file->rawFd_ = -1;
1394  }
1395  if (numConcurrentReads_ > 1 && fileDescriptor != -1)
1396  close(fileDescriptor);
1397 
1398  //detect FRD event version. Skip file Header if it exists
1399  if (detectedFRDversion_ == 0 && chunk->offset_ == 0) {
1400  detectedFRDversion_ = *((uint16_t*)(chunk->buf_ + file->rawHeaderSize_));
1401  }
1403  chunk->readComplete_ =
1404  true; //this is atomic to secure the sequential buffer fill before becoming available for processing)
1405  file->chunks_[chunk->fileIndex_] = chunk; //put the completed chunk in the file chunk vector at predetermined index
1406  }
1407 }
Definition: start.py:1
void read(edm::EventPrincipal &eventPrincipal) override
constexpr size_t FRDHeaderMaxVersion
unsigned int offset_
tbb::concurrent_queue< unsigned int > workerPool_
std::vector< ReaderInfo > workerJob_
Log< level::Error, false > LogError
assert(be >=bs)
U second(std::pair< T, U > const &p)
unsigned char * buf_
unsigned int fileIndex_
std::atomic< bool > readComplete_
Definition: init.py:1
std::condition_variable startupCv_
std::vector< unsigned int > thread_quit_signal
std::vector< std::unique_ptr< std::condition_variable > > cvReader_
std::vector< unsigned int > tid_active_
#define LogDebug(id)

◆ reportEventsThisLumiInSource()

void FedRawDataInputSource::reportEventsThisLumiInSource ( unsigned int  lumi,
unsigned int  events 
)
private

Definition at line 1573 of file FedRawDataInputSource.cc.

References events, CommonMethods::lock(), monlock_, and sourceEventsReport_.

Referenced by checkNext(), and getNextEvent().

1573  {
1574  std::lock_guard<std::mutex> lock(monlock_);
1575  auto itr = sourceEventsReport_.find(lumi);
1576  if (itr != sourceEventsReport_.end())
1577  itr->second += events;
1578  else
1580 }
std::map< unsigned int, unsigned int > sourceEventsReport_
int events

◆ rewind_()

void FedRawDataInputSource::rewind_ ( )
overrideprivatevirtual

Reimplemented from edm::InputSource.

Definition at line 769 of file FedRawDataInputSource.cc.

769 {}

◆ setMonState()

void FedRawDataInputSource::setMonState ( evf::FastMonState::InputState  state)
inlineprotected

Definition at line 1414 of file FedRawDataInputSource.cc.

References fms_, evf::FastMonitoringService::setInState(), and edm::InputSource::state().

Referenced by InputFile::advance(), checkNext(), getNextEvent(), and read().

1414  {
1415  if (fms_)
1416  fms_->setInState(state);
1417 }
ItemType state() const
Definition: InputSource.h:332
evf::FastMonitoringService * fms_
void setInState(FastMonState::InputState inputState)

◆ setMonStateSup()

void FedRawDataInputSource::setMonStateSup ( evf::FastMonState::InputState  state)
inlineprotected

Definition at line 1419 of file FedRawDataInputSource.cc.

References fms_, evf::FastMonitoringService::setInStateSup(), and edm::InputSource::state().

Referenced by readSupervisor().

1419  {
1420  if (fms_)
1422 }
void setInStateSup(FastMonState::InputState inputState)
ItemType state() const
Definition: InputSource.h:332
evf::FastMonitoringService * fms_

◆ threadError()

void FedRawDataInputSource::threadError ( )
private

Definition at line 1409 of file FedRawDataInputSource.cc.

References Exception, and quit_threads_.

Referenced by InputFile::advance(), and getNextEvent().

1409  {
1410  quit_threads_ = true;
1411  throw cms::Exception("FedRawDataInputSource:threadError") << " file reader thread error ";
1412 }
std::atomic< bool > quit_threads_

Friends And Related Function Documentation

◆ InputChunk

friend struct InputChunk
friend

Definition at line 42 of file FedRawDataInputSource.h.

Referenced by FedRawDataInputSource().

◆ InputFile

friend struct InputFile
friend

Definition at line 41 of file FedRawDataInputSource.h.

Referenced by readSupervisor().

Member Data Documentation

◆ alwaysStartFromFirstLS_

const bool FedRawDataInputSource::alwaysStartFromFirstLS_
private

Definition at line 98 of file FedRawDataInputSource.h.

Referenced by readSupervisor().

◆ bufferInputRead_

uint32_t FedRawDataInputSource::bufferInputRead_ = 0
private

Definition at line 178 of file FedRawDataInputSource.h.

Referenced by getNextEvent(), and readNextChunkIntoBuffer().

◆ checkEvery_

unsigned int FedRawDataInputSource::checkEvery_ = 10
private

Definition at line 169 of file FedRawDataInputSource.h.

Referenced by read().

◆ chunkIsFree_

bool FedRawDataInputSource::chunkIsFree_ = false
private

Definition at line 142 of file FedRawDataInputSource.h.

Referenced by getNextEvent(), and read().

◆ currentFile_

std::unique_ptr<InputFile> FedRawDataInputSource::currentFile_
private

Definition at line 141 of file FedRawDataInputSource.h.

Referenced by getNextEvent(), read(), and ~FedRawDataInputSource().

◆ currentFileIndex_

int FedRawDataInputSource::currentFileIndex_ = -1
private

Definition at line 164 of file FedRawDataInputSource.h.

Referenced by getNextEvent(), and read().

◆ currentLumiSection_

unsigned int FedRawDataInputSource::currentLumiSection_
private

Definition at line 121 of file FedRawDataInputSource.h.

Referenced by checkNext(), getNextEvent(), maybeOpenNewLumiSection(), and read().

◆ cvReader_

std::vector<std::unique_ptr<std::condition_variable> > FedRawDataInputSource::cvReader_
private

◆ cvWakeup_

std::condition_variable FedRawDataInputSource::cvWakeup_
private

Definition at line 173 of file FedRawDataInputSource.h.

Referenced by getNextEvent(), and readSupervisor().

◆ daqDirector_

evf::EvFDaqDirector* FedRawDataInputSource::daqDirector_ = nullptr
private

◆ daqProvenanceHelper_

const edm::DaqProvenanceHelper FedRawDataInputSource::daqProvenanceHelper_
private

Definition at line 114 of file FedRawDataInputSource.h.

Referenced by FedRawDataInputSource(), and read().

◆ defPath_

std::string FedRawDataInputSource::defPath_
private

Definition at line 86 of file FedRawDataInputSource.h.

◆ detectedFRDversion_

uint16_t FedRawDataInputSource::detectedFRDversion_ = 0
private

Definition at line 140 of file FedRawDataInputSource.h.

Referenced by getNextEvent(), and readWorker().

◆ event_

std::unique_ptr<FRDEventMsgView> FedRawDataInputSource::event_
private

Definition at line 116 of file FedRawDataInputSource.h.

Referenced by checkNext(), fillFEDRawDataCollection(), getNextEvent(), and read().

◆ eventChunkBlock_

unsigned int FedRawDataInputSource::eventChunkBlock_
private

◆ eventChunkSize_

unsigned int FedRawDataInputSource::eventChunkSize_
private

◆ eventID_

edm::EventID FedRawDataInputSource::eventID_
private

Definition at line 118 of file FedRawDataInputSource.h.

Referenced by read().

◆ eventRunNumber_

uint32_t FedRawDataInputSource::eventRunNumber_ = 0
private

Definition at line 122 of file FedRawDataInputSource.h.

Referenced by checkNext(), and read().

◆ eventsThisLumi_

unsigned int FedRawDataInputSource::eventsThisLumi_
private

Definition at line 126 of file FedRawDataInputSource.h.

Referenced by checkNext(), getNextEvent(), and read().

◆ eventsThisRun_

unsigned long FedRawDataInputSource::eventsThisRun_ = 0
private

Definition at line 127 of file FedRawDataInputSource.h.

◆ fileDeleteLock_

std::mutex FedRawDataInputSource::fileDeleteLock_
private

Definition at line 167 of file FedRawDataInputSource.h.

Referenced by FedRawDataInputSource(), getNextEvent(), and read().

◆ fileDescriptor_

int FedRawDataInputSource::fileDescriptor_ = -1
private

Definition at line 177 of file FedRawDataInputSource.h.

Referenced by readNextChunkIntoBuffer().

◆ fileListIndex_

unsigned int FedRawDataInputSource::fileListIndex_ = 0
private

Definition at line 107 of file FedRawDataInputSource.h.

Referenced by getFile().

◆ fileListLoopMode_

const bool FedRawDataInputSource::fileListLoopMode_
private

Definition at line 108 of file FedRawDataInputSource.h.

Referenced by checkNext(), FedRawDataInputSource(), getFile(), and read().

◆ fileListMode_

const bool FedRawDataInputSource::fileListMode_
private

◆ fileNames_

std::vector<std::string> FedRawDataInputSource::fileNames_
private

Definition at line 102 of file FedRawDataInputSource.h.

Referenced by getFile(), and initFileList().

◆ fileNamesToDelete_

std::list<std::pair<int, std::string> > FedRawDataInputSource::fileNamesToDelete_
private

Definition at line 166 of file FedRawDataInputSource.h.

◆ fileQueue_

tbb::concurrent_queue<std::unique_ptr<InputFile> > FedRawDataInputSource::fileQueue_
private

Definition at line 152 of file FedRawDataInputSource.h.

Referenced by getNextEvent(), and readSupervisor().

◆ filesToDelete_

std::list<std::pair<int, std::unique_ptr<InputFile> > > FedRawDataInputSource::filesToDelete_
private

◆ fms_

evf::FastMonitoringService* FedRawDataInputSource::fms_ = nullptr
private

◆ freeChunks_

tbb::concurrent_queue<InputChunk*> FedRawDataInputSource::freeChunks_
private

Definition at line 151 of file FedRawDataInputSource.h.

Referenced by FedRawDataInputSource(), getNextEvent(), read(), and readSupervisor().

◆ fuOutputDir_

std::string FedRawDataInputSource::fuOutputDir_
private

Definition at line 112 of file FedRawDataInputSource.h.

◆ getLSFromFilename_

const bool FedRawDataInputSource::getLSFromFilename_
private

Definition at line 97 of file FedRawDataInputSource.h.

Referenced by checkNext(), getNextEvent(), and readSupervisor().

◆ GTPEventID_

uint32_t FedRawDataInputSource::GTPEventID_ = 0
private

Definition at line 123 of file FedRawDataInputSource.h.

Referenced by fillFEDRawDataCollection(), and read().

◆ L1EventID_

uint32_t FedRawDataInputSource::L1EventID_ = 0
private

Definition at line 124 of file FedRawDataInputSource.h.

Referenced by checkNext(), and read().

◆ loopModeIterationInc_

unsigned int FedRawDataInputSource::loopModeIterationInc_ = 0
private

Definition at line 109 of file FedRawDataInputSource.h.

Referenced by getFile().

◆ maxBufferedFiles_

unsigned int FedRawDataInputSource::maxBufferedFiles_
private

Definition at line 92 of file FedRawDataInputSource.h.

Referenced by readSupervisor().

◆ MAXTCDSuTCAFEDID_

uint16_t FedRawDataInputSource::MAXTCDSuTCAFEDID_ = FEDNumbering::MAXTCDSuTCAFEDID
private

Definition at line 130 of file FedRawDataInputSource.h.

Referenced by FedRawDataInputSource(), and fillFEDRawDataCollection().

◆ MINTCDSuTCAFEDID_

uint16_t FedRawDataInputSource::MINTCDSuTCAFEDID_ = FEDNumbering::MINTCDSuTCAFEDID
private

Definition at line 129 of file FedRawDataInputSource.h.

Referenced by FedRawDataInputSource(), and fillFEDRawDataCollection().

◆ monlock_

std::mutex FedRawDataInputSource::monlock_
private

Definition at line 183 of file FedRawDataInputSource.h.

Referenced by getEventReport(), and reportEventsThisLumiInSource().

◆ mReader_

std::mutex FedRawDataInputSource::mReader_
private

Definition at line 154 of file FedRawDataInputSource.h.

Referenced by readSupervisor(), readWorker(), and ~FedRawDataInputSource().

◆ mWakeup_

std::mutex FedRawDataInputSource::mWakeup_
private

Definition at line 172 of file FedRawDataInputSource.h.

Referenced by getNextEvent(), and readSupervisor().

◆ numBuffers_

unsigned int FedRawDataInputSource::numBuffers_
private

Definition at line 91 of file FedRawDataInputSource.h.

Referenced by FedRawDataInputSource().

◆ numConcurrentReads_

unsigned int FedRawDataInputSource::numConcurrentReads_
private

Definition at line 93 of file FedRawDataInputSource.h.

Referenced by FedRawDataInputSource(), and readWorker().

◆ processHistoryID_

edm::ProcessHistoryID FedRawDataInputSource::processHistoryID_
private

Definition at line 119 of file FedRawDataInputSource.h.

Referenced by FedRawDataInputSource(), maybeOpenNewLumiSection(), and read().

◆ quit_threads_

std::atomic<bool> FedRawDataInputSource::quit_threads_
private

◆ readBlocks_

unsigned int FedRawDataInputSource::readBlocks_
private

◆ readingFilesCount_

std::atomic<unsigned int> FedRawDataInputSource::readingFilesCount_
private

Definition at line 94 of file FedRawDataInputSource.h.

Referenced by FedRawDataInputSource(), getNextEvent(), and readSupervisor().

◆ readSupervisorThread_

std::unique_ptr<std::thread> FedRawDataInputSource::readSupervisorThread_
private

Definition at line 145 of file FedRawDataInputSource.h.

Referenced by checkNext(), and ~FedRawDataInputSource().

◆ runNumber_

edm::RunNumber_t FedRawDataInputSource::runNumber_
private

Definition at line 111 of file FedRawDataInputSource.h.

Referenced by checkNext(), and FedRawDataInputSource().

◆ setExceptionState_

bool FedRawDataInputSource::setExceptionState_ = false
private

Definition at line 160 of file FedRawDataInputSource.h.

Referenced by exceptionState(), getNextEvent(), readSupervisor(), and readWorker().

◆ singleBufferMode_

bool FedRawDataInputSource::singleBufferMode_
private

Definition at line 176 of file FedRawDataInputSource.h.

Referenced by FedRawDataInputSource(), getNextEvent(), and readSupervisor().

◆ sourceEventsReport_

std::map<unsigned int, unsigned int> FedRawDataInputSource::sourceEventsReport_
private

Definition at line 182 of file FedRawDataInputSource.h.

Referenced by getEventReport(), and reportEventsThisLumiInSource().

◆ startedSupervisorThread_

bool FedRawDataInputSource::startedSupervisorThread_ = false
private

Definition at line 144 of file FedRawDataInputSource.h.

Referenced by checkNext(), and ~FedRawDataInputSource().

◆ startupCv_

std::condition_variable FedRawDataInputSource::startupCv_
private

◆ startupLock_

std::mutex FedRawDataInputSource::startupLock_
private

◆ streamFileTracker_

std::vector<int> FedRawDataInputSource::streamFileTracker_
private

Definition at line 168 of file FedRawDataInputSource.h.

Referenced by read().

◆ tcds_pointer_

unsigned char* FedRawDataInputSource::tcds_pointer_
private

Definition at line 125 of file FedRawDataInputSource.h.

Referenced by fillFEDRawDataCollection(), and read().

◆ testTCDSFEDRange_

const std::vector<unsigned int> FedRawDataInputSource::testTCDSFEDRange_
private

Definition at line 101 of file FedRawDataInputSource.h.

Referenced by FedRawDataInputSource().

◆ thread_quit_signal

std::vector<unsigned int> FedRawDataInputSource::thread_quit_signal
private

◆ threadInit_

std::atomic<bool> FedRawDataInputSource::threadInit_
private

Definition at line 180 of file FedRawDataInputSource.h.

◆ tid_active_

std::vector<unsigned int> FedRawDataInputSource::tid_active_
private

Definition at line 156 of file FedRawDataInputSource.h.

Referenced by FedRawDataInputSource(), readSupervisor(), and readWorker().

◆ useFileBroker_

bool FedRawDataInputSource::useFileBroker_
private

◆ useL1EventID_

const bool FedRawDataInputSource::useL1EventID_
private

Definition at line 100 of file FedRawDataInputSource.h.

Referenced by read().

◆ verifyChecksum_

const bool FedRawDataInputSource::verifyChecksum_
private

Definition at line 99 of file FedRawDataInputSource.h.

Referenced by getNextEvent().

◆ workerJob_

std::vector<ReaderInfo> FedRawDataInputSource::workerJob_
private

Definition at line 149 of file FedRawDataInputSource.h.

Referenced by FedRawDataInputSource(), readSupervisor(), and readWorker().

◆ workerPool_

tbb::concurrent_queue<unsigned int> FedRawDataInputSource::workerPool_
private

Definition at line 148 of file FedRawDataInputSource.h.

Referenced by readSupervisor(), and readWorker().

◆ workerThreads_

std::vector<std::thread*> FedRawDataInputSource::workerThreads_
private