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_;}
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  private:
84  std::shared_ptr<std::map<std::string, int> > treeMap_;
85  };
86 
87  OutputItem();
88 
89  explicit OutputItem(BranchDescription const* bd, EDGetToken const& token, int splitLevel, int basketSize);
90 
92 
93  BranchID branchID() const { return branchDescription_->branchID(); }
94  std::string const& branchName() const { return branchDescription_->branchName(); }
95 
96  bool operator <(OutputItem const& rh) const {
97  return *branchDescription_ < *rh.branchDescription_;
98  }
99 
102  mutable void const* product_;
105  };
106 
107  typedef std::vector<OutputItem> OutputItemList;
108 
109  typedef std::array<OutputItemList, NumBranchTypes> OutputItemListArray;
110 
112  SpecialSplitLevelForBranch(std::string const& iBranchName, int iSplitLevel):
113  branch_(convert(iBranchName)),
114  splitLevel_(iSplitLevel < 1? 1: iSplitLevel) //minimum is 1
115  {}
116  bool match(std::string const& iBranchName) const;
117  std::regex convert(std::string const& iGlobBranchExpression )const;
118 
119  std::regex branch_;
121  };
122 
123  OutputItemListArray const& selectedOutputItemList() const {return selectedOutputItemList_;}
124 
126 
127  protected:
129  bool shouldWeCloseFile() const override;
130  void write(EventForOutput const& e) override;
131 
132  virtual std::pair<std::string, std::string> physicalAndLogicalNameForNewFile();
133  virtual void doExtrasAfterCloseFile();
134  private:
135  void preActionBeforeRunEventAsync(WaitingTask* iTask, ModuleCallingContext const& iModuleCallingContext, Principal const& iPrincipal) const override;
136 
137  void openFile(FileBlock const& fb) override;
138  void respondToOpenInputFile(FileBlock const& fb) override;
139  void respondToCloseInputFile(FileBlock const& fb) override;
140  void writeLuminosityBlock(LuminosityBlockForOutput const& lb) override;
141  void writeRun(RunForOutput const& r) override;
142  bool isFileOpen() const override;
143  void reallyOpenFile();
144  void reallyCloseFile() override;
145  void beginJob() override;
146 
147  typedef std::map<BranchID, std::set<ParentageID> > BranchParents;
149  BranchID const& branchID);
150  void updateBranchParents(EventForOutput const& e);
151  void fillDependencyGraph();
152 
153  void startEndFile();
154  void writeFileFormatVersion();
155  void writeFileIdentifier();
156  void writeIndexIntoFile();
160  void writeParentageRegistry();
164  void finishEndFile();
165 
166  void fillSelectedItemList(BranchType branchtype, TTree* theInputTree);
167  void beginInputFile(FileBlock const& fb);
168 
170  AuxItemArray auxItems_;
171  OutputItemListArray selectedOutputItemList_;
172  std::vector<SpecialSplitLevelForBranch> specialSplitLevelForBranches_;
176  unsigned int const maxFileSize_;
177  int const compressionLevel_;
179  int const basketSize_;
181  int const splitLevel_;
190  unsigned int childIndex_;
192  BranchParents branchParents_;
194  std::vector<BranchID> producedBranches_;
198  };
199 }
200 
201 #endif
202 
bool operator<(DetSet< T > const &x, DetSet< T > const &y)
Definition: DetSet.h:90
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
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
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
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
RootServiceChecker rootServiceChecker_
int const & inputFileCount() const
ParameterSetID selectorConfig() const
Definition: OutputModule.h:113
std::string match(BranchDescription const &a, BranchDescription const &b, std::string const &fileName)
void writeLuminosityBlock(LuminosityBlockForOutput const &lb) override