-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement an EDFilter to select events based on their bunch crossing number (10.3.x) #25019
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
#include "FWCore/Framework/interface/global/EDFilter.h" | ||
#include "FWCore/Framework/interface/MakerMacros.h" | ||
#include "FWCore/Framework/interface/Event.h" | ||
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" | ||
#include "FWCore/ParameterSet/interface/ParameterSet.h" | ||
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" | ||
|
||
template <typename T> | ||
std::vector<T> sorted(std::vector<T> v) { | ||
std::sort(v.begin(), v.end()); | ||
return v; | ||
} | ||
|
||
namespace edm { | ||
class BunchCrossingFilter : public global::EDFilter<> { | ||
public: | ||
explicit BunchCrossingFilter(ParameterSet const& config); | ||
|
||
static void fillDescriptions(ConfigurationDescriptions& descriptions); | ||
bool filter(StreamID, Event& event, EventSetup const&) const final; | ||
|
||
private: | ||
const std::vector<unsigned int> bunches_; | ||
}; | ||
|
||
BunchCrossingFilter::BunchCrossingFilter(ParameterSet const& config) : | ||
bunches_(sorted(config.getParameter<std::vector<unsigned int>>("bunches"))) | ||
{ | ||
} | ||
|
||
bool BunchCrossingFilter::filter(StreamID, Event& event, EventSetup const&) const | ||
{ | ||
return std::binary_search(bunches_.begin(), bunches_.end(), event.bunchCrossing()); | ||
} | ||
|
||
void | ||
BunchCrossingFilter::fillDescriptions(ConfigurationDescriptions& descriptions) { | ||
ParameterSetDescription desc; | ||
desc.add<std::vector<unsigned int>>("bunches", {})->setComment("List of bunch crossings for which events should be accepted [1-3564]."); | ||
descriptions.add("bunchCrossingFilter", desc); | ||
} | ||
} | ||
|
||
using edm::BunchCrossingFilter; | ||
DEFINE_FWK_MODULE(BunchCrossingFilter); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# simple test for the BunchCrossingFilter | ||
|
||
# colliding bunches in run 317435, fill 6759, scheme 25ns_2556b_2544_2215_2332_144bpi_20injV2: | ||
# 81-128, 136-183 | ||
# 215-262, 270-317, 325-372, | ||
# 404-451, 459-506, 514-561, | ||
# 593-640, 648-695, 703-750, | ||
# 786-833, 841-888, | ||
# 920-967, 975-1022, 1030-1077, | ||
# 1109-1156, 1164-1211, 1219-1266, | ||
# 1298-1345, 1353-1400, 1408-1455, | ||
# 1487-1534, 1542-1589, 1597-1644, | ||
# 1680-1727, 1735-1782, | ||
# 1814-1861, 1869-1916, 1924-1971, | ||
# 2003-2050, 2058-2105, 2113-2160, | ||
# 2192-2239, 2247-2294, 2302-2349, | ||
# 2381-2428, 2436-2483, 2491-2538, | ||
# 2574-2621, 2629-2676, | ||
# 2708-2755, 2763-2810, 2818-2865, | ||
# 2897-2944, 2952-2999, 3007-3054, | ||
# 3086-3133, 3141-3188, 3196-3243, | ||
# 3275-3322, 3330-3377, 3385-3432 | ||
# (see https://lpc.web.cern.ch/fillingSchemes/2018/25ns_2556b_2544_2215_2332_144bpi_20injV2.csv) | ||
|
||
import FWCore.ParameterSet.Config as cms | ||
|
||
process = cms.Process('TEST') | ||
|
||
process.maxEvents = cms.untracked.PSet( | ||
input = cms.untracked.int32(-1) | ||
) | ||
|
||
process.options = cms.untracked.PSet( | ||
wantSummary = cms.untracked.bool(True) | ||
) | ||
|
||
process.load('FWCore.MessageService.MessageLogger_cfi') | ||
|
||
# input data | ||
process.source = cms.Source('PoolSource', | ||
fileNames = cms.untracked.vstring('/store/data/Run2018B/ZeroBias/RAW/v1/000/317/435/00000/10FA8B3F-5A68-E811-A1D9-FA163E481185.root') | ||
) | ||
|
||
from FWCore.Modules.bunchCrossingFilter_cfi import bunchCrossingFilter as _bunchCrossingFilter | ||
|
||
# empty input, do not select any bunch crossings | ||
process.selectNone = _bunchCrossingFilter.clone( | ||
bunches = cms.vuint32(), | ||
) | ||
|
||
# full range of possible bunch crossings [1,3564] | ||
process.selectAll = _bunchCrossingFilter.clone( | ||
bunches = cms.vuint32(range(1,3565)) | ||
) | ||
|
||
# select bx 536 | ||
process.selectSingle = _bunchCrossingFilter.clone( | ||
bunches = cms.vuint32(536) | ||
) | ||
|
||
# select the whole train 514-561 | ||
process.selectTrain = _bunchCrossingFilter.clone( | ||
bunches = cms.vuint32(range(514,562)) | ||
) | ||
|
||
# inverted to veto (non-colliding) bx 1 | ||
process.selectEmpty = _bunchCrossingFilter.clone( | ||
bunches = cms.vuint32(1) | ||
) | ||
|
||
process.SelectNone = cms.Path( process.selectNone ) | ||
process.SelectAll = cms.Path( process.selectAll ) | ||
process.SelectSingle = cms.Path( process.selectSingle ) | ||
process.SelectTrain = cms.Path( process.selectTrain ) | ||
process.VetoEmpty = cms.Path( ~ process.selectEmpty ) | ||
process.VetoSingle = cms.Path( ~ process.selectSingle ) | ||
process.VetoTrain = cms.Path( ~ process.selectTrain ) | ||
process.SelectTrainButOne = cms.Path( process.selectTrain * ~ process.selectSingle ) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to avoid getting files from storage for framework tests since I do run these test on my laptop without internet connections. We normally either create new input files for the test or we store tiny ROOT files into the repository. Would any of the files in IOPool/Input/testdata work for your test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the files under
IOPool/Input/testdata
have at most one event, so it is hard to show the various ways how to use the filter.Of course if this is a requirement, I can simplify the test case and adapt it to that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could stick a tiny file in IOPool/Input/testdata if you want, or one in FWCore/Modules/testdata
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do I create a tiny file ?
Even if I drop all collections (
"drop *"
), a file with 1 event is ~1.3 MB.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried the following
the generated file was 1.5MB in size. Looking at the internals, the ParameterSets branch is 1.47MB in size. I'll see if I can come up with a simple way to fake that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you checkout
IOPool/Provenance
and editIOPool/Provenance/src/CommonProvenanceFiller.cc
and comment out the loophttps://github.com/cms-sw/cmssw/blob/master/IOPool/Provenance/src/CommonProvenanceFiller.cc#L24
and rebuild IOPool/Output. At that point, using the configuration I tested, you can create a
slim.root
file which is only 40KB in length. I was successfully able to read back that tiny file from a simple cmsRun job.