Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:29:16

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       :  // The default value provided as the second argument to the getUntrackedParameter function call
0009          // is not used when the ParameterSet has been validated and the parameters are not optional
0010          // in the description.  As soon as all primary input sources and all modules with a secondary
0011          // input sources have defined descriptions, the defaults in the getUntrackedParameterSet function
0012          // calls can and should be deleted from the code.
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   // Determines whether a run, lumi, or event will be skipped based on the run, lumi, and event number.
0047   // This function is called by a predicate, so it must not modify the state of the EventSkipperByID_ object.
0048   // The mutable lumi_ and event_ data members are just temporary caches, so they may be modified.
0049   bool EventSkipperByID::skipIt(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const {
0050     if (run == 0U)
0051       run = 1U;  // Correct zero run number
0052     if (run < firstRun_) {
0053       // Skip all entries before the first run.
0054       return true;
0055     }
0056     if (lumi == 0U) {
0057       // This is a run entry that is not before the first run.
0058       // Keep it, since there are no other parameters to skip runs.
0059       return false;
0060     }
0061     // If we get here, this is a lumi or event entry.
0062     if (run == firstRun_) {
0063       // This lumi or event entry is in the first run to be processed.
0064       if (lumi < firstLumi_) {
0065         // This lumi or event entry is for a lumi prior to the first lumi to be processed.  Skip it.
0066         return true;
0067       }
0068       if (firstLumi_ == 0 || lumi == firstLumi_) {
0069         // If we get here, this entry is in the first lumi to be processed in the first run.
0070         // Note that if firstLumi_ == 0, we are processing all lumis in the run.
0071         if (event != 0U && event < firstEvent_) {
0072           // This is an event entry prior to the first event to be processed. Skip it.
0073           return true;
0074         }
0075       }
0076     }
0077     if (skippingLumis()) {
0078       // If we get here, the entry was not skipped due to firstRun, firstLuminosityBlock, and/or firstEvent.
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         // The entry is in a lumi specified in whichLumisToSkip.  Skip it.
0084         return true;
0085       }
0086       if (!whichLumisToProcess_.empty() && !binary_search_all(whichLumisToProcess_, lumiRange, lt)) {
0087         // The entry is not in a lumi specified in non-empty whichLumisToProcess.  Skip it.
0088         return true;
0089       }
0090     }
0091     if (event == 0U) {
0092       // The entry is a lumi entry that was not skipped above.  Keep it.
0093       return false;
0094     }
0095     if (skippingEvents()) {
0096       // If we get here, the entry was not skipped due to firstRun, firstLuminosityBlock, and/or firstEvent.
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         // The entry is an event specified in whichEventsToSkip.  Skip it.
0105         return true;
0106       }
0107       if (!whichEventsToProcess_.empty() && !binary_search_all(whichEventsToProcess_, eventRange, lt) &&
0108           !binary_search_all(whichEventsToProcess_, eventRangeNoLumi, lt)) {
0109         // The entry is not an event specified in non-empty whichEventsToProcess.  Skip it.
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 }  // namespace edm