Skip to content

Commit

Permalink
Merge pull request #60 from blinkseb/producer_scheduling
Browse files Browse the repository at this point in the history
Support for producers scheduling
  • Loading branch information
OlivierBondu committed Sep 21, 2015
2 parents d7b1512 + 477ee1b commit 0530a4b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 17 deletions.
4 changes: 2 additions & 2 deletions interface/Framework.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ class ExTreeMaker: public edm::EDProducer, ProducerGetter, AnalyzerGetter {
std::string m_output_filename;
std::unique_ptr<TFile> m_output;
std::unique_ptr<ROOT::TreeWrapper> m_wrapper;
std::unordered_map<std::string, std::shared_ptr<Framework::Producer>> m_producers;
std::unordered_map<std::string, std::shared_ptr<Framework::Filter>> m_filters;

std::unordered_map<std::string, std::shared_ptr<Framework::Filter>> m_filters;

// Order is important, we can't use a map here
std::vector<std::pair<std::string, std::shared_ptr<Framework::Producer>>> m_producers;
std::vector<std::shared_ptr<Framework::Analyzer>> m_analyzers;
std::vector<std::string> m_analyzers_name;

Expand Down
30 changes: 20 additions & 10 deletions python/Framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 11 additions & 3 deletions src/Framework.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> producersName = producers.getParameterNames();

if (iConfig.exists("producers_scheduling")) {
const std::vector<std::string>& scheduling = iConfig.getUntrackedParameter<std::vector<std::string>>("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<bool>("enable");
Expand All @@ -106,7 +114,7 @@ ExTreeMaker::ExTreeMaker(const edm::ParameterSet& iConfig):
auto producer = std::shared_ptr<Framework::Producer>(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<edm::ParameterSet>("analyzers")) {
Expand Down Expand Up @@ -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<std::string, std::shared_ptr<Framework::Producer>>& 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";
Expand All @@ -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<std::string, std::shared_ptr<Framework::Producer>>& element) { return element.first == name; });
return (producer != m_producers.end());
}

Expand Down
3 changes: 2 additions & 1 deletion test/TestConfigurationData.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 2 additions & 1 deletion test/TestConfigurationMC.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 0530a4b

Please sign in to comment.