CMS 3D CMS Logo

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 noexcept 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_;
221  };
222 } // namespace edm
223 
224 #endif
void openFile(FileBlock const &fb) override
std::array< AuxItem, numberOfRunLumiEventProductTrees > AuxItemArray
virtual std::pair< std::string, std::string > physicalAndLogicalNameForNewFile()
bool operator<(OutputItem const &rh) const
BranchDescription const * branchDescription_
std::string const compressionAlgorithm_
std::string const & moduleLabel() const
void write(EventForOutput const &e) override
edm::propagate_const< std::unique_ptr< RootOutputFile > > rootOutputFile_
BranchID const & branchID() const
std::string const catalog_
std::vector< SpecialSplitLevelForBranch > specialSplitLevelForBranches_
void const *const product() const
PoolOutputModule & operator=(PoolOutputModule const &)=delete
void setProcessesWithSelectedMergeableRunProducts(std::set< std::string > const &) override
BranchChildren const & branchChildren() const
void updateBranchParents(EventForOutput const &e)
BranchChildren branchChildren_
void writeRun(RunForOutput const &) override
bool overrideInputFileSplitLevels() const
std::string const moduleLabel_
bool int lh
Definition: SIMDVec.h:27
int treeMaxVirtualSize() const
virtual void doExtrasAfterCloseFile()
std::string const & currentFileName() const
BranchType
Definition: BranchType.h:11
bool compactEventAuxiliary() const
unsigned int maxFileSize() const
std::string const & basketOrder() const
void preActionBeforeRunEventAsync(WaitingTaskHolder iTask, ModuleCallingContext const &iModuleCallingContext, Principal const &iPrincipal) const noexcept override
PoolOutputModule(ParameterSet const &ps)
void updateBranchParentsForOneBranch(ProductProvenanceRetriever const *provRetriever, BranchID const &branchID)
int eventAuxiliaryBasketSize() const
std::string const & branchName() const
std::vector< BranchID > producedBranches_
std::vector< OutputItemList > selectedOutputItemList_
std::map< BranchID, std::set< ParentageID > > BranchParents
std::regex convert(std::string const &iGlobBranchExpression) const
OutputItem(BranchDescription const *bd, EDGetToken const &token, int splitLevel, int basketSize)
std::vector< OutputItemList > const & selectedOutputItemList() const
void writeStoredMergeableRunProductMetadata()
BranchParents branchParents_
DropMetaData const & dropMetaData() const
std::string const & compressionAlgorithm() const
BranchDescription const * branchDescription() const
bool operator()(OutputItem const &lh, OutputItem const &rh) const
unsigned int const maxFileSize_
std::string const & catalog() 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
std::string const fileName_
void setProduct(void const *iProduct)
std::string const & branchName() const
std::string const & processName() const
bool match(std::string const &iBranchName) const
HLT enums.
std::shared_ptr< std::map< std::string, int > > treeMap_
std::string const logicalFileName_
std::string const & logicalFileName() const
int eventAutoFlushSize() const
int whyNotFastClonable() const
void beginInputFile(FileBlock const &fb)
std::string const & fileName() const
int compressionLevel() const
Definition: tree.py:1
std::vector< OutputItem > OutputItemList
void respondToOpenInputFile(FileBlock const &fb) override
void writeProcessBlock(ProcessBlockForOutput const &) override
void fillSelectedItemList(BranchType branchtype, std::string const &processName, TTree *theInputTree, OutputItemList &)
std::vector< OutputItemList > & selectedOutputItemList()
static void fillDescriptions(ConfigurationDescriptions &descriptions)
static void fillDescription(ParameterSetDescription &desc)
std::vector< std::string > processesWithSelectedMergeableRunProducts_
RootServiceChecker rootServiceChecker_
AuxItemArray const & auxItems() const
void writeLuminosityBlock(LuminosityBlockForOutput const &) override