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  DropMetaData const& dropMetaData() const { return dropMetaData_; }
61  std::string const& catalog() const { return catalog_; }
62  std::string const& moduleLabel() const { return moduleLabel_; }
63  unsigned int maxFileSize() const { return maxFileSize_; }
64  int inputFileCount() const { return inputFileCount_; }
65  int whyNotFastClonable() const { return whyNotFastClonable_; }
66 
67  std::string const& currentFileName() const;
68 
70  static void fillDescriptions(ConfigurationDescriptions& descriptions);
71 
72  using OutputModule::selectorConfig;
73 
74  struct AuxItem {
75  AuxItem();
76  ~AuxItem() {}
78  };
79  using AuxItemArray = std::array<AuxItem, numberOfRunLumiEventProductTrees>;
80  AuxItemArray const& auxItems() const { return auxItems_; }
81 
82  struct OutputItem {
83  class Sorter {
84  public:
85  explicit Sorter(TTree* tree);
86  bool operator()(OutputItem const& lh, OutputItem const& rh) const;
87 
88  private:
89  std::shared_ptr<std::map<std::string, int>> treeMap_;
90  };
91 
92  explicit OutputItem(BranchDescription const* bd, EDGetToken const& token, int splitLevel, int basketSize);
93 
95  std::string const& branchName() const { return branchDescription_->branchName(); }
96 
97  bool operator<(OutputItem const& rh) const { return *branchDescription_ < *rh.branchDescription_; }
98 
100  EDGetToken token() const { return token_; }
101  void const* const product() const { return product_; }
102  void const*& product() { return product_; }
103  void setProduct(void const* iProduct) { product_ = iProduct; }
104  int splitLevel() const { return splitLevel_; }
105  int basketSize() const { return basketSize_; }
106 
107  private:
110  void const* product_;
113  };
114 
115  using OutputItemList = std::vector<OutputItem>;
116 
118  SpecialSplitLevelForBranch(std::string const& iBranchName, int iSplitLevel)
119  : branch_(convert(iBranchName)),
120  splitLevel_(iSplitLevel < 1 ? 1 : iSplitLevel) //minimum is 1
121  {}
122  bool match(std::string const& iBranchName) const;
123  std::regex convert(std::string const& iGlobBranchExpression) const;
124 
125  std::regex branch_;
127  };
128 
129  std::vector<OutputItemList> const& selectedOutputItemList() const { return selectedOutputItemList_; }
130 
131  std::vector<OutputItemList>& selectedOutputItemList() { return selectedOutputItemList_; }
132 
133  BranchChildren const& branchChildren() const { return branchChildren_; }
134 
135  protected:
137  bool shouldWeCloseFile() const override;
138  void write(EventForOutput const& e) override;
139 
140  virtual std::pair<std::string, std::string> physicalAndLogicalNameForNewFile();
141  virtual void doExtrasAfterCloseFile();
142 
143  private:
145  ModuleCallingContext const& iModuleCallingContext,
146  Principal const& iPrincipal) const override;
147 
148  void openFile(FileBlock const& fb) override;
149  void respondToOpenInputFile(FileBlock const& fb) override;
150  void respondToCloseInputFile(FileBlock const& fb) override;
151  void writeLuminosityBlock(LuminosityBlockForOutput const&) override;
152  void writeRun(RunForOutput const&) override;
153  void writeProcessBlock(ProcessBlockForOutput const&) override;
154  bool isFileOpen() const override;
155  void reallyOpenFile();
156  void reallyCloseFile() override;
157  void beginJob() override;
158 
159  void setProcessesWithSelectedMergeableRunProducts(std::set<std::string> const&) override;
160 
161  using BranchParents = std::map<BranchID, std::set<ParentageID>>;
162  void updateBranchParentsForOneBranch(ProductProvenanceRetriever const* provRetriever, BranchID const& branchID);
163  void updateBranchParents(EventForOutput const& e);
164  void fillDependencyGraph();
165 
166  void startEndFile();
167  void writeFileFormatVersion();
168  void writeFileIdentifier();
169  void writeIndexIntoFile();
174  void writeParentageRegistry();
178  void writeEventAuxiliary();
180  void finishEndFile();
181 
182  void fillSelectedItemList(BranchType branchtype,
183  std::string const& processName,
184  TTree* theInputTree,
185  OutputItemList&);
186  void beginInputFile(FileBlock const& fb);
187 
190  std::vector<OutputItemList> selectedOutputItemList_;
191  std::vector<SpecialSplitLevelForBranch> specialSplitLevelForBranches_;
195  unsigned int const maxFileSize_;
196  int const compressionLevel_;
198  int const basketSize_;
201  int const splitLevel_;
212  std::vector<BranchID> producedBranches_;
218  };
219 } // namespace edm
220 
221 #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