CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RootFile.cc
Go to the documentation of this file.
1 /*----------------------------------------------------------------------
2 ----------------------------------------------------------------------*/
3 
4 #include "RootFile.h"
6 #include "DuplicateChecker.h"
7 #include "InputFile.h"
8 #include "ProvenanceAdaptor.h"
9 
39 
40 //used for backward compatibility
48 
49 #include "TROOT.h"
50 #include "Rtypes.h"
51 #include "TClass.h"
52 #include "TTree.h"
53 #include "TTreeCache.h"
54 
55 #include <algorithm>
56 #include <map>
57 #include <list>
58 
59 namespace edm {
60  namespace {
61  int
62  forcedRunOffset(RunNumber_t const& forcedRunNumber, IndexIntoFile::IndexIntoFileItr inxBegin, IndexIntoFile::IndexIntoFileItr inxEnd) {
63  if(inxBegin == inxEnd) return 0;
64  int defaultOffset = (inxBegin.run() != 0 ? 0 : 1);
65  int offset = (forcedRunNumber != 0U ? forcedRunNumber - inxBegin.run() : defaultOffset);
66  if(offset < 0) {
68  << "The value of the 'setRunNumber' parameter must not be\n"
69  << "less than the first run number in the first input file.\n"
70  << "'setRunNumber' was " << forcedRunNumber <<", while the first run was "
71  << forcedRunNumber - offset << ".\n";
72  }
73  return offset;
74  }
75  }
76 
77  // This is a helper class for IndexIntoFile.
79  public:
80  explicit RootFileEventFinder(RootTree& eventTree) : eventTree_(eventTree) {}
81  virtual ~RootFileEventFinder() {}
82  virtual
86  EventAuxiliary eventAux;
87  EventAuxiliary *pEvAux = &eventAux;
89  eventTree_.setEntryNumber(saveEntry);
90  return eventAux.event();
91  }
92 
93  private:
95  };
96 
97 
98 //---------------------------------------------------------------------
99  RootFile::RootFile(std::string const& fileName,
100  ProcessConfiguration const& processConfiguration,
101  std::string const& logicalFileName,
102  boost::shared_ptr<InputFile> filePtr,
103  boost::shared_ptr<EventSkipperByID> eventSkipperByID,
104  bool skipAnyEvents,
105  int remainingEvents,
106  int remainingLumis,
107  unsigned int treeCacheSize,
108  int treeMaxVirtualSize,
110  RunNumber_t const& forcedRunNumber,
111  bool noEventSort,
112  GroupSelectorRules const& groupSelectorRules,
113  bool secondaryFile,
114  boost::shared_ptr<DuplicateChecker> duplicateChecker,
115  bool dropDescendants,
116  std::vector<boost::shared_ptr<IndexIntoFile> > const& indexesIntoFiles,
117  std::vector<boost::shared_ptr<IndexIntoFile> >::size_type currentIndexIntoFile,
118  std::vector<ProcessHistoryID>& orderedProcessHistoryIDs,
119  bool usingGoToEvent) :
120  file_(fileName),
121  logicalFile_(logicalFileName),
122  processConfiguration_(processConfiguration),
123  filePtr_(filePtr),
124  eventSkipperByID_(eventSkipperByID),
125  fileFormatVersion_(),
126  fid_(),
127  indexIntoFileSharedPtr_(new IndexIntoFile),
128  indexIntoFile_(*indexIntoFileSharedPtr_),
129  orderedProcessHistoryIDs_(orderedProcessHistoryIDs),
130  indexIntoFileBegin_(indexIntoFile_.begin(noEventSort ? IndexIntoFile::firstAppearanceOrder : IndexIntoFile::numericalOrder)),
131  indexIntoFileEnd_(indexIntoFileBegin_),
132  indexIntoFileIter_(indexIntoFileBegin_),
133  eventProcessHistoryIDs_(),
134  eventProcessHistoryIter_(eventProcessHistoryIDs_.begin()),
135  skipAnyEvents_(skipAnyEvents),
136  noEventSort_(noEventSort),
137  whyNotFastClonable_(0),
138  hasNewlyDroppedBranch_(),
139  branchListIndexesUnchanged_(false),
140  eventAux_(),
141  eventTree_(filePtr_, InEvent, treeMaxVirtualSize, treeCacheSize, roottree::defaultLearningEntries),
142  lumiTree_(filePtr_, InLumi, treeMaxVirtualSize, roottree::defaultNonEventCacheSize, roottree::defaultNonEventLearningEntries),
143  runTree_(filePtr_, InRun, treeMaxVirtualSize, roottree::defaultNonEventCacheSize, roottree::defaultNonEventLearningEntries),
144  treePointers_(),
145  lastEventEntryNumberRead_(-1LL),
146  productRegistry_(),
147  branchIDLists_(),
148  processingMode_(processingMode),
149  forcedRunOffset_(0),
150  newBranchToOldBranch_(),
151  eventHistoryTree_(0),
152  eventSelectionIDs_(new EventSelectionIDVector),
153  branchListIndexes_(new BranchListIndexes),
154  history_(),
155  branchChildren_(new BranchChildren),
156  duplicateChecker_(duplicateChecker),
157  provenanceAdaptor_() {
158 
159  hasNewlyDroppedBranch_.assign(false);
160 
164 
165  // Read the metadata tree.
166  TTree *metaDataTree = dynamic_cast<TTree *>(filePtr_->Get(poolNames::metaDataTreeName().c_str()));
167  if(!metaDataTree)
168  throw Exception(errors::FileReadError) << "Could not find tree " << poolNames::metaDataTreeName()
169  << " in the input file.\n";
170 
171  // To keep things simple, we just read in every possible branch that exists.
172  // We don't pay attention to which branches exist in which file format versions
173 
175  if(metaDataTree->FindBranch(poolNames::fileFormatVersionBranchName().c_str()) != 0) {
176  TBranch *fft = metaDataTree->GetBranch(poolNames::fileFormatVersionBranchName().c_str());
177  fft->SetAddress(&fftPtr);
178  roottree::getEntry(fft, 0);
179  metaDataTree->SetBranchAddress(poolNames::fileFormatVersionBranchName().c_str(), &fftPtr);
180  }
181 
182  setRefCoreStreamer(0, !fileFormatVersion().splitProductIDs(), !fileFormatVersion().productIDIsInt()); // backward compatibility
183 
184  FileID *fidPtr = &fid_;
185  if(metaDataTree->FindBranch(poolNames::fileIdentifierBranchName().c_str()) != 0) {
186  metaDataTree->SetBranchAddress(poolNames::fileIdentifierBranchName().c_str(), &fidPtr);
187  }
188 
189  IndexIntoFile *iifPtr = &indexIntoFile_;
190  if(metaDataTree->FindBranch(poolNames::indexIntoFileBranchName().c_str()) != 0) {
191  metaDataTree->SetBranchAddress(poolNames::indexIntoFileBranchName().c_str(), &iifPtr);
192  }
193 
194  // Need to read to a temporary registry so we can do a translation of the BranchKeys.
195  // This preserves backward compatibility against friendly class name algorithm changes.
196  ProductRegistry inputProdDescReg;
197  ProductRegistry *ppReg = &inputProdDescReg;
198  metaDataTree->SetBranchAddress(poolNames::productDescriptionBranchName().c_str(), (&ppReg));
199 
200  typedef std::map<ParameterSetID, ParameterSetBlob> PsetMap;
201  PsetMap psetMap;
202  PsetMap *psetMapPtr = &psetMap;
203  if(metaDataTree->FindBranch(poolNames::parameterSetMapBranchName().c_str()) != 0) {
204  //backward compatibility
205  assert(!fileFormatVersion().parameterSetsTree());
206  metaDataTree->SetBranchAddress(poolNames::parameterSetMapBranchName().c_str(), &psetMapPtr);
207  } else {
208  assert(fileFormatVersion().parameterSetsTree());
209  TTree* psetTree = dynamic_cast<TTree *>(filePtr_->Get(poolNames::parameterSetsTreeName().c_str()));
210  if(0 == psetTree) {
211  throw Exception(errors::FileReadError) << "Could not find tree " << poolNames::parameterSetsTreeName()
212  << " in the input file.\n";
213  }
214 
215  typedef std::pair<ParameterSetID, ParameterSetBlob> IdToBlobs;
216  IdToBlobs idToBlob;
217  IdToBlobs* pIdToBlob = &idToBlob;
218  psetTree->SetBranchAddress(poolNames::idToParameterSetBlobsBranchName().c_str(), &pIdToBlob);
219 
220  std::auto_ptr<TTreeCache> psetTreeCache = roottree::trainCache(psetTree, *filePtr_, roottree::defaultNonEventCacheSize, "*");
221  filePtr_->SetCacheRead(psetTreeCache.get());
222  for(Long64_t i = 0; i != psetTree->GetEntries(); ++i) {
223  psetTree->GetEntry(i);
224  psetMap.insert(idToBlob);
225  }
226  filePtr_->SetCacheRead(0);
227  }
228 
229  // backward compatibility
231  ProcessHistoryRegistry::collection_type *pHistMapPtr = &pHistMap;
232  if(metaDataTree->FindBranch(poolNames::processHistoryMapBranchName().c_str()) != 0) {
233  metaDataTree->SetBranchAddress(poolNames::processHistoryMapBranchName().c_str(), &pHistMapPtr);
234  }
235 
237  ProcessHistoryRegistry::vector_type *pHistVectorPtr = &pHistVector;
238  if(metaDataTree->FindBranch(poolNames::processHistoryBranchName().c_str()) != 0) {
239  metaDataTree->SetBranchAddress(poolNames::processHistoryBranchName().c_str(), &pHistVectorPtr);
240  }
241 
242  ProcessConfigurationVector procConfigVector;
243  ProcessConfigurationVector* procConfigVectorPtr = &procConfigVector;
244  if(metaDataTree->FindBranch(poolNames::processConfigurationBranchName().c_str()) != 0) {
245  metaDataTree->SetBranchAddress(poolNames::processConfigurationBranchName().c_str(), &procConfigVectorPtr);
246  }
247 
248  std::auto_ptr<BranchIDListRegistry::collection_type> branchIDListsAPtr(new BranchIDListRegistry::collection_type);
249  BranchIDListRegistry::collection_type *branchIDListsPtr = branchIDListsAPtr.get();
250  if(metaDataTree->FindBranch(poolNames::branchIDListBranchName().c_str()) != 0) {
251  metaDataTree->SetBranchAddress(poolNames::branchIDListBranchName().c_str(), &branchIDListsPtr);
252  }
253 
254  BranchChildren* branchChildrenBuffer = branchChildren_.get();
255  if(metaDataTree->FindBranch(poolNames::productDependenciesBranchName().c_str()) != 0) {
256  metaDataTree->SetBranchAddress(poolNames::productDependenciesBranchName().c_str(), &branchChildrenBuffer);
257  }
258 
259  // backward compatibility
260  std::vector<EventProcessHistoryID> *eventHistoryIDsPtr = &eventProcessHistoryIDs_;
261  if(metaDataTree->FindBranch(poolNames::eventHistoryBranchName().c_str()) != 0) {
262  metaDataTree->SetBranchAddress(poolNames::eventHistoryBranchName().c_str(), &eventHistoryIDsPtr);
263  }
264 
265  if(metaDataTree->FindBranch(poolNames::moduleDescriptionMapBranchName().c_str()) != 0) {
266  if(metaDataTree->GetBranch(poolNames::moduleDescriptionMapBranchName().c_str())->GetSplitLevel() != 0) {
267  metaDataTree->SetBranchStatus((poolNames::moduleDescriptionMapBranchName() + ".*").c_str(), 0);
268  } else {
269  metaDataTree->SetBranchStatus(poolNames::moduleDescriptionMapBranchName().c_str(), 0);
270  }
271  }
272 
273  // Here we read the metadata tree
274  roottree::getEntry(metaDataTree, 0);
275 
277 
278  // Here we read the event history tree, if we have one.
280 
282  if(!fileFormatVersion().triggerPathsTracked()) {
283  ParameterSetConverter converter(psetMap, psetIdConverter, fileFormatVersion().parameterSetsByReference());
284  } else {
285  // Merge into the parameter set registry.
286  pset::Registry& psetRegistry = *pset::Registry::instance();
287  for(PsetMap::const_iterator i = psetMap.begin(), iEnd = psetMap.end(); i != iEnd; ++i) {
288  ParameterSet pset(i->second.pset());
289  pset.setID(i->first);
290  psetRegistry.insertMapped(pset);
291  }
292  }
293  if(!fileFormatVersion().splitProductIDs()) {
294  // Old provenance format input file. Create a provenance adaptor.
296  inputProdDescReg, pHistMap, pHistVector, procConfigVector, psetIdConverter, true));
297  // Fill in the branchIDLists branch from the provenance adaptor
298  branchIDLists_ = provenanceAdaptor_->branchIDLists();
299  } else {
300  if(!fileFormatVersion().triggerPathsTracked()) {
301  // New provenance format, but change in ParameterSet Format. Create a provenance adaptor.
303  inputProdDescReg, pHistMap, pHistVector, procConfigVector, psetIdConverter, false));
304  }
305  // New provenance format input file. The branchIDLists branch was read directly from the input file.
306  if(metaDataTree->FindBranch(poolNames::branchIDListBranchName().c_str()) == 0) {
308  << "Failed to find branchIDLists branch in metaData tree.\n";
309  }
310  branchIDLists_.reset(branchIDListsAPtr.release());
311  }
312 
313  // Merge into the hashed registries.
316 
318 
319  validateFile(secondaryFile, usingGoToEvent);
320 
321  // Read the parentage tree. Old format files are handled internally in readParentageTree().
323 
324  if(eventSkipperByID_ && eventSkipperByID_->somethingToSkip()) {
326  }
327 
328  initializeDuplicateChecker(indexesIntoFiles, currentIndexIntoFile);
330  indexIntoFileEnd_ = indexIntoFile_.end(noEventSort ? IndexIntoFile::firstAppearanceOrder : IndexIntoFile::numericalOrder);
331  forcedRunOffset_ = forcedRunOffset(forcedRunNumber, indexIntoFileBegin_, indexIntoFileEnd_);
333 
334  // Set product presence information in the product registry.
335  ProductRegistry::ProductList const& pList = inputProdDescReg.productList();
336  for(ProductRegistry::ProductList::const_iterator it = pList.begin(), itEnd = pList.end();
337  it != itEnd; ++it) {
338  BranchDescription const& prod = it->second;
339  treePointers_[prod.branchType()]->setPresence(prod);
340  }
341 
342  fillProductRegistryTransients(procConfigVector, inputProdDescReg);
343 
344  std::auto_ptr<ProductRegistry> newReg(new ProductRegistry);
345 
346  // Do the translation from the old registry to the new one
347  {
348  ProductRegistry::ProductList const& prodList = inputProdDescReg.productList();
349  for(ProductRegistry::ProductList::const_iterator it = prodList.begin(), itEnd = prodList.end();
350  it != itEnd; ++it) {
351  BranchDescription const& prod = it->second;
352  std::string newFriendlyName = friendlyname::friendlyName(prod.className());
353  if(newFriendlyName == prod.friendlyClassName()) {
354  newReg->copyProduct(prod);
355  } else {
356  if(fileFormatVersion().splitProductIDs()) {
358  << "Cannot change friendly class name algorithm without more development work\n"
359  << "to update BranchIDLists. Contact the framework group.\n";
360  }
361  BranchDescription newBD(prod);
362  newBD.updateFriendlyClassName();
363  newReg->copyProduct(newBD);
364  newBranchToOldBranch_.insert(std::make_pair(newBD.branchName(), prod.branchName()));
365  }
366  }
367  dropOnInput(*newReg, groupSelectorRules, dropDescendants, secondaryFile);
368  // freeze the product registry
369  newReg->setFrozen();
370  productRegistry_.reset(newReg.release());
371  }
372 
373 
374  // Set up information from the product registry.
375  ProductRegistry::ProductList const& prodList = productRegistry()->productList();
376  for(ProductRegistry::ProductList::const_iterator it = prodList.begin(), itEnd = prodList.end();
377  it != itEnd; ++it) {
378  BranchDescription const& prod = it->second;
379  treePointers_[prod.branchType()]->addBranch(it->first, prod,
381  }
382 
383  // Determine if this file is fast clonable.
384  setIfFastClonable(remainingEvents, remainingLumis);
385 
386  // Update the branch id info.
387  if(!secondaryFile) {
389  }
390 
391  setRefCoreStreamer(true); // backward compatibility
392 
393  // We are done with our initial reading of EventAuxiliary.
395 
396  // Tell the event tree to begin training at the next read.
398 
399  // Train the run and lumi trees.
400  runTree_.trainCache("*");
401  lumiTree_.trainCache("*");
402  }
403 
405  }
406 
407  void
409  // Called only for old format files.
410  if(!fileFormatVersion().perEventProductIDs()) return;
411  TTree* entryDescriptionTree = dynamic_cast<TTree*>(filePtr_->Get(poolNames::entryDescriptionTreeName().c_str()));
412  if(!entryDescriptionTree)
413  throw Exception(errors::FileReadError) << "Could not find tree " << poolNames::entryDescriptionTreeName()
414  << " in the input file.\n";
415 
416 
417  EntryDescriptionID idBuffer;
418  EntryDescriptionID* pidBuffer = &idBuffer;
419  entryDescriptionTree->SetBranchAddress(poolNames::entryDescriptionIDBranchName().c_str(), &pidBuffer);
420 
422 
423  EventEntryDescription entryDescriptionBuffer;
424  EventEntryDescription *pEntryDescriptionBuffer = &entryDescriptionBuffer;
425  entryDescriptionTree->SetBranchAddress(poolNames::entryDescriptionBranchName().c_str(), &pEntryDescriptionBuffer);
426 
427  // Fill in the parentage registry.
429 
430  for(Long64_t i = 0, numEntries = entryDescriptionTree->GetEntries(); i < numEntries; ++i) {
431  roottree::getEntry(entryDescriptionTree, i);
432  if(idBuffer != entryDescriptionBuffer.id())
433  throw Exception(errors::EventCorruption) << "Corruption of EntryDescription tree detected.\n";
434  oldregistry.insertMapped(entryDescriptionBuffer);
436  parents.parents() = entryDescriptionBuffer.parents();
437  registry.insertMapped(parents);
438  }
439  entryDescriptionTree->SetBranchAddress(poolNames::entryDescriptionIDBranchName().c_str(), 0);
440  entryDescriptionTree->SetBranchAddress(poolNames::entryDescriptionBranchName().c_str(), 0);
441  }
442 
443  void
445  if(!fileFormatVersion().splitProductIDs()) {
446  // Old format file.
448  return;
449  }
450  // New format file
451  TTree* parentageTree = dynamic_cast<TTree*>(filePtr_->Get(poolNames::parentageTreeName().c_str()));
452  if(!parentageTree)
453  throw Exception(errors::FileReadError) << "Could not find tree " << poolNames::parentageTreeName()
454  << " in the input file.\n";
455 
456  Parentage parentageBuffer;
457  Parentage *pParentageBuffer = &parentageBuffer;
458  parentageTree->SetBranchAddress(poolNames::parentageBranchName().c_str(), &pParentageBuffer);
459 
461 
462  for(Long64_t i = 0, numEntries = parentageTree->GetEntries(); i < numEntries; ++i) {
463  roottree::getEntry(parentageTree, i);
464  registry.insertMapped(parentageBuffer);
465  }
466  parentageTree->SetBranchAddress(poolNames::parentageBranchName().c_str(), 0);
467  }
468 
469  void
470  RootFile::setIfFastClonable(int remainingEvents, int remainingLumis) {
471  if(!fileFormatVersion().splitProductIDs()) {
473  return;
474  }
477  return;
478  }
479  // Find entry for first event in file
481  while(it != indexIntoFileEnd_ && it.getEntryType() != IndexIntoFile::kEvent) {
482  ++it;
483  }
484  if(it == indexIntoFileEnd_) {
486  return;
487  }
488 
489  // From here on, record all reasons we can't fast clone.
494  }
495  if(skipAnyEvents_) {
497  }
498  if(remainingEvents >= 0 && eventTree_.entries() > remainingEvents) {
500  }
501  if(remainingLumis >= 0 && lumiTree_.entries() > remainingLumis) {
503  }
504  // We no longer fast copy the EventAuxiliary branch, so there
505  // is no longer any need to disable fast copying because the run
506  // number is being modified. Also, this check did not work anyway
507  // because this function is called before forcedRunOffset_ is set.
508 
509  // if(forcedRunOffset_ != 0) {
510  // whyNotFastClonable_ += FileBlock::RunNumberModified;
511  // }
512  if(duplicateChecker_ &&
513  !duplicateChecker_->checkDisabled() &&
514  !duplicateChecker_->noDuplicatesInFile()) {
516  }
517  }
518 
519  boost::shared_ptr<FileBlock>
521  return boost::shared_ptr<FileBlock>(new FileBlock(fileFormatVersion(),
522  eventTree_.tree(),
524  lumiTree_.tree(),
526  runTree_.tree(),
527  runTree_.metaTree(),
530  file_,
532  branchChildren_));
533  }
534 
535  std::string const&
536  RootFile::newBranchToOldBranch(std::string const& newBranch) const {
537  std::map<std::string, std::string>::const_iterator it = newBranchToOldBranch_.find(newBranch);
538  if(it != newBranchToOldBranch_.end()) {
539  return it->second;
540  }
541  return newBranch;
542  }
543 
546  return indexIntoFileIter_;
547  }
548 
549  void
552  }
553 
554  bool
557  return false;
558  }
559  if(eventSkipperByID_ && eventSkipperByID_->somethingToSkip()) {
560 
561  // See first if the entire lumi or run is skipped, so we won't have to read the event Auxiliary in that case.
563  return true;
564  }
565 
566  // The Lumi is not skipped. If this is an event, see if the event is skipped.
571  eventAux_.id().event())) {
572  return true;
573  }
574  }
575 
576  // Skip runs with no lumis if either lumisToSkip or lumisToProcess have been set to select lumis
578  eventSkipperByID_->skippingLumis()) {
580 
581  // There are no lumis in this run, not even ones we will skip
582  if(iterLumi.peekAheadAtLumi() == IndexIntoFile::invalidLumi) {
583  return true;
584  }
585  // If we get here there are lumis in the run, check to see if we are skipping all of them
586  do {
587  if(!eventSkipperByID_->skipIt(iterLumi.run(), iterLumi.peekAheadAtLumi(), 0U)) {
588  return false;
589  }
590  }
591  while(iterLumi.skipLumiInRun());
592  return true;
593  }
594  }
595  return false;
596  }
597 
600  while(skipThisEntry()) {
603  }
606  }
607  else {
609  }
610  }
612  }
613 
614  bool
617  if(duplicateChecker_.get() == 0) {
618  return false;
619  }
621  return duplicateChecker_->isDuplicateAndCheckActive(indexIntoFileIter_.processHistoryIDIndex(),
623  }
624 
628  if(entryType == IndexIntoFile::kEnd) {
629  return IndexIntoFile::kEnd;
630  }
631  if(entryType == IndexIntoFile::kRun) {
632  return IndexIntoFile::kRun;
633  } else if(processingMode_ == InputSource::Runs) {
635  return getNextEntryTypeWanted();
636  }
637  if(entryType == IndexIntoFile::kLumi) {
638  return IndexIntoFile::kLumi;
641  return getNextEntryTypeWanted();
642  }
643  if(isDuplicateEvent()) {
645  return getNextEntryTypeWanted();
646  }
647  return IndexIntoFile::kEvent;
648  }
649 
650  bool
653  itr.advanceToEvent();
654  return itr.getEntryType() == IndexIntoFile::kEnd;
655  }
656 
657  bool
660  int phIndex;
663  IndexIntoFile::EntryNumber_t eventEntry;
664  itr.skipEventBackward(phIndex,
665  run,
666  lumi,
667  eventEntry);
668  itr.skipEventBackward(phIndex,
669  run,
670  lumi,
671  eventEntry);
672  return eventEntry == IndexIntoFile::invalidEntry;
673  }
674 
675  namespace {
676  typedef IndexIntoFile::EntryNumber_t EntryNumber_t;
677  struct RunItem {
678  RunItem(ProcessHistoryID const& phid, RunNumber_t const& run) :
679  phid_(phid), run_(run) {}
680  ProcessHistoryID phid_;
681  RunNumber_t run_;
682  };
683  struct RunItemSortByRun {
684  bool operator()(RunItem const& a, RunItem const& b) const {
685  return a.run_ < b.run_;
686  }
687  };
688  struct RunItemSortByRunPhid {
689  bool operator()(RunItem const& a, RunItem const& b) const {
690  return a.run_ < b.run_ || (!(b.run_ < a.run_) && a.phid_ < b.phid_);
691  }
692  };
693  struct LumiItem {
694  LumiItem(ProcessHistoryID const& phid, RunNumber_t const& run,
695  LuminosityBlockNumber_t const& lumi, EntryNumber_t const& entry) :
696  phid_(phid), run_(run), lumi_(lumi), firstEventEntry_(entry),
697  lastEventEntry_(entry == -1LL ? -1LL : entry + 1) {}
698  ProcessHistoryID phid_;
699  RunNumber_t run_;
701  EntryNumber_t firstEventEntry_;
702  EntryNumber_t lastEventEntry_;
703  };
704  struct LumiItemSortByRunLumi {
705  bool operator()(LumiItem const& a, LumiItem const& b) const {
706  return a.run_ < b.run_ || (!(b.run_ < a.run_) && a.lumi_ < b.lumi_);
707  }
708  };
709  struct LumiItemSortByRunLumiPhid {
710  bool operator()(LumiItem const& a, LumiItem const& b) const {
711  if(a.run_ < b.run_) return true;
712  if(b.run_ < a.run_) return false;
713  if(a.lumi_ < b.lumi_) return true;
714  if(b.lumi_ < a.lumi_) return false;
715  return a.phid_ < b.phid_;
716  }
717  };
718  }
719 
720  void
722  // This function is for backward compatibility.
723  // If reading a current format file, indexIntoFile_ is read from the input
724  // file and should always be there. Note that the algorithm below will work
725  // sometimes but often fail with the new format introduced in release 3_8_0.
726  // If it ever becomes necessary to rebuild IndexIntoFile from the new format,
727  // probably a separate function should be written to deal with the task.
728  // This is possible just not implemented yet.
729  assert(!fileFormatVersion().hasIndexIntoFile());
730 
731  typedef std::list<LumiItem> LumiList;
732  LumiList lumis; // (declare 1)
733 
734  typedef std::set<LuminosityBlockID> RunLumiSet;
735  RunLumiSet runLumiSet; // (declare 2)
736 
737  typedef std::list<RunItem> RunList;
738  RunList runs; // (declare 5)
739 
740  typedef std::set<RunNumber_t> RunSet;
741  RunSet runSet; // (declare 4)
742 
743  typedef std::set<RunItem, RunItemSortByRunPhid> RunItemSet;
744  RunItemSet runItemSet; // (declare 3)
745 
746  typedef std::map<RunNumber_t, ProcessHistoryID> PHIDMap;
747  PHIDMap phidMap;
748 
749  RunNumber_t prevRun = 0;
750  LuminosityBlockNumber_t prevLumi = 0;
751  ProcessHistoryID prevPhid;
752 
753  indexIntoFile_.unsortedEventNumbers().clear(); // should already be empty, just being careful
755 
756  // First, loop through the event tree.
757  while(eventTree_.next()) {
758  bool newRun = false;
759  bool newLumi = false;
761  fillHistory();
762 
763  // Save the event numbers as we loop through the event auxiliary to avoid
764  // having to read through the event auxiliary again later. These event numbers
765  // are not actually used in this function, but could be needed elsewhere.
767 
768  if(prevPhid != eventAux().processHistoryID() || prevRun != eventAux().run()) {
769  newRun = newLumi = true;
770  } else if(prevLumi != eventAux().luminosityBlock()) {
771  newLumi = true;
772  }
773  prevPhid = eventAux().processHistoryID();
774  prevRun = eventAux().run();
775  prevLumi = eventAux().luminosityBlock();
776  if(newLumi) {
777  lumis.push_back(LumiItem(eventAux().processHistoryID(),
778  eventAux().run(), eventAux().luminosityBlock(), eventTree_.entryNumber())); // (insert 1)
779  runLumiSet.insert(LuminosityBlockID(eventAux().run(), eventAux().luminosityBlock())); // (insert 2)
780  } else {
781  LumiItem& currentLumi = lumis.back();
782  assert(currentLumi.lastEventEntry_ == eventTree_.entryNumber());
783  ++currentLumi.lastEventEntry_;
784  }
785  if(newRun) {
786  // Insert run in list if it is not already there.
787  RunItem item(eventAux().processHistoryID(), eventAux().run());
788  if(runItemSet.insert(item).second) { // (check 3, insert 3)
789  runs.push_back(item); // (insert 5)
790  runSet.insert(eventAux().run()); // (insert 4)
791  phidMap.insert(std::make_pair(eventAux().run(), eventAux().processHistoryID()));
792  }
793  }
794  }
795  // now clean up.
799 
800  // Loop over run entries and fill information.
801 
802  typedef std::map<RunNumber_t, EntryNumber_t> RunMap;
803  RunMap runMap; // (declare 11)
804 
805  typedef std::vector<RunItem> RunVector;
806  RunVector emptyRuns; // (declare 12)
807 
808  if(runTree_.isValid()) {
809  while(runTree_.next()) {
810  // Note: adjacent duplicates will be skipped without an explicit check.
811  boost::shared_ptr<RunAuxiliary> runAux = fillRunAuxiliary();
812  if(runSet.insert(runAux->run()).second) { // (check 4, insert 4)
813  // This run was not assciated with any events or lumis.
814  emptyRuns.push_back(RunItem(runAux->processHistoryID(), runAux->run())); // (insert 12)
815  }
816  runMap.insert(std::make_pair(runAux->run(), runTree_.entryNumber())); // (insert 11)
817  phidMap.insert(std::make_pair(runAux->run(), runAux->processHistoryID()));
818  }
819  // now clean up.
821  }
822 
823  // Insert the ordered empty runs into the run list.
824  RunItemSortByRun runItemSortByRun;
825  stable_sort_all(emptyRuns, runItemSortByRun);
826 
827  RunList::iterator itRuns = runs.begin(), endRuns = runs.end();
828  for (RunVector::const_iterator i = emptyRuns.begin(), iEnd = emptyRuns.end(); i != iEnd; ++i) {
829  for (; itRuns != endRuns; ++itRuns) {
830  if(runItemSortByRun(*i, *itRuns)) {
831  break;
832  }
833  }
834  runs.insert(itRuns, *i);
835  }
836 
837  // Loop over luminosity block entries and fill information.
838 
839  typedef std::vector<LumiItem> LumiVector;
840  LumiVector emptyLumis; // (declare 7)
841 
842  typedef std::map<LuminosityBlockID, EntryNumber_t> RunLumiMap;
843  RunLumiMap runLumiMap; // (declare 6)
844 
845  if(lumiTree_.isValid()) {
846  while(lumiTree_.next()) {
847  // Note: adjacent duplicates will be skipped without an explicit check.
848  boost::shared_ptr<LuminosityBlockAuxiliary> lumiAux = fillLumiAuxiliary();
849  LuminosityBlockID lumiID = LuminosityBlockID(lumiAux->run(), lumiAux->luminosityBlock());
850  if(runLumiSet.insert(lumiID).second) { // (check 2, insert 2)
851  // This lumi was not associated with any events.
852  // Use the process history ID from the corresponding run. In cases of practical
853  // importance, this should be the correct process history ID, but it is possible
854  // to construct files where this is not the correct process history ID ...
855  PHIDMap::const_iterator iPhidMap = phidMap.find(lumiAux->run());
856  assert(iPhidMap != phidMap.end());
857  emptyLumis.push_back(LumiItem(iPhidMap->second, lumiAux->run(), lumiAux->luminosityBlock(), -1LL)); // (insert 7)
858  }
859  runLumiMap.insert(std::make_pair(lumiID, lumiTree_.entryNumber()));
860  }
861  // now clean up.
863  }
864 
865  // Insert the ordered empty lumis into the lumi list.
866  LumiItemSortByRunLumi lumiItemSortByRunLumi;
867  stable_sort_all(emptyLumis, lumiItemSortByRunLumi);
868 
869  LumiList::iterator itLumis = lumis.begin(), endLumis = lumis.end();
870  for (LumiVector::const_iterator i = emptyLumis.begin(), iEnd = emptyLumis.end(); i != iEnd; ++i) {
871  for (; itLumis != endLumis; ++itLumis) {
872  if(lumiItemSortByRunLumi(*i, *itLumis)) {
873  break;
874  }
875  }
876  lumis.insert(itLumis, *i);
877  }
878 
879  // Create a map of RunItems that gives the order of first appearance in the list.
880  // Also fill in the vector of process history IDs
881  typedef std::map<RunItem, int, RunItemSortByRunPhid> RunCountMap;
882  RunCountMap runCountMap; // Declare (17)
883  std::vector<ProcessHistoryID>& phids = indexIntoFile_.setProcessHistoryIDs();
884  assert(phids.empty());
885  std::vector<IndexIntoFile::RunOrLumiEntry>& entries = indexIntoFile_.setRunOrLumiEntries();
886  assert(entries.empty());
887  int rcount = 0;
888  for (RunList::iterator it = runs.begin(), itEnd = runs.end(); it != itEnd; ++it) {
889  RunCountMap::const_iterator countMapItem = runCountMap.find(*it);
890  if(countMapItem == runCountMap.end()) {
891  countMapItem = runCountMap.insert(std::make_pair(*it, rcount)).first; // Insert (17)
892  assert(countMapItem != runCountMap.end());
893  ++rcount;
894  }
895  std::vector<ProcessHistoryID>::const_iterator phidItem = find_in_all(phids, it->phid_);
896  if(phidItem == phids.end()) {
897  phids.push_back(it->phid_);
898  phidItem = phids.end() - 1;
899  }
900  entries.push_back(IndexIntoFile::RunOrLumiEntry(
901  countMapItem->second, // use (17)
902  -1LL,
903  runMap[it->run_], // use (11)
904  phidItem - phids.begin(),
905  it->run_,
906  0U,
907  -1LL,
908  -1LL));
909  }
910 
911  // Create a map of LumiItems that gives the order of first appearance in the list.
912  typedef std::map<LumiItem, int, LumiItemSortByRunLumiPhid> LumiCountMap;
913  LumiCountMap lumiCountMap; // Declare (19)
914  int lcount = 0;
915  for (LumiList::iterator it = lumis.begin(), itEnd = lumis.end(); it != itEnd; ++it) {
916  RunCountMap::const_iterator runCountMapItem = runCountMap.find(RunItem(it->phid_, it->run_));
917  assert(runCountMapItem != runCountMap.end());
918  LumiCountMap::const_iterator countMapItem = lumiCountMap.find(*it);
919  if(countMapItem == lumiCountMap.end()) {
920  countMapItem = lumiCountMap.insert(std::make_pair(*it, lcount)).first; // Insert (17)
921  assert(countMapItem != lumiCountMap.end());
922  ++lcount;
923  }
924  std::vector<ProcessHistoryID>::const_iterator phidItem = find_in_all(phids, it->phid_);
925  assert(phidItem != phids.end());
926  entries.push_back(IndexIntoFile::RunOrLumiEntry(
927  runCountMapItem->second,
928  countMapItem->second,
929  runLumiMap[LuminosityBlockID(it->run_, it->lumi_)],
930  phidItem - phids.begin(),
931  it->run_,
932  it->lumi_,
933  it->firstEventEntry_,
934  it->lastEventEntry_));
935  }
936  stable_sort_all(entries);
937  }
938 
939  void
940  RootFile::validateFile(bool secondaryFile, bool usingGoToEvent) {
941  if(!fid_.isValid()) {
943  }
944  if(!eventTree_.isValid()) {
946  "'Events' tree is corrupted or not present\n" << "in the input file.\n";
947  }
948 
949  if(fileFormatVersion().hasIndexIntoFile()) {
950  if(runTree().entries() > 0) {
951  assert(!indexIntoFile_.empty());
952  }
953  }
954  else {
955  assert(indexIntoFile_.empty());
957  }
958 
961  indexIntoFile_.setEventFinder(boost::shared_ptr<IndexIntoFile::EventFinder>(new RootFileEventFinder(eventTree_)));
962  // We fill the event numbers explicitly if we need to find events in closed files,
963  // such as for secondary files (or secondary sources) or if duplicate checking across files.
964  bool needEventNumbers = false;
965  bool needIndexesForDuplicateChecker = duplicateChecker_ && duplicateChecker_->checkingAllFiles() && !duplicateChecker_->checkDisabled();
966  if(secondaryFile || needIndexesForDuplicateChecker || usingGoToEvent) {
967  needEventNumbers = true;
968  }
969  bool needEventEntries = false;
970  if(secondaryFile || !noEventSort_) {
971  // We need event entries for sorting or for secondary files or sources.
972  needEventEntries = true;
973  }
974  indexIntoFile_.fillEventNumbersOrEntries(needEventNumbers, needEventEntries);
975  }
976 
977  void
978  RootFile::reportOpened(std::string const& inputType) {
979  // Report file opened.
980  std::string const label = "source";
981  std::string moduleName = "PoolSource";
982  filePtr_->inputFileOpened(
983  logicalFile_,
984  inputType,
985  moduleName,
986  label,
987  fid_.fid(),
989  }
990 
991  void
993  // Just to play it safe, zero all pointers to objects in the InputFile to be closed.
994  eventHistoryTree_ = 0;
995  for(RootTreePtrArray::iterator it = treePointers_.begin(), itEnd = treePointers_.end(); it != itEnd; ++it) {
996  (*it)->close();
997  (*it) = 0;
998  }
999  filePtr_->Close();
1000  filePtr_.reset();
1001  }
1002 
1003  void
1006  // Already read.
1007  return;
1008  }
1010  EventAuxiliary *pEvAux = &eventAux_;
1012  } else {
1013  // for backward compatibility.
1015  EventAux *pEvAux = &eventAux;
1016  eventTree_.fillAux<EventAux>(pEvAux);
1017  conversion(eventAux, eventAux_);
1018  }
1020  }
1021 
1022  void
1026  }
1027 
1028  void
1030  // We could consider doing delayed reading, but because we have to
1031  // store this History object in a different tree than the event
1032  // data tree, this is too hard to do in this first version.
1033 
1034  if(fileFormatVersion().eventHistoryBranch()) {
1035  // Lumi block number was not in EventID for the relevant releases.
1036  EventID id(eventAux().id().run(), 0, eventAux().id().event());
1037  if(eventProcessHistoryIter_->eventID() != id) {
1040  assert(eventProcessHistoryIter_->eventID() == id);
1041  }
1044  } else if(fileFormatVersion().eventHistoryTree()) {
1045  // for backward compatibility.
1046  History* pHistory = history_.get();
1047  TBranch* eventHistoryBranch = eventHistoryTree_->GetBranch(poolNames::eventHistoryBranchName().c_str());
1048  if(!eventHistoryBranch) {
1050  << "Failed to find history branch in event history tree.\n";
1051  }
1052  eventHistoryBranch->SetAddress(&pHistory);
1054  eventAux_.setProcessHistoryID(history_->processHistoryID());
1055  eventSelectionIDs_.reset(&history_->eventSelectionIDs(), do_nothing_deleter());
1056  branchListIndexes_.reset(&history_->branchListIndexes(), do_nothing_deleter());
1057  } else if(fileFormatVersion().noMetaDataTrees()) {
1058  // Current format
1060  TBranch* eventSelectionIDBranch = eventTree_.tree()->GetBranch(poolNames::eventSelectionsBranchName().c_str());
1061  assert(eventSelectionIDBranch != 0);
1062  eventTree_.fillBranchEntry(eventSelectionIDBranch, pESV);
1063  BranchListIndexes* pBLI = branchListIndexes_.get();
1064  TBranch* branchListIndexesBranch = eventTree_.tree()->GetBranch(poolNames::branchListIndexesBranchName().c_str());
1065  assert(branchListIndexesBranch != 0);
1066  eventTree_.fillBranchEntry(branchListIndexesBranch, pBLI);
1067  }
1068  if(provenanceAdaptor_) {
1069  eventAux_.setProcessHistoryID(provenanceAdaptor_->convertID(eventAux().processHistoryID()));
1070  for(EventSelectionIDVector::iterator i = eventSelectionIDs_->begin(), e = eventSelectionIDs_->end(); i != e; ++i) {
1071  (*i) = provenanceAdaptor_->convertID(*i);
1072  }
1073  }
1074  if(!fileFormatVersion().splitProductIDs()) {
1075  // old format. branchListIndexes_ must be filled in from the ProvenanceAdaptor.
1076  provenanceAdaptor_->branchListIndexes(*branchListIndexes_);
1077  }
1078  }
1079 
1080  boost::shared_ptr<LuminosityBlockAuxiliary>
1082  boost::shared_ptr<LuminosityBlockAuxiliary> lumiAuxiliary(new LuminosityBlockAuxiliary);
1083  if(fileFormatVersion().newAuxiliary()) {
1084  LuminosityBlockAuxiliary *pLumiAux = lumiAuxiliary.get();
1086  } else {
1087  LuminosityBlockAux lumiAux;
1088  LuminosityBlockAux *pLumiAux = &lumiAux;
1090  conversion(lumiAux, *lumiAuxiliary);
1091  }
1092  if(provenanceAdaptor_) {
1093  lumiAuxiliary->setProcessHistoryID(provenanceAdaptor_->convertID(lumiAuxiliary->processHistoryID()));
1094  }
1095  if(lumiAuxiliary->luminosityBlock() == 0 && !fileFormatVersion().runsAndLumis()) {
1096  lumiAuxiliary->id() = LuminosityBlockID(RunNumber_t(1), LuminosityBlockNumber_t(1));
1097  }
1098  return lumiAuxiliary;
1099  }
1100 
1101  boost::shared_ptr<RunAuxiliary>
1103  boost::shared_ptr<RunAuxiliary> runAuxiliary(new RunAuxiliary);
1104  if(fileFormatVersion().newAuxiliary()) {
1105  RunAuxiliary *pRunAux = runAuxiliary.get();
1106  runTree_.fillAux<RunAuxiliary>(pRunAux);
1107  } else {
1108  RunAux runAux;
1109  RunAux *pRunAux = &runAux;
1110  runTree_.fillAux<RunAux>(pRunAux);
1111  conversion(runAux, *runAuxiliary);
1112  }
1113  if(provenanceAdaptor_) {
1114  runAuxiliary->setProcessHistoryID(provenanceAdaptor_->convertID(runAuxiliary->processHistoryID()));
1115  }
1116  return runAuxiliary;
1117  }
1118 
1119  bool
1120  RootFile::skipEvents(int& offset) {
1121  while (offset > 0 && indexIntoFileIter_ != indexIntoFileEnd_) {
1122 
1123  int phIndexOfSkippedEvent = IndexIntoFile::invalidIndex;
1124  RunNumber_t runOfSkippedEvent = IndexIntoFile::invalidRun;
1127 
1128  indexIntoFileIter_.skipEventForward(phIndexOfSkippedEvent,
1129  runOfSkippedEvent,
1130  lumiOfSkippedEvent,
1131  skippedEventEntry);
1132 
1133  // At the end of the file and there were no more events to skip
1134  if(skippedEventEntry == IndexIntoFile::invalidEntry) break;
1135 
1136  if(eventSkipperByID_ && eventSkipperByID_->somethingToSkip()) {
1137  eventTree_.setEntryNumber(skippedEventEntry);
1139  if(eventSkipperByID_->skipIt(runOfSkippedEvent, lumiOfSkippedEvent, eventAux_.id().event())) {
1140  continue;
1141  }
1142  }
1143  if(duplicateChecker_ &&
1144  !duplicateChecker_->checkDisabled() &&
1145  !duplicateChecker_->noDuplicatesInFile()) {
1146 
1147  eventTree_.setEntryNumber(skippedEventEntry);
1149  if(duplicateChecker_->isDuplicateAndCheckActive(phIndexOfSkippedEvent,
1150  runOfSkippedEvent,
1151  lumiOfSkippedEvent,
1152  eventAux_.id().event(),
1153  file_)) {
1154  continue;
1155  }
1156  }
1157  --offset;
1158  }
1159 
1160  while(offset < 0) {
1161 
1162  if(duplicateChecker_) {
1163  duplicateChecker_->disable();
1164  }
1165 
1166  int phIndexOfEvent = IndexIntoFile::invalidIndex;
1169  EntryNumber_t eventEntry = IndexIntoFile::invalidEntry;
1170 
1171  indexIntoFileIter_.skipEventBackward(phIndexOfEvent,
1172  runOfEvent,
1173  lumiOfEvent,
1174  eventEntry);
1175 
1176  if(eventEntry == IndexIntoFile::invalidEntry) break;
1177 
1178  if(eventSkipperByID_ && eventSkipperByID_->somethingToSkip()) {
1179  eventTree_.setEntryNumber(eventEntry);
1181  if(eventSkipperByID_->skipIt(runOfEvent, lumiOfEvent, eventAux_.id().event())) {
1182  continue;
1183  }
1184  }
1185  ++offset;
1186  }
1188  }
1189 
1190  bool
1191  RootFile::goToEvent(EventID const& eventID) {
1192 
1194 
1195  if(duplicateChecker_) {
1196  duplicateChecker_->disable();
1197  }
1198 
1201 
1203  indexIntoFile_.findPosition(sortOrder, eventID.run(), eventID.luminosityBlock(), eventID.event());
1204 
1205  if(iter == indexIntoFile_.end(sortOrder)) {
1206  return false;
1207  }
1208  indexIntoFileIter_ = iter;
1209  return true;
1210  }
1211 
1212  // readEvent() is responsible for creating, and setting up, the
1213  // EventPrincipal.
1214  //
1215  // 1. create an EventPrincipal with a unique EventID
1216  // 2. For each entry in the provenance, put in one Group,
1217  // holding the Provenance for the corresponding EDProduct.
1218  // 3. set up the caches in the EventPrincipal to know about this
1219  // Group.
1220  //
1221  // We do *not* create the EDProduct instance (the equivalent of reading
1222  // the branch containing this EDProduct. That will be done by the Delayed Reader,
1223  // when it is asked to do so.
1224  //
1226  RootFile::readEvent(EventPrincipal& cache, boost::shared_ptr<RootFile> rootFilePtr, boost::shared_ptr<LuminosityBlockPrincipal> lb) {
1229  // Set the entry in the tree, and read the event at that entry.
1231  EventPrincipal* ep = readCurrentEvent(cache, rootFilePtr, lb);
1232 
1233  assert(ep != 0);
1234  assert(eventAux().run() == indexIntoFileIter_.run() + forcedRunOffset_);
1235  assert(eventAux().luminosityBlock() == indexIntoFileIter_.lumi());
1236 
1238  return ep;
1239  }
1240 
1241  // Reads event at the current entry in the event tree
1244  boost::shared_ptr<RootFile> rootFilePtr,
1245  boost::shared_ptr<LuminosityBlockPrincipal> lb) {
1246  if(!eventTree_.current()) {
1247  return 0;
1248  }
1250  if(!fileFormatVersion().lumiInEventID()) {
1251  //ugly, but will disappear when the backward compatibility is done with schema evolution.
1252  const_cast<EventID&>(eventAux_.id()).setLuminosityBlockNumber(eventAux_.oldLuminosityBlock());
1254  }
1255  fillHistory();
1257 
1258  std::auto_ptr<EventAuxiliary> aux(new EventAuxiliary(eventAux()));
1259  // We're not done ... so prepare the EventPrincipal
1260  cache.fillEventPrincipal(aux,
1261  lb,
1266 
1267  // report event read from file
1268  filePtr_->eventReadFromFile(eventID().run(), eventID().event());
1269  return &cache;
1270  }
1271 
1272  void
1274  eventTree_.setEntryNumber(entry);
1275  }
1276 
1277  boost::shared_ptr<RunAuxiliary>
1281  // Begin code for backward compatibility before the existence of run trees.
1282  if(!runTree_.isValid()) {
1283  // prior to the support of run trees.
1284  // RunAuxiliary did not contain a valid timestamp. Take it from the next event.
1285  if(eventTree_.next()) {
1287  // back up, so event will not be skipped.
1288  eventTree_.previous();
1289  }
1291  overrideRunNumber(run);
1292  return boost::shared_ptr<RunAuxiliary>(new RunAuxiliary(run.run(), eventAux().time(), Timestamp::invalidTimestamp()));
1293  }
1294  // End code for backward compatibility before the existence of run trees.
1296  boost::shared_ptr<RunAuxiliary> runAuxiliary = fillRunAuxiliary();
1297  assert(runAuxiliary->run() == indexIntoFileIter_.run());
1298  overrideRunNumber(runAuxiliary->id());
1299  filePtr_->reportInputRunNumber(runAuxiliary->run());
1300  if(runAuxiliary->beginTime() == Timestamp::invalidTimestamp()) {
1301  // RunAuxiliary did not contain a valid timestamp. Take it from the next event.
1302  if(eventTree_.next()) {
1304  // back up, so event will not be skipped.
1305  eventTree_.previous();
1306  }
1307  runAuxiliary->setBeginTime(eventAux().time());
1308  runAuxiliary->setEndTime(Timestamp::invalidTimestamp());
1309  }
1312  assert(runAuxiliary->processHistoryID() == phid);
1313  } else {
1314  runAuxiliary->setProcessHistoryID(phid);
1315  }
1316  return runAuxiliary;
1317  }
1318 
1319  boost::shared_ptr<RunPrincipal>
1320  RootFile::readRun_(boost::shared_ptr<RunPrincipal> rpCache) {
1323  // Begin code for backward compatibility before the existence of run trees.
1324  if(!runTree_.isValid()) {
1326  return rpCache;
1327  }
1328  // End code for backward compatibility before the existence of run trees.
1330  // Read in all the products now.
1331  rpCache->readImmediate();
1333  return rpCache;
1334  }
1335 
1336  boost::shared_ptr<LuminosityBlockAuxiliary>
1340  // Begin code for backward compatibility before the existence of lumi trees.
1341  if(!lumiTree_.isValid()) {
1342  if(eventTree_.next()) {
1344  // back up, so event will not be skipped.
1345  eventTree_.previous();
1346  }
1347 
1349  overrideRunNumber(lumi);
1350  return boost::shared_ptr<LuminosityBlockAuxiliary>(new LuminosityBlockAuxiliary(lumi.run(), lumi.luminosityBlock(), eventAux().time(), Timestamp::invalidTimestamp()));
1351  }
1352  // End code for backward compatibility before the existence of lumi trees.
1354  boost::shared_ptr<LuminosityBlockAuxiliary> lumiAuxiliary = fillLumiAuxiliary();
1355  assert(lumiAuxiliary->run() == indexIntoFileIter_.run());
1356  assert(lumiAuxiliary->luminosityBlock() == indexIntoFileIter_.lumi());
1357  overrideRunNumber(lumiAuxiliary->id());
1358  filePtr_->reportInputLumiSection(lumiAuxiliary->run(), lumiAuxiliary->luminosityBlock());
1359 
1360  if(lumiAuxiliary->beginTime() == Timestamp::invalidTimestamp()) {
1361  // LuminosityBlockAuxiliary did not contain a timestamp. Take it from the next event.
1362  if(eventTree_.next()) {
1364  // back up, so event will not be skipped.
1365  eventTree_.previous();
1366  }
1367  lumiAuxiliary->setBeginTime(eventAux().time());
1368  lumiAuxiliary->setEndTime(Timestamp::invalidTimestamp());
1369  }
1370  if(fileFormatVersion().processHistorySameWithinRun()) {
1372  assert(lumiAuxiliary->processHistoryID() == phid);
1373  } else {
1375  lumiAuxiliary->setProcessHistoryID(phid);
1376  }
1377  return lumiAuxiliary;
1378  }
1379 
1380  boost::shared_ptr<LuminosityBlockPrincipal>
1381  RootFile::readLumi(boost::shared_ptr<LuminosityBlockPrincipal> lbCache) {
1384  // Begin code for backward compatibility before the existence of lumi trees.
1385  if(!lumiTree_.isValid()) {
1387  return lbCache;
1388  }
1389  // End code for backward compatibility before the existence of lumi trees.
1391  lbCache->fillLuminosityBlockPrincipal(makeBranchMapper(lumiTree_, InLumi),
1393  // Read in all the products now.
1394  lbCache->readImmediate();
1396  return lbCache;
1397  }
1398 
1399  bool
1402  if(indexIntoFileIter_ == indexIntoFileEnd_) return false;
1404  return true;
1405  }
1406 
1407  bool
1410  if(indexIntoFileIter_ == indexIntoFileEnd_) return false;
1412  return true;
1413  }
1414 
1415  bool
1418  if(indexIntoFileIter_ == indexIntoFileEnd_) return false;
1420  return true;
1421  }
1422 
1423  void
1425  if(forcedRunOffset_ != 0) {
1426  id = RunID(id.run() + forcedRunOffset_);
1427  }
1428  if(id < RunID::firstValidRun()) id = RunID::firstValidRun();
1429  }
1430 
1431  void
1433  if(forcedRunOffset_ != 0) {
1434  id = LuminosityBlockID(id.run() + forcedRunOffset_, id.luminosityBlock());
1435  }
1436  if(RunID(id.run()) < RunID::firstValidRun()) id = LuminosityBlockID(RunID::firstValidRun().run(), id.luminosityBlock());
1437  }
1438 
1439  void
1440  RootFile::overrideRunNumber(EventID& id, bool isRealData) {
1441  if(forcedRunOffset_ != 0) {
1442  if(isRealData) {
1443  throw Exception(errors::Configuration, "RootFile::RootFile()")
1444  << "The 'setRunNumber' parameter of PoolSource cannot be used with real data.\n";
1445  }
1446  id = EventID(id.run() + forcedRunOffset_, id.luminosityBlock(), id.event());
1447  }
1448  if(RunID(id.run()) < RunID::firstValidRun()) {
1450  }
1451  }
1452 
1453 
1454  void
1456  // Read in the event history tree, if we have one...
1457  if(fileFormatVersion().eventHistoryTree()) {
1458  history_.reset(new History);
1459  eventHistoryTree_ = dynamic_cast<TTree*>(filePtr_->Get(poolNames::eventHistoryTreeName().c_str()));
1460  if(!eventHistoryTree_) {
1462  << "Failed to find the event history tree.\n";
1463  }
1464  }
1465  }
1466 
1467  void
1469  std::vector<boost::shared_ptr<IndexIntoFile> > const& indexesIntoFiles,
1470  std::vector<boost::shared_ptr<IndexIntoFile> >::size_type currentIndexIntoFile) {
1471  if(duplicateChecker_) {
1472  if(eventTree_.next()) {
1474  duplicateChecker_->inputFileOpened(eventAux().isRealData(),
1476  indexesIntoFiles,
1477  currentIndexIntoFile);
1478  }
1480  }
1481  }
1482 
1483  void
1484  RootFile::dropOnInput (ProductRegistry& reg, GroupSelectorRules const& rules, bool dropDescendants, bool secondaryFile) {
1485  // This is the selector for drop on input.
1486  GroupSelector groupSelector;
1487  groupSelector.initialize(rules, reg.allBranchDescriptions());
1488 
1490  // Do drop on input. On the first pass, just fill in a set of branches to be dropped.
1491  std::set<BranchID> branchesToDrop;
1492  for(ProductRegistry::ProductList::const_iterator it = prodList.begin(), itEnd = prodList.end();
1493  it != itEnd; ++it) {
1494  BranchDescription const& prod = it->second;
1495  if(!groupSelector.selected(prod)) {
1496  if(dropDescendants) {
1497  branchChildren_->appendToDescendants(prod.branchID(), branchesToDrop);
1498  } else {
1499  branchesToDrop.insert(prod.branchID());
1500  }
1501  }
1502  }
1503 
1504  // On this pass, actually drop the branches.
1505  std::set<BranchID>::const_iterator branchesToDropEnd = branchesToDrop.end();
1506  for(ProductRegistry::ProductList::iterator it = prodList.begin(), itEnd = prodList.end(); it != itEnd;) {
1507  BranchDescription const& prod = it->second;
1508  bool drop = branchesToDrop.find(prod.branchID()) != branchesToDropEnd;
1509  if(drop) {
1510  if(groupSelector.selected(prod)) {
1511  LogWarning("RootFile")
1512  << "Branch '" << prod.branchName() << "' is being dropped from the input\n"
1513  << "of file '" << file_ << "' because it is dependent on a branch\n"
1514  << "that was explicitly dropped.\n";
1515  }
1516  treePointers_[prod.branchType()]->dropBranch(newBranchToOldBranch(prod.branchName()));
1517  hasNewlyDroppedBranch_[prod.branchType()] = true;
1518  ProductRegistry::ProductList::iterator icopy = it;
1519  ++it;
1520  prodList.erase(icopy);
1521  } else {
1522  ++it;
1523  }
1524  }
1525 
1526  // Drop on input mergeable run and lumi products, this needs to be invoked for secondary file input
1527  if(secondaryFile) {
1528  for(ProductRegistry::ProductList::iterator it = prodList.begin(), itEnd = prodList.end(); it != itEnd;) {
1529  BranchDescription const& prod = it->second;
1530  if(prod.branchType() != InEvent) {
1531  TClass *cp = gROOT->GetClass(prod.wrappedName().c_str());
1532  boost::shared_ptr<EDProduct> dummy(static_cast<EDProduct *>(cp->New()));
1533  if(dummy->isMergeable()) {
1534  treePointers_[prod.branchType()]->dropBranch(newBranchToOldBranch(prod.branchName()));
1535  ProductRegistry::ProductList::iterator icopy = it;
1536  ++it;
1537  prodList.erase(icopy);
1538  } else {
1539  ++it;
1540  }
1541  }
1542  else ++it;
1543  }
1544  }
1545  }
1546 
1547  // backward compatibility
1548 
1549  namespace {
1550  boost::shared_ptr<BranchMapper>
1551  makeBranchMapperInRelease180(RootTree& rootTree, BranchType const& type, ProductRegistry const& preg) {
1552  boost::shared_ptr<BranchMapperWithReader> mapper(new BranchMapperWithReader());
1553  mapper->setDelayedRead(false);
1554 
1555  for(ProductRegistry::ProductList::const_iterator it = preg.productList().begin(),
1556  itEnd = preg.productList().end(); it != itEnd; ++it) {
1557  if(type == it->second.branchType() && !it->second.transient()) {
1558  TBranch *br = rootTree.branches().find(it->first)->second.provenanceBranch_;
1559  std::auto_ptr<BranchEntryDescription> pb(new BranchEntryDescription);
1560  BranchEntryDescription* ppb = pb.get();
1561  br->SetAddress(&ppb);
1562  roottree::getEntry(br, rootTree.entryNumber());
1564  // Not providing parentage!!!
1565  ProductProvenance entry(it->second.branchID(), status, ParentageID());
1566  mapper->insert(entry);
1567  mapper->insertIntoMap(it->second.oldProductID(), it->second.branchID());
1568  }
1569  }
1570  return mapper;
1571  }
1572 
1573  boost::shared_ptr<BranchMapper>
1574  makeBranchMapperInRelease200(RootTree& rootTree, BranchType const& type, ProductRegistry const& preg) {
1575  rootTree.fillStatus();
1576  boost::shared_ptr<BranchMapperWithReader> mapper(new BranchMapperWithReader());
1577  mapper->setDelayedRead(false);
1578  for(ProductRegistry::ProductList::const_iterator it = preg.productList().begin(),
1579  itEnd = preg.productList().end(); it != itEnd; ++it) {
1580  if(type == it->second.branchType() && !it->second.transient()) {
1581  std::vector<ProductStatus>::size_type index = it->second.oldProductID().oldID() - 1;
1582  // Not providing parentage!!!
1583  ProductProvenance entry(it->second.branchID(), rootTree.productStatuses()[index], ParentageID());
1584  mapper->insert(entry);
1585  mapper->insertIntoMap(it->second.oldProductID(), it->second.branchID());
1586  }
1587  }
1588  return mapper;
1589  }
1590 
1591  boost::shared_ptr<BranchMapper>
1592  makeBranchMapperInRelease210(RootTree& rootTree, BranchType const& type) {
1593  boost::shared_ptr<BranchMapperWithReader> mapper(new BranchMapperWithReader());
1594  mapper->setDelayedRead(false);
1595  if(type == InEvent) {
1596  std::auto_ptr<std::vector<EventEntryInfo> > infoVector(new std::vector<EventEntryInfo>);
1597  std::vector<EventEntryInfo> *pInfoVector = infoVector.get();
1598  rootTree.branchEntryInfoBranch()->SetAddress(&pInfoVector);
1599  setRefCoreStreamer(0, true, false);
1600  roottree::getEntry(rootTree.branchEntryInfoBranch(), rootTree.entryNumber());
1601  setRefCoreStreamer(true);
1602  for(std::vector<EventEntryInfo>::const_iterator it = infoVector->begin(), itEnd = infoVector->end();
1603  it != itEnd; ++it) {
1604  EventEntryDescription eed;
1605  EntryDescriptionRegistry::instance()->getMapped(it->entryDescriptionID(), eed);
1606  Parentage parentage(eed.parents());
1607  ProductProvenance entry(it->branchID(), it->productStatus(), parentage.id());
1608  mapper->insert(entry);
1609  mapper->insertIntoMap(it->productID(), it->branchID());
1610  }
1611  } else {
1612  std::auto_ptr<std::vector<RunLumiEntryInfo> > infoVector(new std::vector<RunLumiEntryInfo>);
1613  std::vector<RunLumiEntryInfo> *pInfoVector = infoVector.get();
1614  rootTree.branchEntryInfoBranch()->SetAddress(&pInfoVector);
1615  setRefCoreStreamer(0, true, false);
1616  roottree::getEntry(rootTree.branchEntryInfoBranch(), rootTree.entryNumber());
1617  setRefCoreStreamer(true);
1618  for(std::vector<RunLumiEntryInfo>::const_iterator it = infoVector->begin(), itEnd = infoVector->end();
1619  it != itEnd; ++it) {
1620  ProductProvenance entry(it->branchID(), it->productStatus(), ParentageID());
1621  mapper->insert(entry);
1622  }
1623  }
1624  return mapper;
1625  }
1626 
1627  boost::shared_ptr<BranchMapper>
1628  makeBranchMapperInRelease300(RootTree& rootTree) {
1629  boost::shared_ptr<BranchMapperWithReader> mapper(
1630  new BranchMapperWithReader(&rootTree));
1631  mapper->setDelayedRead(true);
1632  return mapper;
1633  }
1634  }
1635 
1636  boost::shared_ptr<BranchMapper>
1637  RootFile::makeBranchMapper(RootTree& rootTree, BranchType const& type) const {
1638  if(fileFormatVersion().splitProductIDs()) {
1639  return makeBranchMapperInRelease300(rootTree);
1640  } else if(fileFormatVersion().perEventProductIDs()) {
1641  return makeBranchMapperInRelease210(rootTree, type);
1642  } else if(fileFormatVersion().eventHistoryTree()) {
1643  return makeBranchMapperInRelease200(rootTree, type, *productRegistry_);
1644  } else {
1645  return makeBranchMapperInRelease180(rootTree, type, *productRegistry_);
1646  }
1647  }
1648  // end backward compatibility
1649 }
RunNumber_t run() const
Definition: EventID.h:42
EventID const & eventID() const
Definition: RootFile.h:89
Int_t getEntry(TBranch *branch, EntryNumber entryNumber)
Definition: RootTree.cc:251
void fillEventNumbersOrEntries(bool needEventNumbers, bool needEventEntries) const
type
Definition: HCALResponse.h:22
EventNumber_t event() const
Definition: EventID.h:44
std::string const & idToParameterSetBlobsBranchName()
Definition: BranchType.cc:239
int i
Definition: DBlmapReader.cc:9
boost::shared_ptr< BranchChildren > branchChildren_
Definition: RootFile.h:190
bool isRealData() const
boost::shared_ptr< BranchListIndexes > branchListIndexes_
Definition: RootFile.h:188
std::string const & BranchTypeToAuxiliaryBranchName(BranchType const &branchType)
Definition: BranchType.cc:108
unsigned int const defaultNonEventLearningEntries
Definition: RootTree.h:42
void doneFileInitialization() const
Clears the temporary vector of event numbers to reduce memory usage.
static int const invalidIndex
boost::shared_ptr< FileBlock > createFileBlock() const
Definition: RootFile.cc:520
TPRegexp parents
Definition: eve_filter.cc:24
BranchType const & branchType() const
std::string const & parentageTreeName()
Definition: BranchType.cc:148
static LuminosityBlockID firstValidLuminosityBlock()
std::string const & entryDescriptionBranchName()
Definition: BranchType.cc:143
bool skipEvents(int &offset)
Definition: RootFile.cc:1120
FileFormatVersion fileFormatVersion() const
Definition: RootFile.h:93
boost::array< bool, NumBranchTypes > const & hasNewlyDroppedBranch() const
Definition: RootFile.h:95
const std::string & label
Definition: MVAComputer.cc:186
ForwardSequence::const_iterator lower_bound_all(ForwardSequence const &s, Datum const &d)
wrappers for std::lower_bound
Definition: Algorithms.h:91
byte_t ProductStatus
Definition: ProductStatus.h:15
bool branchListIndexesUnchanged() const
Definition: RootFile.h:96
RunNumber_t run() const
Definition: RunID.h:44
std::vector< std::string > const & branchNames() const
Definition: RootTree.h:89
unsigned int EventNumber_t
Definition: EventID.h:30
std::string & branchName() const
boost::array< bool, NumBranchTypes > hasNewlyDroppedBranch_
Definition: RootFile.h:173
void readParentageTree()
Definition: RootFile.cc:444
int whyNotFastClonable_
Definition: RootFile.h:172
tuple lumi
Definition: fjr2json.py:41
std::map< std::string, std::string > newBranchToOldBranch_
Definition: RootFile.h:185
IndexIntoFile::EntryType getEntryTypeWithSkipping()
Definition: RootFile.cc:599
bool empty() const
True if no runs, lumis, or events are in the file.
std::map< BranchKey, BranchDescription > ProductList
void fillEventAuxiliary()
Definition: RootFile.cc:1023
static bool updateFromInput(BranchIDLists const &bidlists, std::string const &fileName)
bool setEntryAtRun(RunNumber_t run)
Definition: RootFile.cc:1416
RootTree lumiTree_
Definition: RootFile.h:177
Timestamp const & time() const
EntryNumber const & entries() const
Definition: RootTree.h:87
RunNumber_t run() const
bool getMapped(key_type const &k, value_type &result) const
void setRefCoreStreamer(bool resetAll=false)
std::string const & fileFormatVersionBranchName()
Definition: BranchType.cc:202
IndexIntoFileItr begin(SortOrder sortOrder) const
std::vector< BranchID > const & parents() const
std::string const & eventSelectionsBranchName()
Definition: BranchType.cc:227
InputSource::ProcessingMode processingMode_
Definition: RootFile.h:183
boost::shared_ptr< History > history_
Definition: RootFile.h:189
IndexIntoFile::IndexIntoFileItr indexIntoFileIter_
Definition: RootFile.h:167
boost::shared_ptr< RunAuxiliary > fillRunAuxiliary()
Definition: RootFile.cc:1102
void stable_sort_all(RandomAccessSequence &s)
wrappers for std::stable_sort
Definition: Algorithms.h:135
static RunID firstValidRun()
Definition: RunID.h:82
LuminosityBlockNumber_t lumi() const
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:43
void trainCache(char const *branchNames)
Definition: RootTree.cc:231
bool insertMapped(value_type const &v)
uint16_t size_type
unsigned int LuminosityBlockNumber_t
Definition: EventID.h:31
IndexIntoFileItr findRunPosition(RunNumber_t run) const
Same as findPosition.
long long EntryNumber_t
static int position[TOTALCHAMBERS][3]
Definition: ReadPGInfo.cc:509
void fillProductRegistryTransients(std::vector< ProcessConfiguration > const &pcVec, ProductRegistry const &preg, bool okToRegister=false)
BranchType
Definition: BranchType.h:11
bool previous()
Definition: RootTree.h:82
IndexIntoFileItr findPosition(RunNumber_t run, LuminosityBlockNumber_t lumi=0U, EventNumber_t event=0U) const
std::vector< EventSelectionID > EventSelectionIDVector
LuminosityBlockNumber_t luminosityBlock() const
FileFormatVersion fileFormatVersion_
Definition: RootFile.h:160
TTree const * metaTree() const
Definition: RootTree.h:115
std::string const & parameterSetsTreeName()
Definition: BranchType.cc:235
void setPosition(IndexIntoFile::IndexIntoFileItr const &position)
Definition: RootFile.cc:550
ProcessConfigurationRegistry::vector_type ProcessConfigurationVector
std::vector< BranchID > const & parents() const
Definition: Parentage.h:39
ProductList const & productList() const
U second(std::pair< T, U > const &p)
std::vector< EventProcessHistoryID >::const_iterator eventProcessHistoryIter_
Definition: RootFile.h:169
bool skipThisEntry()
Definition: RootFile.cc:555
IndexIntoFile::EntryType getNextEntryTypeWanted()
Definition: RootFile.cc:626
TTree const * tree() const
Definition: RootTree.h:113
RootFile(std::string const &fileName, ProcessConfiguration const &processConfiguration, std::string const &logicalFileName, boost::shared_ptr< InputFile > filePtr, boost::shared_ptr< EventSkipperByID > eventSkipperByID, bool skipAnyEvents, int remainingEvents, int remainingLumis, unsigned int treeCacheSize, int treeMaxVirtualSize, InputSource::ProcessingMode processingMode, RunNumber_t const &forcedRunNumber, bool noEventSort, GroupSelectorRules const &groupSelectorRules, bool secondaryFile, boost::shared_ptr< DuplicateChecker > duplicateChecker, bool dropDescendantsOfDroppedProducts, std::vector< boost::shared_ptr< IndexIntoFile > > const &indexesIntoFiles, std::vector< boost::shared_ptr< IndexIntoFile > >::size_type currentIndexIntoFile, std::vector< ProcessHistoryID > &orderedProcessHistoryIDs, bool usingGoToEvent)
Definition: RootFile.cc:99
FileID fid_
Definition: RootFile.h:161
boost::shared_ptr< DuplicateChecker > duplicateChecker_
Definition: RootFile.h:191
std::auto_ptr< TTreeCache > trainCache(TTree *tree, InputFile &file, unsigned int cacheSize, char const *branchNames)
Definition: RootTree.cc:275
std::string const logicalFile_
Definition: RootFile.h:156
std::map< key_type, value_type > collection_type
std::vector< BranchListIndex > BranchListIndexes
IndexIntoFile::IndexIntoFileItr indexIntoFileEnd_
Definition: RootFile.h:166
std::string const & processHistoryMapBranchName()
Definition: BranchType.cc:182
std::vector< ProcessHistoryID > & setProcessHistoryIDs()
bool next()
Definition: RootTree.h:81
CreatorStatus const & creatorStatus() const
bool noEventSort_
Definition: RootFile.h:171
std::string const & className() const
bool wasLastEventJustRead() const
Definition: RootFile.cc:651
bool setEntryAtLumi(RunNumber_t run, LuminosityBlockNumber_t lumi)
Definition: RootFile.cc:1408
std::string friendlyName(std::string const &iFullName)
static RunNumber_t const invalidRun
std::string const & entryDescriptionTreeName()
Definition: BranchType.cc:135
void close()
Definition: RootFile.cc:992
EventPrincipal * readEvent(EventPrincipal &cache, boost::shared_ptr< RootFile > rootFilePtr, boost::shared_ptr< LuminosityBlockPrincipal > lb=boost::shared_ptr< LuminosityBlockPrincipal >())
Definition: RootFile.cc:1226
std::string const & fid() const
Definition: FileID.h:19
RootTree const & runTree() const
Definition: RootFile.h:92
IndexIntoFile::EntryNumber_t lastEventEntryNumberRead_
Definition: RootFile.h:180
void copyPosition(IndexIntoFileItr const &position)
Copy the position without modifying the pointer to the IndexIntoFile or size.
std::string const & indexIntoFileBranchName()
Definition: BranchType.cc:217
IndexIntoFileItr end(SortOrder sortOrder) const
Used to end an iteration over the Runs, Lumis, and Events in a file.
virtual EventNumber_t getEventNumberOfEntry(roottree::EntryNumber entry) const
Definition: RootFile.cc:83
std::string const & eventHistoryBranchName()
Definition: BranchType.cc:222
void skipEventBackward(int &phIndexOfEvent, RunNumber_t &runOfEvent, LuminosityBlockNumber_t &lumiOfEvent, EntryNumber_t &eventEntry)
Long64_t numEntries(TFile *hdl, std::string const &trname)
Definition: CollUtil.cc:50
std::pair< std::string, MonitorElement * > entry
Definition: ME_MAP.h:8
EventAuxiliary const & eventAux() const
Definition: RootFile.h:85
bool eventHistoryTree() const
int whyNotFastClonable() const
Definition: RootFile.h:94
ProductStatus neverCreated()
Definition: ProductStatus.h:18
RunNumber_t run() const
bool skipAnyEvents_
Definition: RootFile.h:170
RootTree eventTree_
Definition: RootFile.h:176
std::vector< BranchDescription const * > allBranchDescriptions() const
std::map< ParameterSetID, ParameterSetID > ParameterSetIdConverter
bool isValid() const
Definition: FileID.h:18
bool iterationWillBeInEntryOrder(SortOrder sortOrder) const
Used to determine whether or not to disable fast cloning.
std::string const & friendlyClassName() const
BranchID const & branchID() const
void dropOnInput(ProductRegistry &reg, GroupSelectorRules const &rules, bool dropDescendants, bool secondaryFile)
Definition: RootFile.cc:1484
std::string const & metaDataTreeName()
Definition: BranchType.cc:157
std::string & wrappedName() const
void fillHistory()
Definition: RootFile.cc:1029
bool isDuplicateEvent()
Definition: RootFile.cc:615
LuminosityBlockNumber_t oldLuminosityBlock() const
EntryDescriptionID id() const
unsigned int offset(bool)
void insertCollection(collection_type const &c)
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
bool wasFirstEventJustRead() const
Definition: RootFile.cc:658
std::string const & parameterSetMapBranchName()
Definition: BranchType.cc:172
Hash< ProcessHistoryType > ProcessHistoryID
EventPrincipal * readCurrentEvent(EventPrincipal &cache, boost::shared_ptr< RootFile > rootFilePtr, boost::shared_ptr< LuminosityBlockPrincipal > lb=boost::shared_ptr< LuminosityBlockPrincipal >())
Definition: RootFile.cc:1243
const int drop
boost::shared_ptr< EventSelectionIDVector > eventSelectionIDs_
Definition: RootFile.h:187
std::string const & processHistoryBranchName()
Definition: BranchType.cc:187
IndexIntoFile & indexIntoFile_
Definition: RootFile.h:163
RootTree runTree_
Definition: RootFile.h:178
EntryNumber const & entryNumber() const
Definition: RootTree.h:86
bool goToEvent(EventID const &eventID)
Definition: RootFile.cc:1191
ProductStatus present()
Definition: ProductStatus.h:17
void setAtEventEntry(IndexIntoFile::EntryNumber_t entry)
Definition: RootFile.cc:1273
void fixIndexes(std::vector< ProcessHistoryID > &processHistoryIDs)
std::vector< RunOrLumiEntry > & setRunOrLumiEntries()
void conversion(EventAux const &from, EventAuxiliary &to)
Definition: EventAux.cc:9
std::vector< EventNumber_t > & unsortedEventNumbers() const
void fillEventPrincipal(std::auto_ptr< EventAuxiliary > aux, boost::shared_ptr< LuminosityBlockPrincipal > lbp, boost::shared_ptr< EventSelectionIDVector > eventSelectionIDs=boost::shared_ptr< EventSelectionIDVector >(new EventSelectionIDVector), boost::shared_ptr< BranchListIndexes > branchListIndexes=boost::shared_ptr< BranchListIndexes >(new BranchListIndexes), boost::shared_ptr< BranchMapper > mapper=boost::shared_ptr< BranchMapper >(new BranchMapper), boost::shared_ptr< DelayedReader > rtrv=boost::shared_ptr< DelayedReader >(new NoDelayedReader))
static Timestamp const & invalidTimestamp()
Definition: Timestamp.cc:83
static EntryNumber_t const invalidEntry
boost::shared_ptr< DelayedReader > makeDelayedReader(FileFormatVersion const &fileFormatVersion, boost::shared_ptr< RootFile > rootFilePtr=boost::shared_ptr< RootFile >()) const
Definition: RootTree.cc:133
ForwardSequence::const_iterator find_in_all(ForwardSequence const &s, Datum const &d)
wrappers for std::find
Definition: Algorithms.h:32
void setIfFastClonable(int remainingEvents, int remainingLumis)
Definition: RootFile.cc:470
void fillBranchEntry(TBranch *branch, T *&pbuf)
Definition: RootTree.h:108
static LuminosityBlockNumber_t const invalidLumi
IndexIntoFileItr findLumiPosition(RunNumber_t run, LuminosityBlockNumber_t lumi) const
void readEntryDescriptionTree()
Definition: RootFile.cc:408
std::string const & parentageBranchName()
Definition: BranchType.cc:152
boost::shared_ptr< LuminosityBlockAuxiliary > fillLumiAuxiliary()
Definition: RootFile.cc:1081
boost::shared_ptr< LuminosityBlockAuxiliary > readLuminosityBlockAuxiliary_()
Definition: RootFile.cc:1337
double b
Definition: hdecay.h:120
LuminosityBlockNumber_t luminosityBlock() const
bool processHistorySameWithinRun() const
ProcessHistoryID const & processHistoryID(int i) const
ProductList & productListUpdator()
void setProcessHistoryID(ProcessHistoryID const &phid)
bool isValid() const
Definition: RootTree.cc:66
std::string const & productDescriptionBranchName()
Definition: BranchType.cc:162
std::string const & processConfigurationBranchName()
Definition: BranchType.cc:192
IndexIntoFile::IndexIntoFileItr indexIntoFileBegin_
Definition: RootFile.h:165
ProcessHistoryID const & processHistoryID() const
EventID const & id() const
bool branchListIndexesUnchanged_
Definition: RootFile.h:174
void setEventFinder(boost::shared_ptr< EventFinder > ptr) const
void fillIndexIntoFile()
Definition: RootFile.cc:721
#define begin
Definition: vmac.h:31
author Stefano ARGIRO author Bill Tanenbaum
bool selected(BranchDescription const &desc) const
unsigned int const defaultNonEventCacheSize
Definition: RootTree.h:40
std::vector< value_type > vector_type
RootTreePtrArray treePointers_
Definition: RootFile.h:179
void fillEventNumbers() const
double a
Definition: hdecay.h:121
boost::shared_ptr< ProductRegistry const > productRegistry_
Definition: RootFile.h:181
Long64_t EntryNumber
Definition: RootTree.h:43
boost::shared_ptr< BranchMapper > makeBranchMapper(RootTree &rootTree, BranchType const &type) const
Definition: RootFile.cc:1637
std::vector< ProcessHistoryID > & orderedProcessHistoryIDs_
Definition: RootFile.h:164
std::string const & productDependenciesBranchName()
Definition: BranchType.cc:167
void setNumberOfEvents(EntryNumber_t nevents) const
void overrideRunNumber(RunID &id)
Definition: RootFile.cc:1424
std::string const & entryDescriptionIDBranchName()
Definition: BranchType.cc:139
BranchMap const & branches() const
Definition: RootTree.cc:130
boost::shared_ptr< RunPrincipal > readRun_(boost::shared_ptr< RunPrincipal > rpCache)
Definition: RootFile.cc:1320
boost::shared_ptr< InputFile > filePtr_
Definition: RootFile.h:158
void initializeDuplicateChecker(std::vector< boost::shared_ptr< IndexIntoFile > > const &indexesIntoFiles, std::vector< boost::shared_ptr< IndexIntoFile > >::size_type currentIndexIntoFile)
Definition: RootFile.cc:1468
std::string const & branchIDListBranchName()
Definition: BranchType.cc:197
unsigned int RunNumber_t
Definition: EventRange.h:32
std::string const & branchListIndexesBranchName()
Definition: BranchType.cc:231
static ThreadSafeRegistry * instance()
boost::shared_ptr< ProvenanceAdaptor > provenanceAdaptor_
Definition: RootFile.h:192
EventAuxiliary eventAux_
Definition: RootFile.h:175
void fillThisEventAuxiliary()
Definition: RootFile.cc:1004
void resetTraining()
Definition: RootTree.h:127
bool setEntryAtEvent(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event)
Definition: RootFile.cc:1400
boost::shared_ptr< BranchIDListRegistry::collection_type const > branchIDLists_
Definition: RootFile.h:182
std::string const & eventHistoryTreeName()
Definition: BranchType.cc:252
static Interceptor::Registry registry("Interceptor")
tuple status
Definition: ntuplemaker.py:245
RootFileEventFinder(RootTree &eventTree)
Definition: RootFile.cc:80
IndexIntoFile::IndexIntoFileItr indexIntoFileIter() const
Definition: RootFile.cc:545
void initialize(GroupSelectorRules const &rules, std::vector< BranchDescription const * > const &branchDescriptions)
std::string const & newBranchToOldBranch(std::string const &newBranch) const
Definition: RootFile.cc:536
IndexIntoFileItr findEventPosition(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const
unsigned int const defaultLearningEntries
Definition: RootTree.h:41
boost::shared_ptr< EventSkipperByID > eventSkipperByID_
Definition: RootFile.h:159
TTree * eventHistoryTree_
Definition: RootFile.h:186
LuminosityBlockNumber_t peekAheadAtLumi() const
std::string const & fileIdentifierBranchName()
Definition: BranchType.cc:207
void validateFile(bool secondaryFile, bool usingGoToEvent)
Definition: RootFile.cc:940
boost::shared_ptr< ProductRegistry const > productRegistry() const
Definition: RootFile.h:83
Hash< ParentageType > ParentageID
Definition: ParentageID.h:9
virtual ~RootFileEventFinder()
Definition: RootFile.cc:81
EventNumber_t event() const
std::string const & moduleDescriptionMapBranchName()
Definition: BranchType.cc:177
std::string const file_
Definition: RootFile.h:155
boost::shared_ptr< RunAuxiliary > readRunAuxiliary_()
Definition: RootFile.cc:1278
void skipEventForward(int &phIndexOfSkippedEvent, RunNumber_t &runOfSkippedEvent, LuminosityBlockNumber_t &lumiOfSkippedEvent, EntryNumber_t &skippedEventEntry)
are no more events in the current run or lumi.
std::vector< EventProcessHistoryID > eventProcessHistoryIDs_
Definition: RootFile.h:168
std::string createGlobalIdentifier()
void readEventHistoryTree()
Definition: RootFile.cc:1455
int forcedRunOffset_
Definition: RootFile.h:184
void fillAux(T *&pAux)
Definition: RootTree.h:92
void setEntryNumber(EntryNumber theEntryNumber)
Definition: RootTree.cc:154
void reportOpened(std::string const &inputType)
Definition: RootFile.cc:978
bool current()
Definition: RootTree.h:83
boost::shared_ptr< LuminosityBlockPrincipal > readLumi(boost::shared_ptr< LuminosityBlockPrincipal > lbCache)
Definition: RootFile.cc:1381