BranchData.cc
Go to the documentation of this file.
1 #include "gallery/BranchData.h"
2 // vim: set sw=2 expandtab :
3 
7 #include "canvas_root_io/Streamers/RefCoreStreamer.h"
9 
10 #include "TBranch.h"
11 #include "TClass.h"
12 
13 namespace {
15  calculateEDProductAddress(TClass* const tClass, void* address)
16  {
17  static TClass* const edProductTClass_s = TClass::GetClass("art::EDProduct");
18  union {
19  void* vp;
20  unsigned char* ucp;
21  art::EDProduct* edProduct;
22  } pointerUnion;
23  pointerUnion.vp = address;
24  pointerUnion.ucp += tClass->GetBaseClassOffset(edProductTClass_s);
25  return pointerUnion.edProduct;
26  }
27 } // namespace
28 
29 namespace gallery {
30 
32  {
33  if (tClass_) {
34  tClass_->Destructor(address_);
35  }
36  }
37 
39  TClass* iTClass,
40  TBranch* iBranch,
41  EventNavigator const* eventNavigator,
42  art::PrincipalBase const* finder,
43  std::string&& iBranchName)
44  : tClass_{iTClass}
45  , address_{(tClass_ != nullptr) ? tClass_->New() : nullptr}
46  , edProduct_{calculateEDProductAddress(tClass_, address_)}
47  , branch_{iBranch}
48  , eventNavigator_{eventNavigator}
49  , finder_{finder}
50  , lastProduct_{-1}
51  , branchName_{move(iBranchName)}
52  {
53  if (tClass_ == nullptr) {
55  << "In BranchData constructor, no dictionary exists for type "
56  << type.className();
57  }
58  if (address_ == nullptr) {
60  << "In BranchData constructor, failed to construct type "
61  << type.className();
62  }
63  if (branch_) {
64  branch_->SetAddress(&address_);
65  }
66  }
67 
68  void
69  BranchData::updateFile(TBranch* iBranch)
70  {
71  branch_ = iBranch;
72  if (branch_) {
73  branch_->SetAddress(&address_);
74  }
75  lastProduct_ = -1;
76  }
77 
78  art::EDProduct const*
80  {
81  if (branch_ == nullptr) {
82  return nullptr;
83  }
84  long long entry = eventNavigator_->eventEntry();
85  if (entry != lastProduct_) {
86  // haven't gotten the data for this event
87  art::configureRefCoreStreamer(finder_.get());
88  branch_->GetEntry(entry);
89  art::configureRefCoreStreamer();
91  }
92  if (edProduct_->isPresent()) {
93  return edProduct_;
94  }
95  return nullptr;
96  }
97 
98  art::EDProduct const*
100  {
101  return getIt_();
102  }
103 
104  art::EDProduct const*
106  {
107  return getIt_();
108  }
109 
110 } // namespace gallery
std::string branchName_
Definition: BranchData.h:89
art::EDProduct const * edProduct_
Definition: BranchData.h:84
virtual ~BranchData()
Definition: BranchData.cc:31
QList< Entry > entry
std::string string
Definition: nybbler.cc:12
EventNavigator const * eventNavigator_
Definition: BranchData.h:86
constexpr pointer get() const noexcept
Definition: exempt_ptr.h:148
cet::exempt_ptr< art::PrincipalBase const > finder_
Definition: BranchData.h:87
def move(depos, offset)
Definition: depos.py:107
long long lastProduct_
Definition: BranchData.h:88
virtual art::EDProduct const * getIt_() const
Definition: BranchData.cc:79
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
virtual void updateFile(TBranch *iBranch)
Definition: BranchData.cc:69
bool isPresent() const
Definition: EDProduct.h:31
long long eventEntry() const
virtual art::EDProduct const * uniqueProduct_() const
Definition: BranchData.cc:99
TBranch * branch_
Definition: BranchData.h:85