LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
art::RootInputTree Class Reference

#include "RootInputTree.h"

Public Types

using BranchMap = input::BranchMap
 
using EntryNumber = input::EntryNumber
 
using EntryNumbers = input::EntryNumbers
 

Public Member Functions

 RootInputTree (cet::exempt_ptr< TFile >, BranchType, int64_t saveMemoryObjectThreshold, cet::exempt_ptr< RootInputFile >, bool compactSubRunRanges=false, bool missingOK=false)
 
 RootInputTree (RootInputTree const &)=delete
 
RootInputTreeoperator= (RootInputTree const &)=delete
 
 operator bool () const
 
bool isValid () const
 
bool hasBranch (std::string const &branchName) const
 
void addBranch (BranchKey const &, BranchDescription const &)
 
void dropBranch (std::string const &branchName)
 
bool next ()
 
bool previous ()
 
bool current (EntryNumbers const &numbers)
 
void rewind ()
 
EntryNumber entryNumber () const
 
EntryNumber entries () const
 
void setEntryNumber (EntryNumber theEntryNumber)
 
void fillGroups (Principal &p)
 
std::unique_ptr< DelayedReadermakeDelayedReader (FileFormatVersion, cet::exempt_ptr< BranchIDLists const > branchIDLists, BranchType, std::vector< EntryNumber > const &entrySet, EventID)
 
std::unique_ptr< DelayedReadermakeDelayedReader (FileFormatVersion, sqlite3 *inputDB, cet::exempt_ptr< BranchIDLists const > branchIDLists, BranchType, std::vector< EntryNumber > const &entrySet, EventID)
 
std::unique_ptr< BranchMappermakeBranchMapper () const
 
template<typename AUX >
AUX getAux (EntryNumber const entry)
 
template<typename AUX >
std::unique_ptr< RangeSetHandlerfillAux (FileFormatVersion const fileFormatVersion, EntryNumbers const &entries, FileIndex const &fileIndex, sqlite3 *db, std::string const &filename, AUX &aux)
 
TTree const * tree () const
 
TTree const * metaTree () const
 
void setCacheSize (unsigned int cacheSize) const
 
void setTreeMaxVirtualSize (int treeMaxVirtualSize)
 
TBranch * productProvenanceBranch () const
 

Private Attributes

cet::exempt_ptr< TFile > filePtr_
 
TTree * tree_ {nullptr}
 
TTree * metaTree_ {nullptr}
 
BranchType branchType_
 
int64_t const saveMemoryObjectThreshold_
 
TBranch * auxBranch_ {nullptr}
 
TBranch * productProvenanceBranch_ {nullptr}
 
EntryNumber entries_ {0}
 
EntryNumber entryNumber_ {-1}
 
BranchMap branches_ {}
 
cet::exempt_ptr< RootInputFileprimaryFile_
 
bool const compactSubRunRanges_
 

Detailed Description

Definition at line 74 of file RootInputTree.h.

Member Typedef Documentation

Constructor & Destructor Documentation

art::RootInputTree::RootInputTree ( cet::exempt_ptr< TFile >  filePtr,
BranchType  branchType,
int64_t  saveMemoryObjectThreshold,
cet::exempt_ptr< RootInputFile primaryFile,
bool  compactSubRunRanges = false,
bool  missingOK = false 
)

Definition at line 17 of file RootInputTree.cc.

References auxBranch_, branchType_, art::BranchTypeToAuxiliaryBranchName(), art::BranchTypeToMetaDataTreeName(), art::BranchTypeToProductTreeName(), art::BranchTypeToString(), compactSubRunRanges_, entries_, filePtr_, art::errors::FileReadError, isValid(), metaTree_, primaryFile_, productProvenanceBranch_, art::productProvenanceBranchName(), saveMemoryObjectThreshold_, and tree_.

23  : filePtr_{filePtr}
24  , branchType_{branchType}
25  , saveMemoryObjectThreshold_{saveMemoryObjectThreshold}
26  , primaryFile_{primaryFile}
27  , compactSubRunRanges_{compactSubRunRanges}
28  {
29  if (filePtr_) {
30  tree_ = static_cast<TTree*>(
31  filePtr->Get(BranchTypeToProductTreeName(branchType).c_str()));
32  metaTree_ = static_cast<TTree*>(
33  filePtr->Get(BranchTypeToMetaDataTreeName(branchType).c_str()));
34  }
35  if (tree_) {
36  auxBranch_ =
38  entries_ = tree_->GetEntries();
39  }
40  if (metaTree_) {
43  }
44  if (!(missingOK || isValid())) {
46  << "RootInputTree for branch type " << BranchTypeToString(branchType)
47  << " could not be initialized correctly from input file.\n";
48  }
49  }
std::string const & BranchTypeToProductTreeName(BranchType const bt)
Definition: BranchType.cc:71
std::string const & productProvenanceBranchName(BranchType const bt)
Definition: BranchType.cc:91
cet::exempt_ptr< TFile > filePtr_
std::string const & BranchTypeToMetaDataTreeName(BranchType const bt)
Definition: BranchType.cc:77
int64_t const saveMemoryObjectThreshold_
std::string const & BranchTypeToAuxiliaryBranchName(BranchType const bt)
Definition: BranchType.cc:83
BranchType branchType_
TBranch * productProvenanceBranch_
cet::exempt_ptr< RootInputFile > primaryFile_
std::string const & BranchTypeToString(BranchType const bt)
Definition: BranchType.cc:65
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
bool const compactSubRunRanges_
EntryNumber entries_
bool isValid() const
art::RootInputTree::RootInputTree ( RootInputTree const &  )
delete

Member Function Documentation

void art::RootInputTree::addBranch ( BranchKey const &  key,
BranchDescription const &  pd 
)

Definition at line 67 of file RootInputTree.cc.

References branches_, art::BranchDescription::branchName(), isValid(), art::BranchDescription::present(), and tree_.

68  {
69  assert(isValid());
70  TBranch* branch = tree_->GetBranch(pd.branchName().c_str());
71  assert(pd.present() == (branch != nullptr));
72  input::BranchInfo info{pd, branch};
73  branches_.emplace(key, std::move(info));
74  }
bool isValid() const
bool art::RootInputTree::current ( EntryNumbers const &  numbers)
inline

Definition at line 108 of file RootInputTree.h.

109  {
110  assert(!numbers.empty());
111  return std::all_of(numbers.cbegin(), numbers.cend(), [this](auto entry) {
112  return (entry < entries_) && (entry >= 0);
113  });
114  }
EntryNumber entries_
void art::RootInputTree::dropBranch ( std::string const &  branchName)

Definition at line 77 of file RootInputTree.cc.

References branches_, compactSubRunRanges_, entries(), makeDelayedReader(), primaryFile_, saveMemoryObjectThreshold_, and tree_.

78  {
79  TBranch* branch = tree_->GetBranch(branchName.c_str());
80  if (!branch) {
81  return;
82  }
83  TObjArray* leaves = tree_->GetListOfLeaves();
84  int entries = leaves->GetEntries();
85  for (int i = 0; i < entries; ++i) {
86  auto leaf = reinterpret_cast<TLeaf*>((*leaves)[i]);
87  if (leaf == nullptr) {
88  continue;
89  }
90  TBranch* br = leaf->GetBranch();
91  if (br == nullptr) {
92  continue;
93  }
94  if (br->GetMother() == branch) {
95  leaves->Remove(leaf);
96  }
97  }
98  leaves->Compress();
99  tree_->GetListOfBranches()->Remove(branch);
100  tree_->GetListOfBranches()->Compress();
101  delete branch;
102  }
EntryNumber entries() const
EntryNumber art::RootInputTree::entries ( ) const
inline

Definition at line 127 of file RootInputTree.h.

Referenced by dropBranch().

128  {
129  return entries_;
130  }
EntryNumber entries_
EntryNumber art::RootInputTree::entryNumber ( ) const
inline

Definition at line 122 of file RootInputTree.h.

123  {
124  return entryNumber_;
125  }
EntryNumber entryNumber_
template<typename AUX >
std::unique_ptr<RangeSetHandler> art::RootInputTree::fillAux ( FileFormatVersion const  fileFormatVersion,
EntryNumbers const &  entries,
FileIndex const &  fileIndex,
sqlite3 *  db,
std::string const &  filename,
AUX &  aux 
)
inline

Definition at line 186 of file RootInputTree.h.

References e, art::detail::mergeAuxiliary(), art::detail::rangeSetFromFileIndex(), art::detail::resolveRangeSet(), art::detail::resolveRangeSetInfo(), and art::FileFormatVersion::value_.

192  {
193  auto auxResult = getAux<AUX>(entries[0]);
194  if (fileFormatVersion.value_ < 9) {
195  auxResult.setRangeSetID(-1u);
196  auto const& rs = detail::rangeSetFromFileIndex(
197  fileIndex, auxResult.id(), compactSubRunRanges_);
198  std::swap(aux, auxResult);
199  return std::make_unique<ClosedRangeSetHandler>(rs);
200  }
201 
202  auto resolve_info = [db, &filename](auto const id,
203  bool const compactSubRunRanges) {
205  db, filename, AUX::branch_type, id, compactSubRunRanges);
206  };
207 
208  auto rangeSetInfo =
209  resolve_info(auxResult.rangeSetID(), compactSubRunRanges_);
210  for (auto i = entries.cbegin() + 1, e = entries.cend(); i != e; ++i) {
211  auto const& tmpAux = getAux<AUX>(*i);
212  detail::mergeAuxiliary(auxResult, tmpAux);
213  rangeSetInfo.update(
214  resolve_info(tmpAux.rangeSetID(), compactSubRunRanges_),
216  }
217 
218  auxResult.setRangeSetID(-1u); // Range set of new auxiliary is invalid
219  std::swap(aux, auxResult);
220  return std::make_unique<ClosedRangeSetHandler>(
221  resolveRangeSet(rangeSetInfo));
222  }
RangeSetInfo resolveRangeSetInfo(sqlite3 *, std::string const &filename, BranchType, unsigned RangeSetID, bool compact)
RangeSet rangeSetFromFileIndex(FileIndex const &fileIndex, RunID runID, bool compactRanges)
EntryNumber entries() const
RangeSet resolveRangeSet(RangeSetInfo const &rs)
void mergeAuxiliary(AUX &left, AUX const &right)
Definition: RootInputTree.h:43
void swap(art::HLTGlobalStatus &lhs, art::HLTGlobalStatus &rhs)
bool const compactSubRunRanges_
Float_t e
Definition: plot.C:34
void art::RootInputTree::fillGroups ( Principal p)
inline

Definition at line 135 of file RootInputTree.h.

References art::Principal::fillGroup().

136  {
137  if ((metaTree_ == nullptr) || (metaTree_->GetNbranches() == 0)) {
138  return;
139  }
140  // Loop over provenance
141  for (auto const& b : branches_) {
142  p.fillGroup(b.second.branchDescription_);
143  }
144  }
template<typename AUX >
AUX art::RootInputTree::getAux ( EntryNumber const  entry)
inline

Definition at line 174 of file RootInputTree.h.

References art::input::getEntry().

175  {
176  auto aux = std::make_unique<AUX>();
177  auto pAux = aux.get();
178  auxBranch_->SetAddress(&pAux);
179  setEntryNumber(entry);
180  input::getEntry(auxBranch_, entry);
181  return *aux;
182  }
Int_t getEntry(TBranch *branch, EntryNumber entryNumber)
Definition: getEntry.cc:12
void setEntryNumber(EntryNumber theEntryNumber)
bool art::RootInputTree::hasBranch ( std::string const &  branchName) const

Definition at line 61 of file RootInputTree.cc.

References tree_.

62  {
63  return tree_->GetBranch(branchName.c_str()) != nullptr;
64  }
bool art::RootInputTree::isValid ( ) const

Definition at line 52 of file RootInputTree.cc.

References auxBranch_, metaTree_, productProvenanceBranch_, and tree_.

Referenced by addBranch(), and RootInputTree().

53  {
54  if ((metaTree_ == nullptr) || (metaTree_->GetNbranches() == 0)) {
55  return tree_ && auxBranch_ && (tree_->GetNbranches() == 1);
56  }
58  }
TBranch * productProvenanceBranch_
std::unique_ptr< BranchMapper > art::RootInputTree::makeBranchMapper ( ) const

Definition at line 166 of file RootInputTree.cc.

References entryNumber_, and productProvenanceBranch_.

167  {
168  return std::make_unique<BranchMapperWithReader>(productProvenanceBranch_,
169  entryNumber_);
170  }
TBranch * productProvenanceBranch_
EntryNumber entryNumber_
std::unique_ptr<DelayedReader> art::RootInputTree::makeDelayedReader ( FileFormatVersion  ,
cet::exempt_ptr< BranchIDLists const >  branchIDLists,
BranchType  ,
std::vector< EntryNumber > const &  entrySet,
EventID   
)

Referenced by dropBranch().

std::unique_ptr<DelayedReader> art::RootInputTree::makeDelayedReader ( FileFormatVersion  ,
sqlite3 *  inputDB,
cet::exempt_ptr< BranchIDLists const >  branchIDLists,
BranchType  ,
std::vector< EntryNumber > const &  entrySet,
EventID   
)
TTree const* art::RootInputTree::metaTree ( ) const
inline

Definition at line 230 of file RootInputTree.h.

231  {
232  return metaTree_;
233  }
bool art::RootInputTree::next ( )
inline

Definition at line 97 of file RootInputTree.h.

Referenced by art::RootInputFile::nextEventEntry().

98  {
99  return ++entryNumber_ < entries_;
100  }
EntryNumber entryNumber_
EntryNumber entries_
art::RootInputTree::operator bool ( ) const
inlineexplicit

Definition at line 89 of file RootInputTree.h.

89 { return isValid(); }
bool isValid() const
RootInputTree& art::RootInputTree::operator= ( RootInputTree const &  )
delete
bool art::RootInputTree::previous ( )
inline

Definition at line 102 of file RootInputTree.h.

103  {
104  return --entryNumber_ >= 0;
105  }
EntryNumber entryNumber_
TBranch* art::RootInputTree::productProvenanceBranch ( ) const
inline

Definition at line 239 of file RootInputTree.h.

240  {
242  }
TBranch * productProvenanceBranch_
void art::RootInputTree::rewind ( )
inline

Definition at line 117 of file RootInputTree.h.

Referenced by art::RootInputFile::rewind().

118  {
119  entryNumber_ = 0;
120  }
EntryNumber entryNumber_
void art::RootInputTree::setCacheSize ( unsigned int  cacheSize) const

Definition at line 139 of file RootInputTree.cc.

References tree_.

140  {
141  tree_->SetCacheSize(static_cast<Long64_t>(cacheSize));
142  }
void art::RootInputTree::setEntryNumber ( EntryNumber  theEntryNumber)

Definition at line 153 of file RootInputTree.cc.

References entryNumber_, and tree_.

154  {
155  // Note: An entry number of -1 is ok, this can be used
156  // to put the tree an an invalid entry.
157  entryNumber_ = theEntryNumber;
158  auto err = tree_->LoadTree(theEntryNumber);
159  if (err == -2) {
160  // FIXME: Throw an error here!
161  // FIXME: -2 means entry number too big.
162  }
163  }
EntryNumber entryNumber_
void art::RootInputTree::setTreeMaxVirtualSize ( int  treeMaxVirtualSize)

Definition at line 145 of file RootInputTree.cc.

References tree_.

146  {
147  if (treeMaxVirtualSize >= 0) {
148  tree_->SetMaxVirtualSize(static_cast<Long64_t>(treeMaxVirtualSize));
149  }
150  }
TTree const* art::RootInputTree::tree ( ) const
inline

Definition at line 225 of file RootInputTree.h.

226  {
227  return tree_;
228  }

Member Data Documentation

TBranch* art::RootInputTree::auxBranch_ {nullptr}
private

Definition at line 253 of file RootInputTree.h.

Referenced by isValid(), and RootInputTree().

BranchMap art::RootInputTree::branches_ {}
private

Definition at line 257 of file RootInputTree.h.

Referenced by addBranch(), and dropBranch().

BranchType art::RootInputTree::branchType_
private

Definition at line 251 of file RootInputTree.h.

Referenced by RootInputTree().

bool const art::RootInputTree::compactSubRunRanges_
private

Definition at line 259 of file RootInputTree.h.

Referenced by dropBranch(), and RootInputTree().

EntryNumber art::RootInputTree::entries_ {0}
private

Definition at line 255 of file RootInputTree.h.

Referenced by RootInputTree().

EntryNumber art::RootInputTree::entryNumber_ {-1}
private

Definition at line 256 of file RootInputTree.h.

Referenced by makeBranchMapper(), and setEntryNumber().

cet::exempt_ptr<TFile> art::RootInputTree::filePtr_
private

Definition at line 245 of file RootInputTree.h.

Referenced by RootInputTree().

TTree* art::RootInputTree::metaTree_ {nullptr}
private

Definition at line 250 of file RootInputTree.h.

Referenced by isValid(), and RootInputTree().

cet::exempt_ptr<RootInputFile> art::RootInputTree::primaryFile_
private

Definition at line 258 of file RootInputTree.h.

Referenced by dropBranch(), and RootInputTree().

TBranch* art::RootInputTree::productProvenanceBranch_ {nullptr}
private

Definition at line 254 of file RootInputTree.h.

Referenced by isValid(), makeBranchMapper(), and RootInputTree().

int64_t const art::RootInputTree::saveMemoryObjectThreshold_
private

Definition at line 252 of file RootInputTree.h.

Referenced by dropBranch(), and RootInputTree().

TTree* art::RootInputTree::tree_ {nullptr}
private

The documentation for this class was generated from the following files: