CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/FWCore/Framework/interface/OutputModule.h

Go to the documentation of this file.
00001 #ifndef FWCore_Framework_OutputModule_h
00002 #define FWCore_Framework_OutputModule_h
00003 
00004 /*----------------------------------------------------------------------
00005 
00006 OutputModule: The base class of all "modules" that write Events to an
00007 output stream.
00008 
00009 ----------------------------------------------------------------------*/
00010 
00011 #include <vector>
00012 
00013 #include "boost/array.hpp"
00014 #include "boost/utility.hpp"
00015 
00016 #include "DataFormats/Provenance/interface/BranchChildren.h"
00017 #include "DataFormats/Provenance/interface/ParentageID.h"
00018 #include "DataFormats/Provenance/interface/ModuleDescription.h"
00019 #include "DataFormats/Provenance/interface/Selections.h"
00020 
00021 #include "FWCore/Framework/interface/CachedProducts.h"
00022 #include "FWCore/Framework/interface/Frameworkfwd.h"
00023 #include "FWCore/Framework/interface/GroupSelectorRules.h"
00024 #include "FWCore/Framework/interface/GroupSelector.h"
00025 #include "FWCore/ParameterSet/interface/ParameterSetfwd.h"
00026 
00027 #include <string>
00028 
00029 namespace edm {
00030 
00031   typedef detail::CachedProducts::handle_t Trig;
00032 
00033   std::vector<std::string> const& getAllTriggerNames();
00034 
00035 
00036   class OutputModule : private boost::noncopyable {
00037   public:
00038     template <typename T> friend class WorkerT;
00039     friend class OutputWorker;
00040     typedef OutputModule ModuleType;
00041     typedef OutputWorker WorkerType;
00042 
00043     explicit OutputModule(ParameterSet const& pset);
00044     virtual ~OutputModule();
00047     int maxEvents() const {return maxEvents_;}
00048 
00051     int remainingEvents() const {return remainingEvents_;}
00052 
00053     bool selected(BranchDescription const& desc) const;
00054 
00055     void selectProducts();
00056     std::string const& processName() const {return process_name_;}
00057     SelectionsArray const& keptProducts() const {return keptProducts_;}
00058     boost::array<bool, NumBranchTypes> const& hasNewlyDroppedBranch() const {return hasNewlyDroppedBranch_;}
00059 
00060     static void fillDescription(ParameterSetDescription & desc);
00061     static void fillDescriptions(ConfigurationDescriptions& descriptions);
00062     static const std::string& baseType();
00063 
00064     BranchChildren const& branchChildren() const {return branchChildren_;}
00065 
00066     bool wantAllEvents() const {return wantAllEvents_;}
00067 
00068   protected:
00069     //Trig const& getTriggerResults(Event const& ep) const;
00070     Trig getTriggerResults(Event const& ep) const;
00071 
00072     // This function is needed for compatibility with older code. We
00073     // need to clean up the use of Event and EventPrincipal, to avoid
00074     // creation of multiple Event objects when handling a single
00075     // event.
00076     Trig getTriggerResults(EventPrincipal const& ep) const;
00077 
00078     // The returned pointer will be null unless the this is currently
00079     // executing its event loop function ('write').
00080     CurrentProcessingContext const* currentContext() const;
00081 
00082     ModuleDescription const& description() const;
00083 
00084     ParameterSetID selectorConfig() const { return selector_config_id_; }
00085 
00086   private:
00087 
00088     int maxEvents_;
00089     int remainingEvents_;
00090 
00091     // TODO: Give OutputModule
00092     // an interface (protected?) that supplies client code with the
00093     // needed functionality *without* giving away implementation
00094     // details ... don't just return a reference to keptProducts_, because
00095     // we are looking to have the flexibility to change the
00096     // implementation of keptProducts_ without modifying clients. When this
00097     // change is made, we'll have a one-time-only task of modifying
00098     // clients (classes derived from OutputModule) to use the
00099     // newly-introduced interface.
00100     // TODO: Consider using shared pointers here?
00101 
00102     // keptProducts_ are pointers to the BranchDescription objects describing
00103     // the branches we are to write.
00104     //
00105     // We do not own the BranchDescriptions to which we point.
00106     SelectionsArray keptProducts_;
00107     boost::array<bool, NumBranchTypes> hasNewlyDroppedBranch_;
00108 
00109     std::string process_name_;
00110     GroupSelectorRules groupSelectorRules_;
00111     GroupSelector groupSelector_;
00112     ModuleDescription moduleDescription_;
00113 
00114     // We do not own the pointed-to CurrentProcessingContext.
00115     CurrentProcessingContext const* current_context_;
00116 
00117     //This will store TriggerResults objects for the current event.
00118     // mutable std::vector<Trig> prods_;
00119     mutable bool prodsValid_;
00120 
00121     bool wantAllEvents_;
00122     mutable detail::CachedProducts selectors_;
00123     // ID of the ParameterSet that configured the event selector
00124     // subsystem.
00125     ParameterSetID selector_config_id_;
00126 
00127     typedef std::map<BranchID, std::set<ParentageID> > BranchParents;
00128     BranchParents branchParents_;
00129 
00130     BranchChildren branchChildren_;
00131 
00132     //------------------------------------------------------------------
00133     // private member functions
00134     //------------------------------------------------------------------
00135     void configure(OutputModuleDescription const& desc);
00136     void doBeginJob();
00137     void doEndJob();
00138     bool doEvent(EventPrincipal const& ep, EventSetup const& c,
00139                  CurrentProcessingContext const* cpc);
00140     bool doBeginRun(RunPrincipal const& rp, EventSetup const& c,
00141                  CurrentProcessingContext const* cpc);
00142     bool doEndRun(RunPrincipal const& rp, EventSetup const& c,
00143                  CurrentProcessingContext const* cpc);
00144     bool doBeginLuminosityBlock(LuminosityBlockPrincipal const& lbp, EventSetup const& c,
00145                  CurrentProcessingContext const* cpc);
00146     bool doEndLuminosityBlock(LuminosityBlockPrincipal const& lbp, EventSetup const& c,
00147                  CurrentProcessingContext const* cpc);
00148     void doWriteRun(RunPrincipal const& rp);
00149     void doWriteLuminosityBlock(LuminosityBlockPrincipal const& lbp);
00150     void doOpenFile(FileBlock const& fb);
00151     void doRespondToOpenInputFile(FileBlock const& fb);
00152     void doRespondToCloseInputFile(FileBlock const& fb);
00153     void doRespondToOpenOutputFiles(FileBlock const& fb);
00154     void doRespondToCloseOutputFiles(FileBlock const& fb);
00155     void doPreForkReleaseResources();
00156     void doPostForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren);
00157 
00158     std::string workerType() const {return "OutputWorker";}
00159 
00161     void doCloseFile();
00162 
00165     void maybeOpenFile();
00166 
00167 
00168     // Do the end-of-file tasks; this is only called internally, after
00169     // the appropriate tests have been done.
00170     void reallyCloseFile();
00171 
00172     void registerAnyProducts(OutputModule const*, ProductRegistry const*) {}
00173 
00175     virtual bool shouldWeCloseFile() const {return false;}
00176 
00177     virtual void write(EventPrincipal const& e) = 0;
00178     virtual void beginJob(){}
00179     virtual void endJob(){}
00180     virtual void beginRun(RunPrincipal const& r){}
00181     virtual void endRun(RunPrincipal const& r){}
00182     virtual void writeRun(RunPrincipal const& r) = 0;
00183     virtual void beginLuminosityBlock(LuminosityBlockPrincipal const& lb){}
00184     virtual void endLuminosityBlock(LuminosityBlockPrincipal const& lb){}
00185     virtual void writeLuminosityBlock(LuminosityBlockPrincipal const& lb) = 0;
00186     virtual void openFile(FileBlock const& fb) {}
00187     virtual void respondToOpenInputFile(FileBlock const& fb) {}
00188     virtual void respondToCloseInputFile(FileBlock const& fb) {}
00189     virtual void respondToOpenOutputFiles(FileBlock const& fb) {}
00190     virtual void respondToCloseOutputFiles(FileBlock const& fb) {}
00191     virtual void preForkReleaseResources() {}
00192     virtual void postForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren) {}
00193 
00194     virtual bool isFileOpen() const { return true; }
00195 
00196     virtual void doOpenFile() { }
00197 
00198     void setModuleDescription(ModuleDescription const& md) {
00199       moduleDescription_ = md;
00200     }
00201 
00202     void updateBranchParents(EventPrincipal const& ep);
00203     void fillDependencyGraph();
00204 
00205     bool limitReached() const {return remainingEvents_ == 0;}
00206 
00207     // The following member functions are part of the Template Method
00208     // pattern, used for implementing doCloseFile() and maybeEndFile().
00209 
00210     virtual void startEndFile() {}
00211     virtual void writeFileFormatVersion() {}
00212     virtual void writeFileIdentifier() {}
00213     virtual void writeIndexIntoFile() {}
00214     virtual void writeProcessConfigurationRegistry() {}
00215     virtual void writeProcessHistoryRegistry() {}
00216     virtual void writeParameterSetRegistry() {}
00217     virtual void writeBranchIDListRegistry() {}
00218     virtual void writeParentageRegistry() {}
00219     virtual void writeProductDescriptionRegistry() {}
00220     virtual void writeProductDependencies() {}
00221     virtual void writeBranchMapper() {}
00222     virtual void finishEndFile() {}
00223   };
00224 }
00225 
00226 //this is included after the class definition since this header also needs to know about OutputModule
00227 // we put this here since all OutputModules need this header to create their plugin
00228 #include "FWCore/Framework/src/OutputWorker.h"
00229 
00230 #endif