CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes
dqmservices::DQMStreamerReader Class Reference

#include <DQMStreamerReader.h>

Inheritance diagram for dqmservices::DQMStreamerReader:
edm::StreamerInputSource edm::RawInputSource edm::InputSource

Classes

struct  OpenFile
 

Public Member Functions

 DQMStreamerReader (edm::ParameterSet const &pset, edm::InputSourceDescription const &desc)
 
bool newHeader ()
 
 ~DQMStreamerReader () override
 
- Public Member Functions inherited from edm::StreamerInputSource
void deserializeAndMergeWithRegistry (InitMsgView const &initView, bool subsequent=false)
 
void deserializeEvent (EventMsgView const &eventView)
 
std::unique_ptr< SendJobHeaderdeserializeRegistry (InitMsgView const &initView)
 
bool isBufferLZMA (unsigned char const *inputBuffer, unsigned int inputSize)
 
bool isBufferZSTD (unsigned char const *inputBuffer, unsigned int inputSize)
 
 StreamerInputSource (ParameterSet const &pset, InputSourceDescription const &desc)
 
 ~StreamerInputSource () 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::StreamerInputSource
static void fillDescription (ParameterSetDescription &description)
 
static void mergeIntoRegistry (SendJobHeader const &header, ProductRegistry &, BranchIDListHelper &, ThinnedAssociationsHelper &, bool subsequent)
 
static unsigned int uncompressBuffer (unsigned char *inputBuffer, unsigned int inputSize, std::vector< unsigned char > &outputBuffer, unsigned int expectedFullSize)
 
static unsigned int uncompressBufferLZMA (unsigned char *inputBuffer, unsigned int inputSize, std::vector< unsigned char > &outputBuffer, unsigned int expectedFullSize, bool hasHeader=true)
 
static unsigned int uncompressBufferZSTD (unsigned char *inputBuffer, unsigned int inputSize, std::vector< unsigned char > &outputBuffer, unsigned int expectedFullSize, bool hasHeader=true)
 
- 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 genuineCloseFile () override
 
void genuineReadFile () override
 
void skip (int toSkip) override
 
- Protected Member Functions inherited from edm::StreamerInputSource
void resetAfterEndRun ()
 
- 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...
 
ItemType state () const
 

Private Member Functions

bool acceptEvent (const EventMsgView *)
 
void closeFileImp_ (const std::string &reason)
 
EventMsgView const * getEventMsg ()
 
InitMsgView const * getHeaderMsg ()
 
void openFileImp_ (const DQMFileIterator::LumiEntry &entry)
 
bool openNextFileImp_ ()
 
EventMsgView const * prepareNextEvent ()
 
bool prepareNextFile ()
 
void reset_ () override
 
bool setAcceptAllEvt ()
 
bool setMatchTriggerSel (std::vector< std::string > const &tnames)
 

Private Attributes

bool acceptAllEvt_ = false
 
std::shared_ptr< edm::EventSkipperByIDeventSkipperByID_
 
struct dqmservices::DQMStreamerReader::OpenFile file_
 
DQMFileIterator fiterator_
 
bool const flagDeleteDatFiles_
 
bool const flagEndOfRunKills_
 
bool const flagSkipFirstLumis_
 
std::vector< std::string > const hltSel_
 
bool isFirstFile_ = true
 
bool matchTriggerSel_ = false
 
unsigned int const minEventsPerLs_
 
edm::Service< DQMMonitoringServicemon_
 
unsigned int processedEventPerLs_ = 0
 
std::shared_ptr< TriggerSelectortriggerSelector_
 

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_
 
- Static Protected Member Functions inherited from edm::StreamerInputSource
static void buildClassCache (SendDescs const &descs)
 
static void declareStreamers (SendDescs const &descs)
 

Detailed Description

Definition at line 19 of file DQMStreamerReader.h.

Constructor & Destructor Documentation

◆ DQMStreamerReader()

dqmservices::DQMStreamerReader::DQMStreamerReader ( edm::ParameterSet const &  pset,
edm::InputSourceDescription const &  desc 
)

Definition at line 22 of file DQMStreamerReader.cc.

References reset_(), and setAcceptAllEvt().

25  minEventsPerLs_(pset.getUntrackedParameter<int>("minEventsPerLumi")),
26  flagSkipFirstLumis_(pset.getUntrackedParameter<bool>("skipFirstLumis")),
27  flagEndOfRunKills_(pset.getUntrackedParameter<bool>("endOfRunKills")),
28  flagDeleteDatFiles_(pset.getUntrackedParameter<bool>("deleteDatFiles")),
29  hltSel_(pset.getUntrackedParameter<std::vector<std::string>>("SelectEvents")) {
31  reset_();
32  }
unsigned int const minEventsPerLs_
std::vector< std::string > const hltSel_
StreamerInputSource(ParameterSet const &pset, InputSourceDescription const &desc)

◆ ~DQMStreamerReader()

dqmservices::DQMStreamerReader::~DQMStreamerReader ( )
override

Definition at line 34 of file DQMStreamerReader.cc.

34  {
35  // Sometimes(?) the destructor called after service registry was already destructed
36  // and closeFile_ throws away no ServiceRegistry found exception...
37  //
38  // Normally, this file should be closed before this destructor is called.
39  //closeFileImp_("destructor");
40  }

Member Function Documentation

◆ acceptEvent()

bool dqmservices::DQMStreamerReader::acceptEvent ( const EventMsgView evtmsg)
private

Check the trigger path to accept event

Definition at line 369 of file DQMStreamerReader.cc.

References acceptAllEvt_, EventMsgView::hltCount(), EventMsgView::hltTriggerBits(), matchTriggerSel_, and triggerSelector_.

Referenced by prepareNextEvent().

369  {
370  if (acceptAllEvt_)
371  return true;
372  if (!matchTriggerSel_)
373  return false;
374 
375  std::vector<unsigned char> hltTriggerBits_;
376  int hltTriggerCount_ = evtmsg->hltCount();
377  if (hltTriggerCount_ > 0) {
378  hltTriggerBits_.resize(1 + (hltTriggerCount_ - 1) / 4);
379  }
380  evtmsg->hltTriggerBits(&hltTriggerBits_[0]);
381 
382  return (triggerSelector_->wantAll() || triggerSelector_->acceptEvent(&hltTriggerBits_[0], evtmsg->hltCount()));
383  }
void hltTriggerBits(uint8 *put_here) const
std::shared_ptr< TriggerSelector > triggerSelector_
uint32 hltCount() const
Definition: EventMessage.h:94

◆ checkNext()

edm::RawInputSource::Next dqmservices::DQMStreamerReader::checkNext ( )
overrideprotectedvirtual

This is the actual code for checking the new event and/or deserializing it.

Implements edm::RawInputSource.

Definition at line 302 of file DQMStreamerReader.cc.

References closeFileImp_(), edm::StreamerInputSource::deserializeEvent(), MillePedeFileConverter_cfg::e, file_, fiterator_, edm::RawInputSource::kEvent, edm::RawInputSource::kFile, edm::RawInputSource::kStop, dqmservices::DQMFileIterator::logFileAction(), prepareNextEvent(), processedEventPerLs_, dqmservices::DQMStreamerReader::OpenFile::streamFile_, and AlCaHLTBitMon_QueryRunRegistry::string.

302  {
303  try {
304  EventMsgView const* eview = prepareNextEvent();
305  if (eview == nullptr) {
306  if (file_.streamFile_ and file_.streamFile_->newHeader()) {
307  return Next::kFile;
308  }
309  return Next::kStop;
310  }
311 
312  deserializeEvent(*eview);
313  } catch (const cms::Exception& e) {
314  // try to recover from corrupted files/events
315  fiterator_.logFileAction(std::string("Can't deserialize event or registry data: ") + e.what());
316  closeFileImp_("data file corrupted");
317 
318  // this is not optimal, but hopefully we won't catch this many times in a row
319  return checkNext();
320  }
321 
323 
324  return Next::kEvent;
325  }
std::unique_ptr< edm::StreamerInputFile > streamFile_
void deserializeEvent(EventMsgView const &eventView)
void logFileAction(const std::string &msg, const std::string &fileName="") const
EventMsgView const * prepareNextEvent()
void closeFileImp_(const std::string &reason)
struct dqmservices::DQMStreamerReader::OpenFile file_

◆ closeFileImp_()

void dqmservices::DQMStreamerReader::closeFileImp_ ( const std::string &  reason)
private

◆ fillDescriptions()

void dqmservices::DQMStreamerReader::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 401 of file DQMStreamerReader.cc.

References edm::ConfigurationDescriptions::add(), submitPVResolutionJobs::desc, edm::EventSkipperByID::fillDescription(), edm::StreamerInputSource::fillDescription(), and dqmservices::DQMFileIterator::fillDescription().

401  {
403  desc.setComment("Reads events from streamer files.");
404 
405  desc.addUntracked<std::vector<std::string>>("SelectEvents")->setComment("HLT path to select events");
406 
407  desc.addUntracked<int>("minEventsPerLumi", 1)
408  ->setComment(
409  "Minimum number of events to process per lumisection, "
410  "before switching to a new input file. If the next file "
411  "does not yet exist, "
412  "the number of processed events will be bigger.");
413 
414  desc.addUntracked<bool>("skipFirstLumis", false)
415  ->setComment(
416  "Skip (and ignore the minEventsPerLumi parameter) for the files "
417  "which have been available at the begining of the processing. "
418  "If set to true, the reader will open last available file for "
419  "processing.");
420 
421  desc.addUntracked<bool>("deleteDatFiles", false)
422  ->setComment(
423  "Delete data files after they have been closed, in order to "
424  "save disk space.");
425 
426  desc.addUntracked<bool>("endOfRunKills", false)
427  ->setComment(
428  "Kill the processing as soon as the end-of-run file appears, even if "
429  "there are/will be unprocessed lumisections.");
430 
431  // desc.addUntracked<unsigned int>("skipEvents", 0U)
432  // ->setComment("Skip the first 'skipEvents' events that otherwise would "
433  // "have been processed.");
434 
435  // This next parameter is read in the base class, but its default value
436  // depends on the derived class, so it is set here.
437  desc.addUntracked<bool>("inputFileTransitionsEachEvent", false);
438 
442 
443  descriptions.add("source", desc);
444  }
static void fillDescription(ParameterSetDescription &description)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static void fillDescription(ParameterSetDescription &desc)
static void fillDescription(edm::ParameterSetDescription &d)

◆ genuineCloseFile()

void dqmservices::DQMStreamerReader::genuineCloseFile ( )
overrideprotectedvirtual

Reimplemented from edm::RawInputSource.

Definition at line 120 of file DQMStreamerReader.cc.

120 {}

◆ genuineReadFile()

void dqmservices::DQMStreamerReader::genuineReadFile ( )
overrideprotectedvirtual

Reimplemented from edm::RawInputSource.

Definition at line 131 of file DQMStreamerReader.cc.

References edm::StreamerInputSource::deserializeAndMergeWithRegistry(), getHeaderMsg(), RecoTauValidation_cfi::header, and isFirstFile_.

131  {
132  if (isFirstFile_) {
133  //The file was already opened in the constructor
134  isFirstFile_ = false;
135  return;
136  }
137 
138  //Get header/init from reader
139  InitMsgView const* header = getHeaderMsg();
141  }
InitMsgView const * getHeaderMsg()
void deserializeAndMergeWithRegistry(InitMsgView const &initView, bool subsequent=false)

◆ getEventMsg()

EventMsgView const * dqmservices::DQMStreamerReader::getEventMsg ( )
private

Definition at line 180 of file DQMStreamerReader.cc.

References file_, edm::RawInputSource::kFile, edm::RawInputSource::kStop, mps_check::msg, GetRecoTauVFromDQM_MC_cff::next, and dqmservices::DQMStreamerReader::OpenFile::streamFile_.

Referenced by prepareNextEvent().

180  {
181  auto next = file_.streamFile_->next();
183  return nullptr;
184  }
185 
187  return nullptr;
188  }
189 
190  EventMsgView const* msg = file_.streamFile_->currentRecord();
191 
192  // if (msg != nullptr) dumpEventView(msg);
193  return msg;
194  }
std::unique_ptr< edm::StreamerInputFile > streamFile_
tuple msg
Definition: mps_check.py:286
struct dqmservices::DQMStreamerReader::OpenFile file_

◆ getHeaderMsg()

InitMsgView const * dqmservices::DQMStreamerReader::getHeaderMsg ( )
private

Definition at line 169 of file DQMStreamerReader.cc.

References Exception, file_, edm::errors::FileReadError, RecoTauValidation_cfi::header, Header::INIT, and dqmservices::DQMStreamerReader::OpenFile::streamFile_.

Referenced by genuineReadFile(), and openFileImp_().

169  {
170  InitMsgView const* header = file_.streamFile_->startMessage();
171 
172  if (header->code() != Header::INIT) { // INIT Msg
173  throw edm::Exception(edm::errors::FileReadError, "DQMStreamerReader::readHeader")
174  << "received wrong message type: expected INIT, got " << header->code() << "\n";
175  }
176 
177  return header;
178  }
std::unique_ptr< edm::StreamerInputFile > streamFile_
struct dqmservices::DQMStreamerReader::OpenFile file_

◆ newHeader()

bool dqmservices::DQMStreamerReader::newHeader ( )

◆ openFileImp_()

void dqmservices::DQMStreamerReader::openFileImp_ ( const DQMFileIterator::LumiEntry entry)
private

Definition at line 84 of file DQMStreamerReader.cc.

References acceptAllEvt_, edm::StreamerInputSource::deserializeAndMergeWithRegistry(), mps_splice::entry, file_, flagDeleteDatFiles_, getHeaderMsg(), RecoTauValidation_cfi::header, hltSel_, isFirstFile_, dqmservices::DQMStreamerReader::OpenFile::lumi_, castor_dqm_sourceclient_file_cfg::path, processedEventPerLs_, setMatchTriggerSel(), dqmservices::DQMStreamerReader::OpenFile::streamFile_, AlCaHLTBitMon_QueryRunRegistry::string, and triggerSelector_.

Referenced by openNextFileImp_().

84  {
86 
87  std::string path = entry.get_data_path();
88 
89  file_.lumi_ = entry;
90  file_.streamFile_ = std::make_unique<edm::StreamerInputFile>(path);
91 
92  InitMsgView const* header = getHeaderMsg();
93  if (isFirstFile_) {
95  }
96 
97  // dump the list of HLT trigger name from the header
98  // dumpInitHeader(header);
99 
100  // if specific trigger selection is requested, check if the requested triggers match with trigger paths in the header file
101  if (!acceptAllEvt_) {
102  std::vector<std::string> tnames;
103  header->hltTriggerNames(tnames);
104 
105  triggerSelector_.reset(new TriggerSelector(hltSel_, tnames));
106 
107  // check if any trigger path name requested matches with trigger name in the header file
108  setMatchTriggerSel(tnames);
109  }
110 
111  // our initialization
113 
114  if (flagDeleteDatFiles_) {
115  // unlink the file
116  unlink(path.c_str());
117  }
118  }
std::vector< std::string > const hltSel_
InitMsgView const * getHeaderMsg()
std::shared_ptr< TriggerSelector > triggerSelector_
bool setMatchTriggerSel(std::vector< std::string > const &tnames)
std::unique_ptr< edm::StreamerInputFile > streamFile_
void deserializeAndMergeWithRegistry(InitMsgView const &initView, bool subsequent=false)
struct dqmservices::DQMStreamerReader::OpenFile file_

◆ openNextFileImp_()

bool dqmservices::DQMStreamerReader::openNextFileImp_ ( )
private

Definition at line 143 of file DQMStreamerReader.cc.

References closeFileImp_(), MillePedeFileConverter_cfg::e, fiterator_, dqmservices::DQMFileIterator::LumiEntry::get_data_path(), dqmservices::DQMFileIterator::logFileAction(), dqmservices::DQMFileIterator::logLumiState(), dqmservices::DQMFileIterator::open(), openFileImp_(), AlCaHLTBitMon_ParallelJobs::p, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by prepareNextFile().

143  {
144  closeFileImp_("skipping to another file");
145 
146  DQMFileIterator::LumiEntry currentLumi = fiterator_.open();
147  std::string p = currentLumi.get_data_path();
148 
149  if (std::filesystem::exists(p)) {
150  try {
151  openFileImp_(currentLumi);
152  return true;
153  } catch (const cms::Exception& e) {
154  fiterator_.logFileAction(std::string("Can't deserialize registry data (in open file): ") + e.what(), p);
155  fiterator_.logLumiState(currentLumi, "error: data file corrupted");
156 
157  closeFileImp_("data file corrupted");
158  return false;
159  }
160  } else {
161  /* dat file missing */
162  fiterator_.logFileAction("Data file (specified in json) is missing:", p);
163  fiterator_.logLumiState(currentLumi, "error: data file missing");
164 
165  return false;
166  }
167  }
void logLumiState(const LumiEntry &lumi, const std::string &msg)
void openFileImp_(const DQMFileIterator::LumiEntry &entry)
void logFileAction(const std::string &msg, const std::string &fileName="") const
void closeFileImp_(const std::string &reason)

◆ prepareNextEvent()

EventMsgView const * dqmservices::DQMStreamerReader::prepareNextEvent ( )
private

Waits and reads the event header. If end-of-run nullptr is returned.

Definition at line 263 of file DQMStreamerReader.cc.

References acceptEvent(), closeFileImp_(), dqmservices::DQMFileIterator::delay(), file_, fiterator_, getEventMsg(), GetRecoTauVFromDQM_MC_cff::next, dqmservices::DQMStreamerReader::OpenFile::open(), and prepareNextFile().

Referenced by checkNext(), and skip().

263  {
264  EventMsgView const* eview = nullptr;
266 
267  // wait for the next event
268  for (;;) {
269  // edm::LogAbsolute("DQMStreamerReader")
270  // << "State loop.";
271  bool next = prepareNextFile();
272  if (!next)
273  return nullptr;
274 
275  // sleep
276  if (!file_.open()) {
277  // the reader does not exist
278  fiterator_.delay();
279  } else {
280  // our reader exists, try to read out an event
281  eview = getEventMsg();
282 
283  if (eview == nullptr) {
284  // read unsuccessful
285  // this means end of file, so close the file
286  closeFileImp_("eof");
287  } else {
288  if (!acceptEvent(eview)) {
289  continue;
290  } else {
291  return eview;
292  }
293  }
294  }
295  }
296  return eview;
297  }
EventMsgView const * getEventMsg()
bool acceptEvent(const EventMsgView *)
void closeFileImp_(const std::string &reason)
struct dqmservices::DQMStreamerReader::OpenFile file_

◆ prepareNextFile()

bool dqmservices::DQMStreamerReader::prepareNextFile ( )
private

Prepare (open) the next file for reading. It is used by prepareNextEvent and in the constructor.

Does not block/wait.

Return false if this is end of run and/or no more file are available. However, return of "true" does not imply the file has been openned, but we need to wait until some future file becomes available.

Definition at line 206 of file DQMStreamerReader.cc.

References closeFileImp_(), file_, fiterator_, flagEndOfRunKills_, svgfig::load(), dqmservices::DQMFileIterator::logFileAction(), dqmservices::DQMFileIterator::lumiReady(), minEventsPerLs_, dqmservices::DQMStreamerReader::OpenFile::open(), openNextFileImp_(), processedEventPerLs_, edm::shutdown_flag, dqmservices::DQMFileIterator::state(), and dqmservices::DQMFileIterator::update_state().

Referenced by prepareNextEvent(), and reset_().

206  {
208 
209  for (;;) {
211 
212  if (edm::shutdown_flag.load()) {
213  fiterator_.logFileAction("Shutdown flag was set, shutting down.");
214 
215  closeFileImp_("shutdown flag is set");
216  return false;
217  }
218 
219  // check for end of run file and force quit
220  if (flagEndOfRunKills_ && (fiterator_.state() != State::OPEN)) {
221  closeFileImp_("forced end-of-run");
222  return false;
223  }
224 
225  // check for end of run and quit if everything has been processed.
226  // this clean exit
227  if ((!file_.open()) && (!fiterator_.lumiReady()) && (fiterator_.state() == State::EOR)) {
228  return false;
229  }
230 
231  // if this is end of run and no more files to process
232  // close it
234  (fiterator_.state() == State::EOR)) {
235  closeFileImp_("graceful end-of-run");
236  return false;
237  }
238 
239  // skip to the next file if we have no files openned yet
240  if (!file_.open()) {
241  if (fiterator_.lumiReady()) {
243  // we might need to open once more (if .dat is missing)
244  continue;
245  }
246  }
247 
248  // or if there is a next file and enough eventshas been processed.
251  // we might need to open once more (if .dat is missing)
252  continue;
253  }
254 
255  return true;
256  }
257  }
unsigned int const minEventsPerLs_
volatile std::atomic< bool > shutdown_flag
void logFileAction(const std::string &msg, const std::string &fileName="") const
def load(fileName)
Definition: svgfig.py:547
void closeFileImp_(const std::string &reason)
struct dqmservices::DQMStreamerReader::OpenFile file_

◆ reset_()

void dqmservices::DQMStreamerReader::reset_ ( )
overrideprivatevirtual

Reimplemented from edm::RawInputSource.

Definition at line 42 of file DQMStreamerReader.cc.

References dqmservices::DQMFileIterator::advanceToLumi(), dqmservices::DQMFileIterator::delay(), file_, fiterator_, flagSkipFirstLumis_, cmsLHEtoEOSManager::l, dqmservices::DQMFileIterator::lastLumiFound(), dqmservices::DQMFileIterator::logFileAction(), GetRecoTauVFromDQM_MC_cff::next, dqmservices::DQMStreamerReader::OpenFile::open(), prepareNextFile(), and dqmservices::DQMFileIterator::update_state().

Referenced by DQMStreamerReader().

42  {
43  // We have to load at least a single header,
44  // so the ProductRegistry gets initialized.
45  //
46  // This must happen here (inside the constructor),
47  // as ProductRegistry gets frozen after we initialize:
48  // https://cmssdt.cern.ch/SDT/lxr/source/FWCore/Framework/src/Schedule.cc#441
49 
50  fiterator_.logFileAction("Waiting for the first lumi in order to initialize.");
51 
53 
54  // Fast-forward to the last open file.
55  if (flagSkipFirstLumis_) {
56  unsigned int l = fiterator_.lastLumiFound();
57  if (l > 1) {
58  fiterator_.advanceToLumi(l, "skipped: fast-forward to the latest lumi");
59  }
60  }
61 
62  for (;;) {
63  bool next = prepareNextFile();
64 
65  // check for end of run
66  if (!next) {
67  fiterator_.logFileAction("End of run reached before DQMStreamerReader was initialised.");
68  return;
69  }
70 
71  // check if we have a file openned
72  if (file_.open()) {
73  // we are now initialised
74  break;
75  }
76 
77  // wait
78  fiterator_.delay();
79  }
80 
81  fiterator_.logFileAction("DQMStreamerReader initialised.");
82  }
void logFileAction(const std::string &msg, const std::string &fileName="") const
void advanceToLumi(unsigned int lumi, std::string reason)
struct dqmservices::DQMStreamerReader::OpenFile file_

◆ setAcceptAllEvt()

bool dqmservices::DQMStreamerReader::setAcceptAllEvt ( )
private

If hlt trigger selection is '*', return a boolean variable to accept all events

Definition at line 331 of file DQMStreamerReader.cc.

References acceptAllEvt_, HltBtagPostValidation_cff::c, TriggerAnalyzer::hltPath, and hltSel_.

Referenced by DQMStreamerReader().

331  {
332  acceptAllEvt_ = false;
333  for (auto hltPath : hltSel_) {
334  hltPath.erase(std::remove_if(hltPath.begin(), hltPath.end(), [](unsigned char c) { return std::isspace(c); }),
335  hltPath.end());
336  if (hltPath == "*") {
337  acceptAllEvt_ = true;
338  break;
339  }
340  }
341  return acceptAllEvt_;
342  }
std::vector< std::string > const hltSel_

◆ setMatchTriggerSel()

bool dqmservices::DQMStreamerReader::setMatchTriggerSel ( std::vector< std::string > const &  tnames)
private

Check if hlt selection matches any trigger name taken from the header file

Definition at line 347 of file DQMStreamerReader.cc.

References HltBtagPostValidation_cff::c, TriggerAnalyzer::hltPath, hltSel_, oniaPATMuonsWithTrigger_cff::matches, matchTriggerSel_, and edm::regexMatch().

Referenced by openFileImp_().

347  {
348  matchTriggerSel_ = false;
349  for (auto hltPath : hltSel_) {
350  hltPath.erase(std::remove_if(hltPath.begin(), hltPath.end(), [](unsigned char c) { return std::isspace(c); }),
351  hltPath.end());
352  auto const matches = edm::regexMatch(tnames, hltPath);
353  if (not matches.empty()) {
354  matchTriggerSel_ = true;
355  break;
356  }
357  }
358 
359  if (not matchTriggerSel_) {
360  edm::LogWarning("DQMStreamerReader") << "Trigger selection does not match any trigger path!!!";
361  }
362 
363  return matchTriggerSel_;
364  }
std::vector< std::string > const hltSel_
std::vector< std::vector< std::string >::const_iterator > regexMatch(std::vector< std::string > const &strings, std::regex const &regexp)
Definition: RegexMatch.cc:26
Log< level::Warning, false > LogWarning

◆ skip()

void dqmservices::DQMStreamerReader::skip ( int  toSkip)
overrideprotectedvirtual

Reimplemented from edm::InputSource.

Definition at line 385 of file DQMStreamerReader.cc.

References closeFileImp_(), MillePedeFileConverter_cfg::e, fiterator_, mps_fire::i, dqmservices::DQMFileIterator::logFileAction(), prepareNextEvent(), and AlCaHLTBitMon_QueryRunRegistry::string.

385  {
386  try {
387  for (int i = 0; i != toSkip; ++i) {
388  EventMsgView const* evMsg = prepareNextEvent();
389 
390  if (evMsg == nullptr) {
391  return;
392  }
393  }
394  } catch (const cms::Exception& e) {
395  // try to recover from corrupted files/events
396  fiterator_.logFileAction(std::string("Can't deserialize event data: ") + e.what());
397  closeFileImp_("data file corrupted");
398  }
399  }
void logFileAction(const std::string &msg, const std::string &fileName="") const
EventMsgView const * prepareNextEvent()
void closeFileImp_(const std::string &reason)

Member Data Documentation

◆ acceptAllEvt_

bool dqmservices::DQMStreamerReader::acceptAllEvt_ = false
private

Definition at line 62 of file DQMStreamerReader.h.

Referenced by acceptEvent(), openFileImp_(), and setAcceptAllEvt().

◆ eventSkipperByID_

std::shared_ptr<edm::EventSkipperByID> dqmservices::DQMStreamerReader::eventSkipperByID_
private

Definition at line 76 of file DQMStreamerReader.h.

◆ file_

struct dqmservices::DQMStreamerReader::OpenFile dqmservices::DQMStreamerReader::file_
private

◆ fiterator_

DQMFileIterator dqmservices::DQMStreamerReader::fiterator_
private

◆ flagDeleteDatFiles_

bool const dqmservices::DQMStreamerReader::flagDeleteDatFiles_
private

Definition at line 59 of file DQMStreamerReader.h.

Referenced by openFileImp_().

◆ flagEndOfRunKills_

bool const dqmservices::DQMStreamerReader::flagEndOfRunKills_
private

Definition at line 58 of file DQMStreamerReader.h.

Referenced by prepareNextFile().

◆ flagSkipFirstLumis_

bool const dqmservices::DQMStreamerReader::flagSkipFirstLumis_
private

Definition at line 57 of file DQMStreamerReader.h.

Referenced by reset_().

◆ hltSel_

std::vector<std::string> const dqmservices::DQMStreamerReader::hltSel_
private

Definition at line 60 of file DQMStreamerReader.h.

Referenced by openFileImp_(), setAcceptAllEvt(), and setMatchTriggerSel().

◆ isFirstFile_

bool dqmservices::DQMStreamerReader::isFirstFile_ = true
private

Definition at line 49 of file DQMStreamerReader.h.

Referenced by genuineReadFile(), and openFileImp_().

◆ matchTriggerSel_

bool dqmservices::DQMStreamerReader::matchTriggerSel_ = false
private

Definition at line 65 of file DQMStreamerReader.h.

Referenced by acceptEvent(), and setMatchTriggerSel().

◆ minEventsPerLs_

unsigned int const dqmservices::DQMStreamerReader::minEventsPerLs_
private

Definition at line 56 of file DQMStreamerReader.h.

Referenced by prepareNextFile().

◆ mon_

edm::Service<DQMMonitoringService> dqmservices::DQMStreamerReader::mon_
private

Definition at line 80 of file DQMStreamerReader.h.

◆ processedEventPerLs_

unsigned int dqmservices::DQMStreamerReader::processedEventPerLs_ = 0
private

Definition at line 54 of file DQMStreamerReader.h.

Referenced by checkNext(), openFileImp_(), and prepareNextFile().

◆ triggerSelector_

std::shared_ptr<TriggerSelector> dqmservices::DQMStreamerReader::triggerSelector_
private

Definition at line 77 of file DQMStreamerReader.h.

Referenced by acceptEvent(), and openFileImp_().