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