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  treeCacheSize_(noEventSort_ ? pset.getUntrackedParameter<unsigned int>("cacheSize", roottree::defaultCacheSize) : 0U),
59  treeMaxVirtualSize_(pset.getUntrackedParameter<int>("treeMaxVirtualSize", -1)),
60  setRun_(pset.getUntrackedParameter<unsigned int>("setRunNumber", 0U)),
61  groupSelectorRules_(pset, "inputCommands", "InputSource"),
62  duplicateChecker_(inputType == InputType::Primary ? new DuplicateChecker(pset) : 0),
63  dropDescendants_(pset.getUntrackedParameter<bool>("dropDescendantsOfDroppedBranches", inputType != InputType::SecondarySource)),
64  labelRawDataLikeMC_(pset.getUntrackedParameter<bool>("labelRawDataLikeMC", true)),
65  usingGoToEvent_(false) {
66 
67  //we now allow the site local config to specify what the TTree cache size should be
69  if(treeCacheSize_ != 0U && pSLC.isAvailable() && pSLC->sourceTTreeCacheSize()) {
70  treeCacheSize_ = *(pSLC->sourceTTreeCacheSize());
71  }
72 
74  //NOTE: we do not want to stage in secondary files since we can be given a list of
75  // thousands of files and prestaging all those files can cause a site to fail
78  factory->activateTimeout(fileIter_->fileName());
79  factory->stagein(fileIter_->fileName());
80  }
81  }
82 
83  std::string parametersMustMatch = pset.getUntrackedParameter<std::string>("parametersMustMatch", std::string("permissive"));
84  if(parametersMustMatch == std::string("strict")) parametersMustMatch_ = BranchDescription::Strict;
85 
86  std::string branchesMustMatch = pset.getUntrackedParameter<std::string>("branchesMustMatch", std::string("permissive"));
87  if(branchesMustMatch == std::string("strict")) branchesMustMatch_ = BranchDescription::Strict;
88 
89  if(inputType != InputType::SecondarySource) {
92  if(rootFile_) break;
93  }
94  if(rootFile_) {
95  productRegistryUpdate().updateFromInput(rootFile_->productRegistry()->productList());
96  if(numberOfEventsToSkip_ != 0) {
98  }
99  }
100  }
101  }
102 
103  std::vector<FileCatalogItem> const&
105  return catalog_.fileCatalogItems();
106  }
107 
108  void
110  closeFile_();
111  }
112 
113  boost::shared_ptr<FileBlock>
115  if(firstFile_) {
116  // The first input file has already been opened.
117  firstFile_ = false;
118  if(!rootFile_) {
120  }
121  } else {
122  if(!nextFile(cache)) {
123  assert(0);
124  }
125  }
126  if(!rootFile_) {
127  return boost::shared_ptr<FileBlock>(new FileBlock);
128  }
129  return rootFile_->createFileBlock();
130  }
131 
133  // close the currently open file, if any, and delete the RootFile object.
134  if(rootFile_) {
136  std::unique_ptr<InputSource::FileCloseSentry>
138  rootFile_->close();
139  if(duplicateChecker_) duplicateChecker_->inputFileClosed();
140  }
141  rootFile_.reset();
142  }
143  }
144 
146  // We are really going to close the open file.
147 
148  // If this is the primary sequence, we are not duplicate checking across files
149  // and we are not using random access to find events, then we can delete the
150  // IndexIntoFile for the file we are closing. If we can't delete all of it,
151  // then we can delete the parts we do not need.
153  size_t currentIndexIntoFile = fileIterLastOpened_ - fileIterBegin_;
154  bool needIndexesForDuplicateChecker = duplicateChecker_ && duplicateChecker_->checkingAllFiles() && !duplicateChecker_->checkDisabled();
155  bool deleteIndexIntoFile = inputType_ == InputType::Primary &&
156  !needIndexesForDuplicateChecker &&
158  if(deleteIndexIntoFile) {
159  indexesIntoFiles_[currentIndexIntoFile].reset();
160  } else {
161  if(indexesIntoFiles_[currentIndexIntoFile]) indexesIntoFiles_[currentIndexIntoFile]->inputFileClosed();
162  }
164  }
165  closeFile_();
166 
167  if(fileIter_ == fileIterEnd_) {
168  // No files specified
169  return;
170  }
171 
172  // Check if the logical file name was found.
173  if(fileIter_->fileName().empty()) {
174  // LFN not found in catalog.
175  InputFile::reportSkippedFile(fileIter_->fileName(), fileIter_->logicalFileName());
176  if(!skipBadFiles) {
177  throw cms::Exception("LogicalFileNameNotFound", "RootInputFileSequence::initFile()\n")
178  << "Logical file name '" << fileIter_->logicalFileName() << "' was not found in the file catalog.\n"
179  << "If you wanted a local file, you forgot the 'file:' prefix\n"
180  << "before the file name in your configuration file.\n";
181  }
182  LogWarning("") << "Input logical file: " << fileIter_->logicalFileName() << " was not found in the catalog, and will be skipped.\n";
183  return;
184  }
185 
186  // Determine whether we have a fallback URL specified; if so, prepare it;
187  // Only valid if it is non-empty and differs from the original filename.
188  std::string fallbackName = fileIter_->fallbackFileName();
189  bool hasFallbackUrl = !fallbackName.empty() && fallbackName != fileIter_->fileName();
190 
191  boost::shared_ptr<InputFile> filePtr;
192  try {
193  std::unique_ptr<InputSource::FileOpenSentry>
195  filePtr.reset(new InputFile(gSystem->ExpandPathName(fileIter_->fileName().c_str()), " Initiating request to open file "));
196  }
197  catch (cms::Exception const& e) {
198  if(!skipBadFiles) {
199  if(hasFallbackUrl) {
200  std::ostringstream out;
201  out << e.explainSelf();
202  std::string pfn(gSystem->ExpandPathName(fallbackName.c_str()));
203  InputFile::reportFallbackAttempt(pfn, fileIter_->logicalFileName(), out.str());
204  } else {
205  InputFile::reportSkippedFile(fileIter_->fileName(), fileIter_->logicalFileName());
206  Exception ex(errors::FileOpenError, "", e);
207  ex.addContext("Calling RootInputFileSequence::initFile()");
208  ex.clearMessage();
209  ex << "Input file " << fileIter_->fileName() << " was not found, could not be opened, or is corrupted.\n";
210  throw ex;
211  }
212  }
213  }
214  if(!filePtr && (hasFallbackUrl)) {
215  try {
216  std::unique_ptr<InputSource::FileOpenSentry>
218  filePtr.reset(new InputFile(gSystem->ExpandPathName(fallbackName.c_str()), " Fallback request to file "));
219  }
220  catch (cms::Exception const& e) {
221  if(!skipBadFiles) {
222  InputFile::reportSkippedFile(fileIter_->fileName(), fileIter_->logicalFileName());
224  ex.addContext("Calling RootInputFileSequence::initFile()");
225  ex.clearMessage();
226  ex << "Input file " << fileIter_->fileName() << " was not found, could not be opened, or is corrupted.\n";
227  ex << "Fallback Input file " << fallbackName << " also was not found, could not be opened, or is corrupted.\n";
228  throw ex;
229  }
230  }
231  }
232  if(filePtr) {
233  std::vector<boost::shared_ptr<IndexIntoFile> >::size_type currentIndexIntoFile = fileIter_ - fileIterBegin_;
234  rootFile_ = RootFileSharedPtr(new RootFile(fileIter_->fileName(),
235  processConfiguration(), fileIter_->logicalFileName(), filePtr,
239  setRun_,
240  noEventSort_,
242  inputType_,
246  currentIndexIntoFile,
249  usingGoToEvent_));
250 
252  indexesIntoFiles_[currentIndexIntoFile] = rootFile_->indexIntoFileSharedPtr();
253  char const* inputType = 0;
254  switch(inputType_) {
255  case InputType::Primary: inputType = "primaryFiles"; break;
256  case InputType::SecondaryFile: inputType = "secondaryFiles"; break;
257  case InputType::SecondarySource: inputType = "mixingFiles"; break;
258  }
259  rootFile_->reportOpened(inputType);
260  } else {
261  InputFile::reportSkippedFile(fileIter_->fileName(), fileIter_->logicalFileName());
262  if(!skipBadFiles) {
264  "RootInputFileSequence::initFile(): Input file " << fileIter_->fileName() << " was not found or could not be opened.\n";
265  }
266  LogWarning("") << "Input file: " << fileIter_->fileName() << " was not found or could not be opened, and will be skipped.\n";
267  }
268  }
269 
270  boost::shared_ptr<ProductRegistry const>
272  assert(rootFile_);
273  return rootFile_->productRegistry();
274  }
275 
278  if(fileIter_ == fileIterEnd_) {
280  return false;
281  } else {
283  }
284  }
285 
287 
289  size_t size = productRegistry()->size();
290  // make sure the new product registry is compatible with the main one
291  std::string mergeInfo = productRegistryUpdate().merge(*rootFile_->productRegistry(),
292  fileIter_->fileName(),
295  if(!mergeInfo.empty()) {
296  throw Exception(errors::MismatchedInputFiles,"RootInputFileSequence::nextFile()") << mergeInfo;
297  }
298  if(productRegistry()->size() > size) {
300  }
302  }
303  return true;
304  }
305 
307  if(fileIter_ == fileIterBegin_) {
309  return false;
310  } else {
312  }
313  }
314  --fileIter_;
315 
316  initFile(false);
317 
319  size_t size = productRegistry()->size();
320  // make sure the new product registry is compatible to the main one
321  std::string mergeInfo = productRegistryUpdate().merge(*rootFile_->productRegistry(),
322  fileIter_->fileName(),
325  if(!mergeInfo.empty()) {
326  throw Exception(errors::MismatchedInputFiles,"RootInputFileSequence::previousEvent()") << mergeInfo;
327  }
328  if(productRegistry()->size() > size) {
330  }
332  }
333  if(rootFile_) rootFile_->setToLastEntry();
334  return true;
335  }
336 
338  }
339 
340  boost::shared_ptr<RunAuxiliary>
342  return rootFile_->readRunAuxiliary_();
343  }
344 
345  boost::shared_ptr<LuminosityBlockAuxiliary>
347  return rootFile_->readLuminosityBlockAuxiliary_();
348  }
349 
350  boost::shared_ptr<RunPrincipal>
351  RootInputFileSequence::readRun_(boost::shared_ptr<RunPrincipal> rpCache) {
352  return rootFile_->readRun_(rpCache);
353  }
354 
355  boost::shared_ptr<LuminosityBlockPrincipal>
356  RootInputFileSequence::readLuminosityBlock_(boost::shared_ptr<LuminosityBlockPrincipal> lbCache) {
357  return rootFile_->readLumi(lbCache);
358  }
359 
360  // readEvent() is responsible for setting up the EventPrincipal.
361  //
362  // 1. create an EventPrincipal with a unique EventID
363  // 2. For each entry in the provenance, put in one Group,
364  // holding the Provenance for the corresponding EDProduct.
365  // 3. set up the caches in the EventPrincipal to know about this
366  // Group.
367  //
368  // We do *not* create the EDProduct instance (the equivalent of reading
369  // the branch containing this EDProduct. That will be done by the Delayed Reader,
370  // when it is asked to do so.
371  //
372 
374  RootInputFileSequence::readEvent(EventPrincipal& cache, boost::shared_ptr<LuminosityBlockPrincipal> lb) {
375  return rootFile_->readEvent(cache, lb);
376  }
377 
380  if(fileIter_ == fileIterEnd_) {
381  return InputSource::IsStop;
382  }
383  if(firstFile_) {
384  return InputSource::IsFile;
385  }
386  if(rootFile_) {
387  IndexIntoFile::EntryType entryType = rootFile_->getNextEntryTypeWanted();
388  if(entryType == IndexIntoFile::kEvent) {
389  return InputSource::IsEvent;
390  } else if(entryType == IndexIntoFile::kLumi) {
391  return InputSource::IsLumi;
392  } else if(entryType == IndexIntoFile::kRun) {
393  return InputSource::IsRun;
394  }
395  assert(entryType == IndexIntoFile::kEnd);
396  }
397  if(fileIter_ + 1 == fileIterEnd_) {
398  return InputSource::IsStop;
399  }
400  return InputSource::IsFile;
401  }
402 
403  // Rewind to before the first event that was read.
404  void
406  if(fileIter_ != fileIterBegin_) {
407  closeFile_();
409  }
410  if(!rootFile_) {
411  initFile(false);
412  }
413  rewindFile();
414  firstFile_ = true;
415  }
416 
417  // Rewind to the beginning of the current file
418  void
420  if(rootFile_) rootFile_->rewind();
421  }
422 
423  void
425  //NOTE: Need to handle duplicate checker
426  // Also what if skipBadFiles_==true and the first time we succeeded but after a reset we fail?
428  firstFile_ = true;
431  if(rootFile_) break;
432  }
433  if(rootFile_) {
434  if(numberOfEventsToSkip_ != 0) {
436  }
437  }
438  }
439  }
440 
441  // Advance "offset" events. Offset can be positive or negative (or zero).
442  bool
444  assert (numberOfEventsToSkip_ == 0 || numberOfEventsToSkip_ == offset);
446  while(numberOfEventsToSkip_ != 0) {
447  bool atEnd = rootFile_->skipEvents(numberOfEventsToSkip_);
448  if((numberOfEventsToSkip_ > 0 || atEnd) && !nextFile(cache)) {
450  return false;
451  }
452  if(numberOfEventsToSkip_ < 0 && !previousFile(cache)) {
455  return false;
456  }
457  }
458  return true;
459  }
460 
461  bool
463  usingGoToEvent_ = true;
464  if(rootFile_) {
465  if(rootFile_->goToEvent(eventID)) {
466  return true;
467  }
468  // If only one input file, give up now, to save time.
469  if(rootFile_ && indexesIntoFiles_.size() == 1) {
470  return false;
471  }
472  // Save the current file and position so that we can restore them
473  // if we fail to restore the desired event
474  bool closedOriginalFile = false;
475  std::vector<FileCatalogItem>::const_iterator originalFile = fileIter_;
476  IndexIntoFile::IndexIntoFileItr originalPosition = rootFile_->indexIntoFileIter();
477 
478  // Look for item (run/lumi/event) in files previously opened without reopening unnecessary files.
479  typedef std::vector<boost::shared_ptr<IndexIntoFile> >::const_iterator Iter;
480  for(Iter it = indexesIntoFiles_.begin(), itEnd = indexesIntoFiles_.end(); it != itEnd; ++it) {
481  if(*it && (*it)->containsItem(eventID.run(), eventID.luminosityBlock(), eventID.event())) {
482  // We found it. Close the currently open file, and open the correct one.
483  fileIter_ = fileIterBegin_ + (it - indexesIntoFiles_.begin());
484  initFile(false);
485  // Now get the item from the correct file.
486  bool found = rootFile_->goToEvent(eventID);
487  assert (found);
488  return true;
489  }
490  }
491  // Look for item in files not yet opened.
492  for(Iter it = indexesIntoFiles_.begin(), itEnd = indexesIntoFiles_.end(); it != itEnd; ++it) {
493  if(!*it) {
494  fileIter_ = fileIterBegin_ + (it - indexesIntoFiles_.begin());
495  initFile(false);
496  closedOriginalFile = true;
497  if((*it)->containsItem(eventID.run(), eventID.luminosityBlock(), eventID.event())) {
498  if (rootFile_->goToEvent(eventID)) {
499  return true;
500  }
501  }
502  }
503  }
504  if(closedOriginalFile) {
505  fileIter_ = originalFile;
506  initFile(false);
507  rootFile_->setPosition(originalPosition);
508  }
509  }
510  return false;
511  }
512 
513  bool
515  // Look for item in files not yet opened.
516  typedef std::vector<boost::shared_ptr<IndexIntoFile> >::const_iterator Iter;
517  for(Iter it = indexesIntoFiles_.begin(), itEnd = indexesIntoFiles_.end(); it != itEnd; ++it) {
518  if(!*it) {
519  fileIter_ = fileIterBegin_ + (it - indexesIntoFiles_.begin());
520  initFile(false);
521  bool found = rootFile_->setEntryAtItem(run, lumi, event);
522  if(found) {
523  return true;
524  }
525  }
526  }
527  // Not found
528  return false;
529  }
530 
531  bool
533  // Attempt to find item in currently open input file.
534  bool found = currentFileFirst && rootFile_ && rootFile_->setEntryAtItem(run, lumi, event);
535  if(!found) {
536  // If only one input file, give up now, to save time.
537  if(currentFileFirst && rootFile_ && indexesIntoFiles_.size() == 1) {
538  return false;
539  }
540  // Look for item (run/lumi/event) in files previously opened without reopening unnecessary files.
541  typedef std::vector<boost::shared_ptr<IndexIntoFile> >::const_iterator Iter;
542  for(Iter it = indexesIntoFiles_.begin(), itEnd = indexesIntoFiles_.end(); it != itEnd; ++it) {
543  if(*it && (*it)->containsItem(run, lumi, event)) {
544  // We found it. Close the currently open file, and open the correct one.
545  std::vector<FileCatalogItem>::const_iterator currentIter = fileIter_;
546  fileIter_ = fileIterBegin_ + (it - indexesIntoFiles_.begin());
547  if(fileIter_ != currentIter) {
548  initFile(false);
549  }
550  // Now get the item from the correct file.
551  found = rootFile_->setEntryAtItem(run, lumi, event);
552  assert (found);
553  return true;
554  }
555  }
556  // Look for item in files not yet opened.
557  return skipToItemInNewFile(run, lumi, event);
558  }
559  return true;
560  }
561 
562  ProcessConfiguration const&
564  return input_.processConfiguration();
565  }
566 
567  int
569  return input_.remainingEvents();
570  }
571 
572  int
575  }
576 
579  return input_.productRegistryUpdate();
580  }
581 
582  boost::shared_ptr<ProductRegistry const>
584  return input_.productRegistry();
585  }
586 
587  void
588  RootInputFileSequence::dropUnwantedBranches_(std::vector<std::string> const& wantedBranches) {
589  std::vector<std::string> rules;
590  rules.reserve(wantedBranches.size() + 1);
591  rules.emplace_back("drop *");
592  for(std::vector<std::string>::const_iterator it = wantedBranches.begin(), itEnd = wantedBranches.end();
593  it != itEnd; ++it) {
594  rules.push_back("keep " + *it + "_*");
595  }
596  ParameterSet pset;
597  pset.addUntrackedParameter("inputCommands", rules);
598  groupSelectorRules_ = GroupSelectorRules(pset, "inputCommands", "InputSource");
599  }
600 
603  skipBadFiles_ = false;
604  if(fileIter_ == fileIterEnd_ || !rootFile_) {
606  throw Exception(errors::Configuration) << "RootInputFileSequence::readOneSequential(): no input files specified.\n";
607  }
609  initFile(false);
610  rootFile_->setAtEventEntry(-1);
611  }
612  rootFile_->nextEventEntry();
613  EventPrincipal* ep = rootFile_->clearAndReadCurrentEvent(rootFile_->secondaryEventPrincipal());
614  if(ep == 0) {
615  ++fileIter_;
616  if(fileIter_ == fileIterEnd_) {
617  return 0;
618  }
619  initFile(false);
620  rootFile_->setAtEventEntry(-1);
621  return readOneSequential();
622  }
623  return ep;
624  }
625 
629  throw Exception(errors::Configuration) << "RootInputFileSequence::readOneSequentialWithID(): no input files specified.\n";
630  }
631  skipBadFiles_ = false;
632  if(fileIter_ == fileIterEnd_ || !rootFile_ ||
633  rootFile_->indexIntoFileIter().run() != id.run() ||
634  rootFile_->indexIntoFileIter().lumi() != id.luminosityBlock()) {
635  bool found = skipToItem(id.run(), id.luminosityBlock(), 0, false);
636  if(!found) {
637  return 0;
638  }
639  }
640  bool nextFound = rootFile_->setEntryAtNextEventInLumi(id.run(), id.luminosityBlock());
641  EventPrincipal* ep = (nextFound ? rootFile_->clearAndReadCurrentEvent(rootFile_->secondaryEventPrincipal()) : 0);
642  if(ep == 0) {
643  bool found = skipToItemInNewFile(id.run(), id.luminosityBlock(), 0);
644  if(found) {
645  return readOneSequentialWithID(id);
646  }
647  }
648  return ep;
649  }
650 
653  skipBadFiles_ = false;
654  bool found = skipToItem(id.run(), id.luminosityBlock(), id.event());
655  if(!found) {
656  throw Exception(errors::NotFound) <<
657  "RootInputFileSequence::readOneSpecified(): Secondary Input file " <<
658  fileIter_->fileName() <<
659  " does not contain specified event:\n" << id << "\n";
660  }
661  EventPrincipal* ep = rootFile_->clearAndReadCurrentEvent(rootFile_->secondaryEventPrincipal());
662  assert(ep != 0);
663  return ep;
664  }
665 
669  throw Exception(errors::Configuration) << "RootInputFileSequence::readOneRandom(): no input files specified.\n";
670  }
671  if(!flatDistribution_) {
673  CLHEP::HepRandomEngine& engine = rng->getEngine();
674  flatDistribution_.reset(new CLHEP::RandFlat(engine));
675  }
676  skipBadFiles_ = false;
677  unsigned int currentSeqNumber = fileIter_ - fileIterBegin_;
678  while(eventsRemainingInFile_ == 0) {
679  fileIter_ = fileIterBegin_ + flatDistribution_->fireInt(fileCatalogItems().size());
680  unsigned int newSeqNumber = fileIter_ - fileIterBegin_;
681  if(newSeqNumber != currentSeqNumber) {
682  initFile(false);
683  currentSeqNumber = newSeqNumber;
684  }
685  eventsRemainingInFile_ = rootFile_->eventTree().entries();
686  if(eventsRemainingInFile_ == 0) {
687  throw Exception(errors::NotFound) <<
688  "RootInputFileSequence::readOneRandom(): Secondary Input file " << fileIter_->fileName() << " contains no events.\n";
689  }
690  rootFile_->setAtEventEntry(flatDistribution_->fireInt(eventsRemainingInFile_) - 1);
691  }
692  rootFile_->nextEventEntry();
693 
694  EventPrincipal* ep = rootFile_->clearAndReadCurrentEvent(rootFile_->secondaryEventPrincipal());
695  if(ep == 0) {
696  rootFile_->setAtEventEntry(0);
697  ep = rootFile_->clearAndReadCurrentEvent(rootFile_->secondaryEventPrincipal());
698  assert(ep != 0);
699  }
701  return ep;
702  }
703 
704  // bool RootFile::setEntryAtNextEventInLumi(RunNumber_t run, LuminosityBlockNumber_t lumi) {
705 
709  throw Exception(errors::Configuration) << "RootInputFileSequence::readOneRandomWithID(): no input files specified.\n";
710  }
711  if(!flatDistribution_) {
713  CLHEP::HepRandomEngine& engine = rng->getEngine();
714  flatDistribution_.reset(new CLHEP::RandFlat(engine));
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);
721  if(!found) {
722  return 0;
723  }
724  int eventsInLumi = 0;
725  while(rootFile_->setEntryAtNextEventInLumi(id.run(), id.luminosityBlock())) ++eventsInLumi;
726  found = skipToItem(id.run(), id.luminosityBlock(), 0);
727  assert(found);
728  int eventInLumi = flatDistribution_->fireInt(eventsInLumi);
729  for(int i = 0; i < eventInLumi; ++i) {
730  bool found = rootFile_->setEntryAtNextEventInLumi(id.run(), id.luminosityBlock());
731  assert(found);
732  }
733  }
734  bool nextFound = rootFile_->setEntryAtNextEventInLumi(id.run(), id.luminosityBlock());
735  EventPrincipal* ep = (nextFound ? rootFile_->clearAndReadCurrentEvent(rootFile_->secondaryEventPrincipal()) : 0);
736  if(ep == 0) {
737  bool found = rootFile_->setEntryAtItem(id.run(), id.luminosityBlock(), 0);
738  if(found) {
739  return readOneRandomWithID(id);
740  }
741  }
742  return ep;
743  }
744 
745  void
747  desc.addUntracked<unsigned int>("skipEvents", 0U)
748  ->setComment("Skip the first 'skipEvents' events that otherwise would have been processed.");
749  desc.addUntracked<bool>("noEventSort", true)
750  ->setComment("True: Process runs, lumis and events in the order they appear in the file (but see notes 1 and 2).\n"
751  "False: Process runs, lumis and events in each file in numerical order (run#, lumi#, event#) (but see note 3).\n"
752  "Note 1: Events within the same lumi will always be processed contiguously.\n"
753  "Note 2: Lumis within the same run will always be processed contiguously.\n"
754  "Note 3: Any sorting occurs independently in each input file (no sorting across input files).");
755  desc.addUntracked<bool>("skipBadFiles", false)
756  ->setComment("True: Ignore any missing or unopenable input file.\n"
757  "False: Throw exception if missing or unopenable input file.");
758  desc.addUntracked<unsigned int>("cacheSize", roottree::defaultCacheSize)
759  ->setComment("Size of ROOT TTree prefetch cache. Affects performance.");
760  desc.addUntracked<int>("treeMaxVirtualSize", -1)
761  ->setComment("Size of ROOT TTree TBasket cache. Affects performance.");
762  desc.addUntracked<unsigned int>("setRunNumber", 0U)
763  ->setComment("If non-zero, change number of first run to this number. Apply same offset to all runs. Allowed only for simulation.");
764  desc.addUntracked<bool>("dropDescendantsOfDroppedBranches", true)
765  ->setComment("If True, also drop on input any descendent of any branch dropped on input.");
766  std::string defaultString("permissive");
767  desc.addUntracked<std::string>("parametersMustMatch", defaultString)
768  ->setComment("'strict': Values of tracked parameters must be unique across all input files.\n"
769  "'permissive': Values of tracked parameters may differ across or within files.");
770  desc.addUntracked<std::string>("branchesMustMatch", defaultString)
771  ->setComment("'strict': Branches in each input file must match those in the first file.\n"
772  "'permissive': Branches in each input file may be any subset of those in the first file.");
773  desc.addUntracked<bool>("labelRawDataLikeMC", true)
774  ->setComment("If True: replace module label for raw data to match MC. Also use 'LHC' as process.");
775 
776  GroupSelectorRules::fillDescription(desc, "inputCommands");
779  }
780 
783  if(rootFile_) {
784  if(!rootFile_->wasLastEventJustRead()) {
786  }
787  std::vector<FileCatalogItem>::const_iterator itr(fileIter_);
788  if(itr != fileIterEnd_) ++itr;
789  if(itr != fileIterEnd_) {
791  }
793  }
795  }
796 
799  if(rootFile_) {
800  if(!rootFile_->wasFirstEventJustRead()) {
802  }
803  if(fileIter_ != fileIterBegin_) {
805  }
807  }
809  }
810 }
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_