File indexing completed on 2024-04-06 12:19:10
0001 #ifndef IOPool_Output_RootOutputTree_h
0002 #define IOPool_Output_RootOutputTree_h
0003
0004
0005
0006
0007
0008
0009
0010 #include <string>
0011 #include <vector>
0012 #include <set>
0013 #include <memory>
0014
0015 #include "FWCore/Utilities/interface/BranchType.h"
0016 #include "FWCore/Utilities/interface/propagate_const.h"
0017
0018 #include "TTree.h"
0019
0020 class TFile;
0021 class TBranch;
0022
0023 namespace edm {
0024 class RootOutputTree {
0025 public:
0026 RootOutputTree(std::shared_ptr<TFile> filePtr,
0027 BranchType const& branchType,
0028 int splitLevel,
0029 int treeMaxVirtualSize,
0030 std::string const& processName = std::string());
0031
0032 ~RootOutputTree() {}
0033
0034 RootOutputTree(RootOutputTree const&) = delete;
0035 RootOutputTree& operator=(RootOutputTree const&) = delete;
0036
0037 template <typename T>
0038 void addAuxiliary(std::string const& branchName, T const*& pAux, int bufSize, bool allowCloning = true) {
0039 if (allowCloning) {
0040 auxBranches_.push_back(tree_->Branch(branchName.c_str(), &pAux, bufSize, 0));
0041 } else {
0042 unclonedAuxBranches_.push_back(tree_->Branch(branchName.c_str(), &pAux, bufSize, 0));
0043 }
0044 }
0045
0046 template <typename T>
0047 void addAuxiliary(std::string const& branchName, T*& pAux, int bufSize, bool allowCloning = true) {
0048 if (allowCloning) {
0049 auxBranches_.push_back(tree_->Branch(branchName.c_str(), &pAux, bufSize, 0));
0050 } else {
0051 unclonedAuxBranches_.push_back(tree_->Branch(branchName.c_str(), &pAux, bufSize, 0));
0052 }
0053 }
0054
0055 void fastCloneTTree(TTree* in, std::string const& option);
0056
0057 static TTree* makeTTree(TFile* filePtr, std::string const& name, int splitLevel);
0058
0059 static TTree* assignTTree(TFile* file, TTree* tree);
0060
0061 static void writeTTree(TTree* tree);
0062
0063 bool isValid() const;
0064
0065 void addBranch(std::string const& branchName,
0066 std::string const& className,
0067 void const*& pProd,
0068 int splitLevel,
0069 int basketSize,
0070 bool produced);
0071
0072 bool checkSplitLevelsAndBasketSizes(TTree* inputTree) const;
0073
0074 bool checkIfFastClonable(TTree* inputTree) const;
0075
0076 void setSubBranchBasketSizes(TTree* inputTree) const;
0077
0078 bool checkEntriesInReadBranches(Long64_t expectedNumberOfEntries) const;
0079
0080 void maybeFastCloneTree(bool canFastClone, bool canFastCloneAux, TTree* tree, std::string const& option);
0081
0082 void fillTree();
0083
0084 void writeTree();
0085
0086 TTree const* tree() const { return tree_.get(); }
0087
0088 TTree* tree() { return tree_.get(); }
0089
0090 void setEntries() {
0091 if (tree_->GetNbranches() != 0)
0092 tree_->SetEntries(-1);
0093 }
0094
0095 bool uncloned(std::string const& branchName) const {
0096 return clonedReadBranchNames_.find(branchName) == clonedReadBranchNames_.end();
0097 }
0098
0099 void close();
0100
0101 void optimizeBaskets(ULong64_t size) { tree_->OptimizeBaskets(size); }
0102
0103 void setAutoFlush(Long64_t size) { tree_->SetAutoFlush(size); }
0104
0105 private:
0106 static void fillTTree(std::vector<TBranch*> const& branches);
0107
0108
0109
0110 edm::propagate_const<std::shared_ptr<TFile>> filePtr_;
0111 edm::propagate_const<TTree*> tree_;
0112
0113 std::vector<TBranch*> producedBranches_;
0114 std::vector<TBranch*> readBranches_;
0115 std::vector<TBranch*> auxBranches_;
0116 std::vector<TBranch*> unclonedAuxBranches_;
0117 std::vector<TBranch*> unclonedReadBranches_;
0118
0119 std::set<std::string> clonedReadBranchNames_;
0120 bool currentlyFastCloning_;
0121 bool fastCloneAuxBranches_;
0122 };
0123 }
0124 #endif