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 
28 
29 class TTree;
30 namespace edm {
31 
32  class EDGetToken;
33  class ModuleCallingContext;
34  class ParameterSet;
35  class RootOutputFile;
37  class ProductProvenanceRetriever;
38 
39  class PoolOutputModule : public one::OutputModule<WatchInputFiles> {
40  public:
42  explicit PoolOutputModule(ParameterSet const& ps);
43  ~PoolOutputModule() override;
44  PoolOutputModule(PoolOutputModule const&) = delete; // Disallow copying and moving
45  PoolOutputModule& operator=(PoolOutputModule const&) = delete; // Disallow copying and moving
46  std::string const& fileName() const { return fileName_; }
47  std::string const& logicalFileName() const { return logicalFileName_; }
48  int const& compressionLevel() const { return compressionLevel_; }
50  int const& basketSize() const { return basketSize_; }
51  int eventAutoFlushSize() const { return eventAutoFlushSize_; }
52  int const& splitLevel() const { return splitLevel_; }
53  std::string const& basketOrder() const { return basketOrder_; }
54  int const& treeMaxVirtualSize() const { return treeMaxVirtualSize_; }
56  DropMetaData const& dropMetaData() const { return dropMetaData_; }
57  std::string const& catalog() const { return catalog_; }
58  std::string const& moduleLabel() const { return moduleLabel_; }
59  unsigned int const& maxFileSize() const { return maxFileSize_; }
60  int const& inputFileCount() const { return inputFileCount_; }
61  int const& whyNotFastClonable() const { return whyNotFastClonable_; }
62 
63  std::string const& currentFileName() const;
64 
65  static void fillDescription(ParameterSetDescription& desc);
66  static void fillDescriptions(ConfigurationDescriptions& descriptions);
67 
69 
70  struct AuxItem {
71  AuxItem();
72  ~AuxItem() {}
74  };
75  typedef std::array<AuxItem, NumBranchTypes> AuxItemArray;
76  AuxItemArray const& auxItems() const { return auxItems_; }
77 
78  struct OutputItem {
79  class Sorter {
80  public:
81  explicit Sorter(TTree* tree);
82  bool operator()(OutputItem const& lh, OutputItem const& rh) const;
83 
84  private:
85  std::shared_ptr<std::map<std::string, int>> treeMap_;
86  };
87 
88  OutputItem();
89 
90  explicit OutputItem(BranchDescription const* bd, EDGetToken const& token, int splitLevel, int basketSize);
91 
93 
94  BranchID branchID() const { return branchDescription_->branchID(); }
95  std::string const& branchName() const { return branchDescription_->branchName(); }
96 
97  bool operator<(OutputItem const& rh) const { return *branchDescription_ < *rh.branchDescription_; }
98 
101  mutable void const* product_;
104  };
105 
106  typedef std::vector<OutputItem> OutputItemList;
107 
108  typedef std::array<OutputItemList, NumBranchTypes> OutputItemListArray;
109 
111  SpecialSplitLevelForBranch(std::string const& iBranchName, int iSplitLevel)
112  : branch_(convert(iBranchName)),
113  splitLevel_(iSplitLevel < 1 ? 1 : iSplitLevel) //minimum is 1
114  {}
115  bool match(std::string const& iBranchName) const;
116  std::regex convert(std::string const& iGlobBranchExpression) const;
117 
118  std::regex branch_;
120  };
121 
122  OutputItemListArray const& selectedOutputItemList() const { return selectedOutputItemList_; }
123 
124  BranchChildren const& branchChildren() const { return branchChildren_; }
125 
126  protected:
128  bool shouldWeCloseFile() const override;
129  void write(EventForOutput const& e) override;
130 
131  virtual std::pair<std::string, std::string> physicalAndLogicalNameForNewFile();
132  virtual void doExtrasAfterCloseFile();
133 
134  private:
136  ModuleCallingContext const& iModuleCallingContext,
137  Principal const& iPrincipal) const override;
138 
139  void openFile(FileBlock const& fb) override;
140  void respondToOpenInputFile(FileBlock const& fb) override;
141  void respondToCloseInputFile(FileBlock const& fb) override;
142  void writeLuminosityBlock(LuminosityBlockForOutput const& lb) override;
143  void writeRun(RunForOutput const& r) override;
144  bool isFileOpen() const override;
145  void reallyOpenFile();
146  void reallyCloseFile() override;
147  void beginJob() override;
148 
149  void setProcessesWithSelectedMergeableRunProducts(std::set<std::string> const&) override;
150 
151  typedef std::map<BranchID, std::set<ParentageID>> BranchParents;
152  void updateBranchParentsForOneBranch(ProductProvenanceRetriever const* provRetriever, BranchID const& branchID);
153  void updateBranchParents(EventForOutput const& e);
154  void fillDependencyGraph();
155 
156  void startEndFile();
157  void writeFileFormatVersion();
158  void writeFileIdentifier();
159  void writeIndexIntoFile();
164  void writeParentageRegistry();
168  void finishEndFile();
169 
170  void fillSelectedItemList(BranchType branchtype, TTree* theInputTree);
171  void beginInputFile(FileBlock const& fb);
172 
174  AuxItemArray auxItems_;
175  OutputItemListArray selectedOutputItemList_;
176  std::vector<SpecialSplitLevelForBranch> specialSplitLevelForBranches_;
180  unsigned int const maxFileSize_;
181  int const compressionLevel_;
183  int const basketSize_;
185  int const splitLevel_;
194  unsigned int childIndex_;
196  BranchParents branchParents_;
198  std::vector<BranchID> producedBranches_;
203  };
204 } // namespace edm
205 
206 #endif
void openFile(FileBlock const &fb) override
virtual std::pair< std::string, std::string > physicalAndLogicalNameForNewFile()
bool shouldWeCloseFile() const override
allow inheriting classes to override but still be able to call this method in the overridden version ...
BranchDescription const * branchDescription_
int const & basketSize() const
std::string const compressionAlgorithm_
bool const & overrideInputFileSplitLevels() const
int eventAutoFlushSize() const
std::string const & catalog() const
void write(EventForOutput const &e) override
edm::propagate_const< std::unique_ptr< RootOutputFile > > rootOutputFile_
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_
std::vector< OutputItem > OutputItemList
std::string const & fileName() const
int const & compressionLevel() const
OutputItemListArray const & selectedOutputItemList() const
std::string const moduleLabel_
bool int lh
Definition: SIMDVec.h:21
unsigned int const & maxFileSize() const
virtual void doExtrasAfterCloseFile()
std::string const & logicalFileName() const
BranchType
Definition: BranchType.h:11
void fillSelectedItemList(BranchType branchtype, TTree *theInputTree)
PoolOutputModule(ParameterSet const &ps)
void updateBranchParentsForOneBranch(ProductProvenanceRetriever const *provRetriever, BranchID const &branchID)
std::string const & currentFileName() const
bool operator<(OutputItem const &rh) const
std::string const & compressionAlgorithm() const
OutputItemListArray selectedOutputItemList_
std::vector< BranchID > producedBranches_
void preActionBeforeRunEventAsync(WaitingTask *iTask, ModuleCallingContext const &iModuleCallingContext, Principal const &iPrincipal) const override
std::string const & basketOrder() const
std::string const & branchName() const
void writeStoredMergeableRunProductMetadata()
int const & splitLevel() const
BranchParents branchParents_
def convert(infile, ofile)
int const & whyNotFastClonable() const
unsigned int numberOfDigitsInIndex_
std::array< AuxItem, NumBranchTypes > AuxItemArray
unsigned int const maxFileSize_
void writeRun(RunForOutput const &r) override
bool isFileOpen() const override
BranchChildren const & branchChildren() const
SpecialSplitLevelForBranch(std::string const &iBranchName, int iSplitLevel)
void respondToCloseInputFile(FileBlock const &fb) override
void beginJob() override
void reallyCloseFile() override
AuxItemArray const & auxItems() const
std::string const fileName_
int const & treeMaxVirtualSize() const
std::array< OutputItemList, NumBranchTypes > OutputItemListArray
HLT enums.
std::shared_ptr< std::map< std::string, int > > treeMap_
std::string const logicalFileName_
void beginInputFile(FileBlock const &fb)
Definition: tree.py:1
void respondToOpenInputFile(FileBlock const &fb) override
static void fillDescriptions(ConfigurationDescriptions &descriptions)
static void fillDescription(ParameterSetDescription &desc)
std::map< BranchID, std::set< ParentageID > > BranchParents
std::vector< std::string > processesWithSelectedMergeableRunProducts_
RootServiceChecker rootServiceChecker_
int const & inputFileCount() const
ParameterSetID selectorConfig() const
Definition: OutputModule.h:117
std::string match(BranchDescription const &a, BranchDescription const &b, std::string const &fileName)
void writeLuminosityBlock(LuminosityBlockForOutput const &lb) override