CMS 3D CMS Logo

List of all members | Public Member Functions | Protected Types | Protected Member Functions | Private Member Functions | Private Attributes
edm::RootInputFileSequence Class Referenceabstract

#include <RootInputFileSequence.h>

Inheritance diagram for edm::RootInputFileSequence:
edm::RootEmbeddedFileSequence edm::RootPrimaryFileSequence edm::RootSecondaryFileSequence

Public Member Functions

void closeFile ()
 
bool containedInCurrentFile (RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const
 
std::shared_ptr< BranchIDListHelper const > fileBranchIDListHelper () const
 
std::shared_ptr< ProductRegistry const > fileProductRegistry () const
 
RootInputFileSequenceoperator= (RootInputFileSequence const &)=delete
 
void readEvent (EventPrincipal &cache)
 
void readLuminosityBlock_ (LuminosityBlockPrincipal &lumiPrincipal)
 
std::shared_ptr< LuminosityBlockAuxiliaryreadLuminosityBlockAuxiliary_ ()
 
void readRun_ (RunPrincipal &runPrincipal)
 
std::shared_ptr< RunAuxiliaryreadRunAuxiliary_ ()
 
 RootInputFileSequence (ParameterSet const &pset, InputFileCatalog const &catalog)
 
 RootInputFileSequence (RootInputFileSequence const &)=delete
 
bool skipToItem (RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event, size_t fileNameHash=0U, bool currentFileFirst=true)
 
virtual ~RootInputFileSequence ()
 

Protected Types

typedef std::shared_ptr< RootFileRootFileSharedPtr
 

Protected Member Functions

bool atFirstFile () const
 
bool atLastFile () const
 
std::string const & fallbackFileName () const
 
std::vector< FileCatalogItem > const & fileCatalogItems () const
 
std::string const & fileName () const
 
std::vector< std::shared_ptr< IndexIntoFile > > const & indexesIntoFiles () const
 
void initFile (bool skipBadFiles)
 
void initTheFile (bool skipBadFiles, bool deleteIndexIntoFile, InputSource *input, char const *inputTypeName, InputType inputType)
 
std::string const & lfn () const
 
size_t lfnHash () const
 
std::string const & logicalFileName () const
 
bool noFiles () const
 
bool noMoreFiles () const
 
size_t numberOfFiles () const
 
std::shared_ptr< RootFile const > rootFile () const
 
std::shared_ptr< RootFile > & rootFile ()
 
size_t sequenceNumberOfFile () const
 
void setAtFileSequenceNumber (size_t offset)
 
void setAtFirstFile ()
 
void setAtNextFile ()
 
void setAtPreviousFile ()
 
void setIndexIntoFile (size_t index)
 
void setNoMoreFiles ()
 
bool skipToItemInNewFile (RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event)
 
bool skipToItemInNewFile (RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event, size_t fileNameHash)
 
bool usedFallback () const
 

Private Member Functions

virtual void closeFile_ ()=0
 
virtual void initFile_ (bool skipBadFiles)=0
 
virtual RootFileSharedPtr makeRootFile (std::shared_ptr< InputFile > filePtr)=0
 

Private Attributes

InputFileCatalog const & catalog_
 
std::vector< FileCatalogItem >::const_iterator fileIter_
 
std::vector< FileCatalogItem >::const_iterator const fileIterBegin_
 
std::vector< FileCatalogItem >::const_iterator const fileIterEnd_
 
std::vector< FileCatalogItem >::const_iterator fileIterLastOpened_
 
edm::propagate_const< std::unique_ptr< std::unordered_multimap< size_t, size_t > > > findFileForSpecifiedID_
 
std::vector< std::shared_ptr< IndexIntoFile > > indexesIntoFiles_
 
std::string lfn_
 
size_t lfnHash_
 
edm::propagate_const< RootFileSharedPtrrootFile_
 
bool usedFallback_
 

Detailed Description

Definition at line 29 of file RootInputFileSequence.h.

Member Typedef Documentation

typedef std::shared_ptr<RootFile> edm::RootInputFileSequence::RootFileSharedPtr
protected

Definition at line 54 of file RootInputFileSequence.h.

Constructor & Destructor Documentation

edm::RootInputFileSequence::RootInputFileSequence ( ParameterSet const &  pset,
InputFileCatalog const &  catalog 
)
explicit

Definition at line 24 of file RootInputFileSequence.cc.

25  : catalog_(catalog),
26  lfn_("unknown"),
27  lfnHash_(0U),
28  usedFallback_(false),
29  findFileForSpecifiedID_(nullptr),
34  rootFile_(),
size
Write out results.
std::vector< FileCatalogItem >::const_iterator fileIter_
std::vector< FileCatalogItem >::const_iterator const fileIterEnd_
std::vector< FileCatalogItem >::const_iterator const fileIterBegin_
std::vector< FileCatalogItem >::const_iterator fileIterLastOpened_
std::vector< FileCatalogItem > const & fileCatalogItems() const
#define end
Definition: vmac.h:37
std::vector< std::shared_ptr< IndexIntoFile > > indexesIntoFiles_
edm::propagate_const< RootFileSharedPtr > rootFile_
#define begin
Definition: vmac.h:30
edm::propagate_const< std::unique_ptr< std::unordered_multimap< size_t, size_t > > > findFileForSpecifiedID_
InputFileCatalog const & catalog_
edm::RootInputFileSequence::~RootInputFileSequence ( )
virtual

Definition at line 51 of file RootInputFileSequence.cc.

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

Member Function Documentation

bool edm::RootInputFileSequence::atFirstFile ( ) const
inlineprotected
bool edm::RootInputFileSequence::atLastFile ( ) const
inlineprotected

Definition at line 65 of file RootInputFileSequence.h.

References fileIter_, and fileIterEnd_.

Referenced by edm::RootPrimaryFileSequence::forwardState(), and edm::RootPrimaryFileSequence::getNextItemType().

65 { return fileIter_ + 1 == fileIterEnd_; }
std::vector< FileCatalogItem >::const_iterator const fileIterEnd_
std::vector< FileCatalogItem >::const_iterator fileIter_
void edm::RootInputFileSequence::closeFile ( )
virtual void edm::RootInputFileSequence::closeFile_ ( )
privatepure virtual
bool edm::RootInputFileSequence::containedInCurrentFile ( RunNumber_t  run,
LuminosityBlockNumber_t  lumi,
EventNumber_t  event 
) const

Definition at line 91 of file RootInputFileSequence.cc.

References rootFile().

93  {
94  if (!rootFile())
95  return false;
96  return rootFile()->containsItem(run, lumi, event);
97  }
std::shared_ptr< RootFile const > rootFile() const
Definition: event.py:1
std::string const& edm::RootInputFileSequence::fallbackFileName ( ) const
inlineprotected

Definition at line 79 of file RootInputFileSequence.h.

References fileIter_.

Referenced by initTheFile().

79 { return fileIter_->fallbackFileName(); }
std::vector< FileCatalogItem >::const_iterator fileIter_
std::shared_ptr< BranchIDListHelper const > edm::RootInputFileSequence::fileBranchIDListHelper ( ) const

Definition at line 46 of file RootInputFileSequence.cc.

References rootFile().

46  {
47  assert(rootFile());
48  return rootFile()->branchIDListHelper();
49  }
std::shared_ptr< RootFile const > rootFile() const
std::vector< FileCatalogItem > const & edm::RootInputFileSequence::fileCatalogItems ( ) const
protected

Definition at line 37 of file RootInputFileSequence.cc.

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

Referenced by lfn(), and edm::RootEmbeddedFileSequence::readOneRandom().

37  {
38  return catalog_.fileCatalogItems();
39  }
std::vector< FileCatalogItem > const & fileCatalogItems() const
InputFileCatalog const & catalog_
std::string const& edm::RootInputFileSequence::fileName ( ) const
inlineprotected
std::shared_ptr< ProductRegistry const > edm::RootInputFileSequence::fileProductRegistry ( ) const

Definition at line 41 of file RootInputFileSequence.cc.

References rootFile().

41  {
42  assert(rootFile());
43  return rootFile()->productRegistry();
44  }
std::shared_ptr< RootFile const > rootFile() const
std::vector<std::shared_ptr<IndexIntoFile> > const& edm::RootInputFileSequence::indexesIntoFiles ( ) const
inlineprotected
void edm::RootInputFileSequence::initFile ( bool  skipBadFiles)
inlineprotected
virtual void edm::RootInputFileSequence::initFile_ ( bool  skipBadFiles)
privatepure virtual
void edm::RootInputFileSequence::initTheFile ( bool  skipBadFiles,
bool  deleteIndexIntoFile,
InputSource input,
char const *  inputTypeName,
InputType  inputType 
)
protected

Definition at line 183 of file RootInputFileSequence.cc.

References cms::Exception::addAdditionalInfo(), cms::Exception::addContext(), cms::Exception::additionalInfo(), closeFile(), MillePedeFileConverter_cfg::e, relativeConstraints::empty, Exception, cms::Exception::explainSelf(), fallbackFileName(), edm::errors::FallbackFileOpenError, fileIter_, fileIterBegin_, fileIterEnd_, fileIterLastOpened_, fileName(), edm::errors::FileOpenError, indexesIntoFiles_, ElectronMcFakePostValidator_cfi::InputFile, edm::Service< T >::isAvailable(), lfn(), lfn_, lfnHash_, logicalFileName(), makeRootFile(), dataset::name, noMoreFiles(), edm::storage::StatisticsSenderService::openingFile(), MillePedeFileConverter_cfg::out, edm::InputSource::postEventReadFromSourceSignal_, edm::InputSource::preEventReadFromSourceSignal_, edm::InputFile::reportFallbackAttempt(), edm::InputFile::reportSkippedFile(), rootFile_, alignCSCRings::s, setIndexIntoFile(), AlCaHLTBitMon_QueryRunRegistry::string, and usedFallback_.

Referenced by initFile(), edm::RootSecondaryFileSequence::initFile_(), edm::RootPrimaryFileSequence::initFile_(), and edm::RootEmbeddedFileSequence::initFile_().

184  {
185  // We are really going to close the open file.
186 
188  size_t currentIndexIntoFile = fileIterLastOpened_ - fileIterBegin_;
189  if (deleteIndexIntoFile) {
190  indexesIntoFiles_[currentIndexIntoFile].reset();
191  } else {
192  if (indexesIntoFiles_[currentIndexIntoFile])
193  indexesIntoFiles_[currentIndexIntoFile]->inputFileClosed();
194  }
196  }
197  closeFile();
198 
199  if (noMoreFiles()) {
200  // No files specified
201  return;
202  }
203 
204  // Check if the logical file name was found.
205  if (fileName().empty()) {
206  // LFN not found in catalog.
208  if (!skipBadFiles) {
209  throw cms::Exception("LogicalFileNameNotFound", "RootFileSequenceBase::initTheFile()\n")
210  << "Logical file name '" << logicalFileName() << "' was not found in the file catalog.\n"
211  << "If you wanted a local file, you forgot the 'file:' prefix\n"
212  << "before the file name in your configuration file.\n";
213  }
214  LogWarning("") << "Input logical file: " << logicalFileName()
215  << " was not found in the catalog, and will be skipped.\n";
216  return;
217  }
218 
219  lfn_ = logicalFileName().empty() ? fileName() : logicalFileName();
220  lfnHash_ = std::hash<std::string>()(lfn_);
221  usedFallback_ = false;
222 
223  // Determine whether we have a fallback URL specified; if so, prepare it;
224  // Only valid if it is non-empty and differs from the original filename.
225  bool hasFallbackUrl = !fallbackFileName().empty() && fallbackFileName() != fileName();
226 
227  std::shared_ptr<InputFile> filePtr;
228  std::list<std::string> originalInfo;
229  {
230  std::unique_ptr<InputSource::FileOpenSentry> sentry(
231  input ? std::make_unique<InputSource::FileOpenSentry>(*input, lfn_, false) : nullptr);
233  if (service.isAvailable()) {
234  service->openingFile(lfn(), inputType, -1);
235  }
236  try {
237  std::unique_ptr<char[]> name(gSystem->ExpandPathName(fileName().c_str()));
238  filePtr = std::make_shared<InputFile>(name.get(), " Initiating request to open file ", inputType);
239  } catch (cms::Exception const& e) {
240  if (!skipBadFiles) {
241  if (hasFallbackUrl) {
242  std::ostringstream out;
243  out << e.explainSelf();
244 
245  std::unique_ptr<char[]> name(gSystem->ExpandPathName(fallbackFileName().c_str()));
246  std::string pfn(name.get());
248  originalInfo = e.additionalInfo();
249  } else {
251  Exception ex(errors::FileOpenError, "", e);
252  ex.addContext("Calling RootFileSequenceBase::initTheFile()");
253  std::ostringstream out;
254  out << "Input file " << fileName() << " could not be opened.";
255  ex.addAdditionalInfo(out.str());
256  throw ex;
257  }
258  }
259  }
260  if (!filePtr && (hasFallbackUrl)) {
261  try {
262  usedFallback_ = true;
263  std::unique_ptr<char[]> fallbackFullName(gSystem->ExpandPathName(fallbackFileName().c_str()));
264  filePtr.reset(new InputFile(fallbackFullName.get(), " Fallback request to file ", inputType));
265  } catch (cms::Exception const& e) {
266  if (!skipBadFiles) {
269  ex.addContext("Calling RootFileSequenceBase::initTheFile()");
270  std::ostringstream out;
271  out << "Input file " << fileName() << " could not be opened.\n";
272  out << "Fallback Input file " << fallbackFileName() << " also could not be opened.";
273  if (!originalInfo.empty()) {
274  out << std::endl << "Original exception info is above; fallback exception info is below.";
275  ex.addAdditionalInfo(out.str());
276  for (auto const& s : originalInfo) {
277  ex.addAdditionalInfo(s);
278  }
279  } else {
280  ex.addAdditionalInfo(out.str());
281  }
282  throw ex;
283  }
284  }
285  }
286  }
287  if (filePtr) {
288  size_t currentIndexIntoFile = fileIter_ - fileIterBegin_;
289  rootFile_ = makeRootFile(filePtr);
290  if (input) {
291  rootFile_->setSignals(&(input->preEventReadFromSourceSignal_), &(input->postEventReadFromSourceSignal_));
292  }
293  assert(rootFile_);
295  setIndexIntoFile(currentIndexIntoFile);
296  rootFile_->reportOpened(inputTypeName);
297  } else {
299  if (!skipBadFiles) {
300  throw Exception(errors::FileOpenError) << "RootFileSequenceBase::initTheFile(): Input file " << fileName()
301  << " was not found or could not be opened.\n";
302  }
303  LogWarning("") << "Input file: " << fileName() << " was not found or could not be opened, and will be skipped.\n";
304  }
305  }
std::string const & logicalFileName() const
std::string const & fileName() const
virtual std::string explainSelf() const
Definition: Exception.cc:146
std::vector< FileCatalogItem >::const_iterator fileIter_
std::vector< FileCatalogItem >::const_iterator const fileIterEnd_
std::vector< FileCatalogItem >::const_iterator const fileIterBegin_
std::list< std::string > const & additionalInfo() const
Definition: Exception.cc:195
static void reportFallbackAttempt(std::string const &pfn, std::string const &logicalFileName, std::string const &errorMessage)
Definition: InputFile.cc:95
std::vector< FileCatalogItem >::const_iterator fileIterLastOpened_
std::string const & lfn() const
bool isAvailable() const
Definition: Service.h:46
static void reportSkippedFile(std::string const &fileName, std::string const &logicalFileName)
Definition: InputFile.cc:89
virtual RootFileSharedPtr makeRootFile(std::shared_ptr< InputFile > filePtr)=0
std::vector< std::shared_ptr< IndexIntoFile > > indexesIntoFiles_
void openingFile(std::string const &lfn, edm::InputType type, size_t size=-1)
edm::propagate_const< RootFileSharedPtr > rootFile_
std::string const & fallbackFileName() const
std::string const& edm::RootInputFileSequence::lfn ( ) const
inlineprotected

Definition at line 80 of file RootInputFileSequence.h.

References fileCatalogItems(), and lfn_.

Referenced by closeFile(), edm::RootPrimaryFileSequence::closeFile_(), and initTheFile().

80 { return lfn_; }
size_t edm::RootInputFileSequence::lfnHash ( ) const
inlineprotected
std::string const& edm::RootInputFileSequence::logicalFileName ( ) const
inlineprotected

Definition at line 78 of file RootInputFileSequence.h.

References fileIter_.

Referenced by initTheFile(), edm::RootSecondaryFileSequence::makeRootFile(), edm::RootPrimaryFileSequence::makeRootFile(), and edm::RootEmbeddedFileSequence::makeRootFile().

78 { return fileIter_->logicalFileName(); }
std::vector< FileCatalogItem >::const_iterator fileIter_
virtual RootFileSharedPtr edm::RootInputFileSequence::makeRootFile ( std::shared_ptr< InputFile filePtr)
privatepure virtual
bool edm::RootInputFileSequence::noFiles ( ) const
inlineprotected

Definition at line 67 of file RootInputFileSequence.h.

References fileIterBegin_, and fileIterEnd_.

Referenced by edm::RootEmbeddedFileSequence::RootEmbeddedFileSequence().

67 { return fileIterBegin_ == fileIterEnd_; }
std::vector< FileCatalogItem >::const_iterator const fileIterEnd_
std::vector< FileCatalogItem >::const_iterator const fileIterBegin_
bool edm::RootInputFileSequence::noMoreFiles ( ) const
inlineprotected
size_t edm::RootInputFileSequence::numberOfFiles ( ) const
inlineprotected

Definition at line 69 of file RootInputFileSequence.h.

References fileIterBegin_, and fileIterEnd_.

Referenced by edm::RootEmbeddedFileSequence::RootEmbeddedFileSequence().

69 { return fileIterEnd_ - fileIterBegin_; }
std::vector< FileCatalogItem >::const_iterator const fileIterEnd_
std::vector< FileCatalogItem >::const_iterator const fileIterBegin_
RootInputFileSequence& edm::RootInputFileSequence::operator= ( RootInputFileSequence const &  )
delete
void edm::RootInputFileSequence::readEvent ( EventPrincipal cache)

Definition at line 86 of file RootInputFileSequence.cc.

References rootFile().

86  {
87  assert(rootFile());
88  rootFile()->readEvent(eventPrincipal);
89  }
std::shared_ptr< RootFile const > rootFile() const
void edm::RootInputFileSequence::readLuminosityBlock_ ( LuminosityBlockPrincipal lumiPrincipal)

Definition at line 68 of file RootInputFileSequence.cc.

References rootFile().

68  {
69  assert(rootFile());
70  rootFile()->readLuminosityBlock_(lumiPrincipal);
71  }
std::shared_ptr< RootFile const > rootFile() const
std::shared_ptr< LuminosityBlockAuxiliary > edm::RootInputFileSequence::readLuminosityBlockAuxiliary_ ( )

Definition at line 58 of file RootInputFileSequence.cc.

References rootFile().

58  {
59  assert(rootFile());
60  return rootFile()->readLuminosityBlockAuxiliary_();
61  }
std::shared_ptr< RootFile const > rootFile() const
void edm::RootInputFileSequence::readRun_ ( RunPrincipal runPrincipal)

Definition at line 63 of file RootInputFileSequence.cc.

References rootFile().

63  {
64  assert(rootFile());
65  rootFile()->readRun_(runPrincipal);
66  }
std::shared_ptr< RootFile const > rootFile() const
std::shared_ptr< RunAuxiliary > edm::RootInputFileSequence::readRunAuxiliary_ ( )

Definition at line 53 of file RootInputFileSequence.cc.

References rootFile().

53  {
54  assert(rootFile());
55  return rootFile()->readRunAuxiliary_();
56  }
std::shared_ptr< RootFile const > rootFile() const
std::shared_ptr<RootFile const> edm::RootInputFileSequence::rootFile ( ) const
inlineprotected

Definition at line 88 of file RootInputFileSequence.h.

References edm::get_underlying_safe(), and rootFile_.

Referenced by closeFile(), edm::RootSecondaryFileSequence::closeFile_(), edm::RootEmbeddedFileSequence::closeFile_(), edm::RootPrimaryFileSequence::closeFile_(), containedInCurrentFile(), fileBranchIDListHelper(), fileProductRegistry(), edm::RootPrimaryFileSequence::forwardState(), edm::RootPrimaryFileSequence::getNextItemType(), edm::RootPrimaryFileSequence::goToEvent(), edm::RootSecondaryFileSequence::initAssociationsFromSecondary(), edm::RootPrimaryFileSequence::nextFile(), edm::RootPrimaryFileSequence::previousFile(), readEvent(), edm::RootPrimaryFileSequence::readFile_(), readLuminosityBlock_(), readLuminosityBlockAuxiliary_(), edm::RootEmbeddedFileSequence::readOneRandom(), edm::RootEmbeddedFileSequence::readOneRandomWithID(), edm::RootEmbeddedFileSequence::readOneSequential(), edm::RootEmbeddedFileSequence::readOneSequentialWithID(), edm::RootEmbeddedFileSequence::readOneSpecified(), readRun_(), readRunAuxiliary_(), edm::RootPrimaryFileSequence::reverseState(), edm::RootPrimaryFileSequence::rewind_(), edm::RootPrimaryFileSequence::rewindFile(), edm::RootEmbeddedFileSequence::RootEmbeddedFileSequence(), edm::RootPrimaryFileSequence::RootPrimaryFileSequence(), edm::RootSecondaryFileSequence::RootSecondaryFileSequence(), setIndexIntoFile(), edm::RootEmbeddedFileSequence::skipEntries(), edm::RootPrimaryFileSequence::skipEvents(), skipToItem(), and skipToItemInNewFile().

88 { return get_underlying_safe(rootFile_); }
std::shared_ptr< T > & get_underlying_safe(propagate_const< std::shared_ptr< T >> &iP)
edm::propagate_const< RootFileSharedPtr > rootFile_
std::shared_ptr<RootFile>& edm::RootInputFileSequence::rootFile ( )
inlineprotected

Definition at line 89 of file RootInputFileSequence.h.

References edm::get_underlying_safe(), and rootFile_.

89 { return get_underlying_safe(rootFile_); }
std::shared_ptr< T > & get_underlying_safe(propagate_const< std::shared_ptr< T >> &iP)
edm::propagate_const< RootFileSharedPtr > rootFile_
size_t edm::RootInputFileSequence::sequenceNumberOfFile ( ) const
inlineprotected
void edm::RootInputFileSequence::setAtFileSequenceNumber ( size_t  offset)
inlineprotected
void edm::RootInputFileSequence::setAtFirstFile ( )
inlineprotected
void edm::RootInputFileSequence::setAtNextFile ( )
inlineprotected
void edm::RootInputFileSequence::setAtPreviousFile ( )
inlineprotected

Definition at line 75 of file RootInputFileSequence.h.

References fileIter_.

Referenced by edm::RootPrimaryFileSequence::previousFile().

75 { --fileIter_; }
std::vector< FileCatalogItem >::const_iterator fileIter_
void edm::RootInputFileSequence::setIndexIntoFile ( size_t  index)
protected

Definition at line 315 of file RootInputFileSequence.cc.

References diffTreeTool::index, indexesIntoFiles_, and rootFile().

Referenced by indexesIntoFiles(), and initTheFile().

315  {
316  indexesIntoFiles_[index] = rootFile()->indexIntoFileSharedPtr();
317  }
std::vector< std::shared_ptr< IndexIntoFile > > indexesIntoFiles_
std::shared_ptr< RootFile const > rootFile() const
void edm::RootInputFileSequence::setNoMoreFiles ( )
inlineprotected

Definition at line 73 of file RootInputFileSequence.h.

References fileIter_, and fileIterEnd_.

Referenced by edm::RootPrimaryFileSequence::skipEvents().

std::vector< FileCatalogItem >::const_iterator const fileIterEnd_
std::vector< FileCatalogItem >::const_iterator fileIter_
bool edm::RootInputFileSequence::skipToItem ( RunNumber_t  run,
LuminosityBlockNumber_t  lumi,
EventNumber_t  event,
size_t  fileNameHash = 0U,
bool  currentFileFirst = true 
)

Definition at line 152 of file RootInputFileSequence.cc.

References fileIter_, runEdmFileComparison::found, indexesIntoFiles_, initFile(), rootFile(), setAtFileSequenceNumber(), skipToItemInNewFile(), and mitigatedMETSequence_cff::U.

Referenced by edm::RootEmbeddedFileSequence::readOneRandomWithID(), edm::RootEmbeddedFileSequence::readOneSequentialWithID(), and edm::RootEmbeddedFileSequence::readOneSpecified().

153  {
154  // Attempt to find item in currently open input file.
155  bool found = currentFileFirst && rootFile() && rootFile()->setEntryAtItem(run, lumi, event);
156  if (!found) {
157  // If only one input file, give up now, to save time.
158  if (currentFileFirst && rootFile() && indexesIntoFiles_.size() == 1) {
159  return false;
160  }
161  // Look for item (run/lumi/event) in files previously opened without reopening unnecessary files.
162  for (auto it = indexesIntoFiles_.begin(), itEnd = indexesIntoFiles_.end(); it != itEnd; ++it) {
163  if (*it && (*it)->containsItem(run, lumi, event)) {
164  // We found it. Close the currently open file, and open the correct one.
165  std::vector<FileCatalogItem>::const_iterator currentIter = fileIter_;
167  if (fileIter_ != currentIter) {
168  initFile(false);
169  }
170  // Now get the item from the correct file.
171  assert(rootFile());
172  found = rootFile()->setEntryAtItem(run, lumi, event);
173  assert(found);
174  return true;
175  }
176  }
177  return (fileNameHash != 0U && skipToItemInNewFile(run, lumi, event, fileNameHash)) ||
179  }
180  return true;
181  }
void initFile(bool skipBadFiles)
void setAtFileSequenceNumber(size_t offset)
std::vector< FileCatalogItem >::const_iterator fileIter_
std::vector< std::shared_ptr< IndexIntoFile > > indexesIntoFiles_
std::shared_ptr< RootFile const > rootFile() const
bool skipToItemInNewFile(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event)
Definition: event.py:1
bool edm::RootInputFileSequence::skipToItemInNewFile ( RunNumber_t  run,
LuminosityBlockNumber_t  lumi,
EventNumber_t  event 
)
protected

Definition at line 134 of file RootInputFileSequence.cc.

References runEdmFileComparison::found, indexesIntoFiles_, initFile_(), rootFile(), and setAtFileSequenceNumber().

Referenced by initFile(), edm::RootEmbeddedFileSequence::readOneSequentialWithID(), and skipToItem().

134  {
135  // Look for item in files not yet opened. We do not have a valid hash of the logical file name.
136  for (auto it = indexesIntoFiles_.begin(), itEnd = indexesIntoFiles_.end(); it != itEnd; ++it) {
137  if (!*it) {
138  // File not yet opened.
140  initFile_(false);
141  assert(rootFile());
142  bool found = rootFile()->setEntryAtItem(run, lumi, event);
143  if (found) {
144  return true;
145  }
146  }
147  }
148  // Not found
149  return false;
150  }
void setAtFileSequenceNumber(size_t offset)
virtual void initFile_(bool skipBadFiles)=0
std::vector< std::shared_ptr< IndexIntoFile > > indexesIntoFiles_
std::shared_ptr< RootFile const > rootFile() const
Definition: event.py:1
bool edm::RootInputFileSequence::skipToItemInNewFile ( RunNumber_t  run,
LuminosityBlockNumber_t  lumi,
EventNumber_t  event,
size_t  fileNameHash 
)
protected

Definition at line 99 of file RootInputFileSequence.cc.

References fileIterBegin_, fileIterEnd_, findFileForSpecifiedID_, runEdmFileComparison::found, indexesIntoFiles_, initFile_(), rootFile(), setAtFileSequenceNumber(), and mitigatedMETSequence_cff::U.

102  {
103  // Look for item in files not yet opened. We have a hash of the logical file name
104  assert(fileNameHash != 0U);
105  // If the lookup table is not yet filled in, fill it.
107  // We use a multimap because there may be hash collisions (Two different LFNs could have the same hash).
108  // We map the hash of the LFN to the index into the list of files.
110  std::make_unique<std::unordered_multimap<size_t, size_t>>(); // propagate_const<T> has no reset() function
111  auto hasher = std::hash<std::string>();
112  for (auto fileIter = fileIterBegin_; fileIter != fileIterEnd_; ++fileIter) {
113  findFileForSpecifiedID_->insert(std::make_pair(hasher(fileIter->logicalFileName()), fileIter - fileIterBegin_));
114  }
115  }
116  // Look up the logical file name in the table
117  auto range = findFileForSpecifiedID_->equal_range(fileNameHash);
118  for (auto iter = range.first; iter != range.second; ++iter) {
119  // Don't look in files previously opened, because those have already been searched.
120  if (!indexesIntoFiles_[iter->second]) {
121  setAtFileSequenceNumber(iter->second);
122  initFile_(false);
123  assert(rootFile());
124  bool found = rootFile()->setEntryAtItem(run, lumi, event);
125  if (found) {
126  return true;
127  }
128  }
129  }
130  // Not found
131  return false;
132  }
void setAtFileSequenceNumber(size_t offset)
std::vector< FileCatalogItem >::const_iterator const fileIterEnd_
std::vector< FileCatalogItem >::const_iterator const fileIterBegin_
virtual void initFile_(bool skipBadFiles)=0
std::vector< std::shared_ptr< IndexIntoFile > > indexesIntoFiles_
std::shared_ptr< RootFile const > rootFile() const
edm::propagate_const< std::unique_ptr< std::unordered_multimap< size_t, size_t > > > findFileForSpecifiedID_
Definition: event.py:1
bool edm::RootInputFileSequence::usedFallback ( ) const
inlineprotected

Member Data Documentation

InputFileCatalog const& edm::RootInputFileSequence::catalog_
private

Definition at line 92 of file RootInputFileSequence.h.

Referenced by fileCatalogItems().

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

Definition at line 100 of file RootInputFileSequence.h.

Referenced by initTheFile().

edm::propagate_const<std::unique_ptr<std::unordered_multimap<size_t, size_t> > > edm::RootInputFileSequence::findFileForSpecifiedID_
private

Definition at line 96 of file RootInputFileSequence.h.

Referenced by skipToItemInNewFile().

std::vector<std::shared_ptr<IndexIntoFile> > edm::RootInputFileSequence::indexesIntoFiles_
private
std::string edm::RootInputFileSequence::lfn_
private

Definition at line 93 of file RootInputFileSequence.h.

Referenced by initTheFile(), and lfn().

size_t edm::RootInputFileSequence::lfnHash_
private

Definition at line 94 of file RootInputFileSequence.h.

Referenced by initTheFile(), and lfnHash().

edm::propagate_const<RootFileSharedPtr> edm::RootInputFileSequence::rootFile_
private

Definition at line 101 of file RootInputFileSequence.h.

Referenced by initTheFile(), and rootFile().

bool edm::RootInputFileSequence::usedFallback_
private

Definition at line 95 of file RootInputFileSequence.h.

Referenced by initTheFile(), and usedFallback().