CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RootOutputFile.cc
Go to the documentation of this file.
1 
3 
5 
6 
35 
36 #include "TTree.h"
37 #include "TFile.h"
38 #include "TClass.h"
39 #include "Rtypes.h"
40 #include "RVersion.h"
41 
42 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,30,0)
43 #include "Compression.h"
44 #endif
45 
46 #include <algorithm>
47 #include <iomanip>
48 #include <sstream>
49 
50 namespace edm {
51 
52  namespace {
53  bool
54  sorterForJobReportHash(BranchDescription const* lh, BranchDescription const* rh) {
55  return
56  lh->fullClassName() < rh->fullClassName() ? true :
57  lh->fullClassName() > rh->fullClassName() ? false :
58  lh->moduleLabel() < rh->moduleLabel() ? true :
59  lh->moduleLabel() > rh->moduleLabel() ? false :
60  lh->productInstanceName() < rh->productInstanceName() ? true :
61  lh->productInstanceName() > rh->productInstanceName() ? false :
62  lh->processName() < rh->processName() ? true :
63  false;
64  }
65  }
66 
68  file_(fileName),
69  logicalFile_(logicalFileName),
70  reportToken_(0),
71  om_(om),
72  whyNotFastClonable_(om_->whyNotFastClonable()),
73  canFastCloneAux_(false),
74  filePtr_(TFile::Open(file_.c_str(), "recreate", "", om_->compressionLevel())),
75  fid_(),
76  eventEntryNumber_(0LL),
77  lumiEntryNumber_(0LL),
78  runEntryNumber_(0LL),
79  indexIntoFile_(),
80  metaDataTree_(nullptr),
81  parameterSetsTree_(nullptr),
82  parentageTree_(nullptr),
83  lumiAux_(),
84  runAux_(),
85  pEventAux_(nullptr),
86  pLumiAux_(&lumiAux_),
87  pRunAux_(&runAux_),
88  eventEntryInfoVector_(),
89  pEventEntryInfoVector_(&eventEntryInfoVector_),
90  pBranchListIndexes_(nullptr),
91  pEventSelectionIDs_(nullptr),
92  eventTree_(filePtr_, InEvent, om_->splitLevel(), om_->treeMaxVirtualSize()),
93  lumiTree_(filePtr_, InLumi, om_->splitLevel(), om_->treeMaxVirtualSize()),
94  runTree_(filePtr_, InRun, om_->splitLevel(), om_->treeMaxVirtualSize()),
95  treePointers_(),
96  dataTypeReported_(false),
97  processHistoryRegistry_(),
98  parentageIDs_(),
99  branchesWithStoredHistory_(),
100  wrapperBaseTClass_(TClass::GetClass("edm::WrapperBase")) {
101 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,30,0)
102  if (om_->compressionAlgorithm() == std::string("ZLIB")) {
103  filePtr_->SetCompressionAlgorithm(ROOT::kZLIB);
104  } else if (om_->compressionAlgorithm() == std::string("LZMA")) {
105  filePtr_->SetCompressionAlgorithm(ROOT::kLZMA);
106  } else {
107  throw Exception(errors::Configuration) << "PoolOutputModule configured with unknown compression algorithm '" << om_->compressionAlgorithm() << "'\n"
108  << "Allowed compression algorithms are ZLIB and LZMA\n";
109  }
110 #endif
111  if (-1 != om->eventAutoFlushSize()) {
113  }
115  pEventAux_, om_->auxItems()[InEvent].basketSize_);
117  pEventEntryInfoVector_, om_->auxItems()[InEvent].basketSize_);
119  pEventSelectionIDs_, om_->auxItems()[InEvent].basketSize_,false);
121  pBranchListIndexes_, om_->auxItems()[InEvent].basketSize_);
122 
124  pLumiAux_, om_->auxItems()[InLumi].basketSize_);
125 
127  pRunAux_, om_->auxItems()[InRun].basketSize_);
128 
130  treePointers_[InLumi] = &lumiTree_;
131  treePointers_[InRun] = &runTree_;
132 
133  for(int i = InEvent; i < NumBranchTypes; ++i) {
134  BranchType branchType = static_cast<BranchType>(i);
135  RootOutputTree *theTree = treePointers_[branchType];
136  for(auto const& item : om_->selectedOutputItemList()[branchType]) {
137  item.product_ = nullptr;
138  BranchDescription const& desc = *item.branchDescription_;
139  theTree->addBranch(desc.branchName(),
140  desc.wrappedName(),
141  item.product_,
142  item.splitLevel_,
143  item.basketSize_,
144  item.branchDescription_->produced());
145  //make sure we always store product registry info for all branches we create
146  branchesWithStoredHistory_.insert(item.branchID());
147  }
148  }
149  // Don't split metadata tree or event description tree
153 
155 
156  // For the Job Report, get a vector of branch names in the "Events" tree.
157  // Also create a hash of all the branch names in the "Events" tree
158  // in a deterministic order, except use the full class name instead of the friendly class name.
159  // To avoid extra string copies, we create a vector of pointers into the product registry,
160  // and use a custom comparison operator for sorting.
161  std::vector<std::string> branchNames;
162  std::vector<BranchDescription const*> branches;
163  branchNames.reserve(om_->selectedOutputItemList()[InEvent].size());
164  branches.reserve(om->selectedOutputItemList()[InEvent].size());
165  for(auto const& item : om_->selectedOutputItemList()[InEvent]) {
166  branchNames.push_back(item.branchDescription_->branchName());
167  branches.push_back(item.branchDescription_);
168  }
169  // Now sort the branches for the hash.
170  sort_all(branches, sorterForJobReportHash);
171  // Now, make a concatenated string.
172  std::ostringstream oss;
173  char const underscore = '_';
174  for(auto const& branch : branches) {
175  BranchDescription const& bd = *branch;
176  oss << bd.fullClassName() << underscore
177  << bd.moduleLabel() << underscore
178  << bd.productInstanceName() << underscore
179  << bd.processName() << underscore;
180  }
181  std::string stringrep = oss.str();
182  cms::Digest md5alg(stringrep);
183 
184  // Register the output file with the JobReport service
185  // and get back the token for it.
186  std::string moduleName = "PoolOutputModule";
187  Service<JobReport> reportSvc;
188  reportToken_ = reportSvc->outputFileOpened(
189  file_, logicalFile_, // PFN and LFN
190  om_->catalog(), // catalog
191  moduleName, // module class name
192  om_->moduleLabel(), // module label
193  fid_.fid(), // file id (guid)
194  std::string(), // data type (not yet known, so string is empty).
195  md5alg.digest().toString(), // branch hash
196  branchNames); // branch names being written
197  }
198 
199  namespace {
200  void
201  maybeIssueWarning(int whyNotFastClonable, std::string const& ifileName, std::string const& ofileName) {
202 
203  // No message if fast cloning was deliberately disabled, or if there are no events to copy anyway.
204  if ((whyNotFastClonable &
206  return;
207  }
208 
209  // There will be a message stating every reason that fast cloning was not possible.
210  // If at one or more of the reasons was because of something the user explicitly specified (e.g. event selection, skipping events),
211  // or if the input file was in an old format, the message will be informational. Otherwise, the message will be a warning.
212  bool isWarning = true;
213  std::ostringstream message;
214  message << "Fast copying of file " << ifileName << " to file " << ofileName << " is disabled because:\n";
215  if((whyNotFastClonable & FileBlock::HasSecondaryFileSequence) != 0) {
216  message << "a SecondaryFileSequence was specified.\n";
217  whyNotFastClonable &= ~(FileBlock::HasSecondaryFileSequence);
218  isWarning = false;
219  }
220  if((whyNotFastClonable & FileBlock::FileTooOld) != 0) {
221  message << "the input file is in an old format.\n";
222  whyNotFastClonable &= ~(FileBlock::FileTooOld);
223  isWarning = false;
224  }
225  if((whyNotFastClonable & FileBlock::EventsToBeSorted) != 0) {
226  message << "events need to be sorted.\n";
227  whyNotFastClonable &= ~(FileBlock::EventsToBeSorted);
228  }
229  if((whyNotFastClonable & FileBlock::RunOrLumiNotContiguous) != 0) {
230  message << "a run or a lumi is not contiguous in the input file.\n";
231  whyNotFastClonable &= ~(FileBlock::RunOrLumiNotContiguous);
232  }
233  if((whyNotFastClonable & FileBlock::EventsOrLumisSelectedByID) != 0) {
234  message << "events or lumis were selected or skipped by ID.\n";
235  whyNotFastClonable &= ~(FileBlock::EventsOrLumisSelectedByID);
236  isWarning = false;
237  }
238  if((whyNotFastClonable & FileBlock::InitialEventsSkipped) != 0) {
239  message << "initial events, lumis or runs were skipped.\n";
240  whyNotFastClonable &= ~(FileBlock::InitialEventsSkipped);
241  isWarning = false;
242  }
243  if((whyNotFastClonable & FileBlock::DuplicateEventsRemoved) != 0) {
244  message << "some events were skipped because of duplicate checking.\n";
245  whyNotFastClonable &= ~(FileBlock::DuplicateEventsRemoved);
246  }
247  if((whyNotFastClonable & FileBlock::MaxEventsTooSmall) != 0) {
248  message << "some events were not copied because of maxEvents limit.\n";
249  whyNotFastClonable &= ~(FileBlock::MaxEventsTooSmall);
250  isWarning = false;
251  }
252  if((whyNotFastClonable & FileBlock::MaxLumisTooSmall) != 0) {
253  message << "some events were not copied because of maxLumis limit.\n";
254  whyNotFastClonable &= ~(FileBlock::MaxLumisTooSmall);
255  isWarning = false;
256  }
257  if((whyNotFastClonable & FileBlock::ParallelProcesses) != 0) {
258  message << "parallel processing was specified.\n";
259  whyNotFastClonable &= ~(FileBlock::ParallelProcesses);
260  isWarning = false;
261  }
262  if((whyNotFastClonable & FileBlock::EventSelectionUsed) != 0) {
263  message << "an EventSelector was specified.\n";
264  whyNotFastClonable &= ~(FileBlock::EventSelectionUsed);
265  isWarning = false;
266  }
267  if((whyNotFastClonable & FileBlock::OutputMaxEventsTooSmall) != 0) {
268  message << "some events were not copied because of maxEvents output limit.\n";
269  whyNotFastClonable &= ~(FileBlock::OutputMaxEventsTooSmall);
270  isWarning = false;
271  }
272  if((whyNotFastClonable & FileBlock::SplitLevelMismatch) != 0) {
273  message << "the split level or basket size of a branch or branches was modified.\n";
274  whyNotFastClonable &= ~(FileBlock::SplitLevelMismatch);
275  }
276  if((whyNotFastClonable & FileBlock::BranchMismatch) != 0) {
277  message << "The format of a data product has changed.\n";
278  whyNotFastClonable &= ~(FileBlock::BranchMismatch);
279  }
280  assert(whyNotFastClonable == FileBlock::CanFastClone);
281  if (isWarning) {
282  LogWarning("FastCloningDisabled") << message.str();
283  } else {
284  LogInfo("FastCloningDisabled") << message.str();
285  }
286  }
287  }
288 
289  void RootOutputFile::beginInputFile(FileBlock const& fb, int remainingEvents) {
290 
291  // Reset per input file information
293  canFastCloneAux_ = false;
294 
295  if(fb.tree() != nullptr) {
296 
298 
299  if(remainingEvents >= 0 && remainingEvents < fb.tree()->GetEntries()) {
301  }
302 
304  if(!match) {
306  // We may be fast copying. We must disable fast copying if the split levels
307  // or basket sizes do not match.
309  } else {
310  // We are using the input split levels and basket sizes from the first input file
311  // for copied output branches. In this case, we throw an exception if any branches
312  // have different split levels or basket sizes in a subsequent input file.
313  // If the mismatch is in the first file, there is a bug somewhere, so we assert.
314  assert(om_->inputFileCount() > 1);
315  throw Exception(errors::MismatchedInputFiles, "RootOutputFile::beginInputFile()") <<
316  "Merge failure because input file " << file_ << " has different ROOT split levels or basket sizes\n" <<
317  "than previous files. To allow merging in splite of this, use the configuration parameter\n" <<
318  "overrideInputFileSplitLevels=cms.untracked.bool(True)\n" <<
319  "in every PoolOutputModule.\n";
320  }
321  }
322 
323  // Since this check can be time consuming, we do it only if we would otherwise fast clone.
325  if(!eventTree_.checkIfFastClonable(fb.tree())) {
327  }
328  }
329  // We now check if we can fast copy the auxiliary branches.
330  // We can do so only if we can otherwise fast copy,
331  // the input file has the current format (these branches are in the Events Tree),
332  // there are no newly dropped or produced products,
333  // no metadata has been dropped,
334  // ID's have not been modified,
335  // and the branch list indexes do not need modification.
336 
337  // Note: Fast copy of the EventProductProvenance branch is unsafe
338  // unless we can enforce that the parentage information for a fully copied
339  // output file will be the same as for the input file, with nothing dropped.
340  // This has never been enforced, and, withthe EDAlias feature, it may no longer
341  // work by accident.
342  // So, for now, we do not enable fast cloning of the non-product branches.
343 /*
344  Service<ConstProductRegistry> reg;
345  canFastCloneAux_ = (whyNotFastClonable_ == FileBlock::CanFastClone) &&
346  fb.fileFormatVersion().noMetaDataTrees() &&
347  !om_->hasNewlyDroppedBranch()[InEvent] &&
348  !fb.hasNewlyDroppedBranch()[InEvent] &&
349  om_->dropMetaData() == PoolOutputModule::DropNone &&
350  !reg->anyProductProduced() &&
351  !fb.modifiedIDs() &&
352  fb.branchListIndexesUnchanged();
353 */
354 
355  // Report the fast copying status.
356  Service<JobReport> reportSvc;
357  reportSvc->reportFastCopyingStatus(reportToken_, fb.fileName(), whyNotFastClonable_ == FileBlock::CanFastClone);
358  } else {
360  }
361 
363 
364  // Possibly issue warning or informational message if we haven't fast cloned.
365  if(fb.tree() != nullptr && whyNotFastClonable_ != FileBlock::CanFastClone) {
366  maybeIssueWarning(whyNotFastClonable_, fb.fileName(), file_);
367  }
368  }
369 
374  }
375 
377  unsigned int const oneK = 1024;
378  Long64_t size = filePtr_->GetSize()/oneK;
379  return(size >= om_->maxFileSize());
380  }
381 
383  ModuleCallingContext const* mcc) {
384  // Auxiliary branch
385  pEventAux_ = &e.aux();
386 
387  // Because getting the data may cause an exception to be thrown we want to do that
388  // first before writing anything to the file about this event
389  // NOTE: pEventAux_, pBranchListIndexes_, pEventSelectionIDs_, and pEventEntryInfoVector_
390  // must be set before calling fillBranches since they get written out in that routine.
391  assert(pEventAux_->processHistoryID() == e.processHistoryID());
393 
394  // Note: The EventSelectionIDVector should have a one to one correspondence with the processes in the process history.
395  // Therefore, a new entry should be added if and only if the current process has been added to the process history,
396  // which is done if and only if there is a produced product.
399  if (reg->anyProductProduced() || !om_->wantAllEvents()) {
400  esids.push_back(om_->selectorConfig());
401  }
402  pEventSelectionIDs_ = &esids;
404 
405  // Add the dataType to the job report if it hasn't already been done
406  if(!dataTypeReported_) {
407  Service<JobReport> reportSvc;
408  std::string dataType("MC");
409  if(pEventAux_->isRealData()) dataType = "Data";
410  reportSvc->reportDataType(reportToken_, dataType);
411  dataTypeReported_ = true;
412  }
413 
414  // Store the process history.
416  // Store the reduced ID in the IndexIntoFile
418  // Add event to index
421 
422  // Report event written
423  Service<JobReport> reportSvc;
424  reportSvc->eventWrittenToFile(reportToken_, e.id().run(), e.id().event());
425  }
426 
428  // Auxiliary branch
429  // NOTE: lumiAux_ must be filled before calling fillBranches since it gets written out in that routine.
430  lumiAux_ = lb.aux();
431  // Use the updated process historyID
433  // Store the process history.
435  // Store the reduced ID in the IndexIntoFile
437  // Add lumi to index.
440  fillBranches(InLumi, lb, nullptr, mcc);
441  lumiTree_.optimizeBaskets(10ULL*1024*1024);
442 
443  Service<JobReport> reportSvc;
444  reportSvc->reportLumiSection(reportToken_, lb.id().run(), lb.id().luminosityBlock());
445  }
446 
448  // Auxiliary branch
449  // NOTE: runAux_ must be filled before calling fillBranches since it gets written out in that routine.
450  runAux_ = r.aux();
451  // Use the updated process historyID
453  // Store the process history.
455  // Store the reduced ID in the IndexIntoFile
457  // Add run to index.
458  indexIntoFile_.addEntry(reducedPHID, runAux_.run(), 0U, 0U, runEntryNumber_);
459  ++runEntryNumber_;
460  fillBranches(InRun, r, nullptr, mcc);
461  runTree_.optimizeBaskets(10ULL*1024*1024);
462 
463  Service<JobReport> reportSvc;
464  reportSvc->reportRunNumber(reportToken_, r.run());
465  }
466 
468  Parentage const* desc(nullptr);
469 
470  if(!parentageTree_->Branch(poolNames::parentageBranchName().c_str(),
471  &desc, om_->basketSize(), 0))
473  << "Failed to create a branch for Parentages in the output file";
474 
476 
477  std::vector<ParentageID> orderedIDs(parentageIDs_.size());
478  for(auto const& parentageID : parentageIDs_) {
479  orderedIDs[parentageID.second] = parentageID.first;
480  }
481  //now put them into the TTree in the correct order
482  for(auto const& orderedID : orderedIDs) {
483  desc = ptReg.getMapped(orderedID);
484  //NOTE: some old format files have missing Parentage info
485  // so a null value of desc can't be fatal.
486  // Root will default construct an object in that case.
487  parentageTree_->Fill();
488  }
489  }
490 
492  FileFormatVersion fileFormatVersion(getFileFormatVersion());
493  FileFormatVersion* pFileFmtVsn = &fileFormatVersion;
494  TBranch* b = metaDataTree_->Branch(poolNames::fileFormatVersionBranchName().c_str(), &pFileFmtVsn, om_->basketSize(), 0);
495  assert(b);
496  b->Fill();
497  }
498 
500  FileID* fidPtr = &fid_;
501  TBranch* b = metaDataTree_->Branch(poolNames::fileIdentifierBranchName().c_str(), &fidPtr, om_->basketSize(), 0);
502  assert(b);
503  b->Fill();
504  }
505 
509  ex << "The number of entries in at least one output TBranch whose entries\n"
510  "were copied from the input does not match the number of events\n"
511  "recorded in IndexIntoFile. This might (or might not) indicate a\n"
512  "problem related to fast copy.";
513  ex.addContext("Calling RootOutputFile::writeIndexIntoFile");
514  throw ex;
515  }
517  IndexIntoFile* iifPtr = &indexIntoFile_;
518  TBranch* b = metaDataTree_->Branch(poolNames::indexIntoFileBranchName().c_str(), &iifPtr, om_->basketSize(), 0);
519  assert(b);
520  b->Fill();
521  }
522 
524  ProcessHistoryVector procHistoryVector;
525  for(auto const& ph : processHistoryRegistry_) {
526  procHistoryVector.push_back(ph.second);
527  }
528  ProcessHistoryVector* p = &procHistoryVector;
529  TBranch* b = metaDataTree_->Branch(poolNames::processHistoryBranchName().c_str(), &p, om_->basketSize(), 0);
530  assert(b);
531  b->Fill();
532  }
533 
535  BranchIDLists const* p = om_->branchIDLists();
536  TBranch* b = metaDataTree_->Branch(poolNames::branchIDListBranchName().c_str(), &p, om_->basketSize(), 0);
537  assert(b);
538  b->Fill();
539  }
540 
543  TBranch* b = metaDataTree_->Branch(poolNames::thinnedAssociationsHelperBranchName().c_str(), &p, om_->basketSize(), 0);
544  assert(b);
545  b->Fill();
546  }
547 
549  std::pair<ParameterSetID, ParameterSetBlob> idToBlob;
550  std::pair<ParameterSetID, ParameterSetBlob>* pIdToBlob = &idToBlob;
551  TBranch* b = parameterSetsTree_->Branch(poolNames::idToParameterSetBlobsBranchName().c_str(),&pIdToBlob,om_->basketSize(), 0);
552 
553  for(auto const& pset : *pset::Registry::instance()) {
554  idToBlob.first = pset.first;
555  idToBlob.second.pset() = pset.second.toString();
556 
557  b->Fill();
558  }
559  }
560 
562  // Make a local copy of the ProductRegistry, removing any transient or pruned products.
563  typedef ProductRegistry::ProductList ProductList;
565  ProductRegistry pReg(reg->productList());
566  ProductList& pList = const_cast<ProductList &>(pReg.productList());
567  for(auto const& prod : pList) {
568  if(prod.second.branchID() != prod.second.originalBranchID()) {
569  if(branchesWithStoredHistory_.find(prod.second.branchID()) != branchesWithStoredHistory_.end()) {
570  branchesWithStoredHistory_.insert(prod.second.originalBranchID());
571  }
572  }
573  }
574  std::set<BranchID>::iterator end = branchesWithStoredHistory_.end();
575  for(ProductList::iterator it = pList.begin(); it != pList.end();) {
576  if(branchesWithStoredHistory_.find(it->second.branchID()) == end) {
577  // avoid invalidating iterator on deletion
578  ProductList::iterator itCopy = it;
579  ++it;
580  pList.erase(itCopy);
581 
582  } else {
583  ++it;
584  }
585  }
586 
587  ProductRegistry* ppReg = &pReg;
588  TBranch* b = metaDataTree_->Branch(poolNames::productDescriptionBranchName().c_str(), &ppReg, om_->basketSize(), 0);
589  assert(b);
590  b->Fill();
591  }
593  BranchChildren& pDeps = const_cast<BranchChildren&>(om_->branchChildren());
594  BranchChildren* ppDeps = &pDeps;
595  TBranch* b = metaDataTree_->Branch(poolNames::productDependenciesBranchName().c_str(), &ppDeps, om_->basketSize(), 0);
596  assert(b);
597  b->Fill();
598  }
599 
601  metaDataTree_->SetEntries(-1);
604 
606 
607  // Create branch aliases for all the branches in the
608  // events/lumis/runs trees. The loop is over all types of data
609  // products.
610  for(int i = InEvent; i < NumBranchTypes; ++i) {
611  BranchType branchType = static_cast<BranchType>(i);
613  treePointers_[branchType]->writeTree();
614  }
615 
616  // close the file -- mfp
617  // Just to play it safe, zero all pointers to objects in the TFile to be closed.
618  metaDataTree_ = parentageTree_ = nullptr;
619  for(auto& treePointer : treePointers_) {
620  treePointer->close();
621  treePointer = nullptr;
622  }
623  filePtr_->Close();
624  filePtr_.reset();
625 
626  // report that file has been closed
627  Service<JobReport> reportSvc;
628  reportSvc->outputFileClosed(reportToken_);
629 
630  }
631 
632  void
633  RootOutputFile::setBranchAliases(TTree* tree, SelectedProducts const& branches) const {
634  if(tree && tree->GetNbranches() != 0) {
635  for(auto const& selection : branches) {
636  BranchDescription const& pd = *selection;
637  std::string const& full = pd.branchName() + "obj";
638  if(pd.branchAliases().empty()) {
639  std::string const& alias =
640  (pd.productInstanceName().empty() ? pd.moduleLabel() : pd.productInstanceName());
641  tree->SetAlias(alias.c_str(), full.c_str());
642  } else {
643  for(auto const& alias : pd.branchAliases()) {
644  tree->SetAlias(alias.c_str(), full.c_str());
645  }
646  }
647  }
648  }
649  }
650 
651  void
653  EventPrincipal const& principal,
654  bool produced,
655  std::set<StoredProductProvenance>& oToFill,
656  ModuleCallingContext const* mcc) {
658  assert(produced || om_->dropMetaData() != PoolOutputModule::DropPrior);
660  ProductProvenanceRetriever const& iMapper = *principal.productProvenanceRetrieverPtr();
661  std::vector<BranchID> const& parentIDs = iGetParents.parentage().parents();
662  for(auto const& parentID : parentIDs) {
663  branchesWithStoredHistory_.insert(parentID);
664  ProductProvenance const* info = iMapper.branchIDToProvenance(parentID);
665  if(info) {
667  principal.getProvenance(info->branchID(), mcc).product().produced()) {
668  if(insertProductProvenance(*info,oToFill) ) {
669  //haven't seen this one yet
670  insertAncestors(*info, principal, produced, oToFill, mcc);
671  }
672  }
673  }
674  }
675  }
676 
678  BranchType const& branchType,
679  Principal const& principal,
680  StoredProductProvenanceVector* productProvenanceVecPtr,
681  ModuleCallingContext const* mcc) {
682 
683  std::vector<std::unique_ptr<WrapperBase> > dummies;
684 
685  bool const fastCloning = (branchType == InEvent) && (whyNotFastClonable_ == FileBlock::CanFastClone);
686 
688 
689  std::set<StoredProductProvenance> provenanceToKeep;
690 
691  // Loop over EDProduct branches, fill the provenance, and write the branch.
692  for(auto const& item : items) {
693 
694  BranchID const& id = item.branchDescription_->branchID();
695  branchesWithStoredHistory_.insert(id);
696 
697  bool produced = item.branchDescription_->produced();
698  bool keepProvenance = productProvenanceVecPtr != nullptr &&
702  bool getProd = (produced || !fastCloning ||
703  treePointers_[branchType]->uncloned(item.branchDescription_->branchName()));
704 
705  WrapperBase const* product = nullptr;
706  OutputHandle const oh = principal.getForOutput(id, getProd, mcc);
707  if(keepProvenance && oh.productProvenance()) {
708  insertProductProvenance(*oh.productProvenance(),provenanceToKeep);
709  //provenanceToKeep.insert(*oh.productProvenance());
710  EventPrincipal const& eventPrincipal = dynamic_cast<EventPrincipal const&>(principal);
711  assert(eventPrincipal.productProvenanceRetrieverPtr());
712  insertAncestors(*oh.productProvenance(), eventPrincipal, produced, provenanceToKeep, mcc);
713  }
714  product = oh.wrapper();
715  if(getProd) {
716  if(product == nullptr) {
717  // No product with this ID is in the event.
718  // Add a null product.
719  TClass* cp = TClass::GetClass(item.branchDescription_->wrappedName().c_str());
720  int offset = cp->GetBaseClassOffset(wrapperBaseTClass_);
721  void* p = cp->New();
722  std::unique_ptr<WrapperBase> dummy = getWrapperBasePtr(p, offset);
723  product = dummy.get();
724  dummies.emplace_back(std::move(dummy));
725  }
726  item.product_ = product;
727  }
728  }
729 
730  if(productProvenanceVecPtr != nullptr) productProvenanceVecPtr->assign(provenanceToKeep.begin(), provenanceToKeep.end());
731  treePointers_[branchType]->fillTree();
732  if(productProvenanceVecPtr != nullptr) productProvenanceVecPtr->clear();
733  }
734 
735  bool
737  std::set<edm::StoredProductProvenance>& oToInsert) {
738  StoredProductProvenance toStore;
739  toStore.branchID_ = iProv.branchID().id();
740  std::set<edm::StoredProductProvenance>::iterator itFound = oToInsert.find(toStore);
741  if(itFound == oToInsert.end()) {
742  //get the index to the ParentageID or insert a new value if not already present
743  std::pair<std::map<edm::ParentageID,unsigned int>::iterator,bool> i = parentageIDs_.insert(std::make_pair(iProv.parentageID(),static_cast<unsigned int>(parentageIDs_.size())));
744  toStore.parentageIDIndex_ = i.first->second;
745  if(toStore.parentageIDIndex_ >= parentageIDs_.size()) {
747  << "RootOutputFile::insertProductProvenance\n"
748  << "The parentage ID index value " << toStore.parentageIDIndex_ << " is out of bounds. The maximum value is currently " << parentageIDs_.size()-1 << ".\n"
749  << "This should never happen.\n"
750  << "Please report this to the framework hypernews forum 'hn-cms-edmFramework@cern.ch'.\n";
751  }
752 
753  oToInsert.insert(toStore);
754  return true;
755  }
756  return false;
757  }
758 }
BranchIDLists const * branchIDLists() const
RunNumber_t run() const
Definition: EventID.h:39
std::vector< ProcessHistory > ProcessHistoryVector
EventNumber_t event() const
Definition: EventID.h:41
void fillBranches(BranchType const &branchType, Principal const &principal, StoredProductProvenanceVector *productProvenanceVecPtr, ModuleCallingContext const *)
std::string const & idToParameterSetBlobsBranchName()
Definition: BranchType.cc:255
int i
Definition: DBlmapReader.cc:9
std::string const & branchName() const
bool isRealData() const
void beginInputFile(FileBlock const &fb, int remainingEvents)
BranchID const & branchID() const
LuminosityBlockAuxiliary lumiAux_
std::string const & BranchTypeToAuxiliaryBranchName(BranchType const &branchType)
Definition: BranchType.cc:115
int const & basketSize() const
static const TGPicture * info(bool iBackgroundIsBlack)
WrapperBase const * wrapper() const
Definition: OutputHandle.h:89
std::shared_ptr< TFile > filePtr_
EventSelectionIDVector const & eventSelectionIDs() const
bool const & overrideInputFileSplitLevels() const
std::string const & parentageTreeName()
Definition: BranchType.cc:159
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
int eventAutoFlushSize() const
std::string const & catalog() const
ThinnedAssociationsHelper const * thinnedAssociationsHelper() const
void writeProcessHistoryRegistry()
std::string const & moduleLabel() const
void writeRun(RunPrincipal const &r, ModuleCallingContext const *)
DropMetaData const & dropMetaData() const
std::map< BranchKey, BranchDescription > ProductList
bool checkSplitLevelsAndBasketSizes(TTree *inputTree) const
bool registerProcessHistory(ProcessHistory const &processHistory)
selection
main part
Definition: corrVsCorr.py:98
void writeOne(EventPrincipal const &e, ModuleCallingContext const *)
EventID const & id() const
Provenance getProvenance(ProductID const &pid, ModuleCallingContext const *mcc) const
ProductProvenance const * productProvenance() const
Definition: OutputHandle.h:97
int whyNotFastClonable() const
Definition: FileBlock.h:104
RunNumber_t run() const
LuminosityBlockAuxiliary const & aux() const
std::string const & fileFormatVersionBranchName()
Definition: BranchType.cc:218
OutputItemListArray const & selectedOutputItemList() const
ProcessHistoryRegistry processHistoryRegistry_
std::string const & processName() const
std::string const & eventSelectionsBranchName()
Definition: BranchType.cc:243
RunNumber_t run() const
Definition: RunPrincipal.h:61
bool int lh
Definition: SIMDVec.h:19
unsigned int const & maxFileSize() const
MD5Result digest() const
Definition: Digest.cc:194
void setAutoFlush(Long64_t size)
#define nullptr
ParameterSetID selectorConfig() const
BranchListIndexes const & branchListIndexes() const
bool shouldWeCloseFile() const
unsigned int id() const
Definition: BranchID.h:23
bool checkIfFastClonable(TTree *inputTree) const
ProcessHistory const & processHistory() const
Definition: Principal.h:137
BranchType
Definition: BranchType.h:11
std::set< BranchID > branchesWithStoredHistory_
std::vector< EventSelectionID > EventSelectionIDVector
void sortVector_Run_Or_Lumi_Entries()
LuminosityBlockNumber_t luminosityBlock() const
std::string const & parameterSetsTreeName()
Definition: BranchType.cc:251
std::vector< BranchID > const & parents() const
Definition: Parentage.h:37
void writeThinnedAssociationsHelper()
std::map< ParentageID, unsigned int > parentageIDs_
RootOutputTree eventTree_
std::vector< BranchListIndex > BranchListIndexes
std::string moduleName(Provenance const &provenance)
Definition: Provenance.cc:27
bool getMapped(key_type const &k, value_type &result) const
void addBranch(std::string const &branchName, std::string const &className, void const *&pProd, int splitLevel, int basketSize, bool produced)
PoolOutputModule const * om_
std::string const & compressionAlgorithm() const
std::string const & moduleLabel() const
IndexIntoFile::EntryNumber_t eventEntryNumber_
std::string const & productInstanceName() const
ProcessHistoryID const & processHistoryID() const
Definition: Principal.h:141
std::shared_ptr< ProductProvenanceRetriever > productProvenanceRetrieverPtr() const
void insertAncestors(ProductProvenance const &iGetParents, EventPrincipal const &principal, bool produced, std::set< StoredProductProvenance > &oToFill, ModuleCallingContext const *)
LuminosityBlockAuxiliary const * pLumiAux_
std::string const & indexIntoFileBranchName()
Definition: BranchType.cc:233
std::string const & basketOrder() const
Definition: GenABIO.cc:180
RunNumber_t run() const
int getFileFormatVersion()
std::string logicalFile_
SelectedProductsForBranchType const & keptProducts() const
bool checkEntriesInReadBranches(Long64_t expectedNumberOfEntries) const
RunAuxiliary const & aux() const
Definition: RunPrincipal.h:57
ProcessHistoryID const & reducedProcessHistoryID(ProcessHistoryID const &fullID) const
void setProcessHistoryID(ProcessHistoryID const &phid)
#define end
Definition: vmac.h:37
std::string const & metaDataTreeName()
Definition: BranchType.cc:168
PoolOutputModule::OutputItemList OutputItemList
unsigned int offset(bool)
LuminosityBlockNumber_t luminosityBlock() const
void addEntry(ProcessHistoryID const &processHistoryID, RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event, EntryNumber_t entry)
static TTree * makeTTree(TFile *filePtr, std::string const &name, int splitLevel)
int const & whyNotFastClonable() const
std::string const & fullClassName() const
std::string const & processHistoryBranchName()
Definition: BranchType.cc:198
EventSelectionIDVector const * pEventSelectionIDs_
StoredProductProvenanceVector * pEventEntryInfoVector_
OutputHandle getForOutput(BranchID const &bid, bool getProd, ModuleCallingContext const *mcc) const
Definition: Principal.cc:716
eventsetup::produce::Produce produced
Definition: ESProducts.cc:20
void sort_all(RandomAccessSequence &s)
wrappers for std::sort
Definition: Algorithms.h:120
BranchChildren const & branchChildren() const
void setBranchAliases(TTree *tree, SelectedProducts const &branches) const
RootOutputTree runTree_
std::string toString() const
Definition: Digest.cc:87
std::string const & parentageBranchName()
Definition: BranchType.cc:163
double b
Definition: hdecay.h:120
LuminosityBlockNumber_t luminosityBlock() const
string const
Definition: compareJSON.py:14
void addContext(std::string const &context)
Definition: Exception.cc:227
AuxItemArray const & auxItems() const
std::set< std::string > const & branchAliases() const
bool insertProductProvenance(const ProductProvenance &, std::set< StoredProductProvenance > &oToInsert)
void addAuxiliary(std::string const &branchName, T const *&pAux, int bufSize, bool allowCloning=true)
std::vector< StoredProductProvenance > StoredProductProvenanceVector
void respondToCloseInputFile(FileBlock const &fb)
IndexIntoFile indexIntoFile_
std::string const & productDescriptionBranchName()
Definition: BranchType.cc:173
IndexIntoFile::EntryNumber_t runEntryNumber_
ParentageID const & parentageID() const
static void writeTTree(TTree *tree)
ProcessHistoryID const & processHistoryID() const
EventAuxiliary const * pEventAux_
RunAuxiliary runAux_
std::vector< BranchDescription const * > SelectedProducts
ProductProvenance const * branchIDToProvenance(BranchID const &bid) const
void writeProductDescriptionRegistry()
std::string const & BranchTypeToProductProvenanceBranchName(BranchType const &BranchType)
Definition: BranchType.cc:131
std::string const & productDependenciesBranchName()
Definition: BranchType.cc:178
RootOutputFile(PoolOutputModule *om, std::string const &fileName, std::string const &logicalFileName)
std::string const & thinnedAssociationsHelperBranchName()
Definition: BranchType.cc:213
std::unique_ptr< WrapperBase > getWrapperBasePtr(void *p, int offset)
std::string const & branchIDListBranchName()
Definition: BranchType.cc:208
void setProcessHistoryID(ProcessHistoryID const &phid)
Definition: RunAuxiliary.h:36
std::string const & branchListIndexesBranchName()
Definition: BranchType.cc:247
Parentage const & parentage() const
RootOutputTreePtrArray treePointers_
volatile std::atomic< bool > shutdown_flag false
BranchListIndexes const * pBranchListIndexes_
void writeLuminosityBlock(LuminosityBlockPrincipal const &lb, ModuleCallingContext const *)
void maybeFastCloneTree(bool canFastClone, bool canFastCloneAux, TTree *tree, std::string const &option)
static ParentageRegistry * instance()
IndexIntoFile::EntryNumber_t lumiEntryNumber_
RootOutputTree lumiTree_
void optimizeBaskets(ULong64_t size)
EventAuxiliary const & aux() const
TTree * tree() const
Definition: FileBlock.h:97
std::string const & fileIdentifierBranchName()
Definition: BranchType.cc:223
RunAuxiliary const * pRunAux_
std::string const & wrappedName() const
tuple size
Write out results.
EventNumber_t event() const
RunNumber_t run() const
Definition: RunAuxiliary.h:41
int const & inputFileCount() const
static Registry * instance()
Definition: Registry.cc:16
JobReport::Token reportToken_
std::string createGlobalIdentifier()
std::string const & fileName() const
Definition: FileBlock.h:106
std::string match(BranchDescription const &a, BranchDescription const &b, std::string const &fileName)