From b595bc7e2fe682bc39ca3d3d06c5bcf1e8708dab Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Wed, 14 Jan 2026 14:09:22 -0600 Subject: [PATCH] Use std::range in FWCore/Framework - switched to std::ranges::iota for loops needing indicies - use std::view for case where makes simpler --- FWCore/Framework/src/EventProcessor.cc | 19 +++++++++--------- FWCore/Framework/src/Schedule.cc | 27 +++++++++++++++----------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/FWCore/Framework/src/EventProcessor.cc b/FWCore/Framework/src/EventProcessor.cc index 2a504d07ef86a..e2f4d443708d8 100644 --- a/FWCore/Framework/src/EventProcessor.cc +++ b/FWCore/Framework/src/EventProcessor.cc @@ -88,6 +88,7 @@ #include #include #include +#include #include #include @@ -546,7 +547,7 @@ namespace edm { actReg_->prePrincipalsCreationSignal_.emit(); auto guard = makeGuard([this]() { actReg_->postPrincipalsCreationSignal_.emit(); }); principalCache_.setNumberOfConcurrentPrincipals(preallocations_); - for (unsigned int index = 0; index < preallocations_.numberOfStreams(); ++index) { + for (auto index : std::views::iota(0U, preallocations_.numberOfStreams())) { // Reusable event principal auto ep = std::make_shared(preg(), productResolversFactory::makePrimary, @@ -559,7 +560,7 @@ namespace edm { principalCache_.insert(std::move(ep)); } - for (unsigned int index = 0; index < preallocations_.numberOfRuns(); ++index) { + for (auto index : std::views::iota(0U, preallocations_.numberOfRuns())) { auto rp = std::make_unique(preg(), productResolversFactory::makePrimary, *processConfiguration_, @@ -569,7 +570,7 @@ namespace edm { principalCache_.insert(std::move(rp)); } - for (unsigned int index = 0; index < preallocations_.numberOfLuminosityBlocks(); ++index) { + for (auto index : std::views::iota(0U, preallocations_.numberOfLuminosityBlocks())) { auto lp = std::make_unique( preg(), productResolversFactory::makePrimary, *processConfiguration_, historyAppender_.get(), index); principalCache_.insert(std::move(lp)); @@ -772,7 +773,7 @@ namespace edm { using namespace edm::waiting_task::chain; { WaitingTaskHolder taskHolder(group, &finalWaitingTask); - for (unsigned int i = 0; i < preallocations_.numberOfStreams(); ++i) { + for (auto i : std::views::iota(0U, preallocations_.numberOfStreams())) { first([this, i](auto nextTask) { std::exception_ptr exceptionPtr; { @@ -798,7 +799,7 @@ namespace edm { using namespace edm::waiting_task::chain; { WaitingTaskHolder taskHolder(group, &finalWaitingTask); - for (unsigned int i = 0; i < preallocations_.numberOfStreams(); ++i) { + for (auto i : std::views::iota(0U, preallocations_.numberOfStreams())) { first([this, i, &collector, &collectorMutex](auto nextTask) { { ServiceRegistry::Operate operate(serviceToken_); @@ -1332,7 +1333,7 @@ namespace edm { CMS_SA_ALLOW try { streamQueuesInserter_.push(*holder.group(), [this, status, holder]() mutable { - for (unsigned int i = 0; i < preallocations_.numberOfStreams(); ++i) { + for (auto i : std::views::iota(0U, preallocations_.numberOfStreams())) { CMS_SA_ALLOW try { streamQueues_[i].push(*holder.group(), [this, i, status, holder]() mutable { streamBeginRunAsync(i, std::move(status), std::move(holder)); @@ -1443,7 +1444,7 @@ namespace edm { } ServiceRegistry::Operate operate(serviceToken_); streamQueuesInserter_.push(*nextTask.group(), [this, nextTask]() mutable { - for (unsigned int i = 0; i < preallocations_.numberOfStreams(); ++i) { + for (auto i : std::views::iota(0U, preallocations_.numberOfStreams())) { CMS_SA_ALLOW try { streamQueues_[i].push(*nextTask.group(), [this, i, nextTask]() mutable { streamQueues_[i].pause(); @@ -1757,7 +1758,7 @@ namespace edm { using Traits = OccurrenceTraits; streamQueuesInserter_.push(*holder.group(), [this, status, holder, &es]() mutable { - for (unsigned int i = 0; i < preallocations_.numberOfStreams(); ++i) { + for (auto i : std::views::iota(0U, preallocations_.numberOfStreams())) { streamQueues_[i].push(*holder.group(), [this, i, status, holder, &es]() mutable { if (!status->shouldStreamStartLumi()) { return; @@ -1962,7 +1963,7 @@ namespace edm { streamLumiStatus_[0]->setCleaningUpAfterException(cleaningUpAfterException); { WaitingTaskHolder holder{taskGroup_, &globalWaitTask}; - for (unsigned int i = 0; i < preallocations_.numberOfStreams(); ++i) { + for (auto i : std::views::iota(0U, preallocations_.numberOfStreams())) { streamEndLumiAsync(holder, i); } } diff --git a/FWCore/Framework/src/Schedule.cc b/FWCore/Framework/src/Schedule.cc index 70ac3abb7f048..2769d4e15e809 100644 --- a/FWCore/Framework/src/Schedule.cc +++ b/FWCore/Framework/src/Schedule.cc @@ -52,6 +52,7 @@ #include #include #include +#include #include "make_shared_noexcept_false.h" #include "processEDAliases.h" @@ -100,18 +101,20 @@ namespace edm { vstring scheduledPaths = proc_pset.getParameter("@paths"); std::set modulesOnPaths; { - std::set noEndPaths(scheduledPaths.begin(), scheduledPaths.end()); - for (auto const& endPath : end_path_name_list) { - noEndPaths.erase(endPath); - } - { - vstring labels; - for (auto const& path : noEndPaths) { - labels = proc_pset.getParameter(path); - modulesOnPaths.insert(labels.begin(), labels.end()); - } + auto getModuleLabelsOfPath = [&](auto const& lbl) { + return proc_pset.getParameter>(lbl); + }; + auto notEndPath = [&](auto const& lbl) { + return std::ranges::find(end_path_name_list, lbl) == end_path_name_list.end(); + }; + + auto tmp = scheduledPaths | std::views::filter(notEndPath) | std::views::transform(getModuleLabelsOfPath) | + std::views::join; + for (auto const& modLabel : tmp) { + modulesOnPaths.insert(modLabel); } } + //Initially fill labelsToBeDropped with all module mentioned in // the configuration but which are not being used by the system std::vector labelsToBeDropped; @@ -144,7 +147,9 @@ namespace edm { labelsToBeDropped.begin(), labelsToBeDropped.begin() + sizeBeforeOutputModules, labelsToBeDropped.end()); // drop the parameter sets used to configure the modules - for_all(labelsToBeDropped, std::bind(&ParameterSet::eraseOrSetUntrackedParameterSet, std::ref(proc_pset), _1)); + for (auto& label : labelsToBeDropped) { + proc_pset.eraseOrSetUntrackedParameterSet(label); + } // drop the labels from @all_modules vstring::iterator endAfterRemove =