00001 #ifndef FWCore_Framework_OutputModule_h
00002 #define FWCore_Framework_OutputModule_h
00003
00004
00005
00006
00007
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/BranchID.h"
00018 #include "DataFormats/Provenance/interface/EntryDescriptionID.h"
00019 #include "DataFormats/Provenance/interface/BranchType.h"
00020 #include "DataFormats/Provenance/interface/ModuleDescription.h"
00021 #include "DataFormats/Provenance/interface/Selections.h"
00022
00023 #include "FWCore/Framework/interface/CachedProducts.h"
00024 #include "FWCore/Framework/interface/Frameworkfwd.h"
00025 #include "FWCore/Framework/interface/GroupSelectorRules.h"
00026 #include "FWCore/Framework/interface/GroupSelector.h"
00027 #include "FWCore/Framework/interface/OutputModuleDescription.h"
00028 #include "FWCore/Framework/src/OutputWorker.h"
00029 #include "FWCore/ParameterSet/interface/ParameterSetfwd.h"
00030
00031 namespace edm {
00032
00033 typedef edm::detail::CachedProducts::handle_t Trig;
00034
00035 std::vector<std::string> const& getAllTriggerNames();
00036
00037
00038 class OutputModule : private boost::noncopyable {
00039 public:
00040 template <typename T> friend class WorkerT;
00041 friend class OutputWorker;
00042 typedef OutputModule ModuleType;
00043 typedef OutputWorker WorkerType;
00044
00045 explicit OutputModule(ParameterSet const& pset);
00046 virtual ~OutputModule();
00049 int maxEvents() const {return maxEvents_;}
00050
00053 int remainingEvents() const {return remainingEvents_;}
00054
00055 bool selected(BranchDescription const& desc) const;
00056
00057 unsigned int nextID() const;
00058 void selectProducts();
00059 std::string const& processName() const {return process_name_;}
00060 SelectionsArray const& keptProducts() const {return keptProducts_;}
00061 boost::array<bool, NumBranchTypes> const& hasNewlyDroppedBranch() const {return hasNewlyDroppedBranch_;}
00062
00063 static void fillDescription(edm::ParameterSetDescription&);
00064
00065 BranchChildren const& branchChildren() const {return branchChildren_;}
00066
00067 protected:
00068
00069 Trig getTriggerResults(Event const& ep) const;
00070
00071
00072
00073
00074
00075 Trig getTriggerResults(EventPrincipal const& ep) const;
00076
00077
00078
00079 CurrentProcessingContext const* currentContext() const;
00080
00081 ModuleDescription const& description() const;
00082
00083 bool wantAllEvents() const {return wantAllEvents_;}
00084
00085 ParameterSetID selectorConfig() const { return selector_config_id_; }
00086
00087 private:
00088
00089 int maxEvents_;
00090 int remainingEvents_;
00091
00092 unsigned int nextID_;
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108 SelectionsArray keptProducts_;
00109
00110 boost::array<bool, NumBranchTypes> hasNewlyDroppedBranch_;
00111
00112 std::string process_name_;
00113 GroupSelectorRules groupSelectorRules_;
00114 GroupSelector groupSelector_;
00115 ModuleDescription moduleDescription_;
00116
00117
00118 CurrentProcessingContext const* current_context_;
00119
00120
00121
00122 mutable bool prodsValid_;
00123
00124 bool wantAllEvents_;
00125 mutable detail::CachedProducts selectors_;
00126
00127
00128 ParameterSetID selector_config_id_;
00129
00130 typedef std::map<BranchID, std::set<EntryDescriptionID> > BranchParents;
00131 BranchParents branchParents_;
00132
00133 BranchChildren branchChildren_;
00134
00135
00136
00137
00138 void configure(OutputModuleDescription const& desc);
00139 void doBeginJob(EventSetup const&);
00140 void doEndJob();
00141 bool doEvent(EventPrincipal const& ep, EventSetup const& c,
00142 CurrentProcessingContext const* cpc);
00143 bool doBeginRun(RunPrincipal const& rp, EventSetup const& c,
00144 CurrentProcessingContext const* cpc);
00145 bool doEndRun(RunPrincipal const& rp, EventSetup const& c,
00146 CurrentProcessingContext const* cpc);
00147 bool doBeginLuminosityBlock(LuminosityBlockPrincipal const& lbp, EventSetup const& c,
00148 CurrentProcessingContext const* cpc);
00149 bool doEndLuminosityBlock(LuminosityBlockPrincipal const& lbp, EventSetup const& c,
00150 CurrentProcessingContext const* cpc);
00151 void doWriteRun(RunPrincipal const& rp);
00152 void doWriteLuminosityBlock(LuminosityBlockPrincipal const& lbp);
00153 void doOpenFile(FileBlock const& fb);
00154 void doRespondToOpenInputFile(FileBlock const& fb);
00155 void doRespondToCloseInputFile(FileBlock const& fb);
00156 void doRespondToOpenOutputFiles(FileBlock const& fb);
00157 void doRespondToCloseOutputFiles(FileBlock const& fb);
00158
00159 std::string workerType() const {return "OutputWorker";}
00160
00162 void doCloseFile();
00163
00166 void maybeOpenFile();
00167
00168
00169
00170
00171 void reallyCloseFile();
00172
00173 void registerAnyProducts(boost::shared_ptr<OutputModule>const&, ProductRegistry const*) {}
00174
00176 virtual bool shouldWeCloseFile() const {return false;}
00177
00178 virtual void write(EventPrincipal const& e) = 0;
00179 virtual void beginJob(EventSetup const&){}
00180 virtual void endJob(){}
00181 virtual void beginRun(RunPrincipal const& r){}
00182 virtual void endRun(RunPrincipal const& r){}
00183 virtual void writeRun(RunPrincipal const& r) = 0;
00184 virtual void beginLuminosityBlock(LuminosityBlockPrincipal const& lb){}
00185 virtual void endLuminosityBlock(LuminosityBlockPrincipal const& lb){}
00186 virtual void writeLuminosityBlock(LuminosityBlockPrincipal const& lb) = 0;
00187 virtual void openFile(FileBlock const& fb) {}
00188 virtual void respondToOpenInputFile(FileBlock const& fb) {}
00189 virtual void respondToCloseInputFile(FileBlock const& fb) {}
00190 virtual void respondToOpenOutputFiles(FileBlock const& fb) {}
00191 virtual void respondToCloseOutputFiles(FileBlock const& fb) {}
00192
00193 virtual bool isFileOpen() const { return true; }
00194
00195 virtual void doOpenFile() { }
00196
00197 void setModuleDescription(ModuleDescription const& md) {
00198 moduleDescription_ = md;
00199 }
00200
00201 void updateBranchParents(EventPrincipal const& ep);
00202 void fillDependencyGraph();
00203
00204 bool limitReached() const {return remainingEvents_ == 0;}
00205
00206
00207
00208
00209 virtual void startEndFile() {}
00210 virtual void writeFileFormatVersion() {}
00211 virtual void writeFileIdentifier() {}
00212 virtual void writeFileIndex() {}
00213 virtual void writeEventHistory() {}
00214 virtual void writeProcessConfigurationRegistry() {}
00215 virtual void writeProcessHistoryRegistry() {}
00216 virtual void writeModuleDescriptionRegistry() {}
00217 virtual void writeParameterSetRegistry() {}
00218 virtual void writeProductDescriptionRegistry() {}
00219 virtual void writeProductDependencies() {}
00220 virtual void writeEntryDescriptions() {}
00221 virtual void writeBranchMapper() {}
00222 virtual void finishEndFile() {}
00223 };
00224 }
00225
00226 #endif