diff --git a/interface/Framework.h b/interface/Framework.h index 5c40c44..695db5e 100644 --- a/interface/Framework.h +++ b/interface/Framework.h @@ -50,11 +50,11 @@ class ExTreeMaker: public edm::EDProducer, ProducerGetter, AnalyzerGetter { std::string m_output_filename; std::unique_ptr m_output; std::unique_ptr m_wrapper; - std::unordered_map> m_producers; - std::unordered_map> m_filters; + std::unordered_map> m_filters; // Order is important, we can't use a map here + std::vector>> m_producers; std::vector> m_analyzers; std::vector m_analyzers_name; diff --git a/python/Framework.py b/python/Framework.py index 52a0d88..9603d7e 100644 --- a/python/Framework.py +++ b/python/Framework.py @@ -444,25 +444,35 @@ def create(isData, era, globalTag=None, analyzers=cms.PSet(), redoJEC=False): print("") return process -def schedule(process, analyzers): +def schedule(process, analyzers=None, producers=None): """Inform the framework of the desired scheduling of the analyzers Args: process (cms.Process): the current framework process, return by the ``create`` method analyzers (string tuple): a string array representing the desired scheduling of the analyzers. Analyzers will be executed in the specified order. + producers (string tuple): a string array representing the desired scheduling of the producers. Producers will be executed in the specified order. """ - if analyzers is None or len(analyzers) == 0: - return process + if analyzers and len(analyzers) > 0: + framework_analyzers = process.framework.analyzers.parameterNames_() + for a in framework_analyzers: + if not a in analyzers: + raise Exception('Analyzer %r not found in your scheduling array. Please add it somewhere suitable for you.' % a) - framework_analyzers = process.framework.analyzers.parameterNames_() - for a in framework_analyzers: - if not a in analyzers: - raise Exception('Analyzer %r not found in your scheduling array. Please add it somewhere suitable for you.' % a) + if len(analyzers) != len(framework_analyzers): + raise Exception('Your scheduling array contains a different number of analyzers than the framework (%d vs %d)' % (len(analyzers), len(framework_analyzers))) - if len(analyzers) != len(framework_analyzers): - raise Exception('Your scheduling array contains a different number of analyzers than the framework (%d vs %d)' % (len(analyzers), len(framework_analyzers))) + process.framework.analyzers_scheduling = cms.untracked.vstring(analyzers) - process.framework.analyzers_scheduling = cms.untracked.vstring(analyzers) + if producers and len(producers) > 0: + framework_producers = process.framework.producers.parameterNames_() + for a in framework_producers: + if not a in producers: + raise Exception('Producer %r not found in your scheduling array. Please add it somewhere suitable for you.' % a) + + if len(producers) != len(framework_producers): + raise Exception('Your scheduling array contains a different number of producers than the framework (%d vs %d)' % (len(producers), len(framework_producers))) + + process.framework.producers_scheduling = cms.untracked.vstring(producers) return process diff --git a/src/Framework.cc b/src/Framework.cc index 9fc33f0..43f5fb1 100644 --- a/src/Framework.cc +++ b/src/Framework.cc @@ -90,6 +90,14 @@ ExTreeMaker::ExTreeMaker(const edm::ParameterSet& iConfig): std::cout << std::endl << "producers: " << std::endl; const edm::ParameterSet& producers = iConfig.getParameterSet("producers"); std::vector producersName = producers.getParameterNames(); + + if (iConfig.exists("producers_scheduling")) { + const std::vector& scheduling = iConfig.getUntrackedParameter>("producers_scheduling"); + auto p = get_permutations(scheduling, producersName); + + apply_permutations(producersName, p); + } + for (std::string& producerName: producersName) { edm::ParameterSet producerData = producers.getParameterSet(producerName); bool enable = producerData.getParameter("enable"); @@ -106,7 +114,7 @@ ExTreeMaker::ExTreeMaker(const edm::ParameterSet& iConfig): auto producer = std::shared_ptr(ExTreeMakerProducerFactory::get()->create(type, producerName, m_wrapper->group(tree_prefix), producerParameters)); producer->doConsumes(producerParameters, consumesCollector()); - m_producers.emplace(producerName, producer); + m_producers.push_back(std::make_pair(producerName, producer)); } if (!iConfig.existsAs("analyzers")) { @@ -274,7 +282,7 @@ void ExTreeMaker::endLuminosityBlock(const edm::LuminosityBlock& lumi, const edm } const Framework::Producer& ExTreeMaker::getProducer(const std::string& name) const { - const auto& producer = m_producers.find(name); + const auto producer = std::find_if(m_producers.begin(), m_producers.end(), [&name](const std::pair>& element) { return element.first == name; }); if (producer == m_producers.end()) { std::stringstream details; details << "Producer '" << name << "' not found. Please load it first in the python configuration"; @@ -285,7 +293,7 @@ const Framework::Producer& ExTreeMaker::getProducer(const std::string& name) con } bool ExTreeMaker::producerExists(const std::string& name) const { - const auto& producer = m_producers.find(name); + const auto producer = std::find_if(m_producers.begin(), m_producers.end(), [&name](const std::pair>& element) { return element.first == name; }); return (producer != m_producers.end()); } diff --git a/test/TestConfigurationData.py b/test/TestConfigurationData.py index 18d7d4f..53ce644 100644 --- a/test/TestConfigurationData.py +++ b/test/TestConfigurationData.py @@ -62,7 +62,8 @@ ) ) -Framework.schedule(process, ['dilepton', 'bTagsLoose', 'bTagsMedium', 'bTagsTight', 'test']) +Framework.schedule(process, analyzers=['dilepton', 'bTagsLoose', 'bTagsMedium', 'bTagsTight', 'test'], + producers=['event', 'hlt', 'vertices', 'electrons', 'muons', 'jets', 'fat_jets', 'met', 'nohf_met']) process.source.fileNames = cms.untracked.vstring( '/store/data/Run2015B/DoubleMuon/MINIAOD/17Jul2015-v1/30000/D8ED75E7-C12E-E511-8CBF-0025905A608C.root' diff --git a/test/TestConfigurationMC.py b/test/TestConfigurationMC.py index 2178405..428a026 100644 --- a/test/TestConfigurationMC.py +++ b/test/TestConfigurationMC.py @@ -66,7 +66,8 @@ ) -Framework.schedule(process, ['dilepton', 'bTagsLoose', 'bTagsMedium', 'bTagsTight', 'test']) +Framework.schedule(process, analyzers=['dilepton', 'bTagsLoose', 'bTagsMedium', 'bTagsTight', 'test'], + producers=['event', 'gen_particles', 'hlt', 'vertices', 'electrons', 'muons', 'jets', 'fat_jets', 'met', 'nohf_met']) process.source.fileNames = cms.untracked.vstring( 'file:///home/fynu/sbrochet/storage/MINIAODSIM/TTJets_TuneCUETP8M1_13TeV-amcatnloFXFX-pythia8_Asympt25ns_MCRUN2_74_V9_reduced.root'