File indexing completed on 2024-04-06 12:13:10
0001 #include "FWCore/Sources/interface/EventSkipperByID.h"
0002 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0003 #include "FWCore/Utilities/interface/Algorithms.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0005
0006 namespace edm {
0007 EventSkipperByID::EventSkipperByID(ParameterSet const& pset)
0008 :
0009
0010
0011
0012
0013 firstRun_(pset.getUntrackedParameter<unsigned int>("firstRun", 1U)),
0014 firstLumi_(pset.getUntrackedParameter<unsigned int>("firstLuminosityBlock", 0U)),
0015 firstEvent_(pset.existsAs<unsigned int>("firstEvent", false)
0016 ? pset.getUntrackedParameter<unsigned int>("firstEvent")
0017 : pset.getUntrackedParameter<unsigned long long>("firstEvent", 1U)),
0018 whichLumisToSkip_(pset.getUntrackedParameter<std::vector<LuminosityBlockRange> >(
0019 "lumisToSkip", std::vector<LuminosityBlockRange>())),
0020 whichLumisToProcess_(pset.getUntrackedParameter<std::vector<LuminosityBlockRange> >(
0021 "lumisToProcess", std::vector<LuminosityBlockRange>())),
0022 whichEventsToSkip_(
0023 pset.getUntrackedParameter<std::vector<EventRange> >("eventsToSkip", std::vector<EventRange>())),
0024 whichEventsToProcess_(
0025 pset.getUntrackedParameter<std::vector<EventRange> >("eventsToProcess", std::vector<EventRange>())),
0026 skippingLumis_(!(whichLumisToSkip_.empty() && whichLumisToProcess_.empty() && firstLumi_ == 0)),
0027 skippingEvents_(!(whichEventsToSkip_.empty() && whichEventsToProcess_.empty())),
0028 somethingToSkip_(skippingLumis_ || skippingEvents_ ||
0029 !(firstRun_ <= 1U && firstLumi_ <= 1U && firstEvent_ <= 1U)) {
0030 sortAndRemoveOverlaps(whichLumisToSkip_);
0031 sortAndRemoveOverlaps(whichLumisToProcess_);
0032 sortAndRemoveOverlaps(whichEventsToSkip_);
0033 sortAndRemoveOverlaps(whichEventsToProcess_);
0034 }
0035
0036 EventSkipperByID::~EventSkipperByID() {}
0037
0038 std::unique_ptr<EventSkipperByID> EventSkipperByID::create(ParameterSet const& pset) {
0039 auto evSkp = std::make_unique<EventSkipperByID>(pset);
0040 if (!evSkp->somethingToSkip()) {
0041 evSkp.reset();
0042 }
0043 return evSkp;
0044 }
0045
0046
0047
0048
0049 bool EventSkipperByID::skipIt(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const {
0050 if (run == 0U)
0051 run = 1U;
0052 if (run < firstRun_) {
0053
0054 return true;
0055 }
0056 if (lumi == 0U) {
0057
0058
0059 return false;
0060 }
0061
0062 if (run == firstRun_) {
0063
0064 if (lumi < firstLumi_) {
0065
0066 return true;
0067 }
0068 if (firstLumi_ == 0 || lumi == firstLumi_) {
0069
0070
0071 if (event != 0U && event < firstEvent_) {
0072
0073 return true;
0074 }
0075 }
0076 }
0077 if (skippingLumis()) {
0078
0079 LuminosityBlockID lumiID = LuminosityBlockID(run, lumi);
0080 LuminosityBlockRange lumiRange = LuminosityBlockRange(lumiID, lumiID);
0081 bool (*lt)(LuminosityBlockRange const&, LuminosityBlockRange const&) = &lessThan;
0082 if (binary_search_all(whichLumisToSkip_, lumiRange, lt)) {
0083
0084 return true;
0085 }
0086 if (!whichLumisToProcess_.empty() && !binary_search_all(whichLumisToProcess_, lumiRange, lt)) {
0087
0088 return true;
0089 }
0090 }
0091 if (event == 0U) {
0092
0093 return false;
0094 }
0095 if (skippingEvents()) {
0096
0097 EventID eventID = EventID(run, lumi, event);
0098 EventRange eventRange = EventRange(eventID, eventID);
0099 EventID eventIDNoLumi = EventID(run, 0U, event);
0100 EventRange eventRangeNoLumi = EventRange(eventIDNoLumi, eventIDNoLumi);
0101 bool (*lt)(EventRange const&, EventRange const&) = &lessThanSpecial;
0102 if (binary_search_all(whichEventsToSkip_, eventRange, lt) ||
0103 binary_search_all(whichEventsToSkip_, eventRangeNoLumi, lt)) {
0104
0105 return true;
0106 }
0107 if (!whichEventsToProcess_.empty() && !binary_search_all(whichEventsToProcess_, eventRange, lt) &&
0108 !binary_search_all(whichEventsToProcess_, eventRangeNoLumi, lt)) {
0109
0110 return true;
0111 }
0112 }
0113 return false;
0114 }
0115
0116 void EventSkipperByID::fillDescription(ParameterSetDescription& desc) {
0117 desc.addUntracked<unsigned int>("firstRun", 1U)->setComment("Skip any run with run number < 'firstRun'.");
0118 desc.addUntracked<unsigned int>("firstLuminosityBlock", 0U)
0119 ->setComment("Skip any lumi in run 'firstRun' with lumi number < 'firstLuminosityBlock'.");
0120
0121 desc.addNode(edm::ParameterDescription<unsigned int>("firstEvent", 1U, false) xor
0122 edm::ParameterDescription<unsigned long long>("firstEvent", 1ULL, false))
0123 ->setComment(
0124 "'firstEvent' is an XOR group because it can have type uint32 or uint64, default:1\n"
0125 "If 'firstLuminosityBlock' == 0, skip any event in run 'firstRun' with event number < 'firstEvent'.\n"
0126 "If 'firstLuminosityBlock' != 0, skip any event in lumi 'firstRun:firstLuminosityBlock' with event number "
0127 "< 'firstEvent'.");
0128
0129 std::vector<LuminosityBlockRange> defaultLumis;
0130 desc.addUntracked<std::vector<LuminosityBlockRange> >("lumisToSkip", defaultLumis)
0131 ->setComment(
0132 "Skip any lumi inside the specified run:lumi range. In python do 'help(cms.LuminosityBlockRange)' for "
0133 "documentation.");
0134 desc.addUntracked<std::vector<LuminosityBlockRange> >("lumisToProcess", defaultLumis)
0135 ->setComment(
0136 "If not empty, skip any lumi outside the specified run:lumi range. In python do "
0137 "'help(cms.LuminosityBlockRange)' for documentation.");
0138
0139 std::vector<EventRange> defaultEvents;
0140 desc.addUntracked<std::vector<EventRange> >("eventsToSkip", defaultEvents)
0141 ->setComment(
0142 "Skip any event inside the specified run:event or run:lumi:event range. In python do "
0143 "'help(cms.EventRange)' for documentation.");
0144 desc.addUntracked<std::vector<EventRange> >("eventsToProcess", defaultEvents)
0145 ->setComment(
0146 "If not empty, skip any event outside the specified run:event or run:lumi:event range. In python do "
0147 "'help(cms.EventRange)' for documentation.");
0148 }
0149 }