CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PoolOutputModule.h
Go to the documentation of this file.
1 #ifndef IOPool_Output_PoolOutputModule_h
2 #define IOPool_Output_PoolOutputModule_h
3 
5 //
6 // Class PoolOutputModule. Output module to POOL file
7 //
8 // Oringinal Author: Luca Lista
9 // Current Author: Bill Tanenbaum
10 //
12 
13 #include <array>
14 #include <map>
15 #include <memory>
16 #include <set>
17 #include <string>
18 #include <vector>
19 #include <regex>
20 
30 
31 class TTree;
32 namespace edm {
33 
34  class EDGetToken;
35  class ModuleCallingContext;
36  class ParameterSet;
37  class RootOutputFile;
39  class ProductProvenanceRetriever;
40 
41  class PoolOutputModule : public one::OutputModule<WatchInputFiles> {
42  public:
44  explicit PoolOutputModule(ParameterSet const& ps);
45  ~PoolOutputModule() override;
46  PoolOutputModule(PoolOutputModule const&) = delete; // Disallow copying and moving
47  PoolOutputModule& operator=(PoolOutputModule const&) = delete; // Disallow copying and moving
48  std::string const& fileName() const { return fileName_; }
49  std::string const& logicalFileName() const { return logicalFileName_; }
50  int compressionLevel() const { return compressionLevel_; }
52  int basketSize() const { return basketSize_; }
54  int eventAutoFlushSize() const { return eventAutoFlushSize_; }
55  int splitLevel() const { return splitLevel_; }
56  std::string const& basketOrder() const { return basketOrder_; }
57  int treeMaxVirtualSize() const { return treeMaxVirtualSize_; }
60  bool mergeJob() const { return mergeJob_; }
61  DropMetaData const& dropMetaData() const { return dropMetaData_; }
62  std::string const& catalog() const { return catalog_; }
63  std::string const& moduleLabel() const { return moduleLabel_; }
64  unsigned int maxFileSize() const { return maxFileSize_; }
65  int inputFileCount() const { return inputFileCount_; }
66  int whyNotFastClonable() const { return whyNotFastClonable_; }
67 
68  std::string const& currentFileName() const;
69 
71  static void fillDescriptions(ConfigurationDescriptions& descriptions);
72 
73  using OutputModule::selectorConfig;
74 
75  struct AuxItem {
76  AuxItem();
77  ~AuxItem() {}
79  };
80  using AuxItemArray = std::array<AuxItem, numberOfRunLumiEventProductTrees>;
81  AuxItemArray const& auxItems() const { return auxItems_; }
82 
83  struct OutputItem {
84  class Sorter {
85  public:
86  explicit Sorter(TTree* tree);
87  bool operator()(OutputItem const& lh, OutputItem const& rh) const;
88 
89  private:
90  std::shared_ptr<std::map<std::string, int>> treeMap_;
91  };
92 
93  explicit OutputItem(BranchDescription const* bd, EDGetToken const& token, int splitLevel, int basketSize);
94 
96  std::string const& branchName() const { return branchDescription_->branchName(); }
97 
98  bool operator<(OutputItem const& rh) const { return *branchDescription_ < *rh.branchDescription_; }
99 
101  EDGetToken token() const { return token_; }
102  void const* const product() const { return product_; }
103  void const*& product() { return product_; }
104  void setProduct(void const* iProduct) { product_ = iProduct; }
105  int splitLevel() const { return splitLevel_; }
106  int basketSize() const { return basketSize_; }
107 
108  private:
111  void const* product_;
114  };
115 
116  using OutputItemList = std::vector<OutputItem>;
117 
119  SpecialSplitLevelForBranch(std::string const& iBranchName, int iSplitLevel)
120  : branch_(convert(iBranchName)),
121  splitLevel_(iSplitLevel < 1 ? 1 : iSplitLevel) //minimum is 1
122  {}
123  bool match(std::string const& iBranchName) const;
124  std::regex convert(std::string const& iGlobBranchExpression) const;
125 
126  std::regex branch_;
128  };
129 
130  std::vector<OutputItemList> const& selectedOutputItemList() const { return selectedOutputItemList_; }
131 
132  std::vector<OutputItemList>& selectedOutputItemList() { return selectedOutputItemList_; }
133 
134  BranchChildren const& branchChildren() const { return branchChildren_; }
135 
136  protected:
138  bool shouldWeCloseFile() const override;
139  void write(EventForOutput const& e) override;
140 
141  virtual std::pair<std::string, std::string> physicalAndLogicalNameForNewFile();
142  virtual void doExtrasAfterCloseFile();
143 
144  private:
146  ModuleCallingContext const& iModuleCallingContext,
147  Principal const& iPrincipal) const override;
148 
149  void openFile(FileBlock const& fb) override;
150  void respondToOpenInputFile(FileBlock const& fb) override;
151  void respondToCloseInputFile(FileBlock const& fb) override;
152  void writeLuminosityBlock(LuminosityBlockForOutput const&) override;
153  void writeRun(RunForOutput const&) override;
154  void writeProcessBlock(ProcessBlockForOutput const&) override;
155  bool isFileOpen() const override;
156  void reallyOpenFile();
157  void reallyCloseFile() override;
158  void beginJob() override;
159 
160  void setProcessesWithSelectedMergeableRunProducts(std::set<std::string> const&) override;
161 
162  using BranchParents = std::map<BranchID, std::set<ParentageID>>;
163  void updateBranchParentsForOneBranch(ProductProvenanceRetriever const* provRetriever, BranchID const& branchID);
164  void updateBranchParents(EventForOutput const& e);
165  void fillDependencyGraph();
166 
167  void startEndFile();
168  void writeFileFormatVersion();
169  void writeFileIdentifier();
170  void writeIndexIntoFile();
175  void writeParentageRegistry();
179  void writeEventAuxiliary();
181  void finishEndFile();
182 
183  void fillSelectedItemList(BranchType branchtype,
184  std::string const& processName,
185  TTree* theInputTree,
186  OutputItemList&);
187  void beginInputFile(FileBlock const& fb);
188 
191  std::vector<OutputItemList> selectedOutputItemList_;
192  std::vector<SpecialSplitLevelForBranch> specialSplitLevelForBranches_;
196  unsigned int const maxFileSize_;
197  int const compressionLevel_;
199  int const basketSize_;
202  int const splitLevel_;
213  std::vector<BranchID> producedBranches_;
216  bool mergeJob_;
220  };
221 } // namespace edm
222 
223 #endif
void openFile(FileBlock const &fb) override
std::array< AuxItem, numberOfRunLumiEventProductTrees > AuxItemArray
virtual std::pair< std::string, std::string > physicalAndLogicalNameForNewFile()
std::string const & branchName() const
BranchDescription const * branchDescription_
std::string const compressionAlgorithm_
int eventAutoFlushSize() const
std::string const & catalog() const
void write(EventForOutput const &e) override
edm::propagate_const< std::unique_ptr< RootOutputFile > > rootOutputFile_
int compressionLevel() const
int inputFileCount() const
std::string const catalog_
std::vector< SpecialSplitLevelForBranch > specialSplitLevelForBranches_
PoolOutputModule & operator=(PoolOutputModule const &)=delete
void setProcessesWithSelectedMergeableRunProducts(std::set< std::string > const &) override
std::string const & moduleLabel() const
void updateBranchParents(EventForOutput const &e)
DropMetaData const & dropMetaData() const
BranchChildren branchChildren_
void writeRun(RunForOutput const &) override
std::string const & fileName() const
std::string const moduleLabel_
bool int lh
Definition: SIMDVec.h:20
virtual void doExtrasAfterCloseFile()
std::string const & logicalFileName() const
BranchType
Definition: BranchType.h:11
bool compactEventAuxiliary() const
std::regex convert(std::string const &iGlobBranchExpression) const
PoolOutputModule(ParameterSet const &ps)
bool overrideInputFileSplitLevels() const
void updateBranchParentsForOneBranch(ProductProvenanceRetriever const *provRetriever, BranchID const &branchID)
std::vector< OutputItemList > const & selectedOutputItemList() const
bool operator()(OutputItem const &lh, OutputItem const &rh) const
void preActionBeforeRunEventAsync(WaitingTaskHolder iTask, ModuleCallingContext const &iModuleCallingContext, Principal const &iPrincipal) const override
std::string const & currentFileName() const
bool operator<(OutputItem const &rh) const
std::string const & compressionAlgorithm() const
std::vector< BranchID > producedBranches_
std::vector< OutputItemList > selectedOutputItemList_
std::string const & basketOrder() const
OutputItem(BranchDescription const *bd, EDGetToken const &token, int splitLevel, int basketSize)
std::string const & branchName() const
void writeStoredMergeableRunProductMetadata()
BranchID const & branchID() const
BranchParents branchParents_
unsigned int maxFileSize() const
int eventAuxiliaryBasketSize() const
BranchDescription const * branchDescription() const
unsigned int const maxFileSize_
std::map< BranchID, std::set< ParentageID >> BranchParents
std::string const & processName() const
BranchChildren const & branchChildren() const
SpecialSplitLevelForBranch(std::string const &iBranchName, int iSplitLevel)
bool shouldWeCloseFile() const override
allow inheriting classes to override but still be able to call this method in the overridden version ...
void respondToCloseInputFile(FileBlock const &fb) override
bool isFileOpen() const override
void beginJob() override
void reallyCloseFile() override
void const *const product() const
AuxItemArray const & auxItems() const
std::string const fileName_
void setProduct(void const *iProduct)
std::shared_ptr< std::map< std::string, int > > treeMap_
std::string const logicalFileName_
void beginInputFile(FileBlock const &fb)
std::vector< OutputItem > OutputItemList
void respondToOpenInputFile(FileBlock const &fb) override
void writeProcessBlock(ProcessBlockForOutput const &) override
int whyNotFastClonable() const
void fillSelectedItemList(BranchType branchtype, std::string const &processName, TTree *theInputTree, OutputItemList &)
std::vector< OutputItemList > & selectedOutputItemList()
static void fillDescriptions(ConfigurationDescriptions &descriptions)
int treeMaxVirtualSize() const
bool match(std::string const &iBranchName) const
static void fillDescription(ParameterSetDescription &desc)
std::vector< std::string > processesWithSelectedMergeableRunProducts_
RootServiceChecker rootServiceChecker_
void writeLuminosityBlock(LuminosityBlockForOutput const &) override