CMS 3D CMS Logo

RootFile.cc
Go to the documentation of this file.
1 /*----------------------------------------------------------------------
2 ----------------------------------------------------------------------*/
3 
4 #include "RootFile.h"
5 #include "DuplicateChecker.h"
6 #include "InputFile.h"
7 #include "ProvenanceAdaptor.h"
8 #include "RunHelper.h"
9 
48 
51 
52 //used for backward compatibility
57 
58 #include "Rtypes.h"
59 #include "TClass.h"
60 #include "TString.h"
61 #include "TTree.h"
62 #include "TTreeCache.h"
63 
64 #include <algorithm>
65 #include <list>
66 
67 namespace edm {
68 
69  // Algorithm classes for making ProvenanceReader:
71  public:
72  std::unique_ptr<ProvenanceReaderBase> makeReader(RootTree& eventTree,
73  DaqProvenanceHelper const* daqProvenanceHelper) const override;
74  };
76  public:
77  MakeOldProvenanceReader(std::unique_ptr<EntryDescriptionMap>&& entryDescriptionMap)
78  : MakeProvenanceReader(), entryDescriptionMap_(std::move(entryDescriptionMap)) {}
79  std::unique_ptr<ProvenanceReaderBase> makeReader(RootTree& eventTree,
80  DaqProvenanceHelper const* daqProvenanceHelper) const override;
81 
82  private:
84  };
86  public:
87  std::unique_ptr<ProvenanceReaderBase> makeReader(RootTree& eventTree,
88  DaqProvenanceHelper const* daqProvenanceHelper) const override;
89  };
91  public:
92  MakeReducedProvenanceReader(std::vector<ParentageID> const& parentageIDLookup)
93  : parentageIDLookup_(parentageIDLookup) {}
94  std::unique_ptr<ProvenanceReaderBase> makeReader(RootTree& eventTree,
95  DaqProvenanceHelper const* daqProvenanceHelper) const override;
96 
97  private:
98  std::vector<ParentageID> const& parentageIDLookup_;
99  };
100 
101  namespace {
102  void checkReleaseVersion(std::vector<ProcessHistory> processHistoryVector, std::string const& fileName) {
103  std::string releaseVersion = getReleaseVersion();
104  releaseversion::DecomposedReleaseVersion currentRelease(releaseVersion);
105  for (auto const& ph : processHistoryVector) {
106  for (auto const& pc : ph) {
107  if (releaseversion::isEarlierRelease(currentRelease, pc.releaseVersion())) {
109  << "The release you are using, " << getReleaseVersion() << " , predates\n"
110  << "a release (" << pc.releaseVersion() << ") used in writing the input file, " << fileName << ".\n"
111  << "Forward compatibility cannot be supported.\n";
112  }
113  }
114  }
115  }
116  } // namespace
117 
118  // This is a helper class for IndexIntoFile.
120  public:
121  explicit RootFileEventFinder(RootTree& eventTree) : eventTree_(eventTree) {}
122  ~RootFileEventFinder() override {}
123 
125  roottree::EntryNumber saveEntry = eventTree_.entryNumber();
126  eventTree_.setEntryNumber(entry);
127  EventAuxiliary eventAux;
128  EventAuxiliary* pEvAux = &eventAux;
129  eventTree_.fillAux<EventAuxiliary>(pEvAux);
130  eventTree_.setEntryNumber(saveEntry);
131  return eventAux.event();
132  }
133 
134  private:
136  };
137 
138  //---------------------------------------------------------------------
140  ProcessConfiguration const& processConfiguration,
141  std::string const& logicalFileName,
142  std::shared_ptr<InputFile> filePtr,
143  std::shared_ptr<EventSkipperByID> eventSkipperByID,
144  bool skipAnyEvents,
145  int remainingEvents,
146  int remainingLumis,
147  unsigned int nStreams,
148  unsigned int treeCacheSize,
149  int treeMaxVirtualSize,
150  InputSource::ProcessingMode processingMode,
151  RunHelperBase* runHelper,
152  bool noEventSort,
153  ProductSelectorRules const& productSelectorRules,
154  InputType inputType,
155  std::shared_ptr<BranchIDListHelper> branchIDListHelper,
156  std::shared_ptr<ThinnedAssociationsHelper> thinnedAssociationsHelper,
157  std::vector<BranchID> const* associationsFromSecondary,
158  std::shared_ptr<DuplicateChecker> duplicateChecker,
159  bool dropDescendants,
160  ProcessHistoryRegistry& processHistoryRegistry,
161  std::vector<std::shared_ptr<IndexIntoFile>> const& indexesIntoFiles,
162  std::vector<std::shared_ptr<IndexIntoFile>>::size_type currentIndexIntoFile,
163  std::vector<ProcessHistoryID>& orderedProcessHistoryIDs,
164  bool bypassVersionCheck,
165  bool labelRawDataLikeMC,
166  bool usingGoToEvent,
167  bool enablePrefetching)
168  : file_(fileName),
169  logicalFile_(logicalFileName),
170  processConfiguration_(processConfiguration),
171  processHistoryRegistry_(&processHistoryRegistry),
172  filePtr_(filePtr),
173  eventSkipperByID_(eventSkipperByID),
174  fileFormatVersion_(),
175  fid_(),
176  indexIntoFileSharedPtr_(new IndexIntoFile),
177  indexIntoFile_(*indexIntoFileSharedPtr_),
178  orderedProcessHistoryIDs_(orderedProcessHistoryIDs),
179  indexIntoFileBegin_(
180  indexIntoFile_.begin(noEventSort ? IndexIntoFile::firstAppearanceOrder : IndexIntoFile::numericalOrder)),
181  indexIntoFileEnd_(indexIntoFileBegin_),
182  indexIntoFileIter_(indexIntoFileBegin_),
183  storedMergeableRunProductMetadata_((inputType == InputType::Primary) ? new StoredMergeableRunProductMetadata
184  : nullptr),
185  eventProcessHistoryIDs_(),
186  eventProcessHistoryIter_(eventProcessHistoryIDs_.begin()),
187  savedRunAuxiliary_(),
188  skipAnyEvents_(skipAnyEvents),
189  noEventSort_(noEventSort),
190  whyNotFastClonable_(0),
191  hasNewlyDroppedBranch_(),
192  branchListIndexesUnchanged_(false),
193  eventAux_(),
194  eventTree_(filePtr,
195  InEvent,
196  nStreams,
197  treeMaxVirtualSize,
198  treeCacheSize,
199  roottree::defaultLearningEntries,
200  enablePrefetching,
201  inputType),
202  lumiTree_(filePtr,
203  InLumi,
204  1,
205  treeMaxVirtualSize,
206  roottree::defaultNonEventCacheSize,
208  enablePrefetching,
209  inputType),
210  runTree_(filePtr,
211  InRun,
212  1,
213  treeMaxVirtualSize,
214  roottree::defaultNonEventCacheSize,
216  enablePrefetching,
217  inputType),
218  treePointers_(),
219  lastEventEntryNumberRead_(IndexIntoFile::invalidEntry),
220  productRegistry_(),
221  branchIDLists_(),
222  branchIDListHelper_(branchIDListHelper),
223  fileThinnedAssociationsHelper_(),
224  thinnedAssociationsHelper_(thinnedAssociationsHelper),
225  processingMode_(processingMode),
226  runHelper_(runHelper),
227  newBranchToOldBranch_(),
228  eventHistoryTree_(nullptr),
229  eventSelectionIDs_(),
230  branchListIndexes_(),
231  history_(),
232  branchChildren_(new BranchChildren),
233  duplicateChecker_(duplicateChecker),
234  provenanceAdaptor_(),
235  provenanceReaderMaker_(),
236  eventProductProvenanceRetrievers_(),
237  parentageIDLookup_(),
238  daqProvenanceHelper_(),
239  edProductClass_(TypeWithDict::byName("edm::WrapperBase").getClass()),
240  inputType_(inputType) {
241  hasNewlyDroppedBranch_.fill(false);
242 
246 
247  // Read the metadata tree.
248  // We use a smart pointer so the tree will be deleted after use, and not kept for the life of the file.
249  std::unique_ptr<TTree> metaDataTree(dynamic_cast<TTree*>(filePtr_->Get(poolNames::metaDataTreeName().c_str())));
250  if (nullptr == metaDataTree.get()) {
252  << "Could not find tree " << poolNames::metaDataTreeName() << " in the input file.\n";
253  }
254 
255  // To keep things simple, we just read in every possible branch that exists.
256  // We don't pay attention to which branches exist in which file format versions
257 
259  if (metaDataTree->FindBranch(poolNames::fileFormatVersionBranchName().c_str()) != nullptr) {
260  TBranch* fft = metaDataTree->GetBranch(poolNames::fileFormatVersionBranchName().c_str());
261  fft->SetAddress(&fftPtr);
262  roottree::getEntry(fft, 0);
263  metaDataTree->SetBranchAddress(poolNames::fileFormatVersionBranchName().c_str(), &fftPtr);
264  }
265 
266  FileID* fidPtr = &fid_;
267  if (metaDataTree->FindBranch(poolNames::fileIdentifierBranchName().c_str()) != nullptr) {
268  metaDataTree->SetBranchAddress(poolNames::fileIdentifierBranchName().c_str(), &fidPtr);
269  }
270 
271  IndexIntoFile* iifPtr = &indexIntoFile_;
272  if (metaDataTree->FindBranch(poolNames::indexIntoFileBranchName().c_str()) != nullptr) {
273  metaDataTree->SetBranchAddress(poolNames::indexIntoFileBranchName().c_str(), &iifPtr);
274  }
275 
276  StoredMergeableRunProductMetadata* smrc = nullptr;
277  if (inputType == InputType::Primary) {
279  if (metaDataTree->FindBranch(poolNames::mergeableRunProductMetadataBranchName().c_str()) != nullptr) {
280  metaDataTree->SetBranchAddress(poolNames::mergeableRunProductMetadataBranchName().c_str(), &smrc);
281  }
282  }
283 
284  // Need to read to a temporary registry so we can do a translation of the BranchKeys.
285  // This preserves backward compatibility against friendly class name algorithm changes.
286  ProductRegistry inputProdDescReg;
287  ProductRegistry* ppReg = &inputProdDescReg;
288  metaDataTree->SetBranchAddress(poolNames::productDescriptionBranchName().c_str(), (&ppReg));
289 
290  typedef std::map<ParameterSetID, ParameterSetBlob> PsetMap;
291  PsetMap psetMap;
292  PsetMap* psetMapPtr = &psetMap;
293  if (metaDataTree->FindBranch(poolNames::parameterSetMapBranchName().c_str()) != nullptr) {
294  //backward compatibility
295  assert(!fileFormatVersion().parameterSetsTree());
296  metaDataTree->SetBranchAddress(poolNames::parameterSetMapBranchName().c_str(), &psetMapPtr);
297  } else {
298  assert(fileFormatVersion().parameterSetsTree());
299  // We use a smart pointer so the tree will be deleted after use, and not kept for the life of the file.
300  std::unique_ptr<TTree> psetTree(dynamic_cast<TTree*>(filePtr_->Get(poolNames::parameterSetsTreeName().c_str())));
301  if (nullptr == psetTree.get()) {
303  << "Could not find tree " << poolNames::parameterSetsTreeName() << " in the input file.\n";
304  }
305 
306  typedef std::pair<ParameterSetID, ParameterSetBlob> IdToBlobs;
307  IdToBlobs idToBlob;
308  IdToBlobs* pIdToBlob = &idToBlob;
309  psetTree->SetBranchAddress(poolNames::idToParameterSetBlobsBranchName().c_str(), &pIdToBlob);
310 
311  std::unique_ptr<TTreeCache> psetTreeCache =
313  psetTreeCache->SetEnablePrefetching(false);
314  filePtr_->SetCacheRead(psetTreeCache.get());
315  for (Long64_t i = 0; i != psetTree->GetEntries(); ++i) {
316  psetTree->GetEntry(i);
317  psetMap.insert(idToBlob);
318  }
319  filePtr_->SetCacheRead(nullptr);
320  }
321 
322  // backward compatibility
324  ProcessHistoryRegistry::collection_type* pHistMapPtr = &pHistMap;
325  if (metaDataTree->FindBranch(poolNames::processHistoryMapBranchName().c_str()) != nullptr) {
326  metaDataTree->SetBranchAddress(poolNames::processHistoryMapBranchName().c_str(), &pHistMapPtr);
327  }
328 
330  ProcessHistoryRegistry::vector_type* pHistVectorPtr = &pHistVector;
331  if (metaDataTree->FindBranch(poolNames::processHistoryBranchName().c_str()) != nullptr) {
332  metaDataTree->SetBranchAddress(poolNames::processHistoryBranchName().c_str(), &pHistVectorPtr);
333  }
334 
335  // backward compatibility
336  ProcessConfigurationVector processConfigurations;
337  ProcessConfigurationVector* procConfigVectorPtr = &processConfigurations;
338  if (metaDataTree->FindBranch(poolNames::processConfigurationBranchName().c_str()) != nullptr) {
339  metaDataTree->SetBranchAddress(poolNames::processConfigurationBranchName().c_str(), &procConfigVectorPtr);
340  }
341 
342  auto branchIDListsAPtr = std::make_unique<BranchIDLists>();
343  BranchIDLists* branchIDListsPtr = branchIDListsAPtr.get();
344  if (metaDataTree->FindBranch(poolNames::branchIDListBranchName().c_str()) != nullptr) {
345  metaDataTree->SetBranchAddress(poolNames::branchIDListBranchName().c_str(), &branchIDListsPtr);
346  }
347 
348  if (inputType != InputType::SecondarySource) {
350  std::make_unique<ThinnedAssociationsHelper>(); // propagate_const<T> has no reset() function
351  ThinnedAssociationsHelper* thinnedAssociationsHelperPtr = fileThinnedAssociationsHelper_.get();
352  if (metaDataTree->FindBranch(poolNames::thinnedAssociationsHelperBranchName().c_str()) != nullptr) {
353  metaDataTree->SetBranchAddress(poolNames::thinnedAssociationsHelperBranchName().c_str(),
354  &thinnedAssociationsHelperPtr);
355  }
356  }
357 
358  BranchChildren* branchChildrenBuffer = branchChildren_.get();
359  if (metaDataTree->FindBranch(poolNames::productDependenciesBranchName().c_str()) != nullptr) {
360  metaDataTree->SetBranchAddress(poolNames::productDependenciesBranchName().c_str(), &branchChildrenBuffer);
361  }
362 
363  // backward compatibility
364  std::vector<EventProcessHistoryID>* eventHistoryIDsPtr = &eventProcessHistoryIDs_;
365  if (metaDataTree->FindBranch(poolNames::eventHistoryBranchName().c_str()) != nullptr) {
366  metaDataTree->SetBranchAddress(poolNames::eventHistoryBranchName().c_str(), &eventHistoryIDsPtr);
367  }
368 
369  if (metaDataTree->FindBranch(poolNames::moduleDescriptionMapBranchName().c_str()) != nullptr) {
370  if (metaDataTree->GetBranch(poolNames::moduleDescriptionMapBranchName().c_str())->GetSplitLevel() != 0) {
371  metaDataTree->SetBranchStatus((poolNames::moduleDescriptionMapBranchName() + ".*").c_str(), false);
372  } else {
373  metaDataTree->SetBranchStatus(poolNames::moduleDescriptionMapBranchName().c_str(), false);
374  }
375  }
376 
377  // Here we read the metadata tree
378  roottree::getEntry(metaDataTree.get(), 0);
379 
381 
382  // Here we read the event history tree, if we have one.
384 
386  if (!fileFormatVersion().triggerPathsTracked()) {
387  ParameterSetConverter converter(psetMap, psetIdConverter, fileFormatVersion().parameterSetsByReference());
388  } else {
389  // Merge into the parameter set registry.
390  pset::Registry& psetRegistry = *pset::Registry::instance();
391  for (auto const& psetEntry : psetMap) {
392  ParameterSet pset(psetEntry.second.pset());
393  pset.setID(psetEntry.first);
394  // For thread safety, don't update global registries when a secondary source opens a file.
395  if (inputType != InputType::SecondarySource) {
396  psetRegistry.insertMapped(pset);
397  }
398  }
399  }
400  if (!fileFormatVersion().splitProductIDs()) {
401  // Old provenance format input file. Create a provenance adaptor.
402  // propagate_const<T> has no reset() function
403  provenanceAdaptor_ = std::make_unique<ProvenanceAdaptor>(
404  inputProdDescReg, pHistMap, pHistVector, processConfigurations, psetIdConverter, true);
405  // Fill in the branchIDLists branch from the provenance adaptor
406  branchIDLists_ = provenanceAdaptor_->branchIDLists();
407  } else {
408  if (!fileFormatVersion().triggerPathsTracked()) {
409  // New provenance format, but change in ParameterSet Format. Create a provenance adaptor.
410  // propagate_const<T> has no reset() function
411  provenanceAdaptor_ = std::make_unique<ProvenanceAdaptor>(
412  inputProdDescReg, pHistMap, pHistVector, processConfigurations, psetIdConverter, false);
413  }
414  // New provenance format input file. The branchIDLists branch was read directly from the input file.
415  if (metaDataTree->FindBranch(poolNames::branchIDListBranchName().c_str()) == nullptr) {
416  throw Exception(errors::EventCorruption) << "Failed to find branchIDLists branch in metaData tree.\n";
417  }
418  branchIDLists_.reset(branchIDListsAPtr.release());
419  }
420 
422  if (metaDataTree->FindBranch(poolNames::thinnedAssociationsHelperBranchName().c_str()) == nullptr) {
424  << "Failed to find thinnedAssociationsHelper branch in metaData tree.\n";
425  }
426  }
427 
428  if (!bypassVersionCheck) {
429  checkReleaseVersion(pHistVector, file());
430  }
431 
432  if (labelRawDataLikeMC) {
433  std::string const rawData("FEDRawDataCollection");
434  std::string const source("source");
435  ProductRegistry::ProductList& pList = inputProdDescReg.productListUpdator();
436  BranchKey finder(rawData, source, "", "");
437  ProductRegistry::ProductList::iterator it = pList.lower_bound(finder);
438  if (it != pList.end() && it->first.friendlyClassName() == rawData && it->first.moduleLabel() == source) {
439  // We found raw data with a module label of source.
440  // We need to change the module label and process name.
441  // Create helper.
442  it->second.init();
443  // propagate_const<T> has no reset() function
444  daqProvenanceHelper_ = std::make_unique<DaqProvenanceHelper>(it->second.unwrappedTypeID());
445  // Create the new branch description
446  BranchDescription const& newBD = daqProvenanceHelper_->branchDescription();
447  // Save info from the old and new branch descriptions
448  daqProvenanceHelper_->saveInfo(it->second, newBD);
449  // Map the new branch name to the old branch name.
450  newBranchToOldBranch_.insert(std::make_pair(newBD.branchName(), it->second.branchName()));
451  // Remove the old branch description from the product Registry.
452  pList.erase(it);
453  // Check that there was only one.
454  it = pList.lower_bound(finder);
455  assert(!(it != pList.end() && it->first.friendlyClassName() == rawData && it->first.moduleLabel() == source));
456  // Insert the new branch description into the product registry.
457  inputProdDescReg.copyProduct(newBD);
458  // Fix up other per file metadata.
459  daqProvenanceHelper_->fixMetaData(processConfigurations, pHistVector);
460  daqProvenanceHelper_->fixMetaData(*branchIDLists_);
461  daqProvenanceHelper_->fixMetaData(*branchChildren_);
462  }
463  }
464 
465  for (auto const& history : pHistVector) {
466  processHistoryRegistry.registerProcessHistory(history);
467  }
468 
470 
471  // Update the branch id info. This has to be done before validateFile since
472  // depending on the file format, the branchIDListHelper_ may have its fixBranchListIndexes call made
473  if (inputType == InputType::Primary) {
475  }
476 
477  validateFile(inputType, usingGoToEvent);
478 
479  // Here, we make the class that will make the ProvenanceReader
480  // It reads whatever trees it needs.
481  // propagate_const<T> has no reset() function
482  provenanceReaderMaker_ = std::unique_ptr<MakeProvenanceReader>(makeProvenanceReaderMaker(inputType).release());
483 
484  // Merge into the hashed registries.
485  if (eventSkipperByID_ && eventSkipperByID_->somethingToSkip()) {
487  }
488 
489  initializeDuplicateChecker(indexesIntoFiles, currentIndexIntoFile);
493  indexIntoFile_.end(noEventSort ? IndexIntoFile::firstAppearanceOrder : IndexIntoFile::numericalOrder);
495  eventProcessHistoryIter_ = eventProcessHistoryIDs_.begin();
496 
497  // Set product presence information in the product registry.
498  ProductRegistry::ProductList& pList = inputProdDescReg.productListUpdator();
499  for (auto& product : pList) {
500  BranchDescription& prod = product.second;
501  prod.init();
502  treePointers_[prod.branchType()]->setPresence(prod, newBranchToOldBranch(prod.branchName()));
503  }
504 
505  auto newReg = std::make_unique<ProductRegistry>();
506 
507  // Do the translation from the old registry to the new one
508  {
509  ProductRegistry::ProductList const& prodList = inputProdDescReg.productList();
510  for (auto const& product : prodList) {
511  BranchDescription const& prod = product.second;
512  std::string newFriendlyName = friendlyname::friendlyName(prod.className());
513  if (newFriendlyName == prod.friendlyClassName()) {
514  newReg->copyProduct(prod);
515  } else {
516  if (fileFormatVersion().splitProductIDs()) {
518  << "Cannot change friendly class name algorithm without more development work\n"
519  << "to update BranchIDLists and ThinnedAssociationsHelper. Contact the framework group.\n";
520  }
521  BranchDescription newBD(prod);
522  newBD.updateFriendlyClassName();
523  newReg->copyProduct(newBD);
524  newBranchToOldBranch_.insert(std::make_pair(newBD.branchName(), prod.branchName()));
525  }
526  }
527  dropOnInput(*newReg, productSelectorRules, dropDescendants, inputType);
528  if (inputType == InputType::SecondaryFile) {
529  thinnedAssociationsHelper->updateFromSecondaryInput(*fileThinnedAssociationsHelper_,
530  *associationsFromSecondary);
531  } else if (inputType == InputType::Primary) {
532  thinnedAssociationsHelper->updateFromPrimaryInput(*fileThinnedAssociationsHelper_);
533  }
534 
535  if (inputType == InputType::Primary) {
536  for (auto& product : newReg->productListUpdator()) {
537  setIsMergeable(product.second);
538  }
539  }
540 
541  // freeze the product registry
542  newReg->setFrozen(inputType != InputType::Primary);
543  productRegistry_.reset(newReg.release());
544  }
545 
546  // Set up information from the product registry.
547  ProductRegistry::ProductList const& prodList = productRegistry()->productList();
548 
549  {
550  std::array<size_t, NumBranchTypes> nBranches;
551  nBranches.fill(0);
552  for (auto const& product : prodList) {
553  ++nBranches[product.second.branchType()];
554  }
555 
556  int i = 0;
557  for (auto t : treePointers_) {
558  t->numberOfBranchesToAdd(nBranches[i]);
559  ++i;
560  }
561  }
562  for (auto const& product : prodList) {
563  BranchDescription const& prod = product.second;
564  treePointers_[prod.branchType()]->addBranch(prod, newBranchToOldBranch(prod.branchName()));
565  }
566 
567  // Determine if this file is fast clonable.
568  setIfFastClonable(remainingEvents, remainingLumis);
569 
570  // We are done with our initial reading of EventAuxiliary.
572 
573  // Tell the event tree to begin training at the next read.
575 
576  // Train the run and lumi trees.
577  runTree_.trainCache("*");
578  lumiTree_.trainCache("*");
579  }
580 
582 
583  void RootFile::readEntryDescriptionTree(EntryDescriptionMap& entryDescriptionMap, InputType inputType) {
584  // Called only for old format files.
585  // We use a smart pointer so the tree will be deleted after use, and not kept for the life of the file.
586  std::unique_ptr<TTree> entryDescriptionTree(
587  dynamic_cast<TTree*>(filePtr_->Get(poolNames::entryDescriptionTreeName().c_str())));
588  if (nullptr == entryDescriptionTree.get()) {
590  << "Could not find tree " << poolNames::entryDescriptionTreeName() << " in the input file.\n";
591  }
592 
593  EntryDescriptionID idBuffer;
594  EntryDescriptionID* pidBuffer = &idBuffer;
595  entryDescriptionTree->SetBranchAddress(poolNames::entryDescriptionIDBranchName().c_str(), &pidBuffer);
596 
597  EventEntryDescription entryDescriptionBuffer;
598  EventEntryDescription* pEntryDescriptionBuffer = &entryDescriptionBuffer;
599  entryDescriptionTree->SetBranchAddress(poolNames::entryDescriptionBranchName().c_str(), &pEntryDescriptionBuffer);
600 
601  // Fill in the parentage registry.
603 
604  for (Long64_t i = 0, numEntries = entryDescriptionTree->GetEntries(); i < numEntries; ++i) {
605  roottree::getEntry(entryDescriptionTree.get(), i);
606  if (idBuffer != entryDescriptionBuffer.id()) {
607  throw Exception(errors::EventCorruption) << "Corruption of EntryDescription tree detected.\n";
608  }
609  entryDescriptionMap.insert(std::make_pair(entryDescriptionBuffer.id(), entryDescriptionBuffer));
611  parents.setParents(entryDescriptionBuffer.parents());
612  if (daqProvenanceHelper_) {
613  ParentageID const oldID = parents.id();
614  daqProvenanceHelper_->fixMetaData(parents.parentsForUpdate());
615  ParentageID newID = parents.id();
616  if (newID != oldID) {
617  daqProvenanceHelper_->setOldParentageIDToNew(oldID, newID);
618  }
619  }
620  // For thread safety, don't update global registries when a secondary source opens a file.
621  if (inputType != InputType::SecondarySource) {
622  registry.insertMapped(parents);
623  }
624  }
625  entryDescriptionTree->SetBranchAddress(poolNames::entryDescriptionIDBranchName().c_str(), nullptr);
626  entryDescriptionTree->SetBranchAddress(poolNames::entryDescriptionBranchName().c_str(), nullptr);
627  }
628 
630  // New format file
631  // We use a smart pointer so the tree will be deleted after use, and not kept for the life of the file.
632  std::unique_ptr<TTree> parentageTree(dynamic_cast<TTree*>(filePtr_->Get(poolNames::parentageTreeName().c_str())));
633  if (nullptr == parentageTree.get()) {
635  << "Could not find tree " << poolNames::parentageTreeName() << " in the input file.\n";
636  }
637 
639  Parentage* pParentageBuffer = &parents;
640  parentageTree->SetBranchAddress(poolNames::parentageBranchName().c_str(), &pParentageBuffer);
641 
643 
644  parentageIDLookup_.reserve(parentageTree->GetEntries());
645  for (Long64_t i = 0, numEntries = parentageTree->GetEntries(); i < numEntries; ++i) {
646  roottree::getEntry(parentageTree.get(), i);
647  if (daqProvenanceHelper_) {
648  ParentageID const oldID = parents.id();
649  daqProvenanceHelper_->fixMetaData(parents.parentsForUpdate());
650  ParentageID newID = parents.id();
651  if (newID != oldID) {
652  daqProvenanceHelper_->setOldParentageIDToNew(oldID, newID);
653  }
654  }
655  // For thread safety, don't update global registries when a secondary source opens a file.
656  if (inputType != InputType::SecondarySource) {
657  registry.insertMapped(parents);
658  }
659  parentageIDLookup_.push_back(parents.id());
660  }
661  parentageTree->SetBranchAddress(poolNames::parentageBranchName().c_str(), nullptr);
662  }
663 
664  void RootFile::setIfFastClonable(int remainingEvents, int remainingLumis) {
665  if (fileFormatVersion().noMetaDataTrees() and !fileFormatVersion().storedProductProvenanceUsed()) {
666  //we must avoid copying the old branch which stored the per product per event provenance
668  return;
669  }
670  if (!fileFormatVersion().splitProductIDs()) {
672  return;
673  }
676  return;
677  }
678  // Find entry for first event in file
680  while (it != indexIntoFileEnd_ && it.getEntryType() != IndexIntoFile::kEvent) {
681  ++it;
682  }
683  if (it == indexIntoFileEnd_) {
685  return;
686  }
687 
688  // From here on, record all reasons we can't fast clone.
689  IndexIntoFile::SortOrder sortOrder =
693  }
694  if (skipAnyEvents_) {
696  }
697  if (remainingEvents >= 0 && eventTree_.entries() > remainingEvents) {
699  }
700  if (remainingLumis >= 0 && lumiTree_.entries() > remainingLumis) {
702  }
703  if (duplicateChecker_ && !duplicateChecker_->checkDisabled() && !duplicateChecker_->noDuplicatesInFile()) {
705  }
706  }
707 
708  std::unique_ptr<FileBlock> RootFile::createFileBlock() const {
709  return std::make_unique<FileBlock>(fileFormatVersion(),
710  eventTree_.tree(),
712  lumiTree_.tree(),
714  runTree_.tree(),
715  runTree_.metaTree(),
718  file_,
720  modifiedIDs(),
721  branchChildren());
722  }
723 
724  std::string const& RootFile::newBranchToOldBranch(std::string const& newBranch) const {
725  std::map<std::string, std::string>::const_iterator it = newBranchToOldBranch_.find(newBranch);
726  if (it != newBranchToOldBranch_.end()) {
727  return it->second;
728  }
729  return newBranch;
730  }
731 
733 
736  }
737 
738  void RootFile::initAssociationsFromSecondary(std::vector<BranchID> const& associationsFromSecondary) {
739  thinnedAssociationsHelper_->initAssociationsFromSecondary(associationsFromSecondary,
741  }
742 
745  return false;
746  }
747  if (eventSkipperByID_ && eventSkipperByID_->somethingToSkip()) {
748  // See first if the entire lumi or run is skipped, so we won't have to read the event Auxiliary in that case.
750  return true;
751  }
752 
753  // The Lumi is not skipped. If this is an event, see if the event is skipped.
757  return true;
758  }
759  }
760 
761  // Skip runs with no lumis if either lumisToSkip or lumisToProcess have been set to select lumis
764 
765  // There are no lumis in this run, not even ones we will skip
766  if (iterLumi.peekAheadAtLumi() == IndexIntoFile::invalidLumi) {
767  return true;
768  }
769  // If we get here there are lumis in the run, check to see if we are skipping all of them
770  do {
771  if (!eventSkipperByID_->skipIt(iterLumi.run(), iterLumi.peekAheadAtLumi(), 0U)) {
772  return false;
773  }
774  } while (iterLumi.skipLumiInRun());
775  return true;
776  }
777  }
778  return false;
779  }
780 
783  if (duplicateChecker_.get() == nullptr) {
784  return false;
785  }
787  return duplicateChecker_->isDuplicateAndCheckActive(indexIntoFileIter_.processHistoryIDIndex(),
790  eventAux_.id().event(),
791  file_);
792  }
793 
795  return indexIntoFile_.containsItem(run, lumi, event);
796  }
797 
800  EventNumber_t& event) {
801  // First, account for consecutive skipped entries.
802  while (skipThisEntry()) {
807  } else {
809  }
810  }
811  // OK, we have an entry that is not skipped.
813  if (entryType == IndexIntoFile::kEnd) {
814  return IndexIntoFile::kEnd;
815  }
816  if (entryType == IndexIntoFile::kRun) {
817  run = indexIntoFileIter_.run();
818  runHelper_->checkForNewRun(run);
819  return IndexIntoFile::kRun;
820  } else if (processingMode_ == InputSource::Runs) {
822  return getNextItemType(run, lumi, event);
823  }
824  if (entryType == IndexIntoFile::kLumi) {
825  run = indexIntoFileIter_.run();
826  lumi = indexIntoFileIter_.lumi();
827  return IndexIntoFile::kLumi;
830  return getNextItemType(run, lumi, event);
831  }
832  if (isDuplicateEvent()) {
834  return getNextItemType(run, lumi, event);
835  }
836  run = indexIntoFileIter_.run();
837  lumi = indexIntoFileIter_.lumi();
839  event = eventAux_.event();
840  return IndexIntoFile::kEvent;
841  }
842 
845  itr.advanceToEvent();
846  return itr.getEntryType() == IndexIntoFile::kEnd;
847  }
848 
851  int phIndex;
854  IndexIntoFile::EntryNumber_t eventEntry;
855  itr.skipEventBackward(phIndex, run, lumi, eventEntry);
856  itr.skipEventBackward(phIndex, run, lumi, eventEntry);
857  return eventEntry == IndexIntoFile::invalidEntry;
858  }
859 
860  namespace {
861  struct RunItem {
862  RunItem(ProcessHistoryID const& phid, RunNumber_t const& run) : phid_(phid), run_(run) {}
863  ProcessHistoryID phid_;
864  RunNumber_t run_;
865  };
866  struct RunItemSortByRun {
867  bool operator()(RunItem const& a, RunItem const& b) const { return a.run_ < b.run_; }
868  };
869  struct RunItemSortByRunPhid {
870  bool operator()(RunItem const& a, RunItem const& b) const {
871  return a.run_ < b.run_ || (!(b.run_ < a.run_) && a.phid_ < b.phid_);
872  }
873  };
874  struct LumiItem {
875  LumiItem(ProcessHistoryID const& phid,
876  RunNumber_t const& run,
879  : phid_(phid),
880  run_(run),
881  lumi_(lumi),
882  firstEventEntry_(entry),
883  lastEventEntry_(entry == IndexIntoFile::invalidEntry ? IndexIntoFile::invalidEntry : entry + 1) {}
884  ProcessHistoryID phid_;
885  RunNumber_t run_;
887  IndexIntoFile::EntryNumber_t firstEventEntry_;
888  IndexIntoFile::EntryNumber_t lastEventEntry_;
889  };
890  struct LumiItemSortByRunLumi {
891  bool operator()(LumiItem const& a, LumiItem const& b) const {
892  return a.run_ < b.run_ || (!(b.run_ < a.run_) && a.lumi_ < b.lumi_);
893  }
894  };
895  struct LumiItemSortByRunLumiPhid {
896  bool operator()(LumiItem const& a, LumiItem const& b) const {
897  if (a.run_ < b.run_)
898  return true;
899  if (b.run_ < a.run_)
900  return false;
901  if (a.lumi_ < b.lumi_)
902  return true;
903  if (b.lumi_ < a.lumi_)
904  return false;
905  return a.phid_ < b.phid_;
906  }
907  };
908  } // namespace
909 
911  // This function is for backward compatibility.
912  // If reading a current format file, indexIntoFile_ is read from the input
913  // file and should always be there. Note that the algorithm below will work
914  // sometimes but often fail with the new format introduced in release 3_8_0.
915  // If it ever becomes necessary to rebuild IndexIntoFile from the new format,
916  // probably a separate function should be written to deal with the task.
917  // This is possible just not implemented yet.
918  assert(!fileFormatVersion().hasIndexIntoFile());
919 
920  typedef std::list<LumiItem> LumiList;
921  LumiList lumis; // (declare 1)
922 
923  typedef std::set<LuminosityBlockID> RunLumiSet;
924  RunLumiSet runLumiSet; // (declare 2)
925 
926  typedef std::list<RunItem> RunList;
927  RunList runs; // (declare 5)
928 
929  typedef std::set<RunNumber_t> RunSet;
930  RunSet runSet; // (declare 4)
931 
932  typedef std::set<RunItem, RunItemSortByRunPhid> RunItemSet;
933  RunItemSet runItemSet; // (declare 3)
934 
935  typedef std::map<RunNumber_t, ProcessHistoryID> PHIDMap;
936  PHIDMap phidMap;
937 
938  RunNumber_t prevRun = 0;
939  LuminosityBlockNumber_t prevLumi = 0;
940  ProcessHistoryID prevPhid;
941  bool iFirst = true;
942 
943  indexIntoFile_.unsortedEventNumbers().clear(); // should already be empty, just being careful
945 
946  // First, loop through the event tree.
947  while (eventTree_.next()) {
948  bool newRun = false;
949  bool newLumi = false;
952 
953  // Save the event numbers as we loop through the event auxiliary to avoid
954  // having to read through the event auxiliary again later. These event numbers
955  // are not actually used in this function, but could be needed elsewhere.
957 
958  ProcessHistoryID reducedPHID = processHistoryRegistry_->reducedProcessHistoryID(eventAux().processHistoryID());
959 
960  if (iFirst || prevPhid != reducedPHID || prevRun != eventAux().run()) {
961  iFirst = false;
962  newRun = newLumi = true;
963  } else if (prevLumi != eventAux().luminosityBlock()) {
964  newLumi = true;
965  }
966  prevPhid = reducedPHID;
967  prevRun = eventAux().run();
968  prevLumi = eventAux().luminosityBlock();
969  if (newLumi) {
970  lumis.emplace_back(
971  reducedPHID, eventAux().run(), eventAux().luminosityBlock(), eventTree_.entryNumber()); // (insert 1)
972  runLumiSet.insert(LuminosityBlockID(eventAux().run(), eventAux().luminosityBlock())); // (insert 2)
973  } else {
974  LumiItem& currentLumi = lumis.back();
975  assert(currentLumi.lastEventEntry_ == eventTree_.entryNumber());
976  ++currentLumi.lastEventEntry_;
977  }
978  if (newRun) {
979  // Insert run in list if it is not already there.
980  RunItem item(reducedPHID, eventAux().run());
981  if (runItemSet.insert(item).second) { // (check 3, insert 3)
982  runs.push_back(std::move(item)); // (insert 5)
983  runSet.insert(eventAux().run()); // (insert 4)
984  phidMap.insert(std::make_pair(eventAux().run(), reducedPHID));
985  }
986  }
987  }
988  // now clean up.
992 
993  // Loop over run entries and fill information.
994 
995  typedef std::map<RunNumber_t, IndexIntoFile::EntryNumber_t> RunMap;
996  RunMap runMap; // (declare 11)
997 
998  typedef std::vector<RunItem> RunVector;
999  RunVector emptyRuns; // (declare 12)
1000 
1001  if (runTree_.isValid()) {
1002  while (runTree_.next()) {
1003  // Note: adjacent duplicates will be skipped without an explicit check.
1004 
1005  std::shared_ptr<RunAuxiliary> runAux = fillRunAuxiliary();
1006  ProcessHistoryID reducedPHID = processHistoryRegistry_->reducedProcessHistoryID(runAux->processHistoryID());
1007 
1008  if (runSet.insert(runAux->run()).second) { // (check 4, insert 4)
1009  // This run was not associated with any events.
1010  emptyRuns.emplace_back(reducedPHID, runAux->run()); // (insert 12)
1011  }
1012  runMap.insert(std::make_pair(runAux->run(), runTree_.entryNumber())); // (insert 11)
1013  phidMap.insert(std::make_pair(runAux->run(), reducedPHID));
1014  }
1015  // now clean up.
1017  }
1018 
1019  // Insert the ordered empty runs into the run list.
1020  RunItemSortByRun runItemSortByRun;
1021  stable_sort_all(emptyRuns, runItemSortByRun);
1022 
1023  RunList::iterator itRuns = runs.begin(), endRuns = runs.end();
1024  for (auto const& emptyRun : emptyRuns) {
1025  for (; itRuns != endRuns; ++itRuns) {
1026  if (runItemSortByRun(emptyRun, *itRuns)) {
1027  break;
1028  }
1029  }
1030  runs.insert(itRuns, emptyRun);
1031  }
1032 
1033  // Loop over luminosity block entries and fill information.
1034 
1035  typedef std::vector<LumiItem> LumiVector;
1036  LumiVector emptyLumis; // (declare 7)
1037 
1038  typedef std::map<LuminosityBlockID, IndexIntoFile::EntryNumber_t> RunLumiMap;
1039  RunLumiMap runLumiMap; // (declare 6)
1040 
1041  if (lumiTree_.isValid()) {
1042  while (lumiTree_.next()) {
1043  // Note: adjacent duplicates will be skipped without an explicit check.
1044  std::shared_ptr<LuminosityBlockAuxiliary> lumiAux = fillLumiAuxiliary();
1045  LuminosityBlockID lumiID = LuminosityBlockID(lumiAux->run(), lumiAux->luminosityBlock());
1046  if (runLumiSet.insert(lumiID).second) { // (check 2, insert 2)
1047  // This lumi was not associated with any events.
1048  // Use the process history ID from the corresponding run. In cases of practical
1049  // importance, this should be the correct process history ID, but it is possible
1050  // to construct files where this is not the correct process history ID ...
1051  PHIDMap::const_iterator iPhidMap = phidMap.find(lumiAux->run());
1052  assert(iPhidMap != phidMap.end());
1053  emptyLumis.emplace_back(
1054  iPhidMap->second, lumiAux->run(), lumiAux->luminosityBlock(), IndexIntoFile::invalidEntry); // (insert 7)
1055  }
1056  runLumiMap.insert(std::make_pair(lumiID, lumiTree_.entryNumber()));
1057  }
1058  // now clean up.
1060  }
1061 
1062  // Insert the ordered empty lumis into the lumi list.
1063  LumiItemSortByRunLumi lumiItemSortByRunLumi;
1064  stable_sort_all(emptyLumis, lumiItemSortByRunLumi);
1065 
1066  LumiList::iterator itLumis = lumis.begin(), endLumis = lumis.end();
1067  for (auto const& emptyLumi : emptyLumis) {
1068  for (; itLumis != endLumis; ++itLumis) {
1069  if (lumiItemSortByRunLumi(emptyLumi, *itLumis)) {
1070  break;
1071  }
1072  }
1073  lumis.insert(itLumis, emptyLumi);
1074  }
1075 
1076  // Create a map of RunItems that gives the order of first appearance in the list.
1077  // Also fill in the vector of process history IDs
1078  typedef std::map<RunItem, int, RunItemSortByRunPhid> RunCountMap;
1079  RunCountMap runCountMap; // Declare (17)
1080  std::vector<ProcessHistoryID>& phids = indexIntoFile_.setProcessHistoryIDs();
1081  assert(phids.empty());
1082  std::vector<IndexIntoFile::RunOrLumiEntry>& entries = indexIntoFile_.setRunOrLumiEntries();
1083  assert(entries.empty());
1084  int rcount = 0;
1085  for (auto& run : runs) {
1086  RunCountMap::const_iterator countMapItem = runCountMap.find(run);
1087  if (countMapItem == runCountMap.end()) {
1088  countMapItem = runCountMap.insert(std::make_pair(run, rcount)).first; // Insert (17)
1089  assert(countMapItem != runCountMap.end());
1090  ++rcount;
1091  }
1092  std::vector<ProcessHistoryID>::const_iterator phidItem = find_in_all(phids, run.phid_);
1093  if (phidItem == phids.end()) {
1094  phids.push_back(run.phid_);
1095  phidItem = phids.end() - 1;
1096  }
1097  entries.emplace_back(countMapItem->second, // use (17)
1099  runMap[run.run_], // use (11)
1100  phidItem - phids.begin(),
1101  run.run_,
1102  0U,
1105  }
1106 
1107  // Create a map of LumiItems that gives the order of first appearance in the list.
1108  typedef std::map<LumiItem, int, LumiItemSortByRunLumiPhid> LumiCountMap;
1109  LumiCountMap lumiCountMap; // Declare (19)
1110  int lcount = 0;
1111  for (auto& lumi : lumis) {
1112  RunCountMap::const_iterator runCountMapItem = runCountMap.find(RunItem(lumi.phid_, lumi.run_));
1113  assert(runCountMapItem != runCountMap.end());
1114  LumiCountMap::const_iterator countMapItem = lumiCountMap.find(lumi);
1115  if (countMapItem == lumiCountMap.end()) {
1116  countMapItem = lumiCountMap.insert(std::make_pair(lumi, lcount)).first; // Insert (17)
1117  assert(countMapItem != lumiCountMap.end());
1118  ++lcount;
1119  }
1120  std::vector<ProcessHistoryID>::const_iterator phidItem = find_in_all(phids, lumi.phid_);
1121  assert(phidItem != phids.end());
1122  entries.emplace_back(runCountMapItem->second,
1123  countMapItem->second,
1124  runLumiMap[LuminosityBlockID(lumi.run_, lumi.lumi_)],
1125  phidItem - phids.begin(),
1126  lumi.run_,
1127  lumi.lumi_,
1128  lumi.firstEventEntry_,
1129  lumi.lastEventEntry_);
1130  }
1131  stable_sort_all(entries);
1132  }
1133 
1134  void RootFile::validateFile(InputType inputType, bool usingGoToEvent) {
1135  if (!fid_.isValid()) {
1137  }
1138  if (!eventTree_.isValid()) {
1139  throw Exception(errors::EventCorruption) << "'Events' tree is corrupted or not present\n"
1140  << "in the input file.\n";
1141  }
1142 
1143  if (fileFormatVersion().hasIndexIntoFile()) {
1144  if (runTree().entries() > 0) {
1145  assert(!indexIntoFile_.empty());
1146  }
1148  if (daqProvenanceHelper_) {
1149  std::vector<ProcessHistoryID>& phidVec = indexIntoFile_.setProcessHistoryIDs();
1150  for (auto& phid : phidVec) {
1151  phid = daqProvenanceHelper_->mapProcessHistoryID(phid);
1152  }
1153  }
1155  }
1156  } else {
1157  assert(indexIntoFile_.empty());
1159  }
1160 
1164  std::shared_ptr<IndexIntoFile::EventFinder>(std::make_shared<RootFileEventFinder>(eventTree_)));
1165  // We fill the event numbers explicitly if we need to find events in closed files,
1166  // such as for secondary files (or secondary sources) or if duplicate checking across files.
1167  bool needEventNumbers = false;
1168  bool needIndexesForDuplicateChecker =
1169  duplicateChecker_ && duplicateChecker_->checkingAllFiles() && !duplicateChecker_->checkDisabled();
1170  if (inputType != InputType::Primary || needIndexesForDuplicateChecker || usingGoToEvent) {
1171  needEventNumbers = true;
1172  }
1173  bool needEventEntries = false;
1174  if (inputType != InputType::Primary || !noEventSort_) {
1175  // We need event entries for sorting or for secondary files or sources.
1176  needEventEntries = true;
1177  }
1178  indexIntoFile_.fillEventNumbersOrEntries(needEventNumbers, needEventEntries);
1179  }
1180 
1181  void RootFile::reportOpened(std::string const& inputType) {
1182  // Report file opened.
1183  std::string const label = "source";
1184  std::string moduleName = "PoolSource";
1185  filePtr_->inputFileOpened(logicalFile_, inputType, moduleName, label, fid_.fid(), eventTree_.branchNames());
1186  }
1187 
1189  // Just to play it safe, zero all pointers to objects in the InputFile to be closed.
1190  eventHistoryTree_ = nullptr;
1191  for (auto& treePointer : treePointers_) {
1192  treePointer->close();
1193  treePointer = nullptr;
1194  }
1195  filePtr_->Close();
1196  filePtr_ = nullptr; // propagate_const<T> has no reset() function
1197  }
1198 
1201  // Already read.
1202  return;
1203  }
1204  if (fileFormatVersion().newAuxiliary()) {
1205  EventAuxiliary* pEvAux = &eventAux_;
1207  } else {
1208  // for backward compatibility.
1210  EventAux* pEvAux = &eventAux;
1211  eventTree_.fillAux<EventAux>(pEvAux);
1212  conversion(eventAux, eventAux_);
1213  }
1215  }
1216 
1218  if (!eventTree_.current(entry)) {
1219  return false;
1220  }
1221  eventTree_.setEntryNumber(entry);
1223  return true;
1224  }
1225 
1227  // We could consider doing delayed reading, but because we have to
1228  // store this History object in a different tree than the event
1229  // data tree, this is too hard to do in this first version.
1230 
1231  if (fileFormatVersion().eventHistoryBranch()) {
1232  // Lumi block number was not in EventID for the relevant releases.
1233  EventID id(eventAux().id().run(), 0, eventAux().id().event());
1234  if (eventProcessHistoryIter_->eventID() != id) {
1237  assert(eventProcessHistoryIter_->eventID() == id);
1238  }
1241  } else if (fileFormatVersion().eventHistoryTree()) {
1242  // for backward compatibility.
1243  History* pHistory = history_.get();
1244  TBranch* eventHistoryBranch = eventHistoryTree_->GetBranch(poolNames::eventHistoryBranchName().c_str());
1245  if (!eventHistoryBranch) {
1246  throw Exception(errors::EventCorruption) << "Failed to find history branch in event history tree.\n";
1247  }
1248  eventHistoryBranch->SetAddress(&pHistory);
1250  eventAux_.setProcessHistoryID(history_->processHistoryID());
1251  eventSelectionIDs_.swap(history_->eventSelectionIDs());
1252  branchListIndexes_.swap(history_->branchListIndexes());
1253  } else if (fileFormatVersion().noMetaDataTrees()) {
1254  // Current format
1256  TBranch* eventSelectionIDBranch = eventTree_.tree()->GetBranch(poolNames::eventSelectionsBranchName().c_str());
1257  assert(eventSelectionIDBranch != nullptr);
1258  eventTree_.fillBranchEntry(eventSelectionIDBranch, pESV);
1260  TBranch* branchListIndexesBranch = eventTree_.tree()->GetBranch(poolNames::branchListIndexesBranchName().c_str());
1261  assert(branchListIndexesBranch != nullptr);
1262  eventTree_.fillBranchEntry(branchListIndexesBranch, pBLI);
1263  }
1264  if (provenanceAdaptor_) {
1265  eventAux_.setProcessHistoryID(provenanceAdaptor_->convertID(eventAux().processHistoryID()));
1266  for (auto& esID : eventSelectionIDs_) {
1267  esID = provenanceAdaptor_->convertID(esID);
1268  }
1269  }
1270  if (daqProvenanceHelper_) {
1272  }
1274  // old format. branchListIndexes_ must be filled in from the ProvenanceAdaptor.
1275  provenanceAdaptor_->branchListIndexes(branchListIndexes_);
1276  }
1277  if (branchIDListHelper_) {
1278  branchIDListHelper_->fixBranchListIndexes(branchListIndexes_);
1279  }
1280  }
1281 
1282  std::shared_ptr<LuminosityBlockAuxiliary> RootFile::fillLumiAuxiliary() {
1283  auto lumiAuxiliary = std::make_shared<LuminosityBlockAuxiliary>();
1284  if (fileFormatVersion().newAuxiliary()) {
1285  LuminosityBlockAuxiliary* pLumiAux = lumiAuxiliary.get();
1287  } else {
1288  LuminosityBlockAux lumiAux;
1289  LuminosityBlockAux* pLumiAux = &lumiAux;
1291  conversion(lumiAux, *lumiAuxiliary);
1292  }
1293  if (provenanceAdaptor_) {
1294  lumiAuxiliary->setProcessHistoryID(provenanceAdaptor_->convertID(lumiAuxiliary->processHistoryID()));
1295  }
1296  if (daqProvenanceHelper_) {
1297  lumiAuxiliary->setProcessHistoryID(daqProvenanceHelper_->mapProcessHistoryID(lumiAuxiliary->processHistoryID()));
1298  }
1299  if (lumiAuxiliary->luminosityBlock() == 0 && !fileFormatVersion().runsAndLumis()) {
1300  lumiAuxiliary->id() = LuminosityBlockID(RunNumber_t(1), LuminosityBlockNumber_t(1));
1301  }
1302  return lumiAuxiliary;
1303  }
1304 
1305  std::shared_ptr<RunAuxiliary> RootFile::fillRunAuxiliary() {
1306  auto runAuxiliary = std::make_shared<RunAuxiliary>();
1307  if (fileFormatVersion().newAuxiliary()) {
1308  RunAuxiliary* pRunAux = runAuxiliary.get();
1309  runTree_.fillAux<RunAuxiliary>(pRunAux);
1310  } else {
1311  RunAux runAux;
1312  RunAux* pRunAux = &runAux;
1313  runTree_.fillAux<RunAux>(pRunAux);
1314  conversion(runAux, *runAuxiliary);
1315  }
1316  if (provenanceAdaptor_) {
1317  runAuxiliary->setProcessHistoryID(provenanceAdaptor_->convertID(runAuxiliary->processHistoryID()));
1318  }
1319  if (daqProvenanceHelper_) {
1320  runAuxiliary->setProcessHistoryID(daqProvenanceHelper_->mapProcessHistoryID(runAuxiliary->processHistoryID()));
1321  }
1322  return runAuxiliary;
1323  }
1324 
1326  while (offset > 0 && indexIntoFileIter_ != indexIntoFileEnd_) {
1327  int phIndexOfSkippedEvent = IndexIntoFile::invalidIndex;
1328  RunNumber_t runOfSkippedEvent = IndexIntoFile::invalidRun;
1331 
1333  phIndexOfSkippedEvent, runOfSkippedEvent, lumiOfSkippedEvent, skippedEventEntry);
1334 
1335  // At the end of the file and there were no more events to skip
1336  if (skippedEventEntry == IndexIntoFile::invalidEntry)
1337  break;
1338 
1339  if (eventSkipperByID_ && eventSkipperByID_->somethingToSkip()) {
1340  fillEventAuxiliary(skippedEventEntry);
1341  if (eventSkipperByID_->skipIt(runOfSkippedEvent, lumiOfSkippedEvent, eventAux_.id().event())) {
1342  continue;
1343  }
1344  }
1345  if (duplicateChecker_ && !duplicateChecker_->checkDisabled() && !duplicateChecker_->noDuplicatesInFile()) {
1346  fillEventAuxiliary(skippedEventEntry);
1347  if (duplicateChecker_->isDuplicateAndCheckActive(
1348  phIndexOfSkippedEvent, runOfSkippedEvent, lumiOfSkippedEvent, eventAux_.id().event(), file_)) {
1349  continue;
1350  }
1351  }
1352  --offset;
1353  }
1354 
1355  while (offset < 0) {
1356  if (duplicateChecker_) {
1357  duplicateChecker_->disable();
1358  }
1359 
1360  int phIndexOfEvent = IndexIntoFile::invalidIndex;
1364 
1365  indexIntoFileIter_.skipEventBackward(phIndexOfEvent, runOfEvent, lumiOfEvent, eventEntry);
1366 
1367  if (eventEntry == IndexIntoFile::invalidEntry)
1368  break;
1369 
1370  if (eventSkipperByID_ && eventSkipperByID_->somethingToSkip()) {
1371  fillEventAuxiliary(eventEntry);
1372  if (eventSkipperByID_->skipIt(runOfEvent, lumiOfEvent, eventAux_.id().event())) {
1373  continue;
1374  }
1375  }
1376  ++offset;
1377  }
1379  }
1380 
1383 
1384  if (duplicateChecker_) {
1385  duplicateChecker_->disable();
1386  }
1387 
1389  if (noEventSort_)
1391 
1393  indexIntoFile_.findPosition(sortOrder, eventID.run(), eventID.luminosityBlock(), eventID.event());
1394 
1395  if (iter == indexIntoFile_.end(sortOrder)) {
1396  return false;
1397  }
1398  indexIntoFileIter_ = iter;
1399  return true;
1400  }
1401 
1402  // readEvent() is responsible for creating, and setting up, the
1403  // EventPrincipal.
1404  //
1405  // 1. create an EventPrincipal with a unique EventID
1406  // 2. For each entry in the provenance, put in one ProductResolver,
1407  // holding the Provenance for the corresponding EDProduct.
1408  // 3. set up the the EventPrincipal to know about this ProductResolver.
1409  //
1410  // We do *not* create the EDProduct instance (the equivalent of reading
1411  // the branch containing this EDProduct. That will be done by the Delayed Reader,
1412  // when it is asked to do so.
1413  //
1417  // read the event auxiliary if not alrady read.
1419 
1420  // read the event
1421  readCurrentEvent(principal);
1422 
1423  runHelper_->checkRunConsistency(eventAux().run(), indexIntoFileIter_.run());
1424  runHelper_->checkLumiConsistency(eventAux().luminosityBlock(), indexIntoFileIter_.lumi());
1425 
1426  // If this next assert shows up in performance profiling or significantly affects memory, then these three lines should be deleted.
1427  // The IndexIntoFile should guarantee that it never fails.
1429  ? *daqProvenanceHelper_->oldProcessHistoryID()
1430  : eventAux().processHistoryID());
1431  ProcessHistoryID const& reducedPHID = processHistoryRegistry_->reducedProcessHistoryID(idToCheck);
1433 
1435  }
1436 
1437  // Reads event at the current entry in the event tree
1439  if (!eventTree_.current()) {
1440  return false;
1441  }
1443  if (!fileFormatVersion().lumiInEventID()) {
1444  //ugly, but will disappear when the backward compatibility is done with schema evolution.
1445  const_cast<EventID&>(eventAux_.id()).setLuminosityBlockNumber(eventAux_.oldLuminosityBlock());
1447  }
1448  fillEventHistory();
1449  runHelper_->overrideRunNumber(eventAux_.id(), eventAux().isRealData());
1450 
1451  // We're not done ... so prepare the EventPrincipal
1453  principal.fillEventPrincipal(eventAux(),
1457  *(makeProductProvenanceRetriever(principal.streamID().value())),
1459 
1460  // report event read from file
1461  filePtr_->eventReadFromFile();
1462  return true;
1463  }
1464 
1466 
1467  std::shared_ptr<RunAuxiliary> RootFile::readRunAuxiliary_() {
1468  if (runHelper_->fakeNewRun()) {
1469  runHelper_->overrideRunNumber(savedRunAuxiliary_->id());
1470  return savedRunAuxiliary();
1471  }
1474 
1475  // Begin code for backward compatibility before the existence of run trees.
1476  if (!runTree_.isValid()) {
1477  // prior to the support of run trees.
1478  // RunAuxiliary did not contain a valid timestamp. Take it from the next event.
1480  assert(eventEntry != IndexIntoFile::invalidEntry);
1481  assert(eventTree_.current(eventEntry));
1482  fillEventAuxiliary(eventEntry);
1483 
1485  runHelper_->overrideRunNumber(run);
1486  savedRunAuxiliary_ = std::make_shared<RunAuxiliary>(run.run(), eventAux().time(), Timestamp::invalidTimestamp());
1487  return savedRunAuxiliary();
1488  }
1489  // End code for backward compatibility before the existence of run trees.
1491  std::shared_ptr<RunAuxiliary> runAuxiliary = fillRunAuxiliary();
1492  assert(runAuxiliary->run() == indexIntoFileIter_.run());
1493  runHelper_->overrideRunNumber(runAuxiliary->id());
1494  filePtr_->reportInputRunNumber(runAuxiliary->run());
1495  // If RunAuxiliary did not contain a valid begin timestamp, invalidate any end timestamp.
1496  if (runAuxiliary->beginTime() == Timestamp::invalidTimestamp()) {
1497  runAuxiliary->setEndTime(Timestamp::invalidTimestamp());
1498  }
1499 
1500  // If RunAuxiliary did not contain a valid timestamp, or if this an old format file from
1501  // when the Run's ProcessHistory included only processes where products were added to the Run itself,
1502  // we attempt to read the first event in the run to get appropriate info.
1503  if (runAuxiliary->beginTime() == Timestamp::invalidTimestamp() ||
1506  // If we have a valid event, use its information.
1507  if (eventEntry != IndexIntoFile::invalidEntry) {
1508  assert(eventTree_.current(eventEntry));
1509  fillEventAuxiliary(eventEntry);
1510 
1511  // RunAuxiliary did not contain a valid timestamp. Take it from the next event in this run if there is one.
1512  if (runAuxiliary->beginTime() == Timestamp::invalidTimestamp()) {
1513  runAuxiliary->setBeginTime(eventAux().time());
1514  }
1515 
1516  // For backwards compatibility when the Run's ProcessHistory included only processes where products were added to the
1517  // Run, and then the Run and Event auxiliaries could be different. Use the event ProcessHistoryID if there is one. It should
1518  // almost always be correct by the current definition (processes included if any products are added. This makes the run, lumi,
1519  // and event ProcessHistory's always be the same if no file merging occurs).
1520  if (!fileFormatVersion().processHistorySameWithinRun()) {
1521  fillEventHistory();
1522  runAuxiliary->setProcessHistoryID(eventAux().processHistoryID());
1523  }
1524  }
1525  }
1526  savedRunAuxiliary_ = runAuxiliary;
1527  return runAuxiliary;
1528  }
1529 
1530  void RootFile::readRun_(RunPrincipal& runPrincipal) {
1531  MergeableRunProductMetadata* mergeableRunProductMetadata = nullptr;
1532  if (inputType_ == InputType::Primary) {
1533  mergeableRunProductMetadata = runPrincipal.mergeableRunProductMetadata();
1534  RootTree::EntryNumber const& entryNumber = runTree_.entryNumber();
1535  assert(entryNumber >= 0);
1536  mergeableRunProductMetadata->readRun(
1538  }
1539 
1540  if (!runHelper_->fakeNewRun()) {
1544  }
1545  // Begin code for backward compatibility before the existence of run trees.
1546  if (!runTree_.isValid()) {
1547  return;
1548  }
1549  // End code for backward compatibility before the existence of run trees.
1550  // NOTE: we use 0 for the index since do not do delayed reads for RunPrincipals
1553  // Read in all the products now.
1554  runPrincipal.readAllFromSourceAndMergeImmediately(mergeableRunProductMetadata);
1555  }
1556 
1557  std::shared_ptr<LuminosityBlockAuxiliary> RootFile::readLuminosityBlockAuxiliary_() {
1560  // Begin code for backward compatibility before the existence of lumi trees.
1561  if (!lumiTree_.isValid()) {
1563  assert(eventEntry != IndexIntoFile::invalidEntry);
1564  assert(eventTree_.current(eventEntry));
1565  fillEventAuxiliary(eventEntry);
1566 
1568  runHelper_->overrideRunNumber(lumi);
1569  return std::make_shared<LuminosityBlockAuxiliary>(
1571  }
1572  // End code for backward compatibility before the existence of lumi trees.
1574  std::shared_ptr<LuminosityBlockAuxiliary> lumiAuxiliary = fillLumiAuxiliary();
1575  assert(lumiAuxiliary->run() == indexIntoFileIter_.run());
1576  assert(lumiAuxiliary->luminosityBlock() == indexIntoFileIter_.lumi());
1577  runHelper_->overrideRunNumber(lumiAuxiliary->id());
1578  filePtr_->reportInputLumiSection(lumiAuxiliary->run(), lumiAuxiliary->luminosityBlock());
1579  if (lumiAuxiliary->beginTime() == Timestamp::invalidTimestamp()) {
1581  if (eventEntry != IndexIntoFile::invalidEntry) {
1582  assert(eventTree_.current(eventEntry));
1583  fillEventAuxiliary(eventEntry);
1584 
1585  lumiAuxiliary->setBeginTime(eventAux().time());
1586  }
1587  lumiAuxiliary->setEndTime(Timestamp::invalidTimestamp());
1588  }
1589  if (!fileFormatVersion().processHistorySameWithinRun() && savedRunAuxiliary_) {
1590  lumiAuxiliary->setProcessHistoryID(savedRunAuxiliary_->processHistoryID());
1591  }
1592  return lumiAuxiliary;
1593  }
1594 
1598  // Begin code for backward compatibility before the existence of lumi trees.
1599  if (!lumiTree_.isValid()) {
1601  return;
1602  }
1603  // End code for backward compatibility before the existence of lumi trees.
1605  // NOTE: we use 0 for the index since do not do delayed reads for LuminosityBlockPrincipals
1608  // Read in all the products now.
1609  lumiPrincipal.readAllFromSourceAndMergeImmediately();
1611  }
1612 
1616  return false;
1618  return true;
1619  }
1620 
1624  return false;
1626  return true;
1627  }
1628 
1632  return false;
1634  return true;
1635  }
1636 
1640  }
1643  return false;
1644  if (run != indexIntoFileIter_.run())
1645  return false;
1646  if (lumi != indexIntoFileIter_.lumi())
1647  return false;
1649  return true;
1650  }
1651 
1653  // Read in the event history tree, if we have one...
1654  if (fileFormatVersion().eventHistoryTree()) {
1655  history_ = std::make_unique<History>(); // propagate_const<T> has no reset() function
1656  eventHistoryTree_ = dynamic_cast<TTree*>(filePtr_->Get(poolNames::eventHistoryTreeName().c_str()));
1657  if (!eventHistoryTree_) {
1658  throw Exception(errors::EventCorruption) << "Failed to find the event history tree.\n";
1659  }
1660  }
1661  }
1662 
1664  std::vector<std::shared_ptr<IndexIntoFile>> const& indexesIntoFiles,
1665  std::vector<std::shared_ptr<IndexIntoFile>>::size_type currentIndexIntoFile) {
1666  if (duplicateChecker_ && !duplicateChecker_->checkDisabled()) {
1667  if (eventTree_.next()) {
1669  duplicateChecker_->inputFileOpened(
1670  eventAux().isRealData(), indexIntoFile_, indexesIntoFiles, currentIndexIntoFile);
1671  }
1673  }
1674  }
1675 
1676  void RootFile::markBranchToBeDropped(bool dropDescendants,
1677  BranchDescription const& branch,
1678  std::set<BranchID>& branchesToDrop,
1679  std::map<BranchID, BranchID> const& droppedToKeptAlias) const {
1680  if (dropDescendants) {
1681  branchChildren_->appendToDescendants(branch, branchesToDrop, droppedToKeptAlias);
1682  } else {
1683  branchesToDrop.insert(branch.branchID());
1684  }
1685  }
1686 
1688  ProductSelectorRules const& rules,
1689  bool dropDescendants,
1690  InputType inputType) {
1691  // This is the selector for drop on input.
1692  ProductSelector productSelector;
1693  productSelector.initialize(rules, reg.allBranchDescriptions());
1694 
1695  std::vector<BranchDescription const*> associationDescriptions;
1696 
1698  // Do drop on input. On the first pass, just fill in a set of branches to be dropped.
1699  std::set<BranchID> branchesToDrop;
1700  std::map<BranchID, BranchID> droppedToKeptAlias;
1701  for (auto const& product : prodList) {
1702  BranchDescription const& prod = product.second;
1703  if (prod.branchID() != prod.originalBranchID() && prod.present()) {
1704  droppedToKeptAlias[prod.originalBranchID()] = prod.branchID();
1705  }
1706  }
1707  for (auto const& product : prodList) {
1708  BranchDescription const& prod = product.second;
1709  // Special handling for ThinnedAssociations
1710  if (prod.unwrappedType() == typeid(ThinnedAssociation) && prod.present()) {
1711  if (inputType != InputType::SecondarySource) {
1712  associationDescriptions.push_back(&prod);
1713  } else {
1714  markBranchToBeDropped(dropDescendants, prod, branchesToDrop, droppedToKeptAlias);
1715  }
1716  } else if (!productSelector.selected(prod)) {
1717  markBranchToBeDropped(dropDescendants, prod, branchesToDrop, droppedToKeptAlias);
1718  }
1719  }
1720 
1721  if (inputType != InputType::SecondarySource) {
1722  // Decide whether to keep the thinned associations and corresponding
1723  // entries in the helper. For secondary source they are all dropped,
1724  // but in other cases we look for thinned collections the associations
1725  // redirect a Ref or Ptr to when dereferencing them.
1726 
1727  // Need a list of kept products in order to determine which thinned associations
1728  // are kept.
1729  std::set<BranchID> keptProductsInEvent;
1730  for (auto const& product : prodList) {
1731  BranchDescription const& prod = product.second;
1732  if (branchesToDrop.find(prod.branchID()) == branchesToDrop.end() && prod.present() &&
1733  prod.branchType() == InEvent) {
1734  keptProductsInEvent.insert(prod.branchID());
1735  }
1736  }
1737 
1738  // Decide which ThinnedAssociations to keep and store the decision in keepAssociation
1739  std::map<BranchID, bool> keepAssociation;
1740  fileThinnedAssociationsHelper_->selectAssociationProducts(
1741  associationDescriptions, keptProductsInEvent, keepAssociation);
1742 
1743  for (auto association : associationDescriptions) {
1744  if (!keepAssociation[association->branchID()]) {
1745  markBranchToBeDropped(dropDescendants, *association, branchesToDrop, droppedToKeptAlias);
1746  }
1747  }
1748 
1749  // Also delete the dropped associations from the ThinnedAssociationsHelper
1750  auto temp = std::make_unique<ThinnedAssociationsHelper>();
1751  for (auto const& associationBranches : fileThinnedAssociationsHelper_->data()) {
1752  auto iter = keepAssociation.find(associationBranches.association());
1753  if (iter != keepAssociation.end() && iter->second) {
1754  temp->addAssociation(associationBranches);
1755  }
1756  }
1757  // propagate_const<T> has no reset() function
1758  fileThinnedAssociationsHelper_ = std::unique_ptr<ThinnedAssociationsHelper>(temp.release());
1759  }
1760 
1761  // On this pass, actually drop the branches.
1762  std::set<BranchID>::const_iterator branchesToDropEnd = branchesToDrop.end();
1763  for (ProductRegistry::ProductList::iterator it = prodList.begin(), itEnd = prodList.end(); it != itEnd;) {
1764  BranchDescription const& prod = it->second;
1765  bool drop = branchesToDrop.find(prod.branchID()) != branchesToDropEnd;
1766  if (drop) {
1767  if (!prod.dropped()) {
1768  if (productSelector.selected(prod) && prod.unwrappedType() != typeid(ThinnedAssociation)) {
1769  LogWarning("RootFile") << "Branch '" << prod.branchName() << "' is being dropped from the input\n"
1770  << "of file '" << file_ << "' because it is dependent on a branch\n"
1771  << "that was explicitly dropped.\n";
1772  }
1773  treePointers_[prod.branchType()]->dropBranch(newBranchToOldBranch(prod.branchName()));
1774  hasNewlyDroppedBranch_[prod.branchType()] = true;
1775  }
1776  ProductRegistry::ProductList::iterator icopy = it;
1777  ++it;
1778  prodList.erase(icopy);
1779  } else {
1780  ++it;
1781  }
1782  }
1783 
1784  // Drop on input mergeable run and lumi products, this needs to be invoked for secondary file input
1785  if (inputType == InputType::SecondaryFile) {
1786  TString tString;
1787  for (ProductRegistry::ProductList::iterator it = prodList.begin(), itEnd = prodList.end(); it != itEnd;) {
1788  BranchDescription const& prod = it->second;
1789  if (prod.branchType() != InEvent) {
1790  TClass* cp = prod.wrappedType().getClass();
1791  void* p = cp->New();
1792  int offset = cp->GetBaseClassOffset(edProductClass_);
1793  std::unique_ptr<WrapperBase> edp = getWrapperBasePtr(p, offset);
1794  if (edp->isMergeable()) {
1795  treePointers_[prod.branchType()]->dropBranch(newBranchToOldBranch(prod.branchName()));
1796  ProductRegistry::ProductList::iterator icopy = it;
1797  ++it;
1798  prodList.erase(icopy);
1799  } else {
1800  ++it;
1801  }
1802  } else
1803  ++it;
1804  }
1805  }
1806  }
1807 
1809  signalslot::Signal<void(StreamContext const&, ModuleCallingContext const&)> const* preEventReadSource,
1810  signalslot::Signal<void(StreamContext const&, ModuleCallingContext const&)> const* postEventReadSource) {
1811  eventTree_.setSignals(preEventReadSource, postEventReadSource);
1812  }
1813 
1814  std::unique_ptr<MakeProvenanceReader> RootFile::makeProvenanceReaderMaker(InputType inputType) {
1816  readParentageTree(inputType);
1817  return std::make_unique<MakeReducedProvenanceReader>(parentageIDLookup_);
1818  } else if (fileFormatVersion_.splitProductIDs()) {
1819  readParentageTree(inputType);
1820  return std::make_unique<MakeFullProvenanceReader>();
1821  } else if (fileFormatVersion_.perEventProductIDs()) {
1822  auto entryDescriptionMap = std::make_unique<EntryDescriptionMap>();
1823  readEntryDescriptionTree(*entryDescriptionMap, inputType);
1824  return std::make_unique<MakeOldProvenanceReader>(std::move(entryDescriptionMap));
1825  } else {
1826  return std::make_unique<MakeDummyProvenanceReader>();
1827  }
1828  }
1829 
1830  std::shared_ptr<ProductProvenanceRetriever> RootFile::makeProductProvenanceRetriever(unsigned int iStreamID) {
1831  if (eventProductProvenanceRetrievers_.size() <= iStreamID) {
1832  eventProductProvenanceRetrievers_.resize(iStreamID + 1);
1833  }
1834  if (!eventProductProvenanceRetrievers_[iStreamID]) {
1835  // propagate_const<T> has no reset() function
1836  eventProductProvenanceRetrievers_[iStreamID] = std::make_shared<ProductProvenanceRetriever>(
1838  }
1839  eventProductProvenanceRetrievers_[iStreamID]->reset();
1840  return eventProductProvenanceRetriever(iStreamID);
1841  }
1842 
1844  public:
1845  ReducedProvenanceReader(RootTree* iRootTree,
1846  std::vector<ParentageID> const& iParentageIDLookup,
1847  DaqProvenanceHelper const* daqProvenanceHelper);
1848 
1849  std::set<ProductProvenance> readProvenance(unsigned int) const override;
1850 
1851  private:
1852  void readProvenanceAsync(WaitingTask* task,
1853  ModuleCallingContext const* moduleCallingContext,
1854  unsigned int transitionIndex,
1855  std::atomic<const std::set<ProductProvenance>*>& writeTo) const override;
1856 
1861  std::vector<ParentageID> const& parentageIDLookup_;
1863  std::shared_ptr<std::recursive_mutex> mutex_;
1865  };
1866 
1868  std::vector<ParentageID> const& iParentageIDLookup,
1869  DaqProvenanceHelper const* daqProvenanceHelper)
1871  rootTree_(iRootTree),
1872  pProvVector_(&provVector_),
1873  parentageIDLookup_(iParentageIDLookup),
1874  daqProvenanceHelper_(daqProvenanceHelper),
1875  mutex_(SharedResourcesRegistry::instance()->createAcquirerForSourceDelayedReader().second),
1876  acquirer_(SharedResourcesRegistry::instance()->createAcquirerForSourceDelayedReader().first) {
1877  provBranch_ =
1878  rootTree_->tree()->GetBranch(BranchTypeToProductProvenanceBranchName(rootTree_->branchType()).c_str());
1879  }
1880 
1881  namespace {
1883  template <typename R>
1884  void readProvenanceAsyncImpl(R const* iThis,
1886  WaitingTask* task,
1887  unsigned int transitionIndex,
1888  std::atomic<const std::set<ProductProvenance>*>& writeTo,
1889  ModuleCallingContext const* iContext,
1890  SignalType const* pre,
1891  SignalType const* post) {
1892  if (nullptr == writeTo.load()) {
1893  //need to be sure the task isn't run until after the read
1894  WaitingTaskHolder taskHolder{task};
1895  auto pWriteTo = &writeTo;
1896 
1897  auto serviceToken = ServiceRegistry::instance().presentToken();
1898 
1899  chain.push([holder = std::move(taskHolder),
1900  pWriteTo,
1901  iThis,
1902  transitionIndex,
1903  iContext,
1904  pre,
1905  post,
1906  serviceToken]() mutable {
1907  if (nullptr == pWriteTo->load()) {
1908  ServiceRegistry::Operate operate(serviceToken);
1909  std::unique_ptr<const std::set<ProductProvenance>> prov;
1910  try {
1911  if (pre) {
1912  pre->emit(*(iContext->getStreamContext()), *iContext);
1913  }
1914  prov = std::make_unique<const std::set<ProductProvenance>>(iThis->readProvenance(transitionIndex));
1915  if (post) {
1916  post->emit(*(iContext->getStreamContext()), *iContext);
1917  }
1918 
1919  } catch (...) {
1920  if (post) {
1921  post->emit(*(iContext->getStreamContext()), *iContext);
1922  }
1923 
1924  holder.doneWaiting(std::current_exception());
1925  return;
1926  }
1927  const std::set<ProductProvenance>* expected = nullptr;
1928 
1929  if (pWriteTo->compare_exchange_strong(expected, prov.get())) {
1930  prov.release();
1931  }
1932  }
1933  holder.doneWaiting(std::exception_ptr());
1934  });
1935  }
1936  }
1937  } // namespace
1938 
1940  ModuleCallingContext const* moduleCallingContext,
1941  unsigned int transitionIndex,
1942  std::atomic<const std::set<ProductProvenance>*>& writeTo) const {
1943  readProvenanceAsyncImpl(this,
1945  task,
1946  transitionIndex,
1947  writeTo,
1948  moduleCallingContext,
1949  rootTree_->rootDelayedReader()->preEventReadFromSourceSignal(),
1950  rootTree_->rootDelayedReader()->postEventReadFromSourceSignal());
1951  }
1952 
1953  std::set<ProductProvenance> ReducedProvenanceReader::readProvenance(unsigned int transitionIndex) const {
1954  {
1955  std::lock_guard<std::recursive_mutex> guard(*mutex_);
1956  ReducedProvenanceReader* me = const_cast<ReducedProvenanceReader*>(this);
1957  me->rootTree_->fillBranchEntry(
1958  me->provBranch_, me->rootTree_->entryNumberForIndex(transitionIndex), me->pProvVector_);
1959  }
1960  std::set<ProductProvenance> retValue;
1961  if (daqProvenanceHelper_) {
1962  for (auto const& prov : provVector_) {
1963  BranchID bid(prov.branchID_);
1964  retValue.emplace(daqProvenanceHelper_->mapBranchID(BranchID(prov.branchID_)),
1965  daqProvenanceHelper_->mapParentageID(parentageIDLookup_[prov.parentageIDIndex_]));
1966  }
1967  } else {
1968  for (auto const& prov : provVector_) {
1969  if (prov.parentageIDIndex_ >= parentageIDLookup_.size()) {
1971  << "ReducedProvenanceReader::ReadProvenance\n"
1972  << "The parentage ID index value " << prov.parentageIDIndex_
1973  << " is out of bounds. The maximum value is " << parentageIDLookup_.size() - 1 << ".\n"
1974  << "This should never happen.\n"
1975  << "Please report this to the framework hypernews forum 'hn-cms-edmFramework@cern.ch'.\n";
1976  }
1977  retValue.emplace(BranchID(prov.branchID_), parentageIDLookup_[prov.parentageIDIndex_]);
1978  }
1979  }
1980  return retValue;
1981  }
1982 
1984  public:
1985  explicit FullProvenanceReader(RootTree* rootTree, DaqProvenanceHelper const* daqProvenanceHelper);
1987  std::set<ProductProvenance> readProvenance(unsigned int transitionIndex) const override;
1988 
1989  private:
1991  ModuleCallingContext const* moduleCallingContext,
1992  unsigned int transitionIndex,
1993  std::atomic<const std::set<ProductProvenance>*>& writeTo) const override;
1994 
1999  std::shared_ptr<std::recursive_mutex> mutex_;
2001  };
2002 
2005  rootTree_(rootTree),
2006  infoVector_(),
2007  pInfoVector_(&infoVector_),
2008  daqProvenanceHelper_(daqProvenanceHelper),
2009  mutex_(SharedResourcesRegistry::instance()->createAcquirerForSourceDelayedReader().second),
2010  acquirer_(SharedResourcesRegistry::instance()->createAcquirerForSourceDelayedReader().first) {}
2011 
2013  ModuleCallingContext const* moduleCallingContext,
2014  unsigned int transitionIndex,
2015  std::atomic<const std::set<ProductProvenance>*>& writeTo) const {
2016  readProvenanceAsyncImpl(this,
2018  task,
2019  transitionIndex,
2020  writeTo,
2021  moduleCallingContext,
2024  }
2025 
2026  std::set<ProductProvenance> FullProvenanceReader::readProvenance(unsigned int transitionIndex) const {
2027  {
2028  std::lock_guard<std::recursive_mutex> guard(*mutex_);
2031  }
2032  std::set<ProductProvenance> retValue;
2033  if (daqProvenanceHelper_) {
2034  for (auto const& info : infoVector_) {
2035  retValue.emplace(daqProvenanceHelper_->mapBranchID(info.branchID()),
2036  daqProvenanceHelper_->mapParentageID(info.parentageID()));
2037  }
2038  } else {
2039  for (auto const& info : infoVector_) {
2040  retValue.emplace(info);
2041  }
2042  }
2043  return retValue;
2044  }
2045 
2047  public:
2048  explicit OldProvenanceReader(RootTree* rootTree,
2049  EntryDescriptionMap const& theMap,
2050  DaqProvenanceHelper const* daqProvenanceHelper);
2051  ~OldProvenanceReader() override {}
2052  std::set<ProductProvenance> readProvenance(unsigned int transitionIndex) const override;
2053 
2054  private:
2056  ModuleCallingContext const* moduleCallingContext,
2057  unsigned int transitionIndex,
2058  std::atomic<const std::set<ProductProvenance>*>& writeTo) const override;
2059 
2061  std::vector<EventEntryInfo> infoVector_;
2062  mutable std::vector<EventEntryInfo>* pInfoVector_;
2065  std::shared_ptr<std::recursive_mutex> mutex_;
2067  };
2068 
2070  EntryDescriptionMap const& theMap,
2071  DaqProvenanceHelper const* daqProvenanceHelper)
2073  rootTree_(rootTree),
2074  infoVector_(),
2076  entryDescriptionMap_(theMap),
2077  daqProvenanceHelper_(daqProvenanceHelper),
2078  mutex_(SharedResourcesRegistry::instance()->createAcquirerForSourceDelayedReader().second),
2079  acquirer_(SharedResourcesRegistry::instance()->createAcquirerForSourceDelayedReader().first) {}
2080 
2082  ModuleCallingContext const* moduleCallingContext,
2083  unsigned int transitionIndex,
2084  std::atomic<const std::set<ProductProvenance>*>& writeTo) const {
2085  readProvenanceAsyncImpl(this,
2087  task,
2088  transitionIndex,
2089  writeTo,
2090  moduleCallingContext,
2091  rootTree_->rootDelayedReader()->preEventReadFromSourceSignal(),
2092  rootTree_->rootDelayedReader()->postEventReadFromSourceSignal());
2093  }
2094 
2095  std::set<ProductProvenance> OldProvenanceReader::readProvenance(unsigned int transitionIndex) const {
2096  {
2097  std::lock_guard<std::recursive_mutex> guard(*mutex_);
2098  rootTree_->branchEntryInfoBranch()->SetAddress(&pInfoVector_);
2099  roottree::getEntry(rootTree_->branchEntryInfoBranch(), rootTree_->entryNumberForIndex(transitionIndex));
2100  }
2101  std::set<ProductProvenance> retValue;
2102  for (auto const& info : infoVector_) {
2103  EntryDescriptionMap::const_iterator iter = entryDescriptionMap_.find(info.entryDescriptionID());
2104  assert(iter != entryDescriptionMap_.end());
2105  Parentage parentage(iter->second.parents());
2106  if (daqProvenanceHelper_) {
2107  retValue.emplace(daqProvenanceHelper_->mapBranchID(info.branchID()),
2108  daqProvenanceHelper_->mapParentageID(parentage.id()));
2109  } else {
2110  retValue.emplace(info.branchID(), parentage.id());
2111  }
2112  }
2113  return retValue;
2114  }
2115 
2117  public:
2120 
2121  private:
2122  std::set<ProductProvenance> readProvenance(unsigned int) const override;
2124  ModuleCallingContext const* moduleCallingContext,
2125  unsigned int transitionIndex,
2126  std::atomic<const std::set<ProductProvenance>*>& writeTo) const override;
2127  };
2128 
2130 
2131  std::set<ProductProvenance> DummyProvenanceReader::readProvenance(unsigned int) const {
2132  // Not providing parentage!!!
2133  return std::set<ProductProvenance>{};
2134  }
2136  ModuleCallingContext const* moduleCallingContext,
2137  unsigned int transitionIndex,
2138  std::atomic<const std::set<ProductProvenance>*>& writeTo) const {
2139  if (nullptr == writeTo.load()) {
2140  auto emptyProv = std::make_unique<const std::set<ProductProvenance>>();
2141  const std::set<ProductProvenance>* expected = nullptr;
2142  if (writeTo.compare_exchange_strong(expected, emptyProv.get())) {
2143  emptyProv.release();
2144  }
2145  }
2146  }
2147 
2148  std::unique_ptr<ProvenanceReaderBase> MakeDummyProvenanceReader::makeReader(RootTree&,
2149  DaqProvenanceHelper const*) const {
2150  return std::make_unique<DummyProvenanceReader>();
2151  }
2152 
2153  std::unique_ptr<ProvenanceReaderBase> MakeOldProvenanceReader::makeReader(
2154  RootTree& rootTree, DaqProvenanceHelper const* daqProvenanceHelper) const {
2155  return std::make_unique<OldProvenanceReader>(&rootTree, *entryDescriptionMap_, daqProvenanceHelper);
2156  }
2157 
2158  std::unique_ptr<ProvenanceReaderBase> MakeFullProvenanceReader::makeReader(
2159  RootTree& rootTree, DaqProvenanceHelper const* daqProvenanceHelper) const {
2160  return std::make_unique<FullProvenanceReader>(&rootTree, daqProvenanceHelper);
2161  }
2162 
2163  std::unique_ptr<ProvenanceReaderBase> MakeReducedProvenanceReader::makeReader(
2164  RootTree& rootTree, DaqProvenanceHelper const* daqProvenanceHelper) const {
2165  return std::make_unique<ReducedProvenanceReader>(&rootTree, parentageIDLookup_, daqProvenanceHelper);
2166  }
2167 } // namespace edm
void dropOnInput(ProductRegistry &reg, ProductSelectorRules const &rules, bool dropDescendants, InputType inputType)
Definition: RootFile.cc:1687
RunNumber_t run() const
Definition: EventID.h:39
EventID const & eventID() const
Definition: RootFile.h:215
Int_t getEntry(TBranch *branch, EntryNumber entryNumber)
Definition: RootTree.cc:495
void fillEventNumbersOrEntries(bool needEventNumbers, bool needEventEntries) const
EventNumber_t event() const
Definition: EventID.h:41
std::string const & idToParameterSetBlobsBranchName()
Definition: BranchType.cc:261
edm::propagate_const< std::unique_ptr< ThinnedAssociationsHelper > > fileThinnedAssociationsHelper_
Definition: RootFile.h:340
std::vector< ProcessConfiguration > ProcessConfigurationVector
void setEventFinder(std::shared_ptr< EventFinder > ptr) const
std::string const & branchName() const
StoredProductProvenanceVector provVector_
Definition: RootFile.cc:1859
bool isRealData() const
bool selected(BranchDescription const &desc) const
std::string const & BranchTypeToAuxiliaryBranchName(BranchType const &branchType)
Definition: BranchType.cc:116
unsigned int const defaultNonEventLearningEntries
Definition: RootTree.h:49
InputType
Definition: InputType.h:5
static const TGPicture * info(bool iBackgroundIsBlack)
void doneFileInitialization() const
Clears the temporary vector of event numbers to reduce memory usage.
static constexpr int invalidIndex
TPRegexp parents
Definition: eve_filter.cc:21
BranchType const & branchType() const
std::string const & parentageTreeName()
Definition: BranchType.cc:160
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
std::shared_ptr< BranchIDLists const > branchIDLists_
Definition: RootFile.h:338
std::string const & entryDescriptionBranchName()
Definition: BranchType.cc:155
bool skipEvents(int &offset)
Definition: RootFile.cc:1325
StreamContext const * getStreamContext() const
edm::propagate_const< std::shared_ptr< DuplicateChecker > > duplicateChecker_
Definition: RootFile.h:350
FileFormatVersion fileFormatVersion() const
Definition: RootFile.h:219
std::shared_ptr< LuminosityBlockAuxiliary > fillLumiAuxiliary()
Definition: RootFile.cc:1282
ProductProvenanceVector infoVector_
Definition: RootFile.cc:1996
static std::string const source("source")
static Timestamp invalidTimestamp()
Definition: Timestamp.h:101
ForwardSequence::const_iterator lower_bound_all(ForwardSequence const &s, Datum const &d)
wrappers for std::lower_bound
Definition: Algorithms.h:69
Definition: chain.py:1
void readEntryDescriptionTree(EntryDescriptionMap &entryDescriptionMap, InputType inputType)
Definition: RootFile.cc:583
bool branchListIndexesUnchanged() const
Definition: RootFile.h:222
RunNumber_t run() const
Definition: RunID.h:39
std::vector< std::string > const & branchNames() const
Definition: RootTree.h:138
bool setEntryAtNextEventInLumi(RunNumber_t run, LuminosityBlockNumber_t lumi)
Definition: RootFile.cc:1637
static PFTauRenderPlugin instance
MakeOldProvenanceReader(std::unique_ptr< EntryDescriptionMap > &&entryDescriptionMap)
Definition: RootFile.cc:77
int whyNotFastClonable_
Definition: RootFile.h:328
std::vector< BranchID > & parentsForUpdate()
Definition: Parentage.h:45
edm::propagate_const< std::shared_ptr< EventSkipperByID > > eventSkipperByID_
Definition: RootFile.h:313
edm::propagate_const< std::shared_ptr< ThinnedAssociationsHelper > > thinnedAssociationsHelper_
Definition: RootFile.h:341
ParentageID id() const
Definition: Parentage.cc:23
DaqProvenanceHelper const * daqProvenanceHelper_
Definition: RootFile.cc:1998
std::map< std::string, std::string > newBranchToOldBranch_
Definition: RootFile.h:344
bool empty() const
True if no runs, lumis, or events are in the file.
std::map< BranchKey, BranchDescription > ProductList
BranchID const & mapBranchID(BranchID const &branchID) const
#define nullptr
bool registerProcessHistory(ProcessHistory const &processHistory)
bool setEntryAtRun(RunNumber_t run)
Definition: RootFile.cc:1629
void readRun_(RunPrincipal &runPrincipal)
Definition: RootFile.cc:1530
ProductProvenanceVector * pInfoVector_
Definition: RootFile.cc:1997
RootTree lumiTree_
Definition: RootFile.h:333
Timestamp const & time() const
InputType inputType_
Definition: RootFile.h:357
edm::propagate_const< ProcessHistoryRegistry * > processHistoryRegistry_
Definition: RootFile.h:311
edm::propagate_const< std::unique_ptr< DaqProvenanceHelper > > daqProvenanceHelper_
Definition: RootFile.h:355
edm::propagate_const< std::shared_ptr< RunAuxiliary > > savedRunAuxiliary_
Definition: RootFile.h:325
unsigned long long EventNumber_t
EntryNumber const & entries() const
Definition: RootTree.h:135
RunNumber_t run() const
void setSignals(signalslot::Signal< void(StreamContext const &, ModuleCallingContext const &)> const *preEventReadSource, signalslot::Signal< void(StreamContext const &, ModuleCallingContext const &)> const *postEventReadSource)
Definition: RootTree.cc:488
std::string const & fileFormatVersionBranchName()
Definition: BranchType.cc:219
IndexIntoFileItr begin(SortOrder sortOrder) const
FullProvenanceReader(RootTree *rootTree, DaqProvenanceHelper const *daqProvenanceHelper)
Definition: RootFile.cc:2003
EntryDescriptionMap const & entryDescriptionMap_
Definition: RootFile.cc:2063
std::vector< BranchID > const & parents() const
std::string const & eventSelectionsBranchName()
Definition: BranchType.cc:249
edm::propagate_const< std::unique_ptr< EntryDescriptionMap > > entryDescriptionMap_
Definition: RootFile.cc:83
void initializeDuplicateChecker(std::vector< std::shared_ptr< IndexIntoFile >> const &indexesIntoFiles, std::vector< std::shared_ptr< IndexIntoFile >>::size_type currentIndexIntoFile)
Definition: RootFile.cc:1663
void push(T &&iAction)
asynchronously pushes functor iAction into queue
InputSource::ProcessingMode processingMode_
Definition: RootFile.h:342
~RootFileEventFinder() override
Definition: RootFile.cc:122
IndexIntoFile::IndexIntoFileItr indexIntoFileIter_
Definition: RootFile.h:321
std::shared_ptr< ProductProvenanceRetriever const > eventProductProvenanceRetriever(size_t index) const
Definition: RootFile.h:301
bool current() const
Definition: RootTree.h:128
void fillRunPrincipal(ProcessHistoryRegistry const &processHistoryRegistry, DelayedReader *reader=0)
Definition: RunPrincipal.cc:26
void stable_sort_all(RandomAccessSequence &s)
wrappers for std::stable_sort
Definition: Algorithms.h:103
std::shared_ptr< std::recursive_mutex > mutex_
Definition: RootFile.cc:2065
LuminosityBlockNumber_t lumi() const
void fillBranchEntryMeta(TBranch *branch, T *&pbuf)
Definition: RootTree.h:147
std::unique_ptr< FileBlock > createFileBlock() const
Definition: RootFile.cc:708
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:40
void trainCache(char const *branchNames)
Definition: RootTree.cc:460
bool readCurrentEvent(EventPrincipal &cache)
Definition: RootFile.cc:1438
SharedResourcesAcquirer acquirer_
Definition: RootFile.cc:2066
~FullProvenanceReader() override
Definition: RootFile.cc:1986
ServiceToken presentToken() const
std::shared_ptr< ProductRegistry const > productRegistry() const
Definition: RootFile.h:210
uint16_t size_type
unsigned int LuminosityBlockNumber_t
IndexIntoFileItr findRunPosition(RunNumber_t run) const
Same as findPosition.
void readProvenanceAsync(WaitingTask *task, ModuleCallingContext const *moduleCallingContext, unsigned int transitionIndex, std::atomic< const std::set< ProductProvenance > * > &writeTo) const override
Definition: RootFile.cc:2081
void readAllFromSourceAndMergeImmediately(MergeableRunProductMetadata const *mergeableRunProductMetadata=0)
Definition: Principal.cc:904
TBranch * branchEntryInfoBranch() const
Definition: RootTree.h:186
bool fillEventAuxiliary(IndexIntoFile::EntryNumber_t entry)
Definition: RootFile.cc:1217
MakeReducedProvenanceReader(std::vector< ParentageID > const &parentageIDLookup)
Definition: RootFile.cc:92
IndexIntoFileItr findPosition(RunNumber_t run, LuminosityBlockNumber_t lumi=0U, EventNumber_t event=0U) const
std::vector< EventSelectionID > EventSelectionIDVector
edm::propagate_const< TClass * > edProductClass_
Definition: RootFile.h:356
LuminosityBlockNumber_t luminosityBlock() const
FileFormatVersion fileFormatVersion_
Definition: RootFile.h:314
TTree const * metaTree() const
Definition: RootTree.h:182
RootFile(std::string const &fileName, ProcessConfiguration const &processConfiguration, std::string const &logicalFileName, std::shared_ptr< InputFile > filePtr, std::shared_ptr< EventSkipperByID > eventSkipperByID, bool skipAnyEvents, int remainingEvents, int remainingLumis, unsigned int nStreams, unsigned int treeCacheSize, int treeMaxVirtualSize, InputSource::ProcessingMode processingMode, RunHelperBase *runHelper, bool noEventSort, ProductSelectorRules const &productSelectorRules, InputType inputType, std::shared_ptr< BranchIDListHelper > branchIDListHelper, std::shared_ptr< ThinnedAssociationsHelper > thinnedAssociationsHelper, std::vector< BranchID > const *associationsFromSecondary, std::shared_ptr< DuplicateChecker > duplicateChecker, bool dropDescendantsOfDroppedProducts, ProcessHistoryRegistry &processHistoryRegistry, std::vector< std::shared_ptr< IndexIntoFile >> const &indexesIntoFiles, std::vector< std::shared_ptr< IndexIntoFile >>::size_type currentIndexIntoFile, std::vector< ProcessHistoryID > &orderedProcessHistoryIDs, bool bypassVersionCheck, bool labelRawDataLikeMC, bool usingGoToEvent, bool enablePrefetching)
Definition: RootFile.cc:139
std::string const & parameterSetsTreeName()
Definition: BranchType.cc:257
void setPosition(IndexIntoFile::IndexIntoFileItr const &position)
Definition: RootFile.cc:734
std::vector< edm::propagate_const< std::shared_ptr< ProductProvenanceRetriever > > > eventProductProvenanceRetrievers_
Definition: RootFile.h:353
edm::propagate_const< RootTree * > rootTree_
Definition: RootFile.cc:2060
ProductList const & productList() const
U second(std::pair< T, U > const &p)
std::vector< EventProcessHistoryID >::const_iterator eventProcessHistoryIter_
Definition: RootFile.h:324
void reduceProcessHistoryIDs(ProcessHistoryRegistry const &processHistoryRegistry)
bool skipThisEntry()
Definition: RootFile.cc:743
char const * label
TTree const * tree() const
Definition: RootTree.h:180
FileID fid_
Definition: RootFile.h:315
long long EntryNumber_t
bool containsItem(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const
Definition: RootFile.cc:794
void setParents(std::vector< BranchID > const &parents)
Definition: Parentage.h:46
DaqProvenanceHelper const * daqProvenanceHelper_
Definition: RootFile.cc:1862
std::string const logicalFile_
Definition: RootFile.h:309
def principal(options)
std::vector< BranchListIndex > BranchListIndexes
IndexIntoFile::IndexIntoFileItr indexIntoFileEnd_
Definition: RootFile.h:320
std::string moduleName(Provenance const &provenance)
Definition: Provenance.cc:27
void fillLuminosityBlockPrincipal(ProcessHistoryRegistry const &processHistoryRegistry, DelayedReader *reader=0)
void readParentageTree(InputType inputType)
Definition: RootFile.cc:629
std::string const & processHistoryMapBranchName()
Definition: BranchType.cc:194
std::vector< ProcessHistoryID > & setProcessHistoryIDs()
bool next()
Definition: RootTree.h:125
edm::propagate_const< std::unique_ptr< StoredMergeableRunProductMetadata > > storedMergeableRunProductMetadata_
Definition: RootFile.h:322
TClass * getClass() const
bool noEventSort_
Definition: RootFile.h:327
std::string const & className() const
bool wasLastEventJustRead() const
Definition: RootFile.cc:843
void insertEntryForIndex(unsigned int index)
Definition: RootTree.cc:104
DelayedReader * resetAndGetRootDelayedReader() const
Definition: RootTree.cc:122
bool setEntryAtLumi(RunNumber_t run, LuminosityBlockNumber_t lumi)
Definition: RootFile.cc:1621
std::string friendlyName(std::string const &iFullName)
static constexpr RunNumber_t invalidRun
std::string const & entryDescriptionTreeName()
Definition: BranchType.cc:147
void close()
Definition: RootFile.cc:1188
virtual signalslot::Signal< void(StreamContext const &, ModuleCallingContext const &)> const * postEventReadFromSourceSignal() const =0
std::string const & fid() const
Definition: FileID.h:19
std::shared_ptr< std::recursive_mutex > mutex_
Definition: RootFile.cc:1999
std::string const & mergeableRunProductMetadataBranchName()
Definition: BranchType.cc:239
RootTree const & runTree() const
Definition: RootFile.h:218
bool modifiedIDs() const
Definition: RootFile.h:223
IndexIntoFile::EntryNumber_t lastEventEntryNumberRead_
Definition: RootFile.h:336
void copyPosition(IndexIntoFileItr const &position)
Copy the position without modifying the pointer to the IndexIntoFile or size.
std::string const & indexIntoFileBranchName()
Definition: BranchType.cc:234
IndexIntoFileItr end(SortOrder sortOrder) const
Used to end an iteration over the Runs, Lumis, and Events in a file.
std::string const & eventHistoryBranchName()
Definition: BranchType.cc:244
std::set< ProductProvenance > readProvenance(unsigned int transitionIndex) const override
Definition: RootFile.cc:2026
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
edm::propagate_const< RootTree * > rootTree_
Definition: RootFile.cc:1857
std::shared_ptr< RunAuxiliary > readRunAuxiliary_()
Definition: RootFile.cc:1467
EventAuxiliary const & eventAux() const
Definition: RootFile.h:211
EventSelectionIDVector eventSelectionIDs_
Definition: RootFile.h:346
std::shared_ptr< LuminosityBlockAuxiliary > readLuminosityBlockAuxiliary_()
Definition: RootFile.cc:1557
bool eventHistoryTree() const
bool isEarlierRelease(std::string const &a, std::string const &b)
StoredProductProvenanceVector const * pProvVector_
Definition: RootFile.cc:1860
int whyNotFastClonable() const
Definition: RootFile.h:220
edm::propagate_const< std::unique_ptr< ProvenanceAdaptor > > provenanceAdaptor_
Definition: RootFile.h:351
StreamID streamID() const
static ServiceRegistry & instance()
RunNumber_t run() const
std::shared_ptr< RunAuxiliary > fillRunAuxiliary()
Definition: RootFile.cc:1305
bool skipAnyEvents_
Definition: RootFile.h:326
void setSignals(signalslot::Signal< void(StreamContext const &, ModuleCallingContext const &)> const *preEventReadSource, signalslot::Signal< void(StreamContext const &, ModuleCallingContext const &)> const *postEventReadSource)
Definition: RootFile.cc:1808
RootTree eventTree_
Definition: RootFile.h:332
std::vector< BranchDescription const * > allBranchDescriptions() const
EventNumber_t getEventNumberOfEntry(roottree::EntryNumber entry) const override
Definition: RootFile.cc:124
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
TypeWithDict const & unwrappedType() const
bool insertMapped(value_type const &v, bool forceUpdate=false)
Definition: Registry.cc:32
std::array< bool, NumBranchTypes > const & hasNewlyDroppedBranch() const
Definition: RootFile.h:221
IndexIntoFile::EntryType getNextItemType(RunNumber_t &run, LuminosityBlockNumber_t &lumi, EventNumber_t &event)
Definition: RootFile.cc:798
BranchListIndexes branchListIndexes_
Definition: RootFile.h:347
std::string const & metaDataTreeName()
Definition: BranchType.cc:169
virtual signalslot::Signal< void(StreamContext const &, ModuleCallingContext const &)> const * preEventReadFromSourceSignal() const =0
bool isDuplicateEvent()
Definition: RootFile.cc:781
LuminosityBlockNumber_t oldLuminosityBlock() const
EntryDescriptionID id() const
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
IndexIntoFile::EntryNumber_t EntryNumber
Definition: RootTree.h:50
bool wasFirstEventJustRead() const
Definition: RootFile.cc:849
std::string const & parameterSetMapBranchName()
Definition: BranchType.cc:184
Hash< ProcessHistoryType > ProcessHistoryID
std::unique_ptr< ProvenanceReaderBase > makeReader(RootTree &eventTree, DaqProvenanceHelper const *daqProvenanceHelper) const override
Definition: RootFile.cc:2148
edm::propagate_const< std::unique_ptr< History > > history_
Definition: RootFile.h:348
SerialTaskQueueChain & serialQueueChain() const
std::vector< ProductProvenance > ProductProvenanceVector
const int drop
std::string const & processHistoryBranchName()
Definition: BranchType.cc:199
IndexIntoFile & indexIntoFile_
Definition: RootFile.h:317
void readEvent(EventPrincipal &cache)
Definition: RootFile.cc:1414
RootTree runTree_
Definition: RootFile.h:334
SharedResourcesAcquirer acquirer_
Definition: RootFile.cc:2000
edm::propagate_const< std::unique_ptr< MakeProvenanceReader > > provenanceReaderMaker_
Definition: RootFile.h:352
EntryNumber const & entryNumber() const
Definition: RootTree.h:133
bool containsItem(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const
bool goToEvent(EventID const &eventID)
Definition: RootFile.cc:1381
std::string getReleaseVersion()
std::shared_ptr< RunAuxiliary const > savedRunAuxiliary() const
Definition: RootFile.h:295
std::set< ProductProvenance > readProvenance(unsigned int) const override
Definition: RootFile.cc:1953
void setAtEventEntry(IndexIntoFile::EntryNumber_t entry)
Definition: RootFile.cc:1465
bool storedProductProvenanceUsed() const
void fixIndexes(std::vector< ProcessHistoryID > &processHistoryIDs)
DelayedReader * rootDelayedReader() const
Definition: RootTree.cc:127
std::vector< RunOrLumiEntry > & setRunOrLumiEntries()
EntryNumber const & entryNumberForIndex(unsigned int index) const
Definition: RootTree.cc:99
void conversion(EventAux const &from, EventAuxiliary &to)
Definition: EventAux.cc:9
std::array< bool, NumBranchTypes > hasNewlyDroppedBranch_
Definition: RootFile.h:329
std::vector< EventNumber_t > & unsortedEventNumbers() const
unsigned int value() const
Definition: StreamID.h:42
static constexpr EntryNumber_t invalidEntry
ForwardSequence::const_iterator find_in_all(ForwardSequence const &s, Datum const &d)
wrappers for std::find
Definition: Algorithms.h:26
std::shared_ptr< ProductRegistry const > productRegistry_
Definition: RootFile.h:337
void setIfFastClonable(int remainingEvents, int remainingLumis)
Definition: RootFile.cc:664
std::unique_ptr< ProvenanceReaderBase > makeReader(RootTree &eventTree, DaqProvenanceHelper const *daqProvenanceHelper) const override
Definition: RootFile.cc:2163
MergeableRunProductMetadata * mergeableRunProductMetadata()
Definition: RunPrincipal.h:78
void fillBranchEntry(TBranch *branch, T *&pbuf)
Definition: RootTree.h:158
static constexpr LuminosityBlockNumber_t invalidLumi
IndexIntoFileItr findLumiPosition(RunNumber_t run, LuminosityBlockNumber_t lumi) const
std::map< EntryDescriptionID, EventEntryDescription > EntryDescriptionMap
Definition: RootFile.h:52
edm::propagate_const< std::shared_ptr< BranchChildren > > branchChildren_
Definition: RootFile.h:349
std::string const & parentageBranchName()
Definition: BranchType.cc:164
edm::propagate_const< std::shared_ptr< InputFile > > filePtr_
Definition: RootFile.h:312
std::shared_ptr< BranchChildren const > branchChildren() const
Definition: RootFile.h:298
double b
Definition: hdecay.h:120
LuminosityBlockNumber_t luminosityBlock() const
bool processHistorySameWithinRun() const
void fillEventHistory()
Definition: RootFile.cc:1226
ProcessHistoryID const & processHistoryID(int i) const
ProductList & productListUpdator()
void setProcessHistoryID(ProcessHistoryID const &phid)
unsigned int transitionIndex() const
void readProvenanceAsync(WaitingTask *task, ModuleCallingContext const *moduleCallingContext, unsigned int transitionIndex, std::atomic< const std::set< ProductProvenance > * > &writeTo) const override
Definition: RootFile.cc:2135
void readProvenanceAsync(WaitingTask *task, ModuleCallingContext const *moduleCallingContext, unsigned int transitionIndex, std::atomic< const std::set< ProductProvenance > * > &writeTo) const override
Definition: RootFile.cc:1939
std::vector< ParentageID > const & parentageIDLookup_
Definition: RootFile.cc:1861
std::shared_ptr< std::recursive_mutex > mutex_
Definition: RootFile.cc:1863
std::unique_ptr< ProvenanceReaderBase > makeReader(RootTree &eventTree, DaqProvenanceHelper const *daqProvenanceHelper) const override
Definition: RootFile.cc:2153
bool isValid() const
Definition: RootTree.cc:109
~OldProvenanceReader() override
Definition: RootFile.cc:2051
std::shared_ptr< ProductProvenanceRetriever > makeProductProvenanceRetriever(unsigned int iStreamIndex)
Definition: RootFile.cc:1830
std::vector< StoredProductProvenance > StoredProductProvenanceVector
std::string const & file() const
Definition: RootFile.h:209
std::string const & productDescriptionBranchName()
Definition: BranchType.cc:174
std::string const & processConfigurationBranchName()
Definition: BranchType.cc:204
IndexIntoFile::IndexIntoFileItr indexIntoFileBegin_
Definition: RootFile.h:319
ProcessHistoryID const & processHistoryID() const
EventID const & id() const
edm::propagate_const< RunHelperBase * > runHelper_
Definition: RootFile.h:343
bool branchListIndexesUnchanged_
Definition: RootFile.h:330
void fillEventPrincipal(EventAuxiliary const &aux, ProcessHistoryRegistry const &processHistoryRegistry, DelayedReader *reader=0)
void fillIndexIntoFile()
Definition: RootFile.cc:910
#define begin
Definition: vmac.h:32
HLT enums.
edm::propagate_const< TTree * > eventHistoryTree_
Definition: RootFile.h:345
void readLuminosityBlock_(LuminosityBlockPrincipal &lumiPrincipal)
Definition: RootFile.cc:1595
std::vector< EventEntryInfo > * pInfoVector_
Definition: RootFile.cc:2062
std::unique_ptr< ProvenanceReaderBase > makeReader(RootTree &eventTree, DaqProvenanceHelper const *daqProvenanceHelper) const override
Definition: RootFile.cc:2158
unsigned int const defaultNonEventCacheSize
Definition: RootTree.h:47
RootTreePtrArray treePointers_
Definition: RootFile.h:335
void fillEventNumbers() const
double a
Definition: hdecay.h:121
void initialize(ProductSelectorRules const &rules, std::vector< BranchDescription const * > const &branchDescriptions)
static int position[264][3]
Definition: ReadPGInfo.cc:509
bool perEventProductIDs() const
std::string const & BranchTypeToProductProvenanceBranchName(BranchType const &BranchType)
Definition: BranchType.cc:132
std::vector< ProcessHistoryID > & orderedProcessHistoryIDs_
Definition: RootFile.h:318
std::string const & productDependenciesBranchName()
Definition: BranchType.cc:179
void setNumberOfEvents(EntryNumber_t nevents) const
void initAssociationsFromSecondary(std::vector< BranchID > const &)
Definition: RootFile.cc:738
std::string const & thinnedAssociationsHelperBranchName()
Definition: BranchType.cc:214
std::string const & entryDescriptionIDBranchName()
Definition: BranchType.cc:151
~DummyProvenanceReader() override
Definition: RootFile.cc:2119
bool useReducedProcessHistoryID() const
edm::propagate_const< TBranch * > provBranch_
Definition: RootFile.cc:1858
std::unique_ptr< MakeProvenanceReader > makeProvenanceReaderMaker(InputType inputType)
Definition: RootFile.cc:1814
std::unique_ptr< WrapperBase > getWrapperBasePtr(void *p, int offset)
std::string const & branchIDListBranchName()
Definition: BranchType.cc:209
BranchID const & originalBranchID() const
unsigned int RunNumber_t
std::string const & branchListIndexesBranchName()
Definition: BranchType.cc:253
std::vector< ParentageID > parentageIDLookup_
Definition: RootFile.h:354
EventAuxiliary eventAux_
Definition: RootFile.h:331
void readProvenanceAsync(WaitingTask *task, ModuleCallingContext const *moduleCallingContext, unsigned int transitionIndex, std::atomic< const std::set< ProductProvenance > * > &writeTo) const override
Definition: RootFile.cc:2012
void fillThisEventAuxiliary()
Definition: RootFile.cc:1199
void resetTraining()
Definition: RootTree.h:192
bool setEntryAtEvent(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event)
Definition: RootFile.cc:1613
std::vector< ParentageID > const & parentageIDLookup_
Definition: RootFile.cc:98
ReducedProvenanceReader(RootTree *iRootTree, std::vector< ParentageID > const &iParentageIDLookup, DaqProvenanceHelper const *daqProvenanceHelper)
Definition: RootFile.cc:1867
std::string const & eventHistoryTreeName()
Definition: BranchType.cc:274
static Interceptor::Registry registry("Interceptor")
RootFileEventFinder(RootTree &eventTree)
Definition: RootFile.cc:121
ParentageID const & mapParentageID(ParentageID const &phid) const
edm::propagate_const< std::shared_ptr< BranchIDListHelper > > branchIDListHelper_
Definition: RootFile.h:339
void validateFile(InputType inputType, bool usingGoToEvent)
Definition: RootFile.cc:1134
IndexIntoFile::IndexIntoFileItr indexIntoFileIter() const
Definition: RootFile.cc:732
std::string const & newBranchToOldBranch(std::string const &newBranch) const
Definition: RootFile.cc:724
void readRun(long long inputRunEntry, StoredMergeableRunProductMetadata const &inputStoredMergeableRunProductMetadata, IndexIntoFileItrHolder const &inputIndexIntoFileItr)
T first(std::pair< T, U > const &p)
std::unique_ptr< TTreeCache > trainCache(TTree *tree, InputFile &file, unsigned int cacheSize, char const *branchNames)
Definition: RootTree.cc:515
static ParentageRegistry * instance()
OldProvenanceReader(RootTree *rootTree, EntryDescriptionMap const &theMap, DaqProvenanceHelper const *daqProvenanceHelper)
Definition: RootFile.cc:2069
SharedResourcesAcquirer acquirer_
Definition: RootFile.cc:1864
IndexIntoFileItr findEventPosition(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const
unsigned int const defaultLearningEntries
Definition: RootTree.h:48
std::vector< EventEntryInfo > infoVector_
Definition: RootFile.cc:2061
void markBranchToBeDropped(bool dropDescendants, BranchDescription const &branch, std::set< BranchID > &branchesToDrop, std::map< BranchID, BranchID > const &droppedToKeptAlias) const
Definition: RootFile.cc:1676
LuminosityBlockNumber_t peekAheadAtLumi() const
bool hasThinnedAssociations() const
std::string const & fileIdentifierBranchName()
Definition: BranchType.cc:224
void setIsMergeable(BranchDescription &)
EventNumber_t event() const
std::string const & moduleDescriptionMapBranchName()
Definition: BranchType.cc:189
bool insertMapped(value_type const &v)
std::string const file_
Definition: RootFile.h:308
def move(src, dest)
Definition: eostools.py:511
void skipEventForward(int &phIndexOfSkippedEvent, RunNumber_t &runOfSkippedEvent, LuminosityBlockNumber_t &lumiOfSkippedEvent, EntryNumber_t &skippedEventEntry)
std::vector< EventProcessHistoryID > eventProcessHistoryIDs_
Definition: RootFile.h:323
static Registry * instance()
Definition: Registry.cc:12
std::set< ProductProvenance > readProvenance(unsigned int transitionIndex) const override
Definition: RootFile.cc:2095
DaqProvenanceHelper const * daqProvenanceHelper_
Definition: RootFile.cc:2064
std::string createGlobalIdentifier()
Definition: event.py:1
TypeWithDict const & wrappedType() const
void copyProduct(BranchDescription const &productdesc)
void readEventHistoryTree()
Definition: RootFile.cc:1652
void fillAux(T *&pAux)
Definition: RootTree.h:142
std::set< ProductProvenance > readProvenance(unsigned int) const override
Definition: RootFile.cc:2131
void setEntryNumber(EntryNumber theEntryNumber)
Definition: RootTree.cc:201
void reportOpened(std::string const &inputType)
Definition: RootFile.cc:1181
def operate(timelog, memlog, json_f, num)
roottree::EntryNumber EntryNumber
Definition: RootTree.h:104