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