LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
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 
4 #include "TFile.h"
5 #include "TTree.h"
10 
11 #include <memory>
12 
13 // This function selects retrieves the FileIndex based on whether it
14 // is a branch (file format < 7) or tree (file format >= 7).
15 
16 namespace art {
17  namespace detail {
18 
19  inline void
20  readFileIndex(TFile* file, TTree* metaDataTree, FileIndex*& findexPtr)
21  {
22 
23  if (auto branch = metaDataTree->GetBranch(
24  rootNames::metaBranchRootName<FileIndex>())) {
25  branch->SetAddress(&findexPtr);
26  input::getEntry(branch, 0);
27  branch->SetAddress(nullptr);
28  } else {
29  std::unique_ptr<TTree> fileIndexTree{static_cast<TTree*>(
30  file->Get(rootNames::fileIndexTreeName().c_str()))};
31  if (!fileIndexTree)
34 
35  FileIndex::Element element;
36  auto elemPtr = &element;
37  fileIndexTree->SetBranchAddress(
38  rootNames::metaBranchRootName<FileIndex::Element>(), &elemPtr);
39  for (size_t i{0}, sz = fileIndexTree->GetEntries(); i != sz; ++i) {
40  input::getEntry(fileIndexTree.get(), i);
41  findexPtr->addEntryOnLoad(elemPtr->eventID_, elemPtr->entry_);
42  }
43  fileIndexTree->SetBranchAddress(
44  rootNames::metaBranchRootName<FileIndex::Element>(), nullptr);
45  }
46  }
47  }
48 }
49 
50 #endif /* art_Framework_IO_Root_detail_readFileIndex_h */
51 
52 // Local Variables:
53 // mode: c++
54 // End:
void addEntryOnLoad(EventID const &eID, EntryNumber_t entry)
Definition: FileIndex.cc:37
void readFileIndex(TFile *file, TTree *metaDataTree, FileIndex *&findexPtr)
Definition: readFileIndex.h:20
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:48
TFile * file
HLT enums.
Int_t getEntry(TBranch *branch, EntryNumber entryNumber)
Definition: getEntry.cc:12