CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/FWCore/Sources/src/EventSkipperByID.cc

Go to the documentation of this file.
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         // The default value provided as the second argument to the getUntrackedParameter function call
00009         // is not used when the ParameterSet has been validated and the parameters are not optional
00010         // in the description.  As soon as all primary input sources and all modules with a secondary
00011         // input sources have defined descriptions, the defaults in the getUntrackedParameterSet function
00012         // calls can and should be deleted from the code.
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   // Determines whether a run, lumi, or event will be skipped based on the run, lumi, and event number.
00041   // This function is called by a predicate, so it must not modify the state of the EventSkipperByID_ object.
00042   // The mutable lumi_ and event_ data members are just temporary caches, so they may be modified.
00043   bool
00044   EventSkipperByID::skipIt(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const {
00045 
00046     if(run == 0U) run = 1U; // Correct zero run number
00047     if(run < firstRun_) {
00048       // Skip all entries before the first run.
00049       return true;
00050     }
00051     if(lumi == 0U) {
00052       // This is a run entry that is not before the first run.
00053       // Keep it, since there are no other parameters to skip runs.
00054       return false;
00055     }
00056     // If we get here, this is a lumi or event entry.
00057     if(run == firstRun_) {
00058       // This lumi or event entry is in the first run to be processed.
00059       if(lumi < firstLumi_) {
00060         // This lumi or event entry is for a lumi prior to the first lumi to be processed.  Skip it.
00061         return true;
00062       }
00063       if(firstLumi_ == 0 || lumi == firstLumi_) {
00064         // If we get here, this entry is in the first lumi to be processed in the first run.
00065         // Note that if firstLumi_ == 0, we are processing all lumis in the run.
00066         if(event != 0U && event < firstEvent_) {
00067           // This is an event entry prior to the first event to be processed. Skip it.
00068           return true;
00069         }
00070       }
00071     }
00072     if (skippingLumis()) {
00073       // If we get here, the entry was not skipped due to firstRun, firstLuminosityBlock, and/or firstEvent.
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         // The entry is in a lumi specified in whichLumisToSkip.  Skip it.
00079         return true;
00080       }
00081       if(!whichLumisToProcess_.empty() && !binary_search_all(whichLumisToProcess_, lumiRange, lt)) {
00082         // The entry is not in a lumi specified in non-empty whichLumisToProcess.  Skip it.
00083         return true;
00084       }
00085     }
00086     if(event == 0U) {
00087       // The entry is a lumi entry that was not skipped above.  Keep it.
00088       return false;
00089     }
00090     if (skippingEvents()) {
00091       // If we get here, the entry was not skipped due to firstRun, firstLuminosityBlock, and/or firstEvent.
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         // The entry is an event specified in whichEventsToSkip.  Skip it.
00099         return true;
00100       }
00101       if(!whichEventsToProcess_.empty() && !binary_search_all(whichEventsToProcess_, eventRange, lt) && !binary_search_all(whichEventsToProcess_, eventRangeNoLumi, lt)) {
00102         // The entry is not an event specified in non-empty whichEventsToProcess.  Skip it.
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 }