LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
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"
8 
9 namespace art {
10  namespace detail {
11  template <typename T>
12  T
13  readMetadata(TTree* md, bool const requireDict = true)
14  {
15  auto branch = md->GetBranch(art::rootNames::metaBranchRootName<T>());
16  assert(branch != nullptr);
17 
18  auto mdField = requireDict ? root::getObjectRequireDict<T>() : T{};
19  auto field_ptr = &mdField;
20  branch->SetAddress(&field_ptr);
21  input::getEntry(branch, 0);
22  branch->SetAddress(nullptr);
23  return mdField;
24  }
25 
26  template <typename T>
27  bool
28  readMetadata(TTree* md, T& field, bool const requireDict = true)
29  {
30  auto branch = md->GetBranch(art::rootNames::metaBranchRootName<T>());
31  if (branch == nullptr) {
32  return false;
33  }
34 
35  auto mdField = requireDict ? root::getObjectRequireDict<T>() : T{};
36  auto field_ptr = &mdField;
37  branch->SetAddress(&field_ptr);
38  input::getEntry(branch, 0);
39  branch->SetAddress(nullptr);
40  std::swap(mdField, field);
41 
42  return true;
43  }
44  }
45 }
46 
47 #endif /* art_Framework_IO_Root_detail_readMetadata_h */
48 
49 // Local Variables:
50 // mode: c++
51 // End:
HLT enums.
Int_t getEntry(TBranch *branch, EntryNumber entryNumber)
Definition: getEntry.cc:12
T readMetadata(TTree *md, bool const requireDict=true)
Definition: readMetadata.h:13