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  std::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  std::string fallbackFullName = gSystem->ExpandPathName(fallbackName.c_str());
228  StorageFactory *factory = StorageFactory::get();
229  if (factory) {factory->activateTimeout(fallbackFullName);}
230  filePtr.reset(new InputFile(fallbackFullName.c_str(), " Fallback request to file ", inputType_));
231  }
232  catch (cms::Exception const& e) {
233  if(!skipBadFiles) {
234  InputFile::reportSkippedFile(fileIter_->fileName(), fileIter_->logicalFileName());
236  ex.addContext("Calling RootInputFileSequence::initFile()");
237  std::ostringstream out;
238  out << "Input file " << fileIter_->fileName() << " could not be opened.\n";
239  out << "Fallback Input file " << fallbackName << " also could not be opened.";
240  ex.addAdditionalInfo(out.str());
241  throw ex;
242  }
243  }
244  }
245  if(filePtr) {
246  std::vector<std::shared_ptr<IndexIntoFile> >::size_type currentIndexIntoFile = fileIter_ - fileIterBegin_;
248  fileIter_->fileName(),
250  fileIter_->logicalFileName(),
251  filePtr,
254  remainingEvents(),
256  nStreams_,
260  setRun_,
261  noEventSort_,
263  inputType_,
264  (inputType_ == InputType::SecondarySource ? std::make_shared<BranchIDListHelper>() : input_.branchIDListHelper()),
269  currentIndexIntoFile,
275 
276  assert(rootFile_);
278  indexesIntoFiles_[currentIndexIntoFile] = rootFile_->indexIntoFileSharedPtr();
279  char const* inputType = 0;
280  switch(inputType_) {
281  case InputType::Primary: inputType = "primaryFiles"; break;
282  case InputType::SecondaryFile: inputType = "secondaryFiles"; break;
283  case InputType::SecondarySource: inputType = "mixingFiles"; break;
284  }
285  rootFile_->reportOpened(inputType);
286  } else {
287  InputFile::reportSkippedFile(fileIter_->fileName(), fileIter_->logicalFileName());
288  if(!skipBadFiles) {
290  "RootInputFileSequence::initFile(): Input file " << fileIter_->fileName() << " was not found or could not be opened.\n";
291  }
292  LogWarning("") << "Input file: " << fileIter_->fileName() << " was not found or could not be opened, and will be skipped.\n";
293  }
294  }
295 
296  std::shared_ptr<ProductRegistry const>
298  assert(rootFile_);
299  return rootFile_->productRegistry();
300  }
301 
302  std::shared_ptr<BranchIDListHelper const>
304  assert(rootFile_);
305  return rootFile_->branchIDListHelper();
306  }
307 
310  if(fileIter_ == fileIterEnd_) {
312  return false;
313  } else {
315  }
316  }
317 
319 
321  // make sure the new product registry is compatible with the main one
322  std::string mergeInfo = productRegistryUpdate().merge(*rootFile_->productRegistry(),
323  fileIter_->fileName(),
325  if(!mergeInfo.empty()) {
326  throw Exception(errors::MismatchedInputFiles,"RootInputFileSequence::nextFile()") << mergeInfo;
327  }
328  }
329  return true;
330  }
331 
333  if(fileIter_ == fileIterBegin_) {
335  return false;
336  } else {
338  }
339  }
340  --fileIter_;
341 
342  initFile(false);
343 
345  // make sure the new product registry is compatible to the main one
346  std::string mergeInfo = productRegistryUpdate().merge(*rootFile_->productRegistry(),
347  fileIter_->fileName(),
349  if(!mergeInfo.empty()) {
350  throw Exception(errors::MismatchedInputFiles,"RootInputFileSequence::previousEvent()") << mergeInfo;
351  }
352  }
353  if(rootFile_) rootFile_->setToLastEntry();
354  return true;
355  }
356 
358  }
359 
360  std::shared_ptr<RunAuxiliary>
362  assert(rootFile_);
363  return rootFile_->readRunAuxiliary_();
364  }
365 
366  std::shared_ptr<LuminosityBlockAuxiliary>
368  assert(rootFile_);
369  return rootFile_->readLuminosityBlockAuxiliary_();
370  }
371 
372  void
374  assert(rootFile_);
375  rootFile_->readRun_(runPrincipal);
376  }
377 
378  void
380  assert(rootFile_);
381  rootFile_->readLuminosityBlock_(lumiPrincipal);
382  }
383 
384  // readEvent() is responsible for setting up the EventPrincipal.
385  //
386  // 1. fill an EventPrincipal with a unique EventID
387  // 2. For each entry in the provenance, put in one ProductHolder,
388  // holding the Provenance for the corresponding EDProduct.
389  // 3. set up the caches in the EventPrincipal to know about this
390  // ProductHolder.
391  //
392  // We do *not* create the EDProduct instance (the equivalent of reading
393  // the branch containing this EDProduct. That will be done by the Delayed Reader,
394  // when it is asked to do so.
395  //
396 
397  void
399  assert(rootFile_);
400  rootFile_->readEvent(eventPrincipal);
401  }
402 
405  if(fileIter_ == fileIterEnd_) {
406  return InputSource::IsStop;
407  }
408  if(firstFile_) {
409  return InputSource::IsFile;
410  }
411  if(rootFile_) {
412  IndexIntoFile::EntryType entryType = rootFile_->getNextItemType(run, lumi, event);
413  if(entryType == IndexIntoFile::kEvent) {
414  return InputSource::IsEvent;
415  } else if(entryType == IndexIntoFile::kLumi) {
416  return InputSource::IsLumi;
417  } else if(entryType == IndexIntoFile::kRun) {
418  return InputSource::IsRun;
419  }
420  assert(entryType == IndexIntoFile::kEnd);
421  }
422  if(fileIter_ + 1 == fileIterEnd_) {
423  return InputSource::IsStop;
424  }
425  return InputSource::IsFile;
426  }
427 
428  bool
430  if(!rootFile_) return false;
431  return rootFile_->containsItem(run, lumi, event);
432  }
433 
434  // Rewind to before the first event that was read.
435  void
437  if(fileIter_ != fileIterBegin_) {
438  closeFile_();
440  }
441  if(!rootFile_) {
442  initFile(false);
443  }
444  rewindFile();
445  firstFile_ = true;
446  if(rootFile_) {
449  }
450  }
451  }
452 
453  // Rewind to the beginning of the current file
454  void
456  if(rootFile_) rootFile_->rewind();
457  }
458 
459  // Advance "offset" events. Offset can be positive or negative (or zero).
460  bool
462  // We never call skipEvents for secondary input files. If we did,
463  // we would have to implement synchronization if a new file is opened.
464  // To avoid this, just assert.
466  assert(rootFile_);
467  while(offset != 0) {
468  bool atEnd = rootFile_->skipEvents(offset);
469  if((offset > 0 || atEnd) && !nextFile()) {
470  return false;
471  }
472  if(offset < 0 && !previousFile()) {
474  return false;
475  }
476  }
477  return true;
478  }
479 
480  bool
482  usingGoToEvent_ = true;
483  if(rootFile_) {
484  if(rootFile_->goToEvent(eventID)) {
485  return true;
486  }
487  // If only one input file, give up now, to save time.
488  if(rootFile_ && indexesIntoFiles_.size() == 1) {
489  return false;
490  }
491  // Save the current file and position so that we can restore them
492  // if we fail to restore the desired event
493  bool closedOriginalFile = false;
494  std::vector<FileCatalogItem>::const_iterator originalFile = fileIter_;
495  IndexIntoFile::IndexIntoFileItr originalPosition = rootFile_->indexIntoFileIter();
496 
497  // Look for item (run/lumi/event) in files previously opened without reopening unnecessary files.
498  typedef std::vector<std::shared_ptr<IndexIntoFile> >::const_iterator Iter;
499  for(Iter it = indexesIntoFiles_.begin(), itEnd = indexesIntoFiles_.end(); it != itEnd; ++it) {
500  if(*it && (*it)->containsItem(eventID.run(), eventID.luminosityBlock(), eventID.event())) {
501  // We found it. Close the currently open file, and open the correct one.
502  fileIter_ = fileIterBegin_ + (it - indexesIntoFiles_.begin());
503  initFile(false);
504  // Now get the item from the correct file.
505  assert(rootFile_);
506  bool found = rootFile_->goToEvent(eventID);
507  assert(found);
508  return true;
509  }
510  }
511  // Look for item in files not yet opened.
512  for(Iter it = indexesIntoFiles_.begin(), itEnd = indexesIntoFiles_.end(); it != itEnd; ++it) {
513  if(!*it) {
514  fileIter_ = fileIterBegin_ + (it - indexesIntoFiles_.begin());
515  initFile(false);
516  closedOriginalFile = true;
517  if((*it)->containsItem(eventID.run(), eventID.luminosityBlock(), eventID.event())) {
518  assert(rootFile_);
519  if(rootFile_->goToEvent(eventID)) {
520  return true;
521  }
522  }
523  }
524  }
525  if(closedOriginalFile) {
526  fileIter_ = originalFile;
527  initFile(false);
528  assert(rootFile_);
529  rootFile_->setPosition(originalPosition);
530  }
531  }
532  return false;
533  }
534 
535  bool
537  // Look for item in files not yet opened.
538  typedef std::vector<std::shared_ptr<IndexIntoFile> >::const_iterator Iter;
539  for(Iter it = indexesIntoFiles_.begin(), itEnd = indexesIntoFiles_.end(); it != itEnd; ++it) {
540  if(!*it) {
541  fileIter_ = fileIterBegin_ + (it - indexesIntoFiles_.begin());
542  initFile(false);
543  assert(rootFile_);
544  bool found = rootFile_->setEntryAtItem(run, lumi, event);
545  if(found) {
546  return true;
547  }
548  }
549  }
550  // Not found
551  return false;
552  }
553 
554  bool
556  // Attempt to find item in currently open input file.
557  bool found = currentFileFirst && rootFile_ && rootFile_->setEntryAtItem(run, lumi, event);
558  if(!found) {
559  // If only one input file, give up now, to save time.
560  if(currentFileFirst && rootFile_ && indexesIntoFiles_.size() == 1) {
561  return false;
562  }
563  // Look for item (run/lumi/event) in files previously opened without reopening unnecessary files.
564  typedef std::vector<std::shared_ptr<IndexIntoFile> >::const_iterator Iter;
565  for(Iter it = indexesIntoFiles_.begin(), itEnd = indexesIntoFiles_.end(); it != itEnd; ++it) {
566  if(*it && (*it)->containsItem(run, lumi, event)) {
567  // We found it. Close the currently open file, and open the correct one.
568  std::vector<FileCatalogItem>::const_iterator currentIter = fileIter_;
569  fileIter_ = fileIterBegin_ + (it - indexesIntoFiles_.begin());
570  if(fileIter_ != currentIter) {
571  initFile(false);
572  }
573  // Now get the item from the correct file.
574  assert(rootFile_);
575  found = rootFile_->setEntryAtItem(run, lumi, event);
576  assert(found);
577  return true;
578  }
579  }
580  // Look for item in files not yet opened.
581  return skipToItemInNewFile(run, lumi, event);
582  }
583  return true;
584  }
585 
589  }
590 
594  }
595 
596  ProcessConfiguration const&
598  return input_.processConfiguration();
599  }
600 
601  int
603  return input_.remainingEvents();
604  }
605 
606  int
609  }
610 
613  return input_.productRegistryUpdate();
614  }
615 
616  std::shared_ptr<ProductRegistry const>
618  return input_.productRegistry();
619  }
620 
621  void
622  RootInputFileSequence::dropUnwantedBranches_(std::vector<std::string> const& wantedBranches) {
623  std::vector<std::string> rules;
624  rules.reserve(wantedBranches.size() + 1);
625  rules.emplace_back("drop *");
626  for(std::string const& branch : wantedBranches) {
627  rules.push_back("keep " + branch + "_*");
628  }
629  ParameterSet pset;
630  pset.addUntrackedParameter("inputCommands", rules);
631  productSelectorRules_ = ProductSelectorRules(pset, "inputCommands", "InputSource");
632  }
633 
634  bool
636  skipBadFiles_ = false;
637  if(fileIter_ == fileIterEnd_ || !rootFile_) {
639  throw Exception(errors::Configuration) << "RootInputFileSequence::readOneSequential(): no input files specified for secondary input source.\n";
640  }
642  initFile(false);
643  assert(rootFile_);
644  rootFile_->setAtEventEntry(IndexIntoFile::invalidEntry);
645  }
646  assert(rootFile_);
647  rootFile_->nextEventEntry();
648  bool found = rootFile_->readCurrentEvent(cache);
649  if(!found) {
650  ++fileIter_;
651  if(fileIter_ == fileIterEnd_) {
652  return false;
653  }
654  initFile(false);
655  assert(rootFile_);
656  rootFile_->setAtEventEntry(IndexIntoFile::invalidEntry);
657  return readOneSequential(cache);
658  }
659  return true;
660  }
661 
662  bool
665  throw Exception(errors::Configuration) << "RootInputFileSequence::readOneSequentialWithID(): no input files specified for secondary input source.\n";
666  }
667  skipBadFiles_ = false;
668  if(fileIter_ == fileIterEnd_ || !rootFile_ ||
669  rootFile_->indexIntoFileIter().run() != id.run() ||
670  rootFile_->indexIntoFileIter().lumi() != id.luminosityBlock()) {
671  bool found = skipToItem(id.run(), id.luminosityBlock(), 0, false);
672  if(!found) {
673  return false;
674  }
675  }
676  assert(rootFile_);
677  bool found = rootFile_->setEntryAtNextEventInLumi(id.run(), id.luminosityBlock());
678  if(found) {
679  found = rootFile_->readCurrentEvent(cache);
680  }
681  if(!found) {
682  found = skipToItemInNewFile(id.run(), id.luminosityBlock(), 0);
683  if(!found) {
684  return false;
685  }
686  return readOneSequentialWithID(cache, id);
687  }
688  return true;
689  }
690 
691  void
694  throw Exception(errors::Configuration) << "RootInputFileSequence::readOneSpecified(): no input files specified for secondary input source.\n";
695  }
696  skipBadFiles_ = false;
697  bool found = skipToItem(id.run(), id.luminosityBlock(), id.event());
698  if(!found) {
699  throw Exception(errors::NotFound) <<
700  "RootInputFileSequence::readOneSpecified(): Secondary Input files" <<
701  " do not contain specified event:\n" << id << "\n";
702  }
703  assert(rootFile_);
704  found = rootFile_->readCurrentEvent(cache);
705  assert(found);
706  }
707 
708  void
709  RootInputFileSequence::readOneRandom(EventPrincipal& cache, CLHEP::HepRandomEngine* engine) {
711  throw Exception(errors::Configuration) << "RootInputFileSequence::readOneRandom(): no input files specified for secondary input source.\n";
712  }
713  assert(rootFile_);
714  skipBadFiles_ = false;
715  unsigned int currentSeqNumber = fileIter_ - fileIterBegin_;
716  while(eventsRemainingInFile_ == 0) {
717 
718  fileIter_ = fileIterBegin_ + CLHEP::RandFlat::shootInt(engine, fileCatalogItems().size());
719  unsigned int newSeqNumber = fileIter_ - fileIterBegin_;
720  if(newSeqNumber != currentSeqNumber) {
721  initFile(false);
722  currentSeqNumber = newSeqNumber;
723  }
724  eventsRemainingInFile_ = rootFile_->eventTree().entries();
725  if(eventsRemainingInFile_ == 0) {
726  throw Exception(errors::NotFound) <<
727  "RootInputFileSequence::readOneRandom(): Secondary Input file " << fileIter_->fileName() << " contains no events.\n";
728  }
729  rootFile_->setAtEventEntry(CLHEP::RandFlat::shootInt(engine, eventsRemainingInFile_) - 1);
730  }
731  rootFile_->nextEventEntry();
732 
733  bool found = rootFile_->readCurrentEvent(cache);
734  if(!found) {
735  rootFile_->setAtEventEntry(0);
736  bool found = rootFile_->readCurrentEvent(cache);
737  assert(found);
738  }
740  }
741 
742  // bool RootFile::setEntryAtNextEventInLumi(RunNumber_t run, LuminosityBlockNumber_t lumi) {
743 
744  bool
745  RootInputFileSequence::readOneRandomWithID(EventPrincipal& cache, LuminosityBlockID const& id, CLHEP::HepRandomEngine* engine) {
747  throw Exception(errors::Configuration) << "RootInputFileSequence::readOneRandomWithID(): no input files specified for secondary input source.\n";
748  }
749  skipBadFiles_ = false;
750  if(fileIter_ == fileIterEnd_ || !rootFile_ ||
751  rootFile_->indexIntoFileIter().run() != id.run() ||
752  rootFile_->indexIntoFileIter().lumi() != id.luminosityBlock()) {
753  bool found = skipToItem(id.run(), id.luminosityBlock(), 0);
754  if(!found) {
755  return false;
756  }
757  int eventsInLumi = 0;
758  assert(rootFile_);
759  while(rootFile_->setEntryAtNextEventInLumi(id.run(), id.luminosityBlock())) ++eventsInLumi;
760  found = skipToItem(id.run(), id.luminosityBlock(), 0);
761  assert(found);
762  int eventInLumi = CLHEP::RandFlat::shootInt(engine, eventsInLumi);
763  for(int i = 0; i < eventInLumi; ++i) {
764  bool found = rootFile_->setEntryAtNextEventInLumi(id.run(), id.luminosityBlock());
765  assert(found);
766  }
767  }
768  assert(rootFile_);
769  bool found = rootFile_->setEntryAtNextEventInLumi(id.run(), id.luminosityBlock());
770  if(found) {
771  found = rootFile_->readCurrentEvent(cache);
772  }
773  if(!found) {
774  bool found = rootFile_->setEntryAtItem(id.run(), id.luminosityBlock(), 0);
775  if(!found) {
776  return false;
777  }
778  return readOneRandomWithID(cache, id, engine);
779  }
780  return true;
781  }
782 
783  void
785  desc.addUntracked<unsigned int>("skipEvents", 0U)
786  ->setComment("Skip the first 'skipEvents' events that otherwise would have been processed.");
787  desc.addUntracked<bool>("noEventSort", true)
788  ->setComment("True: Process runs, lumis and events in the order they appear in the file (but see notes 1 and 2).\n"
789  "False: Process runs, lumis and events in each file in numerical order (run#, lumi#, event#) (but see note 3).\n"
790  "Note 1: Events within the same lumi will always be processed contiguously.\n"
791  "Note 2: Lumis within the same run will always be processed contiguously.\n"
792  "Note 3: Any sorting occurs independently in each input file (no sorting across input files).");
793  desc.addUntracked<bool>("skipBadFiles", false)
794  ->setComment("True: Ignore any missing or unopenable input file.\n"
795  "False: Throw exception if missing or unopenable input file.");
796  desc.addUntracked<bool>("bypassVersionCheck", false)
797  ->setComment("True: Bypass release version check.\n"
798  "False: Throw exception if reading file in a release prior to the release in which the file was written.");
799  desc.addUntracked<unsigned int>("cacheSize", roottree::defaultCacheSize)
800  ->setComment("Size of ROOT TTree prefetch cache. Affects performance.");
801  desc.addUntracked<int>("treeMaxVirtualSize", -1)
802  ->setComment("Size of ROOT TTree TBasket cache. Affects performance.");
803  desc.addUntracked<unsigned int>("setRunNumber", 0U)
804  ->setComment("If non-zero, change number of first run to this number. Apply same offset to all runs. Allowed only for simulation.");
805  desc.addUntracked<bool>("dropDescendantsOfDroppedBranches", true)
806  ->setComment("If True, also drop on input any descendent of any branch dropped on input.");
807  std::string defaultString("permissive");
808  desc.addUntracked<std::string>("branchesMustMatch", defaultString)
809  ->setComment("'strict': Branches in each input file must match those in the first file.\n"
810  "'permissive': Branches in each input file may be any subset of those in the first file.");
811  desc.addUntracked<bool>("labelRawDataLikeMC", true)
812  ->setComment("If True: replace module label for raw data to match MC. Also use 'LHC' as process.");
813 
814  ProductSelectorRules::fillDescription(desc, "inputCommands");
817  }
818 
821  if(rootFile_) {
822  if(!rootFile_->wasLastEventJustRead()) {
824  }
825  std::vector<FileCatalogItem>::const_iterator itr(fileIter_);
826  if(itr != fileIterEnd_) ++itr;
827  if(itr != fileIterEnd_) {
829  }
831  }
833  }
834 
837  if(rootFile_) {
838  if(!rootFile_->wasFirstEventJustRead()) {
840  }
841  if(fileIter_ != fileIterBegin_) {
843  }
845  }
847  }
848 }
RunNumber_t run() const
Definition: EventID.h:39
void readOneSpecified(EventPrincipal &cache, EventID const &id)
ProcessingController::ForwardState forwardState() const
EventNumber_t event() const
Definition: EventID.h:41
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
int i
Definition: DBlmapReader.cc:9
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)
ProcessConfiguration const & processConfiguration() const
unsigned int EventNumber_t
Definition: EventRange.h:30
virtual std::string explainSelf() const
Definition: Exception.cc:146
std::vector< FileCatalogItem >::const_iterator fileIter_
tuple lumi
Definition: fjr2json.py:35
std::shared_ptr< EventSkipperByID > eventSkipperByID_
ProductRegistry & productRegistryUpdate() const
std::shared_ptr< BranchIDListHelper const > fileBranchIDListHelper() const
ProcessingMode processingMode() const
RunsLumisAndEvents (default), RunsAndLumis, or Runs.
Definition: InputSource.h:253
static void fillDescription(ParameterSetDescription &desc)
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:40
unsigned int const defaultCacheSize
Definition: RootTree.h:37
uint16_t size_type
unsigned int LuminosityBlockNumber_t
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)
std::shared_ptr< RootFile > RootFileSharedPtr
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::shared_ptr< DuplicateChecker > duplicateChecker_
std::vector< FileCatalogItem >::const_iterator fileIterLastOpened_
std::vector< FileCatalogItem > const & fileCatalogItems() const
std::shared_ptr< BranchIDListHelper > branchIDListHelper() const
Accessor for branchIDListHelper.
Definition: InputSource.h:177
bool isAvailable() const
Definition: Service.h:46
ProcessHistoryRegistry const & processHistoryRegistry() const
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)
std::vector< std::shared_ptr< IndexIntoFile > > indexesIntoFiles_
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_()
std::shared_ptr< RunAuxiliary > readRunAuxiliary_()
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_
tuple skipBadFiles
Definition: example_cfg.py:64
static void fillDescription(ParameterSetDescription &desc)
#define begin
Definition: vmac.h:30
std::shared_ptr< LuminosityBlockAuxiliary > readLuminosityBlockAuxiliary_()
std::shared_ptr< ProductRegistry const > productRegistry() const
Accessor for product registry.
Definition: InputSource.h:168
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
std::shared_ptr< ProductRegistry const > fileProductRegistry() const
ProcessingController::ReverseState reverseState() const
SurfaceDeformation * create(int type, const std::vector< double > &params)
tuple size
Write out results.
std::shared_ptr< ProductRegistry const > productRegistry() const
std::vector< FileCatalogItem > const & fileCatalogItems() const
InputFileCatalog const & catalog_