CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RootInputFileSequence.cc
Go to the documentation of this file.
1 /*----------------------------------------------------------------------
2 ----------------------------------------------------------------------*/
3 #include "DuplicateChecker.h"
4 #include "PoolSource.h"
5 #include "RootFile.h"
7 #include "RootTree.h"
8 
22 
23 #include "CLHEP/Random/RandFlat.h"
24 #include "InputFile.h"
25 #include "TSystem.h"
26 
27 namespace edm {
29  ParameterSet const& pset,
32  unsigned int nStreams,
33  InputType inputType) :
34  input_(input),
35  inputType_(inputType),
36  catalog_(catalog),
37  firstFile_(true),
38  lfn_("unknown"),
39  fileIterBegin_(fileCatalogItems().begin()),
40  fileIterEnd_(fileCatalogItems().end()),
41  fileIter_(fileIterEnd_),
42  fileIterLastOpened_(fileIterEnd_),
43  rootFile_(),
44  branchesMustMatch_(BranchDescription::Permissive),
45  flatDistribution_(),
46  indexesIntoFiles_(fileCatalogItems().size()),
47  orderedProcessHistoryIDs_(),
48  nStreams_(nStreams),
49  eventSkipperByID_(inputType == InputType::Primary ? EventSkipperByID::create(pset).release() : 0),
50  eventsRemainingInFile_(0),
51  // The default value provided as the second argument to the getUntrackedParameter function call
52  // is not used when the ParameterSet has been validated and the parameters are not optional
53  // in the description. This is currently true when PoolSource is the primary input source.
54  // The modules that use PoolSource as a SecSource have not defined their fillDescriptions function
55  // yet, so the ParameterSet does not get validated yet. As soon as all the modules with a SecSource
56  // have defined descriptions, the defaults in the getUntrackedParameterSet function calls can
57  // and should be deleted from the code.
58  initialNumberOfEventsToSkip_(inputType == InputType::Primary ? pset.getUntrackedParameter<unsigned int>("skipEvents", 0U) : 0U),
59  noEventSort_(inputType == InputType::Primary ? pset.getUntrackedParameter<bool>("noEventSort", true) : false),
60  skipBadFiles_(pset.getUntrackedParameter<bool>("skipBadFiles", false)),
61  treeCacheSize_(noEventSort_ ? pset.getUntrackedParameter<unsigned int>("cacheSize", roottree::defaultCacheSize) : 0U),
62  treeMaxVirtualSize_(pset.getUntrackedParameter<int>("treeMaxVirtualSize", -1)),
63  setRun_(pset.getUntrackedParameter<unsigned int>("setRunNumber", 0U)),
64  productSelectorRules_(pset, "inputCommands", "InputSource"),
65  duplicateChecker_(inputType == InputType::Primary ? new DuplicateChecker(pset) : 0),
66  dropDescendants_(pset.getUntrackedParameter<bool>("dropDescendantsOfDroppedBranches", inputType != InputType::SecondarySource)),
67  labelRawDataLikeMC_(pset.getUntrackedParameter<bool>("labelRawDataLikeMC", true)),
68  usingGoToEvent_(false),
69  enablePrefetching_(false),
70  usedFallback_(false) {
71 
72  // The SiteLocalConfig controls the TTreeCache size and the prefetching settings.
74  if(pSLC.isAvailable()) {
75  if(treeCacheSize_ != 0U && pSLC->sourceTTreeCacheSize()) {
76  treeCacheSize_ = *(pSLC->sourceTTreeCacheSize());
77  }
78  enablePrefetching_ = pSLC->enablePrefetching();
79  }
80 
83  factory->activateTimeout(fileIter_->fileName());
84  factory->stagein(fileIter_->fileName());
85  //NOTE: we do not want to stage in all secondary files since we can be given a list of
86  // thousands of files and prestaging all those files can cause a site to fail.
87  // So, we stage in the first secondary file only.
89  break;
90  }
91  }
92 
93  std::string branchesMustMatch = pset.getUntrackedParameter<std::string>("branchesMustMatch", std::string("permissive"));
94  if(branchesMustMatch == std::string("strict")) branchesMustMatch_ = BranchDescription::Strict;
95 
98  if(rootFile_) break;
99  }
100  if(rootFile_) {
101  productRegistryUpdate().updateFromInput(rootFile_->productRegistry()->productList());
104  }
105  }
106  }
107 
108  std::vector<FileCatalogItem> const&
110  return catalog_.fileCatalogItems();
111  }
112 
113  void
115  closeFile_();
116  }
117 
118  std::unique_ptr<FileBlock>
120  if(firstFile_) {
121  // The first input file has already been opened.
122  firstFile_ = false;
123  if(!rootFile_) {
125  }
126  } else {
127  if(!nextFile()) {
128  assert(0);
129  }
130  }
131  if(!rootFile_) {
132  return std::unique_ptr<FileBlock>(new FileBlock);
133  }
134  return rootFile_->createFileBlock();
135  }
136 
138  // close the currently open file, if any, and delete the RootFile object.
139  if(rootFile_) {
141  std::unique_ptr<InputSource::FileCloseSentry>
143  rootFile_->close();
144  if(duplicateChecker_) duplicateChecker_->inputFileClosed();
145  }
146  rootFile_.reset();
147  }
148  }
149 
151  // We are really going to close the open file.
152 
153  // If this is the primary sequence, we are not duplicate checking across files
154  // and we are not using random access to find events, then we can delete the
155  // IndexIntoFile for the file we are closing. If we can't delete all of it,
156  // then we can delete the parts we do not need.
158  size_t currentIndexIntoFile = fileIterLastOpened_ - fileIterBegin_;
159  bool needIndexesForDuplicateChecker = duplicateChecker_ && duplicateChecker_->checkingAllFiles() && !duplicateChecker_->checkDisabled();
160  bool deleteIndexIntoFile = inputType_ == InputType::Primary &&
161  !needIndexesForDuplicateChecker &&
163  if(deleteIndexIntoFile) {
164  indexesIntoFiles_[currentIndexIntoFile].reset();
165  } else {
166  if(indexesIntoFiles_[currentIndexIntoFile]) indexesIntoFiles_[currentIndexIntoFile]->inputFileClosed();
167  }
169  }
170  closeFile_();
171 
172  if(fileIter_ == fileIterEnd_) {
173  // No files specified
174  return;
175  }
176 
177  // Check if the logical file name was found.
178  if(fileIter_->fileName().empty()) {
179  // LFN not found in catalog.
180  InputFile::reportSkippedFile(fileIter_->fileName(), fileIter_->logicalFileName());
181  if(!skipBadFiles) {
182  throw cms::Exception("LogicalFileNameNotFound", "RootInputFileSequence::initFile()\n")
183  << "Logical file name '" << fileIter_->logicalFileName() << "' was not found in the file catalog.\n"
184  << "If you wanted a local file, you forgot the 'file:' prefix\n"
185  << "before the file name in your configuration file.\n";
186  }
187  LogWarning("") << "Input logical file: " << fileIter_->logicalFileName() << " was not found in the catalog, and will be skipped.\n";
188  return;
189  }
190 
191  lfn_ = fileIter_->logicalFileName().empty() ? fileIter_->fileName() : fileIter_->logicalFileName();
192  usedFallback_ = false;
193 
194  // Determine whether we have a fallback URL specified; if so, prepare it;
195  // Only valid if it is non-empty and differs from the original filename.
196  std::string fallbackName = fileIter_->fallbackFileName();
197  bool hasFallbackUrl = !fallbackName.empty() && fallbackName != fileIter_->fileName();
198 
199  boost::shared_ptr<InputFile> filePtr;
200  try {
201  std::unique_ptr<InputSource::FileOpenSentry>
203  filePtr.reset(new InputFile(gSystem->ExpandPathName(fileIter_->fileName().c_str()), " Initiating request to open file ", inputType_));
204  }
205  catch (cms::Exception const& e) {
206  if(!skipBadFiles) {
207  if(hasFallbackUrl) {
208  std::ostringstream out;
209  out << e.explainSelf();
210  std::string pfn(gSystem->ExpandPathName(fallbackName.c_str()));
211  InputFile::reportFallbackAttempt(pfn, fileIter_->logicalFileName(), out.str());
212  } else {
213  InputFile::reportSkippedFile(fileIter_->fileName(), fileIter_->logicalFileName());
214  Exception ex(errors::FileOpenError, "", e);
215  ex.addContext("Calling RootInputFileSequence::initFile()");
216  std::ostringstream out;
217  out << "Input file " << fileIter_->fileName() << " could not be opened.";
218  ex.addAdditionalInfo(out.str());
219  throw ex;
220  }
221  }
222  }
223  if(!filePtr && (hasFallbackUrl)) {
224  try {
225  usedFallback_ = true;
226  std::unique_ptr<InputSource::FileOpenSentry>
228  filePtr.reset(new InputFile(gSystem->ExpandPathName(fallbackName.c_str()), " Fallback request to file ", inputType_));
229  }
230  catch (cms::Exception const& e) {
231  if(!skipBadFiles) {
232  InputFile::reportSkippedFile(fileIter_->fileName(), fileIter_->logicalFileName());
234  ex.addContext("Calling RootInputFileSequence::initFile()");
235  std::ostringstream out;
236  out << "Input file " << fileIter_->fileName() << " could not be opened.\n";
237  out << "Fallback Input file " << fallbackName << " also could not be opened.";
238  ex.addAdditionalInfo(out.str());
239  throw ex;
240  }
241  }
242  }
243  if(filePtr) {
244  std::vector<boost::shared_ptr<IndexIntoFile> >::size_type currentIndexIntoFile = fileIter_ - fileIterBegin_;
246  fileIter_->fileName(),
248  fileIter_->logicalFileName(),
249  filePtr,
252  remainingEvents(),
254  nStreams_,
258  setRun_,
259  noEventSort_,
261  inputType_,
262  (inputType_ == InputType::SecondarySource ? boost::shared_ptr<BranchIDListHelper>(new BranchIDListHelper()) : input_.branchIDListHelper()),
267  currentIndexIntoFile,
272 
274  indexesIntoFiles_[currentIndexIntoFile] = rootFile_->indexIntoFileSharedPtr();
275  char const* inputType = 0;
276  switch(inputType_) {
277  case InputType::Primary: inputType = "primaryFiles"; break;
278  case InputType::SecondaryFile: inputType = "secondaryFiles"; break;
279  case InputType::SecondarySource: inputType = "mixingFiles"; break;
280  }
281  rootFile_->reportOpened(inputType);
282  } else {
283  InputFile::reportSkippedFile(fileIter_->fileName(), fileIter_->logicalFileName());
284  if(!skipBadFiles) {
286  "RootInputFileSequence::initFile(): Input file " << fileIter_->fileName() << " was not found or could not be opened.\n";
287  }
288  LogWarning("") << "Input file: " << fileIter_->fileName() << " was not found or could not be opened, and will be skipped.\n";
289  }
290  }
291 
292  boost::shared_ptr<ProductRegistry const>
294  assert(rootFile_);
295  return rootFile_->productRegistry();
296  }
297 
298  boost::shared_ptr<BranchIDListHelper const>
300  assert(rootFile_);
301  return rootFile_->branchIDListHelper();
302  }
303 
306  if(fileIter_ == fileIterEnd_) {
308  return false;
309  } else {
311  }
312  }
313 
315 
317  // make sure the new product registry is compatible with the main one
318  std::string mergeInfo = productRegistryUpdate().merge(*rootFile_->productRegistry(),
319  fileIter_->fileName(),
321  if(!mergeInfo.empty()) {
322  throw Exception(errors::MismatchedInputFiles,"RootInputFileSequence::nextFile()") << mergeInfo;
323  }
324  }
325  return true;
326  }
327 
329  if(fileIter_ == fileIterBegin_) {
331  return false;
332  } else {
334  }
335  }
336  --fileIter_;
337 
338  initFile(false);
339 
341  // make sure the new product registry is compatible to the main one
342  std::string mergeInfo = productRegistryUpdate().merge(*rootFile_->productRegistry(),
343  fileIter_->fileName(),
345  if(!mergeInfo.empty()) {
346  throw Exception(errors::MismatchedInputFiles,"RootInputFileSequence::previousEvent()") << mergeInfo;
347  }
348  }
349  if(rootFile_) rootFile_->setToLastEntry();
350  return true;
351  }
352 
354  }
355 
356  boost::shared_ptr<RunAuxiliary>
358  return rootFile_->readRunAuxiliary_();
359  }
360 
361  boost::shared_ptr<LuminosityBlockAuxiliary>
363  return rootFile_->readLuminosityBlockAuxiliary_();
364  }
365 
366  void
368  rootFile_->readRun_(runPrincipal);
369  }
370 
371  void
373  rootFile_->readLuminosityBlock_(lumiPrincipal);
374  }
375 
376  // readEvent() is responsible for setting up the EventPrincipal.
377  //
378  // 1. fill an EventPrincipal with a unique EventID
379  // 2. For each entry in the provenance, put in one ProductHolder,
380  // holding the Provenance for the corresponding EDProduct.
381  // 3. set up the caches in the EventPrincipal to know about this
382  // ProductHolder.
383  //
384  // We do *not* create the EDProduct instance (the equivalent of reading
385  // the branch containing this EDProduct. That will be done by the Delayed Reader,
386  // when it is asked to do so.
387  //
388 
389  void
391  rootFile_->readEvent(eventPrincipal);
392  }
393 
396  if(fileIter_ == fileIterEnd_) {
397  return InputSource::IsStop;
398  }
399  if(firstFile_) {
400  return InputSource::IsFile;
401  }
402  if(rootFile_) {
403  IndexIntoFile::EntryType entryType = rootFile_->getNextItemType(run, lumi, event);
404  if(entryType == IndexIntoFile::kEvent) {
405  return InputSource::IsEvent;
406  } else if(entryType == IndexIntoFile::kLumi) {
407  return InputSource::IsLumi;
408  } else if(entryType == IndexIntoFile::kRun) {
409  return InputSource::IsRun;
410  }
411  assert(entryType == IndexIntoFile::kEnd);
412  }
413  if(fileIter_ + 1 == fileIterEnd_) {
414  return InputSource::IsStop;
415  }
416  return InputSource::IsFile;
417  }
418 
419  bool
421  if(!rootFile_) return false;
422  return rootFile_->containsItem(run, lumi, event);
423  }
424 
425  // Rewind to before the first event that was read.
426  void
428  if(fileIter_ != fileIterBegin_) {
429  closeFile_();
431  }
432  if(!rootFile_) {
433  initFile(false);
434  }
435  rewindFile();
436  firstFile_ = true;
437  if(rootFile_) {
440  }
441  }
442  }
443 
444  // Rewind to the beginning of the current file
445  void
447  if(rootFile_) rootFile_->rewind();
448  }
449 
450  // Advance "offset" events. Offset can be positive or negative (or zero).
451  bool
453  // We never call skipEvents for secondary input files. If we did,
454  // we would have to implement synchronization if a new file is opened.
455  // To avoid this, just assert.
457  while(offset != 0) {
458  bool atEnd = rootFile_->skipEvents(offset);
459  if((offset > 0 || atEnd) && !nextFile()) {
460  return false;
461  }
462  if(offset < 0 && !previousFile()) {
464  return false;
465  }
466  }
467  return true;
468  }
469 
470  bool
472  usingGoToEvent_ = true;
473  if(rootFile_) {
474  if(rootFile_->goToEvent(eventID)) {
475  return true;
476  }
477  // If only one input file, give up now, to save time.
478  if(rootFile_ && indexesIntoFiles_.size() == 1) {
479  return false;
480  }
481  // Save the current file and position so that we can restore them
482  // if we fail to restore the desired event
483  bool closedOriginalFile = false;
484  std::vector<FileCatalogItem>::const_iterator originalFile = fileIter_;
485  IndexIntoFile::IndexIntoFileItr originalPosition = rootFile_->indexIntoFileIter();
486 
487  // Look for item (run/lumi/event) in files previously opened without reopening unnecessary files.
488  typedef std::vector<boost::shared_ptr<IndexIntoFile> >::const_iterator Iter;
489  for(Iter it = indexesIntoFiles_.begin(), itEnd = indexesIntoFiles_.end(); it != itEnd; ++it) {
490  if(*it && (*it)->containsItem(eventID.run(), eventID.luminosityBlock(), eventID.event())) {
491  // We found it. Close the currently open file, and open the correct one.
492  fileIter_ = fileIterBegin_ + (it - indexesIntoFiles_.begin());
493  initFile(false);
494  // Now get the item from the correct file.
495  bool found = rootFile_->goToEvent(eventID);
496  assert(found);
497  return true;
498  }
499  }
500  // Look for item in files not yet opened.
501  for(Iter it = indexesIntoFiles_.begin(), itEnd = indexesIntoFiles_.end(); it != itEnd; ++it) {
502  if(!*it) {
503  fileIter_ = fileIterBegin_ + (it - indexesIntoFiles_.begin());
504  initFile(false);
505  closedOriginalFile = true;
506  if((*it)->containsItem(eventID.run(), eventID.luminosityBlock(), eventID.event())) {
507  if (rootFile_->goToEvent(eventID)) {
508  return true;
509  }
510  }
511  }
512  }
513  if(closedOriginalFile) {
514  fileIter_ = originalFile;
515  initFile(false);
516  rootFile_->setPosition(originalPosition);
517  }
518  }
519  return false;
520  }
521 
522  bool
524  // Look for item in files not yet opened.
525  typedef std::vector<boost::shared_ptr<IndexIntoFile> >::const_iterator Iter;
526  for(Iter it = indexesIntoFiles_.begin(), itEnd = indexesIntoFiles_.end(); it != itEnd; ++it) {
527  if(!*it) {
528  fileIter_ = fileIterBegin_ + (it - indexesIntoFiles_.begin());
529  initFile(false);
530  bool found = rootFile_->setEntryAtItem(run, lumi, event);
531  if(found) {
532  return true;
533  }
534  }
535  }
536  // Not found
537  return false;
538  }
539 
540  bool
542  // Attempt to find item in currently open input file.
543  bool found = currentFileFirst && rootFile_ && rootFile_->setEntryAtItem(run, lumi, event);
544  if(!found) {
545  // If only one input file, give up now, to save time.
546  if(currentFileFirst && rootFile_ && indexesIntoFiles_.size() == 1) {
547  return false;
548  }
549  // Look for item (run/lumi/event) in files previously opened without reopening unnecessary files.
550  typedef std::vector<boost::shared_ptr<IndexIntoFile> >::const_iterator Iter;
551  for(Iter it = indexesIntoFiles_.begin(), itEnd = indexesIntoFiles_.end(); it != itEnd; ++it) {
552  if(*it && (*it)->containsItem(run, lumi, event)) {
553  // We found it. Close the currently open file, and open the correct one.
554  std::vector<FileCatalogItem>::const_iterator currentIter = fileIter_;
555  fileIter_ = fileIterBegin_ + (it - indexesIntoFiles_.begin());
556  if(fileIter_ != currentIter) {
557  initFile(false);
558  }
559  // Now get the item from the correct file.
560  found = rootFile_->setEntryAtItem(run, lumi, event);
561  assert(found);
562  return true;
563  }
564  }
565  // Look for item in files not yet opened.
566  return skipToItemInNewFile(run, lumi, event);
567  }
568  return true;
569  }
570 
574  }
575 
579  }
580 
581  ProcessConfiguration const&
583  return input_.processConfiguration();
584  }
585 
586  int
588  return input_.remainingEvents();
589  }
590 
591  int
594  }
595 
598  return input_.productRegistryUpdate();
599  }
600 
601  boost::shared_ptr<ProductRegistry const>
603  return input_.productRegistry();
604  }
605 
606  void
607  RootInputFileSequence::dropUnwantedBranches_(std::vector<std::string> const& wantedBranches) {
608  std::vector<std::string> rules;
609  rules.reserve(wantedBranches.size() + 1);
610  rules.emplace_back("drop *");
611  for(std::vector<std::string>::const_iterator it = wantedBranches.begin(), itEnd = wantedBranches.end();
612  it != itEnd; ++it) {
613  rules.push_back("keep " + *it + "_*");
614  }
615  ParameterSet pset;
616  pset.addUntrackedParameter("inputCommands", rules);
617  productSelectorRules_ = ProductSelectorRules(pset, "inputCommands", "InputSource");
618  }
619 
620  bool
622  skipBadFiles_ = false;
623  if(fileIter_ == fileIterEnd_ || !rootFile_) {
625  throw Exception(errors::Configuration) << "RootInputFileSequence::readOneSequential(): no input files specified for secondary input source.\n";
626  }
628  initFile(false);
629  rootFile_->setAtEventEntry(IndexIntoFile::invalidEntry);
630  }
631  rootFile_->nextEventEntry();
632  bool found = rootFile_->readCurrentEvent(cache);
633  if(!found) {
634  ++fileIter_;
635  if(fileIter_ == fileIterEnd_) {
636  return false;
637  }
638  initFile(false);
639  rootFile_->setAtEventEntry(IndexIntoFile::invalidEntry);
640  return readOneSequential(cache);
641  }
642  return true;
643  }
644 
645  bool
648  throw Exception(errors::Configuration) << "RootInputFileSequence::readOneSequentialWithID(): no input files specified for secondary input source.\n";
649  }
650  skipBadFiles_ = false;
651  if(fileIter_ == fileIterEnd_ || !rootFile_ ||
652  rootFile_->indexIntoFileIter().run() != id.run() ||
653  rootFile_->indexIntoFileIter().lumi() != id.luminosityBlock()) {
654  bool found = skipToItem(id.run(), id.luminosityBlock(), 0, false);
655  if(!found) {
656  return false;
657  }
658  }
659  bool found = rootFile_->setEntryAtNextEventInLumi(id.run(), id.luminosityBlock());
660  if(found) {
661  found = rootFile_->readCurrentEvent(cache);
662  }
663  if(!found) {
664  found = skipToItemInNewFile(id.run(), id.luminosityBlock(), 0);
665  if(!found) {
666  return false;
667  }
668  return readOneSequentialWithID(cache, id);
669  }
670  return true;
671  }
672 
673  void
676  throw Exception(errors::Configuration) << "RootInputFileSequence::readOneSpecified(): no input files specified for secondary input source.\n";
677  }
678  skipBadFiles_ = false;
679  bool found = skipToItem(id.run(), id.luminosityBlock(), id.event());
680  if(!found) {
681  throw Exception(errors::NotFound) <<
682  "RootInputFileSequence::readOneSpecified(): Secondary Input files" <<
683  " do not contain specified event:\n" << id << "\n";
684  }
685  found = rootFile_->readCurrentEvent(cache);
686  assert(found);
687  }
688 
689  void
692  throw Exception(errors::Configuration) << "RootInputFileSequence::readOneRandom(): no input files specified for secondary input source.\n";
693  }
694  if(!flatDistribution_) {
696  CLHEP::HepRandomEngine& engine = rng->getEngine();
697  flatDistribution_.reset(new CLHEP::RandFlat(engine));
698  }
699  skipBadFiles_ = false;
700  unsigned int currentSeqNumber = fileIter_ - fileIterBegin_;
701  while(eventsRemainingInFile_ == 0) {
702  fileIter_ = fileIterBegin_ + flatDistribution_->fireInt(fileCatalogItems().size());
703  unsigned int newSeqNumber = fileIter_ - fileIterBegin_;
704  if(newSeqNumber != currentSeqNumber) {
705  initFile(false);
706  currentSeqNumber = newSeqNumber;
707  }
708  eventsRemainingInFile_ = rootFile_->eventTree().entries();
709  if(eventsRemainingInFile_ == 0) {
710  throw Exception(errors::NotFound) <<
711  "RootInputFileSequence::readOneRandom(): Secondary Input file " << fileIter_->fileName() << " contains no events.\n";
712  }
713  rootFile_->setAtEventEntry(flatDistribution_->fireInt(eventsRemainingInFile_) - 1);
714  }
715  rootFile_->nextEventEntry();
716 
717  bool found = rootFile_->readCurrentEvent(cache);
718  if(!found) {
719  rootFile_->setAtEventEntry(0);
720  bool found = rootFile_->readCurrentEvent(cache);
721  assert(found);
722  }
724  }
725 
726  // bool RootFile::setEntryAtNextEventInLumi(RunNumber_t run, LuminosityBlockNumber_t lumi) {
727 
728  bool
731  throw Exception(errors::Configuration) << "RootInputFileSequence::readOneRandomWithID(): no input files specified for secondary input source.\n";
732  }
733  if(!flatDistribution_) {
735  CLHEP::HepRandomEngine& engine = rng->getEngine();
736  flatDistribution_.reset(new CLHEP::RandFlat(engine));
737  }
738  skipBadFiles_ = false;
739  if(fileIter_ == fileIterEnd_ || !rootFile_ ||
740  rootFile_->indexIntoFileIter().run() != id.run() ||
741  rootFile_->indexIntoFileIter().lumi() != id.luminosityBlock()) {
742  bool found = skipToItem(id.run(), id.luminosityBlock(), 0);
743  if(!found) {
744  return false;
745  }
746  int eventsInLumi = 0;
747  while(rootFile_->setEntryAtNextEventInLumi(id.run(), id.luminosityBlock())) ++eventsInLumi;
748  found = skipToItem(id.run(), id.luminosityBlock(), 0);
749  assert(found);
750  int eventInLumi = flatDistribution_->fireInt(eventsInLumi);
751  for(int i = 0; i < eventInLumi; ++i) {
752  bool found = rootFile_->setEntryAtNextEventInLumi(id.run(), id.luminosityBlock());
753  assert(found);
754  }
755  }
756  bool found = rootFile_->setEntryAtNextEventInLumi(id.run(), id.luminosityBlock());
757  if(found) {
758  found = rootFile_->readCurrentEvent(cache);
759  }
760  if(!found) {
761  bool found = rootFile_->setEntryAtItem(id.run(), id.luminosityBlock(), 0);
762  if(!found) {
763  return false;
764  }
765  return readOneRandomWithID(cache, id);
766  }
767  return true;
768  }
769 
770  void
772  desc.addUntracked<unsigned int>("skipEvents", 0U)
773  ->setComment("Skip the first 'skipEvents' events that otherwise would have been processed.");
774  desc.addUntracked<bool>("noEventSort", true)
775  ->setComment("True: Process runs, lumis and events in the order they appear in the file (but see notes 1 and 2).\n"
776  "False: Process runs, lumis and events in each file in numerical order (run#, lumi#, event#) (but see note 3).\n"
777  "Note 1: Events within the same lumi will always be processed contiguously.\n"
778  "Note 2: Lumis within the same run will always be processed contiguously.\n"
779  "Note 3: Any sorting occurs independently in each input file (no sorting across input files).");
780  desc.addUntracked<bool>("skipBadFiles", false)
781  ->setComment("True: Ignore any missing or unopenable input file.\n"
782  "False: Throw exception if missing or unopenable input file.");
783  desc.addUntracked<unsigned int>("cacheSize", roottree::defaultCacheSize)
784  ->setComment("Size of ROOT TTree prefetch cache. Affects performance.");
785  desc.addUntracked<int>("treeMaxVirtualSize", -1)
786  ->setComment("Size of ROOT TTree TBasket cache. Affects performance.");
787  desc.addUntracked<unsigned int>("setRunNumber", 0U)
788  ->setComment("If non-zero, change number of first run to this number. Apply same offset to all runs. Allowed only for simulation.");
789  desc.addUntracked<bool>("dropDescendantsOfDroppedBranches", true)
790  ->setComment("If True, also drop on input any descendent of any branch dropped on input.");
791  std::string defaultString("permissive");
792  desc.addUntracked<std::string>("branchesMustMatch", defaultString)
793  ->setComment("'strict': Branches in each input file must match those in the first file.\n"
794  "'permissive': Branches in each input file may be any subset of those in the first file.");
795  desc.addUntracked<bool>("labelRawDataLikeMC", true)
796  ->setComment("If True: replace module label for raw data to match MC. Also use 'LHC' as process.");
797 
798  ProductSelectorRules::fillDescription(desc, "inputCommands");
801  }
802 
805  if(rootFile_) {
806  if(!rootFile_->wasLastEventJustRead()) {
808  }
809  std::vector<FileCatalogItem>::const_iterator itr(fileIter_);
810  if(itr != fileIterEnd_) ++itr;
811  if(itr != fileIterEnd_) {
813  }
815  }
817  }
818 
821  if(rootFile_) {
822  if(!rootFile_->wasFirstEventJustRead()) {
824  }
825  if(fileIter_ != fileIterBegin_) {
827  }
829  }
831  }
832 }
RunNumber_t run() const
Definition: EventID.h:42
void readOneSpecified(EventPrincipal &cache, EventID const &id)
ProcessingController::ForwardState forwardState() const
EventNumber_t event() const
Definition: EventID.h:44
ProcessHistoryRegistry const & processHistoryRegistry() const
Const accessor for process history registry.
Definition: InputSource.h:170
T getUntrackedParameter(std::string const &, T const &) const
boost::shared_ptr< ProductRegistry const > fileProductRegistry() const
int i
Definition: DBlmapReader.cc:9
std::vector< boost::shared_ptr< IndexIntoFile > > indexesIntoFiles_
void stagein(const std::string &url)
static void fillDescription(ParameterSetDescription &desc, char const *parameterName)
InputType
Definition: InputType.h:5
list pfn
Definition: dbtoconf.py:76
void initFile(bool skipBadFiles)
bool goToEvent(EventID const &eventID)
ProductSelectorRules productSelectorRules_
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
boost::shared_ptr< BranchIDListHelper const > fileBranchIDListHelper() const
ProcessConfiguration const & processConfiguration() const
unsigned int EventNumber_t
Definition: EventID.h:30
virtual std::string explainSelf() const
Definition: Exception.cc:146
boost::shared_ptr< RunAuxiliary > readRunAuxiliary_()
std::vector< FileCatalogItem >::const_iterator fileIter_
tuple lumi
Definition: fjr2json.py:35
ProductRegistry & productRegistryUpdate() const
boost::shared_ptr< LuminosityBlockAuxiliary > readLuminosityBlockAuxiliary_()
ProcessingMode processingMode() const
RunsLumisAndEvents (default), RunsAndLumis, or Runs.
Definition: InputSource.h:249
static void fillDescription(ParameterSetDescription &desc)
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:43
static void reportSkippedFile(std::string const &fileName, std::string const &logicalFileName)
Definition: InputFile.cc:69
unsigned int const defaultCacheSize
Definition: RootTree.h:37
uint16_t size_type
unsigned int LuminosityBlockNumber_t
Definition: EventID.h:31
static void fillDescription(ParameterSetDescription &desc)
bool skipToItem(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event, bool currentFileFirst=true)
static std::string const input
Definition: EdmProvDump.cc:44
bool readOneSequentialWithID(EventPrincipal &cache, LuminosityBlockID const &id)
static StorageFactory * get(void)
tuple InputFile
Open Root file and provide MEs ############.
void readOneRandom(EventPrincipal &cache)
static void reportFallbackAttempt(std::string const &pfn, std::string const &logicalFileName, std::string const &errorMessage)
Definition: InputFile.cc:75
int remainingEvents() const
Definition: InputSource.h:190
std::vector< FileCatalogItem >::const_iterator fileIterLastOpened_
boost::shared_ptr< BranchIDListHelper > branchIDListHelper() const
Accessor for branchIDListHelper.
Definition: InputSource.h:176
std::vector< FileCatalogItem > const & fileCatalogItems() const
bool isAvailable() const
Definition: Service.h:46
ProcessHistoryRegistry const & processHistoryRegistry() const
boost::shared_ptr< DuplicateChecker > duplicateChecker_
std::string merge(ProductRegistry const &other, std::string const &fileName, BranchDescription::MatchMode branchesMustMatch=BranchDescription::Permissive)
bool readOneSequential(EventPrincipal &cache)
#define end
Definition: vmac.h:37
unsigned int offset(bool)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
void dropUnwantedBranches_(std::vector< std::string > const &wantedBranches)
void readRun_(RunPrincipal &runPrincipal)
void readLuminosityBlock_(LuminosityBlockPrincipal &lumiPrincipal)
tuple out
Definition: dbtoconf.py:99
std::unique_ptr< CLHEP::RandFlat > flatDistribution_
static EntryNumber_t const invalidEntry
std::vector< ProcessHistoryID > orderedProcessHistoryIDs_
void addUntrackedParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:206
ProductRegistry & productRegistryUpdate() const
Definition: InputSource.h:343
bool containedInCurrentFile(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const
bool skipToItemInNewFile(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event)
std::unique_ptr< FileBlock > readFile_()
bool readOneRandomWithID(EventPrincipal &cache, LuminosityBlockID const &id)
InputSource::ItemType getNextItemType(RunNumber_t &run, LuminosityBlockNumber_t &lumi, EventNumber_t &event)
RootInputFileSequence(ParameterSet const &pset, PoolSource &input, InputFileCatalog const &catalog, unsigned int nStreams, InputType inputType)
ProcessHistoryRegistry & processHistoryRegistryForUpdate()
Non-const accessor for process history registry.
Definition: InputSource.h:173
std::vector< FileCatalogItem >::const_iterator fileIterBegin_
boost::shared_ptr< ProductRegistry const > productRegistry() const
Accessor for product registry.
Definition: InputSource.h:167
tuple skipBadFiles
Definition: example_cfg.py:64
static void fillDescription(ParameterSetDescription &desc)
#define begin
Definition: vmac.h:30
boost::shared_ptr< EventSkipperByID > eventSkipperByID_
void updateFromInput(ProductList const &other)
ProcessHistoryRegistry & processHistoryRegistryForUpdate()
void activateTimeout(const std::string &url)
std::vector< FileCatalogItem >::const_iterator fileIterEnd_
int remainingLuminosityBlocks() const
Definition: InputSource.h:198
unsigned int RunNumber_t
Definition: EventRange.h:32
BranchDescription::MatchMode branchesMustMatch_
volatile std::atomic< bool > shutdown_flag false
void readEvent(EventPrincipal &cache)
ProcessConfiguration const & processConfiguration() const
Accessor for Process Configuration.
Definition: InputSource.h:204
ProcessingController::ReverseState reverseState() const
SurfaceDeformation * create(int type, const std::vector< double > &params)
tuple size
Write out results.
boost::shared_ptr< RootFile > RootFileSharedPtr
std::vector< FileCatalogItem > const & fileCatalogItems() const
boost::shared_ptr< ProductRegistry const > productRegistry() const
InputFileCatalog const & catalog_