CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/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 #include "boost/utility.hpp"
00015 
00016 #include "FWCore/Framework/interface/RunPrincipal.h"
00017 #include "FWCore/Utilities/interface/BranchType.h"
00018 
00019 #include "TTree.h"
00020 
00021 class TFile;
00022 class TBranch;
00023 
00024 namespace edm {
00025   class RootOutputTree : private boost::noncopyable {
00026   public:
00027     RootOutputTree(boost::shared_ptr<TFile> filePtr,
00028                    BranchType const& branchType,
00029                    int bufSize,
00030                    int splitLevel,
00031                    int treeMaxVirtualSize);
00032 
00033     ~RootOutputTree() {}
00034 
00035     template <typename T>
00036     void
00037     addAuxiliary(std::string const& branchName, T const*& pAux, int bufSize) {
00038       auxBranches_.push_back(tree_->Branch(branchName.c_str(), &pAux, bufSize, 0));
00039     }
00040 
00041     template <typename T>
00042     void
00043     addAuxiliary(std::string const& branchName, T*& pAux, int bufSize) {
00044       auxBranches_.push_back(tree_->Branch(branchName.c_str(), &pAux, bufSize, 0));
00045     }
00046 
00047     void fastCloneTTree(TTree* in, std::string const& option);
00048 
00049     static TTree* makeTTree(TFile* filePtr, std::string const& name, int splitLevel);
00050 
00051     static TTree* assignTTree(TFile* file, TTree* tree);
00052 
00053     static void writeTTree(TTree* tree);
00054 
00055     bool isValid() const;
00056 
00057     void addBranch(std::string const& branchName,
00058                    std::string const& className,
00059                    void const*& pProd,
00060                    int splitLevel,
00061                    int basketSize,
00062                    bool produced);
00063 
00064     bool checkSplitLevelsAndBasketSizes(TTree* inputTree) const;
00065 
00066     bool checkIfFastClonable(TTree* inputTree) const;
00067 
00068     void maybeFastCloneTree(bool canFastClone, bool canFastCloneAux, TTree* tree, std::string const& option);
00069 
00070     void fillTree() const;
00071 
00072     void writeTree() const;
00073 
00074     TTree* const tree() const {
00075       return tree_;
00076     }
00077 
00078     void setEntries() {
00079       if(tree_->GetNbranches() != 0) tree_->SetEntries(-1);
00080     }
00081 
00082     bool
00083     uncloned(std::string const& branchName) const {
00084       return unclonedReadBranchNames_.find(branchName) != unclonedReadBranchNames_.end();
00085     }
00086 
00087     void close();
00088 
00089     void optimizeBaskets(ULong64_t size) {
00090       tree_->OptimizeBaskets(size);
00091     }
00092 
00093     void setAutoFlush(Long64_t size) {
00094       tree_->SetAutoFlush(size);
00095     }
00096   private:
00097     static void fillTTree(TTree* tree, std::vector<TBranch*> const& branches);
00098 // We use bare pointers for pointers to some ROOT entities.
00099 // Root owns them and uses bare pointers internally.
00100 // Therefore, using smart pointers here will do no good.
00101     boost::shared_ptr<TFile> filePtr_;
00102     TTree* tree_;
00103     std::vector<TBranch*> producedBranches_; // does not include cloned branches
00104     std::vector<TBranch*> readBranches_;
00105     std::vector<TBranch*> auxBranches_;
00106     std::vector<TBranch*> unclonedReadBranches_;
00107     std::set<std::string> unclonedReadBranchNames_;
00108     bool currentlyFastCloning_;
00109     bool fastCloneAuxBranches_;
00110   };
00111 }
00112 #endif