CMS 3D CMS Logo

FedRawDataInputSource.cc
Go to the documentation of this file.
1 #include <fcntl.h>
2 #include <iomanip>
3 #include <iostream>
4 #include <memory>
5 #include <sstream>
6 #include <sys/types.h>
7 #include <sys/file.h>
8 #include <sys/time.h>
9 #include <unistd.h>
10 #include <vector>
11 #include <fstream>
12 #include <zlib.h>
13 #include <cstdio>
14 #include <chrono>
15 
16 #include <boost/algorithm/string.hpp>
17 #include <boost/filesystem/fstream.hpp>
18 
22 
24 
31 
33 
35 
39 
41 
46 
47 //JSON file reader
49 
50 #include <boost/lexical_cast.hpp>
51 
53  : edm::RawInputSource(pset, desc),
54  defPath_(pset.getUntrackedParameter<std::string>("buDefPath", "")),
55  eventChunkSize_(pset.getUntrackedParameter<unsigned int>("eventChunkSize", 32) * 1048576),
56  eventChunkBlock_(pset.getUntrackedParameter<unsigned int>("eventChunkBlock", 32) * 1048576),
57  numBuffers_(pset.getUntrackedParameter<unsigned int>("numBuffers", 2)),
58  maxBufferedFiles_(pset.getUntrackedParameter<unsigned int>("maxBufferedFiles", 2)),
59  getLSFromFilename_(pset.getUntrackedParameter<bool>("getLSFromFilename", true)),
60  alwaysStartFromFirstLS_(pset.getUntrackedParameter<bool>("alwaysStartFromFirstLS", false)),
61  verifyChecksum_(pset.getUntrackedParameter<bool>("verifyChecksum", true)),
62  useL1EventID_(pset.getUntrackedParameter<bool>("useL1EventID", false)),
63  testTCDSFEDRange_(
64  pset.getUntrackedParameter<std::vector<unsigned int>>("testTCDSFEDRange", std::vector<unsigned int>())),
65  fileNames_(pset.getUntrackedParameter<std::vector<std::string>>("fileNames", std::vector<std::string>())),
66  fileListMode_(pset.getUntrackedParameter<bool>("fileListMode", false)),
67  fileListLoopMode_(pset.getUntrackedParameter<bool>("fileListLoopMode", false)),
69  daqProvenanceHelper_(edm::TypeID(typeid(FEDRawDataCollection))),
70  eventID_(),
71  processHistoryID_(),
72  currentLumiSection_(0),
73  tcds_pointer_(nullptr),
74  eventsThisLumi_(0) {
75  char thishost[256];
76  gethostname(thishost, 255);
77  edm::LogInfo("FedRawDataInputSource") << "Construction. read-ahead chunk size -: " << std::endl
78  << (eventChunkSize_ / 1048576) << " MB on host " << thishost;
79 
80  if (!testTCDSFEDRange_.empty()) {
81  if (testTCDSFEDRange_.size() != 2) {
82  throw cms::Exception("FedRawDataInputSource::fillFEDRawDataCollection")
83  << "Invalid TCDS Test FED range parameter";
84  }
87  }
88 
89  long autoRunNumber = -1;
90  if (fileListMode_) {
91  autoRunNumber = initFileList();
92  if (!fileListLoopMode_) {
93  if (autoRunNumber < 0)
94  throw cms::Exception("FedRawDataInputSource::FedRawDataInputSource") << "Run number not found from filename";
95  //override run number
96  runNumber_ = (edm::RunNumber_t)autoRunNumber;
97  edm::Service<evf::EvFDaqDirector>()->overrideRunNumber((unsigned int)autoRunNumber);
98  }
99  }
100 
102  setNewRun();
103  //todo:autodetect from file name (assert if names differ)
105 
106  //make sure that chunk size is N * block size
111 
112  if (!numBuffers_)
113  throw cms::Exception("FedRawDataInputSource::FedRawDataInputSource")
114  << "no reading enabled with numBuffers parameter 0";
115 
118  readingFilesCount_ = 0;
119 
120  if (!crc32c_hw_test())
121  edm::LogError("FedRawDataInputSource::FedRawDataInputSource") << "Intel crc32c checksum computation unavailable";
122 
123  //get handles to DaqDirector and FastMonitoringService because getting them isn't possible in readSupervisor thread
124  if (fileListMode_) {
125  try {
126  fms_ = static_cast<evf::FastMonitoringService*>(edm::Service<evf::MicroStateService>().operator->());
127  } catch (cms::Exception const&) {
128  edm::LogInfo("FedRawDataInputSource") << "No FastMonitoringService found in the configuration";
129  }
130  } else {
131  fms_ = static_cast<evf::FastMonitoringService*>(edm::Service<evf::MicroStateService>().operator->());
132  if (!fms_) {
133  throw cms::Exception("FedRawDataInputSource") << "FastMonitoringService not found";
134  }
135  }
136 
138  if (!daqDirector_)
139  cms::Exception("FedRawDataInputSource") << "EvFDaqDirector not found";
140 
142  if (useFileBroker_)
143  edm::LogInfo("FedRawDataInputSource") << "EvFDaqDirector/Source configured to use file service";
144  //set DaqDirector to delete files in preGlobalEndLumi callback
146  if (fms_) {
148  fms_->setInputSource(this);
151  }
152  //should delete chunks when run stops
153  for (unsigned int i = 0; i < numBuffers_; i++) {
155  }
156 
157  quit_threads_ = false;
158 
159  for (unsigned int i = 0; i < numConcurrentReads_; i++) {
160  std::unique_lock<std::mutex> lk(startupLock_);
161  //issue a memory fence here and in threads (constructor was segfaulting without this)
162  thread_quit_signal.push_back(false);
163  workerJob_.push_back(ReaderInfo(nullptr, nullptr));
164  cvReader_.push_back(new std::condition_variable);
165  tid_active_.push_back(0);
166  threadInit_.store(false, std::memory_order_release);
167  workerThreads_.push_back(new std::thread(&FedRawDataInputSource::readWorker, this, i));
168  startupCv_.wait(lk);
169  }
170 
171  runAuxiliary()->setProcessHistoryID(processHistoryID_);
172 }
173 
175  quit_threads_ = true;
176 
177  //delete any remaining open files
178  for (auto it = filesToDelete_.begin(); it != filesToDelete_.end(); it++)
179  it->second.reset();
180 
182  readSupervisorThread_->join();
183  } else {
184  //join aux threads in case the supervisor thread was not started
185  for (unsigned int i = 0; i < workerThreads_.size(); i++) {
186  std::unique_lock<std::mutex> lk(mReader_);
187  thread_quit_signal[i] = true;
188  cvReader_[i]->notify_one();
189  lk.unlock();
190  workerThreads_[i]->join();
191  delete workerThreads_[i];
192  }
193  }
194  for (unsigned int i = 0; i < numConcurrentReads_; i++)
195  delete cvReader_[i];
196  /*
197  for (unsigned int i=0;i<numConcurrentReads_+1;i++) {
198  InputChunk *ch;
199  while (!freeChunks_.try_pop(ch)) {}
200  delete ch;
201  }
202  */
203 }
204 
207  desc.setComment("File-based Filter Farm input source for reading raw data from BU ramdisk");
208  desc.addUntracked<unsigned int>("eventChunkSize", 32)->setComment("Input buffer (chunk) size");
209  desc.addUntracked<unsigned int>("eventChunkBlock", 32)
210  ->setComment("Block size used in a single file read call (must be smaller or equal to buffer size)");
211  desc.addUntracked<unsigned int>("numBuffers", 2)->setComment("Number of buffers used for reading input");
212  desc.addUntracked<unsigned int>("maxBufferedFiles", 2)
213  ->setComment("Maximum number of simultaneously buffered raw files");
214  desc.addUntracked<unsigned int>("alwaysStartFromfirstLS", false)
215  ->setComment("Force source to start from LS 1 if server provides higher lumisection number");
216  desc.addUntracked<bool>("verifyChecksum", true)
217  ->setComment("Verify event CRC-32C checksum of FRDv5 and higher or Adler32 with v3 and v4");
218  desc.addUntracked<bool>("useL1EventID", false)
219  ->setComment("Use L1 event ID from FED header if true or from TCDS FED if false");
220  desc.addUntracked<std::vector<unsigned int>>("testTCDSFEDRange", std::vector<unsigned int>())
221  ->setComment("[min, max] range to search for TCDS FED ID in test setup");
222  desc.addUntracked<bool>("fileListMode", false)
223  ->setComment("Use fileNames parameter to directly specify raw files to open");
224  desc.addUntracked<std::vector<std::string>>("fileNames", std::vector<std::string>())
225  ->setComment("file list used when fileListMode is enabled");
226  desc.setAllowAnything();
227  descriptions.add("source", desc);
228 }
229 
232  //this thread opens new files and dispatches reading to worker readers
233  //threadInit_.store(false,std::memory_order_release);
234  std::unique_lock<std::mutex> lk(startupLock_);
235  readSupervisorThread_ = std::make_unique<std::thread>(&FedRawDataInputSource::readSupervisor, this);
237  startupCv_.wait(lk);
238  }
239  //signal hltd to start event accounting
240  if (!currentLumiSection_)
242  if (fms_)
244  switch (nextEvent()) {
246  //maybe create EoL file in working directory before ending run
247  struct stat buf;
248  if (!useFileBroker_ && currentLumiSection_ > 0) {
249  bool eolFound = (stat(daqDirector_->getEoLSFilePathOnBU(currentLumiSection_).c_str(), &buf) == 0);
250  if (eolFound) {
252  bool found = (stat(fuEoLS.c_str(), &buf) == 0);
253  if (!found) {
255  int eol_fd =
256  open(fuEoLS.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
257  close(eol_fd);
259  }
260  }
261  }
262  //also create EoR file in FU data directory
263  bool eorFound = (stat(daqDirector_->getEoRFilePathOnFU().c_str(), &buf) == 0);
264  if (!eorFound) {
265  int eor_fd = open(daqDirector_->getEoRFilePathOnFU().c_str(),
266  O_RDWR | O_CREAT,
267  S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
268  close(eor_fd);
269  }
271  eventsThisLumi_ = 0;
273  edm::LogInfo("FedRawDataInputSource") << "----------------RUN ENDED----------------";
274  return Next::kStop;
275  }
277  //this is not reachable
278  return Next::kEvent;
279  }
281  //std::cout << "--------------NEW LUMI---------------" << std::endl;
282  return Next::kEvent;
283  }
284  default: {
285  if (!getLSFromFilename_) {
286  //get new lumi from file header
287  if (event_->lumi() > currentLumiSection_) {
289  eventsThisLumi_ = 0;
291  }
292  }
295  else
296  eventRunNumber_ = event_->run();
297  L1EventID_ = event_->event();
298 
299  setEventCached();
300 
301  return Next::kEvent;
302  }
303  }
304 }
305 
306 void FedRawDataInputSource::maybeOpenNewLumiSection(const uint32_t lumiSection) {
307  if (!luminosityBlockAuxiliary() || luminosityBlockAuxiliary()->luminosityBlock() != lumiSection) {
308  if (!useFileBroker_) {
309  if (currentLumiSection_ > 0) {
311  struct stat buf;
312  bool found = (stat(fuEoLS.c_str(), &buf) == 0);
313  if (!found) {
315  int eol_fd =
316  open(fuEoLS.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
317  close(eol_fd);
318  daqDirector_->createBoLSFile(lumiSection, false);
320  }
321  } else
322  daqDirector_->createBoLSFile(lumiSection, true); //needed for initial lumisection
323  }
324 
325  currentLumiSection_ = lumiSection;
326 
328 
329  timeval tv;
330  gettimeofday(&tv, nullptr);
331  const edm::Timestamp lsopentime((unsigned long long)tv.tv_sec * 1000000 + (unsigned long long)tv.tv_usec);
332 
334  runAuxiliary()->run(), lumiSection, lsopentime, edm::Timestamp::invalidTimestamp());
335 
336  setLuminosityBlockAuxiliary(lumiBlockAuxiliary);
337  luminosityBlockAuxiliary()->setProcessHistoryID(processHistoryID_);
338 
339  edm::LogInfo("FedRawDataInputSource") << "New lumi section was opened. LUMI -: " << lumiSection;
340  }
341 }
342 
346  if (edm::shutdown_flag.load(std::memory_order_relaxed))
347  break;
348  }
349  return status;
350 }
351 
353  if (setExceptionState_)
354  threadError();
355  if (!currentFile_.get()) {
357  if (fms_)
359  if (!fileQueue_.try_pop(currentFile_)) {
360  //sleep until wakeup (only in single-buffer mode) or timeout
361  std::unique_lock<std::mutex> lkw(mWakeup_);
362  if (cvWakeup_.wait_for(lkw, std::chrono::milliseconds(100)) == std::cv_status::timeout || !currentFile_.get())
364  }
365  status = currentFile_->status_;
367  if (fms_)
369  currentFile_.reset();
370  return status;
371  } else if (status == evf::EvFDaqDirector::runAbort) {
372  throw cms::Exception("FedRawDataInputSource::getNextEvent")
373  << "Run has been aborted by the input source reader thread";
374  } else if (status == evf::EvFDaqDirector::newLumi) {
375  if (fms_)
377  if (getLSFromFilename_) {
378  if (currentFile_->lumi_ > currentLumiSection_) {
380  eventsThisLumi_ = 0;
382  }
383  } else { //let this be picked up from next event
385  }
386  currentFile_.reset();
387  return status;
388  } else if (status == evf::EvFDaqDirector::newFile) {
390  } else
391  assert(false);
392  }
393  if (fms_)
395 
396  //file is empty
397  if (!currentFile_->fileSize_) {
399  //try to open new lumi
400  assert(currentFile_->nChunks_ == 0);
401  if (getLSFromFilename_)
402  if (currentFile_->lumi_ > currentLumiSection_) {
404  eventsThisLumi_ = 0;
406  }
407  //immediately delete empty file
408  currentFile_.reset();
410  }
411 
412  //file is finished
413  if (currentFile_->bufferPosition_ == currentFile_->fileSize_) {
415  //release last chunk (it is never released elsewhere)
416  freeChunks_.push(currentFile_->chunks_[currentFile_->currentChunk_]);
417  if (currentFile_->nEvents_ >= 0 && currentFile_->nEvents_ != int(currentFile_->nProcessed_)) {
418  throw cms::Exception("FedRawDataInputSource::getNextEvent")
419  << "Fully processed " << currentFile_->nProcessed_ << " from the file " << currentFile_->fileName_
420  << " but according to BU JSON there should be " << currentFile_->nEvents_ << " events";
421  }
422  //try to wake up supervisor thread which might be sleeping waiting for the free chunk
423  if (singleBufferMode_) {
424  std::unique_lock<std::mutex> lkw(mWakeup_);
425  cvWakeup_.notify_one();
426  }
427  bufferInputRead_ = 0;
429  //put the file in pending delete list;
430  std::unique_lock<std::mutex> lkw(fileDeleteLock_);
431  filesToDelete_.push_back(std::pair<int, std::unique_ptr<InputFile>>(currentFileIndex_, std::move(currentFile_)));
432  } else {
433  //in single-thread and stream jobs, events are already processed
434  currentFile_.reset();
435  }
437  }
438 
439  //handle RAW file header
440  if (currentFile_->bufferPosition_ == 0 && currentFile_->rawHeaderSize_ > 0) {
441  if (currentFile_->fileSize_ <= currentFile_->rawHeaderSize_) {
442  if (currentFile_->fileSize_ < currentFile_->rawHeaderSize_)
443  throw cms::Exception("FedRawDataInputSource::getNextEvent")
444  << "Premature end of input file while reading file header";
445 
446  edm::LogWarning("FedRawDataInputSource")
447  << "File with only raw header and no events received in LS " << currentFile_->lumi_;
448  if (getLSFromFilename_)
449  if (currentFile_->lumi_ > currentLumiSection_) {
451  eventsThisLumi_ = 0;
453  }
454  }
455 
456  //advance buffer position to skip file header (chunk will be acquired later)
457  currentFile_->chunkPosition_ += currentFile_->rawHeaderSize_;
458  currentFile_->bufferPosition_ += currentFile_->rawHeaderSize_;
459  }
460 
461  //file is too short
462  if (currentFile_->fileSize_ - currentFile_->bufferPosition_ < FRDHeaderVersionSize[detectedFRDversion_]) {
463  throw cms::Exception("FedRawDataInputSource::getNextEvent")
464  << "Premature end of input file while reading event header";
465  }
466  if (singleBufferMode_) {
467  //should already be there
468  if (fms_)
470  while (!currentFile_->waitForChunk(currentFile_->currentChunk_)) {
471  usleep(10000);
472  if (currentFile_->parent_->exceptionState() || setExceptionState_)
473  currentFile_->parent_->threadError();
474  }
475  if (fms_)
477 
478  unsigned char* dataPosition = currentFile_->chunks_[0]->buf_ + currentFile_->chunkPosition_;
479 
480  //conditions when read amount is not sufficient for the header to fit
484 
485  if (detectedFRDversion_ == 0) {
486  detectedFRDversion_ = *((uint16_t*)dataPosition);
488  throw cms::Exception("FedRawDataInputSource::getNextEvent")
489  << "Unknown FRD version -: " << detectedFRDversion_;
491  }
492 
493  //recalculate chunk position
494  dataPosition = currentFile_->chunks_[0]->buf_ + currentFile_->chunkPosition_;
496  throw cms::Exception("FedRawDataInputSource::getNextEvent")
497  << "Premature end of input file while reading event header";
498  }
499  }
500 
501  event_ = std::make_unique<FRDEventMsgView>(dataPosition);
502  if (event_->size() > eventChunkSize_) {
503  throw cms::Exception("FedRawDataInputSource::getNextEvent")
504  << " event id:" << event_->event() << " lumi:" << event_->lumi() << " run:" << event_->run()
505  << " of size:" << event_->size() << " bytes does not fit into a chunk of size:" << eventChunkSize_
506  << " bytes";
507  }
508 
509  const uint32_t msgSize = event_->size() - FRDHeaderVersionSize[detectedFRDversion_];
510 
511  if (currentFile_->fileSize_ - currentFile_->bufferPosition_ < msgSize) {
512  throw cms::Exception("FedRawDataInputSource::getNextEvent")
513  << "Premature end of input file while reading event data";
514  }
515  if (eventChunkSize_ - currentFile_->chunkPosition_ < msgSize) {
517  //recalculate chunk position
518  dataPosition = currentFile_->chunks_[0]->buf_ + currentFile_->chunkPosition_;
519  event_ = std::make_unique<FRDEventMsgView>(dataPosition);
520  }
521  currentFile_->bufferPosition_ += event_->size();
522  currentFile_->chunkPosition_ += event_->size();
523  //last chunk is released when this function is invoked next time
524 
525  }
526  //multibuffer mode:
527  else {
528  //wait for the current chunk to become added to the vector
529  if (fms_)
531  while (!currentFile_->waitForChunk(currentFile_->currentChunk_)) {
532  usleep(10000);
533  if (setExceptionState_)
534  threadError();
535  }
536  if (fms_)
538 
539  //check if header is at the boundary of two chunks
540  chunkIsFree_ = false;
541  unsigned char* dataPosition;
542 
543  //read header, copy it to a single chunk if necessary
544  bool chunkEnd = currentFile_->advance(dataPosition, FRDHeaderVersionSize[detectedFRDversion_]);
545 
546  event_ = std::make_unique<FRDEventMsgView>(dataPosition);
547  if (event_->size() > eventChunkSize_) {
548  throw cms::Exception("FedRawDataInputSource::getNextEvent")
549  << " event id:" << event_->event() << " lumi:" << event_->lumi() << " run:" << event_->run()
550  << " of size:" << event_->size() << " bytes does not fit into a chunk of size:" << eventChunkSize_
551  << " bytes";
552  }
553 
554  const uint32_t msgSize = event_->size() - FRDHeaderVersionSize[detectedFRDversion_];
555 
556  if (currentFile_->fileSize_ - currentFile_->bufferPosition_ < msgSize) {
557  throw cms::Exception("FedRawDataInputSource::getNextEvent")
558  << "Premature end of input file while reading event data";
559  }
560 
561  if (chunkEnd) {
562  //header was at the chunk boundary, we will have to move payload as well
563  currentFile_->moveToPreviousChunk(msgSize, FRDHeaderVersionSize[detectedFRDversion_]);
564  chunkIsFree_ = true;
565  } else {
566  //header was contiguous, but check if payload fits the chunk
567  if (eventChunkSize_ - currentFile_->chunkPosition_ < msgSize) {
568  //rewind to header start position
570  //copy event to a chunk start and move pointers
571  chunkEnd = currentFile_->advance(dataPosition, FRDHeaderVersionSize[detectedFRDversion_] + msgSize);
572  assert(chunkEnd);
573  chunkIsFree_ = true;
574  //header is moved
575  event_ = std::make_unique<FRDEventMsgView>(dataPosition);
576  } else {
577  //everything is in a single chunk, only move pointers forward
578  chunkEnd = currentFile_->advance(dataPosition, msgSize);
579  assert(!chunkEnd);
580  chunkIsFree_ = false;
581  }
582  }
583  } //end multibuffer mode
584  if (fms_)
586 
587  if (verifyChecksum_ && event_->version() >= 5) {
588  uint32_t crc = 0;
589  crc = crc32c(crc, (const unsigned char*)event_->payload(), event_->eventSize());
590  if (crc != event_->crc32c()) {
591  if (fms_)
593  throw cms::Exception("FedRawDataInputSource::getNextEvent")
594  << "Found a wrong crc32c checksum: expected 0x" << std::hex << event_->crc32c() << " but calculated 0x"
595  << crc;
596  }
597  } else if (verifyChecksum_ && event_->version() >= 3) {
598  uint32_t adler = adler32(0L, Z_NULL, 0);
599  adler = adler32(adler, (Bytef*)event_->payload(), event_->eventSize());
600 
601  if (adler != event_->adler32()) {
602  if (fms_)
604  throw cms::Exception("FedRawDataInputSource::getNextEvent")
605  << "Found a wrong Adler32 checksum: expected 0x" << std::hex << event_->adler32() << " but calculated 0x"
606  << adler;
607  }
608  }
609  if (fms_)
611 
612  currentFile_->nProcessed_++;
613 
615 }
616 
618  if (fms_)
620  std::unique_ptr<FEDRawDataCollection> rawData(new FEDRawDataCollection);
622 
623  if (useL1EventID_) {
626  aux.setProcessHistoryID(processHistoryID_);
627  makeEvent(eventPrincipal, aux);
628  } else if (tcds_pointer_ == nullptr) {
629  if (!GTPEventID_) {
630  throw cms::Exception("FedRawDataInputSource::read")
631  << "No TCDS or GTP FED in event with FEDHeader EID -: " << L1EventID_;
632  }
635  aux.setProcessHistoryID(processHistoryID_);
636  makeEvent(eventPrincipal, aux);
637  } else {
638  const FEDHeader fedHeader(tcds_pointer_);
639  tcds::Raw_v1 const* tcds = reinterpret_cast<tcds::Raw_v1 const*>(tcds_pointer_ + FEDHeader::length);
644  event_->isRealData(),
645  static_cast<edm::EventAuxiliary::ExperimentType>(fedHeader.triggerType()),
646  processGUID(),
648  aux.setProcessHistoryID(processHistoryID_);
649  makeEvent(eventPrincipal, aux);
650  }
651 
652  std::unique_ptr<edm::WrapperBase> edp(new edm::Wrapper<FEDRawDataCollection>(std::move(rawData)));
653 
655 
656  eventsThisLumi_++;
657  if (fms_)
659 
660  //resize vector if needed
661  while (streamFileTracker_.size() <= eventPrincipal.streamID())
662  streamFileTracker_.push_back(-1);
663 
664  streamFileTracker_[eventPrincipal.streamID()] = currentFileIndex_;
665 
666  //this old file check runs no more often than every 10 events
667  if (!((currentFile_->nProcessed_ - 1) % (checkEvery_))) {
668  //delete files that are not in processing
669  std::unique_lock<std::mutex> lkw(fileDeleteLock_);
670  auto it = filesToDelete_.begin();
671  while (it != filesToDelete_.end()) {
672  bool fileIsBeingProcessed = false;
673  for (unsigned int i = 0; i < nStreams_; i++) {
674  if (it->first == streamFileTracker_.at(i)) {
675  fileIsBeingProcessed = true;
676  break;
677  }
678  }
679  if (!fileIsBeingProcessed) {
680  std::string fileToDelete = it->second->fileName_;
681  it = filesToDelete_.erase(it);
682  } else
683  it++;
684  }
685  }
686  if (chunkIsFree_)
687  freeChunks_.push(currentFile_->chunks_[currentFile_->currentChunk_ - 1]);
688  chunkIsFree_ = false;
689  if (fms_)
691  return;
692 }
693 
696  timeval stv;
697  gettimeofday(&stv, nullptr);
698  time = stv.tv_sec;
699  time = (time << 32) + stv.tv_usec;
700  edm::Timestamp tstamp(time);
701 
702  uint32_t eventSize = event_->eventSize();
703  unsigned char* event = (unsigned char*)event_->payload();
704  GTPEventID_ = 0;
705  tcds_pointer_ = nullptr;
706  uint16_t selectedTCDSFed = 0;
707  while (eventSize > 0) {
708  assert(eventSize >= FEDTrailer::length);
709  eventSize -= FEDTrailer::length;
710  const FEDTrailer fedTrailer(event + eventSize);
711  const uint32_t fedSize = fedTrailer.fragmentLength() << 3; //trailer length counts in 8 bytes
712  assert(eventSize >= fedSize - FEDHeader::length);
713  eventSize -= (fedSize - FEDHeader::length);
714  const FEDHeader fedHeader(event + eventSize);
715  const uint16_t fedId = fedHeader.sourceID();
717  throw cms::Exception("FedRawDataInputSource::fillFEDRawDataCollection") << "Out of range FED ID : " << fedId;
718  } else if (fedId >= MINTCDSuTCAFEDID_ && fedId <= MAXTCDSuTCAFEDID_) {
719  if (!selectedTCDSFed) {
720  selectedTCDSFed = fedId;
721  tcds_pointer_ = event + eventSize;
722  } else
723  throw cms::Exception("FedRawDataInputSource::fillFEDRawDataCollection")
724  << "Second TCDS FED ID " << fedId << " found. First ID: " << selectedTCDSFed;
725  }
727  if (evf::evtn::evm_board_sense(event + eventSize, fedSize))
728  GTPEventID_ = evf::evtn::get(event + eventSize, true);
729  else
730  GTPEventID_ = evf::evtn::get(event + eventSize, false);
731  //evf::evtn::evm_board_setformat(fedSize);
732  const uint64_t gpsl = evf::evtn::getgpslow(event + eventSize);
733  const uint64_t gpsh = evf::evtn::getgpshigh(event + eventSize);
734  tstamp = edm::Timestamp(static_cast<edm::TimeValue_t>((gpsh << 32) + gpsl));
735  }
736  //take event ID from GTPE FED
738  if (evf::evtn::gtpe_board_sense(event + eventSize)) {
739  GTPEventID_ = evf::evtn::gtpe_get(event + eventSize);
740  }
741  }
742  FEDRawData& fedData = rawData.FEDData(fedId);
743  fedData.resize(fedSize);
744  memcpy(fedData.data(), event + eventSize, fedSize);
745  }
746  assert(eventSize == 0);
747 
748  return tstamp;
749 }
750 
752 
754  bool stop = false;
755  unsigned int currentLumiSection = 0;
756  //threadInit_.exchange(true,std::memory_order_acquire);
757 
758  {
759  std::unique_lock<std::mutex> lk(startupLock_);
760  startupCv_.notify_one();
761  }
762 
763  uint32_t ls = 0;
764  uint32_t monLS = 1;
765  uint32_t lockCount = 0;
766  uint64_t sumLockWaitTimeUs = 0.;
767 
768  while (!stop) {
769  //wait for at least one free thread and chunk
770  int counter = 0;
771  while ((workerPool_.empty() && !singleBufferMode_) || freeChunks_.empty() ||
773  //report state to monitoring
774  if (fms_) {
775  bool copy_active = false;
776  for (auto j : tid_active_)
777  if (j)
778  copy_active = true;
781  else if (freeChunks_.empty()) {
782  if (copy_active)
784  else
786  } else {
787  if (copy_active)
789  else
791  }
792  }
793  std::unique_lock<std::mutex> lkw(mWakeup_);
794  //sleep until woken up by condition or a timeout
795  if (cvWakeup_.wait_for(lkw, std::chrono::milliseconds(100)) == std::cv_status::timeout) {
796  counter++;
797  //if (!(counter%50)) edm::LogInfo("FedRawDataInputSource") << "No free chunks or threads...";
798  LogDebug("FedRawDataInputSource") << "No free chunks or threads...";
799  } else {
800  assert(!(workerPool_.empty() && !singleBufferMode_) || freeChunks_.empty());
801  }
802  if (quit_threads_.load(std::memory_order_relaxed) || edm::shutdown_flag.load(std::memory_order_relaxed)) {
803  stop = true;
804  break;
805  }
806  }
807  //if this is reached, there are enough buffers and threads to proceed or processing is instructed to stop
808 
809  if (stop)
810  break;
811 
812  //look for a new file
813  std::string nextFile;
814  uint32_t fileSizeIndex;
815  int64_t fileSizeFromMetadata;
816 
817  if (fms_) {
821  }
822 
824  uint16_t rawHeaderSize = 0;
825  uint32_t lsFromRaw = 0;
826  int32_t serverEventsInNewFile = -1;
827  int rawFd = -1;
828 
829  int backoff_exp = 0;
830 
831  //entering loop which tries to grab new file from ramdisk
833  if (quit_threads_.load(std::memory_order_relaxed) || edm::shutdown_flag.load(std::memory_order_relaxed)) {
834  stop = true;
835  break;
836  }
837 
838  assert(rawFd == -1);
839  uint64_t thisLockWaitTimeUs = 0.;
840  if (fileListMode_) {
841  //return LS if LS not set, otherwise return file
842  status = getFile(ls, nextFile, fileSizeIndex, thisLockWaitTimeUs);
845  rawFd,
846  rawHeaderSize,
847  lsFromRaw,
848  serverEventsInNewFile,
849  fileSizeFromMetadata,
850  false,
851  false,
852  false) != 0) {
853  //error
854  setExceptionState_ = true;
855  stop = true;
856  break;
857  }
858  if (!getLSFromFilename_)
859  ls = lsFromRaw;
860  }
861  } else if (!useFileBroker_)
863  ls, nextFile, fileSizeIndex, rawHeaderSize, thisLockWaitTimeUs, setExceptionState_);
864  else {
865  status = daqDirector_->getNextFromFileBroker(currentLumiSection,
866  ls,
867  nextFile,
868  rawFd,
869  rawHeaderSize,
870  serverEventsInNewFile,
871  fileSizeFromMetadata,
872  thisLockWaitTimeUs);
873  }
874 
875  if (fms_)
877 
878  //cycle through all remaining LS even if no files get assigned
879  if (currentLumiSection != ls && status == evf::EvFDaqDirector::runEnded)
881 
882  //monitoring of lock wait time
883  if (thisLockWaitTimeUs > 0.)
884  sumLockWaitTimeUs += thisLockWaitTimeUs;
885  lockCount++;
886  if (ls > monLS) {
887  monLS = ls;
888  if (lockCount)
889  if (fms_)
890  fms_->reportLockWait(monLS, sumLockWaitTimeUs, lockCount);
891  lockCount = 0;
892  sumLockWaitTimeUs = 0;
893  }
894 
895  //check again for any remaining index/EoLS files after EoR file is seen
897  if (fms_)
899  usleep(100000);
900  //now all files should have appeared in ramdisk, check again if any raw files were left behind
902  ls, nextFile, fileSizeIndex, rawHeaderSize, thisLockWaitTimeUs, setExceptionState_);
903  if (currentLumiSection != ls && status == evf::EvFDaqDirector::runEnded)
905  }
906 
908  std::unique_ptr<InputFile> inf(new InputFile(evf::EvFDaqDirector::runEnded));
909  fileQueue_.push(std::move(inf));
910  stop = true;
911  break;
912  }
913 
914  //error from filelocking function
916  std::unique_ptr<InputFile> inf(new InputFile(evf::EvFDaqDirector::runAbort, 0));
917  fileQueue_.push(std::move(inf));
918  stop = true;
919  break;
920  }
921  //queue new lumisection
922  if (getLSFromFilename_) {
923  if (ls > currentLumiSection) {
924  if (!useFileBroker_) {
925  //file locking
926  //fms_->setInStateSup(evf::FastMonitoringThread::inSupNewLumi);
927  currentLumiSection = ls;
928  std::unique_ptr<InputFile> inf(new InputFile(evf::EvFDaqDirector::newLumi, currentLumiSection));
929  fileQueue_.push(std::move(inf));
930  } else {
931  //new file service
932  if (currentLumiSection == 0 && !alwaysStartFromFirstLS_) {
933  if (ls < 100) {
934  //look at last LS file on disk to start from that lumisection (only within first 100 LS)
935  unsigned int lsToStart = daqDirector_->getLumisectionToStart();
936 
937  for (unsigned int nextLS = lsToStart; nextLS <= ls; nextLS++) {
938  std::unique_ptr<InputFile> inf(new InputFile(evf::EvFDaqDirector::newLumi, nextLS));
939  fileQueue_.push(std::move(inf));
940  }
941  } else {
942  //start from current LS
943  std::unique_ptr<InputFile> inf(new InputFile(evf::EvFDaqDirector::newLumi, ls));
944  fileQueue_.push(std::move(inf));
945  }
946  } else {
947  //queue all lumisections after last one seen to avoid gaps
948  for (unsigned int nextLS = currentLumiSection + 1; nextLS <= ls; nextLS++) {
949  std::unique_ptr<InputFile> inf(new InputFile(evf::EvFDaqDirector::newLumi, nextLS));
950  fileQueue_.push(std::move(inf));
951  }
952  }
953  currentLumiSection = ls;
954  }
955  }
956  //else
957  if (currentLumiSection > 0 && ls < currentLumiSection) {
958  edm::LogError("FedRawDataInputSource")
959  << "Got old LS (" << ls << ") file from EvFDAQDirector! Expected LS:" << currentLumiSection
960  << ". Aborting execution." << std::endl;
961  if (rawFd != -1)
962  close(rawFd);
963  rawFd = -1;
964  std::unique_ptr<InputFile> inf(new InputFile(evf::EvFDaqDirector::runAbort, 0));
965  fileQueue_.push(std::move(inf));
966  stop = true;
967  break;
968  }
969  }
970 
971  int dbgcount = 0;
973  if (fms_)
975  dbgcount++;
976  if (!(dbgcount % 20))
977  LogDebug("FedRawDataInputSource") << "No file for me... sleep and try again...";
978  if (!useFileBroker_)
979  usleep(100000);
980  else {
981  backoff_exp = std::min(4, backoff_exp); // max 1.6 seconds
982  //backoff_exp=0; // disabled!
983  int sleeptime = (int)(100000. * pow(2, backoff_exp));
984  usleep(sleeptime);
985  backoff_exp++;
986  }
987  } else
988  backoff_exp = 0;
989  }
990  //end of file grab loop, parse result
992  if (fms_)
994  LogDebug("FedRawDataInputSource") << "The director says to grab -: " << nextFile;
995 
996  std::string rawFile;
997  //file service will report raw extension
998  if (useFileBroker_ || rawHeaderSize)
999  rawFile = nextFile;
1000  else {
1001  std::filesystem::path rawFilePath(nextFile);
1002  rawFile = rawFilePath.replace_extension(".raw").string();
1003  }
1004 
1005  struct stat st;
1006  int stat_res = stat(rawFile.c_str(), &st);
1007  if (stat_res == -1) {
1008  edm::LogError("FedRawDataInputSource") << "Can not stat file (" << errno << "):-" << rawFile << std::endl;
1009  setExceptionState_ = true;
1010  break;
1011  }
1012  uint64_t fileSize = st.st_size;
1013 
1014  if (fms_) {
1018  }
1019  int eventsInNewFile;
1020  if (fileListMode_) {
1021  if (fileSize == 0)
1022  eventsInNewFile = 0;
1023  else
1024  eventsInNewFile = -1;
1025  } else {
1027  if (!useFileBroker_) {
1028  if (rawHeaderSize) {
1029  int rawFdEmpty = -1;
1030  uint16_t rawHeaderCheck;
1031  bool fileFound;
1032  eventsInNewFile = daqDirector_->grabNextJsonFromRaw(
1033  nextFile, rawFdEmpty, rawHeaderCheck, fileSizeFromMetadata, fileFound, 0, true);
1034  assert(fileFound && rawHeaderCheck == rawHeaderSize);
1036  } else
1037  eventsInNewFile = daqDirector_->grabNextJsonFileAndUnlock(nextFile);
1038  } else
1039  eventsInNewFile = serverEventsInNewFile;
1040  assert(eventsInNewFile >= 0);
1041  assert((eventsInNewFile > 0) ==
1042  (fileSize > rawHeaderSize)); //file without events must be empty or contain only header
1043  }
1044 
1045  if (!singleBufferMode_) {
1046  //calculate number of needed chunks
1047  unsigned int neededChunks = fileSize / eventChunkSize_;
1048  if (fileSize % eventChunkSize_)
1049  neededChunks++;
1050 
1051  std::unique_ptr<InputFile> newInputFile(new InputFile(evf::EvFDaqDirector::FileStatus::newFile,
1052  ls,
1053  rawFile,
1054  !fileListMode_,
1055  rawFd,
1056  fileSize,
1057  rawHeaderSize,
1058  neededChunks,
1059  eventsInNewFile,
1060  this));
1062  auto newInputFilePtr = newInputFile.get();
1063  fileQueue_.push(std::move(newInputFile));
1064 
1065  for (unsigned int i = 0; i < neededChunks; i++) {
1066  if (fms_) {
1067  bool copy_active = false;
1068  for (auto j : tid_active_)
1069  if (j)
1070  copy_active = true;
1071  if (copy_active)
1073  else
1075  }
1076  //get thread
1077  unsigned int newTid = 0xffffffff;
1078  while (!workerPool_.try_pop(newTid)) {
1079  usleep(100000);
1080  if (quit_threads_.load(std::memory_order_relaxed)) {
1081  stop = true;
1082  break;
1083  }
1084  }
1085 
1086  if (fms_) {
1087  bool copy_active = false;
1088  for (auto j : tid_active_)
1089  if (j)
1090  copy_active = true;
1091  if (copy_active)
1093  else
1095  }
1096  InputChunk* newChunk = nullptr;
1097  while (!freeChunks_.try_pop(newChunk)) {
1098  usleep(100000);
1099  if (quit_threads_.load(std::memory_order_relaxed)) {
1100  stop = true;
1101  break;
1102  }
1103  }
1104 
1105  if (newChunk == nullptr) {
1106  //return unused tid if we received shutdown (nullptr chunk)
1107  if (newTid != 0xffffffff)
1108  workerPool_.push(newTid);
1109  stop = true;
1110  break;
1111  }
1112  if (stop)
1113  break;
1114  if (fms_)
1116 
1117  std::unique_lock<std::mutex> lk(mReader_);
1118 
1119  unsigned int toRead = eventChunkSize_;
1120  if (i == neededChunks - 1 && fileSize % eventChunkSize_)
1121  toRead = fileSize % eventChunkSize_;
1122  newChunk->reset(i * eventChunkSize_, toRead, i);
1123 
1124  workerJob_[newTid].first = newInputFilePtr;
1125  workerJob_[newTid].second = newChunk;
1126 
1127  //wake up the worker thread
1128  cvReader_[newTid]->notify_one();
1129  }
1130  } else {
1131  if (!eventsInNewFile) {
1132  if (rawFd) {
1133  close(rawFd);
1134  rawFd = -1;
1135  }
1136  //still queue file for lumi update
1137  std::unique_lock<std::mutex> lkw(mWakeup_);
1138  //TODO: also file with only file header fits in this edge case. Check if read correctly in single buffer mode
1139  std::unique_ptr<InputFile> newInputFile(new InputFile(evf::EvFDaqDirector::FileStatus::newFile,
1140  ls,
1141  rawFile,
1142  !fileListMode_,
1143  rawFd,
1144  fileSize,
1145  rawHeaderSize,
1146  (rawHeaderSize > 0),
1147  0,
1148  this));
1150  fileQueue_.push(std::move(newInputFile));
1151  cvWakeup_.notify_one();
1152  break;
1153  }
1154  //in single-buffer mode put single chunk in the file and let the main thread read the file
1155  InputChunk* newChunk;
1156  //should be available immediately
1157  while (!freeChunks_.try_pop(newChunk)) {
1158  usleep(100000);
1159  if (quit_threads_.load(std::memory_order_relaxed))
1160  break;
1161  }
1162 
1163  std::unique_lock<std::mutex> lkw(mWakeup_);
1164 
1165  unsigned int toRead = eventChunkSize_;
1166  if (fileSize % eventChunkSize_)
1167  toRead = fileSize % eventChunkSize_;
1168  newChunk->reset(0, toRead, 0);
1169  newChunk->readComplete_ = true;
1170 
1171  //push file and wakeup main thread
1172  std::unique_ptr<InputFile> newInputFile(new InputFile(evf::EvFDaqDirector::FileStatus::newFile,
1173  ls,
1174  rawFile,
1175  !fileListMode_,
1176  rawFd,
1177  fileSize,
1178  rawHeaderSize,
1179  1,
1180  eventsInNewFile,
1181  this));
1182  newInputFile->chunks_[0] = newChunk;
1184  fileQueue_.push(std::move(newInputFile));
1185  cvWakeup_.notify_one();
1186  }
1187  }
1188  }
1189  if (fms_)
1191  //make sure threads finish reading
1192  unsigned numFinishedThreads = 0;
1193  while (numFinishedThreads < workerThreads_.size()) {
1194  unsigned int tid;
1195  while (!workerPool_.try_pop(tid)) {
1196  usleep(10000);
1197  }
1198  std::unique_lock<std::mutex> lk(mReader_);
1199  thread_quit_signal[tid] = true;
1200  cvReader_[tid]->notify_one();
1201  numFinishedThreads++;
1202  }
1203  for (unsigned int i = 0; i < workerThreads_.size(); i++) {
1204  workerThreads_[i]->join();
1205  delete workerThreads_[i];
1206  }
1207 }
1208 
1209 void FedRawDataInputSource::readWorker(unsigned int tid) {
1210  bool init = true;
1211  threadInit_.exchange(true, std::memory_order_acquire);
1212 
1213  while (true) {
1214  tid_active_[tid] = false;
1215  std::unique_lock<std::mutex> lk(mReader_);
1216  workerJob_[tid].first = nullptr;
1217  workerJob_[tid].first = nullptr;
1218 
1219  assert(!thread_quit_signal[tid]); //should never get it here
1220  workerPool_.push(tid);
1221 
1222  if (init) {
1223  std::unique_lock<std::mutex> lk(startupLock_);
1224  init = false;
1225  startupCv_.notify_one();
1226  }
1227  cvReader_[tid]->wait(lk);
1228 
1229  if (thread_quit_signal[tid])
1230  return;
1231  tid_active_[tid] = true;
1232 
1233  InputFile* file;
1234  InputChunk* chunk;
1235 
1236  assert(workerJob_[tid].first != nullptr && workerJob_[tid].second != nullptr);
1237 
1238  file = workerJob_[tid].first;
1239  chunk = workerJob_[tid].second;
1240 
1241  //skip reading initial header size in first chunk if inheriting file descriptor (already set at appropriate position)
1242  unsigned int bufferLeft = (chunk->offset_ == 0 && file->rawFd_ != -1) ? file->rawHeaderSize_ : 0;
1243 
1244  //if only one worker thread exists, use single fd for all operations
1245  //if more worker threads exist, use rawFd_ for only the first read operation and then close file
1246  int fileDescriptor;
1247  bool fileOpenedHere = false;
1248 
1249  if (numConcurrentReads_ == 1) {
1250  fileDescriptor = file->rawFd_;
1251  if (fileDescriptor == -1) {
1252  fileDescriptor = open(file->fileName_.c_str(), O_RDONLY);
1253  fileOpenedHere = true;
1254  file->rawFd_ = fileDescriptor;
1255  }
1256  } else {
1257  if (chunk->offset_ == 0) {
1258  fileDescriptor = file->rawFd_;
1259  file->rawFd_ = -1;
1260  if (fileDescriptor == -1) {
1261  fileDescriptor = open(file->fileName_.c_str(), O_RDONLY);
1262  fileOpenedHere = true;
1263  }
1264  } else {
1265  fileDescriptor = open(file->fileName_.c_str(), O_RDONLY);
1266  fileOpenedHere = true;
1267  }
1268  }
1269 
1270  if (fileDescriptor < 0) {
1271  edm::LogError("FedRawDataInputSource") << "readWorker failed to open file -: " << file->fileName_
1272  << " fd:" << fileDescriptor << " error: " << strerror(errno);
1273  setExceptionState_ = true;
1274  continue;
1275  }
1276  if (fileOpenedHere) { //fast forward to this chunk position
1277  off_t pos = 0;
1278  pos = lseek(fileDescriptor, chunk->offset_, SEEK_SET);
1279  if (pos == -1) {
1280  edm::LogError("FedRawDataInputSource")
1281  << "readWorker failed to seek file -: " << file->fileName_ << " fd:" << fileDescriptor << " to offset "
1282  << chunk->offset_ << " error: " << strerror(errno);
1283  setExceptionState_ = true;
1284  continue;
1285  }
1286  }
1287 
1288  LogDebug("FedRawDataInputSource") << "Reader thread opened file -: TID: " << tid << " file: " << file->fileName_
1289  << " at offset " << lseek(fileDescriptor, 0, SEEK_CUR);
1290 
1291  unsigned int skipped = bufferLeft;
1293  for (unsigned int i = 0; i < readBlocks_; i++) {
1294  ssize_t last;
1295 
1296  //protect against reading into next block
1297  last = ::read(
1298  fileDescriptor, (void*)(chunk->buf_ + bufferLeft), std::min(chunk->usedSize_ - bufferLeft, eventChunkBlock_));
1299 
1300  if (last < 0) {
1301  edm::LogError("FedRawDataInputSource") << "readWorker failed to read file -: " << file->fileName_
1302  << " fd:" << fileDescriptor << " error: " << strerror(errno);
1303  setExceptionState_ = true;
1304  break;
1305  }
1306  if (last > 0)
1307  bufferLeft += last;
1308  if (last < eventChunkBlock_) { //last read
1309  //check if this is last block, then total read size must match file size
1310  if (!(chunk->usedSize_ - skipped == i * eventChunkBlock_ + last)) {
1311  edm::LogError("FedRawDataInputSource")
1312  << "readWorker failed to read file -: " << file->fileName_ << " fd:" << fileDescriptor << " last:" << last
1313  << " expectedChunkSize:" << chunk->usedSize_
1314  << " readChunkSize:" << (skipped + i * eventChunkBlock_ + last) << " skipped:" << skipped
1315  << " block:" << (i + 1) << "/" << readBlocks_ << " error: " << strerror(errno);
1316  setExceptionState_ = true;
1317  }
1318  break;
1319  }
1320  }
1321  if (setExceptionState_)
1322  continue;
1323 
1325  auto diff = end - start;
1326  std::chrono::milliseconds msec = std::chrono::duration_cast<std::chrono::milliseconds>(diff);
1327  LogDebug("FedRawDataInputSource") << " finished reading block -: " << (bufferLeft >> 20) << " MB"
1328  << " in " << msec.count() << " ms (" << (bufferLeft >> 20) / double(msec.count())
1329  << " GB/s)";
1330 
1331  if (chunk->offset_ + bufferLeft == file->fileSize_) { //file reading finished using same fd
1332  close(fileDescriptor);
1333  fileDescriptor = -1;
1334  if (numConcurrentReads_ == 1)
1335  file->rawFd_ = -1;
1336  }
1337  if (numConcurrentReads_ > 1 && fileDescriptor != -1)
1338  close(fileDescriptor);
1339 
1340  //detect FRD event version. Skip file Header if it exists
1341  if (detectedFRDversion_ == 0 && chunk->offset_ == 0) {
1342  detectedFRDversion_ = *((uint16_t*)(chunk->buf_ + file->rawHeaderSize_));
1343  }
1345  chunk->readComplete_ =
1346  true; //this is atomic to secure the sequential buffer fill before becoming available for processing)
1347  file->chunks_[chunk->fileIndex_] = chunk; //put the completed chunk in the file chunk vector at predetermined index
1348  }
1349 }
1350 
1352  quit_threads_ = true;
1353  throw cms::Exception("FedRawDataInputSource:threadError") << " file reader thread error ";
1354 }
1355 
1356 inline bool InputFile::advance(unsigned char*& dataPosition, const size_t size) {
1357  //wait for chunk
1358  while (!waitForChunk(currentChunk_)) {
1359  usleep(100000);
1360  if (parent_->exceptionState())
1361  parent_->threadError();
1362  }
1363 
1364  dataPosition = chunks_[currentChunk_]->buf_ + chunkPosition_;
1365  size_t currentLeft = chunks_[currentChunk_]->size_ - chunkPosition_;
1366 
1367  if (currentLeft < size) {
1368  //we need next chunk
1369  while (!waitForChunk(currentChunk_ + 1)) {
1370  usleep(100000);
1371  if (parent_->exceptionState())
1372  parent_->threadError();
1373  }
1374  //copy everything to beginning of the first chunk
1375  dataPosition -= chunkPosition_;
1376  assert(dataPosition == chunks_[currentChunk_]->buf_);
1377  memmove(chunks_[currentChunk_]->buf_, chunks_[currentChunk_]->buf_ + chunkPosition_, currentLeft);
1378  memcpy(chunks_[currentChunk_]->buf_ + currentLeft, chunks_[currentChunk_ + 1]->buf_, size - currentLeft);
1379  //set pointers at the end of the old data position
1380  bufferPosition_ += size;
1381  chunkPosition_ = size - currentLeft;
1382  currentChunk_++;
1383  return true;
1384  } else {
1385  chunkPosition_ += size;
1386  bufferPosition_ += size;
1387  return false;
1388  }
1389 }
1390 
1391 inline void InputFile::moveToPreviousChunk(const size_t size, const size_t offset) {
1392  //this will fail in case of events that are too large
1394  assert(size - offset < chunks_[currentChunk_]->size_);
1395  memcpy(chunks_[currentChunk_ - 1]->buf_ + offset, chunks_[currentChunk_]->buf_ + chunkPosition_, size);
1396  chunkPosition_ += size;
1397  bufferPosition_ += size;
1398 }
1399 
1400 inline void InputFile::rewindChunk(const size_t size) {
1401  chunkPosition_ -= size;
1402  bufferPosition_ -= size;
1403 }
1404 
1406  if (rawFd_ != -1)
1407  close(rawFd_);
1408 
1409  if (deleteFile_ && !fileName_.empty()) {
1411  try {
1412  //sometimes this fails but file gets deleted
1413  LogDebug("FedRawDataInputSource:InputFile") << "Deleting input file -:" << fileName_;
1415  return;
1416  } catch (const std::filesystem::filesystem_error& ex) {
1417  edm::LogError("FedRawDataInputSource:InputFile")
1418  << " - deleteFile BOOST FILESYSTEM ERROR CAUGHT -: " << ex.what() << ". Trying again.";
1419  } catch (std::exception& ex) {
1420  edm::LogError("FedRawDataInputSource:InputFile")
1421  << " - deleteFile std::exception CAUGHT -: " << ex.what() << ". Trying again.";
1422  }
1424  }
1425 }
1426 
1427 //single-buffer mode file reading
1429  uint32_t existingSize = 0;
1430 
1431  if (fileDescriptor_ < 0) {
1432  bufferInputRead_ = 0;
1433  if (file->rawFd_ == -1) {
1434  fileDescriptor_ = open(file->fileName_.c_str(), O_RDONLY);
1435  if (file->rawHeaderSize_)
1436  lseek(fileDescriptor_, file->rawHeaderSize_, SEEK_SET);
1437  } else
1438  fileDescriptor_ = file->rawFd_;
1439 
1440  //skip header size in destination buffer (chunk position was already adjusted)
1441  bufferInputRead_ += file->rawHeaderSize_;
1442  existingSize += file->rawHeaderSize_;
1443 
1444  if (fileDescriptor_ >= 0)
1445  LogDebug("FedRawDataInputSource") << "opened file -: " << std::endl << file->fileName_;
1446  else {
1447  throw cms::Exception("FedRawDataInputSource:readNextChunkIntoBuffer")
1448  << "failed to open file " << std::endl
1449  << file->fileName_ << " fd:" << fileDescriptor_;
1450  }
1451  //fill chunk (skipping file header if present)
1452  for (unsigned int i = 0; i < readBlocks_; i++) {
1453  const ssize_t last = ::read(fileDescriptor_,
1454  (void*)(file->chunks_[0]->buf_ + existingSize),
1455  eventChunkBlock_ - (i == readBlocks_ - 1 ? existingSize : 0));
1457  existingSize += last;
1458  }
1459 
1460  } else {
1461  //continue reading
1462  if (file->chunkPosition_ == 0) { //in the rare case the last byte barely fit
1463  for (unsigned int i = 0; i < readBlocks_; i++) {
1464  const ssize_t last = ::read(fileDescriptor_, (void*)(file->chunks_[0]->buf_ + existingSize), eventChunkBlock_);
1466  existingSize += last;
1467  }
1468  } else {
1469  //event didn't fit in last chunk, so leftover must be moved to the beginning and completed
1470  uint32_t existingSizeLeft = eventChunkSize_ - file->chunkPosition_;
1471  memmove((void*)file->chunks_[0]->buf_, file->chunks_[0]->buf_ + file->chunkPosition_, existingSizeLeft);
1472 
1473  //calculate amount of data that can be added
1474  const uint32_t blockcount = file->chunkPosition_ / eventChunkBlock_;
1475  const uint32_t leftsize = file->chunkPosition_ % eventChunkBlock_;
1476 
1477  for (uint32_t i = 0; i < blockcount; i++) {
1478  const ssize_t last =
1479  ::read(fileDescriptor_, (void*)(file->chunks_[0]->buf_ + existingSizeLeft), eventChunkBlock_);
1481  existingSizeLeft += last;
1482  }
1483  if (leftsize) {
1484  const ssize_t last = ::read(fileDescriptor_, (void*)(file->chunks_[0]->buf_ + existingSizeLeft), leftsize);
1486  }
1487  file->chunkPosition_ = 0; //data was moved to beginning of the chunk
1488  }
1489  }
1490  if (bufferInputRead_ == file->fileSize_) { // no more data in this file
1491  if (fileDescriptor_ != -1) {
1492  LogDebug("FedRawDataInputSource") << "Closing input file -: " << std::endl << file->fileName_;
1493  close(fileDescriptor_);
1494  file->rawFd_ = fileDescriptor_ = -1;
1495  }
1496  }
1497 }
1498 
1500  std::lock_guard<std::mutex> lock(monlock_);
1501  auto itr = sourceEventsReport_.find(lumi);
1502  if (itr != sourceEventsReport_.end())
1503  itr->second += events;
1504  else
1506 }
1507 
1508 std::pair<bool, unsigned int> FedRawDataInputSource::getEventReport(unsigned int lumi, bool erase) {
1509  std::lock_guard<std::mutex> lock(monlock_);
1510  auto itr = sourceEventsReport_.find(lumi);
1511  if (itr != sourceEventsReport_.end()) {
1512  std::pair<bool, unsigned int> ret(true, itr->second);
1513  if (erase)
1514  sourceEventsReport_.erase(itr);
1515  return ret;
1516  } else
1517  return std::pair<bool, unsigned int>(false, 0);
1518 }
1519 
1521  std::sort(fileNames_.begin(), fileNames_.end(), [](std::string a, std::string b) {
1522  if (a.rfind('/') != std::string::npos)
1523  a = a.substr(a.rfind('/'));
1524  if (b.rfind('/') != std::string::npos)
1525  b = b.substr(b.rfind('/'));
1526  return b > a;
1527  });
1528 
1529  if (!fileNames_.empty()) {
1530  //get run number from first file in the vector
1532  std::string fileStem = fileName.stem().string();
1533  if (fileStem.find("file://") == 0)
1534  fileStem = fileStem.substr(7);
1535  else if (fileStem.find("file:") == 0)
1536  fileStem = fileStem.substr(5);
1537  auto end = fileStem.find('_');
1538 
1539  if (fileStem.find("run") == 0) {
1540  std::string runStr = fileStem.substr(3, end - 3);
1541  try {
1542  //get long to support test run numbers < 2^32
1543  long rval = boost::lexical_cast<long>(runStr);
1544  edm::LogInfo("FedRawDataInputSource") << "Autodetected run number in fileListMode -: " << rval;
1545  return rval;
1546  } catch (boost::bad_lexical_cast const&) {
1547  edm::LogWarning("FedRawDataInputSource")
1548  << "Unable to autodetect run number in fileListMode from file -: " << fileName;
1549  }
1550  }
1551  }
1552  return -1;
1553 }
1554 
1556  std::string& nextFile,
1557  uint32_t& fsize,
1558  uint64_t& lockWaitTime) {
1559  if (fileListIndex_ < fileNames_.size()) {
1560  nextFile = fileNames_[fileListIndex_];
1561  if (nextFile.find("file://") == 0)
1562  nextFile = nextFile.substr(7);
1563  else if (nextFile.find("file:") == 0)
1564  nextFile = nextFile.substr(5);
1565  std::filesystem::path fileName = nextFile;
1566  std::string fileStem = fileName.stem().string();
1567  if (fileStem.find("ls"))
1568  fileStem = fileStem.substr(fileStem.find("ls") + 2);
1569  if (fileStem.find('_'))
1570  fileStem = fileStem.substr(0, fileStem.find('_'));
1571 
1572  if (!fileListLoopMode_)
1573  ls = boost::lexical_cast<unsigned int>(fileStem);
1574  else //always starting from LS 1 in loop mode
1575  ls = 1 + loopModeIterationInc_;
1576 
1577  //fsize = 0;
1578  //lockWaitTime = 0;
1579  fileListIndex_++;
1581  } else {
1582  if (!fileListLoopMode_)
1584  else {
1585  //loop through files until interrupted
1587  fileListIndex_ = 0;
1588  return getFile(ls, nextFile, fsize, lockWaitTime);
1589  }
1590  }
1591 }
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:373
FedRawDataInputSource::fileDeleteLock_
std::mutex fileDeleteLock_
Definition: FedRawDataInputSource.h:162
FedRawDataInputSource::fillFEDRawDataCollection
edm::Timestamp fillFEDRawDataCollection(FEDRawDataCollection &)
Definition: FedRawDataInputSource.cc:694
change_name.diff
diff
Definition: change_name.py:13
evf::EvFDaqDirector::unlockFULocal2
void unlockFULocal2()
Definition: EvFDaqDirector.cc:922
eostools.ls
def ls(path, rec=False)
Definition: eostools.py:349
edm::RunNumber_t
unsigned int RunNumber_t
Definition: RunLumiEventNumber.h:14
counter
Definition: counter.py:1
FedRawDataInputSource::chunkIsFree_
bool chunkIsFree_
Definition: FedRawDataInputSource.h:137
dttmaxenums::L
Definition: DTTMax.h:29
evf::EvFDaqDirector::createBoLSFile
void createBoLSFile(const uint32_t lumiSection, bool checkIfExists) const
Definition: EvFDaqDirector.cc:927
FedRawDataInputSource::threadInit_
std::atomic< bool > threadInit_
Definition: FedRawDataInputSource.h:176
electrons_cff.bool
bool
Definition: electrons_cff.py:393
mps_fire.i
i
Definition: mps_fire.py:428
FedRawDataInputSource::rewind_
void rewind_() override
Definition: FedRawDataInputSource.cc:751
start
Definition: start.py:1
FEDNumbering::MINTriggerEGTPFEDID
Definition: FEDNumbering.h:63
evf::EvFDaqDirector::runEnded
Definition: EvFDaqDirector.h:64
MessageLogger.h
InputFile::parent_
FedRawDataInputSource * parent_
Definition: FedRawDataInputSource.h:207
evf::EvFDaqDirector::getEoLSFilePathOnBU
std::string getEoLSFilePathOnBU(const unsigned int ls) const
Definition: EvFDaqDirector.cc:470
funct::false
false
Definition: Factorize.h:29
evf::FastMonitoringThread::inSupFileLimit
Definition: FastMonitoringThread.h:54
InputFile::fileName_
std::string fileName_
Definition: FedRawDataInputSource.h:210
FedRawDataInputSource::maybeOpenNewLumiSection
void maybeOpenNewLumiSection(const uint32_t lumiSection)
Definition: FedRawDataInputSource.cc:306
FedRawDataInputSource::quit_threads_
std::atomic< bool > quit_threads_
Definition: FedRawDataInputSource.h:153
FedRawDataInputSource::mWakeup_
std::mutex mWakeup_
Definition: FedRawDataInputSource.h:168
FedRawDataInputSource::fileNames_
std::vector< std::string > fileNames_
Definition: FedRawDataInputSource.h:97
FedRawDataInputSource::workerThreads_
std::vector< std::thread * > workerThreads_
Definition: FedRawDataInputSource.h:141
FedRawDataInputSource::fileListIndex_
unsigned int fileListIndex_
Definition: FedRawDataInputSource.h:102
FedRawDataInputSource::MINTCDSuTCAFEDID_
uint16_t MINTCDSuTCAFEDID_
Definition: FedRawDataInputSource.h:124
FedRawDataInputSource::threadError
void threadError()
Definition: FedRawDataInputSource.cc:1351
evf::FastMonitoringThread::inSupWaitFreeChunk
Definition: FastMonitoringThread.h:55
FedRawDataInputSource::readingFilesCount_
std::atomic< unsigned int > readingFilesCount_
Definition: FedRawDataInputSource.h:89
submitPVValidationJobs.now
now
Definition: submitPVValidationJobs.py:639
mps_update.status
status
Definition: mps_update.py:69
FedRawDataInputSource::useL1EventID_
const bool useL1EventID_
Definition: FedRawDataInputSource.h:95
min
T min(T a, T b)
Definition: MathUtil.h:58
FEDRawDataCollection
Definition: FEDRawDataCollection.h:18
evf::EvFDaqDirector::getLumisectionToStart
unsigned int getLumisectionToStart() const
Definition: EvFDaqDirector.cc:1856
edm
HLT enums.
Definition: AlignableModifier.h:19
FedRawDataInputSource::numConcurrentReads_
unsigned int numConcurrentReads_
Definition: FedRawDataInputSource.h:88
evf::evtn::gtpe_board_sense
bool gtpe_board_sense(const unsigned char *p)
Definition: GlobalEventNumber.cc:11
FedRawDataInputSource::nStreams_
unsigned int nStreams_
Definition: FedRawDataInputSource.h:164
pos
Definition: PixelAliasList.h:18
FedRawDataInputSource::getNextEvent
evf::EvFDaqDirector::FileStatus getNextEvent()
Definition: FedRawDataInputSource.cc:352
FedRawDataInputSource::runNumber_
edm::RunNumber_t runNumber_
Definition: FedRawDataInputSource.h:106
FedRawDataInputSource::currentLumiSection_
unsigned int currentLumiSection_
Definition: FedRawDataInputSource.h:116
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
l1tstage2_dqm_sourceclient-live_cfg.rawData
rawData
Definition: l1tstage2_dqm_sourceclient-live_cfg.py:162
evf::FastMonitoringThread::inRunEnd
Definition: FastMonitoringThread.h:41
FedRawDataInputSource::workerPool_
tbb::concurrent_queue< unsigned int > workerPool_
Definition: FedRawDataInputSource.h:143
FedRawDataInputSource::sourceEventsReport_
std::map< unsigned int, unsigned int > sourceEventsReport_
Definition: FedRawDataInputSource.h:178
DeadROCCounter.getRunNumber
def getRunNumber(filename)
Definition: DeadROCCounter.py:7
FedRawDataInputSource::readNextChunkIntoBuffer
void readNextChunkIntoBuffer(InputFile *file)
Definition: FedRawDataInputSource.cc:1428
edm::InputSourceDescription
Definition: InputSourceDescription.h:20
cms::cuda::assert
assert(be >=bs)
FedRawDataInputSource::fms_
evf::FastMonitoringService * fms_
Definition: FedRawDataInputSource.h:78
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:222
edm::Timestamp::beginOfTime
static Timestamp beginOfTime()
Definition: Timestamp.h:84
InputFile::moveToPreviousChunk
void moveToPreviousChunk(const size_t size, const size_t offset)
Definition: FedRawDataInputSource.cc:1391
FedRawDataInputSource::cvReader_
std::vector< std::condition_variable * > cvReader_
Definition: FedRawDataInputSource.h:150
FedRawDataInputSource::eventChunkSize_
unsigned int eventChunkSize_
Definition: FedRawDataInputSource.h:83
evf::evtn::get
unsigned int get(const unsigned char *, bool)
Definition: GlobalEventNumber.cc:77
evf::FastMonitoringThread::inCachedEvent
Definition: FastMonitoringThread.h:46
FedRawDataInputSource::cvWakeup_
std::condition_variable cvWakeup_
Definition: FedRawDataInputSource.h:169
evf::EvFDaqDirector::sameFile
Definition: EvFDaqDirector.h:64
evf::EvFDaqDirector::runAbort
Definition: EvFDaqDirector.h:64
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
FedRawDataInputSource::freeChunks_
tbb::concurrent_queue< InputChunk * > freeChunks_
Definition: FedRawDataInputSource.h:146
MillePedeFileConverter_cfg.fileName
fileName
Definition: MillePedeFileConverter_cfg.py:32
evf::evtn::getgpslow
unsigned int getgpslow(const unsigned char *)
Definition: GlobalEventNumber.cc:92
patZpeak.events
events
Definition: patZpeak.py:20
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
dqmdumpme.first
first
Definition: dqmdumpme.py:55
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
FRDHeaderVersionSize
constexpr std::array< uint32, FRDHeaderMaxVersion+1 > FRDHeaderVersionSize
Definition: FRDEventMessage.h:129
evf::FastMonitoringThread::inWaitChunk
Definition: FastMonitoringThread.h:43
evf::FastMonitoringService::setInputSource
void setInputSource(FedRawDataInputSource *inputSource)
Definition: FastMonitoringService.h:180
FedRawDataInputSource::bufferInputRead_
uint32_t bufferInputRead_
Definition: FedRawDataInputSource.h:174
edm::InputSource::processHistoryRegistryForUpdate
ProcessHistoryRegistry & processHistoryRegistryForUpdate()
Definition: InputSource.h:330
FEDRawData::data
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
FedRawDataInputSource::getEventReport
std::pair< bool, unsigned int > getEventReport(unsigned int lumi, bool erase)
Definition: FedRawDataInputSource.cc:1508
InputFile::bufferPosition_
uint32_t bufferPosition_
Definition: FedRawDataInputSource.h:221
InputFile
Definition: FedRawDataInputSource.h:206
InputChunk::offset_
unsigned int offset_
Definition: FedRawDataInputSource.h:188
edm::Wrapper
Definition: Product.h:10
FedRawDataInputSource::workerJob_
std::vector< ReaderInfo > workerJob_
Definition: FedRawDataInputSource.h:144
FEDRawData
Definition: FEDRawData.h:19
InputFile::chunkPosition_
uint32_t chunkPosition_
Definition: FedRawDataInputSource.h:222
Utilities.operator
operator
Definition: Utilities.py:24
evf::FastMonitoringThread::inProcessingFile
Definition: FastMonitoringThread.h:42
FedRawDataInputSource::readBlocks_
unsigned int readBlocks_
Definition: FedRawDataInputSource.h:85
evf::FastMonitoringThread::inSupWaitFreeChunkCopying
Definition: FastMonitoringThread.h:56
AuxiliaryMakers.h
edm::LuminosityBlockAuxiliary
Definition: LuminosityBlockAuxiliary.h:15
evf::EvFDaqDirector::updateFuLock
FileStatus updateFuLock(unsigned int &ls, std::string &nextFile, uint32_t &fsize, uint16_t &rawHeaderSize, uint64_t &lockWaitTime, bool &setExceptionState)
Definition: EvFDaqDirector.cc:497
FedRawDataInputSource::streamFileTracker_
std::vector< int > streamFileTracker_
Definition: FedRawDataInputSource.h:163
InputChunk::usedSize_
uint32_t usedSize_
Definition: FedRawDataInputSource.h:186
InputChunk::buf_
unsigned char * buf_
Definition: FedRawDataInputSource.h:183
InputChunk::reset
void reset(unsigned int newOffset, unsigned int toRead, unsigned int fileIndex)
Definition: FedRawDataInputSource.h:196
FedRawDataInputSource::eventRunNumber_
uint32_t eventRunNumber_
Definition: FedRawDataInputSource.h:117
evf::EvFDaqDirector::getEoLSFilePathOnFU
std::string getEoLSFilePathOnFU(const unsigned int ls) const
Definition: EvFDaqDirector.cc:474
FedRawDataInputSource::testTCDSFEDRange_
const std::vector< unsigned int > testTCDSFEDRange_
Definition: FedRawDataInputSource.h:96
dqmdumpme.last
last
Definition: dqmdumpme.py:56
FedRawDataInputSource::InputFile
friend struct InputFile
Definition: FedRawDataInputSource.h:38
edm::EventPrincipal
Definition: EventPrincipal.h:46
hgcalPlots.stat
stat
Definition: hgcalPlots.py:1119
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
evf::EvFDaqDirector::isSingleStreamThread
bool isSingleStreamThread()
Definition: EvFDaqDirector.h:122
evf::evtn::makeEventAuxiliary
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)
Definition: AuxiliaryMakers.cc:9
evf::FastMonitoringThread::inSupWaitFreeThread
Definition: FastMonitoringThread.h:57
evf::FastMonitoringThread::inWaitInput
Definition: FastMonitoringThread.h:37
FRDHeaderMaxVersion
constexpr size_t FRDHeaderMaxVersion
Definition: FRDEventMessage.h:128
evf::EvFDaqDirector::parseFRDFileHeader
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)
Definition: EvFDaqDirector.cc:955
TCDSRaw.h
FedRawDataInputSource::filesToDelete_
std::list< std::pair< int, std::unique_ptr< InputFile > > > filesToDelete_
Definition: FedRawDataInputSource.h:160
EventID.h
FedRawDataInputSource::getLSFromFilename_
const bool getLSFromFilename_
Definition: FedRawDataInputSource.h:92
FedRawDataInputSource::ReaderInfo
std::pair< InputFile *, InputChunk * > ReaderInfo
Definition: FedRawDataInputSource.h:133
InputChunk
Definition: FedRawDataInputSource.h:182
FedRawDataInputSource::FedRawDataInputSource
FedRawDataInputSource(edm::ParameterSet const &, edm::InputSourceDescription const &)
Definition: FedRawDataInputSource.cc:52
evf::FastMonitoringThread::inReadCleanup
Definition: FastMonitoringThread.h:48
mps_fire.end
end
Definition: mps_fire.py:242
FedRawDataInputSource::fileListLoopMode_
const bool fileListLoopMode_
Definition: FedRawDataInputSource.h:103
edm::InputSource::luminosityBlockAuxiliary
std::shared_ptr< LuminosityBlockAuxiliary > luminosityBlockAuxiliary() const
Called by the framework to merge or insert lumi in principal cache.
Definition: InputSource.h:245
InputFile::currentChunk_
unsigned int currentChunk_
Definition: FedRawDataInputSource.h:223
FedRawDataInputSource::daqDirector_
evf::EvFDaqDirector * daqDirector_
Definition: FedRawDataInputSource.h:79
Service
tcds::Raw_v1
Definition: TCDSRaw.h:106
svgfig.load
def load(fileName)
Definition: svgfig.py:547
dt4ml_dqm_sourceclient-live_cfg.filePath
filePath
CUSTOMIZE FOR ML.
Definition: dt4ml_dqm_sourceclient-live_cfg.py:45
evf::EvFDaqDirector::noFile
Definition: EvFDaqDirector.h:64
FedRawDataInputSource::fileQueue_
tbb::concurrent_queue< std::unique_ptr< InputFile > > fileQueue_
Definition: FedRawDataInputSource.h:147
evf::EvFDaqDirector::useFileBroker
bool useFileBroker() const
Definition: EvFDaqDirector.h:79
evf::FastMonitoringThread::inChecksumEvent
Definition: FastMonitoringThread.h:45
InputChunk::readComplete_
std::atomic< bool > readComplete_
Definition: FedRawDataInputSource.h:190
b
double b
Definition: hdecay.h:118
edm::EventPrincipal::put
void put(BranchDescription const &bd, std::unique_ptr< WrapperBase > edp, ProductProvenance const &productProvenance) const
Definition: EventPrincipal.cc:179
FedRawDataInputSource::reportEventsThisLumiInSource
void reportEventsThisLumiInSource(unsigned int lumi, unsigned int events)
Definition: FedRawDataInputSource.cc:1499
evf::FastMonitoringThread::inNewLumi
Definition: FastMonitoringThread.h:38
FedRawDataInputSource::processHistoryID_
edm::ProcessHistoryID processHistoryID_
Definition: FedRawDataInputSource.h:114
InputSourceDescription.h
InputFile::~InputFile
~InputFile()
Definition: FedRawDataInputSource.cc:1405
evf::FastMonitoringThread::inSupNewFileWaitThreadCopying
Definition: FastMonitoringThread.h:64
edm::EventAuxiliary
Definition: EventAuxiliary.h:14
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
FedRawDataInputSource::startedSupervisorThread_
bool startedSupervisorThread_
Definition: FedRawDataInputSource.h:139
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
FedRawDataInputSource::exceptionState
bool exceptionState()
Definition: FedRawDataInputSource.h:63
FedRawDataInputSource::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: FedRawDataInputSource.cc:205
FedRawDataInputSource::daqProvenanceHelper_
const edm::DaqProvenanceHelper daqProvenanceHelper_
Definition: FedRawDataInputSource.h:109
crc32c
uint32_t crc32c(uint32_t crc, const unsigned char *buf, size_t len)
Definition: crc32c.cc:340
edm::InputSource::runAuxiliary
std::shared_ptr< RunAuxiliary > runAuxiliary() const
Called by the framework to merge or insert run in principal cache.
Definition: InputSource.h:242
FedRawDataInputSource::initFileList
long initFileList()
Definition: FedRawDataInputSource.cc:1520
FedRawDataInputSource::L1EventID_
uint32_t L1EventID_
Definition: FedRawDataInputSource.h:119
UnixSignalHandlers.h
cppFunctionSkipper.exception
exception
Definition: cppFunctionSkipper.py:10
funct::true
true
Definition: Factorize.h:173
InputChunk::fileIndex_
unsigned int fileIndex_
Definition: FedRawDataInputSource.h:189
reader.h
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:223
edm::InputSource::setRunAuxiliary
void setRunAuxiliary(RunAuxiliary *rp)
Definition: InputSource.h:332
edm::ParameterSet
Definition: ParameterSet.h:47
FedRawDataInputSource::currentFileIndex_
int currentFileIndex_
Definition: FedRawDataInputSource.h:159
FEDTrailer
Definition: FEDTrailer.h:14
a
double a
Definition: hdecay.h:119
Timestamp.h
FedRawDataInputSource::alwaysStartFromFirstLS_
const bool alwaysStartFromFirstLS_
Definition: FedRawDataInputSource.h:93
FFFNamingSchema.h
Event.h
edm::InputSource::productRegistryUpdate
ProductRegistry & productRegistryUpdate()
Definition: InputSource.h:329
FedRawDataInputSource::eventChunkBlock_
unsigned int eventChunkBlock_
Definition: FedRawDataInputSource.h:84
FEDHeader::triggerType
uint8_t triggerType() const
Event Trigger type identifier.
Definition: FEDHeader.cc:13
CommonMethods.lock
def lock()
Definition: CommonMethods.py:82
edm::DaqProvenanceHelper::daqInit
ProcessHistoryID daqInit(ProductRegistry &productRegistry, ProcessHistoryRegistry &processHistoryRegistry) const
Definition: DaqProvenanceHelper.cc:83
evf::EvFDaqDirector::getNextFromFileBroker
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)
Definition: EvFDaqDirector.cc:1704
FedRawDataInputSource::verifyChecksum_
const bool verifyChecksum_
Definition: FedRawDataInputSource.h:94
mps_check.timeout
int timeout
Definition: mps_check.py:53
SiStripCommissioningSource_FromEDM_cfg.EvFDaqDirector
EvFDaqDirector
Definition: SiStripCommissioningSource_FromEDM_cfg.py:57
evf::EvFDaqDirector::unlockFULocal
void unlockFULocal()
Definition: EvFDaqDirector.cc:912
edm::shutdown_flag
volatile std::atomic< bool > shutdown_flag
Definition: UnixSignalHandlers.cc:22
FedRawDataInputSource::checkNext
Next checkNext() override
Definition: FedRawDataInputSource.cc:230
evf::FastMonitoringService::setInStateSup
void setInStateSup(FastMonitoringThread::InputState inputState)
Definition: FastMonitoringService.h:182
evf::FastMonitoringThread::inChunkReceived
Definition: FastMonitoringThread.h:44
printConversionInfo.aux
aux
Definition: printConversionInfo.py:19
edm::Service
Definition: Service.h:30
createfilelist.int
int
Definition: createfilelist.py:10
FedRawDataInputSource::currentFile_
std::unique_ptr< InputFile > currentFile_
Definition: FedRawDataInputSource.h:136
evf::FastMonitoringThread::inSupNewFileWaitChunk
Definition: FastMonitoringThread.h:67
FedRawDataInputSource::setExceptionState_
bool setExceptionState_
Definition: FedRawDataInputSource.h:155
FrontierConditions_GlobalTag_cff.file
file
Definition: FrontierConditions_GlobalTag_cff.py:13
FastMonitoringService.h
edm::InputSource::luminosityBlock
LuminosityBlockNumber_t luminosityBlock() const
Accessor for current luminosity block number.
Definition: InputSource.cc:444
FedRawDataInputSource::eventID_
edm::EventID eventID_
Definition: FedRawDataInputSource.h:113
edm::RawInputSource::Next::kStop
FEDRawDataCollection.h
evf::FastMonitoringThread::inSupNewFile
Definition: FastMonitoringThread.h:63
FedRawDataInputSource::mReader_
std::mutex mReader_
Definition: FedRawDataInputSource.h:149
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
FedRawDataInputSource::eventsThisLumi_
unsigned int eventsThisLumi_
Definition: FedRawDataInputSource.h:121
crc32c.h
FedRawDataInputSource::~FedRawDataInputSource
~FedRawDataInputSource() override
Definition: FedRawDataInputSource.cc:174
FEDHeader::length
static const uint32_t length
Definition: FEDHeader.h:54
evf::EvFDaqDirector::getEoRFilePathOnFU
std::string getEoRFilePathOnFU() const
Definition: EvFDaqDirector.cc:484
edm::EventPrincipal::streamID
StreamID streamID() const
Definition: EventPrincipal.h:106
l1tstage2_dqm_sourceclient-live_cfg.fedId
fedId
Definition: l1tstage2_dqm_sourceclient-live_cfg.py:88
evf::EvFDaqDirector::newLumi
Definition: EvFDaqDirector.h:64
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
itr
std::vector< std::pair< float, float > >::iterator itr
Definition: HGCDigitizer.cc:29
evf::FastMonitoringThread::inSupNewFileWaitThread
Definition: FastMonitoringThread.h:65
FedRawDataInputSource::getFile
evf::EvFDaqDirector::FileStatus getFile(unsigned int &ls, std::string &nextFile, uint32_t &fsize, uint64_t &lockWaitTime)
Definition: FedRawDataInputSource.cc:1555
InputFile::rawFd_
int rawFd_
Definition: FedRawDataInputSource.h:212
evf::FastMonitoringThread::inSupLockPolling
Definition: FastMonitoringThread.h:60
FedRawDataInputSource::startupLock_
std::mutex startupLock_
Definition: FedRawDataInputSource.h:156
visDQMUpload.buf
buf
Definition: visDQMUpload.py:154
tcds
Definition: TCDSRaw.h:16
FedRawDataInputSource.h
evf::FastMonitoringService::reportLockWait
void reportLockWait(unsigned int ls, double waitTime, unsigned int lockCount)
Definition: FastMonitoringService.cc:702
evf::evtn::evm_board_sense
bool evm_board_sense(const unsigned char *p, size_t size)
Definition: GlobalEventNumber.cc:15
FedRawDataInputSource::thread_quit_signal
std::vector< unsigned int > thread_quit_signal
Definition: FedRawDataInputSource.h:154
InputSourceMacros.h
InputFile::advance
bool advance(unsigned char *&dataPosition, const size_t size)
Definition: FedRawDataInputSource.cc:1356
FedRawDataInputSource::useFileBroker_
bool useFileBroker_
Definition: FedRawDataInputSource.h:98
edm::InputSource::setLuminosityBlockAuxiliary
void setLuminosityBlockAuxiliary(LuminosityBlockAuxiliary *lbp)
Definition: InputSource.h:336
DataPointDefinition.h
evf::FastMonitoringThread::inInit
Definition: FastMonitoringThread.h:36
edm::RawInputSource::Next
Next
Definition: RawInputSource.h:24
edm::Timestamp::invalidTimestamp
static Timestamp invalidTimestamp()
Definition: Timestamp.h:82
edm::EventAuxiliary::PhysicsTrigger
Definition: EventAuxiliary.h:20
FedRawDataInputSource::readSupervisor
void readSupervisor()
Definition: FedRawDataInputSource.cc:753
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
evf::EvFDaqDirector::createProcessingNotificationMaybe
void createProcessingNotificationMaybe() const
Definition: EvFDaqDirector.cc:2011
crc32c_hw_test
bool crc32c_hw_test()
Definition: crc32c.cc:354
dqmiodatasetharvest.inf
inf
Definition: dqmiodatasetharvest.py:38
init
Definition: init.py:1
InputFile::chunks_
tbb::concurrent_vector< InputChunk * > chunks_
Definition: FedRawDataInputSource.h:219
evf::FastMonitoringThread::inNoRequest
Definition: FastMonitoringThread.h:49
edm::RawInputSource::makeEvent
void makeEvent(EventPrincipal &eventPrincipal, EventAuxiliary const &eventAuxiliary)
Definition: RawInputSource.cc:51
edm::DaqProvenanceHelper::branchDescription
BranchDescription const & branchDescription() const
Definition: DaqProvenanceHelper.h:46
FedRawDataInputSource::event_
std::unique_ptr< FRDEventMsgView > event_
Definition: FedRawDataInputSource.h:111
edm::InputSource::setNewRun
void setNewRun()
Definition: InputSource.h:354
FEDTrailer::length
static const uint32_t length
Definition: FEDTrailer.h:57
FedRawDataInputSource::nextEvent
evf::EvFDaqDirector::FileStatus nextEvent()
Definition: FedRawDataInputSource.cc:343
FedRawDataInputSource::detectedFRDversion_
uint16_t detectedFRDversion_
Definition: FedRawDataInputSource.h:135
relativeConstraints.empty
bool empty
Definition: relativeConstraints.py:46
GlobalEventNumber.h
EventAuxiliary.h
FedRawDataInputSource::tid_active_
std::vector< unsigned int > tid_active_
Definition: FedRawDataInputSource.h:151
Exception
Definition: hltDiff.cc:246
evf::FastMonitoringThread::inSupBusy
Definition: FastMonitoringThread.h:59
FedRawDataInputSource::checkEvery_
unsigned int checkEvery_
Definition: FedRawDataInputSource.h:165
FEDRawData::resize
void resize(size_t newsize)
Definition: FEDRawData.cc:28
evf::EvFDaqDirector::setFMS
void setFMS(evf::FastMonitoringService *fms)
Definition: EvFDaqDirector.h:121
MatrixUtil.remove
def remove(d, key, TELL=False)
Definition: MatrixUtil.py:219
FedRawDataInputSource::fileDescriptor_
int fileDescriptor_
Definition: FedRawDataInputSource.h:173
evf
Definition: fillJson.h:27
edm::InputSource::setEventCached
void setEventCached()
Called by the framework to merge or ached() const {return eventCached_;}.
Definition: InputSource.h:361
evf::FastMonitoringThread::inReadEvent
Definition: FastMonitoringThread.h:47
evf::FastMonitoringService::startedLookingForFile
void startedLookingForFile()
Definition: FastMonitoringService.cc:666
evf::FastMonitoringThread::inSupNoFile
Definition: FastMonitoringThread.h:62
evf::FastMonitoringService::setExceptionDetected
void setExceptionDetected(unsigned int ls)
Definition: FastMonitoringService.cc:392
evf::EvFDaqDirector::grabNextJsonFileAndUnlock
int grabNextJsonFileAndUnlock(std::filesystem::path const &jsonSourcePath)
Definition: EvFDaqDirector.cc:1352
edm::InputSource::resetLuminosityBlockAuxiliary
void resetLuminosityBlockAuxiliary(bool isNewLumi=true) const
Definition: InputSource.h:344
FEDHeader::sourceID
uint16_t sourceID() const
Identifier of the FED.
Definition: FEDHeader.cc:19
FedRawDataInputSource::startupCv_
std::condition_variable startupCv_
Definition: FedRawDataInputSource.h:157
evf::FastMonitoringThread::inSupNewFileWaitChunkCopying
Definition: FastMonitoringThread.h:66
FedRawDataInputSource::tcds_pointer_
unsigned char * tcds_pointer_
Definition: FedRawDataInputSource.h:120
cond::uint64_t
unsigned long long uint64_t
Definition: Time.h:13
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
FedRawDataInputSource::fileListMode_
const bool fileListMode_
Definition: FedRawDataInputSource.h:101
cms::Exception
Definition: Exception.h:70
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
FedRawDataInputSource::InputChunk
friend struct InputChunk
Definition: FedRawDataInputSource.h:39
FedRawDataInputSource::readSupervisorThread_
std::unique_ptr< std::thread > readSupervisorThread_
Definition: FedRawDataInputSource.h:140
command_line.start
start
Definition: command_line.py:167
ParameterSet.h
evf::FastMonitoringService::setInState
void setInState(FastMonitoringThread::InputState inputState)
Definition: FastMonitoringService.h:181
edm::InputSource::processGUID
std::string const & processGUID() const
Accessor for global process identifier.
Definition: InputSource.h:207
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
runEdmFileComparison.skipped
skipped
Definition: runEdmFileComparison.py:225
edm::RawInputSource::Next::kEvent
ntuplemaker.time
time
Definition: ntuplemaker.py:310
evf::evtn::gtpe_get
unsigned int gtpe_get(const unsigned char *)
Definition: GlobalEventNumber.cc:83
event
Definition: event.py:1
edm::EventID
Definition: EventID.h:31
evf::FastMonitoringService::stoppedLookingForFile
void stoppedLookingForFile(unsigned int lumi)
Definition: FastMonitoringService.cc:674
hltrates_dqm_sourceclient-live_cfg.offset
offset
Definition: hltrates_dqm_sourceclient-live_cfg.py:82
FEDHeader
Definition: FEDHeader.h:14
evf::FastMonitoringThread::inSupWaitFreeThreadCopying
Definition: FastMonitoringThread.h:58
InputFile::waitForChunk
bool waitForChunk(unsigned int chunkid)
Definition: FedRawDataInputSource.h:253
FedRawDataInputSource::MAXTCDSuTCAFEDID_
uint16_t MAXTCDSuTCAFEDID_
Definition: FedRawDataInputSource.h:125
FEDHeader.h
lumi
Definition: LumiSectionData.h:20
InputFile::rewindChunk
void rewindChunk(const size_t size)
Definition: FedRawDataInputSource.cc:1400
edm::Log
Definition: MessageLogger.h:70
evf::EvFDaqDirector::FileStatus
FileStatus
Definition: EvFDaqDirector.h:64
evf::EvFDaqDirector::lockFULocal2
void lockFULocal2()
Definition: EvFDaqDirector.cc:917
FedRawDataInputSource::monlock_
std::mutex monlock_
Definition: FedRawDataInputSource.h:179
InputFile::deleteFile_
bool deleteFile_
Definition: FedRawDataInputSource.h:211
FedRawDataInputSource::read
void read(edm::EventPrincipal &eventPrincipal) override
Definition: FedRawDataInputSource.cc:617
sistrip::runNumber_
static const char runNumber_[]
Definition: ConstantsForDqm.h:33
FedRawDataInputSource::numBuffers_
unsigned int numBuffers_
Definition: FedRawDataInputSource.h:86
evf::evtn::getgpshigh
unsigned int getgpshigh(const unsigned char *)
Definition: GlobalEventNumber.cc:95
FedRawDataInputSource::maxBufferedFiles_
unsigned int maxBufferedFiles_
Definition: FedRawDataInputSource.h:87
edm::TimeValue_t
unsigned long long TimeValue_t
Definition: Timestamp.h:28
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
FedRawDataInputSource::singleBufferMode_
bool singleBufferMode_
Definition: FedRawDataInputSource.h:172
FedRawDataInputSource::readWorker
void readWorker(unsigned int tid)
Definition: FedRawDataInputSource.cc:1209
FedRawDataInputSource::loopModeIterationInc_
unsigned int loopModeIterationInc_
Definition: FedRawDataInputSource.h:104
FEDNumbering::MAXFEDID
Definition: FEDNumbering.h:26
evf::EvFDaqDirector::newFile
Definition: EvFDaqDirector.h:64
edm::RunAuxiliary
Definition: RunAuxiliary.h:15
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
edm::InputSource::run
RunNumber_t run() const
Accessor for current run number.
Definition: InputSource.cc:439
evf::EvFDaqDirector::grabNextJsonFromRaw
int grabNextJsonFromRaw(std::string const &rawSourcePath, int &rawFd, uint16_t &rawHeaderSize, int64_t &fileSizeFromHeader, bool &fileFound, uint32_t serverLS, bool closeFile)
Definition: EvFDaqDirector.cc:1090
FEDTrailer::fragmentLength
uint32_t fragmentLength() const
The length of the event fragment counted in 64-bit words including header and trailer.
Definition: FEDTrailer.cc:13
FedRawDataInputSource::GTPEventID_
uint32_t GTPEventID_
Definition: FedRawDataInputSource.h:118
evf::EvFDaqDirector::setDeleteTracking
void setDeleteTracking(std::mutex *fileDeleteLock, std::list< std::pair< int, std::unique_ptr< InputFile >>> *filesToDelete)
Definition: EvFDaqDirector.h:175
FEDNumbering::MINTriggerGTPFEDID
Definition: FEDNumbering.h:61
edm::DaqProvenanceHelper::dummyProvenance
ProductProvenance const & dummyProvenance() const
Definition: DaqProvenanceHelper.h:48
FEDTrailer.h
edm::Timestamp
Definition: Timestamp.h:30