CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10/src/IOPool/Output/src/RootOutputTree.h

Go to the documentation of this file.
00001 #ifndef IOPool_Output_RootOutputTree_h
00002 #define IOPool_Output_RootOutputTree_h
00003 
00004 /*----------------------------------------------------------------------
00005 
00006 RootOutputTree.h // used by ROOT output modules
00007 
00008 ----------------------------------------------------------------------*/
00009 
00010 #include <string>
00011 #include <vector>
00012 
00013 #include "boost/shared_ptr.hpp"
00014 
00015 #include "FWCore/Framework/interface/RunPrincipal.h"
00016 #include "FWCore/Utilities/interface/BranchType.h"
00017 
00018 #include "TTree.h"
00019 
00020 class TFile;
00021 class TBranch;
00022 
00023 namespace edm {
00024   class WrapperInterfaceBase;
00025   class RootOutputTree {
00026   public:
00027     RootOutputTree(boost::shared_ptr<TFile> filePtr,
00028                    BranchType const& branchType,
00029                    int splitLevel,
00030                    int treeMaxVirtualSize);
00031 
00032     ~RootOutputTree() {}
00033 
00034     RootOutputTree(RootOutputTree const&) = delete; // Disallow copying and moving
00035     RootOutputTree& operator=(RootOutputTree const&) = delete; // Disallow copying and moving
00036 
00037     template <typename T>
00038     void
00039     addAuxiliary(std::string const& branchName, T const*& pAux, int bufSize, bool allowCloning=true) {
00040       if(allowCloning) {
00041         auxBranches_.push_back(tree_->Branch(branchName.c_str(), &pAux, bufSize, 0));
00042       } else {
00043         unclonedAuxBranches_.push_back(tree_->Branch(branchName.c_str(), &pAux, bufSize, 0));    
00044       }
00045     }
00046 
00047     template <typename T>
00048     void
00049     addAuxiliary(std::string const& branchName, T*& pAux, int bufSize,bool allowCloning=true) {
00050       if(allowCloning) {
00051         auxBranches_.push_back(tree_->Branch(branchName.c_str(), &pAux, bufSize, 0));
00052       } else {
00053         unclonedAuxBranches_.push_back(tree_->Branch(branchName.c_str(), &pAux, bufSize, 0));    
00054       }
00055     }
00056 
00057     void fastCloneTTree(TTree* in, std::string const& option);
00058 
00059     static TTree* makeTTree(TFile* filePtr, std::string const& name, int splitLevel);
00060 
00061     static TTree* assignTTree(TFile* file, TTree* tree);
00062 
00063     static void writeTTree(TTree* tree);
00064 
00065     bool isValid() const;
00066 
00067     void addBranch(std::string const& branchName,
00068                    std::string const& className,
00069                    WrapperInterfaceBase const* interface,
00070                    void const*& pProd,
00071                    int splitLevel,
00072                    int basketSize,
00073                    bool produced);
00074 
00075     bool checkSplitLevelsAndBasketSizes(TTree* inputTree) const;
00076 
00077     bool checkIfFastClonable(TTree* inputTree) const;
00078 
00079     bool checkEntriesInReadBranches(Long64_t expectedNumberOfEntries) const;
00080 
00081     void maybeFastCloneTree(bool canFastClone, bool canFastCloneAux, TTree* tree, std::string const& option);
00082 
00083     void fillTree() const;
00084 
00085     void writeTree() const;
00086 
00087     TTree* tree() const {
00088       return tree_;
00089     }
00090 
00091     void setEntries() {
00092       if(tree_->GetNbranches() != 0) tree_->SetEntries(-1);
00093     }
00094 
00095     bool
00096     uncloned(std::string const& branchName) const {
00097       return clonedReadBranchNames_.find(branchName) == clonedReadBranchNames_.end();
00098     }
00099 
00100     void close();
00101 
00102     void optimizeBaskets(ULong64_t size) {
00103       tree_->OptimizeBaskets(size);
00104     }
00105 
00106     void setAutoFlush(Long64_t size) {
00107       tree_->SetAutoFlush(size);
00108     }
00109   private:
00110     static void fillTTree(std::vector<TBranch*> const& branches);
00111 // We use bare pointers for pointers to some ROOT entities.
00112 // Root owns them and uses bare pointers internally.
00113 // Therefore, using smart pointers here will do no good.
00114     boost::shared_ptr<TFile> filePtr_;
00115     TTree* tree_;
00116     std::vector<TBranch*> producedBranches_; // does not include cloned branches
00117     std::vector<TBranch*> readBranches_;
00118     std::vector<TBranch*> auxBranches_;
00119     std::vector<TBranch*> unclonedAuxBranches_;
00120     std::vector<TBranch*> unclonedReadBranches_;
00121     std::set<std::string> clonedReadBranchNames_;
00122     bool currentlyFastCloning_;
00123     bool fastCloneAuxBranches_;
00124   };
00125 }
00126 #endif