00001 #include "FWCore/Sources/interface/EventSkipperByID.h"
00002 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00003 #include "FWCore/Utilities/interface/Algorithms.h"
00004 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
00005
00006 namespace edm {
00007 EventSkipperByID::EventSkipperByID(ParameterSet const& pset) :
00008
00009
00010
00011
00012
00013 firstRun_(pset.getUntrackedParameter<unsigned int>("firstRun", 1U)),
00014 firstLumi_(pset.getUntrackedParameter<unsigned int>("firstLuminosityBlock", 0U)),
00015 firstEvent_(pset.getUntrackedParameter<unsigned int>("firstEvent", 1U)),
00016 whichLumisToSkip_(pset.getUntrackedParameter<std::vector<LuminosityBlockRange> >("lumisToSkip", std::vector<LuminosityBlockRange>())),
00017 whichLumisToProcess_(pset.getUntrackedParameter<std::vector<LuminosityBlockRange> >("lumisToProcess", std::vector<LuminosityBlockRange>())),
00018 whichEventsToSkip_(pset.getUntrackedParameter<std::vector<EventRange> >("eventsToSkip",std::vector<EventRange>())),
00019 whichEventsToProcess_(pset.getUntrackedParameter<std::vector<EventRange> >("eventsToProcess",std::vector<EventRange>())),
00020 skippingLumis_(!(whichLumisToSkip_.empty() && whichLumisToProcess_.empty())),
00021 skippingEvents_(!(whichEventsToSkip_.empty() && whichEventsToProcess_.empty())),
00022 somethingToSkip_(skippingLumis_ || skippingEvents_ || !(firstRun_ <= 1U && firstLumi_ <= 1U && firstEvent_ <= 1U)) {
00023 sortAndRemoveOverlaps(whichLumisToSkip_);
00024 sortAndRemoveOverlaps(whichLumisToProcess_);
00025 sortAndRemoveOverlaps(whichEventsToSkip_);
00026 sortAndRemoveOverlaps(whichEventsToProcess_);
00027 }
00028
00029 EventSkipperByID::~EventSkipperByID() {}
00030
00031 std::auto_ptr<EventSkipperByID>
00032 EventSkipperByID::create(ParameterSet const& pset) {
00033 std::auto_ptr<EventSkipperByID> evSkp(new EventSkipperByID(pset));
00034 if (!evSkp->somethingToSkip()) {
00035 evSkp.reset();
00036 }
00037 return evSkp;
00038 }
00039
00040
00041
00042
00043 bool
00044 EventSkipperByID::skipIt(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const {
00045
00046 if(run == 0U) run = 1U;
00047 if(run < firstRun_) {
00048
00049 return true;
00050 }
00051 if(lumi == 0U) {
00052
00053
00054 return false;
00055 }
00056
00057 if(run == firstRun_) {
00058
00059 if(lumi < firstLumi_) {
00060
00061 return true;
00062 }
00063 if(firstLumi_ == 0 || lumi == firstLumi_) {
00064
00065
00066 if(event != 0U && event < firstEvent_) {
00067
00068 return true;
00069 }
00070 }
00071 }
00072 if (skippingLumis()) {
00073
00074 LuminosityBlockID lumiID = LuminosityBlockID(run, lumi);
00075 LuminosityBlockRange lumiRange = LuminosityBlockRange(lumiID, lumiID);
00076 bool(*lt)(LuminosityBlockRange const&, LuminosityBlockRange const&) = &lessThan;
00077 if(binary_search_all(whichLumisToSkip_, lumiRange, lt)) {
00078
00079 return true;
00080 }
00081 if(!whichLumisToProcess_.empty() && !binary_search_all(whichLumisToProcess_, lumiRange, lt)) {
00082
00083 return true;
00084 }
00085 }
00086 if(event == 0U) {
00087
00088 return false;
00089 }
00090 if (skippingEvents()) {
00091
00092 EventID eventID = EventID(run, lumi, event);
00093 EventRange eventRange = EventRange(eventID, eventID);
00094 EventID eventIDNoLumi = EventID(run, 0U, event);
00095 EventRange eventRangeNoLumi = EventRange(eventIDNoLumi, eventIDNoLumi);
00096 bool(*lt)(EventRange const&, EventRange const&) = &lessThanSpecial;
00097 if(binary_search_all(whichEventsToSkip_, eventRange, lt) || binary_search_all(whichEventsToSkip_, eventRangeNoLumi, lt)) {
00098
00099 return true;
00100 }
00101 if(!whichEventsToProcess_.empty() && !binary_search_all(whichEventsToProcess_, eventRange, lt) && !binary_search_all(whichEventsToProcess_, eventRangeNoLumi, lt)) {
00102
00103 return true;
00104 }
00105 }
00106 return false;
00107 }
00108
00109 void
00110 EventSkipperByID::fillDescription(ParameterSetDescription & desc) {
00111
00112 desc.addUntracked<unsigned int>("firstRun", 1U)
00113 ->setComment("Skip any run with run number < 'firstRun'.");
00114 desc.addUntracked<unsigned int>("firstLuminosityBlock", 0U)
00115 ->setComment("Skip any lumi in run 'firstRun' with lumi number < 'firstLuminosityBlock'.");
00116 desc.addUntracked<unsigned int>("firstEvent", 1U)
00117 ->setComment("If 'firstLuminosityBlock' == 0, skip any event in run 'firstRun' with event number < 'firstEvent'.\n"
00118 "If 'firstLuminosityBlock' != 0, skip any event in lumi 'firstRun:firstLuminosityBlock' with event number < 'firstEvent'.");
00119
00120 std::vector<LuminosityBlockRange> defaultLumis;
00121 desc.addUntracked<std::vector<LuminosityBlockRange> >("lumisToSkip", defaultLumis)
00122 ->setComment("Skip any lumi inside the specified run:lumi range.");
00123 desc.addUntracked<std::vector<LuminosityBlockRange> >("lumisToProcess", defaultLumis)
00124 ->setComment("If not empty, skip any lumi outside the specified run:lumi range.");
00125
00126 std::vector<EventRange> defaultEvents;
00127 desc.addUntracked<std::vector<EventRange> >("eventsToSkip", defaultEvents)
00128 ->setComment("Skip any event inside the specified run:event or run:lumi:event range.");
00129 desc.addUntracked<std::vector<EventRange> >("eventsToProcess", defaultEvents)
00130 ->setComment("If not empty, skip any event outside the specified run:event or run:lumi:event range.");
00131 }
00132 }