From 2ff8733ddc8f69e13bb0229394a4c04cc51dba46 Mon Sep 17 00:00:00 2001 From: Dmitrijus Bugelskis Date: Wed, 21 Oct 2015 20:06:49 +0200 Subject: [PATCH] Fix code formatting DQMServices/StreamerIO --- .../StreamerIO/plugins/DQMFileIterator.cc | 45 +- .../StreamerIO/plugins/DQMFileIterator.h | 2 +- .../plugins/DQMMonitoringService.cc | 26 +- .../StreamerIO/plugins/DQMMonitoringService.h | 48 +- .../StreamerIO/plugins/DQMProtobufReader.cc | 50 +- .../StreamerIO/plugins/DQMProtobufReader.h | 10 +- .../StreamerIO/plugins/DQMStreamerReader.cc | 93 +-- .../StreamerIO/plugins/DQMStreamerReader.h | 10 +- .../JsonWritingTimeoutPoolOutputModule.cc | 16 +- .../StreamerIO/plugins/RamdiskMonitor.cc | 137 ++-- .../StreamerIO/plugins/TriggerSelector.cc | 749 +++++++++--------- .../StreamerIO/plugins/TriggerSelector.h | 258 +++--- 12 files changed, 697 insertions(+), 747 deletions(-) diff --git a/DQMServices/StreamerIO/plugins/DQMFileIterator.cc b/DQMServices/StreamerIO/plugins/DQMFileIterator.cc index af19474c13bb0..c916621989add 100644 --- a/DQMServices/StreamerIO/plugins/DQMFileIterator.cc +++ b/DQMServices/StreamerIO/plugins/DQMFileIterator.cc @@ -25,16 +25,16 @@ DQMFileIterator::LumiEntry DQMFileIterator::LumiEntry::load_json( lumi.filename = filename; lumi.n_events_processed = std::next(pt.get_child("data").begin(), 0) - ->second.get_value(); + ->second.get_value(); lumi.n_events_accepted = std::next(pt.get_child("data").begin(), 1) - ->second.get_value(); + ->second.get_value(); lumi.file_ls = lumiNumber; if (datafn_position >= 0) { lumi.datafn = std::next(pt.get_child("data").begin(), datafn_position) - ->second.get_value(); + ->second.get_value(); } return lumi; @@ -60,9 +60,7 @@ DQMFileIterator::EorEntry DQMFileIterator::EorEntry::load_json( return eor; } -DQMFileIterator::DQMFileIterator(edm::ParameterSet const& pset) - : state_(EOR) { - +DQMFileIterator::DQMFileIterator(edm::ParameterSet const& pset) : state_(EOR) { runNumber_ = pset.getUntrackedParameter("runNumber"); datafnPosition_ = pset.getUntrackedParameter("datafnPosition"); runInputDir_ = pset.getUntrackedParameter("runInputDir"); @@ -98,7 +96,6 @@ void DQMFileIterator::reset() { doc.put("fi_state", std::to_string(state_)); mon_->outputUpdate(doc); } - } DQMFileIterator::State DQMFileIterator::state() { return state_; } @@ -154,11 +151,11 @@ void DQMFileIterator::advanceToLumi(unsigned int lumi, std::string reason) { } void DQMFileIterator::monUpdateLumi(const LumiEntry& lumi) { - if (! mon_.isAvailable()) - return; + if (!mon_.isAvailable()) return; ptree doc; - doc.put(str(boost::format("extra.lumi_seen.lumi%06d") % lumi.file_ls), lumi.state); + doc.put(str(boost::format("extra.lumi_seen.lumi%06d") % lumi.file_ls), + lumi.state); mon_->outputUpdate(doc); } @@ -176,7 +173,7 @@ void DQMFileIterator::collect(bool ignoreTimers) { auto now = std::chrono::high_resolution_clock::now(); auto last_ms = std::chrono::duration_cast( - now - runPathLastCollect_).count(); + now - runPathLastCollect_).count(); // don't refresh if it's too soon if ((!ignoreTimers) && (last_ms >= 0) && (last_ms < 100)) { @@ -186,11 +183,12 @@ void DQMFileIterator::collect(bool ignoreTimers) { // check if directory changed std::time_t mtime_now = boost::filesystem::last_write_time(runPath_); - if ((!ignoreTimers) && (last_ms < forceFileCheckTimeoutMillis_) && (mtime_now == runPathMTime_)) { - //logFileAction("Directory hasn't changed."); + if ((!ignoreTimers) && (last_ms < forceFileCheckTimeoutMillis_) && + (mtime_now == runPathMTime_)) { + // logFileAction("Directory hasn't changed."); return; } else { - //logFileAction("Directory changed, updating."); + // logFileAction("Directory changed, updating."); } runPathMTime_ = mtime_now; @@ -298,7 +296,6 @@ void DQMFileIterator::update_state() { if ((state_ != State::EOR) && (nextLumiTimeoutMillis_ >= 0)) { auto iter = lumiSeen_.lower_bound(nextLumiNumber_); if ((iter != lumiSeen_.end()) && iter->first != nextLumiNumber_) { - auto elapsed = high_resolution_clock::now() - lastLumiLoad_; auto elapsed_ms = duration_cast(elapsed).count(); @@ -345,7 +342,8 @@ void DQMFileIterator::logFileAction(const std::string& msg, edm::FlushMessageLog(); } -void DQMFileIterator::logLumiState(const LumiEntry& lumi, const std::string& msg) { +void DQMFileIterator::logLumiState(const LumiEntry& lumi, + const std::string& msg) { if (lumiSeen_.find(lumi.file_ls) != lumiSeen_.end()) { lumiSeen_[lumi.file_ls].state = msg; @@ -356,19 +354,19 @@ void DQMFileIterator::logLumiState(const LumiEntry& lumi, const std::string& msg } void DQMFileIterator::delay() { - if (mon_.isAvailable()) - mon_->keepAlive(); + if (mon_.isAvailable()) mon_->keepAlive(); usleep(delayMillis_ * 1000); } void DQMFileIterator::fillDescription(edm::ParameterSetDescription& desc) { - desc.addUntracked("runNumber") ->setComment("Run number passed via configuration file."); desc.addUntracked("datafnPosition", 3) - ->setComment("Data filename position in the positional arguments array 'data' in json file."); + ->setComment( + "Data filename position in the positional arguments array 'data' in " + "json file."); desc.addUntracked("streamLabel") ->setComment("Stream label used in json discovery."); @@ -376,9 +374,10 @@ void DQMFileIterator::fillDescription(edm::ParameterSetDescription& desc) { desc.addUntracked("delayMillis") ->setComment("Number of milliseconds to wait between file checks."); - desc.addUntracked("nextLumiTimeoutMillis", -1)->setComment( - "Number of milliseconds to wait before switching to the next lumi " - "section if the current is missing, -1 to disable."); + desc.addUntracked("nextLumiTimeoutMillis", -1) + ->setComment( + "Number of milliseconds to wait before switching to the next lumi " + "section if the current is missing, -1 to disable."); desc.addUntracked("runInputDir") ->setComment("Directory where the DQM files will appear."); diff --git a/DQMServices/StreamerIO/plugins/DQMFileIterator.h b/DQMServices/StreamerIO/plugins/DQMFileIterator.h index aed98008486b5..31660bd020fe1 100644 --- a/DQMServices/StreamerIO/plugins/DQMFileIterator.h +++ b/DQMServices/StreamerIO/plugins/DQMFileIterator.h @@ -113,7 +113,7 @@ class DQMFileIterator { std::chrono::high_resolution_clock::time_point lastLumiLoad_; void collect(bool ignoreTimers); - void monUpdateLumi(const LumiEntry& lumi); + void monUpdateLumi(const LumiEntry& lumi); /* this is for monitoring */ edm::Service mon_; diff --git a/DQMServices/StreamerIO/plugins/DQMMonitoringService.cc b/DQMServices/StreamerIO/plugins/DQMMonitoringService.cc index 3e13afb10123a..f2566aec3866d 100644 --- a/DQMServices/StreamerIO/plugins/DQMMonitoringService.cc +++ b/DQMServices/StreamerIO/plugins/DQMMonitoringService.cc @@ -4,7 +4,6 @@ #include #include - #include /* @@ -14,7 +13,8 @@ namespace dqmservices { -DQMMonitoringService::DQMMonitoringService(const edm::ParameterSet &pset, edm::ActivityRegistry& ar) { +DQMMonitoringService::DQMMonitoringService(const edm::ParameterSet& pset, + edm::ActivityRegistry& ar) { const char* x = getenv("DQM2_SOCKET"); if (x) { std::cerr << "Monitoring pipe: " << x << std::endl; @@ -37,13 +37,12 @@ DQMMonitoringService::DQMMonitoringService(const edm::ParameterSet &pset, edm::A ar.watchPreSourceEvent(this, &DQMMonitoringService::evEvent); } -DQMMonitoringService::~DQMMonitoringService() { -} +DQMMonitoringService::~DQMMonitoringService() {} void DQMMonitoringService::outputLumiUpdate() { using std::chrono::duration_cast; using std::chrono::milliseconds; - + auto now = std::chrono::high_resolution_clock::now(); ptree doc; @@ -79,7 +78,6 @@ void DQMMonitoringService::outputLumiUpdate() { } outputUpdate(doc); - } void DQMMonitoringService::evLumi(GlobalContext const& iContext) { @@ -92,7 +90,7 @@ void DQMMonitoringService::evLumi(GlobalContext const& iContext) { lumi_ = iContext.luminosityBlockID().luminosityBlock(); outputLumiUpdate(); - + last_lumi_time_ = std::chrono::high_resolution_clock::now(); last_lumi_nevents_ = nevents_; last_lumi_ = lumi_; @@ -107,8 +105,7 @@ void DQMMonitoringService::outputUpdate(ptree& doc) { using std::chrono::duration_cast; using std::chrono::milliseconds; - if (!mstream_) - return; + if (!mstream_) return; try { last_update_time_ = std::chrono::high_resolution_clock::now(); @@ -122,8 +119,7 @@ void DQMMonitoringService::outputUpdate(ptree& doc) { } void DQMMonitoringService::keepAlive() { - if (!mstream_) - return; + if (!mstream_) return; mstream_ << "\n"; mstream_.flush(); @@ -135,21 +131,19 @@ void DQMMonitoringService::tryUpdate() { using std::chrono::duration_cast; using std::chrono::milliseconds; - if (!mstream_) - return; + if (!mstream_) return; // sometimes we don't see any transition for a very long time // but we still want updates // luckily, keepAlive is called rather often by the input source auto now = std::chrono::high_resolution_clock::now(); auto millis = duration_cast(now - last_update_time_).count(); - if (millis >= (25*1000)) { + if (millis >= (25 * 1000)) { outputLumiUpdate(); } } - -} // end-of-namespace +} // end-of-namespace #include "FWCore/ServiceRegistry/interface/ServiceMaker.h" diff --git a/DQMServices/StreamerIO/plugins/DQMMonitoringService.h b/DQMServices/StreamerIO/plugins/DQMMonitoringService.h index b723881fd954b..4b77c92199f20 100644 --- a/DQMServices/StreamerIO/plugins/DQMMonitoringService.h +++ b/DQMServices/StreamerIO/plugins/DQMMonitoringService.h @@ -42,37 +42,39 @@ using edm::StreamContext; using edm::GlobalContext; class DQMMonitoringService { - public: - DQMMonitoringService(const edm::ParameterSet &, edm::ActivityRegistry&); - ~DQMMonitoringService(); + public: + DQMMonitoringService(const edm::ParameterSet&, edm::ActivityRegistry&); + ~DQMMonitoringService(); - void connect(); - void keepAlive(); + void connect(); + void keepAlive(); - void outputLumiUpdate(); - void outputUpdate(ptree& doc); + void outputLumiUpdate(); + void outputUpdate(ptree& doc); - void evLumi(GlobalContext const&); - void evEvent(StreamID const&); - - void tryUpdate(); + void evLumi(GlobalContext const&); + void evEvent(StreamID const&); - private: - boost::asio::local::stream_protocol::iostream mstream_; + void tryUpdate(); - // global number of events processed - long nevents_; + private: + boost::asio::local::stream_protocol::iostream mstream_; - // time point, number of events and the lumi number at the time we switched to it - unsigned long last_lumi_; // last lumi (we report stats for it, after we switch to the next one) - std::chrono::high_resolution_clock::time_point last_lumi_time_; - std::chrono::high_resolution_clock::time_point last_update_time_; - long last_lumi_nevents_; + // global number of events processed + long nevents_; - unsigned long run_; // current run - unsigned long lumi_; // current lumi + // time point, number of events and the lumi number at the time we switched to + // it + unsigned long last_lumi_; // last lumi (we report stats for it, after we + // switch to the next one) + std::chrono::high_resolution_clock::time_point last_lumi_time_; + std::chrono::high_resolution_clock::time_point last_update_time_; + long last_lumi_nevents_; + + unsigned long run_; // current run + unsigned long lumi_; // current lumi }; -} // end-of-namespace +} // end-of-namespace #endif diff --git a/DQMServices/StreamerIO/plugins/DQMProtobufReader.cc b/DQMServices/StreamerIO/plugins/DQMProtobufReader.cc index 91ee4313de6df..914bebc36d60f 100644 --- a/DQMServices/StreamerIO/plugins/DQMProtobufReader.cc +++ b/DQMServices/StreamerIO/plugins/DQMProtobufReader.cc @@ -9,7 +9,6 @@ using namespace dqmservices; DQMProtobufReader::DQMProtobufReader(edm::ParameterSet const& pset, edm::InputSourceDescription const& desc) : InputSource(pset, desc), fiterator_(pset) { - flagSkipFirstLumis_ = pset.getUntrackedParameter("skipFirstLumis"); flagEndOfRunKills_ = pset.getUntrackedParameter("endOfRunKills"); flagDeleteDatFiles_ = pset.getUntrackedParameter("deleteDatFiles"); @@ -21,7 +20,7 @@ edm::InputSource::ItemType DQMProtobufReader::getNextItemType() { typedef DQMFileIterator::State State; typedef DQMFileIterator::LumiEntry LumiEntry; - //fiterator_.logFileAction("getNextItemType"); + // fiterator_.logFileAction("getNextItemType"); for (;;) { fiterator_.update_state(); @@ -34,28 +33,27 @@ edm::InputSource::ItemType DQMProtobufReader::getNextItemType() { // check for end of run and quit if everything has been processed. // this is the clean exit if ((!fiterator_.lumiReady()) && (fiterator_.state() == State::EOR)) { - return InputSource::IsStop; } // skip to the next file if we have no files openned yet if (fiterator_.lumiReady()) { - return InputSource::IsLumi; } fiterator_.delay(); - // BUG: for an unknown reason it fails after a certain time if we use IsSynchronize state + // BUG: for an unknown reason it fails after a certain time if we use + // IsSynchronize state // comment out in order to block at this level // the only downside is that we cannot Ctrl+C :) - //return InputSource::IsSynchronize; + // return InputSource::IsSynchronize; } // this is unreachable } std::shared_ptr DQMProtobufReader::readRunAuxiliary_() { - //fiterator_.logFileAction("readRunAuxiliary_"); + // fiterator_.logFileAction("readRunAuxiliary_"); edm::RunAuxiliary* aux = new edm::RunAuxiliary( fiterator_.runNumber(), edm::Timestamp(), edm::Timestamp()); @@ -63,7 +61,7 @@ std::shared_ptr DQMProtobufReader::readRunAuxiliary_() { } void DQMProtobufReader::readRun_(edm::RunPrincipal& rpCache) { - //fiterator_.logFileAction("readRun_"); + // fiterator_.logFileAction("readRun_"); rpCache.fillRunPrincipal(processHistoryRegistryForUpdate()); edm::Service store; @@ -75,7 +73,7 @@ void DQMProtobufReader::readRun_(edm::RunPrincipal& rpCache) { std::shared_ptr DQMProtobufReader::readLuminosityBlockAuxiliary_() { - //fiterator_.logFileAction("readLuminosityBlockAuxiliary_"); + // fiterator_.logFileAction("readLuminosityBlockAuxiliary_"); currentLumi_ = fiterator_.open(); edm::LuminosityBlockAuxiliary* aux = new edm::LuminosityBlockAuxiliary( @@ -87,8 +85,7 @@ DQMProtobufReader::readLuminosityBlockAuxiliary_() { void DQMProtobufReader::readLuminosityBlock_( edm::LuminosityBlockPrincipal& lbCache) { - - //fiterator_.logFileAction("readLuminosityBlock_"); + // fiterator_.logFileAction("readLuminosityBlock_"); edm::Service store; edm::Service jr; @@ -122,7 +119,7 @@ void DQMProtobufReader::readLuminosityBlock_( fiterator_.logLumiState(currentLumi_, "closed: ok"); }; -void DQMProtobufReader::readEvent_(edm::EventPrincipal&) {}; +void DQMProtobufReader::readEvent_(edm::EventPrincipal&){}; void DQMProtobufReader::fillDescriptions( edm::ConfigurationDescriptions& descriptions) { @@ -133,19 +130,22 @@ void DQMProtobufReader::fillDescriptions( "files."); edm::ProducerSourceBase::fillDescription(desc); - desc.addUntracked("skipFirstLumis", false)->setComment( - "Skip (and ignore the minEventsPerLumi parameter) for the files " - "which have been available at the begining of the processing. " - "If set to true, the reader will open last available file for " - "processing."); - - desc.addUntracked("deleteDatFiles", false)->setComment( - "Delete data files after they have been closed, in order to " - "save disk space."); - - desc.addUntracked("endOfRunKills", false)->setComment( - "Kill the processing as soon as the end-of-run file appears, even if " - "there are/will be unprocessed lumisections."); + desc.addUntracked("skipFirstLumis", false) + ->setComment( + "Skip (and ignore the minEventsPerLumi parameter) for the files " + "which have been available at the begining of the processing. " + "If set to true, the reader will open last available file for " + "processing."); + + desc.addUntracked("deleteDatFiles", false) + ->setComment( + "Delete data files after they have been closed, in order to " + "save disk space."); + + desc.addUntracked("endOfRunKills", false) + ->setComment( + "Kill the processing as soon as the end-of-run file appears, even if " + "there are/will be unprocessed lumisections."); DQMFileIterator::fillDescription(desc); descriptions.add("source", desc); diff --git a/DQMServices/StreamerIO/plugins/DQMProtobufReader.h b/DQMServices/StreamerIO/plugins/DQMProtobufReader.h index 5558d0a88277c..012857b4f2a3a 100644 --- a/DQMServices/StreamerIO/plugins/DQMProtobufReader.h +++ b/DQMServices/StreamerIO/plugins/DQMProtobufReader.h @@ -13,7 +13,6 @@ namespace dqmservices { class DQMProtobufReader : public edm::InputSource { - public: explicit DQMProtobufReader(edm::ParameterSet const&, edm::InputSourceDescription const&); @@ -24,10 +23,10 @@ class DQMProtobufReader : public edm::InputSource { virtual edm::InputSource::ItemType getNextItemType() override; virtual std::shared_ptr readRunAuxiliary_() override; virtual std::shared_ptr - readLuminosityBlockAuxiliary_() override; + readLuminosityBlockAuxiliary_() override; virtual void readRun_(edm::RunPrincipal& rpCache) override; - virtual void readLuminosityBlock_(edm::LuminosityBlockPrincipal& lbCache) - override; + virtual void readLuminosityBlock_( + edm::LuminosityBlockPrincipal& lbCache) override; virtual void readEvent_(edm::EventPrincipal&) override; void logFileAction(char const* msg, char const* fileName) const; @@ -41,8 +40,7 @@ class DQMProtobufReader : public edm::InputSource { DQMFileIterator fiterator_; DQMFileIterator::LumiEntry currentLumi_; - InputSource::ItemType nextItemType; }; -} // end of namespace +} // end of namespace diff --git a/DQMServices/StreamerIO/plugins/DQMStreamerReader.cc b/DQMServices/StreamerIO/plugins/DQMStreamerReader.cc index 1aa44876bb31a..37beb4bc056c5 100644 --- a/DQMServices/StreamerIO/plugins/DQMStreamerReader.cc +++ b/DQMServices/StreamerIO/plugins/DQMStreamerReader.cc @@ -27,9 +27,7 @@ namespace dqmservices { DQMStreamerReader::DQMStreamerReader(edm::ParameterSet const& pset, edm::InputSourceDescription const& desc) - : StreamerInputSource(pset, desc), - fiterator_(pset) { - + : StreamerInputSource(pset, desc), fiterator_(pset) { runNumber_ = pset.getUntrackedParameter("runNumber"); runInputDir_ = pset.getUntrackedParameter("runInputDir"); hltSel_ = @@ -106,16 +104,17 @@ void DQMStreamerReader::openFile_(const DQMFileIterator::LumiEntry& entry) { // dump the list of HLT trigger name from the header // dumpInitHeader(header); - // if specific trigger selection is requested, check if the requested triggers - // match with trigger paths in the header file - if (!acceptAllEvt_){ + // if specific trigger selection is requested, check if the requested triggers + // match with trigger paths in the header file + if (!acceptAllEvt_) { Strings tnames; header->hltTriggerNames(tnames); - + pset.addParameter("SelectEvents", hltSel_); eventSelector_.reset(new TriggerSelector(pset, tnames)); - // check if any trigger path name requested matches with trigger name in the header file + // check if any trigger path name requested matches with trigger name in the + // header file matchTriggerSel(tnames); } @@ -140,7 +139,7 @@ void DQMStreamerReader::closeFile_(const std::string& reason) { bool DQMStreamerReader::openNextFile_() { closeFile_("skipping to another file"); - DQMFileIterator::LumiEntry currentLumi = fiterator_.open(); + DQMFileIterator::LumiEntry currentLumi = fiterator_.open(); std::string p = fiterator_.make_path(currentLumi.datafn); if (boost::filesystem::exists(p)) { @@ -159,7 +158,8 @@ InitMsgView const* DQMStreamerReader::getHeaderMsg() { InitMsgView const* header = file_.streamFile_->startMessage(); if (header->code() != Header::INIT) { // INIT Msg - throw edm::Exception(edm::errors::FileReadError, "DQMStreamerReader::readHeader") + throw edm::Exception(edm::errors::FileReadError, + "DQMStreamerReader::readHeader") << "received wrong message type: expected INIT, got " << header->code() << "\n"; } @@ -204,7 +204,6 @@ bool DQMStreamerReader::prepareNextFile() { // this clean exit if ((!file_.open()) && (!fiterator_.lumiReady()) && (fiterator_.state() == State::EOR)) { - return false; } @@ -212,7 +211,6 @@ bool DQMStreamerReader::prepareNextFile() { // close it if ((processedEventPerLs_ >= minEventsPerLs_) && (!fiterator_.lumiReady()) && (fiterator_.state() == State::EOR)) { - closeFile_("graceful end-of-run"); return false; } @@ -301,46 +299,48 @@ bool DQMStreamerReader::checkNextEvent() { } /** - * If hlt trigger selection is '*', return a boolean variable to accept all events + * If hlt trigger selection is '*', return a boolean variable to accept all + * events */ bool DQMStreamerReader::triggerSel() { acceptAllEvt_ = false; - for (Strings::const_iterator i(hltSel_.begin()), end(hltSel_.end()); - i!=end; ++i){ + for (Strings::const_iterator i(hltSel_.begin()), end(hltSel_.end()); i != end; + ++i) { std::string hltPath(*i); - boost::erase_all(hltPath, " \t"); + boost::erase_all(hltPath, " \t"); if (hltPath == "*") acceptAllEvt_ = true; } return acceptAllEvt_; } /** - * Check if hlt selection matches any trigger name taken from the header file + * Check if hlt selection matches any trigger name taken from the header file */ bool DQMStreamerReader::matchTriggerSel(Strings const& tnames) { matchTriggerSel_ = false; - for (Strings::const_iterator i(hltSel_.begin()), end(hltSel_.end()); - i!=end; ++i){ + for (Strings::const_iterator i(hltSel_.begin()), end(hltSel_.end()); i != end; + ++i) { std::string hltPath(*i); boost::erase_all(hltPath, " \t"); - std::vector matches = edm::regexMatch(tnames, hltPath); + std::vector matches = + edm::regexMatch(tnames, hltPath); if (!matches.empty()) { matchTriggerSel_ = true; } } if (!matchTriggerSel_) { - edm::LogWarning("Trigger selection does not match any trigger path!!!") << std::endl; + edm::LogWarning("Trigger selection does not match any trigger path!!!") + << std::endl; } return matchTriggerSel_; } /** - * Check the trigger path to accept event + * Check the trigger path to accept event */ bool DQMStreamerReader::acceptEvent(const EventMsgView* evtmsg) { - if (acceptAllEvt_) return true; if (!matchTriggerSel_) return false; @@ -354,7 +354,7 @@ bool DQMStreamerReader::acceptEvent(const EventMsgView* evtmsg) { if (eventSelector_->wantAll() || eventSelector_->acceptEvent(&hltTriggerBits_[0], evtmsg->hltCount())) { return true; - }else{ + } else { return false; } } @@ -371,32 +371,35 @@ void DQMStreamerReader::skip(int toSkip) { void DQMStreamerReader::fillDescriptions( edm::ConfigurationDescriptions& descriptions) { - edm::ParameterSetDescription desc; desc.setComment("Reads events from streamer files."); desc.addUntracked >("SelectEvents") ->setComment("HLT path to select events "); - desc.addUntracked("minEventsPerLumi", 1)->setComment( - "Minimum number of events to process per lumisection, " - "before switching to a new input file. If the next file " - "does not yet exist, " - "the number of processed events will be bigger."); - - desc.addUntracked("skipFirstLumis", false)->setComment( - "Skip (and ignore the minEventsPerLumi parameter) for the files " - "which have been available at the begining of the processing. " - "If set to true, the reader will open last available file for " - "processing."); - - desc.addUntracked("deleteDatFiles", false)->setComment( - "Delete data files after they have been closed, in order to " - "save disk space."); - - desc.addUntracked("endOfRunKills", false)->setComment( - "Kill the processing as soon as the end-of-run file appears, even if " - "there are/will be unprocessed lumisections."); + desc.addUntracked("minEventsPerLumi", 1) + ->setComment( + "Minimum number of events to process per lumisection, " + "before switching to a new input file. If the next file " + "does not yet exist, " + "the number of processed events will be bigger."); + + desc.addUntracked("skipFirstLumis", false) + ->setComment( + "Skip (and ignore the minEventsPerLumi parameter) for the files " + "which have been available at the begining of the processing. " + "If set to true, the reader will open last available file for " + "processing."); + + desc.addUntracked("deleteDatFiles", false) + ->setComment( + "Delete data files after they have been closed, in order to " + "save disk space."); + + desc.addUntracked("endOfRunKills", false) + ->setComment( + "Kill the processing as soon as the end-of-run file appears, even if " + "there are/will be unprocessed lumisections."); // desc.addUntracked("skipEvents", 0U) // ->setComment("Skip the first 'skipEvents' events that otherwise would " @@ -413,7 +416,7 @@ void DQMStreamerReader::fillDescriptions( descriptions.add("source", desc); } -} // end of namespace +} // end of namespace #include "FWCore/Framework/interface/InputSourceMacros.h" #include "FWCore/Framework/interface/MakerMacros.h" diff --git a/DQMServices/StreamerIO/plugins/DQMStreamerReader.h b/DQMServices/StreamerIO/plugins/DQMStreamerReader.h index 202e58040450b..53d1adc4c1d56 100644 --- a/DQMServices/StreamerIO/plugins/DQMStreamerReader.h +++ b/DQMServices/StreamerIO/plugins/DQMStreamerReader.h @@ -51,8 +51,8 @@ class DQMStreamerReader : public edm::StreamerInputSource { EventMsgView const* prepareNextEvent(); bool prepareNextFile(); - bool acceptEvent( const EventMsgView*); - + bool acceptEvent(const EventMsgView*); + bool triggerSel(); bool matchTriggerSel(Strings const& tnames); bool acceptAllEvt_; @@ -76,9 +76,7 @@ class DQMStreamerReader : public edm::StreamerInputSource { std::unique_ptr streamFile_; DQMFileIterator::LumiEntry lumi_; - bool open() { - return (streamFile_.get() != nullptr); - } + bool open() { return (streamFile_.get() != nullptr); } } file_; @@ -89,6 +87,6 @@ class DQMStreamerReader : public edm::StreamerInputSource { edm::Service mon_; }; -} //end-of-namespace-def +} // end-of-namespace-def #endif diff --git a/DQMServices/StreamerIO/plugins/JsonWritingTimeoutPoolOutputModule.cc b/DQMServices/StreamerIO/plugins/JsonWritingTimeoutPoolOutputModule.cc index b681ebda54947..00ddb9020d6b7 100644 --- a/DQMServices/StreamerIO/plugins/JsonWritingTimeoutPoolOutputModule.cc +++ b/DQMServices/StreamerIO/plugins/JsonWritingTimeoutPoolOutputModule.cc @@ -39,8 +39,8 @@ JsonWritingTimeoutPoolOutputModule::physicalAndLogicalNameForNewFile() { void JsonWritingTimeoutPoolOutputModule::doExtrasAfterCloseFile() { std::string json_tmp_ = currentJsonName_ + ".open"; std::string transferDest = ""; - auto pt = - DQMFileSaver::fillJson(runNumber_, sequence_, currentFileName_, transferDest, nullptr); + auto pt = DQMFileSaver::fillJson(runNumber_, sequence_, currentFileName_, + transferDest, nullptr); write_json(json_tmp_, pt); rename(json_tmp_.c_str(), currentJsonName_.c_str()); } @@ -55,11 +55,15 @@ void JsonWritingTimeoutPoolOutputModule::fillDescriptions( "follow the FFF naming convention. Additionally a json 'description' " "file is emitted for every .root file written."); - desc.addUntracked("runNumber", 0)->setComment( - "The run number, only used for file prefix: 'run000001_lumi0000_...'."); + desc.addUntracked("runNumber", 0) + ->setComment( + "The run number, only used for file prefix: " + "'run000001_lumi0000_...'."); - desc.addUntracked("outputPath", "./")->setComment( - "Output path for the root and json files, usually the run directory."); + desc.addUntracked("outputPath", "./") + ->setComment( + "Output path for the root and json files, usually the run " + "directory."); desc.addUntracked("streamLabel", "streamEvDOutput") ->setComment("Stream label, used for file suffix."); diff --git a/DQMServices/StreamerIO/plugins/RamdiskMonitor.cc b/DQMServices/StreamerIO/plugins/RamdiskMonitor.cc index 481bf62d3a7de..fc834f9a96c9c 100644 --- a/DQMServices/StreamerIO/plugins/RamdiskMonitor.cc +++ b/DQMServices/StreamerIO/plugins/RamdiskMonitor.cc @@ -35,9 +35,11 @@ class RamdiskMonitor : public DQMEDAnalyzer { edm::EventSetup const &) override; virtual void beginLuminosityBlock(edm::LuminosityBlock const &lumi, edm::EventSetup const &eSetup) override; - virtual void analyze(edm::Event const& e, edm::EventSetup const& eSetup) override {}; + virtual void analyze(edm::Event const &e, + edm::EventSetup const &eSetup) override{}; - void analyzeFile(std::string fn, unsigned int run, unsigned int lumi, std::string label); + void analyzeFile(std::string fn, unsigned int run, unsigned int lumi, + std::string label); double getRunTimestamp(); unsigned int runNumber_; @@ -68,11 +70,10 @@ RamdiskMonitor::RamdiskMonitor(const edm::ParameterSet &ps) { ps.getUntrackedParameter >("streamLabels"); }; -RamdiskMonitor::~RamdiskMonitor() {}; +RamdiskMonitor::~RamdiskMonitor(){}; void RamdiskMonitor::bookHistograms(DQMStore::IBooker &ib, edm::Run const &, - edm::EventSetup const &) { - + edm::EventSetup const &) { runPath_ = str(boost::format("%s/run%06d") % runInputDir_ % runNumber_); for (auto stream : streamLabels_) { @@ -83,10 +84,16 @@ void RamdiskMonitor::bookHistograms(DQMStore::IBooker &ib, edm::Run const &, StreamME m; - m.eventsAccepted = ib.book1D("EventAccepted", "# of accepted events per lumi", 4, 0., 4.); - m.eventsProcessed = ib.book1D("EventProcessed", "# of processed events per lumi", 4, 0., 4.); - m.deliveryDelayMTime = ib.book1D("DeliveryDelayMTime", "Observed delivery delay for the data file (mtime).", 4, 0., 4.); - m.deliveryDelayCTime = ib.book1D("DeliveryDelayCTime", "Observed delivery delay for the data file (ctime).", 4, 0., 4.); + m.eventsAccepted = + ib.book1D("EventAccepted", "# of accepted events per lumi", 4, 0., 4.); + m.eventsProcessed = ib.book1D("EventProcessed", + "# of processed events per lumi", 4, 0., 4.); + m.deliveryDelayMTime = ib.book1D( + "DeliveryDelayMTime", + "Observed delivery delay for the data file (mtime).", 4, 0., 4.); + m.deliveryDelayCTime = ib.book1D( + "DeliveryDelayCTime", + "Observed delivery delay for the data file (ctime).", 4, 0., 4.); m.eventsAccepted->getTH1F()->SetCanExtend(TH1::kXaxis); m.eventsProcessed->getTH1F()->SetCanExtend(TH1::kXaxis); @@ -108,74 +115,73 @@ void RamdiskMonitor::bookHistograms(DQMStore::IBooker &ib, edm::Run const &, }; double RamdiskMonitor::getRunTimestamp() { - if (global_start_ != 0) - return global_start_; - - std::string run_global = str(boost::format("%s/.run%06d.global") % runInputDir_ % runNumber_); - struct stat st; - if (::stat(run_global.c_str(), &st) != 0) { - edm::LogWarning("RamdiskMonitor") << "Stat failed: " << run_global; - return 0.; - } - - global_start_ = st.st_mtime; - edm::LogPrint("RamdiskMonitor") << "Run start timestamp: " << global_start_; - return global_start_; + if (global_start_ != 0) return global_start_; + + std::string run_global = + str(boost::format("%s/.run%06d.global") % runInputDir_ % runNumber_); + struct stat st; + if (::stat(run_global.c_str(), &st) != 0) { + edm::LogWarning("RamdiskMonitor") << "Stat failed: " << run_global; + return 0.; + } + + global_start_ = st.st_mtime; + edm::LogPrint("RamdiskMonitor") << "Run start timestamp: " << global_start_; + return global_start_; }; -void RamdiskMonitor::analyzeFile(std::string fn, unsigned int run, unsigned int lumi, std::string label) { - using LumiEntry = dqmservices::DQMFileIterator::LumiEntry; +void RamdiskMonitor::analyzeFile(std::string fn, unsigned int run, + unsigned int lumi, std::string label) { + using LumiEntry = dqmservices::DQMFileIterator::LumiEntry; - // we are disabled, at least for this stream - if (streams_.size() == 0) - return; + // we are disabled, at least for this stream + if (streams_.size() == 0) return; - if (streams_.find(label) == streams_.end()) { - edm::LogPrint("RamdiskMonitor") << "Stream not monitored [" << label<< "]: " << fn; - return; - } + if (streams_.find(label) == streams_.end()) { + edm::LogPrint("RamdiskMonitor") << "Stream not monitored [" << label + << "]: " << fn; + return; + } - StreamME m = streams_[label]; + StreamME m = streams_[label]; - // decode json and fill in some histograms - LumiEntry lumi_jsn = LumiEntry::load_json(fn, lumi, -1); - m.eventsAccepted->setBinContent(lumi, lumi_jsn.n_events_accepted); - m.eventsProcessed->setBinContent(lumi, lumi_jsn.n_events_processed); + // decode json and fill in some histograms + LumiEntry lumi_jsn = LumiEntry::load_json(fn, lumi, -1); + m.eventsAccepted->setBinContent(lumi, lumi_jsn.n_events_accepted); + m.eventsProcessed->setBinContent(lumi, lumi_jsn.n_events_processed); - // collect stat struct and calculate mtimes - struct stat st; - if (::stat(fn.c_str(), &st) != 0) { - edm::LogWarning("RamdiskMonitor") << "Stat failed: " << fn; - return; - } + // collect stat struct and calculate mtimes + struct stat st; + if (::stat(fn.c_str(), &st) != 0) { + edm::LogWarning("RamdiskMonitor") << "Stat failed: " << fn; + return; + } - // get start offset (from .global) - // abort the calculation if it does not exist - double start_offset = getRunTimestamp(); - if (start_offset <= 0) - return; + // get start offset (from .global) + // abort the calculation if it does not exist + double start_offset = getRunTimestamp(); + if (start_offset <= 0) return; - // check fff_dqmtools (separate repository) - // for calculation details - double mtime = st.st_mtime; - double ctime = st.st_ctime; + // check fff_dqmtools (separate repository) + // for calculation details + double mtime = st.st_mtime; + double ctime = st.st_ctime; - // timeout from the begging of the run - double start_offset_mtime = mtime - start_offset - LUMI; - double start_offset_ctime = ctime - start_offset - LUMI; - double lumi_offset = (lumi - 1) * LUMI; + // timeout from the begging of the run + double start_offset_mtime = mtime - start_offset - LUMI; + double start_offset_ctime = ctime - start_offset - LUMI; + double lumi_offset = (lumi - 1) * LUMI; - // timeout from the time we think this lumi happenned - double delay_mtime = start_offset_mtime - lumi_offset; - double delay_ctime = start_offset_ctime - lumi_offset; + // timeout from the time we think this lumi happenned + double delay_mtime = start_offset_mtime - lumi_offset; + double delay_ctime = start_offset_ctime - lumi_offset; - m.deliveryDelayMTime->setBinContent(lumi, delay_mtime); - m.deliveryDelayCTime->setBinContent(lumi, delay_ctime); + m.deliveryDelayMTime->setBinContent(lumi, delay_mtime); + m.deliveryDelayCTime->setBinContent(lumi, delay_ctime); }; void RamdiskMonitor::beginLuminosityBlock(edm::LuminosityBlock const &lumi, - edm::EventSetup const &eSetup) { - + edm::EventSetup const &eSetup) { // search filesystem to find available lumi section files auto now = std::chrono::high_resolution_clock::now(); runPathLastCollect_ = now; @@ -212,7 +218,7 @@ void RamdiskMonitor::beginLuminosityBlock(edm::LuminosityBlock const &lumi, try { this->analyzeFile(fn, run, lumi, label); - } catch (const std::exception& e) { + } catch (const std::exception &e) { // it's likely we have read it too soon filesSeen_.erase(filename); @@ -227,8 +233,7 @@ void RamdiskMonitor::beginLuminosityBlock(edm::LuminosityBlock const &lumi, // @TODO lookup info for the current lumi }; -void RamdiskMonitor::fillDescriptions( - edm::ConfigurationDescriptions &d) { +void RamdiskMonitor::fillDescriptions(edm::ConfigurationDescriptions &d) { edm::ParameterSetDescription desc; desc.setComment( @@ -247,7 +252,7 @@ void RamdiskMonitor::fillDescriptions( d.add("RamdiskMonitor", desc); } -} // end of namespace +} // end of namespace #include "FWCore/Framework/interface/MakerMacros.h" diff --git a/DQMServices/StreamerIO/plugins/TriggerSelector.cc b/DQMServices/StreamerIO/plugins/TriggerSelector.cc index 0a86fd8aaf4e3..8e2344000facb 100644 --- a/DQMServices/StreamerIO/plugins/TriggerSelector.cc +++ b/DQMServices/StreamerIO/plugins/TriggerSelector.cc @@ -9,448 +9,405 @@ #include #include -namespace dqmservices -{ - - //compatibility constructor - - TriggerSelector::TriggerSelector - ( - Strings const& pathspecs, - Strings const& names - ): - useOld_(true) - { - acceptAll_=false; - eventSelector_.reset( new edm::EventSelector(pathspecs,names)); +namespace dqmservices { + +// compatibility constructor + +TriggerSelector::TriggerSelector(Strings const& pathspecs, Strings const& names) + : useOld_(true) { + acceptAll_ = false; + eventSelector_.reset(new edm::EventSelector(pathspecs, names)); +} + +TriggerSelector::TriggerSelector(edm::ParameterSet const& config, + Strings const& triggernames, bool old_) + : useOld_(old_) { + acceptAll_ = false; + if (old_) { + // old mode forced + acceptAll_ = false; + eventSelector_.reset(new edm::EventSelector(config, triggernames)); + return; } - - TriggerSelector::TriggerSelector - ( - edm::ParameterSet const& config, - Strings const& triggernames, - bool old_ - ): - useOld_(old_) - { - acceptAll_=false; - if (old_) { - //old mode forced - acceptAll_=false; - eventSelector_.reset( new edm::EventSelector(config, triggernames)); - return; - } - if (!config.empty()) { - //let's see if non empty TriggerSelector is present - try { - std::string myPath = trim(config.getParameter("TriggerSelector")); - if (!myPath.empty()) { - init(myPath, triggernames); - return; - } + if (!config.empty()) { + // let's see if non empty TriggerSelector is present + try { + std::string myPath = + trim(config.getParameter("TriggerSelector")); + if (!myPath.empty()) { + init(myPath, triggernames); + return; } - catch(...) {} - - //now try with the SelectEvents - try { - Strings paths; - paths = config.getParameter("SelectEvents"); - if (!paths.empty()) { - useOld_=true; - eventSelector_.reset( new edm::EventSelector(config, triggernames)); - return; - } + } catch (...) { + } + + // now try with the SelectEvents + try { + Strings paths; + paths = config.getParameter("SelectEvents"); + if (!paths.empty()) { + useOld_ = true; + eventSelector_.reset(new edm::EventSelector(config, triggernames)); + return; } - catch(...) {} + } catch (...) { } - //if selection parameters aren't present, don't do selection - //log - acceptAll_=true; } - - TriggerSelector::TriggerSelector - ( - std::string const & expression, - Strings const& triggernames - ): - useOld_(false) - { - init (trim(expression),triggernames); + // if selection parameters aren't present, don't do selection + // log + acceptAll_ = true; +} + +TriggerSelector::TriggerSelector(std::string const& expression, + Strings const& triggernames) + : useOld_(false) { + init(trim(expression), triggernames); +} + +void TriggerSelector::init(std::string const& expression, + Strings const& triggernames) { + // debug_ = true; + if (expression.empty()) { + acceptAll_ = true; + return; } + if (expression.size() == 1 && expression.at(0) == '*') + acceptAll_ = true; + else + acceptAll_ = false; - void - TriggerSelector::init - ( - std::string const& expression, - Strings const& triggernames - ) + // replace all possible alternate operators (.AND. and .OR.) { - //debug_ = true; - if (expression.empty()) - { - acceptAll_ = true; - return; - } - if (expression.size()==1 && expression.at(0)=='*') acceptAll_=true; - else acceptAll_=false; - - //replace all possible alternate operators (.AND. and .OR.) - { - using namespace boost; - std::string temp; - temp = regex_replace( expression , regex(".AND."), "&&"); - expression_ = regex_replace( temp, regex(".and."), "&&"); - temp = regex_replace( expression_, regex(".OR."), "||"); - expression_ = regex_replace( temp, regex(".or."), "||"); - } - - //build decision tree - masterElement_.reset( new TreeElement(expression_,triggernames)); + using namespace boost; + std::string temp; + temp = regex_replace(expression, regex(".AND."), "&&"); + expression_ = regex_replace(temp, regex(".and."), "&&"); + temp = regex_replace(expression_, regex(".OR."), "||"); + expression_ = regex_replace(temp, regex(".or."), "||"); } - /* - Obsolete - */ - std::vector - TriggerSelector::getEventSelectionVString(edm::ParameterSet const& pset) - { - return edm::EventSelector::getEventSelectionVString(pset); + // build decision tree + masterElement_.reset(new TreeElement(expression_, triggernames)); +} + +/* + Obsolete +*/ +std::vector TriggerSelector::getEventSelectionVString( + edm::ParameterSet const& pset) { + return edm::EventSelector::getEventSelectionVString(pset); +} + +bool TriggerSelector::acceptEvent(edm::TriggerResults const& tr) const { + if (useOld_) { + return eventSelector_->acceptEvent(tr); } - bool TriggerSelector::acceptEvent(edm::TriggerResults const& tr) const - { - if (useOld_) { - return eventSelector_->acceptEvent(tr); + if (acceptAll_) return true; + + return masterElement_->returnStatus(tr); +} + +bool TriggerSelector::acceptEvent(unsigned char const* array_of_trigger_results, + int number_of_trigger_paths) const { + if (useOld_) + return eventSelector_->acceptEvent(array_of_trigger_results, + number_of_trigger_paths); + + if (acceptAll_) return true; + + // Form HLTGlobalStatus object to represent the array_of_trigger_results + edm::HLTGlobalStatus tr(number_of_trigger_paths); + int byteIndex = 0; + int subIndex = 0; + for (int pathIndex = 0; pathIndex < number_of_trigger_paths; ++pathIndex) { + int state = array_of_trigger_results[byteIndex] >> (subIndex * 2); + state &= 0x3; + edm::HLTPathStatus pathStatus(static_cast(state)); + tr[pathIndex] = pathStatus; + ++subIndex; + if (subIndex == 4) { + ++byteIndex; + subIndex = 0; } - - if (acceptAll_) return true; - - return masterElement_->returnStatus(tr); } - - bool - TriggerSelector::acceptEvent - ( - unsigned char const* array_of_trigger_results, - int number_of_trigger_paths - ) const - { - if (useOld_) - return eventSelector_->acceptEvent(array_of_trigger_results,number_of_trigger_paths); - - if (acceptAll_) return true; - - // Form HLTGlobalStatus object to represent the array_of_trigger_results - edm::HLTGlobalStatus tr(number_of_trigger_paths); - int byteIndex = 0; - int subIndex = 0; - for (int pathIndex = 0; pathIndex < number_of_trigger_paths; ++pathIndex) - { - int state = array_of_trigger_results[byteIndex] >> (subIndex * 2); - state &= 0x3; - edm::HLTPathStatus pathStatus(static_cast(state)); - tr[pathIndex] = pathStatus; - ++subIndex; - if (subIndex == 4) - { ++byteIndex; - subIndex = 0; - } - } - // Now make the decision, based on the HLTGlobalStatus tr, - // which we have created from the supplied array of results - masterElement_->returnStatus(tr); - return masterElement_->returnStatus(tr); - } - - - TriggerSelector::TreeElement::TreeElement - ( - std::string const& inputString, - Strings const& tr, - TreeElement* parentElement - ) : - op_(NonInit), - trigBit_(-1) - { - std::string str_ = trim(inputString); - children_.clear(); - parent_ = parentElement; - - size_t offset_=0; - bool occurrences_=false; - - if (str_.empty()) - throw edm::Exception(edm::errors::Configuration) + // Now make the decision, based on the HLTGlobalStatus tr, + // which we have created from the supplied array of results + masterElement_->returnStatus(tr); + return masterElement_->returnStatus(tr); +} + +TriggerSelector::TreeElement::TreeElement(std::string const& inputString, + Strings const& tr, + TreeElement* parentElement) + : op_(NonInit), trigBit_(-1) { + std::string str_ = trim(inputString); + children_.clear(); + parent_ = parentElement; + + size_t offset_ = 0; + bool occurrences_ = false; + + if (str_.empty()) + throw edm::Exception(edm::errors::Configuration) << "Syntax Error (empty element)" << std::endl; - static const size_t bopsSize_ = 2; - static const std::string binaryOperators_[bopsSize_] = {"||","&&"}; - - for (size_t opr=0;opr=str_.size()) - throw edm::Exception(edm::errors::Configuration) << "Syntax Error (operator is not unary)\n"; - else { - //count bracket in preceeding part - size_t brackets_=0; - for (size_t k=offset_;k= str_.size()) + throw edm::Exception(edm::errors::Configuration) + << "Syntax Error (operator is not unary)\n"; + else { + // count bracket in preceeding part + size_t brackets_ = 0; + for (size_t k = offset_; k < t_end_; k++) { + if (str_.at(k) == '(') { + brackets_++; + } else if (str_.at(k) == ')') { + if (brackets_ == 0) { + throw edm::Exception(edm::errors::Configuration) + << "Syntax Error (brackets)\n"; + } else { + brackets_--; } - else if (str_.at(k)==')') - { - if (brackets_ == 0) - { + } + } + if (brackets_ == 0) { + std::string next = str_.substr(offset_, t_end_ - offset_); + children_.push_back(new TreeElement(next, tr, this)); + occurrences_ = true; + offset_ = t_end_ + 2; + } else { + // operator is inside brackets, find another + int bracketcnt_ = 0; + for (size_t k = offset_; true; k++) { + if (k >= str_.size()) { + if (bracketcnt_ != 0) throw edm::Exception(edm::errors::Configuration) - << "Syntax Error (brackets)\n"; - } - else - { - brackets_--; + << "Syntax Error (brackets)\n"; + exitloop_ = true; + if (occurrences_) { + children_.push_back( + new TreeElement(str_.substr(offset_), tr, this)); } + break; } - } - if (brackets_==0) { - std::string next = str_.substr(offset_,t_end_-offset_); - children_.push_back(new TreeElement(next,tr,this)); - occurrences_=true; - offset_ = t_end_+2; - } - else { - //operator is inside brackets, find another - int bracketcnt_ = 0; - for (size_t k=offset_;true;k++) { - if (k>=str_.size()) { - if (bracketcnt_!=0) - throw edm::Exception(edm::errors::Configuration) - << "Syntax Error (brackets)\n"; - exitloop_=true; - if (occurrences_) { - children_.push_back(new TreeElement(str_.substr(offset_),tr,this)); - } - break; - } - //look for another operator - if (k>=t_end_+2 && bracketcnt_==0) { - std::string temp = str_.substr(k); - size_t pos = temp.find(binaryOperators_[opr]); - if (pos == std::string::npos) { - exitloop_=true; - if (occurrences_) { - children_.push_back(new TreeElement(str_.substr(offset_),tr,this)); - } - break; - } - else { - int brcount_ = 0; - for (size_t s=0;s= t_end_ + 2 && bracketcnt_ == 0) { + std::string temp = str_.substr(k); + size_t pos = temp.find(binaryOperators_[opr]); + if (pos == std::string::npos) { + exitloop_ = true; + if (occurrences_) { + children_.push_back( + new TreeElement(str_.substr(offset_), tr, this)); + } + break; + } else { + int brcount_ = 0; + for (size_t s = 0; s < pos; s++) { + // counting check of brackets from last position to operator + if (temp.at(pos) == '(') { + brcount_++; + } else if (temp.at(pos) == ')') { + if (brcount_ == 0) { + throw edm::Exception(edm::errors::Configuration) << "Syntax error (brackets)\n"; - } - else - { - brcount_--; - } + } else { + brcount_--; } - } - if (brcount_!=0) - throw edm::Exception(edm::errors::Configuration) - << "Syntax error (brackets)\n"; - - children_.push_back(new TreeElement(str_.substr(offset_,pos+k),tr,this)); - offset_=k+pos+2; - occurrences_=true; - if (offset_>=str_.size()) - throw edm::Exception(edm::errors::Configuration) - << "Syntax Error (operator is not unary)\n"; - break; - } - - } - - - if (str_.at(k)=='(') bracketcnt_++; - if (str_.at(k)==')') bracketcnt_--; - - } - } - } + } + } + if (brcount_ != 0) + throw edm::Exception(edm::errors::Configuration) + << "Syntax error (brackets)\n"; + + children_.push_back( + new TreeElement(str_.substr(offset_, pos + k), tr, this)); + offset_ = k + pos + 2; + occurrences_ = true; + if (offset_ >= str_.size()) + throw edm::Exception(edm::errors::Configuration) + << "Syntax Error (operator is not unary)\n"; + break; + } + } - } - if (occurrences_) { - if (opr==0) op_=OR; - else op_=AND; - return; + if (str_.at(k) == '(') bracketcnt_++; + if (str_.at(k) == ')') bracketcnt_--; + } + } } } - - if (str_.empty()) { - op_=AND; - if (debug_) std::cout << "warning: empty element (will return true)"<< std::endl; + if (occurrences_) { + if (opr == 0) + op_ = OR; + else + op_ = AND; return; } + } - if (str_.at(0)=='!') { - op_=NOT; - std::string next = str_.substr(1); - children_.push_back(new TreeElement(next,tr,this)); - return; - } - size_t beginBlock_ =str_.find('('); - size_t endBlock_ =str_.rfind(')'); - bool found_lbracket = (beginBlock_ != std::string::npos); - bool found_rbracket = (endBlock_ != std::string::npos); + if (str_.empty()) { + op_ = AND; + if (debug_) + std::cout << "warning: empty element (will return true)" << std::endl; + return; + } - if (found_lbracket != found_rbracket) { - throw edm::Exception(edm::errors::Configuration) << "Syntax Error (brackets)\n"; + if (str_.at(0) == '!') { + op_ = NOT; + std::string next = str_.substr(1); + children_.push_back(new TreeElement(next, tr, this)); + return; + } + size_t beginBlock_ = str_.find('('); + size_t endBlock_ = str_.rfind(')'); + bool found_lbracket = (beginBlock_ != std::string::npos); + bool found_rbracket = (endBlock_ != std::string::npos); + + if (found_lbracket != found_rbracket) { + throw edm::Exception(edm::errors::Configuration) + << "Syntax Error (brackets)\n"; + } else if (found_lbracket && found_rbracket) { + if (beginBlock_ >= endBlock_) { + throw edm::Exception(edm::errors::Configuration) + << "Syntax Error (brackets)\n"; } - else if (found_lbracket && found_rbracket) - { - if (beginBlock_>=endBlock_) { - throw edm::Exception(edm::errors::Configuration) << "Syntax Error (brackets)\n"; - } - if (beginBlock_!=0 || endBlock_!=str_.size()-1) - throw edm::Exception(edm::errors::Configuration) << "Syntax Error (invalid character)\n"; + if (beginBlock_ != 0 || endBlock_ != str_.size() - 1) + throw edm::Exception(edm::errors::Configuration) + << "Syntax Error (invalid character)\n"; - std::string next = str_.substr(beginBlock_+1,endBlock_-beginBlock_-1); + std::string next = + str_.substr(beginBlock_ + 1, endBlock_ - beginBlock_ - 1); - children_.push_back(new TreeElement(next,tr,this)); - op_=BR; //a bracket - return; + children_.push_back(new TreeElement(next, tr, this)); + op_ = BR; // a bracket + return; + } else if (!found_lbracket && + !found_rbracket) // assume single trigger or wildcard (parsing) + { + bool ignore_if_missing = true; + size_t chr_pos = str_.find("@"); + if (chr_pos != std::string::npos) { + ignore_if_missing = false; + str_ = str_.substr(0, chr_pos); } - else if (!found_lbracket && !found_rbracket) //assume single trigger or wildcard (parsing) - { - bool ignore_if_missing = true; - size_t chr_pos = str_.find("@"); - if (chr_pos!= std::string::npos) { - ignore_if_missing=false; - str_=str_.substr(0,chr_pos); - } - std::vector matches = edm::regexMatch(tr,str_); - if (matches.empty()) { - if (!ignore_if_missing)// && !edm::is_glob(str_)) - throw edm::Exception(edm::errors::Configuration) << "Trigger name (or match) not present" << std::endl; - else { - if (debug_) - std::cout << "TriggerSelector: Couldn't match any triggers from: "<< str_<< std::endl - << " Node will not be added "<< std::endl; - op_=OR; - return; - } - } - if (matches.size()==1) { - //Single Trigger match - trigBit_ = distance(tr.begin(),matches[0]); - if (debug_) std::cout << "added trigger path: " << trigBit_ << std::endl; - return; - } - if (matches.size()>1) { - op_=OR; - for (size_t l=0;l matches = edm::regexMatch(tr, str_); + if (matches.empty()) { + if (!ignore_if_missing) // && !edm::is_glob(str_)) + throw edm::Exception(edm::errors::Configuration) + << "Trigger name (or match) not present" << std::endl; + else { + if (debug_) + std::cout << "TriggerSelector: Couldn't match any triggers from: " + << str_ << std::endl + << " Node will not be added " << std::endl; + op_ = OR; + return; } } - } - - std::string TriggerSelector::trim(std::string input) - { - if (!input.empty()) - { - std::string::size_type pos = input.find_first_not_of(" "); - if (pos != std::string::npos) - input.erase(0,pos); - - pos = input.find_last_not_of(" "); - if (pos != std::string::npos) - input.erase(pos+1); + if (matches.size() == 1) { + // Single Trigger match + trigBit_ = distance(tr.begin(), matches[0]); + if (debug_) std::cout << "added trigger path: " << trigBit_ << std::endl; + return; } - return input; - } - - std::string TriggerSelector::makeXMLString(std::string const& input) - { - std::string output; - if (!input.empty()) { - for (size_t pos=0;pos 1) { + op_ = OR; + for (size_t l = 0; l < matches.size(); l++) + children_.push_back(new TreeElement(*(matches[l]), tr, this)); } - return output; } +} +std::string TriggerSelector::trim(std::string input) { + if (!input.empty()) { + std::string::size_type pos = input.find_first_not_of(" "); + if (pos != std::string::npos) input.erase(0, pos); - bool TriggerSelector::TreeElement::returnStatus - ( - edm::HLTGlobalStatus const& trStatus - ) const - { - - if (children_.empty()) { + pos = input.find_last_not_of(" "); + if (pos != std::string::npos) input.erase(pos + 1); + } + return input; +} + +std::string TriggerSelector::makeXMLString(std::string const& input) { + std::string output; + if (!input.empty()) { + for (size_t pos = 0; pos < input.size(); pos++) { + char ch = input.at(pos); + if (ch == '&') + output.append("&"); + else + output.append(1, ch); + } + } + return output; +} - if (op_==OR || op_==NOT) return false; - if (op_==AND || op_==BR) return true; +bool TriggerSelector::TreeElement::returnStatus( + edm::HLTGlobalStatus const& trStatus) const { + if (children_.empty()) { + if (op_ == OR || op_ == NOT) return false; + if (op_ == AND || op_ == BR) return true; - if (trigBit_<0 || (unsigned int)trigBit_>=trStatus.size()) - throw edm::Exception(edm::errors::Configuration) + if (trigBit_ < 0 || (unsigned int)trigBit_ >= trStatus.size()) + throw edm::Exception(edm::errors::Configuration) << "Internal Error: array out of bounds " << std::endl; - if ((trStatus[trigBit_]).state() == edm::hlt::Pass) return true; - //else if ((trStatus[trigBit]).state() == edm::hlt::Fail) return false; + if ((trStatus[trigBit_]).state() == edm::hlt::Pass) return true; + // else if ((trStatus[trigBit]).state() == edm::hlt::Fail) return false; - return false; - } - if (op_==NOT) { //NEGATION - return !children_[0]->returnStatus(trStatus); - } - if (op_==BR) { //BRACKET - return children_[0]->returnStatus(trStatus); - } - if (op_==AND) { //AND - bool status = true; - for (size_t i=0;ireturnStatus(trStatus); - return status; - } - else if (op_==OR) { //OR - bool status = false; - for (size_t i=0;ireturnStatus(trStatus); - return status; - } - throw edm::Exception(edm::errors::Configuration) << "Internal error: reached end of returnStatus(...) op:state= " << op_ << std::endl; return false; } - - - TriggerSelector::TreeElement::~TreeElement() - { - for (std::vector::iterator it=children_.begin();it!=children_.end();it++) - delete *it; - children_.clear(); + if (op_ == NOT) { // NEGATION + return !children_[0]->returnStatus(trStatus); } - -} + if (op_ == BR) { // BRACKET + return children_[0]->returnStatus(trStatus); + } + if (op_ == AND) { // AND + bool status = true; + for (size_t i = 0; i < children_.size(); i++) + status = status && children_[i]->returnStatus(trStatus); + return status; + } else if (op_ == OR) { // OR + bool status = false; + for (size_t i = 0; i < children_.size(); i++) + status = status || children_[i]->returnStatus(trStatus); + return status; + } + throw edm::Exception(edm::errors::Configuration) + << "Internal error: reached end of returnStatus(...) op:state= " << op_ + << std::endl; + return false; +} + +TriggerSelector::TreeElement::~TreeElement() { + for (std::vector::iterator it = children_.begin(); + it != children_.end(); it++) + delete *it; + children_.clear(); +} +} diff --git a/DQMServices/StreamerIO/plugins/TriggerSelector.h b/DQMServices/StreamerIO/plugins/TriggerSelector.h index 8a276b414eee6..9ffa5e9a4f16c 100644 --- a/DQMServices/StreamerIO/plugins/TriggerSelector.h +++ b/DQMServices/StreamerIO/plugins/TriggerSelector.h @@ -13,145 +13,135 @@ #include namespace dqmservices { +/** + * Event selector allowing for and/not combination of triggers/paths + * + */ + +class TriggerSelector { + public: + typedef std::vector Strings; + + /** + * Obsolete: Initializes TriggerSelector to use edm::EventSelector for + * selection. + */ + TriggerSelector(Strings const& pathspecs, Strings const& names); + + /** + * Takes ParameterSet wth TriggerSelector string or EventSelection list, and a + * list of triggers. + * if old_ is true, it is forced to use EventSelection. + */ + TriggerSelector(edm::ParameterSet const& pset, Strings const& triggernames, + bool old_ = false); + + /** + * Takes selection string and list of triggers + */ + TriggerSelector(std::string const& expression, Strings const& triggernames); + + ~TriggerSelector(){}; + + /** + * Returns status of always positive bit + */ + bool wantAll() const { + // if (useOld_) return eventSelector_->wantAll(); + return acceptAll_; + } + /** - * Event selector allowing for and/not combination of triggers/paths - * + * Evaluates if trigger results pass selection */ + bool acceptEvent(edm::TriggerResults const&) const; - class TriggerSelector - { - public: - - typedef std::vector Strings; - - /** - * Obsolete: Initializes TriggerSelector to use edm::EventSelector for selection. - */ - TriggerSelector(Strings const& pathspecs, - Strings const& names); - - /** - * Takes ParameterSet wth TriggerSelector string or EventSelection list, and a list of triggers. - * if old_ is true, it is forced to use EventSelection. - */ - TriggerSelector(edm::ParameterSet const& pset, - Strings const& triggernames, bool old_ = false); - - /** - * Takes selection string and list of triggers - */ - TriggerSelector(std::string const& expression, Strings const& triggernames); - - ~TriggerSelector() {}; - - /** - * Returns status of always positive bit - */ - bool wantAll() const { - // if (useOld_) return eventSelector_->wantAll(); - return acceptAll_; - } - - /** - * Evaluates if trigger results pass selection - */ - bool acceptEvent(edm::TriggerResults const&) const; - - /* - * Takes array of trigger results and a number of triggers in array and returns - * if it passes selection - */ - bool acceptEvent(unsigned char const*, int) const; - - /* - * Returns if HLTGlobalStatus passes selection - */ - bool returnStatus(edm::HLTGlobalStatus const& trStatus) const { - return masterElement_->returnStatus(trStatus); - } - - /* - * Does XMl compatible formatting of the selection string - */ - static std::string makeXMLString(std::string const& input); - - /* - * Obsolete: Returns SelectedEvents vector from ParameterSet - */ - static std::vector - getEventSelectionVString(edm::ParameterSet const& pset); - - private: - - bool acceptAll_; - - /* - * Starts parsing selection string - */ - void init(std::string const& path, Strings const& triggernames); - - /* - * Removes extra spaces from string - */ - static std::string trim(std::string input); - - /* - * Class used for storing internal representation of the selection string - */ - class TreeElement { - - enum TreeOperator { - NonInit = 0, - AND = 1, - OR = 2, - NOT = 3, - BR = 4 - }; - - public: - - /* - * Parser of selection string. Splits string into tokens and initializes new elements to parse them. - */ - TreeElement(std::string const& inputString,Strings const& tr,TreeElement* parentElement = NULL); - ~TreeElement(); - - /* - * Returns selection status of current element calculated recursively from it's child elements - */ - bool returnStatus(edm::HLTGlobalStatus const& trStatus) const; - - /* - * Returns operator type of the element - */ - TreeOperator op() const {return op_;} - - /* - * Returns parent element - */ - TreeElement * parent() const {return parent_;} - - private: - - TreeElement * parent_; - std::vector children_; - TreeOperator op_; - int trigBit_; - }; - - boost::shared_ptr masterElement_; - - //keep a copy of initialization string - std::string expression_; - - boost::shared_ptr eventSelector_; - bool useOld_; - - static const bool debug_ = false; + /* + * Takes array of trigger results and a number of triggers in array and + * returns + * if it passes selection + */ + bool acceptEvent(unsigned char const*, int) const; + + /* + * Returns if HLTGlobalStatus passes selection + */ + bool returnStatus(edm::HLTGlobalStatus const& trStatus) const { + return masterElement_->returnStatus(trStatus); + } + + /* + * Does XMl compatible formatting of the selection string + */ + static std::string makeXMLString(std::string const& input); + + /* + * Obsolete: Returns SelectedEvents vector from ParameterSet + */ + static std::vector getEventSelectionVString( + edm::ParameterSet const& pset); + + private: + bool acceptAll_; + /* + * Starts parsing selection string + */ + void init(std::string const& path, Strings const& triggernames); + + /* + * Removes extra spaces from string + */ + static std::string trim(std::string input); + + /* + * Class used for storing internal representation of the selection string + */ + class TreeElement { + enum TreeOperator { NonInit = 0, AND = 1, OR = 2, NOT = 3, BR = 4 }; + + public: + /* + * Parser of selection string. Splits string into tokens and initializes new + * elements to parse them. + */ + TreeElement(std::string const& inputString, Strings const& tr, + TreeElement* parentElement = NULL); + ~TreeElement(); + + /* + * Returns selection status of current element calculated recursively from + * it's child elements + */ + bool returnStatus(edm::HLTGlobalStatus const& trStatus) const; + + /* + * Returns operator type of the element + */ + TreeOperator op() const { return op_; } + + /* + * Returns parent element + */ + TreeElement* parent() const { return parent_; } + + private: + TreeElement* parent_; + std::vector children_; + TreeOperator op_; + int trigBit_; }; -} + boost::shared_ptr masterElement_; + + // keep a copy of initialization string + std::string expression_; + + boost::shared_ptr eventSelector_; + bool useOld_; -#endif + static const bool debug_ = false; +}; +} +#endif