CMS 3D CMS Logo

InputSource.h

Go to the documentation of this file.
00001 #ifndef FWCore_Framework_InputSource_h
00002 #define FWCore_Framework_InputSource_h
00003 
00004 
00005 /*----------------------------------------------------------------------
00006   
00007 InputSource: Abstract interface for all input sources. Input
00008 sources are responsible for creating an EventPrincipal, using data
00009 controlled by the source, and external to the EventPrincipal itself.
00010 
00011 The InputSource is also responsible for dealing with the "process
00012 name list" contained within the EventPrincipal. Each InputSource has
00013 to know what "process" (HLT, PROD, USER, USER1, etc.) the program is
00014 part of. The InputSource is repsonsible for pushing this process name
00015 onto the end of the process name list.
00016 
00017 For now, we specify this process name to the constructor of the
00018 InputSource. This should be improved.
00019 
00020  Some questions about this remain:
00021 
00022    1. What should happen if we "rerun" a process? i.e., if "USER1" is
00023    already last in our input file, and we run again a job which claims
00024    to be "USER1", what should happen? For now, we just quietly add
00025    this to the history.
00026 
00027    2. Do we need to detect a problem with a history like:
00028          HLT PROD USER1 PROD
00029    or is it up to the user not to do something silly? Right now, there
00030    is no protection against such sillyness.
00031 
00032 Some examples of InputSource subclasses may be:
00033 
00034  1) EmptySource: creates EventPrincipals which contain no EDProducts.
00035  2) PoolSource: creates EventPrincipals which "contain" the data
00036     read from a POOL file. This source should provide for delayed loading
00037     of data, thus the quotation marks around contain.
00038  3) DAQInputSource: creats EventPrincipals which contain raw data, as
00039     delivered by the L1 trigger and event builder. 
00040 
00041 $Id: InputSource.h,v 1.48 2008/10/20 19:38:21 wmtan Exp $
00042 
00043 ----------------------------------------------------------------------*/
00044 
00045 #include <memory>
00046 #include <string>
00047 
00048 #include "boost/shared_ptr.hpp"
00049 #include "boost/utility.hpp"
00050 #include "sigc++/signal.h"
00051 
00052 #include "DataFormats/Provenance/interface/RunID.h"
00053 #include "DataFormats/Provenance/interface/LuminosityBlockID.h"
00054 #include "DataFormats/Provenance/interface/ModuleDescription.h"
00055 #include "DataFormats/Provenance/interface/Timestamp.h"
00056 #include "FWCore/Framework/interface/ProductRegistryHelper.h"
00057 #include "FWCore/Framework/interface/Frameworkfwd.h"
00058 
00059 namespace edm {
00060   class ParameterSet;
00061   class ActivityRegistry;
00062 
00063   class InputSource : private ProductRegistryHelper, private boost::noncopyable {
00064   public:
00065     enum ItemType {
00066         IsInvalid,
00067         IsStop,
00068         IsFile,
00069         IsRun,
00070         IsLumi,
00071         IsEvent,
00072         IsRepeat
00073     };
00074 
00075     enum ProcessingMode {
00076         Runs,
00077         RunsAndLumis,
00078         RunsLumisAndEvents
00079     };
00080 
00081     typedef ProductRegistryHelper::TypeLabelList TypeLabelList;
00083     explicit InputSource(ParameterSet const&, InputSourceDescription const&);
00084 
00086     virtual ~InputSource();
00087 
00088     ItemType nextItemType();
00089 
00092     std::auto_ptr<EventPrincipal> readEvent(boost::shared_ptr<LuminosityBlockPrincipal> lbp);
00093 
00095     std::auto_ptr<EventPrincipal> readEvent(EventID const&);
00096 
00098     boost::shared_ptr<LuminosityBlockPrincipal> readLuminosityBlock(boost::shared_ptr<RunPrincipal> rp);
00099 
00101     boost::shared_ptr<RunPrincipal> readRun();
00102 
00104     boost::shared_ptr<FileBlock> readFile();
00105 
00107     void closeFile();
00108 
00111     void skipEvents(int offset);
00112 
00114     void rewind() {
00115       doneReadAhead_ = false;
00116       state_ = IsInvalid;
00117       rewind_();
00118     }
00119 
00121     void wakeUp() {wakeUp_();}
00122 
00124     void setRunNumber(RunNumber_t r) {setRun(r);}
00125 
00127     void setLuminosityBlockNumber_t(LuminosityBlockNumber_t lb) {setLumi(lb);}
00128 
00130     void issueReports(EventID const& eventID, LuminosityBlockNumber_t const& lumi);
00131 
00133     void registerProducts();
00134 
00136     boost::shared_ptr<ProductRegistry const> productRegistry() const {return productRegistry_;}
00137     
00139     void repeat() {
00140       remainingEvents_ = maxEvents_;
00141       remainingLumis_ = maxLumis_;
00142       doneReadAhead_ = false;
00143     }
00144 
00147     int maxEvents() const {return maxEvents_;}
00148 
00151     int remainingEvents() const {return remainingEvents_;}
00152 
00155     int maxLuminosityBlocks() const {return maxLumis_;}
00156 
00159     int remainingLuminosityBlocks() const {return remainingLumis_;}
00160 
00162     ModuleDescription const& moduleDescription() const {return moduleDescription_;}
00163 
00165     ProcessConfiguration const& processConfiguration() const {return moduleDescription().processConfiguration();}
00166 
00168     bool const primary() const {return primary_;}
00169 
00171     std::string const& processGUID() const {return processGUID_;}
00172 
00174     void doBeginJob(EventSetup const&);
00175 
00177     void doEndJob();
00178 
00180     void doEndLumi(LuminosityBlockPrincipal& lbp);
00181     void doEndRun(RunPrincipal& rp);
00182 
00184     Timestamp const& timestamp() const {return time_;}
00185 
00187     RunNumber_t run() const;
00188 
00190     LuminosityBlockNumber_t luminosityBlock() const;
00191 
00193     ProcessingMode processingMode() const {return processingMode_;}
00194 
00196     boost::shared_ptr<ActivityRegistry> actReg() const {return actReg_;}
00197 
00198     using ProductRegistryHelper::produces;
00199     using ProductRegistryHelper::typeLabelList;
00200 
00201     class SourceSentry : private boost::noncopyable {
00202     public:
00203       typedef sigc::signal<void> Sig;
00204       SourceSentry(Sig& pre, Sig& post);
00205       ~SourceSentry();
00206     private:
00207       Sig& post_;
00208     };
00209 
00210     class EventSourceSentry {
00211     public:
00212       explicit EventSourceSentry(InputSource const& source);
00213     private:
00214       SourceSentry sentry_;
00215     };
00216 
00217     class LumiSourceSentry {
00218     public:
00219       explicit LumiSourceSentry(InputSource const& source);
00220     private:
00221       SourceSentry sentry_;
00222     };
00223 
00224     class RunSourceSentry {
00225     public:
00226       explicit RunSourceSentry(InputSource const& source);
00227     private:
00228       SourceSentry sentry_;
00229     };
00230 
00231     class FileOpenSentry {
00232     public:
00233       explicit FileOpenSentry(InputSource const& source);
00234     private:
00235       SourceSentry sentry_;
00236     };
00237 
00238     class FileCloseSentry {
00239     public:
00240       explicit FileCloseSentry(InputSource const& source);
00241     private:
00242       SourceSentry sentry_;
00243     };
00244 
00245   protected:
00247     void setTimestamp(Timestamp const& theTime) {time_ = theTime;}
00248 
00249     ProductRegistry & productRegistryUpdate() const {return const_cast<ProductRegistry &>(*productRegistry_);}
00250     ItemType state() const{return state_;}
00251     boost::shared_ptr<RunPrincipal> runPrincipal() const {return runPrincipal_;}
00252     boost::shared_ptr<LuminosityBlockPrincipal> luminosityBlockPrincipal() const {return lumiPrincipal_;}
00253     void setRunPrincipal(boost::shared_ptr<RunPrincipal> rp) {runPrincipal_ = rp;}
00254     void setLuminosityBlockPrincipal(boost::shared_ptr<LuminosityBlockPrincipal> lbp) {lumiPrincipal_ = lbp;}
00255     void resetRunPrincipal() {runPrincipal_.reset();}
00256     void resetLuminosityBlockPrincipal() {lumiPrincipal_.reset();}
00257     void reset() const {
00258       doneReadAhead_ = false;
00259       state_ = IsInvalid;
00260     }
00261 
00262   private:
00263     bool eventLimitReached() const {return remainingEvents_ == 0;}
00264     bool lumiLimitReached() const {return remainingLumis_ == 0;}
00265     bool limitReached() const {return eventLimitReached() || lumiLimitReached();}
00266     virtual ItemType getNextItemType() = 0;
00267     ItemType nextItemType_();
00268     virtual boost::shared_ptr<RunPrincipal> readRun_() = 0;
00269     virtual boost::shared_ptr<LuminosityBlockPrincipal> readLuminosityBlock_() = 0;
00270     virtual std::auto_ptr<EventPrincipal> readEvent_() = 0;
00271     virtual std::auto_ptr<EventPrincipal> readIt(EventID const&);
00272     virtual boost::shared_ptr<FileBlock> readFile_();
00273     virtual void closeFile_() {}
00274     virtual void skip(int);
00275     virtual void setRun(RunNumber_t r);
00276     virtual void setLumi(LuminosityBlockNumber_t lb);
00277     virtual void rewind_();
00278     virtual void wakeUp_();
00279     void preRead();
00280     void postRead(Event& event);
00281     virtual void endLuminosityBlock(LuminosityBlock &);
00282     virtual void endRun(Run &);
00283     virtual void beginJob(EventSetup const&);
00284     virtual void endJob();
00285 
00286   private:
00287 
00288     boost::shared_ptr<ActivityRegistry> actReg_;
00289     int maxEvents_;
00290     int remainingEvents_;
00291     int maxLumis_;
00292     int remainingLumis_;
00293     int readCount_;
00294     ProcessingMode processingMode_;
00295     ModuleDescription const moduleDescription_;
00296     boost::shared_ptr<ProductRegistry const> productRegistry_;
00297     bool const primary_;
00298     std::string processGUID_;
00299     Timestamp time_;
00300     mutable bool doneReadAhead_;
00301     mutable ItemType state_;
00302     mutable boost::shared_ptr<RunPrincipal>  runPrincipal_;
00303     mutable boost::shared_ptr<LuminosityBlockPrincipal>  lumiPrincipal_;
00304   };
00305 }
00306 
00307 #endif

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