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 
20 
21 #include "CLHEP/Random/RandFlat.h"
22 #include "InputFile.h"
23 #include "TSystem.h"
24 
25 namespace edm {
27  ParameterSet const& pset,
28  PoolSource const& input,
30  PrincipalCache& cache,
31  InputType::InputType inputType) :
32  input_(input),
33  inputType_(inputType),
34  catalog_(catalog),
35  firstFile_(true),
36  fileIterBegin_(fileCatalogItems().begin()),
37  fileIterEnd_(fileCatalogItems().end()),
38  fileIter_(fileIterEnd_),
39  fileIterLastOpened_(fileIterEnd_),
40  rootFile_(),
41  parametersMustMatch_(BranchDescription::Permissive),
42  branchesMustMatch_(BranchDescription::Permissive),
43  flatDistribution_(),
44  indexesIntoFiles_(fileCatalogItems().size()),
45  orderedProcessHistoryIDs_(),
46  eventSkipperByID_(inputType == InputType::Primary ? EventSkipperByID::create(pset).release() : 0),
47  eventsRemainingInFile_(0),
48  // The default value provided as the second argument to the getUntrackedParameter function call
49  // is not used when the ParameterSet has been validated and the parameters are not optional
50  // in the description. This is currently true when PoolSource is the primary input source.
51  // The modules that use PoolSource as a SecSource have not defined their fillDescriptions function
52  // yet, so the ParameterSet does not get validated yet. As soon as all the modules with a SecSource
53  // have defined descriptions, the defaults in the getUntrackedParameterSet function calls can
54  // and should be deleted from the code.
55  numberOfEventsToSkip_(inputType == InputType::Primary ? pset.getUntrackedParameter<unsigned int>("skipEvents", 0U) : 0U),
56  noEventSort_(inputType == InputType::Primary ? pset.getUntrackedParameter<bool>("noEventSort", true) : false),
57  skipBadFiles_(pset.getUntrackedParameter<bool>("skipBadFiles", false)),
58  bypassVersionCheck_(pset.getUntrackedParameter<bool>("bypassVersionCheck", false)),
59  treeCacheSize_(noEventSort_ ? pset.getUntrackedParameter<unsigned int>("cacheSize", roottree::defaultCacheSize) : 0U),
60  treeMaxVirtualSize_(pset.getUntrackedParameter<int>("treeMaxVirtualSize", -1)),
61  setRun_(pset.getUntrackedParameter<unsigned int>("setRunNumber", 0U)),
62  groupSelectorRules_(pset, "inputCommands", "InputSource"),
63  duplicateChecker_(inputType == InputType::Primary ? new DuplicateChecker(pset) : 0),
64  dropDescendants_(pset.getUntrackedParameter<bool>("dropDescendantsOfDroppedBranches", inputType != InputType::SecondarySource)),
65  labelRawDataLikeMC_(pset.getUntrackedParameter<bool>("labelRawDataLikeMC", true)),
66  usingGoToEvent_(false) {
67 
68  //we now allow the site local config to specify what the TTree cache size should be
70  if(treeCacheSize_ != 0U && pSLC.isAvailable() && pSLC->sourceTTreeCacheSize()) {
71  treeCacheSize_ = *(pSLC->sourceTTreeCacheSize());
72  }
73 
75  //NOTE: we do not want to stage in secondary files since we can be given a list of
76  // thousands of files and prestaging all those files can cause a site to fail
79  factory->activateTimeout(fileIter_->fileName());
80  factory->stagein(fileIter_->fileName());
81  }
82  }
83 
84  std::string parametersMustMatch = pset.getUntrackedParameter<std::string>("parametersMustMatch", std::string("permissive"));
85  if(parametersMustMatch == std::string("strict")) parametersMustMatch_ = BranchDescription::Strict;
86 
87  std::string branchesMustMatch = pset.getUntrackedParameter<std::string>("branchesMustMatch", std::string("permissive"));
88  if(branchesMustMatch == std::string("strict")) branchesMustMatch_ = BranchDescription::Strict;
89 
90  if(inputType != InputType::SecondarySource) {
93  if(rootFile_) break;
94  }
95  if(rootFile_) {
96  productRegistryUpdate().updateFromInput(rootFile_->productRegistry()->productList());
97  if(numberOfEventsToSkip_ != 0) {
99  }
100  }
101  }
102  }
103 
104  std::vector<FileCatalogItem> const&
106  return catalog_.fileCatalogItems();
107  }
108 
109  void
111  closeFile_();
112  }
113 
114  boost::shared_ptr<FileBlock>
116  if(firstFile_) {
117  // The first input file has already been opened.
118  firstFile_ = false;
119  if(!rootFile_) {
121  }
122  } else {
123  if(!nextFile(cache)) {
124  assert(0);
125  }
126  }
127  if(!rootFile_) {
128  return boost::shared_ptr<FileBlock>(new FileBlock);
129  }
130  return rootFile_->createFileBlock();
131  }
132 
134  // close the currently open file, if any, and delete the RootFile object.
135  if(rootFile_) {
137  std::unique_ptr<InputSource::FileCloseSentry>
139  rootFile_->close();
140  if(duplicateChecker_) duplicateChecker_->inputFileClosed();
141  }
142  rootFile_.reset();
143  }
144  }
145 
147  // We are really going to close the open file.
148 
149  // If this is the primary sequence, we are not duplicate checking across files
150  // and we are not using random access to find events, then we can delete the
151  // IndexIntoFile for the file we are closing. If we can't delete all of it,
152  // then we can delete the parts we do not need.
154  size_t currentIndexIntoFile = fileIterLastOpened_ - fileIterBegin_;
155  bool needIndexesForDuplicateChecker = duplicateChecker_ && duplicateChecker_->checkingAllFiles() && !duplicateChecker_->checkDisabled();
156  bool deleteIndexIntoFile = inputType_ == InputType::Primary &&
157  !needIndexesForDuplicateChecker &&
159  if(deleteIndexIntoFile) {
160  indexesIntoFiles_[currentIndexIntoFile].reset();
161  } else {
162  if(indexesIntoFiles_[currentIndexIntoFile]) indexesIntoFiles_[currentIndexIntoFile]->inputFileClosed();
163  }
165  }
166  closeFile_();
167 
168  if(fileIter_ == fileIterEnd_) {
169  // No files specified
170  return;
171  }
172 
173  // Check if the logical file name was found.
174  if(fileIter_->fileName().empty()) {
175  // LFN not found in catalog.
176  InputFile::reportSkippedFile(fileIter_->fileName(), fileIter_->logicalFileName());
177  if(!skipBadFiles) {
178  throw cms::Exception("LogicalFileNameNotFound", "RootInputFileSequence::initFile()\n")
179  << "Logical file name '" << fileIter_->logicalFileName() << "' was not found in the file catalog.\n"
180  << "If you wanted a local file, you forgot the 'file:' prefix\n"
181  << "before the file name in your configuration file.\n";
182  }
183  LogWarning("") << "Input logical file: " << fileIter_->logicalFileName() << " was not found in the catalog, and will be skipped.\n";
184  return;
185  }
186 
187  // Determine whether we have a fallback URL specified; if so, prepare it;
188  // Only valid if it is non-empty and differs from the original filename.
189  std::string fallbackName = fileIter_->fallbackFileName();
190  bool hasFallbackUrl = !fallbackName.empty() && fallbackName != fileIter_->fileName();
191 
192  boost::shared_ptr<InputFile> filePtr;
193  try {
194  std::unique_ptr<InputSource::FileOpenSentry>
196  filePtr.reset(new InputFile(gSystem->ExpandPathName(fileIter_->fileName().c_str()), " Initiating request to open file "));
197  }
198  catch (cms::Exception const& e) {
199  if(!skipBadFiles) {
200  if(hasFallbackUrl) {
201  std::ostringstream out;
202  out << e.explainSelf();
203  std::string pfn(gSystem->ExpandPathName(fallbackName.c_str()));
204  InputFile::reportFallbackAttempt(pfn, fileIter_->logicalFileName(), out.str());
205  } else {
206  InputFile::reportSkippedFile(fileIter_->fileName(), fileIter_->logicalFileName());
207  Exception ex(errors::FileOpenError, "", e);
208  ex.addContext("Calling RootInputFileSequence::initFile()");
209  ex.clearMessage();
210  ex << "Input file " << fileIter_->fileName() << " was not found, could not be opened, or is corrupted.\n";
211  throw ex;
212  }
213  }
214  }
215  if(!filePtr && (hasFallbackUrl)) {
216  try {
217  std::unique_ptr<InputSource::FileOpenSentry>
219  filePtr.reset(new InputFile(gSystem->ExpandPathName(fallbackName.c_str()), " Fallback request to file "));
220  }
221  catch (cms::Exception const& e) {
222  if(!skipBadFiles) {
223  InputFile::reportSkippedFile(fileIter_->fileName(), fileIter_->logicalFileName());
225  ex.addContext("Calling RootInputFileSequence::initFile()");
226  ex.clearMessage();
227  ex << "Input file " << fileIter_->fileName() << " was not found, could not be opened, or is corrupted.\n";
228  ex << "Fallback Input file " << fallbackName << " also was not found, could not be opened, or is corrupted.\n";
229  throw ex;
230  }
231  }
232  }
233  if(filePtr) {
234  std::vector<boost::shared_ptr<IndexIntoFile> >::size_type currentIndexIntoFile = fileIter_ - fileIterBegin_;
235  rootFile_ = RootFileSharedPtr(new RootFile(fileIter_->fileName(),
236  processConfiguration(), fileIter_->logicalFileName(), filePtr,
240  setRun_,
241  noEventSort_,
243  inputType_,
247  currentIndexIntoFile,
251  usingGoToEvent_));
252 
254  indexesIntoFiles_[currentIndexIntoFile] = rootFile_->indexIntoFileSharedPtr();
255  char const* inputType = 0;
256  switch(inputType_) {
257  case InputType::Primary: inputType = "primaryFiles"; break;
258  case InputType::SecondaryFile: inputType = "secondaryFiles"; break;
259  case InputType::SecondarySource: inputType = "mixingFiles"; break;
260  }
261  rootFile_->reportOpened(inputType);
262  } else {
263  InputFile::reportSkippedFile(fileIter_->fileName(), fileIter_->logicalFileName());
264  if(!skipBadFiles) {
266  "RootInputFileSequence::initFile(): Input file " << fileIter_->fileName() << " was not found or could not be opened.\n";
267  }
268  LogWarning("") << "Input file: " << fileIter_->fileName() << " was not found or could not be opened, and will be skipped.\n";
269  }
270  }
271 
272  boost::shared_ptr<ProductRegistry const>
274  assert(rootFile_);
275  return rootFile_->productRegistry();
276  }
277 
280  if(fileIter_ == fileIterEnd_) {
282  return false;
283  } else {
285  }
286  }
287 
289 
291  size_t size = productRegistry()->size();
292  // make sure the new product registry is compatible with the main one
293  std::string mergeInfo = productRegistryUpdate().merge(*rootFile_->productRegistry(),
294  fileIter_->fileName(),
297  if(!mergeInfo.empty()) {
298  throw Exception(errors::MismatchedInputFiles,"RootInputFileSequence::nextFile()") << mergeInfo;
299  }
300  if(productRegistry()->size() > size) {
302  }
304  }
305  return true;
306  }
307 
309  if(fileIter_ == fileIterBegin_) {
311  return false;
312  } else {
314  }
315  }
316  --fileIter_;
317 
318  initFile(false);
319 
321  size_t size = productRegistry()->size();
322  // make sure the new product registry is compatible to the main one
323  std::string mergeInfo = productRegistryUpdate().merge(*rootFile_->productRegistry(),
324  fileIter_->fileName(),
327  if(!mergeInfo.empty()) {
328  throw Exception(errors::MismatchedInputFiles,"RootInputFileSequence::previousEvent()") << mergeInfo;
329  }
330  if(productRegistry()->size() > size) {
332  }
334  }
335  if(rootFile_) rootFile_->setToLastEntry();
336  return true;
337  }
338 
340  }
341 
342  boost::shared_ptr<RunAuxiliary>
344  return rootFile_->readRunAuxiliary_();
345  }
346 
347  boost::shared_ptr<LuminosityBlockAuxiliary>
349  return rootFile_->readLuminosityBlockAuxiliary_();
350  }
351 
352  boost::shared_ptr<RunPrincipal>
353  RootInputFileSequence::readRun_(boost::shared_ptr<RunPrincipal> rpCache) {
354  return rootFile_->readRun_(rpCache);
355  }
356 
357  boost::shared_ptr<LuminosityBlockPrincipal>
358  RootInputFileSequence::readLuminosityBlock_(boost::shared_ptr<LuminosityBlockPrincipal> lbCache) {
359  return rootFile_->readLumi(lbCache);
360  }
361 
362  // readEvent() is responsible for setting up the EventPrincipal.
363  //
364  // 1. create an EventPrincipal with a unique EventID
365  // 2. For each entry in the provenance, put in one Group,
366  // holding the Provenance for the corresponding EDProduct.
367  // 3. set up the caches in the EventPrincipal to know about this
368  // Group.
369  //
370  // We do *not* create the EDProduct instance (the equivalent of reading
371  // the branch containing this EDProduct. That will be done by the Delayed Reader,
372  // when it is asked to do so.
373  //
374 
376  RootInputFileSequence::readEvent(EventPrincipal& cache, boost::shared_ptr<LuminosityBlockPrincipal> lb) {
377  return rootFile_->readEvent(cache, lb);
378  }
379 
382  if(fileIter_ == fileIterEnd_) {
383  return InputSource::IsStop;
384  }
385  if(firstFile_) {
386  return InputSource::IsFile;
387  }
388  if(rootFile_) {
389  IndexIntoFile::EntryType entryType = rootFile_->getNextEntryTypeWanted();
390  if(entryType == IndexIntoFile::kEvent) {
391  return InputSource::IsEvent;
392  } else if(entryType == IndexIntoFile::kLumi) {
393  return InputSource::IsLumi;
394  } else if(entryType == IndexIntoFile::kRun) {
395  return InputSource::IsRun;
396  }
397  assert(entryType == IndexIntoFile::kEnd);
398  }
399  if(fileIter_ + 1 == fileIterEnd_) {
400  return InputSource::IsStop;
401  }
402  return InputSource::IsFile;
403  }
404 
405  // Rewind to before the first event that was read.
406  void
408  if(fileIter_ != fileIterBegin_) {
409  closeFile_();
411  }
412  if(!rootFile_) {
413  initFile(false);
414  }
415  rewindFile();
416  firstFile_ = true;
417  }
418 
419  // Rewind to the beginning of the current file
420  void
422  if(rootFile_) rootFile_->rewind();
423  }
424 
425  void
427  //NOTE: Need to handle duplicate checker
428  // Also what if skipBadFiles_==true and the first time we succeeded but after a reset we fail?
430  firstFile_ = true;
433  if(rootFile_) break;
434  }
435  if(rootFile_) {
436  if(numberOfEventsToSkip_ != 0) {
438  }
439  }
440  }
441  }
442 
443  // Advance "offset" events. Offset can be positive or negative (or zero).
444  bool
446  assert (numberOfEventsToSkip_ == 0 || numberOfEventsToSkip_ == offset);
448  while(numberOfEventsToSkip_ != 0) {
449  bool atEnd = rootFile_->skipEvents(numberOfEventsToSkip_);
450  if((numberOfEventsToSkip_ > 0 || atEnd) && !nextFile(cache)) {
452  return false;
453  }
454  if(numberOfEventsToSkip_ < 0 && !previousFile(cache)) {
457  return false;
458  }
459  }
460  return true;
461  }
462 
463  bool
465  usingGoToEvent_ = true;
466  if(rootFile_) {
467  if(rootFile_->goToEvent(eventID)) {
468  return true;
469  }
470  // If only one input file, give up now, to save time.
471  if(rootFile_ && indexesIntoFiles_.size() == 1) {
472  return false;
473  }
474  // Save the current file and position so that we can restore them
475  // if we fail to restore the desired event
476  bool closedOriginalFile = false;
477  std::vector<FileCatalogItem>::const_iterator originalFile = fileIter_;
478  IndexIntoFile::IndexIntoFileItr originalPosition = rootFile_->indexIntoFileIter();
479 
480  // Look for item (run/lumi/event) in files previously opened without reopening unnecessary files.
481  typedef std::vector<boost::shared_ptr<IndexIntoFile> >::const_iterator Iter;
482  for(Iter it = indexesIntoFiles_.begin(), itEnd = indexesIntoFiles_.end(); it != itEnd; ++it) {
483  if(*it && (*it)->containsItem(eventID.run(), eventID.luminosityBlock(), eventID.event())) {
484  // We found it. Close the currently open file, and open the correct one.
485  fileIter_ = fileIterBegin_ + (it - indexesIntoFiles_.begin());
486  initFile(false);
487  // Now get the item from the correct file.
488  bool found = rootFile_->goToEvent(eventID);
489  assert (found);
490  return true;
491  }
492  }
493  // Look for item in files not yet opened.
494  for(Iter it = indexesIntoFiles_.begin(), itEnd = indexesIntoFiles_.end(); it != itEnd; ++it) {
495  if(!*it) {
496  fileIter_ = fileIterBegin_ + (it - indexesIntoFiles_.begin());
497  initFile(false);
498  closedOriginalFile = true;
499  if((*it)->containsItem(eventID.run(), eventID.luminosityBlock(), eventID.event())) {
500  if (rootFile_->goToEvent(eventID)) {
501  return true;
502  }
503  }
504  }
505  }
506  if(closedOriginalFile) {
507  fileIter_ = originalFile;
508  initFile(false);
509  rootFile_->setPosition(originalPosition);
510  }
511  }
512  return false;
513  }
514 
515  bool
517  // Look for item in files not yet opened.
518  typedef std::vector<boost::shared_ptr<IndexIntoFile> >::const_iterator Iter;
519  for(Iter it = indexesIntoFiles_.begin(), itEnd = indexesIntoFiles_.end(); it != itEnd; ++it) {
520  if(!*it) {
521  fileIter_ = fileIterBegin_ + (it - indexesIntoFiles_.begin());
522  initFile(false);
523  bool found = rootFile_->setEntryAtItem(run, lumi, event);
524  if(found) {
525  return true;
526  }
527  }
528  }
529  // Not found
530  return false;
531  }
532 
533  bool
535  // Attempt to find item in currently open input file.
536  bool found = currentFileFirst && rootFile_ && rootFile_->setEntryAtItem(run, lumi, event);
537  if(!found) {
538  // If only one input file, give up now, to save time.
539  if(currentFileFirst && rootFile_ && indexesIntoFiles_.size() == 1) {
540  return false;
541  }
542  // Look for item (run/lumi/event) in files previously opened without reopening unnecessary files.
543  typedef std::vector<boost::shared_ptr<IndexIntoFile> >::const_iterator Iter;
544  for(Iter it = indexesIntoFiles_.begin(), itEnd = indexesIntoFiles_.end(); it != itEnd; ++it) {
545  if(*it && (*it)->containsItem(run, lumi, event)) {
546  // We found it. Close the currently open file, and open the correct one.
547  std::vector<FileCatalogItem>::const_iterator currentIter = fileIter_;
548  fileIter_ = fileIterBegin_ + (it - indexesIntoFiles_.begin());
549  if(fileIter_ != currentIter) {
550  initFile(false);
551  }
552  // Now get the item from the correct file.
553  found = rootFile_->setEntryAtItem(run, lumi, event);
554  assert (found);
555  return true;
556  }
557  }
558  // Look for item in files not yet opened.
559  return skipToItemInNewFile(run, lumi, event);
560  }
561  return true;
562  }
563 
564  ProcessConfiguration const&
566  return input_.processConfiguration();
567  }
568 
569  int
571  return input_.remainingEvents();
572  }
573 
574  int
577  }
578 
581  return input_.productRegistryUpdate();
582  }
583 
584  boost::shared_ptr<ProductRegistry const>
586  return input_.productRegistry();
587  }
588 
589  void
590  RootInputFileSequence::dropUnwantedBranches_(std::vector<std::string> const& wantedBranches) {
591  std::vector<std::string> rules;
592  rules.reserve(wantedBranches.size() + 1);
593  rules.emplace_back("drop *");
594  for(std::vector<std::string>::const_iterator it = wantedBranches.begin(), itEnd = wantedBranches.end();
595  it != itEnd; ++it) {
596  rules.push_back("keep " + *it + "_*");
597  }
598  ParameterSet pset;
599  pset.addUntrackedParameter("inputCommands", rules);
600  groupSelectorRules_ = GroupSelectorRules(pset, "inputCommands", "InputSource");
601  }
602 
605  skipBadFiles_ = false;
606  if(fileIter_ == fileIterEnd_ || !rootFile_) {
608  throw Exception(errors::Configuration) << "RootInputFileSequence::readOneSequential(): no input files specified for secondary input source.\n";
609  }
611  initFile(false);
612  rootFile_->setAtEventEntry(-1);
613  }
614  rootFile_->nextEventEntry();
615  EventPrincipal* ep = rootFile_->clearAndReadCurrentEvent(rootFile_->secondaryEventPrincipal());
616  if(ep == 0) {
617  ++fileIter_;
618  if(fileIter_ == fileIterEnd_) {
619  return 0;
620  }
621  initFile(false);
622  rootFile_->setAtEventEntry(-1);
623  return readOneSequential();
624  }
625  return ep;
626  }
627 
631  throw Exception(errors::Configuration) << "RootInputFileSequence::readOneSequentialWithID(): no input files specified for secondary input source.\n";
632  }
633  skipBadFiles_ = false;
634  if(fileIter_ == fileIterEnd_ || !rootFile_ ||
635  rootFile_->indexIntoFileIter().run() != id.run() ||
636  rootFile_->indexIntoFileIter().lumi() != id.luminosityBlock()) {
637  bool found = skipToItem(id.run(), id.luminosityBlock(), 0, false);
638  if(!found) {
639  return 0;
640  }
641  }
642  bool nextFound = rootFile_->setEntryAtNextEventInLumi(id.run(), id.luminosityBlock());
643  EventPrincipal* ep = (nextFound ? rootFile_->clearAndReadCurrentEvent(rootFile_->secondaryEventPrincipal()) : 0);
644  if(ep == 0) {
645  bool found = skipToItemInNewFile(id.run(), id.luminosityBlock(), 0);
646  if(found) {
647  return readOneSequentialWithID(id);
648  }
649  }
650  return ep;
651  }
652 
656  throw Exception(errors::Configuration) << "RootInputFileSequence::readOneSequential(): no input files specified for secondary input source.\n";
657  }
658  skipBadFiles_ = false;
659  bool found = skipToItem(id.run(), id.luminosityBlock(), id.event());
660  if(!found) {
661  throw Exception(errors::NotFound) <<
662  "RootInputFileSequence::readOneSpecified(): Secondary Input files" <<
663  " do not contain specified event:\n" << id << "\n";
664  }
665  EventPrincipal* ep = rootFile_->clearAndReadCurrentEvent(rootFile_->secondaryEventPrincipal());
666  assert(ep != 0);
667  return ep;
668  }
669 
673  throw Exception(errors::Configuration) << "RootInputFileSequence::readOneRandom(): no input files specified for secondary input source.\n";
674  }
675  if(!flatDistribution_) {
677  CLHEP::HepRandomEngine& engine = rng->getEngine();
678  flatDistribution_.reset(new CLHEP::RandFlat(engine));
679  }
680  skipBadFiles_ = false;
681  unsigned int currentSeqNumber = fileIter_ - fileIterBegin_;
682  while(eventsRemainingInFile_ == 0) {
683  fileIter_ = fileIterBegin_ + flatDistribution_->fireInt(fileCatalogItems().size());
684  unsigned int newSeqNumber = fileIter_ - fileIterBegin_;
685  if(newSeqNumber != currentSeqNumber) {
686  initFile(false);
687  currentSeqNumber = newSeqNumber;
688  }
689  eventsRemainingInFile_ = rootFile_->eventTree().entries();
690  if(eventsRemainingInFile_ == 0) {
691  throw Exception(errors::NotFound) <<
692  "RootInputFileSequence::readOneRandom(): Secondary Input file " << fileIter_->fileName() << " contains no events.\n";
693  }
694  rootFile_->setAtEventEntry(flatDistribution_->fireInt(eventsRemainingInFile_) - 1);
695  }
696  rootFile_->nextEventEntry();
697 
698  EventPrincipal* ep = rootFile_->clearAndReadCurrentEvent(rootFile_->secondaryEventPrincipal());
699  if(ep == 0) {
700  rootFile_->setAtEventEntry(0);
701  ep = rootFile_->clearAndReadCurrentEvent(rootFile_->secondaryEventPrincipal());
702  assert(ep != 0);
703  }
705  return ep;
706  }
707 
708  // bool RootFile::setEntryAtNextEventInLumi(RunNumber_t run, LuminosityBlockNumber_t lumi) {
709 
713  throw Exception(errors::Configuration) << "RootInputFileSequence::readOneRandomWithID(): no input files specified for secondary input source.\n";
714  }
715  if(!flatDistribution_) {
717  CLHEP::HepRandomEngine& engine = rng->getEngine();
718  flatDistribution_.reset(new CLHEP::RandFlat(engine));
719  }
720  skipBadFiles_ = false;
721  if(fileIter_ == fileIterEnd_ || !rootFile_ ||
722  rootFile_->indexIntoFileIter().run() != id.run() ||
723  rootFile_->indexIntoFileIter().lumi() != id.luminosityBlock()) {
724  bool found = skipToItem(id.run(), id.luminosityBlock(), 0);
725  if(!found) {
726  return 0;
727  }
728  int eventsInLumi = 0;
729  while(rootFile_->setEntryAtNextEventInLumi(id.run(), id.luminosityBlock())) ++eventsInLumi;
730  found = skipToItem(id.run(), id.luminosityBlock(), 0);
731  assert(found);
732  int eventInLumi = flatDistribution_->fireInt(eventsInLumi);
733  for(int i = 0; i < eventInLumi; ++i) {
734  bool found = rootFile_->setEntryAtNextEventInLumi(id.run(), id.luminosityBlock());
735  assert(found);
736  }
737  }
738  bool nextFound = rootFile_->setEntryAtNextEventInLumi(id.run(), id.luminosityBlock());
739  EventPrincipal* ep = (nextFound ? rootFile_->clearAndReadCurrentEvent(rootFile_->secondaryEventPrincipal()) : 0);
740  if(ep == 0) {
741  bool found = rootFile_->setEntryAtItem(id.run(), id.luminosityBlock(), 0);
742  if(found) {
743  return readOneRandomWithID(id);
744  }
745  }
746  return ep;
747  }
748 
749  void
751  desc.addUntracked<unsigned int>("skipEvents", 0U)
752  ->setComment("Skip the first 'skipEvents' events that otherwise would have been processed.");
753  desc.addUntracked<bool>("noEventSort", true)
754  ->setComment("True: Process runs, lumis and events in the order they appear in the file (but see notes 1 and 2).\n"
755  "False: Process runs, lumis and events in each file in numerical order (run#, lumi#, event#) (but see note 3).\n"
756  "Note 1: Events within the same lumi will always be processed contiguously.\n"
757  "Note 2: Lumis within the same run will always be processed contiguously.\n"
758  "Note 3: Any sorting occurs independently in each input file (no sorting across input files).");
759  desc.addUntracked<bool>("skipBadFiles", false)
760  ->setComment("True: Ignore any missing or unopenable input file.\n"
761  "False: Throw exception if missing or unopenable input file.");
762  desc.addUntracked<bool>("bypassVersionCheck", false)
763  ->setComment("True: Bypass release version check.\n"
764  "False: Throw exception if reading file in a release prior to the release in which the file was written.");
765  desc.addUntracked<unsigned int>("cacheSize", roottree::defaultCacheSize)
766  ->setComment("Size of ROOT TTree prefetch cache. Affects performance.");
767  desc.addUntracked<int>("treeMaxVirtualSize", -1)
768  ->setComment("Size of ROOT TTree TBasket cache. Affects performance.");
769  desc.addUntracked<unsigned int>("setRunNumber", 0U)
770  ->setComment("If non-zero, change number of first run to this number. Apply same offset to all runs. Allowed only for simulation.");
771  desc.addUntracked<bool>("dropDescendantsOfDroppedBranches", true)
772  ->setComment("If True, also drop on input any descendent of any branch dropped on input.");
773  std::string defaultString("permissive");
774  desc.addUntracked<std::string>("parametersMustMatch", defaultString)
775  ->setComment("'strict': Values of tracked parameters must be unique across all input files.\n"
776  "'permissive': Values of tracked parameters may differ across or within files.");
777  desc.addUntracked<std::string>("branchesMustMatch", defaultString)
778  ->setComment("'strict': Branches in each input file must match those in the first file.\n"
779  "'permissive': Branches in each input file may be any subset of those in the first file.");
780  desc.addUntracked<bool>("labelRawDataLikeMC", true)
781  ->setComment("If True: replace module label for raw data to match MC. Also use 'LHC' as process.");
782 
783  GroupSelectorRules::fillDescription(desc, "inputCommands");
786  }
787 
790  if(rootFile_) {
791  if(!rootFile_->wasLastEventJustRead()) {
793  }
794  std::vector<FileCatalogItem>::const_iterator itr(fileIter_);
795  if(itr != fileIterEnd_) ++itr;
796  if(itr != fileIterEnd_) {
798  }
800  }
802  }
803 
806  if(rootFile_) {
807  if(!rootFile_->wasFirstEventJustRead()) {
809  }
810  if(fileIter_ != fileIterBegin_) {
812  }
814  }
816  }
817 }
RunNumber_t run() const
Definition: EventID.h:42
boost::shared_ptr< RunPrincipal > readRun_(boost::shared_ptr< RunPrincipal > rpCache)
ProcessingController::ForwardState forwardState() const
EventNumber_t event() const
Definition: EventID.h:44
T getUntrackedParameter(std::string const &, T const &) const
boost::shared_ptr< ProductRegistry const > fileProductRegistry() const
int i
Definition: DBlmapReader.cc:9
std::vector< boost::shared_ptr< IndexIntoFile > > indexesIntoFiles_
void stagein(const std::string &url)
list pfn
Definition: dbtoconf.py:76
void initFile(bool skipBadFiles)
bool goToEvent(EventID const &eventID)
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
ProcessConfiguration const & processConfiguration() const
unsigned int EventNumber_t
Definition: EventID.h:30
EventPrincipal * readEvent(EventPrincipal &cache, boost::shared_ptr< LuminosityBlockPrincipal > lb)
virtual std::string explainSelf() const
Definition: Exception.cc:146
boost::shared_ptr< RunAuxiliary > readRunAuxiliary_()
EventPrincipal * readOneRandomWithID(LuminosityBlockID const &id)
std::vector< FileCatalogItem >::const_iterator fileIter_
tuple lumi
Definition: fjr2json.py:35
ProductRegistry & productRegistryUpdate() const
GroupSelectorRules groupSelectorRules_
boost::shared_ptr< LuminosityBlockAuxiliary > readLuminosityBlockAuxiliary_()
EventPrincipal * readOneSequentialWithID(LuminosityBlockID const &id)
ProcessingMode processingMode() const
RunsLumisAndEvents (default), RunsAndLumis, or Runs.
Definition: InputSource.h:229
static void fillDescription(ParameterSetDescription &desc)
std::string merge(ProductRegistry const &other, std::string const &fileName, BranchDescription::MatchMode parametersMustMatch=BranchDescription::Permissive, BranchDescription::MatchMode branchesMustMatch=BranchDescription::Permissive)
static void fillDescription(ParameterSetDescription &desc, char const *parameterName)
void adjustIndexesAfterProductRegistryAddition()
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:43
static void reportSkippedFile(std::string const &fileName, std::string const &logicalFileName)
Definition: InputFile.cc:67
unsigned int const defaultCacheSize
Definition: RootTree.h:34
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)
bool skipEvents(int offset, PrincipalCache &cache)
static StorageFactory * get(void)
tuple InputFile
Open Root file and provide MEs ############.
void adjustEventToNewProductRegistry(boost::shared_ptr< ProductRegistry const > reg)
void reset(PrincipalCache &cache)
boost::shared_ptr< LuminosityBlockPrincipal > readLuminosityBlock_(boost::shared_ptr< LuminosityBlockPrincipal > lbCache)
static void reportFallbackAttempt(std::string const &pfn, std::string const &logicalFileName, std::string const &errorMessage)
Definition: InputFile.cc:73
int remainingEvents() const
Definition: InputSource.h:170
std::vector< FileCatalogItem >::const_iterator fileIterLastOpened_
std::vector< FileCatalogItem > const & fileCatalogItems() const
bool isAvailable() const
Definition: Service.h:47
boost::shared_ptr< DuplicateChecker > duplicateChecker_
#define end
Definition: vmac.h:38
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)
bool nextFile(PrincipalCache &cache)
RootInputFileSequence(ParameterSet const &pset, PoolSource const &input, InputFileCatalog const &catalog, PrincipalCache &cache, InputType::InputType inputType)
tuple out
Definition: dbtoconf.py:99
std::unique_ptr< CLHEP::RandFlat > flatDistribution_
boost::shared_ptr< FileBlock > readFile_(PrincipalCache &cache)
std::vector< ProcessHistoryID > orderedProcessHistoryIDs_
void addUntrackedParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:209
ProductRegistry & productRegistryUpdate() const
Definition: InputSource.h:295
bool skipToItemInNewFile(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event)
std::vector< FileCatalogItem >::const_iterator fileIterBegin_
boost::shared_ptr< ProductRegistry const > productRegistry() const
Accessor for product registry.
Definition: InputSource.h:155
tuple skipBadFiles
Definition: example_cfg.py:64
static void fillDescription(ParameterSetDescription &desc)
#define begin
Definition: vmac.h:31
author Stefano ARGIRO author Bill Tanenbaum
EventPrincipal * readOneSpecified(EventID const &id)
InputSource::ItemType getNextItemType()
boost::shared_ptr< EventSkipperByID > eventSkipperByID_
void updateFromInput(ProductList const &other)
bool previousFile(PrincipalCache &cache)
void activateTimeout(const std::string &url)
std::vector< FileCatalogItem >::const_iterator fileIterEnd_
int remainingLuminosityBlocks() const
Definition: InputSource.h:178
unsigned int RunNumber_t
Definition: EventRange.h:32
BranchDescription::MatchMode branchesMustMatch_
ProcessConfiguration const & processConfiguration() const
Accessor for Process Configuration.
Definition: InputSource.h:184
ProcessingController::ReverseState reverseState() const
BranchDescription::MatchMode parametersMustMatch_
InputType::InputType inputType_
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_