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"
6 #include "TROOT.h"
7 #include "TClass.h"
8 #include "TBranch.h"
9 
10 namespace edm {
11 
13  boost::shared_ptr<BranchMap const> bMap,
14  boost::shared_ptr<TTreeCache> treeCache,
15  boost::shared_ptr<InputFile> filePtr,
16  FileFormatVersion const& fileFormatVersion) :
17  entryNumber_(entry),
18  branches_(bMap),
19  treeCache_(treeCache),
20  filePtr_(filePtr),
21  nextReader_(),
22  fileFormatVersion_(fileFormatVersion) {}
23 
25 
26  std::auto_ptr<EDProduct>
28  iterator iter = branchIter(k);
29  if (!found(iter)) {
30  if (nextReader_) {
31  return nextReader_->getProduct(k, ep);
32  } else {
33  return std::auto_ptr<EDProduct>();
34  }
35  }
36  input::BranchInfo const& branchInfo = getBranchInfo(iter);
37  TBranch *br = branchInfo.productBranch_;
38  if (br == 0) {
39  if (nextReader_) {
40  return nextReader_->getProduct(k, ep);
41  } else {
42  return std::auto_ptr<EDProduct>();
43  }
44  }
46  TClass *cp = branchInfo.classCache_;
47  if(0 == cp) {
48  branchInfo.classCache_ = gROOT->GetClass(branchInfo.branchDescription_.wrappedName().c_str());
49  cp = branchInfo.classCache_;
50  TClass *edProductClass = gROOT->GetClass("edm::EDProduct");
51  branchInfo.offsetToEDProduct_ = edProductClass->GetBaseClassOffset(edProductClass);
52  }
53  void *p = cp->New();
54 
55  // A union is used to avoid possible copies during the triple cast that would otherwise be needed.
56  //std::auto_ptr<EDProduct> edp(static_cast<EDProduct *>(static_cast<void *>(static_cast<unsigned char *>(p) + branchInfo.offsetToEDProduct_)));
57  union {
58  void* vp;
59  unsigned char* ucp;
60  EDProduct* edp;
61  } pointerUnion;
62  pointerUnion.vp = p;
63  pointerUnion.ucp += branchInfo.offsetToEDProduct_;
64  std::auto_ptr<EDProduct> edp(pointerUnion.edp);
65 
66  br->SetAddress(&p);
69  return edp;
70  }
71 }
RootDelayedReader(EntryNumber const &entry, boost::shared_ptr< BranchMap const > bMap, boost::shared_ptr< TTreeCache > treeCache, boost::shared_ptr< InputFile > filePtr, FileFormatVersion const &fileFormatVersion)
std::string const & wrappedName() const
input::EntryNumber EntryNumber
void setRefCoreStreamer(bool resetAll=false)
BranchInfo const & getBranchInfo(iterator const &iter) const
TBranch * productBranch_
Definition: Inputfwd.h:34
TClass * classCache_
Definition: Inputfwd.h:36
boost::shared_ptr< InputFile > filePtr_
boost::shared_ptr< TTreeCache > treeCache_
std::pair< std::string, MonitorElement * > entry
Definition: ME_MAP.h:8
input::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_
ConstBranchDescription branchDescription_
Definition: Inputfwd.h:33
FileFormatVersion fileFormatVersion_
EntryNumber const entryNumber_
iterator branchIter(BranchKey const &k) const
Int_t getEntryWithCache(TBranch *branch, EntryNumber entryNumber, TTreeCache *treeCache, InputFile *filePtr)
Definition: RootTree.cc:208