CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/FWCore/Sources/src/RawInputSource.cc

Go to the documentation of this file.
00001 /*----------------------------------------------------------------------
00002 ----------------------------------------------------------------------*/
00003 
00004 #include "FWCore/Sources/interface/RawInputSource.h"
00005 
00006 #include "DataFormats/Provenance/interface/EventAuxiliary.h"
00007 #include "DataFormats/Provenance/interface/LuminosityBlockAuxiliary.h"
00008 #include "DataFormats/Provenance/interface/RunAuxiliary.h"
00009 #include "DataFormats/Provenance/interface/Timestamp.h"
00010 #include "FWCore/Framework/interface/Event.h"
00011 #include "FWCore/Framework/interface/EventPrincipal.h"
00012 
00013 namespace edm {
00014   RawInputSource::RawInputSource(ParameterSet const& pset, InputSourceDescription const& desc) :
00015     InputSource(pset, desc),
00016     runNumber_(RunNumber_t()),
00017     luminosityBlockNumber_(),
00018     newRun_(false),
00019     newLumi_(false),
00020     eventCached_(false) {
00021       setTimestamp(Timestamp::beginOfTime());
00022   }
00023 
00024   RawInputSource::~RawInputSource() {
00025   }
00026 
00027   boost::shared_ptr<RunAuxiliary>
00028   RawInputSource::readRunAuxiliary_() {
00029     newRun_ = false;
00030     return boost::shared_ptr<RunAuxiliary>(new RunAuxiliary(runNumber_, timestamp(), Timestamp::invalidTimestamp()));
00031   }
00032 
00033   boost::shared_ptr<LuminosityBlockAuxiliary>
00034   RawInputSource::readLuminosityBlockAuxiliary_() {
00035     newLumi_ = false;
00036     return boost::shared_ptr<LuminosityBlockAuxiliary>(new LuminosityBlockAuxiliary(
00037         runNumber_, luminosityBlockNumber_, timestamp(), Timestamp::invalidTimestamp()));
00038   }
00039 
00040   EventPrincipal*
00041   RawInputSource::readEvent_() {
00042     assert(eventCached_);
00043     eventCached_ = false;
00044     eventPrincipalCache()->setLuminosityBlockPrincipal(luminosityBlockPrincipal());
00045     return eventPrincipalCache();
00046   }
00047 
00048   std::auto_ptr<Event>
00049   RawInputSource::makeEvent(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event, Timestamp const& tstamp) {
00050     if(!runAuxiliary()) {
00051       newRun_ = newLumi_ = true;
00052       setRunAuxiliary(new RunAuxiliary(run, tstamp, Timestamp::invalidTimestamp()));
00053     }
00054     if(!luminosityBlockAuxiliary()) {
00055       setLuminosityBlockAuxiliary(new LuminosityBlockAuxiliary(run, lumi, tstamp, Timestamp::invalidTimestamp()));
00056       newLumi_ = true;
00057     }
00058     EventSourceSentry sentry(*this);
00059     EventAuxiliary aux(EventID(run, lumi, event), processGUID(), tstamp, true, EventAuxiliary::PhysicsTrigger);
00060     eventPrincipalCache()->fillEventPrincipal(aux, boost::shared_ptr<LuminosityBlockPrincipal>());
00061     eventCached_ = true;
00062     std::auto_ptr<Event> e(new Event(*eventPrincipalCache(), moduleDescription()));
00063     return e;
00064   }
00065 
00066   InputSource::ItemType
00067   RawInputSource::getNextItemType() {
00068     if(state() == IsInvalid) {
00069       return IsFile;
00070     }
00071     if(newRun_) {
00072       return IsRun;
00073     }
00074     if(newLumi_) {
00075       return IsLumi;
00076     }
00077     if(eventCached_) {
00078       return IsEvent;
00079     }
00080     std::auto_ptr<Event> e(readOneEvent());
00081     if(e.get() == 0) {
00082       return IsStop;
00083     } else {
00084       e->commit_();
00085     }
00086     if(e->run() != runNumber_) {
00087       newRun_ = newLumi_ = true;
00088       runNumber_ = e->run();
00089       luminosityBlockNumber_ = e->luminosityBlock();
00090       return IsRun;
00091     } else if(e->luminosityBlock() != luminosityBlockNumber_) {
00092       luminosityBlockNumber_ = e->luminosityBlock();
00093       newLumi_ = true;
00094       return IsLumi;
00095     }
00096     return IsEvent;
00097   }
00098 
00099   EventPrincipal*
00100   RawInputSource::readIt(EventID const&) {
00101       throw Exception(errors::LogicError, "RawInputSource::readEvent_(EventID const& eventID)")
00102         << "Random access read cannot be used for RawInputSource.\n"
00103         << "Contact a Framework developer.\n";
00104   }
00105 
00106   // Not yet implemented
00107   void
00108   RawInputSource::skip(int) {
00109       throw Exception(errors::LogicError, "RawInputSource::skip(int offset)")
00110         << "Random access skip cannot be used for RawInputSource\n"
00111         << "Contact a Framework developer.\n";
00112   }
00113 }