BranchMapReader.cc
Go to the documentation of this file.
2 
6 #include "canvas_root_io/Streamers/BranchDescriptionStreamer.h"
9 
10 #include "TFile.h"
11 #include "TTree.h"
12 
13 #include <memory>
14 
15 class TBranch;
16 
17 namespace gallery {
18 
19  void
21  {
22 
23  std::unique_ptr<TTree> metaDataTree{
24  tFile->Get<TTree>(art::rootNames::metaDataTreeName().c_str())};
25  if (!metaDataTree) {
27  }
28 
29  auto productRegistry = std::make_unique<art::ProductRegistry>();
30  auto* productRegistryPtr = productRegistry.get();
31  TBranch* productRegistryBranch = metaDataTree->GetBranch(
32  art::rootNames::metaBranchRootName<art::ProductRegistry>());
33  if (productRegistryBranch == nullptr) {
35  art::rootNames::metaBranchRootName<art::ProductRegistry>());
36  }
37  metaDataTree->SetBranchAddress(
38  art::rootNames::metaBranchRootName<art::ProductRegistry>(),
39  &productRegistryPtr);
40 
41  // To support files that contain BranchIDLists
42  branchIDLists_.reset(nullptr);
44  bool hasBranchIDLists{false};
45  if (metaDataTree->GetBranch(
46  art::rootNames::metaBranchRootName<art::BranchIDLists>())) {
47  hasBranchIDLists = true;
48  auto branchIDListsPtr = &branchIDLists;
49  metaDataTree->SetBranchAddress(
50  art::rootNames::metaBranchRootName<art::BranchIDLists>(),
51  &branchIDListsPtr);
52  }
53 
54  metaDataTree->GetEntry(0);
55 
56  // Necessary only for supporting conversion of an old Product ID
57  // schema to the current one
58  if (hasBranchIDLists) {
60  std::make_unique<art::BranchIDLists>(std::move(branchIDLists));
61  metaDataTree->SetBranchAddress(
62  art::rootNames::metaBranchRootName<art::BranchIDLists>(), nullptr);
63  }
64 
66  for (auto const& product : productRegistry->productList_) {
67  art::BranchDescription const& branchDescription = product.second;
68  if (branchDescription.branchType() != art::InEvent)
69  continue;
70  if (!branchDescription.productID().isValid())
71  continue;
72 
73  art::detail::BranchDescriptionStreamer::fluffRootTransients(
74  branchDescription);
75  productIDToDescriptionMap_.emplace(branchDescription.productID(),
76  branchDescription);
77  allSeenProductIDs_.insert(branchDescription.productID());
78  }
79  }
80 
83  std::string const& process) const
84  {
85  return productDescription(
86  info.type(), info.label(), info.instance(), process);
87  }
88 
91  std::string const& label,
92  std::string const& instance,
93  std::string const& process) const
94  {
95  auto const fcn = type.friendlyClassName();
96  auto match = [&fcn, &label, &instance, &process](auto const& pr) {
97  auto const& pd = pr.second;
98  return pd.friendlyClassName() == fcn && pd.moduleLabel() == label &&
99  pd.productInstanceName() == instance &&
100  pd.processName() == process;
101  };
102  auto const end = cend(productIDToDescriptionMap_);
103  auto it = std::find_if(cbegin(productIDToDescriptionMap_), end, match);
104  return it == end ? nullptr : &it->second;
105  }
106 
109  {
110  auto bdi = productIDToDescriptionMap_.find(pid);
111  if (bdi == cend(productIDToDescriptionMap_)) {
112  return nullptr;
113  }
114  return &bdi->second;
115  }
116 
117  std::map<art::ProductID, art::BranchDescription> const&
119  {
121  }
122 
125  {
126  return branchIDLists_.get();
127  }
128 
129  bool
131  art::ProductID const& productID) const
132  {
133  return allSeenProductIDs_.find(productID) != allSeenProductIDs_.end();
134  }
135 } // namespace gallery
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:18
decltype(auto) constexpr cend(T &&obj)
ADL-aware version of std::cend.
Definition: StdUtils.h:87
art::BranchDescription const * productDescription(InfoForTypeLabelInstance const &info, std::string const &process) const
std::string friendlyClassName() const
Definition: TypeID.cc:61
std::string string
Definition: nybbler.cc:12
const std::string instance
std::map< art::ProductID, art::BranchDescription > productIDToDescriptionMap_
def process(f, kind)
Definition: search.py:254
BranchType branchType() const noexcept
void throwTreeNotFound(std::string const &treeName)
std::string const & metaDataTreeName()
Definition: rootNames.cc:42
std::map< art::ProductID, art::BranchDescription > const & productDescriptions() const
void updateFile(TFile *tFile)
std::string const & instance() const noexcept
def move(depos, offset)
Definition: depos.py:107
constexpr bool isValid() const noexcept
Definition: ProductID.h:34
void throwBranchNotFound(std::string const &branchName)
bool branchInRegistryOfAnyOpenedFile(art::ProductID const &) const
std::unique_ptr< art::BranchIDLists > branchIDLists_
std::string const & label() const noexcept
art::TypeID const & type() const noexcept
decltype(auto) constexpr cbegin(T &&obj)
ADL-aware version of std::cbegin.
Definition: StdUtils.h:82
cet::exempt_ptr< art::BranchIDLists const > branchIDLists() const
std::set< art::ProductID > allSeenProductIDs_
ProductID productID() const noexcept