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