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 
21 
22 #include "CLHEP/Random/RandFlat.h"
23 #include "InputFile.h"
24 #include "TSystem.h"
25 
26 namespace edm {
28  ParameterSet const& pset,
31  unsigned int nStreams,
32  InputType inputType) :
33  input_(input),
34  inputType_(inputType),
35  catalog_(catalog),
36  firstFile_(true),
37  lfn_("unknown"),
38  fileIterBegin_(fileCatalogItems().begin()),
39  fileIterEnd_(fileCatalogItems().end()),
40  fileIter_(fileIterEnd_),
41  fileIterLastOpened_(fileIterEnd_),
42  rootFile_(),
43  branchesMustMatch_(BranchDescription::Permissive),
44  indexesIntoFiles_(fileCatalogItems().size()),
45  orderedProcessHistoryIDs_(),
46  nStreams_(nStreams),
47  eventSkipperByID_(inputType == InputType::Primary ? EventSkipperByID::create(pset).release() : 0),
48  eventsRemainingInFile_(0),
49  // The default value provided as the second argument to the getUntrackedParameter function call
50  // is not used when the ParameterSet has been validated and the parameters are not optional
51  // in the description. This is currently true when PoolSource is the primary input source.
52  // The modules that use PoolSource as a SecSource have not defined their fillDescriptions function
53  // yet, so the ParameterSet does not get validated yet. As soon as all the modules with a SecSource
54  // have defined descriptions, the defaults in the getUntrackedParameterSet function calls can
55  // and should be deleted from the code.
56  initialNumberOfEventsToSkip_(inputType == InputType::Primary ? pset.getUntrackedParameter<unsigned int>("skipEvents", 0U) : 0U),
57  noEventSort_(inputType == InputType::Primary ? pset.getUntrackedParameter<bool>("noEventSort", true) : false),
58  skipBadFiles_(pset.getUntrackedParameter<bool>("skipBadFiles", false)),
59  treeCacheSize_(noEventSort_ ? pset.getUntrackedParameter<unsigned int>("cacheSize", roottree::defaultCacheSize) : 0U),
60  treeMaxVirtualSize_(pset.getUntrackedParameter<int>("treeMaxVirtualSize", -1)),
61  setRun_(pset.getUntrackedParameter<unsigned int>("setRunNumber", 0U)),
62  productSelectorRules_(pset, "inputCommands", "InputSource"),
63  duplicateChecker_(inputType == InputType::Primary ? new DuplicateChecker(pset) : 0),
64  dropDescendants_(pset.getUntrackedParameter<bool>("dropDescendantsOfDroppedBranches", inputType != InputType::SecondarySource)),
65  labelRawDataLikeMC_(pset.getUntrackedParameter<bool>("labelRawDataLikeMC", true)),
66  usingGoToEvent_(false),
67  enablePrefetching_(false),
68  usedFallback_(false) {
69 
70  // The SiteLocalConfig controls the TTreeCache size and the prefetching settings.
72  if(pSLC.isAvailable()) {
73  if(treeCacheSize_ != 0U && pSLC->sourceTTreeCacheSize()) {
74  treeCacheSize_ = *(pSLC->sourceTTreeCacheSize());
75  }
76  enablePrefetching_ = pSLC->enablePrefetching();
77  }
78 
81  factory->activateTimeout(fileIter_->fileName());
82  factory->stagein(fileIter_->fileName());
83  //NOTE: we do not want to stage in all secondary files since we can be given a list of
84  // thousands of files and prestaging all those files can cause a site to fail.
85  // So, we stage in the first secondary file only.
87  break;
88  }
89  }
90 
91  std::string branchesMustMatch = pset.getUntrackedParameter<std::string>("branchesMustMatch", std::string("permissive"));
92  if(branchesMustMatch == std::string("strict")) branchesMustMatch_ = BranchDescription::Strict;
93 
96  if(rootFile_) break;
97  }
98  if(rootFile_) {
99  productRegistryUpdate().updateFromInput(rootFile_->productRegistry()->productList());
102  }
103  }
104  }
105 
106  std::vector<FileCatalogItem> const&
108  return catalog_.fileCatalogItems();
109  }
110 
111  void
113  closeFile_();
114  }
115 
116  std::unique_ptr<FileBlock>
118  if(firstFile_) {
119  // The first input file has already been opened.
120  firstFile_ = false;
121  if(!rootFile_) {
123  }
124  } else {
125  if(!nextFile()) {
126  assert(0);
127  }
128  }
129  if(!rootFile_) {
130  return std::unique_ptr<FileBlock>(new FileBlock);
131  }
132  return rootFile_->createFileBlock();
133  }
134 
136  // close the currently open file, if any, and delete the RootFile object.
137  if(rootFile_) {
139  std::unique_ptr<InputSource::FileCloseSentry>
141  rootFile_->close();
142  if(duplicateChecker_) duplicateChecker_->inputFileClosed();
143  }
144  rootFile_.reset();
145  }
146  }
147 
149  // We are really going to close the open file.
150 
151  // If this is the primary sequence, we are not duplicate checking across files
152  // and we are not using random access to find events, then we can delete the
153  // IndexIntoFile for the file we are closing. If we can't delete all of it,
154  // then we can delete the parts we do not need.
156  size_t currentIndexIntoFile = fileIterLastOpened_ - fileIterBegin_;
157  bool needIndexesForDuplicateChecker = duplicateChecker_ && duplicateChecker_->checkingAllFiles() && !duplicateChecker_->checkDisabled();
158  bool deleteIndexIntoFile = inputType_ == InputType::Primary &&
159  !needIndexesForDuplicateChecker &&
161  if(deleteIndexIntoFile) {
162  indexesIntoFiles_[currentIndexIntoFile].reset();
163  } else {
164  if(indexesIntoFiles_[currentIndexIntoFile]) indexesIntoFiles_[currentIndexIntoFile]->inputFileClosed();
165  }
167  }
168  closeFile_();
169 
170  if(fileIter_ == fileIterEnd_) {
171  // No files specified
172  return;
173  }
174 
175  // Check if the logical file name was found.
176  if(fileIter_->fileName().empty()) {
177  // LFN not found in catalog.
178  InputFile::reportSkippedFile(fileIter_->fileName(), fileIter_->logicalFileName());
179  if(!skipBadFiles) {
180  throw cms::Exception("LogicalFileNameNotFound", "RootInputFileSequence::initFile()\n")
181  << "Logical file name '" << fileIter_->logicalFileName() << "' was not found in the file catalog.\n"
182  << "If you wanted a local file, you forgot the 'file:' prefix\n"
183  << "before the file name in your configuration file.\n";
184  }
185  LogWarning("") << "Input logical file: " << fileIter_->logicalFileName() << " was not found in the catalog, and will be skipped.\n";
186  return;
187  }
188 
189  lfn_ = fileIter_->logicalFileName().empty() ? fileIter_->fileName() : fileIter_->logicalFileName();
190  usedFallback_ = false;
191 
192  // Determine whether we have a fallback URL specified; if so, prepare it;
193  // Only valid if it is non-empty and differs from the original filename.
194  std::string fallbackName = fileIter_->fallbackFileName();
195  bool hasFallbackUrl = !fallbackName.empty() && fallbackName != fileIter_->fileName();
196 
197  boost::shared_ptr<InputFile> filePtr;
198  try {
199  std::unique_ptr<InputSource::FileOpenSentry>
201  filePtr.reset(new InputFile(gSystem->ExpandPathName(fileIter_->fileName().c_str()), " Initiating request to open file ", inputType_));
202  }
203  catch (cms::Exception const& e) {
204  if(!skipBadFiles) {
205  if(hasFallbackUrl) {
206  std::ostringstream out;
207  out << e.explainSelf();
208  std::string pfn(gSystem->ExpandPathName(fallbackName.c_str()));
209  InputFile::reportFallbackAttempt(pfn, fileIter_->logicalFileName(), out.str());
210  } else {
211  InputFile::reportSkippedFile(fileIter_->fileName(), fileIter_->logicalFileName());
212  Exception ex(errors::FileOpenError, "", e);
213  ex.addContext("Calling RootInputFileSequence::initFile()");
214  std::ostringstream out;
215  out << "Input file " << fileIter_->fileName() << " could not be opened.";
216  ex.addAdditionalInfo(out.str());
217  throw ex;
218  }
219  }
220  }
221  if(!filePtr && (hasFallbackUrl)) {
222  try {
223  usedFallback_ = true;
224  std::unique_ptr<InputSource::FileOpenSentry>
226  filePtr.reset(new InputFile(gSystem->ExpandPathName(fallbackName.c_str()), " Fallback request to file ", inputType_));
227  }
228  catch (cms::Exception const& e) {
229  if(!skipBadFiles) {
230  InputFile::reportSkippedFile(fileIter_->fileName(), fileIter_->logicalFileName());
232  ex.addContext("Calling RootInputFileSequence::initFile()");
233  std::ostringstream out;
234  out << "Input file " << fileIter_->fileName() << " could not be opened.\n";
235  out << "Fallback Input file " << fallbackName << " also could not be opened.";
236  ex.addAdditionalInfo(out.str());
237  throw ex;
238  }
239  }
240  }
241  if(filePtr) {
242  std::vector<boost::shared_ptr<IndexIntoFile> >::size_type currentIndexIntoFile = fileIter_ - fileIterBegin_;
244  fileIter_->fileName(),
246  fileIter_->logicalFileName(),
247  filePtr,
250  remainingEvents(),
252  nStreams_,
256  setRun_,
257  noEventSort_,
259  inputType_,
260  (inputType_ == InputType::SecondarySource ? boost::shared_ptr<BranchIDListHelper>(new BranchIDListHelper()) : input_.branchIDListHelper()),
265  currentIndexIntoFile,
270 
271  assert(rootFile_);
273  indexesIntoFiles_[currentIndexIntoFile] = rootFile_->indexIntoFileSharedPtr();
274  char const* inputType = 0;
275  switch(inputType_) {
276  case InputType::Primary: inputType = "primaryFiles"; break;
277  case InputType::SecondaryFile: inputType = "secondaryFiles"; break;
278  case InputType::SecondarySource: inputType = "mixingFiles"; break;
279  }
280  rootFile_->reportOpened(inputType);
281  } else {
282  InputFile::reportSkippedFile(fileIter_->fileName(), fileIter_->logicalFileName());
283  if(!skipBadFiles) {
285  "RootInputFileSequence::initFile(): Input file " << fileIter_->fileName() << " was not found or could not be opened.\n";
286  }
287  LogWarning("") << "Input file: " << fileIter_->fileName() << " was not found or could not be opened, and will be skipped.\n";
288  }
289  }
290 
291  boost::shared_ptr<ProductRegistry const>
293  assert(rootFile_);
294  return rootFile_->productRegistry();
295  }
296 
297  boost::shared_ptr<BranchIDListHelper const>
299  assert(rootFile_);
300  return rootFile_->branchIDListHelper();
301  }
302 
305  if(fileIter_ == fileIterEnd_) {
307  return false;
308  } else {
310  }
311  }
312 
314 
316  // make sure the new product registry is compatible with the main one
317  std::string mergeInfo = productRegistryUpdate().merge(*rootFile_->productRegistry(),
318  fileIter_->fileName(),
320  if(!mergeInfo.empty()) {
321  throw Exception(errors::MismatchedInputFiles,"RootInputFileSequence::nextFile()") << mergeInfo;
322  }
323  }
324  return true;
325  }
326 
328  if(fileIter_ == fileIterBegin_) {
330  return false;
331  } else {
333  }
334  }
335  --fileIter_;
336 
337  initFile(false);
338 
340  // make sure the new product registry is compatible to the main one
341  std::string mergeInfo = productRegistryUpdate().merge(*rootFile_->productRegistry(),
342  fileIter_->fileName(),
344  if(!mergeInfo.empty()) {
345  throw Exception(errors::MismatchedInputFiles,"RootInputFileSequence::previousEvent()") << mergeInfo;
346  }
347  }
348  if(rootFile_) rootFile_->setToLastEntry();
349  return true;
350  }
351 
353  }
354 
355  boost::shared_ptr<RunAuxiliary>
357  assert(rootFile_);
358  return rootFile_->readRunAuxiliary_();
359  }
360 
361  boost::shared_ptr<LuminosityBlockAuxiliary>
363  assert(rootFile_);
364  return rootFile_->readLuminosityBlockAuxiliary_();
365  }
366 
367  void
369  assert(rootFile_);
370  rootFile_->readRun_(runPrincipal);
371  }
372 
373  void
375  assert(rootFile_);
376  rootFile_->readLuminosityBlock_(lumiPrincipal);
377  }
378 
379  // readEvent() is responsible for setting up the EventPrincipal.
380  //
381  // 1. fill an EventPrincipal with a unique EventID
382  // 2. For each entry in the provenance, put in one ProductHolder,
383  // holding the Provenance for the corresponding EDProduct.
384  // 3. set up the caches in the EventPrincipal to know about this
385  // ProductHolder.
386  //
387  // We do *not* create the EDProduct instance (the equivalent of reading
388  // the branch containing this EDProduct. That will be done by the Delayed Reader,
389  // when it is asked to do so.
390  //
391 
392  void
394  assert(rootFile_);
395  rootFile_->readEvent(eventPrincipal);
396  }
397 
400  if(fileIter_ == fileIterEnd_) {
401  return InputSource::IsStop;
402  }
403  if(firstFile_) {
404  return InputSource::IsFile;
405  }
406  if(rootFile_) {
407  IndexIntoFile::EntryType entryType = rootFile_->getNextItemType(run, lumi, event);
408  if(entryType == IndexIntoFile::kEvent) {
409  return InputSource::IsEvent;
410  } else if(entryType == IndexIntoFile::kLumi) {
411  return InputSource::IsLumi;
412  } else if(entryType == IndexIntoFile::kRun) {
413  return InputSource::IsRun;
414  }
415  assert(entryType == IndexIntoFile::kEnd);
416  }
417  if(fileIter_ + 1 == fileIterEnd_) {
418  return InputSource::IsStop;
419  }
420  return InputSource::IsFile;
421  }
422 
423  bool
425  if(!rootFile_) return false;
426  return rootFile_->containsItem(run, lumi, event);
427  }
428 
429  // Rewind to before the first event that was read.
430  void
432  if(fileIter_ != fileIterBegin_) {
433  closeFile_();
435  }
436  if(!rootFile_) {
437  initFile(false);
438  }
439  rewindFile();
440  firstFile_ = true;
441  if(rootFile_) {
444  }
445  }
446  }
447 
448  // Rewind to the beginning of the current file
449  void
451  if(rootFile_) rootFile_->rewind();
452  }
453 
454  // Advance "offset" events. Offset can be positive or negative (or zero).
455  bool
457  // We never call skipEvents for secondary input files. If we did,
458  // we would have to implement synchronization if a new file is opened.
459  // To avoid this, just assert.
461  assert(rootFile_);
462  while(offset != 0) {
463  bool atEnd = rootFile_->skipEvents(offset);
464  if((offset > 0 || atEnd) && !nextFile()) {
465  return false;
466  }
467  if(offset < 0 && !previousFile()) {
469  return false;
470  }
471  }
472  return true;
473  }
474 
475  bool
477  usingGoToEvent_ = true;
478  if(rootFile_) {
479  if(rootFile_->goToEvent(eventID)) {
480  return true;
481  }
482  // If only one input file, give up now, to save time.
483  if(rootFile_ && indexesIntoFiles_.size() == 1) {
484  return false;
485  }
486  // Save the current file and position so that we can restore them
487  // if we fail to restore the desired event
488  bool closedOriginalFile = false;
489  std::vector<FileCatalogItem>::const_iterator originalFile = fileIter_;
490  IndexIntoFile::IndexIntoFileItr originalPosition = rootFile_->indexIntoFileIter();
491 
492  // Look for item (run/lumi/event) in files previously opened without reopening unnecessary files.
493  typedef std::vector<boost::shared_ptr<IndexIntoFile> >::const_iterator Iter;
494  for(Iter it = indexesIntoFiles_.begin(), itEnd = indexesIntoFiles_.end(); it != itEnd; ++it) {
495  if(*it && (*it)->containsItem(eventID.run(), eventID.luminosityBlock(), eventID.event())) {
496  // We found it. Close the currently open file, and open the correct one.
497  fileIter_ = fileIterBegin_ + (it - indexesIntoFiles_.begin());
498  initFile(false);
499  // Now get the item from the correct file.
500  assert(rootFile_);
501  bool found = rootFile_->goToEvent(eventID);
502  assert(found);
503  return true;
504  }
505  }
506  // Look for item in files not yet opened.
507  for(Iter it = indexesIntoFiles_.begin(), itEnd = indexesIntoFiles_.end(); it != itEnd; ++it) {
508  if(!*it) {
509  fileIter_ = fileIterBegin_ + (it - indexesIntoFiles_.begin());
510  initFile(false);
511  closedOriginalFile = true;
512  if((*it)->containsItem(eventID.run(), eventID.luminosityBlock(), eventID.event())) {
513  assert(rootFile_);
514  if(rootFile_->goToEvent(eventID)) {
515  return true;
516  }
517  }
518  }
519  }
520  if(closedOriginalFile) {
521  fileIter_ = originalFile;
522  initFile(false);
523  assert(rootFile_);
524  rootFile_->setPosition(originalPosition);
525  }
526  }
527  return false;
528  }
529 
530  bool
532  // Look for item in files not yet opened.
533  typedef std::vector<boost::shared_ptr<IndexIntoFile> >::const_iterator Iter;
534  for(Iter it = indexesIntoFiles_.begin(), itEnd = indexesIntoFiles_.end(); it != itEnd; ++it) {
535  if(!*it) {
536  fileIter_ = fileIterBegin_ + (it - indexesIntoFiles_.begin());
537  initFile(false);
538  assert(rootFile_);
539  bool found = rootFile_->setEntryAtItem(run, lumi, event);
540  if(found) {
541  return true;
542  }
543  }
544  }
545  // Not found
546  return false;
547  }
548 
549  bool
551  // Attempt to find item in currently open input file.
552  bool found = currentFileFirst && rootFile_ && rootFile_->setEntryAtItem(run, lumi, event);
553  if(!found) {
554  // If only one input file, give up now, to save time.
555  if(currentFileFirst && rootFile_ && indexesIntoFiles_.size() == 1) {
556  return false;
557  }
558  // Look for item (run/lumi/event) in files previously opened without reopening unnecessary files.
559  typedef std::vector<boost::shared_ptr<IndexIntoFile> >::const_iterator Iter;
560  for(Iter it = indexesIntoFiles_.begin(), itEnd = indexesIntoFiles_.end(); it != itEnd; ++it) {
561  if(*it && (*it)->containsItem(run, lumi, event)) {
562  // We found it. Close the currently open file, and open the correct one.
563  std::vector<FileCatalogItem>::const_iterator currentIter = fileIter_;
564  fileIter_ = fileIterBegin_ + (it - indexesIntoFiles_.begin());
565  if(fileIter_ != currentIter) {
566  initFile(false);
567  }
568  // Now get the item from the correct file.
569  assert(rootFile_);
570  found = rootFile_->setEntryAtItem(run, lumi, event);
571  assert(found);
572  return true;
573  }
574  }
575  // Look for item in files not yet opened.
576  return skipToItemInNewFile(run, lumi, event);
577  }
578  return true;
579  }
580 
584  }
585 
589  }
590 
591  ProcessConfiguration const&
593  return input_.processConfiguration();
594  }
595 
596  int
598  return input_.remainingEvents();
599  }
600 
601  int
604  }
605 
608  return input_.productRegistryUpdate();
609  }
610 
611  boost::shared_ptr<ProductRegistry const>
613  return input_.productRegistry();
614  }
615 
616  void
617  RootInputFileSequence::dropUnwantedBranches_(std::vector<std::string> const& wantedBranches) {
618  std::vector<std::string> rules;
619  rules.reserve(wantedBranches.size() + 1);
620  rules.emplace_back("drop *");
621  for(std::string const& branch : wantedBranches) {
622  rules.push_back("keep " + branch + "_*");
623  }
624  ParameterSet pset;
625  pset.addUntrackedParameter("inputCommands", rules);
626  productSelectorRules_ = ProductSelectorRules(pset, "inputCommands", "InputSource");
627  }
628 
629  bool
631  skipBadFiles_ = false;
632  if(fileIter_ == fileIterEnd_ || !rootFile_) {
634  throw Exception(errors::Configuration) << "RootInputFileSequence::readOneSequential(): no input files specified for secondary input source.\n";
635  }
637  initFile(false);
638  assert(rootFile_);
639  rootFile_->setAtEventEntry(IndexIntoFile::invalidEntry);
640  }
641  assert(rootFile_);
642  rootFile_->nextEventEntry();
643  bool found = rootFile_->readCurrentEvent(cache);
644  if(!found) {
645  ++fileIter_;
646  if(fileIter_ == fileIterEnd_) {
647  return false;
648  }
649  initFile(false);
650  assert(rootFile_);
651  rootFile_->setAtEventEntry(IndexIntoFile::invalidEntry);
652  return readOneSequential(cache);
653  }
654  return true;
655  }
656 
657  bool
660  throw Exception(errors::Configuration) << "RootInputFileSequence::readOneSequentialWithID(): no input files specified for secondary input source.\n";
661  }
662  skipBadFiles_ = false;
663  if(fileIter_ == fileIterEnd_ || !rootFile_ ||
664  rootFile_->indexIntoFileIter().run() != id.run() ||
665  rootFile_->indexIntoFileIter().lumi() != id.luminosityBlock()) {
666  bool found = skipToItem(id.run(), id.luminosityBlock(), 0, false);
667  if(!found) {
668  return false;
669  }
670  }
671  assert(rootFile_);
672  bool found = rootFile_->setEntryAtNextEventInLumi(id.run(), id.luminosityBlock());
673  if(found) {
674  found = rootFile_->readCurrentEvent(cache);
675  }
676  if(!found) {
677  found = skipToItemInNewFile(id.run(), id.luminosityBlock(), 0);
678  if(!found) {
679  return false;
680  }
681  return readOneSequentialWithID(cache, id);
682  }
683  return true;
684  }
685 
686  void
689  throw Exception(errors::Configuration) << "RootInputFileSequence::readOneSpecified(): no input files specified for secondary input source.\n";
690  }
691  skipBadFiles_ = false;
692  bool found = skipToItem(id.run(), id.luminosityBlock(), id.event());
693  if(!found) {
694  throw Exception(errors::NotFound) <<
695  "RootInputFileSequence::readOneSpecified(): Secondary Input files" <<
696  " do not contain specified event:\n" << id << "\n";
697  }
698  assert(rootFile_);
699  found = rootFile_->readCurrentEvent(cache);
700  assert(found);
701  }
702 
703  void
704  RootInputFileSequence::readOneRandom(EventPrincipal& cache, CLHEP::HepRandomEngine* engine) {
706  throw Exception(errors::Configuration) << "RootInputFileSequence::readOneRandom(): no input files specified for secondary input source.\n";
707  }
708  assert(rootFile_);
709  skipBadFiles_ = false;
710  unsigned int currentSeqNumber = fileIter_ - fileIterBegin_;
711  while(eventsRemainingInFile_ == 0) {
712 
713  fileIter_ = fileIterBegin_ + CLHEP::RandFlat::shootInt(engine, fileCatalogItems().size());
714  unsigned int newSeqNumber = fileIter_ - fileIterBegin_;
715  if(newSeqNumber != currentSeqNumber) {
716  initFile(false);
717  currentSeqNumber = newSeqNumber;
718  }
719  eventsRemainingInFile_ = rootFile_->eventTree().entries();
720  if(eventsRemainingInFile_ == 0) {
721  throw Exception(errors::NotFound) <<
722  "RootInputFileSequence::readOneRandom(): Secondary Input file " << fileIter_->fileName() << " contains no events.\n";
723  }
724  rootFile_->setAtEventEntry(CLHEP::RandFlat::shootInt(engine, eventsRemainingInFile_) - 1);
725  }
726  rootFile_->nextEventEntry();
727 
728  bool found = rootFile_->readCurrentEvent(cache);
729  if(!found) {
730  rootFile_->setAtEventEntry(0);
731  bool found = rootFile_->readCurrentEvent(cache);
732  assert(found);
733  }
735  }
736 
737  // bool RootFile::setEntryAtNextEventInLumi(RunNumber_t run, LuminosityBlockNumber_t lumi) {
738 
739  bool
740  RootInputFileSequence::readOneRandomWithID(EventPrincipal& cache, LuminosityBlockID const& id, CLHEP::HepRandomEngine* engine) {
742  throw Exception(errors::Configuration) << "RootInputFileSequence::readOneRandomWithID(): no input files specified for secondary input source.\n";
743  }
744  skipBadFiles_ = false;
745  if(fileIter_ == fileIterEnd_ || !rootFile_ ||
746  rootFile_->indexIntoFileIter().run() != id.run() ||
747  rootFile_->indexIntoFileIter().lumi() != id.luminosityBlock()) {
748  bool found = skipToItem(id.run(), id.luminosityBlock(), 0);
749  if(!found) {
750  return false;
751  }
752  int eventsInLumi = 0;
753  assert(rootFile_);
754  while(rootFile_->setEntryAtNextEventInLumi(id.run(), id.luminosityBlock())) ++eventsInLumi;
755  found = skipToItem(id.run(), id.luminosityBlock(), 0);
756  assert(found);
757  int eventInLumi = CLHEP::RandFlat::shootInt(engine, eventsInLumi);
758  for(int i = 0; i < eventInLumi; ++i) {
759  bool found = rootFile_->setEntryAtNextEventInLumi(id.run(), id.luminosityBlock());
760  assert(found);
761  }
762  }
763  assert(rootFile_);
764  bool found = rootFile_->setEntryAtNextEventInLumi(id.run(), id.luminosityBlock());
765  if(found) {
766  found = rootFile_->readCurrentEvent(cache);
767  }
768  if(!found) {
769  bool found = rootFile_->setEntryAtItem(id.run(), id.luminosityBlock(), 0);
770  if(!found) {
771  return false;
772  }
773  return readOneRandomWithID(cache, id, engine);
774  }
775  return true;
776  }
777 
778  void
780  desc.addUntracked<unsigned int>("skipEvents", 0U)
781  ->setComment("Skip the first 'skipEvents' events that otherwise would have been processed.");
782  desc.addUntracked<bool>("noEventSort", true)
783  ->setComment("True: Process runs, lumis and events in the order they appear in the file (but see notes 1 and 2).\n"
784  "False: Process runs, lumis and events in each file in numerical order (run#, lumi#, event#) (but see note 3).\n"
785  "Note 1: Events within the same lumi will always be processed contiguously.\n"
786  "Note 2: Lumis within the same run will always be processed contiguously.\n"
787  "Note 3: Any sorting occurs independently in each input file (no sorting across input files).");
788  desc.addUntracked<bool>("skipBadFiles", false)
789  ->setComment("True: Ignore any missing or unopenable input file.\n"
790  "False: Throw exception if missing or unopenable input file.");
791  desc.addUntracked<unsigned int>("cacheSize", roottree::defaultCacheSize)
792  ->setComment("Size of ROOT TTree prefetch cache. Affects performance.");
793  desc.addUntracked<int>("treeMaxVirtualSize", -1)
794  ->setComment("Size of ROOT TTree TBasket cache. Affects performance.");
795  desc.addUntracked<unsigned int>("setRunNumber", 0U)
796  ->setComment("If non-zero, change number of first run to this number. Apply same offset to all runs. Allowed only for simulation.");
797  desc.addUntracked<bool>("dropDescendantsOfDroppedBranches", true)
798  ->setComment("If True, also drop on input any descendent of any branch dropped on input.");
799  std::string defaultString("permissive");
800  desc.addUntracked<std::string>("branchesMustMatch", defaultString)
801  ->setComment("'strict': Branches in each input file must match those in the first file.\n"
802  "'permissive': Branches in each input file may be any subset of those in the first file.");
803  desc.addUntracked<bool>("labelRawDataLikeMC", true)
804  ->setComment("If True: replace module label for raw data to match MC. Also use 'LHC' as process.");
805 
806  ProductSelectorRules::fillDescription(desc, "inputCommands");
809  }
810 
813  if(rootFile_) {
814  if(!rootFile_->wasLastEventJustRead()) {
816  }
817  std::vector<FileCatalogItem>::const_iterator itr(fileIter_);
818  if(itr != fileIterEnd_) ++itr;
819  if(itr != fileIterEnd_) {
821  }
823  }
825  }
826 
829  if(rootFile_) {
830  if(!rootFile_->wasFirstEventJustRead()) {
832  }
833  if(fileIter_ != fileIterBegin_) {
835  }
837  }
839  }
840 }
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
void readOneRandom(EventPrincipal &cache, CLHEP::HepRandomEngine *)
ProcessHistoryRegistry const & processHistoryRegistry() const
Const accessor for process history registry.
Definition: InputSource.h:171
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_
bool readOneRandomWithID(EventPrincipal &cache, LuminosityBlockID const &id, CLHEP::HepRandomEngine *)
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:253
static void fillDescription(ParameterSetDescription &desc)
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:43
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 ############.
static void reportFallbackAttempt(std::string const &pfn, std::string const &logicalFileName, std::string const &errorMessage)
Definition: InputFile.cc:79
int remainingEvents() const
Definition: InputSource.h:194
std::vector< FileCatalogItem >::const_iterator fileIterLastOpened_
boost::shared_ptr< BranchIDListHelper > branchIDListHelper() const
Accessor for branchIDListHelper.
Definition: InputSource.h:177
std::vector< FileCatalogItem > const & fileCatalogItems() const
bool isAvailable() const
Definition: Service.h:46
ProcessHistoryRegistry const & processHistoryRegistry() const
boost::shared_ptr< DuplicateChecker > duplicateChecker_
static void reportSkippedFile(std::string const &fileName, std::string const &logicalFileName)
Definition: InputFile.cc:73
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
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:347
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_()
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:174
std::vector< FileCatalogItem >::const_iterator fileIterBegin_
boost::shared_ptr< ProductRegistry const > productRegistry() const
Accessor for product registry.
Definition: InputSource.h:168
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:202
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:208
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_