readFileIndex.h
Go to the documentation of this file.
1 #ifndef art_Framework_IO_Root_detail_readFileIndex_h
2 #define art_Framework_IO_Root_detail_readFileIndex_h
3 
9 
10 #include "TFile.h"
11 #include "TTree.h"
12 
13 #include <memory>
14 
15 // This function selects retrieves the FileIndex based on whether it
16 // is a branch (file format < 7) or tree (file format >= 7).
17 
18 namespace art {
19  namespace detail {
20 
21  inline void
22  readFileIndex(TFile* file, TTree* metaDataTree, FileIndex*& findexPtr)
23  {
25  if (auto branch = metaDataTree->GetBranch(
26  rootNames::metaBranchRootName<FileIndex>())) {
27  branch->SetAddress(&findexPtr);
28  input::getEntry(branch, 0);
29  branch->SetAddress(nullptr);
30  } else {
31  std::unique_ptr<TTree> fileIndexTree{static_cast<TTree*>(
32  file->Get(rootNames::fileIndexTreeName().c_str()))};
33  if (!fileIndexTree)
36 
37  FileIndex::Element element;
38  auto elemPtr = &element;
39  fileIndexTree->SetBranchAddress(
40  rootNames::metaBranchRootName<FileIndex::Element>(), &elemPtr);
41  for (size_t i{0}, sz = fileIndexTree->GetEntries(); i != sz; ++i) {
42  input::getEntry(fileIndexTree.get(), i);
43  findexPtr->addEntryOnLoad(elemPtr->eventID_, elemPtr->entry_);
44  }
45  fileIndexTree->SetBranchAddress(
46  rootNames::metaBranchRootName<FileIndex::Element>(), nullptr);
47  }
48  }
49  } // namespace detail
50 
51 } // namespace art
52 
53 #endif /* art_Framework_IO_Root_detail_readFileIndex_h */
54 
55 // Local Variables:
56 // mode: c++
57 // End:
void addEntryOnLoad(EventID const &eID, EntryNumber_t entry)
Definition: FileIndex.cc:154
void readFileIndex(TFile *file, TTree *metaDataTree, FileIndex *&findexPtr)
Definition: readFileIndex.h:22
std::string couldNotFindTree(std::string const &treename)
Definition: rootErrMsgs.h:9
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::string const & fileIndexTreeName()
Definition: rootNames.cc:47
Int_t getEntry(TBranch *branch, EntryNumber entryNumber)
Definition: getEntry.cc:20