CMS 3D CMS Logo

edm::RootOutputTree Class Reference

#include <IOPool/Output/src/RootOutputTree.h>

List of all members.

Public Member Functions

void addBranch (BranchDescription const &prod, void const *&pProd, bool produced)
void beginInputFile (bool fastCloning)
bool checkSplitLevelAndBasketSize (TTree *inputTree) const
void fastCloneTree (TTree *tree)
void fillTree () const
bool isValid () const
TTree *const metaTree () const
template<typename T>
 RootOutputTree (T *, boost::shared_ptr< TFile > filePtr, BranchType const &branchType, typename T::Auxiliary const *&pAux, typename T::EntryInfoVector *&pEntryInfoVector, int bufSize, int splitLevel, int treeMaxVirtualSize)
void setEntries ()
TTree *const tree () const
bool uncloned (std::string const &branchName) const
void writeTree () const
 ~RootOutputTree ()

Static Public Member Functions

static TTree * assignTTree (TFile *file, TTree *tree)
static void fastCloneTTree (TTree *in, TTree *out)
static TTree * makeTTree (TFile *filePtr, std::string const &name, int splitLevel)
static void writeTTree (TTree *tree)

Static Private Member Functions

static void fillTTree (TTree *tree, std::vector< TBranch * > const &branches)

Private Attributes

TBranch * auxBranch_
int basketSize_
TBranch * branchEntryInfoBranch_
bool currentlyFastCloning_
boost::shared_ptr< TFile > filePtr_
std::vector< TBranch * > metaBranches_
TTree *const metaTree_
std::vector< TBranch * > producedBranches_
std::vector< TBranch * > readBranches_
int splitLevel_
TTree *const tree_
std::vector< TBranch * > unclonedReadBranches_
std::set< std::string > unclonedReadBranchNames_


Detailed Description

Definition at line 29 of file RootOutputTree.h.


Constructor & Destructor Documentation

template<typename T>
edm::RootOutputTree::RootOutputTree ( T *  ,
boost::shared_ptr< TFile >  filePtr,
BranchType const &  branchType,
typename T::Auxiliary const *&  pAux,
typename T::EntryInfoVector *&  pEntryInfoVector,
int  bufSize,
int  splitLevel,
int  treeMaxVirtualSize 
) [inline]

Definition at line 33 of file RootOutputTree.h.

References auxBranch_, branchEntryInfoBranch_, edm::BranchTypeToAuxiliaryBranchName(), edm::BranchTypeToBranchEntryInfoBranchName(), metaBranches_, metaTree_, readBranches_, and tree_.

00040                                            :
00041       filePtr_(filePtr),
00042       tree_(makeTTree(filePtr.get(), BranchTypeToProductTreeName(branchType), splitLevel)),
00043       metaTree_(makeTTree(filePtr.get(), BranchTypeToMetaDataTreeName(branchType), 0)),
00044       auxBranch_(0),
00045       producedBranches_(),
00046       metaBranches_(),
00047       readBranches_(),
00048       unclonedReadBranches_(),
00049       unclonedReadBranchNames_(),
00050       currentlyFastCloning_(),
00051       basketSize_(bufSize),
00052       splitLevel_(splitLevel) {
00053 
00054       if (treeMaxVirtualSize >= 0) tree_->SetMaxVirtualSize(treeMaxVirtualSize);
00055       auxBranch_ = tree_->Branch(BranchTypeToAuxiliaryBranchName(branchType).c_str(), &pAux, bufSize, 0);
00056       readBranches_.push_back(auxBranch_);  
00057 
00058       branchEntryInfoBranch_ = metaTree_->Branch(BranchTypeToBranchEntryInfoBranchName(branchType).c_str(),
00059                                                  &pEntryInfoVector, bufSize, 0);
00060       metaBranches_.push_back(branchEntryInfoBranch_);
00061   }

edm::RootOutputTree::~RootOutputTree (  )  [inline]

Definition at line 63 of file RootOutputTree.h.

00063 {}


Member Function Documentation

void edm::RootOutputTree::addBranch ( BranchDescription const &  prod,
void const *&  pProd,
bool  produced 
)

Definition at line 125 of file RootOutputTree.cc.

References edm::BranchDescription::basketSize(), basketSize_, edm::BranchDescription::branchName(), edm::BranchDescription::init(), edm::BranchDescription::invalidBasketSize, edm::BranchDescription::invalidSplitLevel, producedBranches_, readBranches_, edm::BranchDescription::splitLevel(), splitLevel_, tree_, and edm::BranchDescription::wrappedName().

00126                                                                {
00127       prod.init();
00128       TBranch *branch = tree_->Branch(prod.branchName().c_str(),
00129                  prod.wrappedName().c_str(),
00130                  &pProd,
00131                  (prod.basketSize() == BranchDescription::invalidBasketSize ? basketSize_ : prod.basketSize()),
00132                  (prod.splitLevel() == BranchDescription::invalidSplitLevel ? splitLevel_ : prod.splitLevel()));
00133       if (produced) {
00134         producedBranches_.push_back(branch);
00135       } else {
00136         readBranches_.push_back(branch);
00137       }
00138   }

TTree * edm::RootOutputTree::assignTTree ( TFile *  file,
TTree *  tree 
) [static]

Definition at line 19 of file RootOutputTree.cc.

References max.

Referenced by makeTTree().

00019                                                            {
00020     tree->SetDirectory(filePtr);
00021     // Turn off autosaving because it is such a memory hog and we are not using
00022     // this check-pointing feature anyway.
00023     tree->SetAutoSave(std::numeric_limits<Long64_t>::max());
00024     return tree;
00025   }

void edm::RootOutputTree::beginInputFile ( bool  fastCloning  )  [inline]

Definition at line 99 of file RootOutputTree.h.

References currentlyFastCloning_.

Referenced by edm::RootOutputFile::beginInputFile().

00099                                           {
00100       currentlyFastCloning_ = fastCloning;
00101     }

bool edm::RootOutputTree::checkSplitLevelAndBasketSize ( TTree *  inputTree  )  const

Definition at line 39 of file RootOutputTree.cc.

References it, and readBranches_.

Referenced by edm::RootOutputFile::beginInputFile().

00039                                                                           {
00040 
00041     if (inputTree == 0) return false;
00042 
00043     // Do the split level and basket size match in the input and output?
00044     for (std::vector<TBranch *>::const_iterator it = readBranches_.begin(), itEnd = readBranches_.end();
00045       it != itEnd; ++it) {
00046 
00047       TBranch* outputBranch = *it;
00048       if (outputBranch != 0) {
00049         TBranch* inputBranch = inputTree->GetBranch(outputBranch->GetName());
00050 
00051         if (inputBranch != 0) {
00052           if (inputBranch->GetSplitLevel() != outputBranch->GetSplitLevel() ||
00053               inputBranch->GetBasketSize() != outputBranch->GetBasketSize()) {
00054             LogInfo("FastCloning")
00055               << "Fast Cloning disabled because split level or basket size do not match";
00056             return false;
00057           }
00058         }
00059       }
00060     }
00061     return true;
00062   }

void edm::RootOutputTree::fastCloneTree ( TTree *  tree  ) 

Definition at line 98 of file RootOutputTree.cc.

References currentlyFastCloning_, fastCloneTTree(), it, readBranches_, tree_, unclonedReadBranches_, and unclonedReadBranchNames_.

Referenced by edm::RootOutputFile::beginInputFile().

00098                                            {
00099     unclonedReadBranches_.clear();
00100     unclonedReadBranchNames_.clear();
00101     if (currentlyFastCloning_) {
00102       fastCloneTTree(tree, tree_);
00103       for (std::vector<TBranch *>::const_iterator it = readBranches_.begin(), itEnd = readBranches_.end();
00104           it != itEnd; ++it) {
00105         if ((*it)->GetEntries() != tree_->GetEntries()) {
00106           unclonedReadBranches_.push_back(*it);
00107           unclonedReadBranchNames_.insert(std::string((*it)->GetName()));
00108         }
00109       }
00110     }
00111   }

void edm::RootOutputTree::fastCloneTTree ( TTree *  in,
TTree *  out 
) [static]

Definition at line 66 of file RootOutputTree.cc.

References edm::errors::FatalRootError.

Referenced by fastCloneTree().

00066                                                       {
00067     if (in->GetEntries() != 0) {
00068       TTreeCloner cloner(in, out, "");
00069       if (!cloner.IsValid()) {
00070         throw edm::Exception(edm::errors::FatalRootError)
00071           << "invalid TTreeCloner\n";
00072       }
00073       out->SetEntries(out->GetEntries() + in->GetEntries());
00074       cloner.Exec();
00075     }
00076   }

void edm::RootOutputTree::fillTree (  )  const

Definition at line 114 of file RootOutputTree.cc.

References currentlyFastCloning_, fillTTree(), metaBranches_, metaTree_, producedBranches_, readBranches_, tree_, and unclonedReadBranches_.

00114                                  {
00115     fillTTree(metaTree_, metaBranches_);
00116     fillTTree(tree_, producedBranches_);
00117     if (currentlyFastCloning_) {
00118       fillTTree(tree_, unclonedReadBranches_);
00119     } else {
00120       fillTTree(tree_, readBranches_);
00121     }
00122   }

void edm::RootOutputTree::fillTTree ( TTree *  tree,
std::vector< TBranch * > const &  branches 
) [static, private]

Definition at line 87 of file RootOutputTree.cc.

References edm::for_all().

Referenced by fillTree().

00087                                                                               {
00088     for_all(branches, boost::bind(&TBranch::Fill, _1));
00089   }

bool edm::RootOutputTree::isValid (  )  const

TTree * edm::RootOutputTree::makeTTree ( TFile *  filePtr,
std::string const &  name,
int  splitLevel 
) [static]

Definition at line 28 of file RootOutputTree.cc.

References assignTTree(), edm::errors::FatalRootError, and tree().

Referenced by edm::RootOutputFile::RootOutputFile().

00028                                                                                   {
00029     TTree *tree = new TTree(name.c_str(), "", splitLevel);
00030     if (!tree) throw edm::Exception(edm::errors::FatalRootError)
00031       << "Failed to create the tree: " << name << "\n";
00032     if (tree->IsZombie())
00033       throw edm::Exception(edm::errors::FatalRootError)
00034         << "Tree: " << name << " is a zombie." << "\n";
00035                                     
00036     return assignTTree(filePtr, tree);
00037   }

TTree* const edm::RootOutputTree::metaTree (  )  const [inline]

Definition at line 90 of file RootOutputTree.h.

References metaTree_.

00090                                   {
00091       return metaTree_;
00092     }

void edm::RootOutputTree::setEntries (  )  [inline]

Definition at line 94 of file RootOutputTree.h.

References metaTree_, and tree_.

Referenced by edm::RootOutputFile::respondToCloseInputFile().

00094                       {
00095       if (tree_->GetNbranches() != 0) tree_->SetEntries(-1);
00096       if (metaTree_->GetNbranches() != 0) metaTree_->SetEntries(-1);
00097     }

TTree* const edm::RootOutputTree::tree (  )  const [inline]

Definition at line 86 of file RootOutputTree.h.

References tree_.

Referenced by makeTTree().

00086                               {
00087       return tree_;
00088     }

bool edm::RootOutputTree::uncloned ( std::string const &  branchName  )  const [inline]

Definition at line 104 of file RootOutputTree.h.

References unclonedReadBranchNames_.

00104                                                 {
00105         return unclonedReadBranchNames_.find(branchName) != unclonedReadBranchNames_.end();
00106     }

void edm::RootOutputTree::writeTree (  )  const

Definition at line 92 of file RootOutputTree.cc.

References metaTree_, tree_, and writeTTree().

00092                                   {
00093     writeTTree(tree_);
00094     writeTTree(metaTree_);
00095   }

void edm::RootOutputTree::writeTTree ( TTree *  tree  )  [static]

Definition at line 79 of file RootOutputTree.cc.

Referenced by edm::RootOutputFile::finishEndFile(), edm::RootOutputFile::writeEventHistory(), and writeTree().

00079                                         {
00080     if (tree->GetNbranches() != 0) {
00081       tree->SetEntries(-1);
00082     }
00083     tree->AutoSave();
00084   }


Member Data Documentation

TBranch* edm::RootOutputTree::auxBranch_ [private]

Definition at line 116 of file RootOutputTree.h.

Referenced by RootOutputTree().

int edm::RootOutputTree::basketSize_ [private]

Definition at line 124 of file RootOutputTree.h.

Referenced by addBranch().

TBranch* edm::RootOutputTree::branchEntryInfoBranch_ [private]

Definition at line 117 of file RootOutputTree.h.

Referenced by RootOutputTree().

bool edm::RootOutputTree::currentlyFastCloning_ [private]

Definition at line 123 of file RootOutputTree.h.

Referenced by beginInputFile(), fastCloneTree(), and fillTree().

boost::shared_ptr<TFile> edm::RootOutputTree::filePtr_ [private]

Definition at line 113 of file RootOutputTree.h.

std::vector<TBranch *> edm::RootOutputTree::metaBranches_ [private]

Definition at line 119 of file RootOutputTree.h.

Referenced by fillTree(), and RootOutputTree().

TTree* const edm::RootOutputTree::metaTree_ [private]

Definition at line 115 of file RootOutputTree.h.

Referenced by fillTree(), metaTree(), RootOutputTree(), setEntries(), and writeTree().

std::vector<TBranch *> edm::RootOutputTree::producedBranches_ [private]

Definition at line 118 of file RootOutputTree.h.

Referenced by addBranch(), and fillTree().

std::vector<TBranch *> edm::RootOutputTree::readBranches_ [private]

Definition at line 120 of file RootOutputTree.h.

Referenced by addBranch(), checkSplitLevelAndBasketSize(), fastCloneTree(), fillTree(), and RootOutputTree().

int edm::RootOutputTree::splitLevel_ [private]

Definition at line 125 of file RootOutputTree.h.

Referenced by addBranch().

TTree* const edm::RootOutputTree::tree_ [private]

Definition at line 114 of file RootOutputTree.h.

Referenced by addBranch(), fastCloneTree(), fillTree(), RootOutputTree(), setEntries(), tree(), and writeTree().

std::vector<TBranch *> edm::RootOutputTree::unclonedReadBranches_ [private]

Definition at line 121 of file RootOutputTree.h.

Referenced by fastCloneTree(), and fillTree().

std::set<std::string> edm::RootOutputTree::unclonedReadBranchNames_ [private]

Definition at line 122 of file RootOutputTree.h.

Referenced by fastCloneTree(), and uncloned().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:44:14 2009 for CMSSW by  doxygen 1.5.4