CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RootFile.cc
Go to the documentation of this file.
1 /*----------------------------------------------------------------------
2 ----------------------------------------------------------------------*/
3 
4 #include "RootFile.h"
5 #include "DuplicateChecker.h"
6 #include "InputFile.h"
7 #include "ProvenanceAdaptor.h"
8 
42 
43 //used for backward compatibility
50 
51 #include "TROOT.h"
52 #include "Rtypes.h"
53 #include "TClass.h"
54 #include "TString.h"
55 #include "TTree.h"
56 #include "TTreeCache.h"
57 
58 #include <algorithm>
59 #include <list>
60 
61 namespace edm {
62 
63  // Algorithm classes for making ProvenanceReader:
65  public:
66  virtual std::unique_ptr<ProvenanceReaderBase> makeReader(RootTree& eventTree, DaqProvenanceHelper const* daqProvenanceHelper) const;
67  };
69  public:
70  virtual std::unique_ptr<ProvenanceReaderBase> makeReader(RootTree& eventTree, DaqProvenanceHelper const* daqProvenanceHelper) const;
71  };
73  public:
74  virtual std::unique_ptr<ProvenanceReaderBase> makeReader(RootTree& eventTree, DaqProvenanceHelper const* daqProvenanceHelper) const;
75  };
77  public:
78  MakeReducedProvenanceReader(std::vector<ParentageID> const& parentageIDLookup) : parentageIDLookup_(parentageIDLookup) {}
79  virtual std::unique_ptr<ProvenanceReaderBase> makeReader(RootTree& eventTree, DaqProvenanceHelper const* daqProvenanceHelper) const;
80  private:
81  std::vector<ParentageID> const& parentageIDLookup_;
82  };
83 
84  namespace {
85  int
86  forcedRunOffset(RunNumber_t const& forcedRunNumber, IndexIntoFile::IndexIntoFileItr inxBegin, IndexIntoFile::IndexIntoFileItr inxEnd) {
87  if(inxBegin == inxEnd) return 0;
88  int defaultOffset = (inxBegin.run() != 0 ? 0 : 1);
89  int offset = (forcedRunNumber != 0U ? forcedRunNumber - inxBegin.run() : defaultOffset);
90  if(offset < 0) {
92  << "The value of the 'setRunNumber' parameter must not be\n"
93  << "less than the first run number in the first input file.\n"
94  << "'setRunNumber' was " << forcedRunNumber <<", while the first run was "
95  << forcedRunNumber - offset << ".\n";
96  }
97  return offset;
98  }
99  }
100 
101  // This is a helper class for IndexIntoFile.
103  public:
104  explicit RootFileEventFinder(RootTree& eventTree) : eventTree_(eventTree) {}
105  virtual ~RootFileEventFinder() {}
106  virtual
109  eventTree_.setEntryNumber(entry);
110  EventAuxiliary eventAux;
111  EventAuxiliary *pEvAux = &eventAux;
113  eventTree_.setEntryNumber(saveEntry);
114  return eventAux.event();
115  }
116 
117  private:
119  };
120 
121 //---------------------------------------------------------------------
122  RootFile::RootFile(std::string const& fileName,
123  ProcessConfiguration const& processConfiguration,
124  std::string const& logicalFileName,
125  boost::shared_ptr<InputFile> filePtr,
126  boost::shared_ptr<EventSkipperByID> eventSkipperByID,
127  bool skipAnyEvents,
128  int remainingEvents,
129  int remainingLumis,
130  unsigned int treeCacheSize,
131  int treeMaxVirtualSize,
133  RunNumber_t const& forcedRunNumber,
134  bool noEventSort,
135  GroupSelectorRules const& groupSelectorRules,
136  InputType::InputType inputType,
137  boost::shared_ptr<DuplicateChecker> duplicateChecker,
138  bool dropDescendants,
139  std::vector<boost::shared_ptr<IndexIntoFile> > const& indexesIntoFiles,
140  std::vector<boost::shared_ptr<IndexIntoFile> >::size_type currentIndexIntoFile,
141  std::vector<ProcessHistoryID>& orderedProcessHistoryIDs,
142  bool bypassVersionCheck,
143  bool labelRawDataLikeMC,
144  bool usingGoToEvent) :
145  file_(fileName),
146  logicalFile_(logicalFileName),
147  processConfiguration_(processConfiguration),
148  processConfigurations_(),
149  filePtr_(filePtr),
150  eventSkipperByID_(eventSkipperByID),
151  fileFormatVersion_(),
152  fid_(),
153  indexIntoFileSharedPtr_(new IndexIntoFile),
154  indexIntoFile_(*indexIntoFileSharedPtr_),
155  orderedProcessHistoryIDs_(orderedProcessHistoryIDs),
156  indexIntoFileBegin_(indexIntoFile_.begin(noEventSort ? IndexIntoFile::firstAppearanceOrder : IndexIntoFile::numericalOrder)),
157  indexIntoFileEnd_(indexIntoFileBegin_),
158  indexIntoFileIter_(indexIntoFileBegin_),
159  eventProcessHistoryIDs_(),
160  eventProcessHistoryIter_(eventProcessHistoryIDs_.begin()),
161  savedRunAuxiliary_(),
162  skipAnyEvents_(skipAnyEvents),
163  noEventSort_(noEventSort),
164  whyNotFastClonable_(0),
165  hasNewlyDroppedBranch_(),
166  branchListIndexesUnchanged_(false),
167  eventAux_(),
168  eventTree_(filePtr_, InEvent, treeMaxVirtualSize, treeCacheSize, roottree::defaultLearningEntries),
169  lumiTree_(filePtr_, InLumi, treeMaxVirtualSize, roottree::defaultNonEventCacheSize, roottree::defaultNonEventLearningEntries),
170  runTree_(filePtr_, InRun, treeMaxVirtualSize, roottree::defaultNonEventCacheSize, roottree::defaultNonEventLearningEntries),
171  treePointers_(),
172  lastEventEntryNumberRead_(-1LL),
173  productRegistry_(),
174  branchIDLists_(),
175  processingMode_(processingMode),
176  forcedRunOffset_(0),
177  newBranchToOldBranch_(),
178  eventHistoryTree_(0),
179  eventSelectionIDs_(new EventSelectionIDVector),
180  branchListIndexes_(new BranchListIndexes),
181  history_(),
182  branchChildren_(new BranchChildren),
183  duplicateChecker_(duplicateChecker),
184  provenanceAdaptor_(),
185  provenanceReaderMaker_(),
186  secondaryEventPrincipal_(),
187  eventBranchMapper_(),
188  parentageIDLookup_(),
189  daqProvenanceHelper_() {
190 
191  hasNewlyDroppedBranch_.fill(false);
192 
196 
197  // Read the metadata tree.
198  // We use a smart pointer so the tree will be deleted after use, and not kept for the life of the file.
199  std::unique_ptr<TTree> metaDataTree(dynamic_cast<TTree *>(filePtr_->Get(poolNames::metaDataTreeName().c_str())));
200  if(0 == metaDataTree.get()) {
201  throw Exception(errors::FileReadError) << "Could not find tree " << poolNames::metaDataTreeName()
202  << " in the input file.\n";
203  }
204 
205  // To keep things simple, we just read in every possible branch that exists.
206  // We don't pay attention to which branches exist in which file format versions
207 
209  if(metaDataTree->FindBranch(poolNames::fileFormatVersionBranchName().c_str()) != 0) {
210  TBranch *fft = metaDataTree->GetBranch(poolNames::fileFormatVersionBranchName().c_str());
211  fft->SetAddress(&fftPtr);
212  roottree::getEntry(fft, 0);
213  metaDataTree->SetBranchAddress(poolNames::fileFormatVersionBranchName().c_str(), &fftPtr);
214  }
215 
216  FileID *fidPtr = &fid_;
217  if(metaDataTree->FindBranch(poolNames::fileIdentifierBranchName().c_str()) != 0) {
218  metaDataTree->SetBranchAddress(poolNames::fileIdentifierBranchName().c_str(), &fidPtr);
219  }
220 
221  IndexIntoFile *iifPtr = &indexIntoFile_;
222  if(metaDataTree->FindBranch(poolNames::indexIntoFileBranchName().c_str()) != 0) {
223  metaDataTree->SetBranchAddress(poolNames::indexIntoFileBranchName().c_str(), &iifPtr);
224  }
225 
226  // Need to read to a temporary registry so we can do a translation of the BranchKeys.
227  // This preserves backward compatibility against friendly class name algorithm changes.
228  ProductRegistry inputProdDescReg;
229  ProductRegistry *ppReg = &inputProdDescReg;
230  metaDataTree->SetBranchAddress(poolNames::productDescriptionBranchName().c_str(), (&ppReg));
231 
232  typedef std::map<ParameterSetID, ParameterSetBlob> PsetMap;
233  PsetMap psetMap;
234  PsetMap *psetMapPtr = &psetMap;
235  if(metaDataTree->FindBranch(poolNames::parameterSetMapBranchName().c_str()) != 0) {
236  //backward compatibility
237  assert(!fileFormatVersion().parameterSetsTree());
238  metaDataTree->SetBranchAddress(poolNames::parameterSetMapBranchName().c_str(), &psetMapPtr);
239  } else {
240  assert(fileFormatVersion().parameterSetsTree());
241  // We use a smart pointer so the tree will be deleted after use, and not kept for the life of the file.
242  std::unique_ptr<TTree> psetTree(dynamic_cast<TTree *>(filePtr_->Get(poolNames::parameterSetsTreeName().c_str())));
243  if(0 == psetTree.get()) {
244  throw Exception(errors::FileReadError) << "Could not find tree " << poolNames::parameterSetsTreeName()
245  << " in the input file.\n";
246  }
247 
248  typedef std::pair<ParameterSetID, ParameterSetBlob> IdToBlobs;
249  IdToBlobs idToBlob;
250  IdToBlobs* pIdToBlob = &idToBlob;
251  psetTree->SetBranchAddress(poolNames::idToParameterSetBlobsBranchName().c_str(), &pIdToBlob);
252 
253  std::unique_ptr<TTreeCache> psetTreeCache = roottree::trainCache(psetTree.get(), *filePtr_, roottree::defaultNonEventCacheSize, "*");
254  filePtr_->SetCacheRead(psetTreeCache.get());
255  for(Long64_t i = 0; i != psetTree->GetEntries(); ++i) {
256  psetTree->GetEntry(i);
257  psetMap.insert(idToBlob);
258  }
259  filePtr_->SetCacheRead(0);
260  }
261 
262  // backward compatibility
264  ProcessHistoryRegistry::collection_type *pHistMapPtr = &pHistMap;
265  if(metaDataTree->FindBranch(poolNames::processHistoryMapBranchName().c_str()) != 0) {
266  metaDataTree->SetBranchAddress(poolNames::processHistoryMapBranchName().c_str(), &pHistMapPtr);
267  }
268 
270  ProcessHistoryRegistry::vector_type *pHistVectorPtr = &pHistVector;
271  if(metaDataTree->FindBranch(poolNames::processHistoryBranchName().c_str()) != 0) {
272  metaDataTree->SetBranchAddress(poolNames::processHistoryBranchName().c_str(), &pHistVectorPtr);
273  }
274 
275  ProcessConfigurationVector* procConfigVectorPtr = &processConfigurations_;
276  if(metaDataTree->FindBranch(poolNames::processConfigurationBranchName().c_str()) != 0) {
277  metaDataTree->SetBranchAddress(poolNames::processConfigurationBranchName().c_str(), &procConfigVectorPtr);
278  }
279 
280  std::unique_ptr<BranchIDListRegistry::collection_type> branchIDListsAPtr(new BranchIDListRegistry::collection_type);
281  BranchIDListRegistry::collection_type *branchIDListsPtr = branchIDListsAPtr.get();
282  if(metaDataTree->FindBranch(poolNames::branchIDListBranchName().c_str()) != 0) {
283  metaDataTree->SetBranchAddress(poolNames::branchIDListBranchName().c_str(), &branchIDListsPtr);
284  }
285 
286  BranchChildren* branchChildrenBuffer = branchChildren_.get();
287  if(metaDataTree->FindBranch(poolNames::productDependenciesBranchName().c_str()) != 0) {
288  metaDataTree->SetBranchAddress(poolNames::productDependenciesBranchName().c_str(), &branchChildrenBuffer);
289  }
290 
291  // backward compatibility
292  std::vector<EventProcessHistoryID> *eventHistoryIDsPtr = &eventProcessHistoryIDs_;
293  if(metaDataTree->FindBranch(poolNames::eventHistoryBranchName().c_str()) != 0) {
294  metaDataTree->SetBranchAddress(poolNames::eventHistoryBranchName().c_str(), &eventHistoryIDsPtr);
295  }
296 
297  if(metaDataTree->FindBranch(poolNames::moduleDescriptionMapBranchName().c_str()) != 0) {
298  if(metaDataTree->GetBranch(poolNames::moduleDescriptionMapBranchName().c_str())->GetSplitLevel() != 0) {
299  metaDataTree->SetBranchStatus((poolNames::moduleDescriptionMapBranchName() + ".*").c_str(), 0);
300  } else {
301  metaDataTree->SetBranchStatus(poolNames::moduleDescriptionMapBranchName().c_str(), 0);
302  }
303  }
304 
305  // Here we read the metadata tree
306  roottree::getEntry(metaDataTree.get(), 0);
307 
308  if(!bypassVersionCheck) {
310  }
311 
313 
314  // Here we read the event history tree, if we have one.
316 
318  if(!fileFormatVersion().triggerPathsTracked()) {
319  ParameterSetConverter converter(psetMap, psetIdConverter, fileFormatVersion().parameterSetsByReference());
320  } else {
321  // Merge into the parameter set registry.
322  pset::Registry& psetRegistry = *pset::Registry::instance();
323  for(PsetMap::const_iterator i = psetMap.begin(), iEnd = psetMap.end(); i != iEnd; ++i) {
324  ParameterSet pset(i->second.pset());
325  pset.setID(i->first);
326  psetRegistry.insertMapped(pset);
327  }
328  }
329  if(!fileFormatVersion().splitProductIDs()) {
330  // Old provenance format input file. Create a provenance adaptor.
332  inputProdDescReg, pHistMap, pHistVector, processConfigurations_, psetIdConverter, true));
333  // Fill in the branchIDLists branch from the provenance adaptor
334  branchIDLists_ = provenanceAdaptor_->branchIDLists();
335  } else {
336  if(!fileFormatVersion().triggerPathsTracked()) {
337  // New provenance format, but change in ParameterSet Format. Create a provenance adaptor.
339  inputProdDescReg, pHistMap, pHistVector, processConfigurations_, psetIdConverter, false));
340  }
341  // New provenance format input file. The branchIDLists branch was read directly from the input file.
342  if(metaDataTree->FindBranch(poolNames::branchIDListBranchName().c_str()) == 0) {
344  << "Failed to find branchIDLists branch in metaData tree.\n";
345  }
346  branchIDLists_.reset(branchIDListsAPtr.release());
347  }
348 
349  if(labelRawDataLikeMC) {
350  std::string const rawData("FEDRawDataCollection");
351  std::string const source("source");
352  ProductRegistry::ProductList& pList = inputProdDescReg.productListUpdator();
353  BranchKey finder(rawData, source, "", "");
354  ProductRegistry::ProductList::iterator it = pList.lower_bound(finder);
355  if(it != pList.end() && it->first.friendlyClassName_ == rawData && it->first.moduleLabel_ == source) {
356  // We found raw data with a module label of source.
357  // We need to change the module label and process name.
358  // Create helper.
359  it->second.init();
360  daqProvenanceHelper_.reset(new DaqProvenanceHelper(it->second.typeID()));
361  // Create the new branch description
362  BranchDescription const& newBD = daqProvenanceHelper_->constBranchDescription_.me();
363  // Save info from the old and new branch descriptions
364  daqProvenanceHelper_->saveInfo(it->second, newBD);
365  // Map the new branch name to the old branch name.
366  it->second.init();
367  newBranchToOldBranch_.insert(std::make_pair(newBD.branchName(), it->second.branchName()));
368  // Remove the old branch description from the product Registry.
369  pList.erase(it);
370  // Check that there was only one.
371  it = pList.lower_bound(finder);
372  assert(!(it != pList.end() && it->first.friendlyClassName_ == rawData && it->first.moduleLabel_ == source));
373  // Insert the new branch description into the product registry.
374  inputProdDescReg.copyProduct(newBD);
375  // Fix up other per file metadata.
377  daqProvenanceHelper_->fixMetaData(pHistVector);
378  daqProvenanceHelper_->fixMetaData(*branchIDLists_);
379  daqProvenanceHelper_->fixMetaData(*branchChildren_);
380  }
381  }
382 
385 
387 
388  validateFile(inputType, usingGoToEvent);
389 
390  // Read the parentage tree. Old format files are handled internally in readParentageTree().
392 
393  // Merge into the hashed registries.
394  if(eventSkipperByID_ && eventSkipperByID_->somethingToSkip()) {
396  }
397 
398  initializeDuplicateChecker(indexesIntoFiles, currentIndexIntoFile);
400  indexIntoFileEnd_ = indexIntoFile_.end(noEventSort ? IndexIntoFile::firstAppearanceOrder : IndexIntoFile::numericalOrder);
401  forcedRunOffset_ = forcedRunOffset(forcedRunNumber, indexIntoFileBegin_, indexIntoFileEnd_);
403 
404  // Set product presence information in the product registry.
405  ProductRegistry::ProductList const& pList = inputProdDescReg.productList();
406  for(ProductRegistry::ProductList::const_iterator it = pList.begin(), itEnd = pList.end();
407  it != itEnd; ++it) {
408  BranchDescription const& prod = it->second;
409  prod.init();
410  treePointers_[prod.branchType()]->setPresence(prod, newBranchToOldBranch(prod.branchName()));
411  }
412 
414 
415  std::unique_ptr<ProductRegistry> newReg(new ProductRegistry);
416 
417  // Do the translation from the old registry to the new one
418  {
419  ProductRegistry::ProductList const& prodList = inputProdDescReg.productList();
420  for(ProductRegistry::ProductList::const_iterator it = prodList.begin(), itEnd = prodList.end();
421  it != itEnd; ++it) {
422  BranchDescription const& prod = it->second;
423  std::string newFriendlyName = friendlyname::friendlyName(prod.className());
424  if(newFriendlyName == prod.friendlyClassName()) {
425  newReg->copyProduct(prod);
426  } else {
427  if(fileFormatVersion().splitProductIDs()) {
429  << "Cannot change friendly class name algorithm without more development work\n"
430  << "to update BranchIDLists. Contact the framework group.\n";
431  }
432  BranchDescription newBD(prod);
433  newBD.updateFriendlyClassName();
434  newReg->copyProduct(newBD);
435  newBranchToOldBranch_.insert(std::make_pair(newBD.branchName(), prod.branchName()));
436  }
437  }
438  dropOnInput(*newReg, groupSelectorRules, dropDescendants, inputType);
439  // freeze the product registry
440  newReg->setFrozen(inputType != InputType::Primary);
441  productRegistry_.reset(newReg.release());
442  }
443 
444  // Here, we make the class that will make the ProvenanceReader
446 
447  // Set up information from the product registry.
448  ProductRegistry::ProductList const& prodList = productRegistry()->productList();
449  for(ProductRegistry::ProductList::const_iterator it = prodList.begin(), itEnd = prodList.end();
450  it != itEnd; ++it) {
451  BranchDescription const& prod = it->second;
452  treePointers_[prod.branchType()]->addBranch(it->first, prod,
454  }
455 
456  // Event Principal cache for secondary input source
457  if(inputType == InputType::SecondarySource) {
458  secondaryEventPrincipal_.reset(new EventPrincipal(productRegistry(), processConfiguration));
459  }
460 
461  // Determine if this file is fast clonable.
462  setIfFastClonable(remainingEvents, remainingLumis);
463 
464  // Update the branch id info.
465  if(inputType == InputType::Primary) {
467  }
468 
469  setRefCoreStreamer(true); // backward compatibility
470 
471  // We are done with our initial reading of EventAuxiliary.
473 
474  // Tell the event tree to begin training at the next read.
476 
477  // Train the run and lumi trees.
478  runTree_.trainCache("*");
479  lumiTree_.trainCache("*");
480  }
481 
483  }
484 
485  void
487  // Called only for old format files.
488  if(!fileFormatVersion().perEventProductIDs()) return;
489  // We use a smart pointer so the tree will be deleted after use, and not kept for the life of the file.
490  std::unique_ptr<TTree> entryDescriptionTree(dynamic_cast<TTree*>(filePtr_->Get(poolNames::entryDescriptionTreeName().c_str())));
491  if(0 == entryDescriptionTree.get()) {
492  throw Exception(errors::FileReadError) << "Could not find tree " << poolNames::entryDescriptionTreeName()
493  << " in the input file.\n";
494  }
495 
496  EntryDescriptionID idBuffer;
497  EntryDescriptionID* pidBuffer = &idBuffer;
498  entryDescriptionTree->SetBranchAddress(poolNames::entryDescriptionIDBranchName().c_str(), &pidBuffer);
499 
501 
502  EventEntryDescription entryDescriptionBuffer;
503  EventEntryDescription *pEntryDescriptionBuffer = &entryDescriptionBuffer;
504  entryDescriptionTree->SetBranchAddress(poolNames::entryDescriptionBranchName().c_str(), &pEntryDescriptionBuffer);
505 
506  // Fill in the parentage registry.
508 
509  for(Long64_t i = 0, numEntries = entryDescriptionTree->GetEntries(); i < numEntries; ++i) {
510  roottree::getEntry(entryDescriptionTree.get(), i);
511  if(idBuffer != entryDescriptionBuffer.id()) {
512  throw Exception(errors::EventCorruption) << "Corruption of EntryDescription tree detected.\n";
513  }
514  oldregistry.insertMapped(entryDescriptionBuffer);
516  parents.parents() = entryDescriptionBuffer.parents();
518  ParentageID const oldID = parents.id();
519  daqProvenanceHelper_->fixMetaData(parents.parents());
520  ParentageID newID = parents.id();
521  if(newID != oldID) {
522  daqProvenanceHelper_->parentageIDMap_.insert(std::make_pair(oldID, newID));
523  }
524  }
525  registry.insertMapped(parents);
526  }
527  entryDescriptionTree->SetBranchAddress(poolNames::entryDescriptionIDBranchName().c_str(), 0);
528  entryDescriptionTree->SetBranchAddress(poolNames::entryDescriptionBranchName().c_str(), 0);
529  }
530 
531  void
533  if(!fileFormatVersion().splitProductIDs()) {
534  // Old format file.
536  return;
537  }
538  // New format file
539  // We use a smart pointer so the tree will be deleted after use, and not kept for the life of the file.
540  std::unique_ptr<TTree> parentageTree(dynamic_cast<TTree*>(filePtr_->Get(poolNames::parentageTreeName().c_str())));
541  if(0 == parentageTree.get()) {
542  throw Exception(errors::FileReadError) << "Could not find tree " << poolNames::parentageTreeName()
543  << " in the input file.\n";
544  }
545 
547  Parentage *pParentageBuffer = &parents;
548  parentageTree->SetBranchAddress(poolNames::parentageBranchName().c_str(), &pParentageBuffer);
549 
551 
552  parentageIDLookup_.reserve(parentageTree->GetEntries());
553  for(Long64_t i = 0, numEntries = parentageTree->GetEntries(); i < numEntries; ++i) {
554  roottree::getEntry(parentageTree.get(), i);
556  ParentageID const oldID = parents.id();
557  daqProvenanceHelper_->fixMetaData(parents.parents());
558  ParentageID newID = parents.id();
559  if(newID != oldID) {
560  daqProvenanceHelper_->parentageIDMap_.insert(std::make_pair(oldID, newID));
561  }
562  }
563  registry.insertMapped(parents);
564  parentageIDLookup_.push_back(parents.id());
565  }
566  parentageTree->SetBranchAddress(poolNames::parentageBranchName().c_str(), 0);
567  }
568 
569  void
570  RootFile::setIfFastClonable(int remainingEvents, int remainingLumis) {
571  if(fileFormatVersion().noMetaDataTrees() and !fileFormatVersion().storedProductProvenanceUsed()) {
572  //we must avoid copying the old branch which stored the per product per event provenance
574  return;
575  }
576  if(!fileFormatVersion().splitProductIDs()) {
578  return;
579  }
582  return;
583  }
584  // Find entry for first event in file
586  while(it != indexIntoFileEnd_ && it.getEntryType() != IndexIntoFile::kEvent) {
587  ++it;
588  }
589  if(it == indexIntoFileEnd_) {
591  return;
592  }
593 
594  // From here on, record all reasons we can't fast clone.
598  }
599  if(skipAnyEvents_) {
601  }
602  if(remainingEvents >= 0 && eventTree_.entries() > remainingEvents) {
604  }
605  if(remainingLumis >= 0 && lumiTree_.entries() > remainingLumis) {
607  }
608  // We no longer fast copy the EventAuxiliary branch, so there
609  // is no longer any need to disable fast copying because the run
610  // number is being modified. Also, this check did not work anyway
611  // because this function is called before forcedRunOffset_ is set.
612 
613  // if(forcedRunOffset_ != 0) {
614  // whyNotFastClonable_ += FileBlock::RunNumberModified;
615  // }
616  if(duplicateChecker_ &&
617  !duplicateChecker_->checkDisabled() &&
618  !duplicateChecker_->noDuplicatesInFile()) {
620  }
621  }
622 
623  boost::shared_ptr<FileBlock>
625  return boost::shared_ptr<FileBlock>(new FileBlock(fileFormatVersion(),
626  eventTree_.tree(),
628  lumiTree_.tree(),
630  runTree_.tree(),
631  runTree_.metaTree(),
634  file_,
636  modifiedIDs(),
637  branchChildren_));
638  }
639 
640  std::string const&
641  RootFile::newBranchToOldBranch(std::string const& newBranch) const {
642  std::map<std::string, std::string>::const_iterator it = newBranchToOldBranch_.find(newBranch);
643  if(it != newBranchToOldBranch_.end()) {
644  return it->second;
645  }
646  return newBranch;
647  }
648 
651  return indexIntoFileIter_;
652  }
653 
654  void
657  }
658 
659  bool
662  return false;
663  }
664  if(eventSkipperByID_ && eventSkipperByID_->somethingToSkip()) {
665 
666  // See first if the entire lumi or run is skipped, so we won't have to read the event Auxiliary in that case.
668  return true;
669  }
670 
671  // The Lumi is not skipped. If this is an event, see if the event is skipped.
676  eventAux_.id().event())) {
677  return true;
678  }
679  }
680 
681  // Skip runs with no lumis if either lumisToSkip or lumisToProcess have been set to select lumis
683  eventSkipperByID_->skippingLumis()) {
685 
686  // There are no lumis in this run, not even ones we will skip
687  if(iterLumi.peekAheadAtLumi() == IndexIntoFile::invalidLumi) {
688  return true;
689  }
690  // If we get here there are lumis in the run, check to see if we are skipping all of them
691  do {
692  if(!eventSkipperByID_->skipIt(iterLumi.run(), iterLumi.peekAheadAtLumi(), 0U)) {
693  return false;
694  }
695  }
696  while(iterLumi.skipLumiInRun());
697  return true;
698  }
699  }
700  return false;
701  }
702 
705  while(skipThisEntry()) {
708  }
711  }
712  else {
714  }
715  }
717  }
718 
719  bool
722  if(duplicateChecker_.get() == 0) {
723  return false;
724  }
726  return duplicateChecker_->isDuplicateAndCheckActive(indexIntoFileIter_.processHistoryIDIndex(),
728  }
729 
733  if(entryType == IndexIntoFile::kEnd) {
734  return IndexIntoFile::kEnd;
735  }
736  if(entryType == IndexIntoFile::kRun) {
737  return IndexIntoFile::kRun;
738  } else if(processingMode_ == InputSource::Runs) {
740  return getNextEntryTypeWanted();
741  }
742  if(entryType == IndexIntoFile::kLumi) {
743  return IndexIntoFile::kLumi;
746  return getNextEntryTypeWanted();
747  }
748  if(isDuplicateEvent()) {
750  return getNextEntryTypeWanted();
751  }
752  return IndexIntoFile::kEvent;
753  }
754 
755  bool
758  itr.advanceToEvent();
759  return itr.getEntryType() == IndexIntoFile::kEnd;
760  }
761 
762  bool
765  int phIndex;
768  IndexIntoFile::EntryNumber_t eventEntry;
769  itr.skipEventBackward(phIndex,
770  run,
771  lumi,
772  eventEntry);
773  itr.skipEventBackward(phIndex,
774  run,
775  lumi,
776  eventEntry);
777  return eventEntry == IndexIntoFile::invalidEntry;
778  }
779 
780  namespace {
781  typedef IndexIntoFile::EntryNumber_t EntryNumber_t;
782  struct RunItem {
783  RunItem(ProcessHistoryID const& phid, RunNumber_t const& run) :
784  phid_(phid), run_(run) {}
785  ProcessHistoryID phid_;
786  RunNumber_t run_;
787  };
788  struct RunItemSortByRun {
789  bool operator()(RunItem const& a, RunItem const& b) const {
790  return a.run_ < b.run_;
791  }
792  };
793  struct RunItemSortByRunPhid {
794  bool operator()(RunItem const& a, RunItem const& b) const {
795  return a.run_ < b.run_ || (!(b.run_ < a.run_) && a.phid_ < b.phid_);
796  }
797  };
798  struct LumiItem {
799  LumiItem(ProcessHistoryID const& phid, RunNumber_t const& run,
800  LuminosityBlockNumber_t const& lumi, EntryNumber_t const& entry) :
801  phid_(phid), run_(run), lumi_(lumi), firstEventEntry_(entry),
802  lastEventEntry_(entry == -1LL ? -1LL : entry + 1) {}
803  ProcessHistoryID phid_;
804  RunNumber_t run_;
806  EntryNumber_t firstEventEntry_;
807  EntryNumber_t lastEventEntry_;
808  };
809  struct LumiItemSortByRunLumi {
810  bool operator()(LumiItem const& a, LumiItem const& b) const {
811  return a.run_ < b.run_ || (!(b.run_ < a.run_) && a.lumi_ < b.lumi_);
812  }
813  };
814  struct LumiItemSortByRunLumiPhid {
815  bool operator()(LumiItem const& a, LumiItem const& b) const {
816  if(a.run_ < b.run_) return true;
817  if(b.run_ < a.run_) return false;
818  if(a.lumi_ < b.lumi_) return true;
819  if(b.lumi_ < a.lumi_) return false;
820  return a.phid_ < b.phid_;
821  }
822  };
823  }
824 
825  void
827  // This function is for backward compatibility.
828  // If reading a current format file, indexIntoFile_ is read from the input
829  // file and should always be there. Note that the algorithm below will work
830  // sometimes but often fail with the new format introduced in release 3_8_0.
831  // If it ever becomes necessary to rebuild IndexIntoFile from the new format,
832  // probably a separate function should be written to deal with the task.
833  // This is possible just not implemented yet.
834  assert(!fileFormatVersion().hasIndexIntoFile());
835 
836  typedef std::list<LumiItem> LumiList;
837  LumiList lumis; // (declare 1)
838 
839  typedef std::set<LuminosityBlockID> RunLumiSet;
840  RunLumiSet runLumiSet; // (declare 2)
841 
842  typedef std::list<RunItem> RunList;
843  RunList runs; // (declare 5)
844 
845  typedef std::set<RunNumber_t> RunSet;
846  RunSet runSet; // (declare 4)
847 
848  typedef std::set<RunItem, RunItemSortByRunPhid> RunItemSet;
849  RunItemSet runItemSet; // (declare 3)
850 
851  typedef std::map<RunNumber_t, ProcessHistoryID> PHIDMap;
852  PHIDMap phidMap;
853 
854  RunNumber_t prevRun = 0;
855  LuminosityBlockNumber_t prevLumi = 0;
856  ProcessHistoryID prevPhid;
857  bool iFirst = true;
858 
859  indexIntoFile_.unsortedEventNumbers().clear(); // should already be empty, just being careful
861 
862  // First, loop through the event tree.
863  while(eventTree_.next()) {
864  bool newRun = false;
865  bool newLumi = false;
867  fillHistory();
868 
869  // Save the event numbers as we loop through the event auxiliary to avoid
870  // having to read through the event auxiliary again later. These event numbers
871  // are not actually used in this function, but could be needed elsewhere.
873 
874  ProcessHistoryID reducedPHID = ProcessHistoryRegistry::instance()->extra().reduceProcessHistoryID(eventAux().processHistoryID());
875 
876  if(iFirst || prevPhid != reducedPHID || prevRun != eventAux().run()) {
877  iFirst = false;
878  newRun = newLumi = true;
879  } else if(prevLumi != eventAux().luminosityBlock()) {
880  newLumi = true;
881  }
882  prevPhid = reducedPHID;
883  prevRun = eventAux().run();
884  prevLumi = eventAux().luminosityBlock();
885  if(newLumi) {
886  lumis.emplace_back(reducedPHID,
887  eventAux().run(), eventAux().luminosityBlock(), eventTree_.entryNumber()); // (insert 1)
888  runLumiSet.insert(LuminosityBlockID(eventAux().run(), eventAux().luminosityBlock())); // (insert 2)
889  } else {
890  LumiItem& currentLumi = lumis.back();
891  assert(currentLumi.lastEventEntry_ == eventTree_.entryNumber());
892  ++currentLumi.lastEventEntry_;
893  }
894  if(newRun) {
895  // Insert run in list if it is not already there.
896  RunItem item(reducedPHID, eventAux().run());
897  if(runItemSet.insert(item).second) { // (check 3, insert 3)
898  runs.push_back(std::move(item)); // (insert 5)
899  runSet.insert(eventAux().run()); // (insert 4)
900  phidMap.insert(std::make_pair(eventAux().run(), reducedPHID));
901  }
902  }
903  }
904  // now clean up.
908 
909  // Loop over run entries and fill information.
910 
911  typedef std::map<RunNumber_t, EntryNumber_t> RunMap;
912  RunMap runMap; // (declare 11)
913 
914  typedef std::vector<RunItem> RunVector;
915  RunVector emptyRuns; // (declare 12)
916 
917  if(runTree_.isValid()) {
918  while(runTree_.next()) {
919  // Note: adjacent duplicates will be skipped without an explicit check.
920 
921  boost::shared_ptr<RunAuxiliary> runAux = fillRunAuxiliary();
922  ProcessHistoryID reducedPHID = ProcessHistoryRegistry::instance()->extra().reduceProcessHistoryID(runAux->processHistoryID());
923 
924  if(runSet.insert(runAux->run()).second) { // (check 4, insert 4)
925  // This run was not associated with any events.
926  emptyRuns.emplace_back(reducedPHID, runAux->run()); // (insert 12)
927  }
928  runMap.insert(std::make_pair(runAux->run(), runTree_.entryNumber())); // (insert 11)
929  phidMap.insert(std::make_pair(runAux->run(), reducedPHID));
930  }
931  // now clean up.
933  }
934 
935  // Insert the ordered empty runs into the run list.
936  RunItemSortByRun runItemSortByRun;
937  stable_sort_all(emptyRuns, runItemSortByRun);
938 
939  RunList::iterator itRuns = runs.begin(), endRuns = runs.end();
940  for(RunVector::const_iterator i = emptyRuns.begin(), iEnd = emptyRuns.end(); i != iEnd; ++i) {
941  for(; itRuns != endRuns; ++itRuns) {
942  if(runItemSortByRun(*i, *itRuns)) {
943  break;
944  }
945  }
946  runs.insert(itRuns, *i);
947  }
948 
949  // Loop over luminosity block entries and fill information.
950 
951  typedef std::vector<LumiItem> LumiVector;
952  LumiVector emptyLumis; // (declare 7)
953 
954  typedef std::map<LuminosityBlockID, EntryNumber_t> RunLumiMap;
955  RunLumiMap runLumiMap; // (declare 6)
956 
957  if(lumiTree_.isValid()) {
958  while(lumiTree_.next()) {
959  // Note: adjacent duplicates will be skipped without an explicit check.
960  boost::shared_ptr<LuminosityBlockAuxiliary> lumiAux = fillLumiAuxiliary();
961  LuminosityBlockID lumiID = LuminosityBlockID(lumiAux->run(), lumiAux->luminosityBlock());
962  if(runLumiSet.insert(lumiID).second) { // (check 2, insert 2)
963  // This lumi was not associated with any events.
964  // Use the process history ID from the corresponding run. In cases of practical
965  // importance, this should be the correct process history ID, but it is possible
966  // to construct files where this is not the correct process history ID ...
967  PHIDMap::const_iterator iPhidMap = phidMap.find(lumiAux->run());
968  assert(iPhidMap != phidMap.end());
969  emptyLumis.emplace_back(iPhidMap->second, lumiAux->run(), lumiAux->luminosityBlock(), -1LL); // (insert 7)
970  }
971  runLumiMap.insert(std::make_pair(lumiID, lumiTree_.entryNumber()));
972  }
973  // now clean up.
975  }
976 
977  // Insert the ordered empty lumis into the lumi list.
978  LumiItemSortByRunLumi lumiItemSortByRunLumi;
979  stable_sort_all(emptyLumis, lumiItemSortByRunLumi);
980 
981  LumiList::iterator itLumis = lumis.begin(), endLumis = lumis.end();
982  for(LumiVector::const_iterator i = emptyLumis.begin(), iEnd = emptyLumis.end(); i != iEnd; ++i) {
983  for(; itLumis != endLumis; ++itLumis) {
984  if(lumiItemSortByRunLumi(*i, *itLumis)) {
985  break;
986  }
987  }
988  lumis.insert(itLumis, *i);
989  }
990 
991  // Create a map of RunItems that gives the order of first appearance in the list.
992  // Also fill in the vector of process history IDs
993  typedef std::map<RunItem, int, RunItemSortByRunPhid> RunCountMap;
994  RunCountMap runCountMap; // Declare (17)
995  std::vector<ProcessHistoryID>& phids = indexIntoFile_.setProcessHistoryIDs();
996  assert(phids.empty());
997  std::vector<IndexIntoFile::RunOrLumiEntry>& entries = indexIntoFile_.setRunOrLumiEntries();
998  assert(entries.empty());
999  int rcount = 0;
1000  for(RunList::iterator it = runs.begin(), itEnd = runs.end(); it != itEnd; ++it) {
1001  RunCountMap::const_iterator countMapItem = runCountMap.find(*it);
1002  if(countMapItem == runCountMap.end()) {
1003  countMapItem = runCountMap.insert(std::make_pair(*it, rcount)).first; // Insert (17)
1004  assert(countMapItem != runCountMap.end());
1005  ++rcount;
1006  }
1007  std::vector<ProcessHistoryID>::const_iterator phidItem = find_in_all(phids, it->phid_);
1008  if(phidItem == phids.end()) {
1009  phids.push_back(it->phid_);
1010  phidItem = phids.end() - 1;
1011  }
1012  entries.emplace_back(
1013  countMapItem->second, // use (17)
1014  -1LL,
1015  runMap[it->run_], // use (11)
1016  phidItem - phids.begin(),
1017  it->run_,
1018  0U,
1019  -1LL,
1020  -1LL);
1021  }
1022 
1023  // Create a map of LumiItems that gives the order of first appearance in the list.
1024  typedef std::map<LumiItem, int, LumiItemSortByRunLumiPhid> LumiCountMap;
1025  LumiCountMap lumiCountMap; // Declare (19)
1026  int lcount = 0;
1027  for(LumiList::iterator it = lumis.begin(), itEnd = lumis.end(); it != itEnd; ++it) {
1028  RunCountMap::const_iterator runCountMapItem = runCountMap.find(RunItem(it->phid_, it->run_));
1029  assert(runCountMapItem != runCountMap.end());
1030  LumiCountMap::const_iterator countMapItem = lumiCountMap.find(*it);
1031  if(countMapItem == lumiCountMap.end()) {
1032  countMapItem = lumiCountMap.insert(std::make_pair(*it, lcount)).first; // Insert (17)
1033  assert(countMapItem != lumiCountMap.end());
1034  ++lcount;
1035  }
1036  std::vector<ProcessHistoryID>::const_iterator phidItem = find_in_all(phids, it->phid_);
1037  assert(phidItem != phids.end());
1038  entries.emplace_back(
1039  runCountMapItem->second,
1040  countMapItem->second,
1041  runLumiMap[LuminosityBlockID(it->run_, it->lumi_)],
1042  phidItem - phids.begin(),
1043  it->run_,
1044  it->lumi_,
1045  it->firstEventEntry_,
1046  it->lastEventEntry_);
1047  }
1048  stable_sort_all(entries);
1049  }
1050 
1051  void
1052  RootFile::validateFile(InputType::InputType inputType, bool usingGoToEvent) {
1053  if(!fid_.isValid()) {
1055  }
1056  if(!eventTree_.isValid()) {
1058  "'Events' tree is corrupted or not present\n" << "in the input file.\n";
1059  }
1060 
1061  if(fileFormatVersion().hasIndexIntoFile()) {
1062  if(runTree().entries() > 0) {
1063  assert(!indexIntoFile_.empty());
1064  }
1066  if(daqProvenanceHelper_) {
1067  std::vector<ProcessHistoryID>& phidVec = indexIntoFile_.setProcessHistoryIDs();
1068  for(std::vector<ProcessHistoryID>::iterator it = phidVec.begin(), itEnd = phidVec.end();
1069  it != itEnd;
1070  ++it) {
1071  *it = daqProvenanceHelper_->mapProcessHistoryID(*it);
1072  }
1073  }
1075  }
1076  }
1077  else {
1078  assert(indexIntoFile_.empty());
1080  }
1081 
1084  indexIntoFile_.setEventFinder(boost::shared_ptr<IndexIntoFile::EventFinder>(new RootFileEventFinder(eventTree_)));
1085  // We fill the event numbers explicitly if we need to find events in closed files,
1086  // such as for secondary files (or secondary sources) or if duplicate checking across files.
1087  bool needEventNumbers = false;
1088  bool needIndexesForDuplicateChecker = duplicateChecker_ && duplicateChecker_->checkingAllFiles() && !duplicateChecker_->checkDisabled();
1089  if(inputType != InputType::Primary || needIndexesForDuplicateChecker || usingGoToEvent) {
1090  needEventNumbers = true;
1091  }
1092  bool needEventEntries = false;
1093  if(inputType != InputType::Primary || !noEventSort_) {
1094  // We need event entries for sorting or for secondary files or sources.
1095  needEventEntries = true;
1096  }
1097  indexIntoFile_.fillEventNumbersOrEntries(needEventNumbers, needEventEntries);
1098  }
1099 
1100  void
1101  RootFile::reportOpened(std::string const& inputType) {
1102  // Report file opened.
1103  std::string const label = "source";
1104  std::string moduleName = "PoolSource";
1105  filePtr_->inputFileOpened(
1106  logicalFile_,
1107  inputType,
1108  moduleName,
1109  label,
1110  fid_.fid(),
1112  }
1113 
1114  void
1116  // Just to play it safe, zero all pointers to objects in the InputFile to be closed.
1117  eventHistoryTree_ = 0;
1118  for(RootTreePtrArray::iterator it = treePointers_.begin(), itEnd = treePointers_.end(); it != itEnd; ++it) {
1119  (*it)->close();
1120  (*it) = 0;
1121  }
1122  filePtr_->Close();
1123  filePtr_.reset();
1124  }
1125 
1126  void
1129  // Already read.
1130  return;
1131  }
1133  EventAuxiliary *pEvAux = &eventAux_;
1135  } else {
1136  // for backward compatibility.
1138  EventAux *pEvAux = &eventAux;
1139  eventTree_.fillAux<EventAux>(pEvAux);
1140  conversion(eventAux, eventAux_);
1141  }
1143  }
1144 
1145  void
1149  }
1150 
1151  void
1153  // We could consider doing delayed reading, but because we have to
1154  // store this History object in a different tree than the event
1155  // data tree, this is too hard to do in this first version.
1156 
1157  if(fileFormatVersion().eventHistoryBranch()) {
1158  // Lumi block number was not in EventID for the relevant releases.
1159  EventID id(eventAux().id().run(), 0, eventAux().id().event());
1160  if(eventProcessHistoryIter_->eventID() != id) {
1163  assert(eventProcessHistoryIter_->eventID() == id);
1164  }
1167  } else if(fileFormatVersion().eventHistoryTree()) {
1168  // for backward compatibility.
1169  History* pHistory = history_.get();
1170  TBranch* eventHistoryBranch = eventHistoryTree_->GetBranch(poolNames::eventHistoryBranchName().c_str());
1171  if(!eventHistoryBranch) {
1173  << "Failed to find history branch in event history tree.\n";
1174  }
1175  eventHistoryBranch->SetAddress(&pHistory);
1177  eventAux_.setProcessHistoryID(history_->processHistoryID());
1178  eventSelectionIDs_.reset(&history_->eventSelectionIDs(), do_nothing_deleter());
1179  branchListIndexes_.reset(&history_->branchListIndexes(), do_nothing_deleter());
1180  } else if(fileFormatVersion().noMetaDataTrees()) {
1181  // Current format
1183  TBranch* eventSelectionIDBranch = eventTree_.tree()->GetBranch(poolNames::eventSelectionsBranchName().c_str());
1184  assert(eventSelectionIDBranch != 0);
1185  eventTree_.fillBranchEntry(eventSelectionIDBranch, pESV);
1186  BranchListIndexes* pBLI = branchListIndexes_.get();
1187  TBranch* branchListIndexesBranch = eventTree_.tree()->GetBranch(poolNames::branchListIndexesBranchName().c_str());
1188  assert(branchListIndexesBranch != 0);
1189  eventTree_.fillBranchEntry(branchListIndexesBranch, pBLI);
1190  }
1191  if(provenanceAdaptor_) {
1192  eventAux_.setProcessHistoryID(provenanceAdaptor_->convertID(eventAux().processHistoryID()));
1193  for(EventSelectionIDVector::iterator i = eventSelectionIDs_->begin(), e = eventSelectionIDs_->end(); i != e; ++i) {
1194  (*i) = provenanceAdaptor_->convertID(*i);
1195  }
1196  }
1197  if(daqProvenanceHelper_) {
1199  }
1201  // old format. branchListIndexes_ must be filled in from the ProvenanceAdaptor.
1202  provenanceAdaptor_->branchListIndexes(*branchListIndexes_);
1203  }
1205  }
1206 
1207  boost::shared_ptr<LuminosityBlockAuxiliary>
1209  boost::shared_ptr<LuminosityBlockAuxiliary> lumiAuxiliary(new LuminosityBlockAuxiliary);
1210  if(fileFormatVersion().newAuxiliary()) {
1211  LuminosityBlockAuxiliary *pLumiAux = lumiAuxiliary.get();
1213  } else {
1214  LuminosityBlockAux lumiAux;
1215  LuminosityBlockAux *pLumiAux = &lumiAux;
1217  conversion(lumiAux, *lumiAuxiliary);
1218  }
1219  if(provenanceAdaptor_) {
1220  lumiAuxiliary->setProcessHistoryID(provenanceAdaptor_->convertID(lumiAuxiliary->processHistoryID()));
1221  }
1222  if(daqProvenanceHelper_) {
1223  lumiAuxiliary->setProcessHistoryID(daqProvenanceHelper_->mapProcessHistoryID(lumiAuxiliary->processHistoryID()));
1224  }
1225  if(lumiAuxiliary->luminosityBlock() == 0 && !fileFormatVersion().runsAndLumis()) {
1226  lumiAuxiliary->id() = LuminosityBlockID(RunNumber_t(1), LuminosityBlockNumber_t(1));
1227  }
1228  return lumiAuxiliary;
1229  }
1230 
1231  boost::shared_ptr<RunAuxiliary>
1233  boost::shared_ptr<RunAuxiliary> runAuxiliary(new RunAuxiliary);
1234  if(fileFormatVersion().newAuxiliary()) {
1235  RunAuxiliary *pRunAux = runAuxiliary.get();
1236  runTree_.fillAux<RunAuxiliary>(pRunAux);
1237  } else {
1238  RunAux runAux;
1239  RunAux *pRunAux = &runAux;
1240  runTree_.fillAux<RunAux>(pRunAux);
1241  conversion(runAux, *runAuxiliary);
1242  }
1243  if(provenanceAdaptor_) {
1244  runAuxiliary->setProcessHistoryID(provenanceAdaptor_->convertID(runAuxiliary->processHistoryID()));
1245  }
1246  if(daqProvenanceHelper_) {
1247  runAuxiliary->setProcessHistoryID(daqProvenanceHelper_->mapProcessHistoryID(runAuxiliary->processHistoryID()));
1248  }
1249  return runAuxiliary;
1250  }
1251 
1252  bool
1254  while(offset > 0 && indexIntoFileIter_ != indexIntoFileEnd_) {
1255 
1256  int phIndexOfSkippedEvent = IndexIntoFile::invalidIndex;
1257  RunNumber_t runOfSkippedEvent = IndexIntoFile::invalidRun;
1260 
1261  indexIntoFileIter_.skipEventForward(phIndexOfSkippedEvent,
1262  runOfSkippedEvent,
1263  lumiOfSkippedEvent,
1264  skippedEventEntry);
1265 
1266  // At the end of the file and there were no more events to skip
1267  if(skippedEventEntry == IndexIntoFile::invalidEntry) break;
1268 
1269  if(eventSkipperByID_ && eventSkipperByID_->somethingToSkip()) {
1270  eventTree_.setEntryNumber(skippedEventEntry);
1272  if(eventSkipperByID_->skipIt(runOfSkippedEvent, lumiOfSkippedEvent, eventAux_.id().event())) {
1273  continue;
1274  }
1275  }
1276  if(duplicateChecker_ &&
1277  !duplicateChecker_->checkDisabled() &&
1278  !duplicateChecker_->noDuplicatesInFile()) {
1279 
1280  eventTree_.setEntryNumber(skippedEventEntry);
1282  if(duplicateChecker_->isDuplicateAndCheckActive(phIndexOfSkippedEvent,
1283  runOfSkippedEvent,
1284  lumiOfSkippedEvent,
1285  eventAux_.id().event(),
1286  file_)) {
1287  continue;
1288  }
1289  }
1290  --offset;
1291  }
1292 
1293  while(offset < 0) {
1294 
1295  if(duplicateChecker_) {
1296  duplicateChecker_->disable();
1297  }
1298 
1299  int phIndexOfEvent = IndexIntoFile::invalidIndex;
1302  EntryNumber_t eventEntry = IndexIntoFile::invalidEntry;
1303 
1304  indexIntoFileIter_.skipEventBackward(phIndexOfEvent,
1305  runOfEvent,
1306  lumiOfEvent,
1307  eventEntry);
1308 
1309  if(eventEntry == IndexIntoFile::invalidEntry) break;
1310 
1311  if(eventSkipperByID_ && eventSkipperByID_->somethingToSkip()) {
1312  eventTree_.setEntryNumber(eventEntry);
1314  if(eventSkipperByID_->skipIt(runOfEvent, lumiOfEvent, eventAux_.id().event())) {
1315  continue;
1316  }
1317  }
1318  ++offset;
1319  }
1321  }
1322 
1323  bool
1324  RootFile::goToEvent(EventID const& eventID) {
1325 
1327 
1328  if(duplicateChecker_) {
1329  duplicateChecker_->disable();
1330  }
1331 
1334 
1336  indexIntoFile_.findPosition(sortOrder, eventID.run(), eventID.luminosityBlock(), eventID.event());
1337 
1338  if(iter == indexIntoFile_.end(sortOrder)) {
1339  return false;
1340  }
1341  indexIntoFileIter_ = iter;
1342  return true;
1343  }
1344 
1345  // readEvent() is responsible for creating, and setting up, the
1346  // EventPrincipal.
1347  //
1348  // 1. create an EventPrincipal with a unique EventID
1349  // 2. For each entry in the provenance, put in one Group,
1350  // holding the Provenance for the corresponding EDProduct.
1351  // 3. set up the caches in the EventPrincipal to know about this
1352  // Group.
1353  //
1354  // We do *not* create the EDProduct instance (the equivalent of reading
1355  // the branch containing this EDProduct. That will be done by the Delayed Reader,
1356  // when it is asked to do so.
1357  //
1359  RootFile::readEvent(EventPrincipal& cache, boost::shared_ptr<LuminosityBlockPrincipal> lb) {
1362  // Set the entry in the tree, and read the event at that entry.
1364  EventPrincipal* ep = readCurrentEvent(cache, lb);
1365 
1366  assert(ep != 0);
1367  assert(eventAux().run() == indexIntoFileIter_.run() + forcedRunOffset_);
1368  assert(eventAux().luminosityBlock() == indexIntoFileIter_.lumi());
1369 
1370  // If this next assert shows up in performance profiling or significantly affects memory, then these three lines should be deleted.
1371  // The IndexIntoFile should guarantee that it never fails.
1373  ProcessHistoryID const& reducedPHID = ProcessHistoryRegistry::instance()->extra().reduceProcessHistoryID(idToCheck);
1375 
1377  return ep;
1378  }
1379 
1380  // Reads event at the current entry in the event tree
1383  boost::shared_ptr<LuminosityBlockPrincipal> lb) {
1384  if(!eventTree_.current()) {
1385  return 0;
1386  }
1388  if(!fileFormatVersion().lumiInEventID()) {
1389  //ugly, but will disappear when the backward compatibility is done with schema evolution.
1390  const_cast<EventID&>(eventAux_.id()).setLuminosityBlockNumber(eventAux_.oldLuminosityBlock());
1392  }
1393  fillHistory();
1395 
1396  // We're not done ... so prepare the EventPrincipal
1397  cache.fillEventPrincipal(eventAux(),
1398  lb,
1401  makeBranchMapper(),
1403 
1404  // report event read from file
1405  filePtr_->eventReadFromFile(eventID().run(), eventID().event());
1406  return &cache;
1407  }
1408 
1411  boost::shared_ptr<LuminosityBlockPrincipal> lb) {
1412  cache.clearEventPrincipal();
1413  return readCurrentEvent(cache, lb);
1414  }
1415 
1416  void
1418  eventTree_.setEntryNumber(entry);
1419  }
1420 
1421  boost::shared_ptr<RunAuxiliary>
1425 
1426  // Begin code for backward compatibility before the existence of run trees.
1427  if(!runTree_.isValid()) {
1428 
1429  // prior to the support of run trees.
1430  // RunAuxiliary did not contain a valid timestamp. Take it from the next event.
1432  assert(eventEntry != IndexIntoFile::invalidEntry);
1434  eventTree_.setEntryNumber(eventEntry);
1435  assert(eventTree_.current());
1437  eventTree_.setEntryNumber(savedEntry);
1438 
1440  overrideRunNumber(run);
1441  return boost::shared_ptr<RunAuxiliary>(new RunAuxiliary(run.run(), eventAux().time(), Timestamp::invalidTimestamp()));
1442  }
1443  // End code for backward compatibility before the existence of run trees.
1445  boost::shared_ptr<RunAuxiliary> runAuxiliary = fillRunAuxiliary();
1446  assert(runAuxiliary->run() == indexIntoFileIter_.run());
1447  overrideRunNumber(runAuxiliary->id());
1448  filePtr_->reportInputRunNumber(runAuxiliary->run());
1449  // If RunAuxiliary did not contain a valid begin timestamp, invalidate any end timestamp.
1450  if(runAuxiliary->beginTime() == Timestamp::invalidTimestamp()) {
1451  runAuxiliary->setEndTime(Timestamp::invalidTimestamp());
1452  }
1453 
1454  // If RunAuxiliary did not contain a valid timestamp, or if this an old format file from
1455  // when the Run's ProcessHistory included only processes where products were added to the Run itself,
1456  // we attempt to read the first event in the run to get appropriate info.
1457  if(runAuxiliary->beginTime() == Timestamp::invalidTimestamp() ||
1459 
1461  // If we have a valid event, use its information.
1462  if(eventEntry != IndexIntoFile::invalidEntry) {
1464  eventTree_.setEntryNumber(eventEntry);
1465  assert(eventTree_.current());
1467 
1468  // RunAuxiliary did not contain a valid timestamp. Take it from the next event in this run if there is one.
1469  if(runAuxiliary->beginTime() == Timestamp::invalidTimestamp()) {
1470  runAuxiliary->setBeginTime(eventAux().time());
1471  }
1472 
1473  // For backwards compatibility when the Run's ProcessHistory included only processes where products were added to the
1474  // Run, and then the Run and Event auxiliaries could be different. Use the event ProcessHistoryID if there is one. It should
1475  // almost always be correct by the current definition (processes included if any products are added. This makes the run, lumi,
1476  // and event ProcessHistory's always be the same if no file merging occurs).
1477  if(!fileFormatVersion().processHistorySameWithinRun()) {
1478  fillHistory();
1479  runAuxiliary->setProcessHistoryID(eventAux().processHistoryID());
1480  savedRunAuxiliary_ = runAuxiliary;
1481  }
1482  eventTree_.setEntryNumber(savedEntry);
1483  } else {
1484  // No valid event, just use what is there, because it is the best we can do.
1485  savedRunAuxiliary_ = runAuxiliary;
1486  }
1487  }
1488  return runAuxiliary;
1489  }
1490 
1491  boost::shared_ptr<RunPrincipal>
1492  RootFile::readRun_(boost::shared_ptr<RunPrincipal> rpCache) {
1495  // Begin code for backward compatibility before the existence of run trees.
1496  if(!runTree_.isValid()) {
1498  return rpCache;
1499  }
1500  // End code for backward compatibility before the existence of run trees.
1501  rpCache->fillRunPrincipal(runTree_.rootDelayedReader());
1502  // Read in all the products now.
1503  rpCache->readImmediate();
1505  return rpCache;
1506  }
1507 
1508  boost::shared_ptr<LuminosityBlockAuxiliary>
1512  // Begin code for backward compatibility before the existence of lumi trees.
1513  if(!lumiTree_.isValid()) {
1515  assert(eventEntry != IndexIntoFile::invalidEntry);
1517  eventTree_.setEntryNumber(eventEntry);
1518  assert(eventTree_.current());
1520  eventTree_.setEntryNumber(savedEntry);
1521 
1523  overrideRunNumber(lumi);
1524  return boost::shared_ptr<LuminosityBlockAuxiliary>(new LuminosityBlockAuxiliary(lumi.run(), lumi.luminosityBlock(), eventAux().time(), Timestamp::invalidTimestamp()));
1525  }
1526  // End code for backward compatibility before the existence of lumi trees.
1528  boost::shared_ptr<LuminosityBlockAuxiliary> lumiAuxiliary = fillLumiAuxiliary();
1529  assert(lumiAuxiliary->run() == indexIntoFileIter_.run());
1530  assert(lumiAuxiliary->luminosityBlock() == indexIntoFileIter_.lumi());
1531  overrideRunNumber(lumiAuxiliary->id());
1532  filePtr_->reportInputLumiSection(lumiAuxiliary->run(), lumiAuxiliary->luminosityBlock());
1533  if(lumiAuxiliary->beginTime() == Timestamp::invalidTimestamp()) {
1535  if(eventEntry != IndexIntoFile::invalidEntry) {
1537  eventTree_.setEntryNumber(eventEntry);
1538  assert(eventTree_.current());
1540  eventTree_.setEntryNumber(savedEntry);
1541 
1542  lumiAuxiliary->setBeginTime(eventAux().time());
1543  }
1544  lumiAuxiliary->setEndTime(Timestamp::invalidTimestamp());
1545  }
1546  if(!fileFormatVersion().processHistorySameWithinRun() && savedRunAuxiliary_) {
1547  lumiAuxiliary->setProcessHistoryID(savedRunAuxiliary_->processHistoryID());
1548  }
1549  return lumiAuxiliary;
1550  }
1551 
1552  boost::shared_ptr<LuminosityBlockPrincipal>
1553  RootFile::readLumi(boost::shared_ptr<LuminosityBlockPrincipal> lbCache) {
1556  // Begin code for backward compatibility before the existence of lumi trees.
1557  if(!lumiTree_.isValid()) {
1559  return lbCache;
1560  }
1561  // End code for backward compatibility before the existence of lumi trees.
1563  lbCache->fillLuminosityBlockPrincipal(lumiTree_.rootDelayedReader());
1564  // Read in all the products now.
1565  lbCache->readImmediate();
1567  return lbCache;
1568  }
1569 
1570  bool
1573  if(indexIntoFileIter_ == indexIntoFileEnd_) return false;
1575  return true;
1576  }
1577 
1578  bool
1581  if(indexIntoFileIter_ == indexIntoFileEnd_) return false;
1583  return true;
1584  }
1585 
1586  bool
1589  if(indexIntoFileIter_ == indexIntoFileEnd_) return false;
1591  return true;
1592  }
1593 
1594  bool
1598  }
1601  if(run != indexIntoFileIter_.run()) return false;
1602  if(lumi != indexIntoFileIter_.lumi()) return false;
1604  return true;
1605  }
1606 
1607  void
1609  if(forcedRunOffset_ != 0) {
1610  id = RunID(id.run() + forcedRunOffset_);
1611  }
1612  if(id < RunID::firstValidRun()) id = RunID::firstValidRun();
1613  }
1614 
1615  void
1617  if(forcedRunOffset_ != 0) {
1618  id = LuminosityBlockID(id.run() + forcedRunOffset_, id.luminosityBlock());
1619  }
1620  if(RunID(id.run()) < RunID::firstValidRun()) id = LuminosityBlockID(RunID::firstValidRun().run(), id.luminosityBlock());
1621  }
1622 
1623  void
1624  RootFile::overrideRunNumber(EventID& id, bool isRealData) {
1625  if(forcedRunOffset_ != 0) {
1626  if(isRealData) {
1627  throw Exception(errors::Configuration, "RootFile::RootFile()")
1628  << "The 'setRunNumber' parameter of PoolSource cannot be used with real data.\n";
1629  }
1630  id = EventID(id.run() + forcedRunOffset_, id.luminosityBlock(), id.event());
1631  }
1632  if(RunID(id.run()) < RunID::firstValidRun()) {
1634  }
1635  }
1636 
1637 
1638  void
1640  // Read in the event history tree, if we have one...
1641  if(fileFormatVersion().eventHistoryTree()) {
1642  history_.reset(new History);
1643  eventHistoryTree_ = dynamic_cast<TTree*>(filePtr_->Get(poolNames::eventHistoryTreeName().c_str()));
1644  if(!eventHistoryTree_) {
1646  << "Failed to find the event history tree.\n";
1647  }
1648  }
1649  }
1650 
1651  void
1653  std::string releaseVersion = getReleaseVersion();
1654  releaseversion::DecomposedReleaseVersion currentRelease(releaseVersion);
1655  for(ProcessConfigurationVector::const_iterator it = processConfigurations_.begin(), itEnd = processConfigurations_.end();
1656  it != itEnd; ++it) {
1657  if(releaseversion::isEarlierRelease(currentRelease, it->releaseVersion())) {
1659  << "The release you are using, " << getReleaseVersion() << " , predates\n"
1660  << "a release (" << it->releaseVersion() << ") used in writing the input file, " << file() <<".\n"
1661  << "Forward compatibility cannot be supported.\n";
1662  }
1663  }
1664  }
1665 
1666  void
1668  std::vector<boost::shared_ptr<IndexIntoFile> > const& indexesIntoFiles,
1669  std::vector<boost::shared_ptr<IndexIntoFile> >::size_type currentIndexIntoFile) {
1670  if(duplicateChecker_) {
1671  if(eventTree_.next()) {
1673  duplicateChecker_->inputFileOpened(eventAux().isRealData(),
1675  indexesIntoFiles,
1676  currentIndexIntoFile);
1677  }
1679  }
1680  }
1681 
1682  void
1683  RootFile::dropOnInput (ProductRegistry& reg, GroupSelectorRules const& rules, bool dropDescendants, InputType::InputType inputType) {
1684  // This is the selector for drop on input.
1685  GroupSelector groupSelector;
1686  groupSelector.initialize(rules, reg.allBranchDescriptions());
1687 
1689  // Do drop on input. On the first pass, just fill in a set of branches to be dropped.
1690  std::set<BranchID> branchesToDrop;
1691  for(ProductRegistry::ProductList::const_iterator it = prodList.begin(), itEnd = prodList.end();
1692  it != itEnd; ++it) {
1693  BranchDescription const& prod = it->second;
1694  if(!groupSelector.selected(prod)) {
1695  if(dropDescendants) {
1696  branchChildren_->appendToDescendants(prod.branchID(), branchesToDrop);
1697  } else {
1698  branchesToDrop.insert(prod.branchID());
1699  }
1700  }
1701  }
1702 
1703  // On this pass, actually drop the branches.
1704  std::set<BranchID>::const_iterator branchesToDropEnd = branchesToDrop.end();
1705  for(ProductRegistry::ProductList::iterator it = prodList.begin(), itEnd = prodList.end(); it != itEnd;) {
1706  BranchDescription const& prod = it->second;
1707  bool drop = branchesToDrop.find(prod.branchID()) != branchesToDropEnd;
1708  if(drop) {
1709  if(groupSelector.selected(prod)) {
1710  LogWarning("RootFile")
1711  << "Branch '" << prod.branchName() << "' is being dropped from the input\n"
1712  << "of file '" << file_ << "' because it is dependent on a branch\n"
1713  << "that was explicitly dropped.\n";
1714  }
1715  treePointers_[prod.branchType()]->dropBranch(newBranchToOldBranch(prod.branchName()));
1716  hasNewlyDroppedBranch_[prod.branchType()] = true;
1717  ProductRegistry::ProductList::iterator icopy = it;
1718  ++it;
1719  prodList.erase(icopy);
1720  } else {
1721  ++it;
1722  }
1723  }
1724 
1725  // Drop on input mergeable run and lumi products, this needs to be invoked for secondary file input
1726  if(inputType == InputType::SecondaryFile) {
1727  TString tString;
1728  for(ProductRegistry::ProductList::iterator it = prodList.begin(), itEnd = prodList.end(); it != itEnd;) {
1729  BranchDescription const& prod = it->second;
1730  if(prod.branchType() != InEvent) {
1731  TClass *cp = gROOT->GetClass(prod.wrappedName().c_str());
1732  WrapperOwningHolder edp(cp->New(), prod.getInterface());
1733  if(edp.isMergeable()) {
1734  treePointers_[prod.branchType()]->dropBranch(newBranchToOldBranch(prod.branchName()));
1735  ProductRegistry::ProductList::iterator icopy = it;
1736  ++it;
1737  prodList.erase(icopy);
1738  } else {
1739  ++it;
1740  }
1741  }
1742  else ++it;
1743  }
1744  }
1745  }
1746 
1747  std::unique_ptr<MakeProvenanceReader>
1750  return std::unique_ptr<MakeProvenanceReader>(new MakeReducedProvenanceReader(parentageIDLookup_));
1751  } else if(fileFormatVersion_.splitProductIDs()) {
1752  return std::unique_ptr<MakeProvenanceReader>(new MakeFullProvenanceReader);
1753  } else if(fileFormatVersion_.perEventProductIDs()) {
1754  return std::unique_ptr<MakeProvenanceReader>(new MakeOldProvenanceReader);
1755  } else {
1756  return std::unique_ptr<MakeProvenanceReader>(new MakeDummyProvenanceReader);
1757  }
1758  }
1759 
1760  boost::shared_ptr<BranchMapper>
1762  if(!eventBranchMapper_) {
1764  }
1765  eventBranchMapper_->reset();
1766  return eventBranchMapper_;
1767  }
1768 
1770  public:
1771  ReducedProvenanceReader(RootTree* iRootTree, std::vector<ParentageID> const& iParentageIDLookup, DaqProvenanceHelper const* daqProvenanceHelper);
1772  private:
1773  virtual void readProvenance(BranchMapper const& mapper) const;
1775  TBranch* provBranch_;
1778  std::vector<ParentageID> const& parentageIDLookup_;
1780  };
1781 
1783  RootTree* iRootTree,
1784  std::vector<ParentageID> const& iParentageIDLookup,
1785  DaqProvenanceHelper const* daqProvenanceHelper) :
1787  rootTree_(iRootTree),
1788  pProvVector_(&provVector_),
1789  parentageIDLookup_(iParentageIDLookup),
1790  daqProvenanceHelper_(daqProvenanceHelper) {
1792  }
1793 
1794  void
1796  ReducedProvenanceReader* me = const_cast<ReducedProvenanceReader*>(this);
1798  setRefCoreStreamer(true);
1799  if(daqProvenanceHelper_) {
1800  for(StoredProductProvenanceVector::const_iterator it = provVector_.begin(), itEnd = provVector_.end();
1801  it != itEnd; ++it) {
1802  BranchID bid(it->branchID_);
1804  daqProvenanceHelper_->mapParentageID(parentageIDLookup_[it->parentageIDIndex_])));
1805  }
1806  } else {
1807  for(StoredProductProvenanceVector::const_iterator it = provVector_.begin(), itEnd = provVector_.end();
1808  it != itEnd; ++it) {
1809  mapper.insertIntoSet(ProductProvenance(BranchID(it->branchID_), parentageIDLookup_[it->parentageIDIndex_]));
1810  }
1811  }
1812  }
1813 
1815  public:
1816  explicit FullProvenanceReader(RootTree* rootTree, DaqProvenanceHelper const* daqProvenanceHelper);
1818  private:
1819  virtual void readProvenance(BranchMapper const& mapper) const;
1824  };
1825 
1828  rootTree_(rootTree),
1829  infoVector_(),
1830  pInfoVector_(&infoVector_),
1831  daqProvenanceHelper_(daqProvenanceHelper) {
1832  }
1833 
1834  void
1837  setRefCoreStreamer(true);
1838  if(daqProvenanceHelper_) {
1839  for(ProductProvenanceVector::const_iterator it = infoVector_.begin(), itEnd = infoVector_.end();
1840  it != itEnd; ++it) {
1842  daqProvenanceHelper_->mapParentageID(it->parentageID())));
1843  }
1844  } else {
1845  for(ProductProvenanceVector::const_iterator it = infoVector_.begin(), itEnd = infoVector_.end();
1846  it != itEnd; ++it) {
1847  mapper.insertIntoSet(*it);
1848  }
1849  }
1850  }
1851 
1853  public:
1854  explicit OldProvenanceReader(RootTree* rootTree, DaqProvenanceHelper const* daqProvenanceHelper);
1856  private:
1857  virtual void readProvenance(BranchMapper const& mapper) const;
1859  std::vector<EventEntryInfo> infoVector_;
1860  mutable std::vector<EventEntryInfo> *pInfoVector_;
1862  };
1863 
1866  rootTree_(rootTree),
1867  infoVector_(),
1868  pInfoVector_(&infoVector_),
1869  daqProvenanceHelper_(daqProvenanceHelper) {
1870  }
1871 
1872  void
1874  rootTree_->branchEntryInfoBranch()->SetAddress(&pInfoVector_);
1876  setRefCoreStreamer(true);
1877  for(std::vector<EventEntryInfo>::const_iterator it = infoVector_.begin(), itEnd = infoVector_.end();
1878  it != itEnd; ++it) {
1880  EntryDescriptionRegistry::instance()->getMapped(it->entryDescriptionID(), eed);
1881  Parentage parentage(eed.parents());
1882  if(daqProvenanceHelper_) {
1884  daqProvenanceHelper_->mapParentageID(parentage.id()));
1885  mapper.insertIntoSet(entry);
1886  } else {
1887  ProductProvenance entry(it->branchID(), parentage.id());
1888  mapper.insertIntoSet(entry);
1889  }
1890 
1891  }
1892  }
1893 
1895  public:
1898  private:
1899  virtual void readProvenance(BranchMapper const& mapper) const;
1900  };
1901 
1904  }
1905 
1906  void
1908  // Not providing parentage!!!
1909  }
1910 
1911  std::unique_ptr<ProvenanceReaderBase>
1913  return std::unique_ptr<ProvenanceReaderBase>(new DummyProvenanceReader);
1914  }
1915 
1916  std::unique_ptr<ProvenanceReaderBase>
1917  MakeOldProvenanceReader::makeReader(RootTree& rootTree, DaqProvenanceHelper const* daqProvenanceHelper) const {
1918  return std::unique_ptr<ProvenanceReaderBase>(new OldProvenanceReader(&rootTree, daqProvenanceHelper));
1919  }
1920 
1921  std::unique_ptr<ProvenanceReaderBase>
1922  MakeFullProvenanceReader::makeReader(RootTree& rootTree, DaqProvenanceHelper const* daqProvenanceHelper) const {
1923  return std::unique_ptr<ProvenanceReaderBase>(new FullProvenanceReader(&rootTree, daqProvenanceHelper));
1924  }
1925 
1926  std::unique_ptr<ProvenanceReaderBase>
1927  MakeReducedProvenanceReader::makeReader(RootTree& rootTree, DaqProvenanceHelper const* daqProvenanceHelper) const {
1928  return std::unique_ptr<ProvenanceReaderBase>(new ReducedProvenanceReader(&rootTree, parentageIDLookup_, daqProvenanceHelper));
1929  }
1930 }
RunNumber_t run() const
Definition: EventID.h:42
EventID const & eventID() const
Definition: RootFile.h:101
Int_t getEntry(TBranch *branch, EntryNumber entryNumber)
Definition: RootTree.cc:273
void fillEventNumbersOrEntries(bool needEventNumbers, bool needEventEntries) const
virtual void readProvenance(BranchMapper const &mapper) const
Definition: RootFile.cc:1795
EventNumber_t event() const
Definition: EventID.h:44
std::string const & idToParameterSetBlobsBranchName()
Definition: BranchType.cc:249
std::unique_ptr< ProvenanceAdaptor > provenanceAdaptor_
Definition: RootFile.h:213
int i
Definition: DBlmapReader.cc:9
boost::shared_ptr< BranchChildren > branchChildren_
Definition: RootFile.h:211
StoredProductProvenanceVector provVector_
Definition: RootFile.cc:1776
bool isRealData() const
boost::shared_ptr< BranchListIndexes > branchListIndexes_
Definition: RootFile.h:209
std::string const & BranchTypeToAuxiliaryBranchName(BranchType const &branchType)
Definition: BranchType.cc:114
unsigned int const defaultNonEventLearningEntries
Definition: RootTree.h:37
std::unique_ptr< EventPrincipal > secondaryEventPrincipal_
Definition: RootFile.h:215
boost::shared_ptr< RunAuxiliary > savedRunAuxiliary_
Definition: RootFile.h:190
virtual void readProvenance(BranchMapper const &mapper) const
Definition: RootFile.cc:1873
std::unique_ptr< History > history_
Definition: RootFile.h:210
void doneFileInitialization() const
Clears the temporary vector of event numbers to reduce memory usage.
static int const invalidIndex
boost::shared_ptr< FileBlock > createFileBlock() const
Definition: RootFile.cc:624
TPRegexp parents
Definition: eve_filter.cc:24
BranchType const & branchType() const
std::string const & parentageTreeName()
Definition: BranchType.cc:158
static LuminosityBlockID firstValidLuminosityBlock()
std::string const & entryDescriptionBranchName()
Definition: BranchType.cc:153
bool skipEvents(int &offset)
Definition: RootFile.cc:1253
FileFormatVersion fileFormatVersion() const
Definition: RootFile.h:105
ProductProvenanceVector infoVector_
Definition: RootFile.cc:1821
ForwardSequence::const_iterator lower_bound_all(ForwardSequence const &s, Datum const &d)
wrappers for std::lower_bound
Definition: Algorithms.h:91
bool branchListIndexesUnchanged() const
Definition: RootFile.h:108
EventPrincipal * readCurrentEvent(EventPrincipal &cache, boost::shared_ptr< LuminosityBlockPrincipal > lb=boost::shared_ptr< LuminosityBlockPrincipal >())
Definition: RootFile.cc:1382
RunNumber_t run() const
Definition: RunID.h:44
std::vector< std::string > const & branchNames() const
Definition: RootTree.h:87
bool setEntryAtNextEventInLumi(RunNumber_t run, LuminosityBlockNumber_t lumi)
Definition: RootFile.cc:1595
ProcessConfigurationVector processConfigurations_
Definition: RootFile.h:177
StoredProductProvenanceVector * pProvVector_
Definition: RootFile.cc:1777
unsigned int EventNumber_t
Definition: EventID.h:30
std::string & branchName() const
void readParentageTree()
Definition: RootFile.cc:532
int whyNotFastClonable_
Definition: RootFile.h:193
void checkReleaseVersion()
Definition: RootFile.cc:1652
ParentageID id() const
Definition: Parentage.cc:20
DaqProvenanceHelper const * daqProvenanceHelper_
Definition: RootFile.cc:1823
tuple lumi
Definition: fjr2json.py:35
std::map< std::string, std::string > newBranchToOldBranch_
Definition: RootFile.h:206
EntryNumber_t firstEventEntryThisRun() const
IndexIntoFile::EntryType getEntryTypeWithSkipping()
Definition: RootFile.cc:704
bool empty() const
True if no runs, lumis, or events are in the file.
std::map< BranchKey, BranchDescription > ProductList
void fillEventAuxiliary()
Definition: RootFile.cc:1146
BranchID const & mapBranchID(BranchID const &branchID) const
static bool updateFromInput(BranchIDLists const &bidlists, std::string const &fileName)
bool setEntryAtRun(RunNumber_t run)
Definition: RootFile.cc:1587
ProductProvenanceVector * pInfoVector_
Definition: RootFile.cc:1822
RootTree lumiTree_
Definition: RootFile.h:198
Timestamp const & time() const
std::unique_ptr< MakeProvenanceReader > provenanceReaderMaker_
Definition: RootFile.h:214
EntryNumber const & entries() const
Definition: RootTree.h:85
RunNumber_t run() const
void setRefCoreStreamer(bool resetAll=false)
std::string const & fileFormatVersionBranchName()
Definition: BranchType.cc:212
static ThreadSafeRegistry * instance()
void reduceProcessHistoryIDs()
IndexIntoFileItr begin(SortOrder sortOrder) const
FullProvenanceReader(RootTree *rootTree, DaqProvenanceHelper const *daqProvenanceHelper)
Definition: RootFile.cc:1826
std::vector< BranchID > const & parents() const
std::string const & eventSelectionsBranchName()
Definition: BranchType.cc:237
virtual std::unique_ptr< ProvenanceReaderBase > makeReader(RootTree &eventTree, DaqProvenanceHelper const *daqProvenanceHelper) const
Definition: RootFile.cc:1922
InputSource::ProcessingMode processingMode_
Definition: RootFile.h:204
IndexIntoFile::IndexIntoFileItr indexIntoFileIter_
Definition: RootFile.h:187
boost::shared_ptr< RunAuxiliary > fillRunAuxiliary()
Definition: RootFile.cc:1232
void stable_sort_all(RandomAccessSequence &s)
wrappers for std::stable_sort
Definition: Algorithms.h:135
static RunID firstValidRun()
Definition: RunID.h:82
LuminosityBlockNumber_t lumi() const
boost::shared_ptr< BranchMapper > eventBranchMapper_
Definition: RootFile.h:216
void fillBranchEntryMeta(TBranch *branch, T *&pbuf)
Definition: RootTree.h:95
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:43
void trainCache(char const *branchNames)
Definition: RootTree.cc:253
uint16_t size_type
unsigned int LuminosityBlockNumber_t
Definition: EventID.h:31
virtual ~OldProvenanceReader()
Definition: RootFile.cc:1855
IndexIntoFileItr findRunPosition(RunNumber_t run) const
Same as findPosition.
TBranch * branchEntryInfoBranch() const
Definition: RootTree.h:117
long long EntryNumber_t
void fillProductRegistryTransients(std::vector< ProcessConfiguration > const &pcVec, ProductRegistry const &preg, bool okToRegister=false)
static void fixBranchListIndexes(BranchListIndexes &indexes)
EventPrincipal * readEvent(EventPrincipal &cache, boost::shared_ptr< LuminosityBlockPrincipal > lb=boost::shared_ptr< LuminosityBlockPrincipal >())
Definition: RootFile.cc:1359
MakeReducedProvenanceReader(std::vector< ParentageID > const &parentageIDLookup)
Definition: RootFile.cc:78
virtual ~DummyProvenanceReader()
Definition: RootFile.cc:1897
IndexIntoFileItr findPosition(RunNumber_t run, LuminosityBlockNumber_t lumi=0U, EventNumber_t event=0U) const
std::vector< EventSelectionID > EventSelectionIDVector
LuminosityBlockNumber_t luminosityBlock() const
FileFormatVersion fileFormatVersion_
Definition: RootFile.h:180
TTree const * metaTree() const
Definition: RootTree.h:113
std::string const & parameterSetsTreeName()
Definition: BranchType.cc:245
void setID(ParameterSetID const &id) const
virtual void readProvenance(BranchMapper const &mapper) const
Definition: RootFile.cc:1907
void setPosition(IndexIntoFile::IndexIntoFileItr const &position)
Definition: RootFile.cc:655
ProcessConfigurationRegistry::vector_type ProcessConfigurationVector
EventPrincipal * clearAndReadCurrentEvent(EventPrincipal &cache, boost::shared_ptr< LuminosityBlockPrincipal > lb=boost::shared_ptr< LuminosityBlockPrincipal >())
Definition: RootFile.cc:1410
tuple runs
Definition: gather_cfg.py:87
std::vector< BranchID > const & parents() const
Definition: Parentage.h:38
ProductList const & productList() const
U second(std::pair< T, U > const &p)
std::vector< EventProcessHistoryID >::const_iterator eventProcessHistoryIter_
Definition: RootFile.h:189
bool skipThisEntry()
Definition: RootFile.cc:660
IndexIntoFile::EntryType getNextEntryTypeWanted()
Definition: RootFile.cc:731
TTree const * tree() const
Definition: RootTree.h:111
FileID fid_
Definition: RootFile.h:181
boost::shared_ptr< DuplicateChecker > duplicateChecker_
Definition: RootFile.h:212
DaqProvenanceHelper const * daqProvenanceHelper_
Definition: RootFile.cc:1779
std::string const logicalFile_
Definition: RootFile.h:175
std::map< key_type, value_type > collection_type
std::vector< BranchListIndex > BranchListIndexes
IndexIntoFile::IndexIntoFileItr indexIntoFileEnd_
Definition: RootFile.h:186
std::string const & processHistoryMapBranchName()
Definition: BranchType.cc:192
std::vector< ProcessHistoryID > & setProcessHistoryIDs()
bool getMapped(key_type const &k, value_type &result) const
bool next()
Definition: RootTree.h:79
virtual std::unique_ptr< ProvenanceReaderBase > makeReader(RootTree &eventTree, DaqProvenanceHelper const *daqProvenanceHelper) const
Definition: RootFile.cc:1917
bool noEventSort_
Definition: RootFile.h:192
std::string const & className() const
bool wasLastEventJustRead() const
Definition: RootFile.cc:756
bool setEntryAtLumi(RunNumber_t run, LuminosityBlockNumber_t lumi)
Definition: RootFile.cc:1579
std::string friendlyName(std::string const &iFullName)
static RunNumber_t const invalidRun
std::string const & entryDescriptionTreeName()
Definition: BranchType.cc:145
void close()
Definition: RootFile.cc:1115
std::string const & fid() const
Definition: FileID.h:19
RootTree const & runTree() const
Definition: RootFile.h:104
bool modifiedIDs() const
Definition: RootFile.h:109
IndexIntoFile::EntryNumber_t lastEventEntryNumberRead_
Definition: RootFile.h:201
void copyPosition(IndexIntoFileItr const &position)
Copy the position without modifying the pointer to the IndexIntoFile or size.
std::string const & indexIntoFileBranchName()
Definition: BranchType.cc:227
IndexIntoFileItr end(SortOrder sortOrder) const
Used to end an iteration over the Runs, Lumis, and Events in a file.
virtual EventNumber_t getEventNumberOfEntry(roottree::EntryNumber entry) const
Definition: RootFile.cc:107
OldProvenanceReader(RootTree *rootTree, DaqProvenanceHelper const *daqProvenanceHelper)
Definition: RootFile.cc:1864
std::string const & eventHistoryBranchName()
Definition: BranchType.cc:232
void skipEventBackward(int &phIndexOfEvent, RunNumber_t &runOfEvent, LuminosityBlockNumber_t &lumiOfEvent, EntryNumber_t &eventEntry)
Long64_t numEntries(TFile *hdl, std::string const &trname)
Definition: CollUtil.cc:50
std::pair< std::string, MonitorElement * > entry
Definition: ME_MAP.h:8
EventAuxiliary const & eventAux() const
Definition: RootFile.h:97
bool eventHistoryTree() const
bool isEarlierRelease(std::string const &a, std::string const &b)
int whyNotFastClonable() const
Definition: RootFile.h:106
BranchType branchType() const
Definition: RootTree.h:122
RunNumber_t run() const
bool skipAnyEvents_
Definition: RootFile.h:191
RootTree eventTree_
Definition: RootFile.h:197
std::vector< BranchDescription const * > allBranchDescriptions() const
std::map< ParameterSetID, ParameterSetID > ParameterSetIdConverter
RootFile(std::string const &fileName, ProcessConfiguration const &processConfiguration, std::string const &logicalFileName, boost::shared_ptr< InputFile > filePtr, boost::shared_ptr< EventSkipperByID > eventSkipperByID, bool skipAnyEvents, int remainingEvents, int remainingLumis, unsigned int treeCacheSize, int treeMaxVirtualSize, InputSource::ProcessingMode processingMode, RunNumber_t const &forcedRunNumber, bool noEventSort, GroupSelectorRules const &groupSelectorRules, InputType::InputType inputType, boost::shared_ptr< DuplicateChecker > duplicateChecker, bool dropDescendantsOfDroppedProducts, std::vector< boost::shared_ptr< IndexIntoFile > > const &indexesIntoFiles, std::vector< boost::shared_ptr< IndexIntoFile > >::size_type currentIndexIntoFile, std::vector< ProcessHistoryID > &orderedProcessHistoryIDs, bool bypassVersionCheck, bool labelRawDataLikeMC, bool usingGoToEvent)
Definition: RootFile.cc:122
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
WrapperInterfaceBase const * getInterface() const
std::array< bool, NumBranchTypes > const & hasNewlyDroppedBranch() const
Definition: RootFile.h:107
std::string const & metaDataTreeName()
Definition: BranchType.cc:167
std::string & wrappedName() const
void fillHistory()
Definition: RootFile.cc:1152
bool isDuplicateEvent()
Definition: RootFile.cc:720
LuminosityBlockNumber_t oldLuminosityBlock() const
EntryDescriptionID id() const
unsigned int offset(bool)
void insertCollection(collection_type const &c)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
bool wasFirstEventJustRead() const
Definition: RootFile.cc:763
std::string const & parameterSetMapBranchName()
Definition: BranchType.cc:182
Hash< ProcessHistoryType > ProcessHistoryID
void fillEventPrincipal(EventAuxiliary const &aux, boost::shared_ptr< LuminosityBlockPrincipal > lbp, boost::shared_ptr< EventSelectionIDVector > eventSelectionIDs=boost::shared_ptr< EventSelectionIDVector >(), boost::shared_ptr< BranchListIndexes > branchListIndexes=boost::shared_ptr< BranchListIndexes >(), boost::shared_ptr< BranchMapper > mapper=boost::shared_ptr< BranchMapper >(new BranchMapper), DelayedReader *reader=0)
std::vector< ProductProvenance > ProductProvenanceVector
const int drop
boost::shared_ptr< EventSelectionIDVector > eventSelectionIDs_
Definition: RootFile.h:208
std::string const & processHistoryBranchName()
Definition: BranchType.cc:197
IndexIntoFile & indexIntoFile_
Definition: RootFile.h:183
virtual ~FullProvenanceReader()
Definition: RootFile.cc:1817
RootTree runTree_
Definition: RootFile.h:199
EntryNumber const & entryNumber() const
Definition: RootTree.h:84
bool goToEvent(EventID const &eventID)
Definition: RootFile.cc:1324
std::string getReleaseVersion()
void setAtEventEntry(IndexIntoFile::EntryNumber_t entry)
Definition: RootFile.cc:1417
bool storedProductProvenanceUsed() const
void fixIndexes(std::vector< ProcessHistoryID > &processHistoryIDs)
DelayedReader * rootDelayedReader() const
Definition: RootTree.cc:80
std::vector< RunOrLumiEntry > & setRunOrLumiEntries()
void conversion(EventAux const &from, EventAuxiliary &to)
Definition: EventAux.cc:9
virtual std::unique_ptr< ProvenanceReaderBase > makeReader(RootTree &eventTree, DaqProvenanceHelper const *daqProvenanceHelper) const
Definition: RootFile.cc:1927
std::array< bool, NumBranchTypes > hasNewlyDroppedBranch_
Definition: RootFile.h:194
std::vector< EventNumber_t > & unsortedEventNumbers() const
static Timestamp const & invalidTimestamp()
Definition: Timestamp.cc:83
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
void setIfFastClonable(int remainingEvents, int remainingLumis)
Definition: RootFile.cc:570
std::unique_ptr< MakeProvenanceReader > makeProvenanceReaderMaker() const
Definition: RootFile.cc:1748
void fillBranchEntry(TBranch *branch, T *&pbuf)
Definition: RootTree.h:106
static LuminosityBlockNumber_t const invalidLumi
IndexIntoFileItr findLumiPosition(RunNumber_t run, LuminosityBlockNumber_t lumi) const
void readEntryDescriptionTree()
Definition: RootFile.cc:486
std::string const & parentageBranchName()
Definition: BranchType.cc:162
boost::shared_ptr< LuminosityBlockAuxiliary > fillLumiAuxiliary()
Definition: RootFile.cc:1208
boost::shared_ptr< LuminosityBlockAuxiliary > readLuminosityBlockAuxiliary_()
Definition: RootFile.cc:1509
double b
Definition: hdecay.h:120
LuminosityBlockNumber_t luminosityBlock() const
bool processHistorySameWithinRun() const
ProcessHistoryID const & processHistoryID(int i) const
ProductList & productListUpdator()
void setProcessHistoryID(ProcessHistoryID const &phid)
std::vector< ParentageID > const & parentageIDLookup_
Definition: RootFile.cc:1778
bool isValid() const
Definition: RootTree.cc:68
std::vector< StoredProductProvenance > StoredProductProvenanceVector
void dropOnInput(ProductRegistry &reg, GroupSelectorRules const &rules, bool dropDescendants, InputType::InputType inputType)
Definition: RootFile.cc:1683
std::string const & file() const
Definition: RootFile.h:94
std::string const & productDescriptionBranchName()
Definition: BranchType.cc:172
std::string const & processConfigurationBranchName()
Definition: BranchType.cc:202
IndexIntoFile::IndexIntoFileItr indexIntoFileBegin_
Definition: RootFile.h:185
void insertIntoSet(ProductProvenance const &provenanceProduct) const
Definition: BranchMapper.cc:44
EntryNumber_t firstEventEntryThisLumi() const
ProcessHistoryID const & processHistoryID() const
EventID const & id() const
std::unique_ptr< DaqProvenanceHelper > daqProvenanceHelper_
Definition: RootFile.h:218
bool branchListIndexesUnchanged_
Definition: RootFile.h:195
void setEventFinder(boost::shared_ptr< EventFinder > ptr) const
void fillIndexIntoFile()
Definition: RootFile.cc:826
#define begin
Definition: vmac.h:31
std::vector< EventEntryInfo > * pInfoVector_
Definition: RootFile.cc:1860
author Stefano ARGIRO author Bill Tanenbaum
bool selected(BranchDescription const &desc) const
unsigned int const defaultNonEventCacheSize
Definition: RootTree.h:35
std::vector< value_type > vector_type
RootTreePtrArray treePointers_
Definition: RootFile.h:200
void fillEventNumbers() const
double a
Definition: hdecay.h:121
boost::shared_ptr< ProductRegistry const > productRegistry_
Definition: RootFile.h:202
static int position[264][3]
Definition: ReadPGInfo.cc:509
bool perEventProductIDs() const
Long64_t EntryNumber
Definition: RootTree.h:38
std::string const & BranchTypeToProductProvenanceBranchName(BranchType const &BranchType)
Definition: BranchType.cc:130
std::vector< ProcessHistoryID > & orderedProcessHistoryIDs_
Definition: RootFile.h:184
std::string const & productDependenciesBranchName()
Definition: BranchType.cc:177
void setNumberOfEvents(EntryNumber_t nevents) const
void overrideRunNumber(RunID &id)
Definition: RootFile.cc:1608
boost::shared_ptr< BranchMapper > makeBranchMapper()
Definition: RootFile.cc:1761
std::string const & entryDescriptionIDBranchName()
Definition: BranchType.cc:149
bool useReducedProcessHistoryID() const
boost::shared_ptr< RunPrincipal > readRun_(boost::shared_ptr< RunPrincipal > rpCache)
Definition: RootFile.cc:1492
boost::shared_ptr< InputFile > filePtr_
Definition: RootFile.h:178
void initializeDuplicateChecker(std::vector< boost::shared_ptr< IndexIntoFile > > const &indexesIntoFiles, std::vector< boost::shared_ptr< IndexIntoFile > >::size_type currentIndexIntoFile)
Definition: RootFile.cc:1667
std::string const & branchIDListBranchName()
Definition: BranchType.cc:207
unsigned int RunNumber_t
Definition: EventRange.h:32
std::string const & branchListIndexesBranchName()
Definition: BranchType.cc:241
std::vector< ParentageID > parentageIDLookup_
Definition: RootFile.h:217
EventAuxiliary eventAux_
Definition: RootFile.h:196
void fillThisEventAuxiliary()
Definition: RootFile.cc:1127
void resetTraining()
Definition: RootTree.h:120
bool setEntryAtEvent(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event)
Definition: RootFile.cc:1571
boost::shared_ptr< BranchIDListRegistry::collection_type const > branchIDLists_
Definition: RootFile.h:203
std::vector< ParentageID > const & parentageIDLookup_
Definition: RootFile.cc:81
ReducedProvenanceReader(RootTree *iRootTree, std::vector< ParentageID > const &iParentageIDLookup, DaqProvenanceHelper const *daqProvenanceHelper)
Definition: RootFile.cc:1782
std::string const & eventHistoryTreeName()
Definition: BranchType.cc:262
static Interceptor::Registry registry("Interceptor")
RootFileEventFinder(RootTree &eventTree)
Definition: RootFile.cc:104
ParentageID const & mapParentageID(ParentageID const &phid) const
IndexIntoFile::IndexIntoFileItr indexIntoFileIter() const
Definition: RootFile.cc:650
void initialize(GroupSelectorRules const &rules, std::vector< BranchDescription const * > const &branchDescriptions)
bool insertMapped(value_type const &v)
std::string const & newBranchToOldBranch(std::string const &newBranch) const
Definition: RootFile.cc:641
std::unique_ptr< TTreeCache > trainCache(TTree *tree, InputFile &file, unsigned int cacheSize, char const *branchNames)
Definition: RootTree.cc:297
virtual void readProvenance(BranchMapper const &mapper) const
Definition: RootFile.cc:1835
IndexIntoFileItr findEventPosition(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const
unsigned int const defaultLearningEntries
Definition: RootTree.h:36
boost::shared_ptr< EventSkipperByID > eventSkipperByID_
Definition: RootFile.h:179
std::vector< EventEntryInfo > infoVector_
Definition: RootFile.cc:1859
TTree * eventHistoryTree_
Definition: RootFile.h:207
LuminosityBlockNumber_t peekAheadAtLumi() const
std::string const & fileIdentifierBranchName()
Definition: BranchType.cc:217
boost::shared_ptr< ProductRegistry const > productRegistry() const
Definition: RootFile.h:95
void validateFile(InputType::InputType inputType, bool usingGoToEvent)
Definition: RootFile.cc:1052
virtual std::unique_ptr< ProvenanceReaderBase > makeReader(RootTree &eventTree, DaqProvenanceHelper const *daqProvenanceHelper) const
Definition: RootFile.cc:1912
virtual ~RootFileEventFinder()
Definition: RootFile.cc:105
EventNumber_t event() const
std::string const & moduleDescriptionMapBranchName()
Definition: BranchType.cc:187
std::string const file_
Definition: RootFile.h:174
boost::shared_ptr< RunAuxiliary > readRunAuxiliary_()
Definition: RootFile.cc:1422
void skipEventForward(int &phIndexOfSkippedEvent, RunNumber_t &runOfSkippedEvent, LuminosityBlockNumber_t &lumiOfSkippedEvent, EntryNumber_t &skippedEventEntry)
std::vector< EventProcessHistoryID > eventProcessHistoryIDs_
Definition: RootFile.h:188
DaqProvenanceHelper const * daqProvenanceHelper_
Definition: RootFile.cc:1861
std::string createGlobalIdentifier()
void copyProduct(BranchDescription const &productdesc)
void readEventHistoryTree()
Definition: RootFile.cc:1639
int forcedRunOffset_
Definition: RootFile.h:205
void fillAux(T *&pAux)
Definition: RootTree.h:90
void setEntryNumber(EntryNumber theEntryNumber)
Definition: RootTree.cc:155
void reportOpened(std::string const &inputType)
Definition: RootFile.cc:1101
roottree::EntryNumber EntryNumber
Definition: RootTree.h:59
bool current()
Definition: RootTree.h:81
boost::shared_ptr< LuminosityBlockPrincipal > readLumi(boost::shared_ptr< LuminosityBlockPrincipal > lbCache)
Definition: RootFile.cc:1553