CMS 3D CMS Logo

Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes

edm::RootInputFileSequence Class Reference

#include <RootInputFileSequence.h>

List of all members.

Public Types

typedef boost::shared_ptr
< RootFile
RootFileSharedPtr

Public Member Functions

void closeFile_ ()
void dropUnwantedBranches_ (std::vector< std::string > const &wantedBranches)
void endJob ()
boost::shared_ptr
< ProductRegistry const > 
fileProductRegistry () const
ProcessingController::ForwardState forwardState () const
InputSource::ItemType getNextItemType ()
bool goToEvent (EventID const &eventID)
RootInputFileSequenceoperator= (RootInputFileSequence const &)
EventPrincipalreadEvent (EventPrincipal &cache, boost::shared_ptr< LuminosityBlockPrincipal > lb)
boost::shared_ptr< FileBlockreadFile_ (PrincipalCache &cache)
boost::shared_ptr
< LuminosityBlockPrincipal
readLuminosityBlock_ (boost::shared_ptr< LuminosityBlockPrincipal > lbCache)
boost::shared_ptr
< LuminosityBlockAuxiliary
readLuminosityBlockAuxiliary_ ()
EventPrincipalreadOneRandom ()
EventPrincipalreadOneRandomWithID (LuminosityBlockID const &id)
EventPrincipalreadOneSequential ()
EventPrincipalreadOneSequentialWithID (LuminosityBlockID const &id)
EventPrincipalreadOneSpecified (EventID const &id)
boost::shared_ptr< RunPrincipalreadRun_ (boost::shared_ptr< RunPrincipal > rpCache)
boost::shared_ptr< RunAuxiliaryreadRunAuxiliary_ ()
void reset (PrincipalCache &cache)
ProcessingController::ReverseState reverseState () const
void rewind_ ()
 RootInputFileSequence (RootInputFileSequence const &)
 RootInputFileSequence (ParameterSet const &pset, PoolSource const &input, InputFileCatalog const &catalog, PrincipalCache &cache, InputType::InputType inputType)
bool skipEvents (int offset, PrincipalCache &cache)
bool skipToItem (RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event, bool currentFileFirst=true)
bool skipToItemInNewFile (RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event)
virtual ~RootInputFileSequence ()

Static Public Member Functions

static void fillDescription (ParameterSetDescription &desc)

Private Member Functions

std::vector< FileCatalogItem >
const & 
fileCatalogItems () const
void initFile (bool skipBadFiles)
bool nextFile (PrincipalCache &cache)
bool previousFile (PrincipalCache &cache)
ProcessConfiguration const & processConfiguration () const
boost::shared_ptr
< ProductRegistry const > 
productRegistry () const
ProductRegistryproductRegistryUpdate () const
int remainingEvents () const
int remainingLuminosityBlocks () const
void rewindFile ()

Private Attributes

BranchDescription::MatchMode branchesMustMatch_
InputFileCatalog const & catalog_
bool dropDescendants_
boost::shared_ptr
< DuplicateChecker
duplicateChecker_
boost::shared_ptr
< EventSkipperByID
eventSkipperByID_
int eventsRemainingInFile_
std::vector< FileCatalogItem >
::const_iterator 
fileIter_
std::vector< FileCatalogItem >
::const_iterator 
fileIterBegin_
std::vector< FileCatalogItem >
::const_iterator 
fileIterEnd_
std::vector< FileCatalogItem >
::const_iterator 
fileIterLastOpened_
bool firstFile_
std::unique_ptr< CLHEP::RandFlat > flatDistribution_
GroupSelectorRules groupSelectorRules_
std::vector< boost::shared_ptr
< IndexIntoFile > > 
indexesIntoFiles_
PoolSource const & input_
InputType::InputType inputType_
bool labelRawDataLikeMC_
bool noEventSort_
int numberOfEventsToSkip_
std::vector< ProcessHistoryIDorderedProcessHistoryIDs_
BranchDescription::MatchMode parametersMustMatch_
RootFileSharedPtr rootFile_
RunNumber_t setRun_
bool skipBadFiles_
unsigned int treeCacheSize_
int const treeMaxVirtualSize_
bool usingGoToEvent_

Detailed Description

Definition at line 38 of file RootInputFileSequence.h.


Member Typedef Documentation

Definition at line 46 of file RootInputFileSequence.h.


Constructor & Destructor Documentation

edm::RootInputFileSequence::RootInputFileSequence ( ParameterSet const &  pset,
PoolSource const &  input,
InputFileCatalog const &  catalog,
PrincipalCache cache,
InputType::InputType  inputType 
) [explicit]

Definition at line 26 of file RootInputFileSequence.cc.

References StorageFactory::activateTimeout(), branchesMustMatch_, tests::test_Package01::factory, fileIter_, fileIterBegin_, fileIterEnd_, reco::get(), edm::ParameterSet::getUntrackedParameter(), initFile(), inputType_, edm::Service< T >::isAvailable(), numberOfEventsToSkip_, parametersMustMatch_, edm::InputType::Primary, productRegistryUpdate(), rootFile_, edm::InputType::SecondarySource, skipBadFiles_, skipEvents(), StorageFactory::stagein(), edm::BranchDescription::Strict, treeCacheSize_, and edm::ProductRegistry::updateFromInput().

                                              :
    input_(input),
    inputType_(inputType),
    catalog_(catalog),
    firstFile_(true),
    fileIterBegin_(fileCatalogItems().begin()),
    fileIterEnd_(fileCatalogItems().end()),
    fileIter_(fileIterEnd_),
    fileIterLastOpened_(fileIterEnd_),
    rootFile_(),
    parametersMustMatch_(BranchDescription::Permissive),
    branchesMustMatch_(BranchDescription::Permissive),
    flatDistribution_(),
    indexesIntoFiles_(fileCatalogItems().size()),
    orderedProcessHistoryIDs_(),
    eventSkipperByID_(inputType == InputType::Primary ? EventSkipperByID::create(pset).release() : 0),
    eventsRemainingInFile_(0),
    // The default value provided as the second argument to the getUntrackedParameter function call
    // is not used when the ParameterSet has been validated and the parameters are not optional
    // in the description.  This is currently true when PoolSource is the primary input source.
    // The modules that use PoolSource as a SecSource have not defined their fillDescriptions function
    // yet, so the ParameterSet does not get validated yet.  As soon as all the modules with a SecSource
    // have defined descriptions, the defaults in the getUntrackedParameterSet function calls can
    // and should be deleted from the code.
    numberOfEventsToSkip_(inputType == InputType::Primary ? pset.getUntrackedParameter<unsigned int>("skipEvents", 0U) : 0U),
    noEventSort_(inputType == InputType::Primary ? pset.getUntrackedParameter<bool>("noEventSort", true) : false),
    skipBadFiles_(pset.getUntrackedParameter<bool>("skipBadFiles", false)),
    treeCacheSize_(noEventSort_ ? pset.getUntrackedParameter<unsigned int>("cacheSize", roottree::defaultCacheSize) : 0U),
    treeMaxVirtualSize_(pset.getUntrackedParameter<int>("treeMaxVirtualSize", -1)),
    setRun_(pset.getUntrackedParameter<unsigned int>("setRunNumber", 0U)),
    groupSelectorRules_(pset, "inputCommands", "InputSource"),
    duplicateChecker_(inputType == InputType::Primary ? new DuplicateChecker(pset) : 0),
    dropDescendants_(pset.getUntrackedParameter<bool>("dropDescendantsOfDroppedBranches", inputType != InputType::SecondarySource)),
    labelRawDataLikeMC_(pset.getUntrackedParameter<bool>("labelRawDataLikeMC", true)),
    usingGoToEvent_(false) {

    //we now allow the site local config to specify what the TTree cache size should be
    Service<SiteLocalConfig> pSLC;
    if(treeCacheSize_ != 0U && pSLC.isAvailable() && pSLC->sourceTTreeCacheSize()) {
      treeCacheSize_ = *(pSLC->sourceTTreeCacheSize());
    }

    if(inputType_ == InputType::Primary) {
      //NOTE: we do not want to stage in secondary files since we can be given a list of
      // thousands of files and prestaging all those files can cause a site to fail
      StorageFactory *factory = StorageFactory::get();
      for(fileIter_ = fileIterBegin_; fileIter_ != fileIterEnd_; ++fileIter_) {
        factory->activateTimeout(fileIter_->fileName());
        factory->stagein(fileIter_->fileName());
      }
    }

    std::string parametersMustMatch = pset.getUntrackedParameter<std::string>("parametersMustMatch", std::string("permissive"));
    if(parametersMustMatch == std::string("strict")) parametersMustMatch_ = BranchDescription::Strict;

    std::string branchesMustMatch = pset.getUntrackedParameter<std::string>("branchesMustMatch", std::string("permissive"));
    if(branchesMustMatch == std::string("strict")) branchesMustMatch_ = BranchDescription::Strict;

    if(inputType != InputType::SecondarySource) {
      for(fileIter_ = fileIterBegin_; fileIter_ != fileIterEnd_; ++fileIter_) {
        initFile(skipBadFiles_);
        if(rootFile_) break;
      }
      if(rootFile_) {
        productRegistryUpdate().updateFromInput(rootFile_->productRegistry()->productList());
        if(numberOfEventsToSkip_ != 0) {
          skipEvents(numberOfEventsToSkip_, cache);
        }
      }
    }
  }
edm::RootInputFileSequence::~RootInputFileSequence ( ) [virtual]

Definition at line 337 of file RootInputFileSequence.cc.

                                                {
  }
edm::RootInputFileSequence::RootInputFileSequence ( RootInputFileSequence const &  )

Member Function Documentation

void edm::RootInputFileSequence::closeFile_ ( )

Definition at line 132 of file RootInputFileSequence.cc.

References duplicateChecker_, input_, inputType_, edm::InputType::Primary, rootFile_, and edm::InputType::SecondarySource.

Referenced by endJob(), initFile(), and rewind_().

                                         {
    // close the currently open file, if any, and delete the RootFile object.
    if(rootFile_) {
      if(inputType_ != InputType::SecondarySource) {
        std::unique_ptr<InputSource::FileCloseSentry>
        sentry((inputType_ == InputType::Primary) ? new InputSource::FileCloseSentry(input_) : 0);
        rootFile_->close();
        if(duplicateChecker_) duplicateChecker_->inputFileClosed();
      }
      rootFile_.reset();
    }
  }
void edm::RootInputFileSequence::dropUnwantedBranches_ ( std::vector< std::string > const &  wantedBranches)

Definition at line 588 of file RootInputFileSequence.cc.

References edm::ParameterSet::addUntrackedParameter(), groupSelectorRules_, and cmsCodeRulesChecker::rules.

                                                                                         {
    std::vector<std::string> rules;
    rules.reserve(wantedBranches.size() + 1);
    rules.emplace_back("drop *");
    for(std::vector<std::string>::const_iterator it = wantedBranches.begin(), itEnd = wantedBranches.end();
        it != itEnd; ++it) {
      rules.push_back("keep " + *it + "_*");
    }
    ParameterSet pset;
    pset.addUntrackedParameter("inputCommands", rules);
    groupSelectorRules_ = GroupSelectorRules(pset, "inputCommands", "InputSource");
  }
void edm::RootInputFileSequence::endJob ( void  )

Definition at line 109 of file RootInputFileSequence.cc.

References closeFile_().

                                {
    closeFile_();
  }
std::vector< FileCatalogItem > const & edm::RootInputFileSequence::fileCatalogItems ( ) const [private]

Definition at line 104 of file RootInputFileSequence.cc.

References catalog_, and edm::InputFileCatalog::fileCatalogItems().

Referenced by readOneRandom().

                                                {
    return catalog_.fileCatalogItems();
  }
boost::shared_ptr< ProductRegistry const > edm::RootInputFileSequence::fileProductRegistry ( ) const

Definition at line 271 of file RootInputFileSequence.cc.

References rootFile_.

                                                   {
    assert(rootFile_);
    return rootFile_->productRegistry();
  }
void edm::RootInputFileSequence::fillDescription ( ParameterSetDescription desc) [static]

Definition at line 746 of file RootInputFileSequence.cc.

References edm::ParameterSetDescription::addUntracked(), and edm::roottree::defaultCacheSize.

                                                                       {
    desc.addUntracked<unsigned int>("skipEvents", 0U)
        ->setComment("Skip the first 'skipEvents' events that otherwise would have been processed.");
    desc.addUntracked<bool>("noEventSort", true)
        ->setComment("True:  Process runs, lumis and events in the order they appear in the file (but see notes 1 and 2).\n"
                     "False: Process runs, lumis and events in each file in numerical order (run#, lumi#, event#) (but see note 3).\n"
                     "Note 1: Events within the same lumi will always be processed contiguously.\n"
                     "Note 2: Lumis within the same run will always be processed contiguously.\n"
                     "Note 3: Any sorting occurs independently in each input file (no sorting across input files).");
    desc.addUntracked<bool>("skipBadFiles", false)
        ->setComment("True:  Ignore any missing or unopenable input file.\n"
                     "False: Throw exception if missing or unopenable input file.");
    desc.addUntracked<unsigned int>("cacheSize", roottree::defaultCacheSize)
        ->setComment("Size of ROOT TTree prefetch cache.  Affects performance.");
    desc.addUntracked<int>("treeMaxVirtualSize", -1)
        ->setComment("Size of ROOT TTree TBasket cache.  Affects performance.");
    desc.addUntracked<unsigned int>("setRunNumber", 0U)
        ->setComment("If non-zero, change number of first run to this number. Apply same offset to all runs.  Allowed only for simulation.");
    desc.addUntracked<bool>("dropDescendantsOfDroppedBranches", true)
        ->setComment("If True, also drop on input any descendent of any branch dropped on input.");
    std::string defaultString("permissive");
    desc.addUntracked<std::string>("parametersMustMatch", defaultString)
        ->setComment("'strict':     Values of tracked parameters must be unique across all input files.\n"
                     "'permissive': Values of tracked parameters may differ across or within files.");
    desc.addUntracked<std::string>("branchesMustMatch", defaultString)
        ->setComment("'strict':     Branches in each input file must match those in the first file.\n"
                     "'permissive': Branches in each input file may be any subset of those in the first file.");
    desc.addUntracked<bool>("labelRawDataLikeMC", true)
        ->setComment("If True: replace module label for raw data to match MC. Also use 'LHC' as process.");

    GroupSelectorRules::fillDescription(desc, "inputCommands");
    EventSkipperByID::fillDescription(desc);
    DuplicateChecker::fillDescription(desc);
  }
ProcessingController::ForwardState edm::RootInputFileSequence::forwardState ( ) const
InputSource::ItemType edm::RootInputFileSequence::getNextItemType ( )
bool edm::RootInputFileSequence::goToEvent ( EventID const &  eventID)

Definition at line 462 of file RootInputFileSequence.cc.

References edm::EventID::event(), fileIter_, fileIterBegin_, newFWLiteAna::found, indexesIntoFiles_, initFile(), edm::EventID::luminosityBlock(), rootFile_, edm::EventID::run(), and usingGoToEvent_.

                                                         {
    usingGoToEvent_ = true;
    if(rootFile_) {
      if(rootFile_->goToEvent(eventID)) {
        return true;
      }
      // If only one input file, give up now, to save time.
      if(rootFile_ && indexesIntoFiles_.size() == 1) {
        return false;
      }
      // Save the current file and position so that we can restore them
      // if we fail to restore the desired event
      bool closedOriginalFile = false;
      std::vector<FileCatalogItem>::const_iterator originalFile = fileIter_;
      IndexIntoFile::IndexIntoFileItr originalPosition = rootFile_->indexIntoFileIter();

      // Look for item (run/lumi/event) in files previously opened without reopening unnecessary files.
      typedef std::vector<boost::shared_ptr<IndexIntoFile> >::const_iterator Iter;
      for(Iter it = indexesIntoFiles_.begin(), itEnd = indexesIntoFiles_.end(); it != itEnd; ++it) {
        if(*it && (*it)->containsItem(eventID.run(), eventID.luminosityBlock(), eventID.event())) {
          // We found it. Close the currently open file, and open the correct one.
          fileIter_ = fileIterBegin_ + (it - indexesIntoFiles_.begin());
          initFile(false);
          // Now get the item from the correct file.
          bool found = rootFile_->goToEvent(eventID);
          assert (found);
          return true;
        }
      }
      // Look for item in files not yet opened.
      for(Iter it = indexesIntoFiles_.begin(), itEnd = indexesIntoFiles_.end(); it != itEnd; ++it) {
        if(!*it) {
          fileIter_ = fileIterBegin_ + (it - indexesIntoFiles_.begin());
          initFile(false);
          closedOriginalFile = true;
          if((*it)->containsItem(eventID.run(), eventID.luminosityBlock(), eventID.event())) {
            if  (rootFile_->goToEvent(eventID)) {
              return true;
            }
          }
        }
      }
      if(closedOriginalFile) {
        fileIter_ = originalFile;
        initFile(false);
        rootFile_->setPosition(originalPosition);
      }
    }
    return false;
  }
void edm::RootInputFileSequence::initFile ( bool  skipBadFiles) [private]

Definition at line 145 of file RootInputFileSequence.cc.

References closeFile_(), dropDescendants_, duplicateChecker_, alignCSCRings::e, eventSkipperByID_, Exception, cms::Exception::explainSelf(), edm::errors::FallbackFileOpenError, fileIter_, fileIterBegin_, fileIterEnd_, fileIterLastOpened_, edm::errors::FileOpenError, groupSelectorRules_, indexesIntoFiles_, input_, RPC_Client_on_RootFile::InputFile, inputType_, labelRawDataLikeMC_, noEventSort_, numberOfEventsToSkip_, orderedProcessHistoryIDs_, dbtoconf::out, dbtoconf::pfn, edm::InputType::Primary, processConfiguration(), edm::InputSource::processingMode(), remainingEvents(), remainingLuminosityBlocks(), edm::InputFile::reportFallbackAttempt(), edm::InputFile::reportSkippedFile(), rootFile_, edm::InputType::SecondaryFile, edm::InputType::SecondarySource, setRun_, treeCacheSize_, treeMaxVirtualSize_, and usingGoToEvent_.

Referenced by goToEvent(), nextFile(), previousFile(), readFile_(), readOneRandom(), readOneSequential(), reset(), rewind_(), RootInputFileSequence(), skipToItem(), and skipToItemInNewFile().

                                                        {
    // We are really going to close the open file.

    // If this is the primary sequence, we are not duplicate checking across files
    // and we are not using random access to find events, then we can delete the
    // IndexIntoFile for the file we are closing. If we can't delete all of it,
    // then we can delete the parts we do not need.
    if(fileIterLastOpened_ != fileIterEnd_) {
      size_t currentIndexIntoFile = fileIterLastOpened_ - fileIterBegin_;
      bool needIndexesForDuplicateChecker = duplicateChecker_ && duplicateChecker_->checkingAllFiles() && !duplicateChecker_->checkDisabled();
      bool deleteIndexIntoFile = inputType_ == InputType::Primary &&
                                 !needIndexesForDuplicateChecker &&
                                 !usingGoToEvent_;
      if(deleteIndexIntoFile) {
        indexesIntoFiles_[currentIndexIntoFile].reset();
      } else {
        if(indexesIntoFiles_[currentIndexIntoFile]) indexesIntoFiles_[currentIndexIntoFile]->inputFileClosed();
      }
      fileIterLastOpened_ = fileIterEnd_;
    }
    closeFile_();

    if(fileIter_ == fileIterEnd_) {
      // No files specified
      return;
    }

    // Check if the logical file name was found.
    if(fileIter_->fileName().empty()) {
      // LFN not found in catalog.
      InputFile::reportSkippedFile(fileIter_->fileName(), fileIter_->logicalFileName());
      if(!skipBadFiles) {
        throw cms::Exception("LogicalFileNameNotFound", "RootInputFileSequence::initFile()\n")
          << "Logical file name '" << fileIter_->logicalFileName() << "' was not found in the file catalog.\n"
          << "If you wanted a local file, you forgot the 'file:' prefix\n"
          << "before the file name in your configuration file.\n";
      }
      LogWarning("") << "Input logical file: " << fileIter_->logicalFileName() << " was not found in the catalog, and will be skipped.\n";
      return;
    }

    // Determine whether we have a fallback URL specified; if so, prepare it;
    // Only valid if it is non-empty and differs from the original filename.
    std::string fallbackName = fileIter_->fallbackFileName();
    bool hasFallbackUrl = !fallbackName.empty() && fallbackName != fileIter_->fileName();

    boost::shared_ptr<InputFile> filePtr;
    try {
      std::unique_ptr<InputSource::FileOpenSentry>
        sentry(inputType_ == InputType::Primary ? new InputSource::FileOpenSentry(input_) : 0);
      filePtr.reset(new InputFile(gSystem->ExpandPathName(fileIter_->fileName().c_str()), "  Initiating request to open file "));
    }
    catch (cms::Exception const& e) {
      if(!skipBadFiles) {
        if(hasFallbackUrl) {
          std::ostringstream out;
          out << e.explainSelf();
          std::string pfn(gSystem->ExpandPathName(fallbackName.c_str()));
          InputFile::reportFallbackAttempt(pfn, fileIter_->logicalFileName(), out.str());
        } else {
          InputFile::reportSkippedFile(fileIter_->fileName(), fileIter_->logicalFileName());
          Exception ex(errors::FileOpenError, "", e);
          ex.addContext("Calling RootInputFileSequence::initFile()");
          ex.clearMessage();
          ex << "Input file " << fileIter_->fileName() << " was not found, could not be opened, or is corrupted.\n";
          throw ex;
        }
      }
    }
    if(!filePtr && (hasFallbackUrl)) {
      try {
        std::unique_ptr<InputSource::FileOpenSentry>
          sentry(inputType_ == InputType::Primary ? new InputSource::FileOpenSentry(input_) : 0);
        filePtr.reset(new InputFile(gSystem->ExpandPathName(fallbackName.c_str()), "  Fallback request to file "));
      }
      catch (cms::Exception const& e) {
        if(!skipBadFiles) {
          InputFile::reportSkippedFile(fileIter_->fileName(), fileIter_->logicalFileName());
          Exception ex(errors::FallbackFileOpenError, "", e);
          ex.addContext("Calling RootInputFileSequence::initFile()");
          ex.clearMessage();
          ex << "Input file " << fileIter_->fileName() << " was not found, could not be opened, or is corrupted.\n";
          ex << "Fallback Input file " << fallbackName << " also was not found, could not be opened, or is corrupted.\n";
          throw ex;
        }
      }
    }
    if(filePtr) {
      std::vector<boost::shared_ptr<IndexIntoFile> >::size_type currentIndexIntoFile = fileIter_ - fileIterBegin_;
      rootFile_ = RootFileSharedPtr(new RootFile(fileIter_->fileName(),
          processConfiguration(), fileIter_->logicalFileName(), filePtr,
          eventSkipperByID_, numberOfEventsToSkip_ != 0,
          remainingEvents(), remainingLuminosityBlocks(), treeCacheSize_, treeMaxVirtualSize_,
          input_.processingMode(),
          setRun_,
          noEventSort_,
          groupSelectorRules_,
          inputType_,
          duplicateChecker_,
          dropDescendants_,
          indexesIntoFiles_,
          currentIndexIntoFile,
          orderedProcessHistoryIDs_,
          labelRawDataLikeMC_,
          usingGoToEvent_));

      fileIterLastOpened_ = fileIter_;
      indexesIntoFiles_[currentIndexIntoFile] = rootFile_->indexIntoFileSharedPtr();
      char const* inputType = 0;
      switch(inputType_) {
      case InputType::Primary: inputType = "primaryFiles"; break;
      case InputType::SecondaryFile: inputType = "secondaryFiles"; break;
      case InputType::SecondarySource: inputType = "mixingFiles"; break;
      }
      rootFile_->reportOpened(inputType);
    } else {
      InputFile::reportSkippedFile(fileIter_->fileName(), fileIter_->logicalFileName());
      if(!skipBadFiles) {
        throw Exception(errors::FileOpenError) <<
           "RootInputFileSequence::initFile(): Input file " << fileIter_->fileName() << " was not found or could not be opened.\n";
      }
      LogWarning("") << "Input file: " << fileIter_->fileName() << " was not found or could not be opened, and will be skipped.\n";
    }
  }
bool edm::RootInputFileSequence::nextFile ( PrincipalCache cache) [private]

Definition at line 276 of file RootInputFileSequence.cc.

References edm::PrincipalCache::adjustEventToNewProductRegistry(), edm::PrincipalCache::adjustIndexesAfterProductRegistryAddition(), branchesMustMatch_, Exception, fileIter_, fileIterBegin_, fileIterEnd_, initFile(), inputType_, edm::ProductRegistry::merge(), edm::errors::MismatchedInputFiles, parametersMustMatch_, edm::InputType::Primary, productRegistry(), productRegistryUpdate(), rootFile_, findQualityFiles::size, and skipBadFiles_.

Referenced by readFile_(), and skipEvents().

                                                            {
    if(fileIter_ != fileIterEnd_) ++fileIter_;
    if(fileIter_ == fileIterEnd_) {
      if(inputType_ == InputType::Primary) {
        return false;
      } else {
        fileIter_ = fileIterBegin_;
      }
    }

    initFile(skipBadFiles_);

    if(inputType_ == InputType::Primary && rootFile_) {
      size_t size = productRegistry()->size();
      // make sure the new product registry is compatible with the main one
      std::string mergeInfo = productRegistryUpdate().merge(*rootFile_->productRegistry(),
                                                            fileIter_->fileName(),
                                                            parametersMustMatch_,
                                                            branchesMustMatch_);
      if(!mergeInfo.empty()) {
        throw Exception(errors::MismatchedInputFiles,"RootInputFileSequence::nextFile()") << mergeInfo;
      }
      if(productRegistry()->size() > size) {
        cache.adjustIndexesAfterProductRegistryAddition();
      }
      cache.adjustEventToNewProductRegistry(productRegistry());
    }
    return true;
  }
RootInputFileSequence& edm::RootInputFileSequence::operator= ( RootInputFileSequence const &  )
bool edm::RootInputFileSequence::previousFile ( PrincipalCache cache) [private]

Definition at line 306 of file RootInputFileSequence.cc.

References edm::PrincipalCache::adjustEventToNewProductRegistry(), edm::PrincipalCache::adjustIndexesAfterProductRegistryAddition(), branchesMustMatch_, Exception, fileIter_, fileIterBegin_, fileIterEnd_, initFile(), inputType_, edm::ProductRegistry::merge(), edm::errors::MismatchedInputFiles, parametersMustMatch_, edm::InputType::Primary, productRegistry(), productRegistryUpdate(), rootFile_, and findQualityFiles::size.

Referenced by skipEvents().

                                                                {
    if(fileIter_ == fileIterBegin_) {
      if(inputType_ == InputType::Primary) {
        return false;
      } else {
        fileIter_ = fileIterEnd_;
      }
    }
    --fileIter_;

    initFile(false);

    if(inputType_ == InputType::Primary && rootFile_) {
      size_t size = productRegistry()->size();
      // make sure the new product registry is compatible to the main one
      std::string mergeInfo = productRegistryUpdate().merge(*rootFile_->productRegistry(),
                                                            fileIter_->fileName(),
                                                            parametersMustMatch_,
                                                            branchesMustMatch_);
      if(!mergeInfo.empty()) {
        throw Exception(errors::MismatchedInputFiles,"RootInputFileSequence::previousEvent()") << mergeInfo;
      }
      if(productRegistry()->size() > size) {
        cache.adjustIndexesAfterProductRegistryAddition();
      }
      cache.adjustEventToNewProductRegistry(productRegistry());
    }
    if(rootFile_) rootFile_->setToLastEntry();
    return true;
  }
ProcessConfiguration const & edm::RootInputFileSequence::processConfiguration ( ) const [private]

Definition at line 563 of file RootInputFileSequence.cc.

References input_, and edm::InputSource::processConfiguration().

Referenced by initFile().

                                                    {
    return input_.processConfiguration();
  }
boost::shared_ptr< ProductRegistry const > edm::RootInputFileSequence::productRegistry ( ) const [private]

Definition at line 583 of file RootInputFileSequence.cc.

References input_, and edm::InputSource::productRegistry().

Referenced by nextFile(), and previousFile().

                                              {
    return input_.productRegistry();
  }
ProductRegistry & edm::RootInputFileSequence::productRegistryUpdate ( ) const [private]

Definition at line 578 of file RootInputFileSequence.cc.

References input_, and edm::InputSource::productRegistryUpdate().

Referenced by nextFile(), previousFile(), and RootInputFileSequence().

                                                    {
    return input_.productRegistryUpdate();
  }
EventPrincipal * edm::RootInputFileSequence::readEvent ( EventPrincipal cache,
boost::shared_ptr< LuminosityBlockPrincipal lb 
)

Definition at line 374 of file RootInputFileSequence.cc.

References rootFile_.

                                                                                                      {
    return rootFile_->readEvent(cache, lb);
  }
boost::shared_ptr< FileBlock > edm::RootInputFileSequence::readFile_ ( PrincipalCache cache)

Definition at line 114 of file RootInputFileSequence.cc.

References firstFile_, initFile(), nextFile(), rootFile_, and skipBadFiles_.

                                                        {
    if(firstFile_) {
      // The first input file has already been opened.
      firstFile_ = false;
      if(!rootFile_) {
        initFile(skipBadFiles_);
      }
    } else {
      if(!nextFile(cache)) {
        assert(0);
      }
    }
    if(!rootFile_) {
      return boost::shared_ptr<FileBlock>(new FileBlock);
    }
    return rootFile_->createFileBlock();
  }
boost::shared_ptr< LuminosityBlockPrincipal > edm::RootInputFileSequence::readLuminosityBlock_ ( boost::shared_ptr< LuminosityBlockPrincipal lbCache)

Definition at line 356 of file RootInputFileSequence.cc.

References rootFile_.

                                                                                               {
    return rootFile_->readLumi(lbCache);
  }
boost::shared_ptr< LuminosityBlockAuxiliary > edm::RootInputFileSequence::readLuminosityBlockAuxiliary_ ( )

Definition at line 346 of file RootInputFileSequence.cc.

References rootFile_.

                                                       {
    return rootFile_->readLuminosityBlockAuxiliary_();
  }
EventPrincipal * edm::RootInputFileSequence::readOneRandom ( )

Definition at line 667 of file RootInputFileSequence.cc.

References edm::errors::Configuration, eventsRemainingInFile_, Exception, fileCatalogItems(), fileIter_, fileIterBegin_, fileIterEnd_, flatDistribution_, initFile(), edm::errors::NotFound, rootFile_, findQualityFiles::size, and skipBadFiles_.

                                       {
    if(fileIterEnd_ == fileIterBegin_) {
      throw Exception(errors::Configuration) << "RootInputFileSequence::readOneRandom(): no input files specified.\n";
    }
    if(!flatDistribution_) {
      Service<RandomNumberGenerator> rng;
      CLHEP::HepRandomEngine& engine = rng->getEngine();
      flatDistribution_.reset(new CLHEP::RandFlat(engine));
    }
    skipBadFiles_ = false;
    unsigned int currentSeqNumber = fileIter_ - fileIterBegin_;
    while(eventsRemainingInFile_ == 0) {
      fileIter_ = fileIterBegin_ + flatDistribution_->fireInt(fileCatalogItems().size());
      unsigned int newSeqNumber = fileIter_ - fileIterBegin_;
      if(newSeqNumber != currentSeqNumber) {
        initFile(false);
        currentSeqNumber = newSeqNumber;
      }
      eventsRemainingInFile_ = rootFile_->eventTree().entries();
      if(eventsRemainingInFile_ == 0) {
        throw Exception(errors::NotFound) <<
           "RootInputFileSequence::readOneRandom(): Secondary Input file " << fileIter_->fileName() << " contains no events.\n";
      }
      rootFile_->setAtEventEntry(flatDistribution_->fireInt(eventsRemainingInFile_) - 1);
    }
    rootFile_->nextEventEntry();

    EventPrincipal* ep = rootFile_->clearAndReadCurrentEvent(rootFile_->secondaryEventPrincipal());
    if(ep == 0) {
      rootFile_->setAtEventEntry(0);
      ep = rootFile_->clearAndReadCurrentEvent(rootFile_->secondaryEventPrincipal());
      assert(ep != 0);
    }
    --eventsRemainingInFile_;
    return ep;
  }
EventPrincipal * edm::RootInputFileSequence::readOneRandomWithID ( LuminosityBlockID const &  id)

Definition at line 707 of file RootInputFileSequence.cc.

References edm::errors::Configuration, Exception, fileIter_, fileIterBegin_, fileIterEnd_, flatDistribution_, newFWLiteAna::found, i, rootFile_, DTTTrigCorrFirst::run, skipBadFiles_, and skipToItem().

                                                                        {
    if(fileIterEnd_ == fileIterBegin_) {
      throw Exception(errors::Configuration) << "RootInputFileSequence::readOneRandomWithID(): no input files specified.\n";
    }
    if(!flatDistribution_) {
      Service<RandomNumberGenerator> rng;
      CLHEP::HepRandomEngine& engine = rng->getEngine();
      flatDistribution_.reset(new CLHEP::RandFlat(engine));
    }
    skipBadFiles_ = false;
    if(fileIter_ == fileIterEnd_ || !rootFile_ ||
        rootFile_->indexIntoFileIter().run() != id.run() || 
        rootFile_->indexIntoFileIter().lumi() != id.luminosityBlock()) {
      bool found = skipToItem(id.run(), id.luminosityBlock(), 0);
      if(!found) {
        return 0;
      }
      int eventsInLumi = 0;
      while(rootFile_->setEntryAtNextEventInLumi(id.run(), id.luminosityBlock())) ++eventsInLumi;
      found = skipToItem(id.run(), id.luminosityBlock(), 0);
      assert(found);
      int eventInLumi = flatDistribution_->fireInt(eventsInLumi);
      for(int i = 0; i < eventInLumi; ++i) {
        bool found = rootFile_->setEntryAtNextEventInLumi(id.run(), id.luminosityBlock());
        assert(found);
      }
    }
    bool nextFound = rootFile_->setEntryAtNextEventInLumi(id.run(), id.luminosityBlock());
    EventPrincipal* ep = (nextFound ? rootFile_->clearAndReadCurrentEvent(rootFile_->secondaryEventPrincipal()) : 0);
    if(ep == 0) {
      bool found = rootFile_->setEntryAtItem(id.run(), id.luminosityBlock(), 0);
      if(found) {
        return readOneRandomWithID(id);
      }
    }
    return ep;
  }
EventPrincipal * edm::RootInputFileSequence::readOneSequential ( )

Definition at line 602 of file RootInputFileSequence.cc.

References edm::errors::Configuration, Exception, fileIter_, fileIterBegin_, fileIterEnd_, initFile(), rootFile_, and skipBadFiles_.

                                           {
    skipBadFiles_ = false;
    if(fileIter_ == fileIterEnd_ || !rootFile_) {
      if(fileIterEnd_ == fileIterBegin_) {
        throw Exception(errors::Configuration) << "RootInputFileSequence::readOneSequential(): no input files specified.\n";
      }
      fileIter_ = fileIterBegin_;
      initFile(false);
      rootFile_->setAtEventEntry(-1);
    }
    rootFile_->nextEventEntry();
    EventPrincipal* ep = rootFile_->clearAndReadCurrentEvent(rootFile_->secondaryEventPrincipal());
    if(ep == 0) {
      ++fileIter_;
      if(fileIter_ == fileIterEnd_) {
        return 0;
      }
      initFile(false);
      rootFile_->setAtEventEntry(-1);
      return readOneSequential();
    }
    return ep;
  }
EventPrincipal * edm::RootInputFileSequence::readOneSequentialWithID ( LuminosityBlockID const &  id)

Definition at line 627 of file RootInputFileSequence.cc.

References edm::errors::Configuration, Exception, fileIter_, fileIterBegin_, fileIterEnd_, newFWLiteAna::found, rootFile_, DTTTrigCorrFirst::run, skipBadFiles_, skipToItem(), and skipToItemInNewFile().

                                                                            {
    if(fileIterEnd_ == fileIterBegin_) {
      throw Exception(errors::Configuration) << "RootInputFileSequence::readOneSequentialWithID(): no input files specified.\n";
    }
    skipBadFiles_ = false;
    if(fileIter_ == fileIterEnd_ || !rootFile_ ||
        rootFile_->indexIntoFileIter().run() != id.run() || 
        rootFile_->indexIntoFileIter().lumi() != id.luminosityBlock()) {
      bool found = skipToItem(id.run(), id.luminosityBlock(), 0, false);
      if(!found) {
        return 0;
      }
    }
    bool nextFound = rootFile_->setEntryAtNextEventInLumi(id.run(), id.luminosityBlock());
    EventPrincipal* ep = (nextFound ? rootFile_->clearAndReadCurrentEvent(rootFile_->secondaryEventPrincipal()) : 0);
    if(ep == 0) {
      bool found = skipToItemInNewFile(id.run(), id.luminosityBlock(), 0);
      if(found) {
        return readOneSequentialWithID(id);
      }
    }
    return ep;
  }
EventPrincipal * edm::RootInputFileSequence::readOneSpecified ( EventID const &  id)

Definition at line 652 of file RootInputFileSequence.cc.

References event(), Exception, fileIter_, newFWLiteAna::found, edm::errors::NotFound, rootFile_, DTTTrigCorrFirst::run, skipBadFiles_, and skipToItem().

                                                           {
    skipBadFiles_ = false;
    bool found = skipToItem(id.run(), id.luminosityBlock(), id.event());
    if(!found) {
      throw Exception(errors::NotFound) <<
         "RootInputFileSequence::readOneSpecified(): Secondary Input file " <<
         fileIter_->fileName() <<
         " does not contain specified event:\n" << id << "\n";
    }
    EventPrincipal* ep = rootFile_->clearAndReadCurrentEvent(rootFile_->secondaryEventPrincipal());
    assert(ep != 0);
    return ep;
  }
boost::shared_ptr< RunPrincipal > edm::RootInputFileSequence::readRun_ ( boost::shared_ptr< RunPrincipal rpCache)

Definition at line 351 of file RootInputFileSequence.cc.

References rootFile_.

                                                                       {
    return rootFile_->readRun_(rpCache);
  }
boost::shared_ptr< RunAuxiliary > edm::RootInputFileSequence::readRunAuxiliary_ ( )

Definition at line 341 of file RootInputFileSequence.cc.

References rootFile_.

                                           {
    return rootFile_->readRunAuxiliary_();
  }
int edm::RootInputFileSequence::remainingEvents ( ) const [private]

Definition at line 568 of file RootInputFileSequence.cc.

References input_, and edm::InputSource::remainingEvents().

Referenced by initFile().

                                               {
    return input_.remainingEvents();
  }
int edm::RootInputFileSequence::remainingLuminosityBlocks ( ) const [private]

Definition at line 573 of file RootInputFileSequence.cc.

References input_, and edm::InputSource::remainingLuminosityBlocks().

Referenced by initFile().

                                                         {
    return input_.remainingLuminosityBlocks();
  }
void edm::RootInputFileSequence::reset ( PrincipalCache cache)

Definition at line 424 of file RootInputFileSequence.cc.

References fileIter_, fileIterBegin_, fileIterEnd_, firstFile_, initFile(), inputType_, numberOfEventsToSkip_, rootFile_, edm::InputType::SecondarySource, skipBadFiles_, and skipEvents().

                                                    {
    //NOTE: Need to handle duplicate checker
    // Also what if skipBadFiles_==true and the first time we succeeded but after a reset we fail?
    if(inputType_ != InputType::SecondarySource) {
      firstFile_ = true;
      for(fileIter_ = fileIterBegin_; fileIter_ != fileIterEnd_; ++fileIter_) {
        initFile(skipBadFiles_);
        if(rootFile_) break;
      }
      if(rootFile_) {
        if(numberOfEventsToSkip_ != 0) {
          skipEvents(numberOfEventsToSkip_, cache);
        }
      }
    }
  }
ProcessingController::ReverseState edm::RootInputFileSequence::reverseState ( ) const
void edm::RootInputFileSequence::rewind_ ( )
void edm::RootInputFileSequence::rewindFile ( ) [private]

Definition at line 419 of file RootInputFileSequence.cc.

References rootFile_.

Referenced by rewind_().

                                    {
    if(rootFile_) rootFile_->rewind();
  }
bool edm::RootInputFileSequence::skipEvents ( int  offset,
PrincipalCache cache 
)
bool edm::RootInputFileSequence::skipToItem ( RunNumber_t  run,
LuminosityBlockNumber_t  lumi,
EventNumber_t  event,
bool  currentFileFirst = true 
)

Definition at line 532 of file RootInputFileSequence.cc.

References fileIter_, fileIterBegin_, newFWLiteAna::found, indexesIntoFiles_, initFile(), rootFile_, and skipToItemInNewFile().

Referenced by readOneRandomWithID(), readOneSequentialWithID(), and readOneSpecified().

                                                                                                                             {
    // Attempt to find item in currently open input file.
    bool found = currentFileFirst && rootFile_ && rootFile_->setEntryAtItem(run, lumi, event);
    if(!found) {
      // If only one input file, give up now, to save time.
      if(currentFileFirst && rootFile_ && indexesIntoFiles_.size() == 1) {
        return false;
      }
      // Look for item (run/lumi/event) in files previously opened without reopening unnecessary files.
      typedef std::vector<boost::shared_ptr<IndexIntoFile> >::const_iterator Iter;
      for(Iter it = indexesIntoFiles_.begin(), itEnd = indexesIntoFiles_.end(); it != itEnd; ++it) {
        if(*it && (*it)->containsItem(run, lumi, event)) {
          // We found it. Close the currently open file, and open the correct one.
          std::vector<FileCatalogItem>::const_iterator currentIter = fileIter_;
          fileIter_ = fileIterBegin_ + (it - indexesIntoFiles_.begin());
          if(fileIter_ != currentIter) {
            initFile(false);
          }
          // Now get the item from the correct file.
          found = rootFile_->setEntryAtItem(run, lumi, event);
          assert (found);
          return true;
        }
      }
      // Look for item in files not yet opened.
      return skipToItemInNewFile(run, lumi, event);
    }
    return true;
  }
bool edm::RootInputFileSequence::skipToItemInNewFile ( RunNumber_t  run,
LuminosityBlockNumber_t  lumi,
EventNumber_t  event 
)

Definition at line 514 of file RootInputFileSequence.cc.

References fileIter_, fileIterBegin_, newFWLiteAna::found, indexesIntoFiles_, initFile(), and rootFile_.

Referenced by readOneSequentialWithID(), and skipToItem().

                                                                                                               {
    // Look for item in files not yet opened.
    typedef std::vector<boost::shared_ptr<IndexIntoFile> >::const_iterator Iter;
    for(Iter it = indexesIntoFiles_.begin(), itEnd = indexesIntoFiles_.end(); it != itEnd; ++it) {
      if(!*it) {
        fileIter_ = fileIterBegin_ + (it - indexesIntoFiles_.begin());
        initFile(false);
        bool found = rootFile_->setEntryAtItem(run, lumi, event);
        if(found) {
          return true;
        }
      }
    }
    // Not found
    return false;
  }

Member Data Documentation

Definition at line 96 of file RootInputFileSequence.h.

Referenced by nextFile(), previousFile(), and RootInputFileSequence().

Definition at line 88 of file RootInputFileSequence.h.

Referenced by fileCatalogItems().

Definition at line 112 of file RootInputFileSequence.h.

Referenced by initFile().

Definition at line 111 of file RootInputFileSequence.h.

Referenced by closeFile_(), and initFile().

Definition at line 102 of file RootInputFileSequence.h.

Referenced by initFile().

Definition at line 103 of file RootInputFileSequence.h.

Referenced by readOneRandom().

std::vector<FileCatalogItem>::const_iterator edm::RootInputFileSequence::fileIter_ [private]
std::vector<FileCatalogItem>::const_iterator edm::RootInputFileSequence::fileIterBegin_ [private]
std::vector<FileCatalogItem>::const_iterator edm::RootInputFileSequence::fileIterEnd_ [private]
std::vector<FileCatalogItem>::const_iterator edm::RootInputFileSequence::fileIterLastOpened_ [private]

Definition at line 93 of file RootInputFileSequence.h.

Referenced by initFile().

Definition at line 89 of file RootInputFileSequence.h.

Referenced by getNextItemType(), readFile_(), reset(), and rewind_().

std::unique_ptr<CLHEP::RandFlat> edm::RootInputFileSequence::flatDistribution_ [private]

Definition at line 98 of file RootInputFileSequence.h.

Referenced by readOneRandom(), and readOneRandomWithID().

Definition at line 110 of file RootInputFileSequence.h.

Referenced by dropUnwantedBranches_(), and initFile().

std::vector<boost::shared_ptr<IndexIntoFile> > edm::RootInputFileSequence::indexesIntoFiles_ [private]

Definition at line 99 of file RootInputFileSequence.h.

Referenced by goToEvent(), initFile(), skipToItem(), and skipToItemInNewFile().

Definition at line 113 of file RootInputFileSequence.h.

Referenced by initFile().

Definition at line 105 of file RootInputFileSequence.h.

Referenced by initFile().

Definition at line 104 of file RootInputFileSequence.h.

Referenced by initFile(), reset(), RootInputFileSequence(), and skipEvents().

Definition at line 100 of file RootInputFileSequence.h.

Referenced by initFile().

Definition at line 95 of file RootInputFileSequence.h.

Referenced by nextFile(), previousFile(), and RootInputFileSequence().

Definition at line 109 of file RootInputFileSequence.h.

Referenced by initFile().

Definition at line 107 of file RootInputFileSequence.h.

Referenced by initFile(), and RootInputFileSequence().

Definition at line 108 of file RootInputFileSequence.h.

Referenced by initFile().

Definition at line 114 of file RootInputFileSequence.h.

Referenced by goToEvent(), and initFile().