CMS 3D CMS Logo

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

fwlite::ChainEvent Class Reference

#include <ChainEvent.h>

Inheritance diagram for fwlite::ChainEvent:
fwlite::EventBase edm::EventBase

List of all members.

Public Member Functions

virtual bool atEnd () const
 ChainEvent (const std::vector< std::string > &iFileNames)
Event const * event () const
virtual edm::EventAuxiliary const & eventAuxiliary () const
Long64_t eventIndex () const
virtual Long64_t fileIndex () const
void fillParameterSetRegistry () 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
fwlite::LuminosityBlock const & getLuminosityBlock ()
const std::vector< std::string > & getProcessHistory () const
fwlite::Run const & getRun ()
TFile * getTFile () const
bool isValid () const
 operator bool () const
const ChainEventoperator++ ()
edm::ProcessHistory const & processHistory () const
void setGetter (boost::shared_ptr< edm::EDProductGetter > getter)
Long64_t size () const
bool to (edm::RunNumber_t run, edm::LuminosityBlockNumber_t lumi, edm::EventNumber_t event)
bool to (edm::RunNumber_t run, edm::EventNumber_t event)
bool to (Long64_t iIndex)
 Go to the event at index iIndex.
bool to (const edm::EventID &id)
 Go to event with event id "id".
const ChainEventtoBegin ()
virtual edm::TriggerNames const & triggerNames (edm::TriggerResults const &triggerResults) const
virtual edm::TriggerResultsByName triggerResultsByName (std::string const &process) const
virtual ~ChainEvent ()

Static Public Member Functions

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

Private Member Functions

 ChainEvent (const Event &)
void findSizes ()
const ChainEventoperator= (const Event &)
void switchToFile (Long64_t)

Private Attributes

std::vector< Long64_t > accumulatedSize_
boost::shared_ptr< Eventevent_
Long64_t eventIndex_
boost::shared_ptr< TFile > file_
std::vector< std::string > fileNames_
boost::shared_ptr
< edm::EDProductGetter
getter_

Friends

class MultiChainEvent

Detailed Description

Definition at line 46 of file ChainEvent.h.


Constructor & Destructor Documentation

ChainEvent::ChainEvent ( const std::vector< std::string > &  iFileNames)

Definition at line 35 of file ChainEvent.cc.

References accumulatedSize_, edm::poolNames::eventTreeName(), Exception, file_, fileNames_, nEvents, switchToFile(), and diffTreeTool::tree.

                                                            :
  fileNames_(),
  file_(),
  event_(),
  eventIndex_(0),
  accumulatedSize_()
{
  Long64_t summedSize=0;
  accumulatedSize_.reserve(iFileNames.size()+1);
  fileNames_.reserve(iFileNames.size());
    
  for (std::vector<std::string>::const_iterator it= iFileNames.begin(), itEnd = iFileNames.end();
      it!=itEnd;
      ++it) {
    TFile *tfilePtr = TFile::Open(it->c_str());
    file_ = boost::shared_ptr<TFile>(tfilePtr);
    gROOT->GetListOfFiles()->Remove(tfilePtr);
    TTree* tree = dynamic_cast<TTree*>(file_->Get(edm::poolNames::eventTreeName().c_str()));
    if (0 == tree) {
      throw cms::Exception("NotEdmFile")<<"The file "<<*it<<" has no 'Events' TTree and therefore is not an EDM ROOT file";
    }
    Long64_t nEvents = tree->GetEntries();
    if (nEvents > 0) { // skip empty files
      fileNames_.push_back(*it);
      // accumulatedSize_ is the entry # at the beginning of this file
      accumulatedSize_.push_back(summedSize);
      summedSize += nEvents;
    }
  }
  // total accumulated size (last enry + 1) at the end of last file
  accumulatedSize_.push_back(summedSize);

  if (fileNames_.size() > 0)
    switchToFile(0);
}
ChainEvent::~ChainEvent ( ) [virtual]

Definition at line 76 of file ChainEvent.cc.

{
}
fwlite::ChainEvent::ChainEvent ( const Event ) [private]

Member Function Documentation

bool ChainEvent::atEnd ( ) const [virtual]

Implements fwlite::EventBase.

Definition at line 293 of file ChainEvent.cc.

References event_, eventIndex_, and fileNames_.

Referenced by fwlite::AnalyzerWrapper< T >::analyze(), and main().

{
  if (eventIndex_ == static_cast<Long64_t>(fileNames_.size())-1) {
    return event_->atEnd();
  }
  return false;
}
Event const* fwlite::ChainEvent::event ( ) const [inline]

Definition at line 102 of file ChainEvent.h.

References event_.

Referenced by to().

{ return &*event_; }
edm::EventAuxiliary const & ChainEvent::eventAuxiliary ( ) const [virtual]

Implements edm::EventBase.

Definition at line 251 of file ChainEvent.cc.

References event_.

{
   return event_->eventAuxiliary();
}
Long64_t fwlite::ChainEvent::eventIndex ( ) const [inline]

Definition at line 95 of file ChainEvent.h.

References eventIndex_.

{ return eventIndex_; }
virtual Long64_t fwlite::ChainEvent::fileIndex ( ) const [inline, virtual]

Reimplemented from fwlite::EventBase.

Definition at line 96 of file ChainEvent.h.

References eventIndex_.

{ return eventIndex_; }
void ChainEvent::fillParameterSetRegistry ( ) const

Definition at line 314 of file ChainEvent.cc.

References event_.

{
  event_->fillParameterSetRegistry();
}
void fwlite::ChainEvent::findSizes ( ) [private]
const std::vector< edm::BranchDescription > & ChainEvent::getBranchDescriptions ( ) const

Definition at line 233 of file ChainEvent.cc.

References event_.

{
  return event_->getBranchDescriptions();
}
const std::string ChainEvent::getBranchNameFor ( const std::type_info &  iType,
const char *  iModule,
const char *  iInstance,
const char *  iProcess 
) const [virtual]

Implements fwlite::EventBase.

Definition at line 224 of file ChainEvent.cc.

References event_.

{
  return event_->getBranchNameFor(iType,iModule,iInstance,iProcess);
}
bool ChainEvent::getByLabel ( const std::type_info &  iType,
const char *  iModule,
const char *  iInstance,
const char *  iProcess,
void *  iValue 
) const [virtual]

Implements fwlite::EventBase.

Definition at line 268 of file ChainEvent.cc.

References event_.

{
  return event_->getByLabel(iType,iModule,iInstance,iProcess,iValue);
}
edm::EDProduct const * ChainEvent::getByProductID ( edm::ProductID const &  iID) const

Definition at line 277 of file ChainEvent.cc.

References event_.

{
  return event_->getByProductID( iID );
}
fwlite::LuminosityBlock const & ChainEvent::getLuminosityBlock ( )

Definition at line 256 of file ChainEvent.cc.

References event_.

{
   return event_->getLuminosityBlock();
}
const std::vector< std::string > & ChainEvent::getProcessHistory ( ) const

Definition at line 239 of file ChainEvent.cc.

References event_.

{
  return event_->getProcessHistory();
}
fwlite::Run const & ChainEvent::getRun ( )

Definition at line 261 of file ChainEvent.cc.

References event_.

{
   return event_->getRun();
}
TFile* fwlite::ChainEvent::getTFile ( ) const [inline]

Definition at line 91 of file ChainEvent.h.

References event_.

Referenced by PFRootEventManager::reset().

                              {
        return event_->getTFile();
      }
bool ChainEvent::isValid ( void  ) const

Definition at line 283 of file ChainEvent.cc.

References event_.

Referenced by PFRootEventManager::connect(), and PFRootEventManager::reset().

{
  return event_->isValid();
}
ChainEvent::operator bool ( ) const

Definition at line 287 of file ChainEvent.cc.

References event_.

{
  return *event_;
}
const ChainEvent & ChainEvent::operator++ ( ) [virtual]

Implements fwlite::EventBase.

Definition at line 97 of file ChainEvent.cc.

References event_, eventIndex_, fileNames_, and switchToFile().

{
   if(eventIndex_ != static_cast<Long64_t>(fileNames_.size())-1)
   {
      ++(*event_);
      if(event_->atEnd()) {
         switchToFile(++eventIndex_);
      }
   } else {
      if(*event_) {
         ++(*event_);
      }
   }
   return *this;
}
const ChainEvent& fwlite::ChainEvent::operator= ( const Event ) [private]
edm::ProcessHistory const & ChainEvent::processHistory ( ) const [virtual]

Implements edm::EventBase.

Definition at line 245 of file ChainEvent.cc.

References event_.

{
  return event_->processHistory();
}
void fwlite::ChainEvent::setGetter ( boost::shared_ptr< edm::EDProductGetter getter) [inline]

Definition at line 98 of file ChainEvent.h.

References event_.

                                                                  {
         event_->setGetter( getter );
      }
Long64_t ChainEvent::size ( void  ) const
void ChainEvent::switchToFile ( Long64_t  iIndex) [private]

Definition at line 211 of file ChainEvent.cc.

References event_, eventIndex_, file_, and fileNames_.

Referenced by ChainEvent(), operator++(), to(), and toBegin().

{
  eventIndex_= iIndex;
  TFile *tfilePtr = TFile::Open(fileNames_[iIndex].c_str());
  file_ = boost::shared_ptr<TFile>(tfilePtr);
  gROOT->GetListOfFiles()->Remove(tfilePtr);
  event_ = boost::shared_ptr<Event>( new Event(file_.get()));
}
void ChainEvent::throwProductNotFoundException ( const std::type_info &  iType,
const char *  iModule,
const char *  iInstance,
const char *  iProcess 
) [static]

Definition at line 328 of file ChainEvent.cc.

                                                                {
  Event::throwProductNotFoundException(iType,iModule,iInstance,iProcess);
}
bool ChainEvent::to ( edm::RunNumber_t  run,
edm::LuminosityBlockNumber_t  lumi,
edm::EventNumber_t  event 
)

If lumi is non-zero, go to event with given run, lumi, and event number If lumi is zero, go to event with given run and event number

Definition at line 154 of file ChainEvent.cc.

References event_, eventIndex_, fileNames_, indexGen::ifile, and switchToFile().

{

   // First try this file
   if ( event_->to( run, lumi, event ) )
   {
      // found it, return
      return true;
   }
   else
   {
      // Did not find it, try the other files sequentially.
      // Someday I can make this smarter. For now... we get something working.
      Long64_t thisFile = eventIndex_;
      std::vector<std::string>::const_iterator filesBegin = fileNames_.begin(),
         filesEnd = fileNames_.end(), ifile = filesBegin;
      for ( ; ifile != filesEnd; ++ifile )
      {
         // skip the "first" file that we tried
         if ( ifile - filesBegin != thisFile )
         {
            // switch to the next file
            switchToFile( ifile - filesBegin );
            // check that tree for the desired event
            if ( event_->to( run, lumi, event ) )
            {
               // found it, return
               return true;
            }
         }// end ignore "first" file that we tried
      }// end loop over files

      // did not find the event with id "id".
      return false;
   }// end if we did not find event id in "first" file
}
bool ChainEvent::to ( const edm::EventID id)

Go to event with event id "id".

Definition at line 146 of file ChainEvent.cc.

References event(), edm::EventBase::luminosityBlock(), DTTTrigCorrFirst::run, and to().

{
  return to(id.run(), id.luminosityBlock(), id.event());
}
bool ChainEvent::to ( edm::RunNumber_t  run,
edm::EventNumber_t  event 
)

Definition at line 192 of file ChainEvent.cc.

References to().

{
  return to(run, 0U, event);
}
bool ChainEvent::to ( Long64_t  iIndex)

Go to the event at index iIndex.

Definition at line 115 of file ChainEvent.cc.

References accumulatedSize_, event_, eventIndex_, and switchToFile().

Referenced by PFRootEventManager::initializeEventInformation(), PFRootEventManager::processEntry(), and to().

{
   if (iIndex >= accumulatedSize_.back())
   {
      // if we're here, then iIndex was not valid
      return false;
   }

   Long64_t offsetIndex = eventIndex_;

   // we're going backwards, so start from the beginning
   if (iIndex < accumulatedSize_[offsetIndex]) {
      offsetIndex = 0;
   }

   // is it past the end of this file?
   while (iIndex >= accumulatedSize_[offsetIndex+1]) {
      ++offsetIndex;
   }

   if(offsetIndex != eventIndex_) {
      switchToFile(eventIndex_ = offsetIndex);
   }

   // adjust to entry # in this file
   return event_->to( iIndex-accumulatedSize_[offsetIndex] );
}
const ChainEvent & ChainEvent::toBegin ( ) [virtual]

Go to the very first Event

Implements fwlite::EventBase.

Definition at line 200 of file ChainEvent.cc.

References event_, eventIndex_, and switchToFile().

Referenced by fwlite::AnalyzerWrapper< T >::analyze(), and main().

{
   if (eventIndex_ != 0)
   {
      switchToFile(0);
   }
   event_->toBegin();
   return *this;
}
edm::TriggerNames const & ChainEvent::triggerNames ( edm::TriggerResults const &  triggerResults) const [virtual]

Implements edm::EventBase.

Definition at line 308 of file ChainEvent.cc.

References event_.

{
  return event_->triggerNames(triggerResults);
}
edm::TriggerResultsByName ChainEvent::triggerResultsByName ( std::string const &  process) const [virtual]

Implements edm::EventBase.

Definition at line 320 of file ChainEvent.cc.

References event_.

                                                               {
  return event_->triggerResultsByName(process);
}

Friends And Related Function Documentation

friend class MultiChainEvent [friend]

Definition at line 119 of file ChainEvent.h.


Member Data Documentation

std::vector<Long64_t> fwlite::ChainEvent::accumulatedSize_ [private]

Definition at line 132 of file ChainEvent.h.

Referenced by ChainEvent(), size(), and to().

boost::shared_ptr<Event> fwlite::ChainEvent::event_ [private]
Long64_t fwlite::ChainEvent::eventIndex_ [private]

Definition at line 131 of file ChainEvent.h.

Referenced by atEnd(), eventIndex(), fileIndex(), operator++(), switchToFile(), to(), and toBegin().

boost::shared_ptr<TFile> fwlite::ChainEvent::file_ [private]

Definition at line 129 of file ChainEvent.h.

Referenced by ChainEvent(), and switchToFile().

std::vector<std::string> fwlite::ChainEvent::fileNames_ [private]

Definition at line 128 of file ChainEvent.h.

Referenced by atEnd(), ChainEvent(), operator++(), switchToFile(), and to().

boost::shared_ptr<edm::EDProductGetter> fwlite::ChainEvent::getter_ [private]

Definition at line 133 of file ChainEvent.h.