CMS 3D CMS Logo

Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Friends

fwlite::Run Class Reference

#include <Run.h>

Inheritance diagram for fwlite::Run:
fwlite::RunBase edm::RunBase

List of all members.

Public Member Functions

virtual bool atEnd () const
const std::vector
< edm::BranchDescription > & 
getBranchDescriptions () const
virtual const std::string getBranchNameFor (const std::type_info &, const char *, const char *, const char *) const
virtual bool getByLabel (const std::type_info &, const char *, const char *, const char *, void *) const
edm::EDProduct const * getByProductID (edm::ProductID const &) const
bool isValid () const
 operator bool () const
const Runoperator++ ()
 Run (boost::shared_ptr< BranchMapReader > branchMap)
 Run (TFile *iFile)
virtual edm::RunAuxiliary const & runAuxiliary () const
Long64_t size () const
bool to (edm::RunNumber_t run)
 Go to event by Run & Run number.
const RuntoBegin ()
virtual ~Run ()

Static Public Member Functions

static void throwProductNotFoundException (const std::type_info &, const char *, const char *, const char *)

Private Member Functions

const edm::ProcessHistoryhistory () const
const Runoperator= (const Run &)
 Run (const Run &)
void updateAux (Long_t runIndex) const

Private Attributes

edm::RunAuxiliary aux_
TBranch * auxBranch_
boost::shared_ptr
< BranchMapReader
branchMap_
fwlite::DataGetterHelper dataHelper_
EntryFinder entryFinder_
int fileVersion_
edm::ProcessHistoryMap historyMap_
std::vector< const char * > labels_
edm::RunAuxiliarypAux_
edm::RunAuxpOldAux_
std::vector< std::string > procHistoryNames_

Friends

class internal::ProductGetter
class RunHistoryGetter

Detailed Description

Definition at line 55 of file Run.h.


Constructor & Destructor Documentation

Run::Run ( TFile *  iFile)

Definition at line 44 of file Run.cc.

References auxBranch_, branchMap_, edm::BranchTypeToAuxiliaryBranchName(), Exception, fileVersion_, edm::InRun, pAux_, and edm::poolNames::runTreeName().

                      :
    branchMap_(new BranchMapReader(iFile)),
    pAux_(&aux_),
    pOldAux_(0),
    fileVersion_(-1),
    dataHelper_(branchMap_->getRunTree(),
                boost::shared_ptr<HistoryGetterBase>(new RunHistoryGetter(this)),
                branchMap_)
  {
    if(0==iFile) {
      throw cms::Exception("NoFile")<<"The TFile pointer passed to the constructor was null";
    }

    if(0==branchMap_->getRunTree()) {
      throw cms::Exception("NoRunTree")<<"The TFile contains no TTree named " <<edm::poolNames::runTreeName();
    }
    //need to know file version in order to determine how to read the basic product info
    fileVersion_ = branchMap_->getFileVersion(iFile);

    //got this logic from IOPool/Input/src/RootFile.cc

    TTree* runTree = branchMap_->getRunTree();
    if(fileVersion_ >= 3 ) {
      auxBranch_ = runTree->GetBranch(edm::BranchTypeToAuxiliaryBranchName(edm::InRun).c_str());
      if(0==auxBranch_) {
        throw cms::Exception("NoRunAuxilliary")<<"The TTree "
        <<edm::poolNames::runTreeName()
        <<" does not contain a branch named 'RunAuxiliary'";
      }
      auxBranch_->SetAddress(&pAux_);
    } else {
      throw cms::Exception("OldFileVersion")<<"The FWLite Run code des not support old file versions";
//       This code commented from fwlite::Event. May be portable if needed.
//       pOldAux_ = new edm::EventAux();
//       auxBranch_ = runTree->GetBranch(edm::BranchTypeToAuxBranchName(edm::InRun).c_str());
//       if(0==auxBranch_) {
//         throw cms::Exception("NoRunAux")<<"The TTree "
//           <<edm::poolNames::runTreeName()
//           <<" does not contain a branch named 'RunAux'";
//       }
//       auxBranch_->SetAddress(&pOldAux_);
    }
    branchMap_->updateRun(0);
//     getter_ = boost::shared_ptr<edm::EDProductGetter>(new ProductGetter(this));
}
Run::Run ( boost::shared_ptr< BranchMapReader branchMap)

Definition at line 90 of file Run.cc.

References auxBranch_, branchMap_, edm::BranchTypeToAuxiliaryBranchName(), Exception, fileVersion_, edm::InRun, pAux_, and edm::poolNames::runTreeName().

                                                    :
    branchMap_(branchMap),
    pAux_(&aux_),
    pOldAux_(0),
    fileVersion_(-1),
    dataHelper_(branchMap_->getRunTree(),
                boost::shared_ptr<HistoryGetterBase>(new RunHistoryGetter(this)),
                branchMap_)
  {
    if(0==branchMap_->getRunTree()) {
      throw cms::Exception("NoRunTree")<<"The TFile contains no TTree named " <<edm::poolNames::runTreeName();
    }
    //need to know file version in order to determine how to read the basic event info
    fileVersion_ = branchMap_->getFileVersion();
    //got this logic from IOPool/Input/src/RootFile.cc

    TTree* runTree = branchMap_->getRunTree();
    if(fileVersion_ >= 3 ) {
      auxBranch_ = runTree->GetBranch(edm::BranchTypeToAuxiliaryBranchName(edm::InRun).c_str());
      if(0==auxBranch_) {
        throw cms::Exception("NoRunAuxilliary")<<"The TTree "
        <<edm::poolNames::runTreeName()
        <<" does not contain a branch named 'RunAuxiliary'";
      }
      auxBranch_->SetAddress(&pAux_);
    } else {
      throw cms::Exception("OldFileVersion")<<"The FWLite Run code des not support old file versions";
/*      pOldAux_ = new edm::EventAux();
      auxBranch_ = runTree->GetBranch(edm::BranchTypeToAuxBranchName(edm::InRun).c_str());
      if(0==auxBranch_) {
        throw cms::Exception("NoRunAux")<<"The TTree "
          <<edm::poolNames::runTreeName()
          <<" does not contain a branch named 'RunAux'";
      }
      auxBranch_->SetAddress(&pOldAux_);*/
    }
    branchMap_->updateRun(0);

//     if(fileVersion_ >= 7 ) {
//       eventHistoryTree_ = dynamic_cast<TTree*>(iFile->Get(edm::poolNames::eventHistoryTreeName().c_str()));
//     }

//     getter_ = boost::shared_ptr<edm::EDProductGetter>(new ProductGetter(this));
}
Run::~Run ( ) [virtual]

Definition at line 135 of file Run.cc.

References labels_, and pOldAux_.

{
  for(std::vector<const char*>::iterator it = labels_.begin(), itEnd=labels_.end();
      it != itEnd;
      ++it) {
    delete [] *it;
  }
  delete pOldAux_;
}
fwlite::Run::Run ( const Run ) [private]

Member Function Documentation

bool Run::atEnd ( ) const [virtual]

Implements fwlite::RunBase.

Definition at line 202 of file Run.cc.

References branchMap_, and size().

Referenced by getByLabel(), and main().

{
  Long_t runIndex = branchMap_->getRunEntry();
  return runIndex==-1 or runIndex == size();
}
const std::vector<edm::BranchDescription>& fwlite::Run::getBranchDescriptions ( ) const [inline]

Definition at line 92 of file Run.h.

References branchMap_.

                                                                              {
            return branchMap_->getBranchDescriptions();
         }
const std::string Run::getBranchNameFor ( const std::type_info &  iInfo,
const char *  iModuleLabel,
const char *  iProductInstanceLabel,
const char *  iProcessLabel 
) const [virtual]

Definition at line 210 of file Run.cc.

References dataHelper_, and fwlite::DataGetterHelper::getBranchNameFor().

{
    return dataHelper_.getBranchNameFor(iInfo, iModuleLabel, iProductInstanceLabel, iProcessLabel);
}
bool Run::getByLabel ( const std::type_info &  iInfo,
const char *  iModuleLabel,
const char *  iProductInstanceLabel,
const char *  iProcessLabel,
void *  oData 
) const [virtual]

Implements fwlite::RunBase.

Definition at line 219 of file Run.cc.

References atEnd(), branchMap_, dataHelper_, Exception, and fwlite::DataGetterHelper::getByLabel().

Referenced by FWMagField::checkFieldInfo().

{
    if(atEnd()) {
        throw cms::Exception("OffEnd")<<"You have requested data past the last run";
    }
    Long_t runIndex = branchMap_->getRunEntry();
    return dataHelper_.getByLabel(iInfo, iModuleLabel, iProductInstanceLabel, iProcessLabel, oData, runIndex);
}
edm::EDProduct const * Run::getByProductID ( edm::ProductID const &  iID) const

Definition at line 317 of file Run.cc.

References branchMap_, dataHelper_, and fwlite::DataGetterHelper::getByProductID().

{
  Long_t runIndex = branchMap_->getRunEntry();
  return dataHelper_.getByProductID(iID, runIndex);
}
const edm::ProcessHistory & Run::history ( ) const [private]

Definition at line 253 of file Run.cc.

References aux_, b, branchMap_, Exception, fileVersion_, historyMap_, i, edm::poolNames::metaDataTreeName(), edm::poolNames::processHistoryBranchName(), edm::RunAuxiliary::processHistoryID(), edm::poolNames::processHistoryMapBranchName(), procHistoryNames_, and updateAux().

Referenced by fwlite::RunHistoryGetter::history().

{
  edm::ProcessHistoryID processHistoryID;

  bool newFormat = false;//(fileVersion_ >= 5);

  Long_t runIndex = branchMap_->getRunEntry();
  updateAux(runIndex);
  if (!newFormat) {
    processHistoryID = aux_.processHistoryID();
  }

  if(historyMap_.empty() || newFormat) {
    procHistoryNames_.clear();
    TTree *meta = dynamic_cast<TTree*>(branchMap_->getFile()->Get(edm::poolNames::metaDataTreeName().c_str()));
    if(0==meta) {
      throw cms::Exception("NoMetaTree")<<"The TFile does not appear to contain a TTree named "
      <<edm::poolNames::metaDataTreeName();
    }
    if (historyMap_.empty()) {
      if (fileVersion_ < 11) {
        edm::ProcessHistoryMap* pPhm=&historyMap_;
        TBranch* b = meta->GetBranch(edm::poolNames::processHistoryMapBranchName().c_str());
        b->SetAddress(&pPhm);
        b->GetEntry(0);
      } else {
        edm::ProcessHistoryVector historyVector;
        edm::ProcessHistoryVector* pPhv=&historyVector;
        TBranch* b = meta->GetBranch(edm::poolNames::processHistoryBranchName().c_str());
        b->SetAddress(&pPhv);
        b->GetEntry(0);
        for (edm::ProcessHistoryVector::const_iterator i = historyVector.begin(), e = historyVector.end();
            i != e; ++i) {
          historyMap_.insert(std::make_pair(i->id(), *i));
        }
      }
    }
//     if (newFormat) {
//       if (fileVersion_ >= 7) {
//         edm::History history;
//         edm::History* pHistory = &history;
//         TBranch* eventHistoryBranch = eventHistoryTree_->GetBranch(edm::poolNames::eventHistoryBranchName().c_str());
//         if (!eventHistoryBranch)
//           throw edm::Exception(edm::errors::FatalRootError)
//             << "Failed to find history branch in event history tree";
//         eventHistoryBranch->SetAddress(&pHistory);
//         eventHistoryTree_->GetEntry(runIndex);
//         processHistoryID = history.processHistoryID();
//       } else {
//         std::vector<edm::EventProcessHistoryID> *pEventProcessHistoryIDs = &eventProcessHistoryIDs_;
//         TBranch* b = meta->GetBranch(edm::poolNames::eventHistoryBranchName().c_str());
//         b->SetAddress(&pEventProcessHistoryIDs);
//         b->GetEntry(0);
//         edm::EventProcessHistoryID target(aux_.id(), edm::ProcessHistoryID());
//         processHistoryID = std::lower_bound(eventProcessHistoryIDs_.begin(), eventProcessHistoryIDs_.end(), target)->processHistoryID_;
//       }
//     }

  }
  return historyMap_[processHistoryID];
}
bool Run::isValid ( void  ) const

Definition at line 189 of file Run.cc.

References branchMap_, and size().

Referenced by operator bool().

{
  Long_t runIndex = branchMap_->getRunEntry();
  return runIndex!=-1 and runIndex < size();
}
Run::operator bool ( ) const

Definition at line 196 of file Run.cc.

References isValid().

{
  return isValid();
}
const Run & Run::operator++ ( ) [virtual]

Implements fwlite::RunBase.

Definition at line 150 of file Run.cc.

References branchMap_, and size().

{
   Long_t runIndex = branchMap_->getRunEntry();
   if(runIndex < size())
   {
      branchMap_->updateRun(++runIndex);
   }
   return *this;
}
const Run& fwlite::Run::operator= ( const Run ) [private]
edm::RunAuxiliary const & Run::runAuxiliary ( ) const [virtual]

Implements edm::RunBase.

Definition at line 233 of file Run.cc.

References aux_, branchMap_, and updateAux().

{
   Long_t runIndex = branchMap_->getRunEntry();
   updateAux(runIndex);
   return aux_;
}
Long64_t Run::size ( void  ) const

Definition at line 183 of file Run.cc.

References branchMap_.

Referenced by atEnd(), isValid(), and operator++().

{
  return branchMap_->getRunTree()->GetEntries();
}
void Run::throwProductNotFoundException ( const std::type_info &  iType,
const char *  iModule,
const char *  iProduct,
const char *  iProcess 
) [static]

Definition at line 328 of file Run.cc.

References edm::TypeID::className(), Exception, and edm::errors::ProductNotFound.

{
    edm::TypeID type(iType);
  throw edm::Exception(edm::errors::ProductNotFound)<<"A branch was found for \n  type ='"<<type.className()<<"'\n  module='"<<iModule
    <<"'\n  productInstance='"<<((0!=iProduct)?iProduct:"")<<"'\n  process='"<<((0!=iProcess)?iProcess:"")<<"'\n"
    "but no data is available for this Run";
}
bool Run::to ( edm::RunNumber_t  run)

Go to event by Run & Run number.

Definition at line 162 of file Run.cc.

References branchMap_, entryFinder_, fwlite::EntryFinder::fillIndex(), fwlite::EntryFinder::findRun(), and fwlite::EntryFinder::invalidEntry.

{
   entryFinder_.fillIndex(*branchMap_);
   EntryFinder::EntryNumber_t entry = entryFinder_.findRun(run);
   if (entry == EntryFinder::invalidEntry) {
      return false;
   }
   return branchMap_->updateRun(entry);
}
const Run & Run::toBegin ( ) [virtual]

Implements fwlite::RunBase.

Definition at line 173 of file Run.cc.

References branchMap_.

Referenced by main().

{
   branchMap_->updateRun(0);
   return *this;
}
void Run::updateAux ( Long_t  runIndex) const [private]

Definition at line 241 of file Run.cc.

References aux_, auxBranch_, edm::conversion(), and pOldAux_.

Referenced by history(), and runAuxiliary().

{
  if(auxBranch_->GetEntryNumber() != runIndex) {
    auxBranch_->GetEntry(runIndex);
    //handling dealing with old version
    if(0 != pOldAux_) {
      conversion(*pOldAux_,aux_);
    }
  }
}

Friends And Related Function Documentation

friend class internal::ProductGetter [friend]

Definition at line 106 of file Run.h.

friend class RunHistoryGetter [friend]

Definition at line 107 of file Run.h.


Member Data Documentation

Definition at line 123 of file Run.h.

Referenced by history(), runAuxiliary(), and updateAux().

TBranch* fwlite::Run::auxBranch_ [private]

Definition at line 127 of file Run.h.

Referenced by Run(), and updateAux().

boost::shared_ptr<BranchMapReader> fwlite::Run::branchMap_ [mutable, private]

Definition at line 130 of file Run.h.

Referenced by getBranchNameFor(), getByLabel(), and getByProductID().

Definition at line 124 of file Run.h.

Referenced by to().

Definition at line 128 of file Run.h.

Referenced by history(), and Run().

Definition at line 121 of file Run.h.

Referenced by history().

std::vector<const char*> fwlite::Run::labels_ [mutable, private]

Definition at line 120 of file Run.h.

Referenced by ~Run().

Definition at line 125 of file Run.h.

Referenced by Run().

Definition at line 126 of file Run.h.

Referenced by updateAux(), and ~Run().

std::vector<std::string> fwlite::Run::procHistoryNames_ [mutable, private]

Definition at line 122 of file Run.h.

Referenced by history().