CMS 3D CMS Logo

ConfigurableInputSource.cc

Go to the documentation of this file.
00001 /*----------------------------------------------------------------------
00002 $Id: ConfigurableInputSource.cc,v 1.40 2008/10/16 23:06:28 wmtan Exp $
00003 ----------------------------------------------------------------------*/
00004 
00005 #include "DataFormats/Provenance/interface/LuminosityBlockAuxiliary.h"
00006 #include "DataFormats/Provenance/interface/RunAuxiliary.h"
00007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00008 #include "FWCore/Framework/interface/ConfigurableInputSource.h"
00009 #include "FWCore/Framework/interface/EventPrincipal.h"
00010 #include "FWCore/Framework/interface/LuminosityBlockPrincipal.h"
00011 #include "FWCore/Framework/interface/RunPrincipal.h"
00012 #include "FWCore/Framework/interface/Event.h"
00013 #include "FWCore/Framework/interface/LuminosityBlock.h"
00014 #include "FWCore/Framework/interface/Run.h"
00015 
00016 namespace edm {
00017   //used for defaults
00018   static const unsigned int kNanoSecPerSec = 1000000000U;
00019   static const unsigned int kAveEventPerSec = 200U;
00020   
00021   ConfigurableInputSource::ConfigurableInputSource(ParameterSet const& pset,
00022                                        InputSourceDescription const& desc, bool realData) :
00023     InputSource(pset, desc),
00024     numberEventsInRun_(pset.getUntrackedParameter<unsigned int>("numberEventsInRun", remainingEvents())),
00025     numberEventsInLumi_(pset.getUntrackedParameter<unsigned int>("numberEventsInLuminosityBlock", remainingEvents())),
00026     presentTime_(pset.getUntrackedParameter<unsigned int>("firstTime", 0)),  //time in ns
00027     origTime_(presentTime_),
00028     timeBetweenEvents_(pset.getUntrackedParameter<unsigned int>("timeBetweenEvents", kNanoSecPerSec/kAveEventPerSec)),
00029     eventCreationDelay_(pset.getUntrackedParameter<unsigned int>("eventCreationDelay", 0)),
00030     numberEventsInThisRun_(0),
00031     numberEventsInThisLumi_(0),
00032     zerothEvent_(pset.getUntrackedParameter<unsigned int>("firstEvent", 1) - 1),
00033     eventID_(pset.getUntrackedParameter<unsigned int>("firstRun", 1), zerothEvent_),
00034     origEventID_(eventID_),
00035     luminosityBlock_(pset.getUntrackedParameter<unsigned int>("firstLuminosityBlock", 1)),
00036     origLuminosityBlockNumber_t_(luminosityBlock_),
00037     newRun_(true),
00038     newLumi_(true),
00039     lumiSet_(false),
00040     eventSet_(false),
00041     ep_(0),
00042     isRealData_(realData),
00043     eType_(EventAuxiliary::Any)
00044   { 
00045     setTimestamp(Timestamp(presentTime_));
00046     // We need to map this string to the EventAuxiliary::ExperimentType enumeration
00047     // std::string eType = pset.getUntrackedParameter<std::string>("experimentType", std::string("Any"))),
00048   }
00049 
00050   ConfigurableInputSource::~ConfigurableInputSource() {
00051   }
00052 
00053   boost::shared_ptr<RunPrincipal>
00054   ConfigurableInputSource::readRun_() {
00055     Timestamp ts = Timestamp(presentTime_);
00056     RunAuxiliary runAux(eventID_.run(), ts, Timestamp::invalidTimestamp());
00057     boost::shared_ptr<RunPrincipal> runPrincipal(
00058         new RunPrincipal(runAux, productRegistry(), processConfiguration()));
00059     RunPrincipal & rp =
00060        const_cast<RunPrincipal &>(*runPrincipal);
00061     Run run(rp, moduleDescription());
00062     beginRun(run);
00063     run.commit_();
00064     newRun_ = false;
00065     return runPrincipal;
00066   }
00067 
00068   boost::shared_ptr<LuminosityBlockPrincipal>
00069   ConfigurableInputSource::readLuminosityBlock_() {
00070     if (processingMode() == Runs) return boost::shared_ptr<LuminosityBlockPrincipal>();
00071     Timestamp ts = Timestamp(presentTime_);
00072     LuminosityBlockAuxiliary lumiAux(runPrincipal()->run(), luminosityBlock_, ts, Timestamp::invalidTimestamp());
00073     boost::shared_ptr<LuminosityBlockPrincipal> lumiPrincipal(
00074         new LuminosityBlockPrincipal(
00075             lumiAux, productRegistry(), processConfiguration()));
00076     LuminosityBlock lb(*lumiPrincipal, moduleDescription());
00077     beginLuminosityBlock(lb);
00078     lb.commit_();
00079     newLumi_ = false;
00080     return lumiPrincipal;
00081   }
00082 
00083   std::auto_ptr<EventPrincipal>
00084   ConfigurableInputSource::readEvent_() {
00085     assert(ep_.get() != 0 || processingMode() != RunsLumisAndEvents);
00086     return ep_;
00087   }
00088 
00089   void
00090   ConfigurableInputSource::reallyReadEvent(LuminosityBlockNumber_t lumi) {
00091     if (processingMode() != RunsLumisAndEvents) return;
00092     EventSourceSentry sentry(*this);
00093     EventAuxiliary eventAux(eventID_,
00094       processGUID(), Timestamp(presentTime_), lumi, isRealData_, eType_);
00095     std::auto_ptr<EventPrincipal> result(
00096         new EventPrincipal(eventAux, productRegistry(), processConfiguration()));
00097     Event e(*result, moduleDescription());
00098     if (!produce(e)) {
00099       ep_.reset(); 
00100       return;
00101     }
00102     e.commit_();
00103     ep_ = result;
00104   }
00105 
00106   void
00107   ConfigurableInputSource::skip(int offset) {
00108     for (; offset < 0; ++offset) {
00109        eventID_ = eventID_.previous();
00110     }
00111     for (; offset > 0; --offset) {
00112        eventID_ = eventID_.next();
00113     }
00114   }
00115 
00116 
00117   void
00118   ConfigurableInputSource::setRun(RunNumber_t r) {
00119     // No need to check for invalid (zero) run number,
00120     // as this is a legitimate way of stopping the job.
00121     // Do nothing if the run is not changed.
00122     if (r != eventID_.run()) {
00123       eventID_ = EventID(r, zerothEvent_);
00124       luminosityBlock_ = origLuminosityBlockNumber_t_;
00125       numberEventsInThisRun_ = 0;
00126       numberEventsInThisLumi_ = 0;
00127       newRun_ = newLumi_ = true;
00128       resetLuminosityBlockPrincipal();
00129       resetRunPrincipal();
00130     }
00131   }
00132 
00133   void
00134   ConfigurableInputSource::beginRun(Run&)
00135   { }
00136 
00137   void
00138   ConfigurableInputSource::endRun(Run&)
00139   { }
00140 
00141   void
00142   ConfigurableInputSource::beginLuminosityBlock(LuminosityBlock &)
00143   { }
00144 
00145   void
00146   ConfigurableInputSource::endLuminosityBlock(LuminosityBlock &)
00147   { }
00148 
00149   void
00150   ConfigurableInputSource::setLumi(LuminosityBlockNumber_t lb) {
00151     // Protect against invalid lumi.
00152     if (lb == LuminosityBlockNumber_t()) {
00153         lb = origLuminosityBlockNumber_t_;
00154     }
00155     // Do nothing if the lumi block is not changed.
00156     if (lb != luminosityBlock_) {
00157       luminosityBlock_ = lb;
00158       numberEventsInThisLumi_ = 0;
00159       newLumi_ = true;
00160       resetLuminosityBlockPrincipal();
00161     }
00162     lumiSet_ = true;
00163   }
00164 
00165   void
00166   ConfigurableInputSource::rewind_() {
00167     luminosityBlock_ = origLuminosityBlockNumber_t_;
00168     presentTime_ = origTime_;
00169     eventID_ = origEventID_;
00170     numberEventsInThisRun_ = 0;
00171     numberEventsInThisLumi_ = 0;
00172     newRun_ = newLumi_ = true;
00173     resetLuminosityBlockPrincipal();
00174     resetRunPrincipal();
00175   }
00176     
00177   InputSource::ItemType 
00178   ConfigurableInputSource::getNextItemType() {
00179     if (newRun_) {
00180       if (eventID_.run() == RunNumber_t()) {
00181         ep_.reset();
00182         return IsStop;
00183       }
00184       return IsRun;
00185     }
00186     if (newLumi_) {
00187       return IsLumi;
00188     }
00189     if(ep_.get() != 0) return IsEvent;
00190     EventID oldEventID = eventID_;
00191     LuminosityBlockNumber_t oldLumi = luminosityBlock_;
00192     if (!eventSet_) {
00193       lumiSet_ = false;
00194       setRunAndEventInfo();
00195       eventSet_ = true;
00196     }
00197     if (eventID_.run() == RunNumber_t()) {
00198       ep_.reset();
00199       return IsStop;
00200     }
00201     if (oldEventID.run() != eventID_.run()) {
00202       //  New Run
00203       // reset these since this event is in the new run
00204       numberEventsInThisRun_ = 0;
00205       numberEventsInThisLumi_ = 0;
00206       // If the user did not explicitly set the luminosity block number,
00207       // reset it back to the beginning.
00208       if (!lumiSet_) {
00209         luminosityBlock_ = origLuminosityBlockNumber_t_;
00210       }
00211       newRun_ = newLumi_ = true;
00212       resetLuminosityBlockPrincipal();
00213       resetRunPrincipal();
00214       return IsRun;
00215     }
00216       // Same Run
00217     if (oldLumi != luminosityBlock_) {
00218       // New Lumi
00219       numberEventsInThisLumi_ = 0;
00220       newLumi_ = true;
00221       resetLuminosityBlockPrincipal();
00222       if (processingMode() != Runs) {
00223         return IsLumi;
00224       }
00225     }
00226     ++numberEventsInThisRun_;
00227     ++numberEventsInThisLumi_;
00228     reallyReadEvent(luminosityBlock_);
00229     if (ep_.get() == 0) {
00230       return IsStop;
00231     }
00232     eventSet_ = false;
00233     return IsEvent;
00234   }
00235 
00236   void
00237   ConfigurableInputSource::setRunAndEventInfo() {
00238     //NOTE: numberEventsInRun < 0 means go forever in this run
00239     if (numberEventsInRun_ < 1 || numberEventsInThisRun_ < numberEventsInRun_) {
00240       // same run
00241       eventID_ = eventID_.next();
00242       if (!(numberEventsInLumi_ < 1 || numberEventsInThisLumi_ < numberEventsInLumi_)) {
00243         // new lumi
00244         ++luminosityBlock_;
00245       }
00246     } else {
00247       // new run
00248       eventID_ = eventID_.nextRunFirstEvent();
00249     }
00250     presentTime_ += timeBetweenEvents_;
00251     if (eventCreationDelay_ > 0) {usleep(eventCreationDelay_);}
00252   }
00253 
00254 }

Generated on Tue Jun 9 17:35:53 2009 for CMSSW by  doxygen 1.5.4