CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/IOPool/Input/src/RootDelayedReader.cc

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