CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RootInputFileSequence.cc
Go to the documentation of this file.
1 /*----------------------------------------------------------------------
2 ----------------------------------------------------------------------*/
3 #include "DuplicateChecker.h"
4 #include "PoolSource.h"
5 #include "RootFile.h"
7 #include "RootTree.h"
8 
22 
23 #include "CLHEP/Random/RandFlat.h"
24 #include "InputFile.h"
25 #include "TSystem.h"
26 
27 namespace edm {
29  ParameterSet const& pset,
32  unsigned int nStreams,
33  InputType inputType) :
34  input_(input),
35  inputType_(inputType),
36  catalog_(catalog),
37  firstFile_(true),
38  lfn_("unknown"),
39  lfnHash_(0U),
40  findFileForSpecifiedID_(nullptr),
41  fileIterBegin_(fileCatalogItems().begin()),
42  fileIterEnd_(fileCatalogItems().end()),
43  fileIter_(fileIterEnd_),
44  fileIterLastOpened_(fileIterEnd_),
45  rootFile_(),
46  branchesMustMatch_(BranchDescription::Permissive),
47  indexesIntoFiles_(fileCatalogItems().size()),
48  orderedProcessHistoryIDs_(),
49  nStreams_(nStreams),
50  eventSkipperByID_(inputType == InputType::Primary ? EventSkipperByID::create(pset).release() : 0),
51  eventsRemainingInFile_(0),
52  // The default value provided as the second argument to the getUntrackedParameter function call
53  // is not used when the ParameterSet has been validated and the parameters are not optional
54  // in the description. This is currently true when PoolSource is the primary input source.
55  // The modules that use PoolSource as a SecSource have not defined their fillDescriptions function
56  // yet, so the ParameterSet does not get validated yet. As soon as all the modules with a SecSource
57  // have defined descriptions, the defaults in the getUntrackedParameterSet function calls can
58  // and should be deleted from the code.
59  initialNumberOfEventsToSkip_(inputType == InputType::Primary ? pset.getUntrackedParameter<unsigned int>("skipEvents", 0U) : 0U),
60  noEventSort_(inputType == InputType::Primary ? pset.getUntrackedParameter<bool>("noEventSort", true) : false),
61  skipBadFiles_(pset.getUntrackedParameter<bool>("skipBadFiles", false)),
62  bypassVersionCheck_(pset.getUntrackedParameter<bool>("bypassVersionCheck", false)),
63  treeCacheSize_(noEventSort_ ? pset.getUntrackedParameter<unsigned int>("cacheSize", roottree::defaultCacheSize) : 0U),
64  treeMaxVirtualSize_(pset.getUntrackedParameter<int>("treeMaxVirtualSize", -1)),
65  setRun_(pset.getUntrackedParameter<unsigned int>("setRunNumber", 0U)),
66  productSelectorRules_(pset, "inputCommands", "InputSource"),
67  duplicateChecker_(inputType == InputType::Primary ? new DuplicateChecker(pset) : 0),
68  dropDescendants_(pset.getUntrackedParameter<bool>("dropDescendantsOfDroppedBranches", inputType != InputType::SecondarySource)),
69  labelRawDataLikeMC_(pset.getUntrackedParameter<bool>("labelRawDataLikeMC", true)),
70  usingGoToEvent_(false),
71  enablePrefetching_(false),
72  usedFallback_(false) {
73 
74  // The SiteLocalConfig controls the TTreeCache size and the prefetching settings.
76  if(pSLC.isAvailable()) {
77  if(treeCacheSize_ != 0U && pSLC->sourceTTreeCacheSize()) {
78  treeCacheSize_ = *(pSLC->sourceTTreeCacheSize());
79  }
80  enablePrefetching_ = pSLC->enablePrefetching();
81  }
82 
85  factory->activateTimeout(fileIter_->fileName());
86  factory->stagein(fileIter_->fileName());
87  //NOTE: we do not want to stage in all secondary files since we can be given a list of
88  // thousands of files and prestaging all those files can cause a site to fail.
89  // So, we stage in the first secondary file only.
91  break;
92  }
93  }
94 
95  std::string branchesMustMatch = pset.getUntrackedParameter<std::string>("branchesMustMatch", std::string("permissive"));
96  if(branchesMustMatch == std::string("strict")) branchesMustMatch_ = BranchDescription::Strict;
97 
100  if(rootFile_) break;
101  }
102  if(rootFile_) {
103  productRegistryUpdate().updateFromInput(rootFile_->productRegistry()->productList());
106  }
107  }
108  }
109 
110  std::vector<FileCatalogItem> const&
112  return catalog_.fileCatalogItems();
113  }
114 
115  void
117  closeFile_();
118  }
119 
120  std::unique_ptr<FileBlock>
122  if(firstFile_) {
123  // The first input file has already been opened.
124  firstFile_ = false;
125  if(!rootFile_) {
127  }
128  } else {
129  if(!nextFile()) {
130  assert(0);
131  }
132  }
133  if(!rootFile_) {
134  return std::unique_ptr<FileBlock>(new FileBlock);
135  }
136  return rootFile_->createFileBlock();
137  }
138 
140  // close the currently open file, if any, and delete the RootFile object.
141  if(rootFile_) {
143  std::unique_ptr<InputSource::FileCloseSentry>
145  rootFile_->close();
146  if(duplicateChecker_) duplicateChecker_->inputFileClosed();
147  }
148  rootFile_.reset();
149  }
150  }
151 
153  // We are really going to close the open file.
154 
155  // If this is the primary sequence, we are not duplicate checking across files
156  // and we are not using random access to find events, then we can delete the
157  // IndexIntoFile for the file we are closing. If we can't delete all of it,
158  // then we can delete the parts we do not need.
160  size_t currentIndexIntoFile = fileIterLastOpened_ - fileIterBegin_;
161  bool needIndexesForDuplicateChecker = duplicateChecker_ && duplicateChecker_->checkingAllFiles() && !duplicateChecker_->checkDisabled();
162  bool deleteIndexIntoFile = inputType_ == InputType::Primary &&
163  !needIndexesForDuplicateChecker &&
165  if(deleteIndexIntoFile) {
166  indexesIntoFiles_[currentIndexIntoFile].reset();
167  } else {
168  if(indexesIntoFiles_[currentIndexIntoFile]) indexesIntoFiles_[currentIndexIntoFile]->inputFileClosed();
169  }
171  }
172  closeFile_();
173 
174  if(fileIter_ == fileIterEnd_) {
175  // No files specified
176  return;
177  }
178 
179  // Check if the logical file name was found.
180  if(fileIter_->fileName().empty()) {
181  // LFN not found in catalog.
182  InputFile::reportSkippedFile(fileIter_->fileName(), fileIter_->logicalFileName());
183  if(!skipBadFiles) {
184  throw cms::Exception("LogicalFileNameNotFound", "RootInputFileSequence::initFile()\n")
185  << "Logical file name '" << fileIter_->logicalFileName() << "' was not found in the file catalog.\n"
186  << "If you wanted a local file, you forgot the 'file:' prefix\n"
187  << "before the file name in your configuration file.\n";
188  }
189  LogWarning("") << "Input logical file: " << fileIter_->logicalFileName() << " was not found in the catalog, and will be skipped.\n";
190  return;
191  }
192 
193  lfn_ = fileIter_->logicalFileName().empty() ? fileIter_->fileName() : fileIter_->logicalFileName();
194  lfnHash_ = std::hash<std::string>()(lfn_);
195  usedFallback_ = false;
196 
197  // Determine whether we have a fallback URL specified; if so, prepare it;
198  // Only valid if it is non-empty and differs from the original filename.
199  std::string fallbackName = fileIter_->fallbackFileName();
200  bool hasFallbackUrl = !fallbackName.empty() && fallbackName != fileIter_->fileName();
201 
202  std::shared_ptr<InputFile> filePtr;
203  std::list<std::string> originalInfo;
204  try {
205  std::unique_ptr<InputSource::FileOpenSentry>
207  filePtr.reset(new InputFile(gSystem->ExpandPathName(fileIter_->fileName().c_str()), " Initiating request to open file ", inputType_));
208  }
209  catch (cms::Exception const& e) {
210  if(!skipBadFiles) {
211  if(hasFallbackUrl) {
212  std::ostringstream out;
213  out << e.explainSelf();
214  std::string pfn(gSystem->ExpandPathName(fallbackName.c_str()));
215  InputFile::reportFallbackAttempt(pfn, fileIter_->logicalFileName(), out.str());
216  originalInfo = e.additionalInfo();
217  } else {
218  InputFile::reportSkippedFile(fileIter_->fileName(), fileIter_->logicalFileName());
219  Exception ex(errors::FileOpenError, "", e);
220  ex.addContext("Calling RootInputFileSequence::initFile()");
221  std::ostringstream out;
222  out << "Input file " << fileIter_->fileName() << " could not be opened.";
223  ex.addAdditionalInfo(out.str());
224  throw ex;
225  }
226  }
227  }
228  if(!filePtr && (hasFallbackUrl)) {
229  try {
230  usedFallback_ = true;
231  std::unique_ptr<InputSource::FileOpenSentry>
233  std::string fallbackFullName = gSystem->ExpandPathName(fallbackName.c_str());
234  StorageFactory *factory = StorageFactory::get();
235  if (factory) {factory->activateTimeout(fallbackFullName);}
236  filePtr.reset(new InputFile(fallbackFullName.c_str(), " Fallback request to file ", inputType_));
237  }
238  catch (cms::Exception const& e) {
239  if(!skipBadFiles) {
240  InputFile::reportSkippedFile(fileIter_->fileName(), fileIter_->logicalFileName());
242  ex.addContext("Calling RootInputFileSequence::initFile()");
243  std::ostringstream out;
244  out << "Input file " << fileIter_->fileName() << " could not be opened.\n";
245  out << "Fallback Input file " << fallbackName << " also could not be opened.";
246  if (originalInfo.size()) {
247  out << std::endl << "Original exception info is above; fallback exception info is below.";
248  ex.addAdditionalInfo(out.str());
249  for (auto const & s : originalInfo) {
250  ex.addAdditionalInfo(s);
251  }
252  } else {
253  ex.addAdditionalInfo(out.str());
254  }
255  throw ex;
256  }
257  }
258  }
259  if(filePtr) {
260  std::vector<std::shared_ptr<IndexIntoFile> >::size_type currentIndexIntoFile = fileIter_ - fileIterBegin_;
262  fileIter_->fileName(),
264  fileIter_->logicalFileName(),
265  filePtr,
268  remainingEvents(),
270  nStreams_,
274  setRun_,
275  noEventSort_,
277  inputType_,
278  (inputType_ == InputType::SecondarySource ? std::make_shared<BranchIDListHelper>() : input_.branchIDListHelper()),
279  (inputType_ == InputType::SecondarySource ? std::shared_ptr<ThinnedAssociationsHelper>() : input_.thinnedAssociationsHelper()),
285  currentIndexIntoFile,
291 
292  assert(rootFile_);
294  indexesIntoFiles_[currentIndexIntoFile] = rootFile_->indexIntoFileSharedPtr();
295  char const* inputType = 0;
296  switch(inputType_) {
297  case InputType::Primary: inputType = "primaryFiles"; break;
298  case InputType::SecondaryFile: inputType = "secondaryFiles"; break;
299  case InputType::SecondarySource: inputType = "mixingFiles"; break;
300  }
301  rootFile_->reportOpened(inputType);
302  } else {
303  InputFile::reportSkippedFile(fileIter_->fileName(), fileIter_->logicalFileName());
304  if(!skipBadFiles) {
306  "RootInputFileSequence::initFile(): Input file " << fileIter_->fileName() << " was not found or could not be opened.\n";
307  }
308  LogWarning("") << "Input file: " << fileIter_->fileName() << " was not found or could not be opened, and will be skipped.\n";
309  }
310  }
311 
312  std::shared_ptr<ProductRegistry const>
314  assert(rootFile_);
315  return rootFile_->productRegistry();
316  }
317 
318  std::shared_ptr<BranchIDListHelper const>
320  assert(rootFile_);
321  return rootFile_->branchIDListHelper();
322  }
323 
326  if(fileIter_ == fileIterEnd_) {
328  return false;
329  } else {
331  }
332  }
333 
335 
337  // make sure the new product registry is compatible with the main one
338  std::string mergeInfo = productRegistryUpdate().merge(*rootFile_->productRegistry(),
339  fileIter_->fileName(),
341  if(!mergeInfo.empty()) {
342  throw Exception(errors::MismatchedInputFiles,"RootInputFileSequence::nextFile()") << mergeInfo;
343  }
344  }
345  return true;
346  }
347 
349  if(fileIter_ == fileIterBegin_) {
351  return false;
352  } else {
354  }
355  }
356  --fileIter_;
357 
358  initFile(false);
359 
361  // make sure the new product registry is compatible to the main one
362  std::string mergeInfo = productRegistryUpdate().merge(*rootFile_->productRegistry(),
363  fileIter_->fileName(),
365  if(!mergeInfo.empty()) {
366  throw Exception(errors::MismatchedInputFiles,"RootInputFileSequence::previousEvent()") << mergeInfo;
367  }
368  }
369  if(rootFile_) rootFile_->setToLastEntry();
370  return true;
371  }
372 
374  }
375 
376  std::shared_ptr<RunAuxiliary>
378  assert(rootFile_);
379  return rootFile_->readRunAuxiliary_();
380  }
381 
382  std::shared_ptr<LuminosityBlockAuxiliary>
384  assert(rootFile_);
385  return rootFile_->readLuminosityBlockAuxiliary_();
386  }
387 
388  void
390  assert(rootFile_);
391  rootFile_->readRun_(runPrincipal);
392  }
393 
394  void
396  assert(rootFile_);
397  rootFile_->readLuminosityBlock_(lumiPrincipal);
398  }
399 
400  // readEvent() is responsible for setting up the EventPrincipal.
401  //
402  // 1. fill an EventPrincipal with a unique EventID
403  // 2. For each entry in the provenance, put in one ProductHolder,
404  // holding the Provenance for the corresponding EDProduct.
405  // 3. set up the caches in the EventPrincipal to know about this
406  // ProductHolder.
407  //
408  // We do *not* create the EDProduct instance (the equivalent of reading
409  // the branch containing this EDProduct. That will be done by the Delayed Reader,
410  // when it is asked to do so.
411  //
412 
413  void
415  assert(rootFile_);
416  rootFile_->readEvent(eventPrincipal);
417  }
418 
421  if(fileIter_ == fileIterEnd_) {
422  return InputSource::IsStop;
423  }
424  if(firstFile_) {
425  return InputSource::IsFile;
426  }
427  if(rootFile_) {
428  IndexIntoFile::EntryType entryType = rootFile_->getNextItemType(run, lumi, event);
429  if(entryType == IndexIntoFile::kEvent) {
430  return InputSource::IsEvent;
431  } else if(entryType == IndexIntoFile::kLumi) {
432  return InputSource::IsLumi;
433  } else if(entryType == IndexIntoFile::kRun) {
434  return InputSource::IsRun;
435  }
436  assert(entryType == IndexIntoFile::kEnd);
437  }
438  if(fileIter_ + 1 == fileIterEnd_) {
439  return InputSource::IsStop;
440  }
441  return InputSource::IsFile;
442  }
443 
444  bool
446  if(!rootFile_) return false;
447  return rootFile_->containsItem(run, lumi, event);
448  }
449 
450  // Rewind to before the first event that was read.
451  void
453  if(fileIter_ != fileIterBegin_) {
454  closeFile_();
456  }
457  if(!rootFile_) {
458  initFile(false);
459  }
460  rewindFile();
461  firstFile_ = true;
462  if(rootFile_) {
465  }
466  }
467  }
468 
469  // Rewind to the beginning of the current file
470  void
472  if(rootFile_) rootFile_->rewind();
473  }
474 
475  // Advance "offset" events. Offset can be positive or negative (or zero).
476  bool
478  // We never call skipEvents for secondary input files. If we did,
479  // we would have to implement synchronization if a new file is opened.
480  // To avoid this, just assert.
482  assert(rootFile_);
483  while(offset != 0) {
484  bool atEnd = rootFile_->skipEvents(offset);
485  if((offset > 0 || atEnd) && !nextFile()) {
486  return false;
487  }
488  if(offset < 0 && !previousFile()) {
490  return false;
491  }
492  }
493  return true;
494  }
495 
496  bool
498  usingGoToEvent_ = true;
499  if(rootFile_) {
500  if(rootFile_->goToEvent(eventID)) {
501  return true;
502  }
503  // If only one input file, give up now, to save time.
504  if(rootFile_ && indexesIntoFiles_.size() == 1) {
505  return false;
506  }
507  // Save the current file and position so that we can restore them
508  // if we fail to restore the desired event
509  bool closedOriginalFile = false;
510  std::vector<FileCatalogItem>::const_iterator originalFile = fileIter_;
511  IndexIntoFile::IndexIntoFileItr originalPosition = rootFile_->indexIntoFileIter();
512 
513  // Look for item (run/lumi/event) in files previously opened without reopening unnecessary files.
514  typedef std::vector<std::shared_ptr<IndexIntoFile> >::const_iterator Iter;
515  for(Iter it = indexesIntoFiles_.begin(), itEnd = indexesIntoFiles_.end(); it != itEnd; ++it) {
516  if(*it && (*it)->containsItem(eventID.run(), eventID.luminosityBlock(), eventID.event())) {
517  // We found it. Close the currently open file, and open the correct one.
518  fileIter_ = fileIterBegin_ + (it - indexesIntoFiles_.begin());
519  initFile(false);
520  // Now get the item from the correct file.
521  assert(rootFile_);
522  bool found = rootFile_->goToEvent(eventID);
523  assert(found);
524  return true;
525  }
526  }
527  // Look for item in files not yet opened.
528  for(Iter it = indexesIntoFiles_.begin(), itEnd = indexesIntoFiles_.end(); it != itEnd; ++it) {
529  if(!*it) {
530  fileIter_ = fileIterBegin_ + (it - indexesIntoFiles_.begin());
531  initFile(false);
532  closedOriginalFile = true;
533  if((*it)->containsItem(eventID.run(), eventID.luminosityBlock(), eventID.event())) {
534  assert(rootFile_);
535  if(rootFile_->goToEvent(eventID)) {
536  return true;
537  }
538  }
539  }
540  }
541  if(closedOriginalFile) {
542  fileIter_ = originalFile;
543  initFile(false);
544  assert(rootFile_);
545  rootFile_->setPosition(originalPosition);
546  }
547  }
548  return false;
549  }
550 
551  bool
553  // Look for item in files not yet opened. We have a hash of the logical file name
554  assert(fileNameHash != 0U);
555  // If the lookup table is not yet filled in, fill it.
557  // We use a multimap because there may be hash collisions (Two different LFNs could have the same hash).
558  // We map the hash of the LFN to the index into the list of files.
559  findFileForSpecifiedID_.reset(new std::unordered_multimap<size_t, size_t>);
560  auto hasher = std::hash<std::string>();
561  for(auto fileIter = fileIterBegin_; fileIter != fileIterEnd_; ++fileIter) {
562  findFileForSpecifiedID_->insert(std::make_pair(hasher(fileIter->logicalFileName()), fileIter - fileIterBegin_));
563  }
564  }
565  // Look up the logical file name in the table
566  auto range = findFileForSpecifiedID_->equal_range(fileNameHash);
567  for(auto iter = range.first; iter != range.second; ++iter) {
568  // Don't look in files previously opened, because those have already been searched.
569  if(!indexesIntoFiles_[iter->second]) {
570  fileIter_ = fileIterBegin_ + iter->second;
571  initFile(false);
572  assert(rootFile_);
573  bool found = rootFile_->setEntryAtItem(run, lumi, event);
574  if(found) {
575  return true;
576  }
577  }
578  }
579  // Not found
580  return false;
581  }
582 
583  bool
585  // Look for item in files not yet opened. We do not have a valid hash of the logical file name.
586  typedef std::vector<std::shared_ptr<IndexIntoFile> >::const_iterator Iter;
587  for(Iter it = indexesIntoFiles_.begin(), itEnd = indexesIntoFiles_.end(); it != itEnd; ++it) {
588  if(!*it) {
589  // File not yet opened.
590  fileIter_ = fileIterBegin_ + (it - indexesIntoFiles_.begin());
591  initFile(false);
592  assert(rootFile_);
593  bool found = rootFile_->setEntryAtItem(run, lumi, event);
594  if(found) {
595  return true;
596  }
597  }
598  }
599  // Not found
600  return false;
601  }
602 
603  bool
605  // Attempt to find item in currently open input file.
606  bool found = currentFileFirst && rootFile_ && rootFile_->setEntryAtItem(run, lumi, event);
607  if(!found) {
608  // If only one input file, give up now, to save time.
609  if(currentFileFirst && rootFile_ && indexesIntoFiles_.size() == 1) {
610  return false;
611  }
612  // Look for item (run/lumi/event) in files previously opened without reopening unnecessary files.
613  typedef std::vector<std::shared_ptr<IndexIntoFile> >::const_iterator Iter;
614  for(Iter it = indexesIntoFiles_.begin(), itEnd = indexesIntoFiles_.end(); it != itEnd; ++it) {
615  if(*it && (*it)->containsItem(run, lumi, event)) {
616  // We found it. Close the currently open file, and open the correct one.
617  std::vector<FileCatalogItem>::const_iterator currentIter = fileIter_;
618  fileIter_ = fileIterBegin_ + (it - indexesIntoFiles_.begin());
619  if(fileIter_ != currentIter) {
620  initFile(false);
621  }
622  // Now get the item from the correct file.
623  assert(rootFile_);
624  found = rootFile_->setEntryAtItem(run, lumi, event);
625  assert(found);
626  return true;
627  }
628  }
629  return (fileNameHash != 0U && skipToItemInNewFile(run, lumi, event, fileNameHash)) || skipToItemInNewFile(run, lumi, event);
630  }
631  return true;
632  }
633 
637  }
638 
642  }
643 
644  ProcessConfiguration const&
646  return input_.processConfiguration();
647  }
648 
649  int
651  return input_.remainingEvents();
652  }
653 
654  int
657  }
658 
661  return input_.productRegistryUpdate();
662  }
663 
664  std::shared_ptr<ProductRegistry const>
666  return input_.productRegistry();
667  }
668 
669  void
670  RootInputFileSequence::dropUnwantedBranches_(std::vector<std::string> const& wantedBranches) {
671  std::vector<std::string> rules;
672  rules.reserve(wantedBranches.size() + 1);
673  rules.emplace_back("drop *");
674  for(std::string const& branch : wantedBranches) {
675  rules.push_back("keep " + branch + "_*");
676  }
677  ParameterSet pset;
678  pset.addUntrackedParameter("inputCommands", rules);
679  productSelectorRules_ = ProductSelectorRules(pset, "inputCommands", "InputSource");
680  }
681 
682  bool
684  skipBadFiles_ = false;
685  if(fileIter_ == fileIterEnd_ || !rootFile_) {
687  throw Exception(errors::Configuration) << "RootInputFileSequence::readOneSequential(): no input files specified for secondary input source.\n";
688  }
690  initFile(false);
691  assert(rootFile_);
692  rootFile_->setAtEventEntry(IndexIntoFile::invalidEntry);
693  }
694  assert(rootFile_);
695  rootFile_->nextEventEntry();
696  bool found = rootFile_->readCurrentEvent(cache);
697  if(!found) {
698  ++fileIter_;
699  if(fileIter_ == fileIterEnd_) {
700  return false;
701  }
702  initFile(false);
703  assert(rootFile_);
704  rootFile_->setAtEventEntry(IndexIntoFile::invalidEntry);
705  return readOneSequential(cache, fileNameHash);
706  }
707  fileNameHash = lfnHash_;
708  return true;
709  }
710 
711  bool
714  throw Exception(errors::Configuration) << "RootInputFileSequence::readOneSequentialWithID(): no input files specified for secondary input source.\n";
715  }
716  skipBadFiles_ = false;
717  if(fileIter_ == fileIterEnd_ || !rootFile_ ||
718  rootFile_->indexIntoFileIter().run() != id.run() ||
719  rootFile_->indexIntoFileIter().lumi() != id.luminosityBlock()) {
720  bool found = skipToItem(id.run(), id.luminosityBlock(), 0, 0, false);
721  if(!found) {
722  return false;
723  }
724  }
725  assert(rootFile_);
726  bool found = rootFile_->setEntryAtNextEventInLumi(id.run(), id.luminosityBlock());
727  if(found) {
728  found = rootFile_->readCurrentEvent(cache);
729  }
730  if(!found) {
731  found = skipToItemInNewFile(id.run(), id.luminosityBlock(), 0);
732  if(!found) {
733  return false;
734  }
735  return readOneSequentialWithID(cache, fileNameHash, id);
736  }
737  fileNameHash = lfnHash_;
738  return true;
739  }
740 
741  void
744  throw Exception(errors::Configuration) << "RootInputFileSequence::readOneSpecified(): no input files specified for secondary input source.\n";
745  }
746  skipBadFiles_ = false;
747  EventID const& id = idx.eventID();
748  bool found = skipToItem(id.run(), id.luminosityBlock(), id.event(), idx.fileNameHash());
749  if(!found) {
750  throw Exception(errors::NotFound) <<
751  "RootInputFileSequence::readOneSpecified(): Secondary Input files" <<
752  " do not contain specified event:\n" << id << "\n";
753  }
754  assert(rootFile_);
755  found = rootFile_->readCurrentEvent(cache);
756  assert(found);
757  fileNameHash = idx.fileNameHash();
758  if(fileNameHash == 0U) {
759  fileNameHash = lfnHash_;
760  }
761  }
762 
763  void
764  RootInputFileSequence::readOneRandom(EventPrincipal& cache, size_t& fileNameHash, CLHEP::HepRandomEngine* engine) {
766  throw Exception(errors::Configuration) << "RootInputFileSequence::readOneRandom(): no input files specified for secondary input source.\n";
767  }
768  assert(rootFile_);
769  skipBadFiles_ = false;
770  unsigned int currentSeqNumber = fileIter_ - fileIterBegin_;
771  while(eventsRemainingInFile_ == 0) {
772 
773  fileIter_ = fileIterBegin_ + CLHEP::RandFlat::shootInt(engine, fileCatalogItems().size());
774  unsigned int newSeqNumber = fileIter_ - fileIterBegin_;
775  if(newSeqNumber != currentSeqNumber) {
776  initFile(false);
777  currentSeqNumber = newSeqNumber;
778  }
779  eventsRemainingInFile_ = rootFile_->eventTree().entries();
780  if(eventsRemainingInFile_ == 0) {
781  throw Exception(errors::NotFound) <<
782  "RootInputFileSequence::readOneRandom(): Secondary Input file " << fileIter_->fileName() << " contains no events.\n";
783  }
784  rootFile_->setAtEventEntry(CLHEP::RandFlat::shootInt(engine, eventsRemainingInFile_) - 1);
785  }
786  rootFile_->nextEventEntry();
787 
788  bool found = rootFile_->readCurrentEvent(cache);
789  if(!found) {
790  rootFile_->setAtEventEntry(0);
791  bool found = rootFile_->readCurrentEvent(cache);
792  assert(found);
793  }
794  fileNameHash = lfnHash_;
796  }
797 
798  // bool RootFile::setEntryAtNextEventInLumi(RunNumber_t run, LuminosityBlockNumber_t lumi) {
799 
800  bool
801  RootInputFileSequence::readOneRandomWithID(EventPrincipal& cache, size_t& fileNameHash, LuminosityBlockID const& id, CLHEP::HepRandomEngine* engine) {
803  throw Exception(errors::Configuration) << "RootInputFileSequence::readOneRandomWithID(): no input files specified for secondary input source.\n";
804  }
805  skipBadFiles_ = false;
806  if(fileIter_ == fileIterEnd_ || !rootFile_ ||
807  rootFile_->indexIntoFileIter().run() != id.run() ||
808  rootFile_->indexIntoFileIter().lumi() != id.luminosityBlock()) {
809  bool found = skipToItem(id.run(), id.luminosityBlock(), 0);
810  if(!found) {
811  return false;
812  }
813  int eventsInLumi = 0;
814  assert(rootFile_);
815  while(rootFile_->setEntryAtNextEventInLumi(id.run(), id.luminosityBlock())) ++eventsInLumi;
816  found = skipToItem(id.run(), id.luminosityBlock(), 0);
817  assert(found);
818  int eventInLumi = CLHEP::RandFlat::shootInt(engine, eventsInLumi);
819  for(int i = 0; i < eventInLumi; ++i) {
820  bool found = rootFile_->setEntryAtNextEventInLumi(id.run(), id.luminosityBlock());
821  assert(found);
822  }
823  }
824  assert(rootFile_);
825  bool found = rootFile_->setEntryAtNextEventInLumi(id.run(), id.luminosityBlock());
826  if(found) {
827  found = rootFile_->readCurrentEvent(cache);
828  }
829  if(!found) {
830  bool found = rootFile_->setEntryAtItem(id.run(), id.luminosityBlock(), 0);
831  if(!found) {
832  return false;
833  }
834  return readOneRandomWithID(cache, fileNameHash, id, engine);
835  }
836  fileNameHash = lfnHash_;
837  return true;
838  }
839 
840  void
842  desc.addUntracked<unsigned int>("skipEvents", 0U)
843  ->setComment("Skip the first 'skipEvents' events that otherwise would have been processed.");
844  desc.addUntracked<bool>("noEventSort", true)
845  ->setComment("True: Process runs, lumis and events in the order they appear in the file (but see notes 1 and 2).\n"
846  "False: Process runs, lumis and events in each file in numerical order (run#, lumi#, event#) (but see note 3).\n"
847  "Note 1: Events within the same lumi will always be processed contiguously.\n"
848  "Note 2: Lumis within the same run will always be processed contiguously.\n"
849  "Note 3: Any sorting occurs independently in each input file (no sorting across input files).");
850  desc.addUntracked<bool>("skipBadFiles", false)
851  ->setComment("True: Ignore any missing or unopenable input file.\n"
852  "False: Throw exception if missing or unopenable input file.");
853  desc.addUntracked<bool>("bypassVersionCheck", false)
854  ->setComment("True: Bypass release version check.\n"
855  "False: Throw exception if reading file in a release prior to the release in which the file was written.");
856  desc.addUntracked<unsigned int>("cacheSize", roottree::defaultCacheSize)
857  ->setComment("Size of ROOT TTree prefetch cache. Affects performance.");
858  desc.addUntracked<int>("treeMaxVirtualSize", -1)
859  ->setComment("Size of ROOT TTree TBasket cache. Affects performance.");
860  desc.addUntracked<unsigned int>("setRunNumber", 0U)
861  ->setComment("If non-zero, change number of first run to this number. Apply same offset to all runs. Allowed only for simulation.");
862  desc.addUntracked<bool>("dropDescendantsOfDroppedBranches", true)
863  ->setComment("If True, also drop on input any descendent of any branch dropped on input.");
864  std::string defaultString("permissive");
865  desc.addUntracked<std::string>("branchesMustMatch", defaultString)
866  ->setComment("'strict': Branches in each input file must match those in the first file.\n"
867  "'permissive': Branches in each input file may be any subset of those in the first file.");
868  desc.addUntracked<bool>("labelRawDataLikeMC", true)
869  ->setComment("If True: replace module label for raw data to match MC. Also use 'LHC' as process.");
870 
871  ProductSelectorRules::fillDescription(desc, "inputCommands");
874  }
875 
878  if(rootFile_) {
879  if(!rootFile_->wasLastEventJustRead()) {
881  }
882  std::vector<FileCatalogItem>::const_iterator itr(fileIter_);
883  if(itr != fileIterEnd_) ++itr;
884  if(itr != fileIterEnd_) {
886  }
888  }
890  }
891 
894  if(rootFile_) {
895  if(!rootFile_->wasFirstEventJustRead()) {
897  }
898  if(fileIter_ != fileIterBegin_) {
900  }
902  }
904  }
905 
906  void RootInputFileSequence::initAssociationsFromSecondary(std::set<BranchID> const& associationsFromSecondary) {
907  for(auto const& branchID : associationsFromSecondary) {
908  associationsFromSecondary_.push_back(branchID);
909  }
910  rootFile_->initAssociationsFromSecondary(associationsFromSecondary_);
911  }
912 }
RunNumber_t run() const
Definition: EventID.h:39
ProcessingController::ForwardState forwardState() const
EventNumber_t event() const
Definition: EventID.h:41
ProcessHistoryRegistry const & processHistoryRegistry() const
Const accessor for process history registry.
Definition: InputSource.h:172
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
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
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
assert(m_qm.get())
std::shared_ptr< ThinnedAssociationsHelper > thinnedAssociationsHelper() const
Accessor for thinnedAssociationsHelper.
Definition: InputSource.h:181
void initAssociationsFromSecondary(std::set< BranchID > const &)
std::shared_ptr< BranchIDListHelper const > fileBranchIDListHelper() const
unsigned long long EventNumber_t
ProcessingMode processingMode() const
RunsLumisAndEvents (default), RunsAndLumis, or Runs.
Definition: InputSource.h:257
static void fillDescription(ParameterSetDescription &desc)
#define nullptr
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)
std::list< std::string > const & additionalInfo() const
Definition: Exception.cc:195
static std::string const input
Definition: EdmProvDump.cc:43
static StorageFactory * get(void)
std::shared_ptr< RootFile > RootFileSharedPtr
tuple InputFile
Open Root file and provide MEs ############.
std::vector< BranchID > associationsFromSecondary_
static void reportFallbackAttempt(std::string const &pfn, std::string const &logicalFileName, std::string const &errorMessage)
Definition: InputFile.cc:86
int remainingEvents() const
Definition: InputSource.h:198
bool readOneRandomWithID(EventPrincipal &cache, size_t &fileNameHash, LuminosityBlockID const &id, CLHEP::HepRandomEngine *)
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:178
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:80
std::string merge(ProductRegistry const &other, std::string const &fileName, BranchDescription::MatchMode branchesMustMatch=BranchDescription::Permissive)
#define end
Definition: vmac.h:37
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
bool skipToItem(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event, size_t fileNameHash=0U, bool currentFileFirst=true)
std::unique_ptr< std::unordered_multimap< size_t, size_t > > findFileForSpecifiedID_
static EntryNumber_t const invalidEntry
std::vector< ProcessHistoryID > orderedProcessHistoryIDs_
void addUntrackedParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:207
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
ProductRegistry & productRegistryUpdate() const
Definition: InputSource.h:351
void readOneRandom(EventPrincipal &cache, size_t &fileNameHash, CLHEP::HepRandomEngine *)
bool containedInCurrentFile(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const
bool skipToItemInNewFile(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event)
std::unique_ptr< FileBlock > readFile_()
bool readOneSequential(EventPrincipal &cache, size_t &fileNameHash)
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:175
std::vector< FileCatalogItem >::const_iterator fileIterBegin_
tuple skipBadFiles
Definition: example_cfg.py:64
static void fillDescription(ParameterSetDescription &desc)
#define begin
Definition: vmac.h:30
void readOneSpecified(EventPrincipal &cache, size_t &fileNameHash, SecondaryEventIDAndFileInfo const &id)
std::shared_ptr< LuminosityBlockAuxiliary > readLuminosityBlockAuxiliary_()
std::shared_ptr< ProductRegistry const > productRegistry() const
Accessor for product registry.
Definition: InputSource.h:169
void updateFromInput(ProductList const &other)
bool readOneSequentialWithID(EventPrincipal &cache, size_t &fileNameHash, LuminosityBlockID const &id)
ProcessHistoryRegistry & processHistoryRegistryForUpdate()
void activateTimeout(const std::string &url)
std::vector< FileCatalogItem >::const_iterator fileIterEnd_
int remainingLuminosityBlocks() const
Definition: InputSource.h:206
unsigned int RunNumber_t
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:212
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_