CMS 3D CMS Logo

Public Types | Public Member Functions | Private Member Functions | Private Attributes

edm::RootTree Class Reference

#include <RootTree.h>

List of all members.

Public Types

typedef input::BranchMap BranchMap
typedef input::EntryNumber EntryNumber

Public Member Functions

void addBranch (BranchKey const &key, BranchDescription const &prod, std::string const &oldBranchName)
TBranch *const branchEntryInfoBranch () const
BranchMap const & branches () const
std::vector< std::string > const & branchNames () const
void close ()
bool current ()
void dropBranch (std::string const &oldBranchName)
EntryNumber const & entries () const
EntryNumber const & entryNumber () const
template<typename T >
void fillAux (T *&pAux)
template<typename T >
void fillBranchEntry (TBranch *branch, T *&pbuf)
template<typename T >
void fillBranchEntryNoCache (TBranch *branch, T *&pbuf)
void fillStatus ()
bool isValid () const
boost::shared_ptr< DelayedReadermakeDelayedReader (FileFormatVersion const &fileFormatVersion) const
TTree const * metaTree () const
bool next ()
bool previous ()
std::vector< ProductStatus >
const & 
productStatuses () const
void resetTraining ()
void rewind ()
 RootTree (boost::shared_ptr< InputFile > filePtr, BranchType const &branchType, unsigned int maxVirtualSize, unsigned int cacheSize, unsigned int learningEntries)
void setEntryNumber (EntryNumber theEntryNumber)
void setPresence (BranchDescription const &prod)
TTree const * tree () const
TTree * tree ()
 ~RootTree ()

Private Member Functions

void setCacheSize (unsigned int cacheSize)
void setTreeMaxVirtualSize (int treeMaxVirtualSize)

Private Attributes

TBranch * auxBranch_
TBranch * branchEntryInfoBranch_
boost::shared_ptr< BranchMapbranches_
std::vector< std::string > branchNames_
BranchType branchType_
EntryNumber entries_
EntryNumber entryNumber_
boost::shared_ptr< InputFilefilePtr_
TTree * infoTree_
unsigned int learningEntries_
TTree * metaTree_
std::vector< ProductStatus > * pProductStatuses_
std::vector< ProductStatusproductStatuses_
TBranch * statusBranch_
bool trained_
TTree * tree_
boost::shared_ptr< TTreeCache > treeCache_

Detailed Description

Definition at line 25 of file RootTree.h.


Member Typedef Documentation

Definition at line 27 of file RootTree.h.

Definition at line 28 of file RootTree.h.


Constructor & Destructor Documentation

edm::RootTree::RootTree ( boost::shared_ptr< InputFile filePtr,
BranchType const &  branchType,
unsigned int  maxVirtualSize,
unsigned int  cacheSize,
unsigned int  learningEntries 
)

Definition at line 33 of file RootTree.cc.

References setCacheSize(), and setTreeMaxVirtualSize().

                                                   :
    filePtr_(filePtr),
    tree_(dynamic_cast<TTree*>(filePtr_.get() != 0 ? filePtr->Get(BranchTypeToProductTreeName(branchType).c_str()) : 0)),
    metaTree_(dynamic_cast<TTree*>(filePtr_.get() != 0 ? filePtr->Get(BranchTypeToMetaDataTreeName(branchType).c_str()) : 0)),
    branchType_(branchType),
    auxBranch_(tree_ ? getAuxiliaryBranch(tree_, branchType_) : 0),
    branchEntryInfoBranch_(metaTree_ ? getProductProvenanceBranch(metaTree_, branchType_) : getProductProvenanceBranch(tree_, branchType_)),
    treeCache_(),
    entries_(tree_ ? tree_->GetEntries() : 0),
    entryNumber_(-1),
    branchNames_(),
    branches_(new BranchMap),
    trained_(kFALSE),
    learningEntries_(learningEntries),
    productStatuses_(), // backward compatibility
    pProductStatuses_(&productStatuses_), // backward compatibility
    infoTree_(dynamic_cast<TTree*>(filePtr_.get() != 0 ? filePtr->Get(BranchTypeToInfoTreeName(branchType).c_str()) : 0)), // backward compatibility
    statusBranch_(infoTree_ ? getStatusBranch(infoTree_, branchType_) : 0) { // backward compatibility
      setTreeMaxVirtualSize(maxVirtualSize);
      setCacheSize(cacheSize);
  }
edm::RootTree::~RootTree ( )

Definition at line 59 of file RootTree.cc.

{}

Member Function Documentation

void edm::RootTree::addBranch ( BranchKey const &  key,
BranchDescription const &  prod,
std::string const &  oldBranchName 
)

Definition at line 83 of file RootTree.cc.

References branches_, edm::BranchDescription::branchName(), branchNames_, info, edm::BranchDescription::init(), isValid(), metaTree_, edm::BranchDescription::present(), edm::input::BranchInfo::productBranch_, edm::input::BranchInfo::provenanceBranch_, and tree_.

                                                      {
      assert(isValid());
      prod.init();
      //use the translated branch name
      TBranch* branch = tree_->GetBranch(oldBranchName.c_str());
      input::BranchInfo info = input::BranchInfo(ConstBranchDescription(prod));
      info.productBranch_ = 0;
      if (prod.present()) {
        info.productBranch_ = branch;
        //we want the new branch name for the JobReport
        branchNames_.push_back(prod.branchName());
      }
      TTree* provTree = (metaTree_ != 0 ? metaTree_ : tree_);
      info.provenanceBranch_ = provTree->GetBranch(oldBranchName.c_str());
      branches_->insert(std::make_pair(key, info));
  }
TBranch* const edm::RootTree::branchEntryInfoBranch ( ) const [inline]

Definition at line 80 of file RootTree.h.

References branchEntryInfoBranch_.

Referenced by edm::BranchMapperWithReader::readProvenance_().

input::BranchMap const & edm::RootTree::branches ( ) const

Definition at line 126 of file RootTree.cc.

References branches_.

{return *branches_;}
std::vector<std::string> const& edm::RootTree::branchNames ( ) const [inline]

Definition at line 50 of file RootTree.h.

References branchNames_.

{return branchNames_;}
void edm::RootTree::close ( void  )

Definition at line 168 of file RootTree.cc.

References auxBranch_, branchEntryInfoBranch_, filePtr_, infoTree_, metaTree_, statusBranch_, trained_, and tree_.

                   {
    // The InputFile is about to be closed, and destructed.
    // Just to play it safe, zero all pointers to quantities that are owned by the InputFile.
    auxBranch_  = branchEntryInfoBranch_ = statusBranch_ = 0;
    tree_ = metaTree_ = infoTree_ = 0;
    // We own the treeCache_.
    // We make sure the treeCache_ is detatched from the file,
    // so that ROOT does not also delete it.
    filePtr_->SetCacheRead(0);
    trained_ = kFALSE;
    // We give up our shared ownership of the InputFile itself.
    filePtr_.reset();
  }
bool edm::RootTree::current ( ) [inline]

Definition at line 44 of file RootTree.h.

{return entryNumber_ < entries_ && entryNumber_ >= 0;}
void edm::RootTree::dropBranch ( std::string const &  oldBranchName)

Definition at line 103 of file RootTree.cc.

References beamvalidation::br, entries(), i, python::Node::leaf, and tree_.

                                                     {
      //use the translated branch name
      TBranch* branch = tree_->GetBranch(oldBranchName.c_str());
      if (branch != 0) {
        TObjArray* leaves = tree_->GetListOfLeaves();
        int entries = leaves->GetEntries();
        for (int i = 0; i < entries; ++i) {
          TLeaf* leaf = (TLeaf*)(*leaves)[i];
          if (leaf == 0) continue;
          TBranch* br = leaf->GetBranch();
          if (br == 0) continue;
          if (br->GetMother() == branch) {
            leaves->Remove(leaf);
          }
        }
        leaves->Compress();
        tree_->GetListOfBranches()->Remove(branch);
        tree_->GetListOfBranches()->Compress();
        delete branch;
      }
  }
EntryNumber const& edm::RootTree::entries ( ) const [inline]

Definition at line 48 of file RootTree.h.

References entries_.

Referenced by dropBranch().

{return entries_;}
EntryNumber const& edm::RootTree::entryNumber ( ) const [inline]

Definition at line 47 of file RootTree.h.

References entryNumber_.

{return entryNumber_;}
template<typename T >
void edm::RootTree::fillAux ( T *&  pAux) [inline]
template<typename T >
void edm::RootTree::fillBranchEntry ( TBranch *  branch,
T *&  pbuf 
) [inline]

Definition at line 59 of file RootTree.h.

References entryNumber_, filePtr_, edm::input::getEntryWithCache(), and treeCache_.

Referenced by edm::BranchMapperWithReader::readProvenance_().

                                                    {
      branch->SetAddress(&pbuf);
      input::getEntryWithCache(branch, entryNumber_, treeCache_.get(), filePtr_.get());
    }
template<typename T >
void edm::RootTree::fillBranchEntryNoCache ( TBranch *  branch,
T *&  pbuf 
) [inline]

Definition at line 64 of file RootTree.h.

References entryNumber_, and edm::input::getEntry().

                                                           {
      branch->SetAddress(&pbuf);
      input::getEntry(branch, entryNumber_);
    }
void edm::RootTree::fillStatus ( ) [inline]

Definition at line 75 of file RootTree.h.

References entryNumber_, edm::input::getEntry(), pProductStatuses_, and statusBranch_.

                      { // backward compatibility
      statusBranch_->SetAddress(&pProductStatuses_); // backward compatibility
      input::getEntry(statusBranch_, entryNumber_); // backward compatibility
    } // backward compatibility
bool edm::RootTree::isValid ( void  ) const

Definition at line 62 of file RootTree.cc.

References auxBranch_, branchEntryInfoBranch_, entries_, metaTree_, statusBranch_, and tree_.

Referenced by addBranch(), and setPresence().

                          {
    if (metaTree_ == 0 || metaTree_->GetNbranches() == 0) {
      return tree_ != 0 && auxBranch_ != 0;
    }
    if (tree_ != 0 && auxBranch_ != 0 && metaTree_ != 0) { // backward compatibility
      if (branchEntryInfoBranch_ != 0 || statusBranch_ != 0) return true; // backward compatibility
      return (entries_ == metaTree_->GetEntries() && tree_->GetNbranches() <= metaTree_->GetNbranches() + 1);  // backward compatibility
    } // backward compatibility
    return false;
  }
boost::shared_ptr< DelayedReader > edm::RootTree::makeDelayedReader ( FileFormatVersion const &  fileFormatVersion) const

Definition at line 129 of file RootTree.cc.

References branches_, entryNumber_, filePtr_, and treeCache_.

                                                                              {
    boost::shared_ptr<DelayedReader>
        store(new RootDelayedReader(entryNumber_, branches_, treeCache_, filePtr_, fileFormatVersion));
    return store;
  }
TTree const* edm::RootTree::metaTree ( ) const [inline]

Definition at line 70 of file RootTree.h.

References metaTree_.

{return metaTree_;}
bool edm::RootTree::next ( void  ) [inline]
bool edm::RootTree::previous ( ) [inline]

Definition at line 43 of file RootTree.h.

References entryNumber_.

Referenced by edm::RootFile::readLuminosityBlockAuxiliary_(), and edm::RootFile::readRunAuxiliary_().

{return --entryNumber_ >= 0;}
std::vector<ProductStatus> const& edm::RootTree::productStatuses ( ) const [inline]

Definition at line 72 of file RootTree.h.

References productStatuses_.

{return productStatuses_;} // backward compatibility
void edm::RootTree::resetTraining ( ) [inline]

Definition at line 81 of file RootTree.h.

References trained_.

Referenced by edm::RootFile::RootFile().

{trained_ = kFALSE;}
void edm::RootTree::rewind ( ) [inline]

Definition at line 45 of file RootTree.h.

References entryNumber_.

Referenced by edm::RootFile::rewind().

{entryNumber_ = 0;}
void edm::RootTree::setCacheSize ( unsigned int  cacheSize) [private]

Definition at line 136 of file RootTree.cc.

References filePtr_, tree_, and treeCache_.

Referenced by RootTree().

                                               {
    tree_->SetCacheSize(static_cast<Long64_t>(cacheSize));
    treeCache_.reset(dynamic_cast<TTreeCache*>(filePtr_->GetCacheRead()));
    filePtr_->SetCacheRead(0);
  }
void edm::RootTree::setEntryNumber ( EntryNumber  theEntryNumber)

Definition at line 148 of file RootTree.cc.

References edm::poolNames::branchListIndexesBranchName(), branchType_, edm::BranchTypeToAuxiliaryBranchName(), entryNumber_, filePtr_, edm::InEvent, learningEntries_, trained_, tree_, and treeCache_.

Referenced by edm::RootFile::initializeDuplicateChecker(), and edm::RootFile::skipEvents().

                                                     {
    filePtr_->SetCacheRead(treeCache_.get());
    entryNumber_ = theEntryNumber;
    tree_->LoadTree(theEntryNumber);
    if (treeCache_ && !trained_ && theEntryNumber >= 0) {
      assert(treeCache_->GetOwner() == tree_);
      treeCache_->SetLearnEntries(learningEntries_);
      treeCache_->SetEntryRange(theEntryNumber, tree_->GetEntries());
      treeCache_->StartLearningPhase();
      treeCache_->AddBranch(BranchTypeToAuxiliaryBranchName(branchType_).c_str());
      if (branchType_ == edm::InEvent) {
        treeCache_->AddBranch(poolNames::branchListIndexesBranchName().c_str());
      }
      trained_ = kTRUE;
    }
    filePtr_->SetCacheRead(0);
  }
void edm::RootTree::setPresence ( BranchDescription const &  prod)

Definition at line 74 of file RootTree.cc.

References edm::BranchDescription::branchName(), edm::BranchDescription::init(), isValid(), edm::BranchDescription::setDropped(), and tree_.

                                                     {
      assert(isValid());
      prod.init();
      if(tree_->GetBranch(prod.branchName().c_str()) == 0){
        prod.setDropped();
      }
  }
void edm::RootTree::setTreeMaxVirtualSize ( int  treeMaxVirtualSize) [private]

Definition at line 143 of file RootTree.cc.

References tree_.

Referenced by RootTree().

                                                        {
    if (treeMaxVirtualSize >= 0) tree_->SetMaxVirtualSize(static_cast<Long64_t>(treeMaxVirtualSize));
  }
TTree const* edm::RootTree::tree ( ) const [inline]

Definition at line 68 of file RootTree.h.

References tree_.

{return tree_;}
TTree* edm::RootTree::tree ( ) [inline]

Definition at line 69 of file RootTree.h.

References tree_.

{return tree_;}

Member Data Documentation

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

Definition at line 94 of file RootTree.h.

Referenced by close(), fillAux(), and isValid().

Definition at line 95 of file RootTree.h.

Referenced by branchEntryInfoBranch(), close(), and isValid().

boost::shared_ptr<BranchMap> edm::RootTree::branches_ [private]

Definition at line 103 of file RootTree.h.

Referenced by addBranch(), branches(), and makeDelayedReader().

std::vector<std::string> edm::RootTree::branchNames_ [private]

Definition at line 102 of file RootTree.h.

Referenced by addBranch(), and branchNames().

Definition at line 93 of file RootTree.h.

Referenced by setEntryNumber().

Definition at line 100 of file RootTree.h.

Referenced by entries(), isValid(), and next().

boost::shared_ptr<InputFile> edm::RootTree::filePtr_ [private]
TTree* edm::RootTree::infoTree_ [private]

Definition at line 110 of file RootTree.h.

Referenced by close().

unsigned int edm::RootTree::learningEntries_ [private]

Definition at line 105 of file RootTree.h.

Referenced by setEntryNumber().

TTree* edm::RootTree::metaTree_ [private]

Definition at line 92 of file RootTree.h.

Referenced by addBranch(), close(), isValid(), and metaTree().

Definition at line 109 of file RootTree.h.

Referenced by fillStatus().

Definition at line 108 of file RootTree.h.

Referenced by productStatuses().

TBranch* edm::RootTree::statusBranch_ [private]

Definition at line 111 of file RootTree.h.

Referenced by close(), fillStatus(), and isValid().

bool edm::RootTree::trained_ [private]

Definition at line 104 of file RootTree.h.

Referenced by close(), resetTraining(), and setEntryNumber().

TTree* edm::RootTree::tree_ [private]
boost::shared_ptr<TTreeCache> edm::RootTree::treeCache_ [private]

Definition at line 99 of file RootTree.h.

Referenced by fillAux(), fillBranchEntry(), makeDelayedReader(), setCacheSize(), and setEntryNumber().