CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RootDelayedReader.cc
Go to the documentation of this file.
1 /*----------------------------------------------------------------------
2 ----------------------------------------------------------------------*/
3 
4 #include "RootDelayedReader.h"
5 #include "RootTree.h"
7 
8 #include "TROOT.h"
9 #include "TBranch.h"
10 #include "TClass.h"
11 
12 namespace edm {
13 
15  boost::shared_ptr<BranchMap const> bMap,
16  RootTree const& tree,
17  FileFormatVersion const& fileFormatVersion,
18  boost::shared_ptr<RootFile> filePtr) :
19  entryNumber_(entry),
20  branches_(bMap),
21  tree_(tree),
22  filePtr_(filePtr),
23  nextReader_(),
24  fileFormatVersion_(fileFormatVersion) {}
25 
27 
28  std::auto_ptr<EDProduct>
30  iterator iter = branchIter(k);
31  if (!found(iter)) {
32  if (nextReader_) {
33  return nextReader_->getProduct(k, ep);
34  } else {
35  return std::auto_ptr<EDProduct>();
36  }
37  }
38  roottree::BranchInfo const& branchInfo = getBranchInfo(iter);
39  TBranch *br = branchInfo.productBranch_;
40  if (br == 0) {
41  if (nextReader_) {
42  return nextReader_->getProduct(k, ep);
43  } else {
44  return std::auto_ptr<EDProduct>();
45  }
46  }
48  TClass *cp = branchInfo.classCache_;
49  if(0 == cp) {
50  branchInfo.classCache_ = gROOT->GetClass(branchInfo.branchDescription_.wrappedName().c_str());
51  cp = branchInfo.classCache_;
52  TClass *edProductClass = gROOT->GetClass("edm::EDProduct");
53  branchInfo.offsetToEDProduct_ = edProductClass->GetBaseClassOffset(edProductClass);
54  }
55  void *p = cp->New();
56 
57  // A union is used to avoid possible copies during the triple cast that would otherwise be needed.
58  //std::auto_ptr<EDProduct> edp(static_cast<EDProduct *>(static_cast<void *>(static_cast<unsigned char *>(p) + branchInfo.offsetToEDProduct_)));
59  union {
60  void* vp;
61  unsigned char* ucp;
62  EDProduct* edp;
63  } pointerUnion;
64  pointerUnion.vp = p;
65  pointerUnion.ucp += branchInfo.offsetToEDProduct_;
66  std::auto_ptr<EDProduct> edp(pointerUnion.edp);
67 
68  br->SetAddress(&p);
71  return edp;
72  }
73 }
std::string const & wrappedName() const
ConstBranchDescription branchDescription_
Definition: RootTree.h:51
RootTree const & tree_
void setRefCoreStreamer(bool resetAll=false)
BranchInfo const & getBranchInfo(iterator const &iter) const
std::pair< std::string, MonitorElement * > entry
Definition: ME_MAP.h:8
roottree::BranchMap::const_iterator iterator
virtual std::auto_ptr< EDProduct > getProduct_(BranchKey const &k, EDProductGetter const *ep) const
int k[5][pyjets_maxn]
bool found(iterator const &iter) const
boost::shared_ptr< DelayedReader > nextReader_
void getEntry(TBranch *branch, EntryNumber entry) const
Definition: RootTree.cc:169
TBranch * productBranch_
Definition: RootTree.h:52
RootDelayedReader(EntryNumber const &entry, boost::shared_ptr< BranchMap const > bMap, RootTree const &tree, FileFormatVersion const &fileFormatVersion, boost::shared_ptr< RootFile > filePtr)
roottree::EntryNumber EntryNumber
FileFormatVersion fileFormatVersion_
EntryNumber const entryNumber_
iterator branchIter(BranchKey const &k) const