readMetadata.h
Go to the documentation of this file.
1 #ifndef art_Framework_IO_Root_detail_readMetadata_h
2 #define art_Framework_IO_Root_detail_readMetadata_h
3 
4 #include "TBranch.h"
9 
10 namespace art {
11  namespace detail {
12  template <typename T>
13  T
14  readMetadata(TTree* md, bool const requireDict = true)
15  {
17  auto branch = md->GetBranch(art::rootNames::metaBranchRootName<T>());
18  assert(branch != nullptr);
19  auto mdField = requireDict ? root::getObjectRequireDict<T>() : T{};
20  auto field_ptr = &mdField;
21  branch->SetAddress(&field_ptr);
22  input::getEntry(branch, 0);
23  branch->SetAddress(nullptr);
24  return mdField;
25  }
26 
27  template <typename T>
28  bool
29  readMetadata(TTree* md, T& field, bool const requireDict = true)
30  {
32  auto branch = md->GetBranch(art::rootNames::metaBranchRootName<T>());
33  if (branch == nullptr) {
34  return false;
35  }
36  auto mdField = requireDict ? root::getObjectRequireDict<T>() : T{};
37  auto field_ptr = &mdField;
38  branch->SetAddress(&field_ptr);
39  input::getEntry(branch, 0);
40  branch->SetAddress(nullptr);
41  std::swap(mdField, field);
42  return true;
43  }
44  } // namespace detail
45 } // namespace art
46 
47 #endif /* art_Framework_IO_Root_detail_readMetadata_h */
48 
49 // Local Variables:
50 // mode: c++
51 // End:
void swap(Handle< T > &a, Handle< T > &b)
Int_t getEntry(TBranch *branch, EntryNumber entryNumber)
Definition: getEntry.cc:20
T readMetadata(TTree *md, bool const requireDict=true)
Definition: readMetadata.h:14