CMS 3D CMS Logo

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