LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
RootBranchInfoList.cc
Go to the documentation of this file.
2 
5 
6 #include <regex>
7 
8 #include "TIterator.h"
9 #include "TObjArray.h"
10 
12 
14 {
15  reset(tree);
16 }
17 
18 void
20 {
21  if (!tree) {
23  << "RootInfoBranchList given null TTree pointer.\n";
24  }
25  TObjArray* branches = tree->GetListOfBranches();
26  size_t nBranches = branches->GetEntriesFast();
27  data_.clear();
28  data_.reserve(nBranches);
29  TIter it(branches, kIterBackward);
30  // Load the list backward, then searches can take place in the forward
31  // direction.
32  while (TBranch* b = dynamic_cast<TBranch*>(it.Next())) {
33  data_.push_back(RootBranchInfo(b));
34  }
35  if (nBranches != data_.size()) {
36  throw Exception(errors::DataCorruption, "RootBranchInfoList")
37  << "Could not read expected number of branches from TTree's list.\n";
38  }
39 }
40 
41 bool
43  InputTag const& tag,
44  RootBranchInfo& rbInfo) const
45 {
46  std::ostringstream pat_s;
47  pat_s << '^' << type.friendlyClassName() << '_' << tag.label() << '_'
48  << tag.instance() << '_';
49  if (tag.process().empty()) {
50  pat_s << ".*";
51  } else {
52  pat_s << tag.process();
53  }
54  pat_s << "\\.$";
55  std::regex const r{pat_s.str()};
56  // data_ is ordered so that the first match is the best.
57  for (auto const& datum : data_) {
58  if (std::regex_match(datum.branchName(), r)) {
59  rbInfo = datum;
60  return true;
61  }
62  }
63  return false;
64 }
std::string friendlyClassName() const
Definition: TypeID.cc:33
bool findBranchInfo(InputTag const &tag, RootBranchInfo &rbInfo) const
std::string const & process() const noexcept
Definition: InputTag.h:67
std::string const & instance() const noexcept
Definition: InputTag.h:60
std::vector< RootBranchInfo > data_
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::string const & label() const noexcept
Definition: InputTag.h:55