CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/IOPool/Input/src/RootDelayedReader.cc

Go to the documentation of this file.
00001 /*----------------------------------------------------------------------
00002 ----------------------------------------------------------------------*/
00003 
00004 #include "RootDelayedReader.h"
00005 #include "RootTree.h"
00006 #include "DataFormats/Common/interface/RefCoreStreamer.h"
00007 
00008 #include "TROOT.h"
00009 #include "TBranch.h"
00010 #include "TClass.h"
00011 
00012 namespace edm {
00013 
00014   RootDelayedReader::RootDelayedReader(EntryNumber const& entry,
00015       boost::shared_ptr<BranchMap const> bMap,
00016       RootTree const& tree,
00017       FileFormatVersion const& fileFormatVersion,
00018       boost::shared_ptr<RootFile> filePtr) :
00019    entryNumber_(entry),
00020    branches_(bMap),
00021    tree_(tree),
00022    filePtr_(filePtr),
00023    nextReader_(),
00024    fileFormatVersion_(fileFormatVersion) {}
00025 
00026   RootDelayedReader::~RootDelayedReader() {}
00027 
00028   std::auto_ptr<EDProduct>
00029   RootDelayedReader::getProduct_(BranchKey const& k, EDProductGetter const* ep) const {
00030     iterator iter = branchIter(k);
00031     if (!found(iter)) {
00032       if (nextReader_) {
00033         return nextReader_->getProduct(k, ep);
00034       } else {
00035         return std::auto_ptr<EDProduct>();
00036       }
00037     }
00038     roottree::BranchInfo const& branchInfo = getBranchInfo(iter);
00039     TBranch *br = branchInfo.productBranch_;
00040     if (br == 0) {
00041       if (nextReader_) {
00042         return nextReader_->getProduct(k, ep);
00043       } else {
00044         return std::auto_ptr<EDProduct>();
00045       }
00046     }
00047     setRefCoreStreamer(ep, !fileFormatVersion_.splitProductIDs(), !fileFormatVersion_.productIDIsInt());
00048     TClass *cp = branchInfo.classCache_;
00049     if(0 == cp) {
00050       branchInfo.classCache_ = gROOT->GetClass(branchInfo.branchDescription_.wrappedName().c_str());
00051       cp = branchInfo.classCache_;
00052       TClass *edProductClass = gROOT->GetClass("edm::EDProduct");
00053       branchInfo.offsetToEDProduct_ = edProductClass->GetBaseClassOffset(edProductClass);
00054     }
00055     void *p = cp->New();
00056 
00057     // A union is used to avoid possible copies during the triple cast that would otherwise be needed.
00058     //std::auto_ptr<EDProduct> edp(static_cast<EDProduct *>(static_cast<void *>(static_cast<unsigned char *>(p) + branchInfo.offsetToEDProduct_)));
00059     union {
00060       void* vp;
00061       unsigned char* ucp;
00062       EDProduct* edp;
00063     } pointerUnion;
00064     pointerUnion.vp = p;
00065     pointerUnion.ucp += branchInfo.offsetToEDProduct_;
00066     std::auto_ptr<EDProduct> edp(pointerUnion.edp);
00067 
00068     br->SetAddress(&p);
00069     tree_.getEntry(br, entryNumber_);
00070     setRefCoreStreamer(!fileFormatVersion_.splitProductIDs());
00071     return edp;
00072   }
00073 }