CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
ProvenanceDumper Class Reference

Public Member Functions

void dump ()
 
int exitCode () const
 
ProvenanceDumperoperator= (ProvenanceDumper const &)=delete
 
void printErrors (std::ostream &os)
 
 ProvenanceDumper (std::string const &filename, bool showDependencies, bool extendedAncestors, bool extendedDescendants, bool excludeESModules, bool showAllModules, bool showTopLevelPSets, std::vector< std::string > const &findMatch, bool dontPrintProducts, std::string const &dumpPSetID, int productIDEntry)
 
 ProvenanceDumper (ProvenanceDumper const &)=delete
 

Private Member Functions

void addAncestors (edm::BranchID const &branchID, std::set< edm::BranchID > &ancestorBranchIDs, std::ostringstream &sout, std::map< edm::BranchID, std::set< edm::ParentageID >> &perProductParentage) const
 
void addDescendants (edm::BranchID const &branchID, std::set< edm::BranchID > &descendantBranchIDs, std::ostringstream &sout, std::map< edm::BranchID, std::set< edm::BranchID >> &parentToChildren) const
 
void dumpEventFilteringParameterSets (edm::EventSelectionIDVector const &ids)
 
void dumpEventFilteringParameterSets_ (TFile *file)
 
void dumpParameterSetForID_ (edm::ParameterSetID const &id)
 
void dumpProcessHistory_ ()
 
std::optional< std::tuple< edm::BranchIDListHelper, std::vector< edm::ProcessIndex > > > makeBranchIDListHelper ()
 
void work_ ()
 

Private Attributes

bool dontPrintProducts_
 
std::string dumpPSetID_
 
int errorCount_
 
std::stringstream errorLog_
 
bool excludeESModules_
 
int exitCode_
 
bool extendedAncestors_
 
bool extendedDescendants_
 
std::string filename_
 
std::vector< std::string > findMatch_
 
HistoryNode historyGraph_
 
edm::propagate_const< std::unique_ptr< TFile > > inputFile_
 
edm::ProcessConfigurationVector phc_
 
edm::ProcessHistoryVector phv_
 
int const productIDEntry_
 
bool productRegistryPresent_
 
ParameterSetMap psm_
 
edm::ProductRegistry reg_
 
bool showDependencies_
 
bool showOtherModules_
 
bool showTopLevelPSets_
 

Detailed Description

Definition at line 434 of file EdmProvDump.cc.

Constructor & Destructor Documentation

◆ ProvenanceDumper() [1/2]

ProvenanceDumper::ProvenanceDumper ( std::string const &  filename,
bool  showDependencies,
bool  extendedAncestors,
bool  extendedDescendants,
bool  excludeESModules,
bool  showAllModules,
bool  showTopLevelPSets,
std::vector< std::string > const &  findMatch,
bool  dontPrintProducts,
std::string const &  dumpPSetID,
int  productIDEntry 
)

Definition at line 499 of file EdmProvDump.cc.

510  : filename_(filename),
511  inputFile_(makeTFile(filename)),
512  exitCode_(0),
513  errorLog_(),
514  errorCount_(0),
515  showDependencies_(showDependencies),
516  extendedAncestors_(extendedAncestors),
517  extendedDescendants_(extendedDescendants),
518  excludeESModules_(excludeESModules),
519  showOtherModules_(showOtherModules),
521  showTopLevelPSets_(showTopLevelPSets),
522  findMatch_(findMatch),
523  dontPrintProducts_(dontPrintProducts),
524  dumpPSetID_(dumpPSetID),
525  productIDEntry_(productIDEntry) {}
std::stringstream errorLog_
Definition: EdmProvDump.cc:472
std::string dumpPSetID_
Definition: EdmProvDump.cc:488
bool productRegistryPresent_
Definition: EdmProvDump.cc:484
edm::propagate_const< std::unique_ptr< TFile > > inputFile_
Definition: EdmProvDump.cc:470
int const productIDEntry_
Definition: EdmProvDump.cc:489
std::string filename_
Definition: EdmProvDump.cc:469
std::vector< std::string > findMatch_
Definition: EdmProvDump.cc:486

◆ ProvenanceDumper() [2/2]

ProvenanceDumper::ProvenanceDumper ( ProvenanceDumper const &  )
delete

Member Function Documentation

◆ addAncestors()

void ProvenanceDumper::addAncestors ( edm::BranchID const &  branchID,
std::set< edm::BranchID > &  ancestorBranchIDs,
std::ostringstream &  sout,
std::map< edm::BranchID, std::set< edm::ParentageID >> &  perProductParentage 
) const
private

Definition at line 1076 of file EdmProvDump.cc.

References MicroEventContent_cff::branch, edm::ParentageRegistry::getMapped(), edm::ParentageRegistry::instance(), and edm::Parentage::parents().

Referenced by work_().

1079  {
1081 
1082  std::set<edm::ParentageID> const& parentIDs = perProductParentage[branchID];
1083  for (auto const& parentageID : parentIDs) {
1084  edm::Parentage const* parentage = registry.getMapped(parentageID);
1085  if (nullptr != parentage) {
1086  for (auto const& branch : parentage->parents()) {
1087  if (ancestorBranchIDs.insert(branch).second) {
1088  addAncestors(branch, ancestorBranchIDs, sout, perProductParentage);
1089  }
1090  }
1091  } else {
1092  sout << " ERROR:parentage info not in registry ParentageID=" << parentageID << std::endl;
1093  }
1094  }
1095 }
std::vector< BranchID > const & parents() const
Definition: Parentage.h:44
bool getMapped(key_type const &k, value_type &result) const
static ParentageRegistry * instance()
void addAncestors(edm::BranchID const &branchID, std::set< edm::BranchID > &ancestorBranchIDs, std::ostringstream &sout, std::map< edm::BranchID, std::set< edm::ParentageID >> &perProductParentage) const

◆ addDescendants()

void ProvenanceDumper::addDescendants ( edm::BranchID const &  branchID,
std::set< edm::BranchID > &  descendantBranchIDs,
std::ostringstream &  sout,
std::map< edm::BranchID, std::set< edm::BranchID >> &  parentToChildren 
) const
private

Definition at line 1097 of file EdmProvDump.cc.

Referenced by work_().

1100  {
1101  for (auto const& childBranchID : parentToChildren[branchID]) {
1102  if (descendantBranchIDs.insert(childBranchID).second) {
1103  addDescendants(childBranchID, descendantBranchIDs, sout, parentToChildren);
1104  }
1105  }
1106 }
void addDescendants(edm::BranchID const &branchID, std::set< edm::BranchID > &descendantBranchIDs, std::ostringstream &sout, std::map< edm::BranchID, std::set< edm::BranchID >> &parentToChildren) const

◆ dump()

void ProvenanceDumper::dump ( void  )

Definition at line 527 of file EdmProvDump.cc.

References work_().

Referenced by main().

527 { work_(); }

◆ dumpEventFilteringParameterSets()

void ProvenanceDumper::dumpEventFilteringParameterSets ( edm::EventSelectionIDVector const &  ids)
private

Definition at line 536 of file EdmProvDump.cc.

References gather_cfg::cout, dumpParameterSetForID_(), and mps_fire::i.

Referenced by dumpEventFilteringParameterSets_().

536  {
537  edm::EventSelectionIDVector::size_type num_ids = ids.size();
538  if (num_ids == 0) {
539  std::cout << "No event filtering information is available.\n";
540  std::cout << "------------------------------\n";
541  } else {
542  std::cout << "Event filtering information for " << num_ids << " processing steps is available.\n"
543  << "The ParameterSets will be printed out, "
544  << "with the oldest printed first.\n";
545  for (edm::EventSelectionIDVector::size_type i = 0; i != num_ids; ++i) {
547  }
548  }
549 }
void dumpParameterSetForID_(edm::ParameterSetID const &id)
Definition: EdmProvDump.cc:580
uint16_t size_type

◆ dumpEventFilteringParameterSets_()

void ProvenanceDumper::dumpEventFilteringParameterSets_ ( TFile *  file)
private

Definition at line 551 of file EdmProvDump.cc.

References cms::cuda::assert(), gather_cfg::cout, dumpEventFilteringParameterSets(), edm::poolNames::eventHistoryBranchName(), edm::poolNames::eventHistoryTreeName(), events, edm::poolNames::eventSelectionsBranchName(), edm::poolNames::eventTreeName(), geometryDiff::file, and h.

Referenced by work_().

551  {
552  TTree* history = dynamic_cast<TTree*>(file->Get(edm::poolNames::eventHistoryTreeName().c_str()));
553  if (history != nullptr) {
554  edm::History h;
555  edm::History* ph = &h;
556 
557  history->SetBranchAddress(edm::poolNames::eventHistoryBranchName().c_str(), &ph);
558  if (history->GetEntry(0) <= 0) {
559  std::cout << "No event filtering information is available; the event history tree has no entries\n";
560  } else {
561  dumpEventFilteringParameterSets(h.eventSelectionIDs());
562  }
563  } else {
564  TTree* events = dynamic_cast<TTree*>(file->Get(edm::poolNames::eventTreeName().c_str()));
565  assert(events != nullptr);
566  TBranch* eventSelectionsBranch = events->GetBranch(edm::poolNames::eventSelectionsBranchName().c_str());
567  if (eventSelectionsBranch == nullptr)
568  return;
570  edm::EventSelectionIDVector* pids = &ids;
571  eventSelectionsBranch->SetAddress(&pids);
572  if (eventSelectionsBranch->GetEntry(0) <= 0) {
573  std::cout << "No event filtering information is available; the event selections branch has no entries\n";
574  } else {
576  }
577  }
578 }
assert(be >=bs)
std::vector< EventSelectionID > EventSelectionIDVector
void dumpEventFilteringParameterSets(edm::EventSelectionIDVector const &ids)
Definition: EdmProvDump.cc:536
std::string const & eventHistoryTreeName()
Definition: BranchType.cc:224
std::string const & eventSelectionsBranchName()
Definition: BranchType.cc:210
std::string const & eventHistoryBranchName()
Definition: BranchType.cc:207
std::string const & eventTreeName()
Definition: BranchType.cc:220
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
int events

◆ dumpParameterSetForID_()

void ProvenanceDumper::dumpParameterSetForID_ ( edm::ParameterSetID const &  id)
private

Definition at line 580 of file EdmProvDump.cc.

References gather_cfg::cout, relativeConstraints::empty, mps_fire::i, sistrip::SpyUtilities::isValid(), prettyPrint(), and psm_.

Referenced by dumpEventFilteringParameterSets(), and work_().

580  {
581  std::cout << "ParameterSetID: " << id << '\n';
582  if (id.isValid()) {
583  ParameterSetMap::const_iterator i = psm_.find(id);
584  if (i == psm_.end()) {
585  std::cout << "We are unable to find the corresponding ParameterSet\n";
587  empty.registerIt();
588  if (id == empty.id()) {
589  std::cout << "But it would have been empty anyway\n";
590  }
591  } else {
592  edm::ParameterSet ps(i->second.pset());
593  prettyPrint(std::cout, ps, " ", " ");
594  std::cout << '\n';
595  }
596  } else {
597  std::cout << "This ID is not valid\n";
598  }
599  std::cout << " -------------------------\n";
600 }
const bool isValid(const Frame &aFrame, const FrameQuality &aQuality, const uint16_t aExpectedPos)
ParameterSetMap psm_
Definition: EdmProvDump.cc:477
static std::ostream & prettyPrint(std::ostream &oStream, edm::ParameterSet const &iPSet, std::string const &iIndent, std::string const &iIndentDelta)
Definition: EdmProvDump.cc:404

◆ dumpProcessHistory_()

void ProvenanceDumper::dumpProcessHistory_ ( )
private

Definition at line 602 of file EdmProvDump.cc.

References submitPVValidationJobs::child, gather_cfg::cout, historyGraph_, l1ctLayer2EG_cff::id, class-composition::parent, and phv_.

Referenced by work_().

602  {
603  std::cout << "Processing History:" << std::endl;
604  std::map<edm::ProcessConfigurationID, unsigned int> simpleIDs;
605  for (auto const& ph : phv_) {
606  //loop over the history entries looking for matches
607  HistoryNode* parent = &historyGraph_;
608  for (auto const& pc : ph) {
609  if (parent->size() == 0) {
610  unsigned int id = simpleIDs[pc.id()];
611  if (0 == id) {
612  id = 1;
613  simpleIDs[pc.id()] = id;
614  }
615  parent->addChild(HistoryNode(pc, id));
616  parent = parent->lastChildAddress();
617  } else {
618  //see if this is unique
619  bool isUnique = true;
620  for (auto& child : *parent) {
621  if (child.configurationID() == pc.id()) {
622  isUnique = false;
623  parent = &child;
624  break;
625  }
626  }
627  if (isUnique) {
628  simpleIDs[pc.id()] = parent->size() + 1;
629  parent->addChild(HistoryNode(pc, simpleIDs[pc.id()]));
630  parent = parent->lastChildAddress();
631  }
632  }
633  }
634  }
635  historyGraph_.printHistory();
636 }
HistoryNode historyGraph_
Definition: EdmProvDump.cc:478
edm::ProcessHistoryVector phv_
Definition: EdmProvDump.cc:476

◆ exitCode()

int ProvenanceDumper::exitCode ( ) const

Definition at line 534 of file EdmProvDump.cc.

References exitCode_.

Referenced by main().

534 { return exitCode_; }

◆ makeBranchIDListHelper()

std::optional< std::tuple< edm::BranchIDListHelper, std::vector< edm::ProcessIndex > > > ProvenanceDumper::makeBranchIDListHelper ( )
private

Definition at line 639 of file EdmProvDump.cc.

References cms::cuda::assert(), edm::poolNames::branchIDListBranchName(), edm::poolNames::branchListIndexesBranchName(), events, edm::poolNames::eventTreeName(), edm::BranchIDListHelper::fixBranchListIndexes(), inputFile_, edm::makeBranchListIndexToProcessIndex(), edm::poolNames::metaDataTreeName(), eostools::move(), or, productIDEntry_, mkLumiAveragedPlots::tuple, and edm::BranchIDListHelper::updateFromInput().

Referenced by work_().

639  {
640  // BranchID-to-ProductID mapping disabled
641  if (productIDEntry_ < 0) {
642  return {};
643  }
644 
645  TTree* metaTree = dynamic_cast<TTree*>(inputFile_->Get(edm::poolNames::metaDataTreeName().c_str()));
646  if (nullptr == metaTree) {
647  //std::cerr << "Did not find " << edm::poolNames::metaDataTreeName() << " tree" << std::endl;
648  return {};
649  }
650 
651  TBranch* branchIDListsBranch = metaTree->GetBranch(edm::poolNames::branchIDListBranchName().c_str());
652  if (nullptr == branchIDListsBranch) {
653  /*
654  std::cerr << "Did not find " << edm::poolNames::branchIDListBranchName() << " from "
655  << edm::poolNames::metaDataTreeName() << " tree" << std::endl;
656  */
657  return {};
658  }
659 
660  edm::BranchIDLists branchIDLists;
661  edm::BranchIDLists* branchIDListsPtr = &branchIDLists;
662  branchIDListsBranch->SetAddress(&branchIDListsPtr);
663  if (branchIDListsBranch->GetEntry(0) <= 0) {
664  //std::cerr << "Failed to read an entry from " << edm::poolNames::branchIDListBranchName() << std::endl;
665  return {};
666  }
667 
668  edm::BranchIDListHelper branchIDListHelper;
669  branchIDListHelper.updateFromInput(branchIDLists);
670 
671  TTree* events = dynamic_cast<TTree*>(inputFile_->Get(edm::poolNames::eventTreeName().c_str()));
672  assert(events != nullptr);
673  TBranch* branchListIndexesBranch = events->GetBranch(edm::poolNames::branchListIndexesBranchName().c_str());
674  if (nullptr == branchListIndexesBranch) {
675  /*
676  std::cerr << "Did not find " << edm::poolNames::branchListIndexesBranchName() << " from "
677  << edm::poolNames::eventTreeName() << " tree" << std::endl;
678  */
679  return {};
680  }
681  edm::BranchListIndexes branchListIndexes;
682  edm::BranchListIndexes* pbranchListIndexes = &branchListIndexes;
683  branchListIndexesBranch->SetAddress(&pbranchListIndexes);
684  if (branchListIndexesBranch->GetEntry(productIDEntry_) <= 0 or branchListIndexes.empty()) {
685  /*
686  std::cerr << "Failed to read entry from " << edm::poolNames::branchListIndexesBranchName() << ", or it is empty"
687  << std::endl;
688  */
689  return {};
690  }
691 
692  if (not branchIDListHelper.fixBranchListIndexes(branchListIndexes)) {
693  //std::cerr << "Call to branchIDListHelper.fixBranchListIndexes() failed" << std::endl;
694  return {};
695  }
696 
697  // Fill in helper map for Branch to ProductID mapping
698  auto branchListIndexToProcessIndex = edm::makeBranchListIndexToProcessIndex(branchListIndexes);
699 
700  return std::tuple(std::move(branchIDListHelper), std::move(branchListIndexToProcessIndex));
701 }
std::string const & metaDataTreeName()
Definition: BranchType.cc:159
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
bool fixBranchListIndexes(BranchListIndexes &indexes, bool assertOnFailure=true) const
Called by sources to convert their read indexes into the indexes used by the job. ...
assert(be >=bs)
std::string const & branchIDListBranchName()
Definition: BranchType.cc:183
std::vector< BranchListIndex > BranchListIndexes
edm::propagate_const< std::unique_ptr< TFile > > inputFile_
Definition: EdmProvDump.cc:470
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
std::vector< ProcessIndex > makeBranchListIndexToProcessIndex(BranchListIndexes const &branchListIndexes)
int const productIDEntry_
Definition: EdmProvDump.cc:489
bool updateFromInput(BranchIDLists const &bidlists)
std::string const & eventTreeName()
Definition: BranchType.cc:220
std::string const & branchListIndexesBranchName()
Definition: BranchType.cc:212
int events
def move(src, dest)
Definition: eostools.py:511

◆ operator=()

ProvenanceDumper& ProvenanceDumper::operator= ( ProvenanceDumper const &  )
delete

◆ printErrors()

void ProvenanceDumper::printErrors ( std::ostream &  os)

Definition at line 529 of file EdmProvDump.cc.

References errorCount_, errorLog_, and l1tGTMenu_BTagSeeds_cff::os.

Referenced by main().

529  {
530  if (errorCount_ > 0)
531  os << errorLog_.str() << std::endl;
532 }
std::stringstream errorLog_
Definition: EdmProvDump.cc:472

◆ work_()

void ProvenanceDumper::work_ ( )
private

Definition at line 703 of file EdmProvDump.cc.

References addAncestors(), addDescendants(), cms::cuda::assert(), MicroEventContent_cff::branch, edm::branchIDToProductID(), edm::BranchTypeToBranchEntryInfoBranchName(), edm::BranchTypeToMetaDataTreeName(), edm::BranchTypeToProductProvenanceBranchName(), edm::BranchTypeToProductTreeName(), DMR_cfg::cerr, gather_cfg::cout, dontPrintProducts_, dumpEventFilteringParameterSets_(), dumpParameterSetForID_(), dumpProcessHistory_(), dumpPSetID_, edm::ParameterSet::empty(), errorCount_, errorLog_, Exception, excludeESModules_, edm::ParameterSet::existsAs(), exitCode_, extendedAncestors_, extendedDescendants_, findMatch_, edm::propagate_const< T >::get(), edm::ParentageRegistry::getMapped(), edm::pset::Registry::getMapped(), edm::ParameterSet::getParameterSet(), historyGraph_, mps_fire::i, edm::Parentage::id(), edm::ParameterSet::id(), l1ctLayer2EG_cff::id, edm::poolNames::idToParameterSetBlobsBranchName(), edm::InEvent, info(), input, inputFile_, edm::ParentageRegistry::insertMapped(), edm::pset::Registry::insertMapped(), edm::ParentageRegistry::instance(), edm::pset::Registry::instance(), edm::ParameterSet::isRegistered(), B2GTnPMonitor_cfi::item, makeBranchIDListHelper(), edm::poolNames::metaDataTreeName(), edm::poolNames::moduleDescriptionMapBranchName(), HerwigMaxPtPartonFilter_cfi::moduleLabel, edm::numEntries(), edm::poolNames::parameterSetMapBranchName(), edm::poolNames::parameterSetsTreeName(), edm::poolNames::parentageBranchName(), edm::poolNames::parentageTreeName(), edm::Parentage::parents(), phc_, phv_, prettyPrint(), LaserDQM_cfg::process, edm::poolNames::processHistoryBranchName(), edm::poolNames::processHistoryMapBranchName(), edm::poolNames::productDescriptionBranchName(), edm::ProductRegistry::productListUpdator(), productRegistryPresent_, muonDTDigis_cfi::pset, psm_, reg_, edm::ParameterSet::registerIt(), alignCSCRings::s, edm::setIsMergeable(), showDependencies_, showOtherModules_, showTopLevelPSets_, edm::sort_all(), source, AlCaHLTBitMon_QueryRunRegistry::string, groupFilesInBlocks::temp, triggerPaths, triggerResults, tier0::unique(), and x.

Referenced by dump().

703  {
704  TTree* meta = dynamic_cast<TTree*>(inputFile_->Get(edm::poolNames::metaDataTreeName().c_str()));
705  assert(nullptr != meta);
706 
707  edm::ProductRegistry* pReg = &reg_;
708  if (meta->FindBranch(edm::poolNames::productDescriptionBranchName().c_str()) != nullptr) {
709  meta->SetBranchAddress(edm::poolNames::productDescriptionBranchName().c_str(), &pReg);
710  } else {
711  productRegistryPresent_ = false;
712  }
713 
714  ParameterSetMap* pPsm = &psm_;
715  if (meta->FindBranch(edm::poolNames::parameterSetMapBranchName().c_str()) != nullptr) {
716  meta->SetBranchAddress(edm::poolNames::parameterSetMapBranchName().c_str(), &pPsm);
717  } else {
718  TTree* psetTree = dynamic_cast<TTree*>(inputFile_->Get(edm::poolNames::parameterSetsTreeName().c_str()));
719  assert(nullptr != psetTree);
720  typedef std::pair<edm::ParameterSetID, edm::ParameterSetBlob> IdToBlobs;
721  IdToBlobs idToBlob;
722  IdToBlobs* pIdToBlob = &idToBlob;
723  psetTree->SetBranchAddress(edm::poolNames::idToParameterSetBlobsBranchName().c_str(), &pIdToBlob);
724  for (long long i = 0; i != psetTree->GetEntries(); ++i) {
725  psetTree->GetEntry(i);
726  psm_.insert(idToBlob);
727  }
728  }
729 
731  if (meta->FindBranch(edm::poolNames::processHistoryBranchName().c_str()) != nullptr) {
732  meta->SetBranchAddress(edm::poolNames::processHistoryBranchName().c_str(), &pPhv);
733  }
734 
736  edm::ProcessHistoryMap* pPhm = &phm;
737  if (meta->FindBranch(edm::poolNames::processHistoryMapBranchName().c_str()) != nullptr) {
738  meta->SetBranchAddress(edm::poolNames::processHistoryMapBranchName().c_str(), &pPhm);
739  }
740 
741  if (meta->FindBranch(edm::poolNames::moduleDescriptionMapBranchName().c_str()) != nullptr) {
742  if (meta->GetBranch(edm::poolNames::moduleDescriptionMapBranchName().c_str())->GetSplitLevel() != 0) {
743  meta->SetBranchStatus((edm::poolNames::moduleDescriptionMapBranchName() + ".*").c_str(), false);
744  } else {
745  meta->SetBranchStatus(edm::poolNames::moduleDescriptionMapBranchName().c_str(), false);
746  }
747  }
748 
749  meta->GetEntry(0);
750  assert(nullptr != pReg);
751 
753  for (auto const& item : psm_) {
754  edm::ParameterSet pset(item.second.pset());
755  pset.setID(item.first);
756  psetRegistry.insertMapped(pset);
757  }
758 
759  if (!phv_.empty()) {
760  for (auto const& history : phv_) {
761  for (auto const& process : history) {
762  phc_.push_back(process);
763  }
764  }
766  phc_.erase(std::unique(phc_.begin(), phc_.end()), phc_.end());
767 
768  }
769  // backward compatibility
770  else if (!phm.empty()) {
771  for (auto const& history : phm) {
772  phv_.push_back(history.second);
773  for (auto const& process : history.second) {
774  phc_.push_back(process);
775  }
776  }
778  phc_.erase(std::unique(phc_.begin(), phc_.end()), phc_.end());
779  }
780 
781  if (!dumpPSetID_.empty()) {
782  edm::ParameterSetID psetID;
783  try {
785  } catch (cms::Exception const& x) {
786  throw cms::Exception("Command Line Argument")
787  << "Illegal ParameterSetID string. It should contain 32 hexadecimal characters";
788  }
789  dumpParameterSetForID_(psetID);
790  return;
791  }
792 
793  // Helper to map BranchID to ProductID (metadata tree needed also for parentage information)
794  auto branchIDListHelperAndToProcessIndex = makeBranchIDListHelper();
795 
796  //Prepare the parentage information if requested
797  std::map<edm::BranchID, std::set<edm::ParentageID>> perProductParentage;
798 
800  TTree* parentageTree = dynamic_cast<TTree*>(inputFile_->Get(edm::poolNames::parentageTreeName().c_str()));
801  if (nullptr == parentageTree) {
802  std::cerr << "ERROR, no Parentage tree available so cannot show dependencies, ancestors, or descendants.\n";
803  std::cerr << "Possibly this is not a standard EDM format file. For example, dependency, ancestor, and\n";
804  std::cerr << "descendant options to edmProvDump will not work with nanoAOD format files.\n\n";
805  showDependencies_ = false;
806  extendedAncestors_ = false;
807  extendedDescendants_ = false;
808  } else {
810 
811  std::vector<edm::ParentageID> orderedParentageIDs;
812  orderedParentageIDs.reserve(parentageTree->GetEntries());
813  for (Long64_t i = 0, numEntries = parentageTree->GetEntries(); i < numEntries; ++i) {
814  edm::Parentage parentageBuffer;
815  edm::Parentage* pParentageBuffer = &parentageBuffer;
816  parentageTree->SetBranchAddress(edm::poolNames::parentageBranchName().c_str(), &pParentageBuffer);
817  parentageTree->GetEntry(i);
818  registry.insertMapped(parentageBuffer);
819  orderedParentageIDs.push_back(parentageBuffer.id());
820  }
821  parentageTree->SetBranchAddress(edm::poolNames::parentageBranchName().c_str(), nullptr);
822 
823  TTree* eventMetaTree =
824  dynamic_cast<TTree*>(inputFile_->Get(edm::BranchTypeToMetaDataTreeName(edm::InEvent).c_str()));
825  if (nullptr == eventMetaTree) {
826  eventMetaTree = dynamic_cast<TTree*>(inputFile_->Get(edm::BranchTypeToProductTreeName(edm::InEvent).c_str()));
827  }
828  if (nullptr == eventMetaTree) {
830  << "' Tree in file so can not show dependencies\n";
831  showDependencies_ = false;
832  extendedAncestors_ = false;
833  extendedDescendants_ = false;
834  } else {
835  TBranch* storedProvBranch =
836  eventMetaTree->GetBranch(edm::BranchTypeToProductProvenanceBranchName(edm::InEvent).c_str());
837 
838  if (nullptr != storedProvBranch) {
839  std::vector<edm::StoredProductProvenance> info;
840  std::vector<edm::StoredProductProvenance>* pInfo = &info;
841  storedProvBranch->SetAddress(&pInfo);
842  for (Long64_t i = 0, numEntries = eventMetaTree->GetEntries(); i < numEntries; ++i) {
843  storedProvBranch->GetEntry(i);
844  for (auto const& item : info) {
845  edm::BranchID bid(item.branchID_);
846  perProductParentage[bid].insert(orderedParentageIDs.at(item.parentageIDIndex_));
847  }
848  }
849  } else {
850  //backwards compatible check
851  TBranch* productProvBranch =
852  eventMetaTree->GetBranch(edm::BranchTypeToBranchEntryInfoBranchName(edm::InEvent).c_str());
853  if (nullptr != productProvBranch) {
854  std::vector<edm::ProductProvenance> info;
855  std::vector<edm::ProductProvenance>* pInfo = &info;
856  productProvBranch->SetAddress(&pInfo);
857  for (Long64_t i = 0, numEntries = eventMetaTree->GetEntries(); i < numEntries; ++i) {
858  productProvBranch->GetEntry(i);
859  for (auto const& item : info) {
860  perProductParentage[item.branchID()].insert(item.parentageID());
861  }
862  }
863  } else {
864  std::cerr << " ERROR, could not find provenance information so can not show dependencies\n";
865  showDependencies_ = false;
866  extendedAncestors_ = false;
867  extendedDescendants_ = false;
868  }
869  }
870  }
871  }
872  }
873 
874  std::map<edm::BranchID, std::set<edm::BranchID>> parentToChildren;
876 
877  if (extendedDescendants_) {
878  for (auto const& itParentageSet : perProductParentage) {
879  edm::BranchID childBranchID = itParentageSet.first;
880  for (auto const& itParentageID : itParentageSet.second) {
881  edm::Parentage const* parentage = registry.getMapped(itParentageID);
882  if (nullptr != parentage) {
883  for (auto const& branch : parentage->parents()) {
884  parentToChildren[branch].insert(childBranchID);
885  }
886  } else {
887  std::cerr << " ERROR:parentage info not in registry ParentageID=" << itParentageID << std::endl;
888  }
889  }
890  }
891  }
892 
894 
896 
898  std::cout << "---------Producers with data in file---------" << std::endl;
899  }
900 
901  //using edm::ParameterSetID as the key does not work
902  // typedef std::map<edm::ParameterSetID, std::vector<edm::BranchDescription> > IdToBranches
903  ModuleToIdBranches moduleToIdBranches;
904  //IdToBranches idToBranches;
905 
906  std::map<edm::BranchID, std::string> branchIDToBranchName;
907 
908  for (auto const& processConfig : phc_) {
909  edm::ParameterSet const* processParameterSet =
910  edm::pset::Registry::instance()->getMapped(processConfig.parameterSetID());
911  if (nullptr == processParameterSet || processParameterSet->empty()) {
912  continue;
913  }
914  for (auto& item : reg_.productListUpdator()) {
915  auto& product = item.second;
916  if (product.processName() != processConfig.processName()) {
917  continue;
918  }
919  //force it to rebuild the branch name
920  product.init();
921  setIsMergeable(product);
922 
924  branchIDToBranchName[product.branchID()] = product.branchName();
925  }
926  /*
927  std::cout << product.branchName()
928  << " id " << product.productID() << std::endl;
929  */
930  std::string moduleLabel = product.moduleLabel();
931  if (moduleLabel == source) {
932  moduleLabel = input;
933  } else if (moduleLabel == triggerResults) {
935  }
936 
937  std::stringstream s;
938 
939  if (processParameterSet->existsAs<edm::ParameterSet>(moduleLabel)) {
940  edm::ParameterSet const& moduleParameterSet = processParameterSet->getParameterSet(moduleLabel);
941  if (!moduleParameterSet.isRegistered()) {
942  edm::ParameterSet moduleParameterSetCopy = processParameterSet->getParameterSet(moduleLabel);
943  moduleParameterSetCopy.registerIt();
944  s << moduleParameterSetCopy.id();
945  } else {
946  s << moduleParameterSet.id();
947  }
948  moduleToIdBranches[std::make_pair(product.processName(), product.moduleLabel())][s.str()].push_back(product);
949  }
950  }
951  }
952 
953  for (auto const& item : moduleToIdBranches) {
954  std::ostringstream sout;
955  sout << "Module: " << item.first.second << " " << item.first.first << std::endl;
956  std::set<edm::BranchID> allBranchIDsForLabelAndProcess;
957  IdToBranches const& idToBranches = item.second;
958  for (auto const& idBranch : idToBranches) {
959  sout << " PSet id:" << idBranch.first << std::endl;
960  if (!dontPrintProducts_) {
961  sout << " products: {" << std::endl;
962  }
963  std::set<edm::BranchID> branchIDs;
964  for (auto const& branch : idBranch.second) {
965  if (!dontPrintProducts_) {
966  sout << " " << branch.branchName();
968  if (branchIDListHelperAndToProcessIndex) {
969  sout << " ProductID "
970  << edm::branchIDToProductID(branch.branchID(),
971  std::get<0>(*branchIDListHelperAndToProcessIndex),
972  std::get<1>(*branchIDListHelperAndToProcessIndex));
973  } else {
974  sout << " BranchID " << branch.branchID();
975  }
976  sout << std::endl;
977  }
978  branchIDs.insert(branch.branchID());
979  allBranchIDsForLabelAndProcess.insert(branch.branchID());
980  }
981  sout << " }" << std::endl;
982  edm::ParameterSetID psid(idBranch.first);
983  ParameterSetMap::const_iterator itpsm = psm_.find(psid);
984  if (psm_.end() == itpsm) {
985  ++errorCount_;
986  errorLog_ << "No ParameterSetID for " << psid << std::endl;
987  exitCode_ = 1;
988  } else {
989  sout << " parameters: ";
990  prettyPrint(sout, edm::ParameterSet((*itpsm).second.pset()), " ", " ");
991  sout << std::endl;
992  }
993  if (showDependencies_) {
994  sout << " dependencies: {" << std::endl;
995  std::set<edm::ParentageID> parentageIDs;
996  for (auto const& branch : branchIDs) {
997  //Save these BranchIDs
998  std::set<edm::ParentageID> const& temp = perProductParentage[branch];
999  parentageIDs.insert(temp.begin(), temp.end());
1000  }
1001  for (auto const& parentID : parentageIDs) {
1002  edm::Parentage const* parentage = registry.getMapped(parentID);
1003  if (nullptr != parentage) {
1004  for (auto const& branch : parentage->parents()) {
1005  sout << " " << branchIDToBranchName[branch] << std::endl;
1006  }
1007  } else {
1008  sout << " ERROR:parentage info not in registry ParentageID=" << parentID << std::endl;
1009  }
1010  }
1011  if (parentageIDs.empty()) {
1012  sout << " no dependencies recorded (event may not contain data from this module)" << std::endl;
1013  }
1014  sout << " }" << std::endl;
1015  }
1016  } // end loop over PSetIDs
1017  if (extendedAncestors_) {
1018  sout << " extendedAncestors: {" << std::endl;
1019  std::set<edm::BranchID> ancestorBranchIDs;
1020  for (auto const& branchID : allBranchIDsForLabelAndProcess) {
1021  addAncestors(branchID, ancestorBranchIDs, sout, perProductParentage);
1022  }
1023  for (auto const& ancestorBranchID : ancestorBranchIDs) {
1024  sout << " " << branchIDToBranchName[ancestorBranchID] << "\n";
1025  }
1026  sout << " }" << std::endl;
1027  }
1028 
1029  if (extendedDescendants_) {
1030  sout << " extendedDescendants: {" << std::endl;
1031  std::set<edm::BranchID> descendantBranchIDs;
1032  for (auto const& branchID : allBranchIDsForLabelAndProcess) {
1033  addDescendants(branchID, descendantBranchIDs, sout, parentToChildren);
1034  }
1035  for (auto const& descendantBranchID : descendantBranchIDs) {
1036  sout << " " << branchIDToBranchName[descendantBranchID] << "\n";
1037  }
1038  sout << " }" << std::endl;
1039  }
1040  bool foundMatch = true;
1041  if (!findMatch_.empty()) {
1042  for (auto const& stringToFind : findMatch_) {
1043  if (sout.str().find(stringToFind) == std::string::npos) {
1044  foundMatch = false;
1045  break;
1046  }
1047  }
1048  }
1049  if (foundMatch) {
1050  std::cout << sout.str() << std::endl;
1051  }
1052  } // end loop over module label/process
1053 
1055  std::cout << "---------Other Modules---------" << std::endl;
1056  historyGraph_.printOtherModulesHistory(psm_, moduleToIdBranches, findMatch_, errorLog_);
1057  } else if (!productRegistryPresent_) {
1058  std::cout << "---------All Modules---------" << std::endl;
1059  historyGraph_.printOtherModulesHistory(psm_, moduleToIdBranches, findMatch_, errorLog_);
1060  }
1061 
1062  if (!excludeESModules_) {
1063  std::cout << "---------EventSetup---------" << std::endl;
1064  historyGraph_.printEventSetupHistory(psm_, findMatch_, errorLog_);
1065  }
1066 
1067  if (showTopLevelPSets_) {
1068  std::cout << "---------Top Level PSets---------" << std::endl;
1069  historyGraph_.printTopLevelPSetsHistory(psm_, findMatch_, errorLog_);
1070  }
1071  if (errorCount_ != 0) {
1072  exitCode_ = 1;
1073  }
1074 }
std::stringstream errorLog_
Definition: EdmProvDump.cc:472
std::vector< ProcessHistory > ProcessHistoryVector
std::string const & metaDataTreeName()
Definition: BranchType.cc:159
static const TGPicture * info(bool iBackgroundIsBlack)
bool getMapped(key_type const &k, value_type &result) const
Definition: Registry.cc:17
std::string dumpPSetID_
Definition: EdmProvDump.cc:488
bool productRegistryPresent_
Definition: EdmProvDump.cc:484
std::string const & BranchTypeToBranchEntryInfoBranchName(BranchType const &branchType)
Definition: BranchType.cc:134
std::string const & moduleDescriptionMapBranchName()
Definition: BranchType.cc:171
edm::ProductRegistry reg_
Definition: EdmProvDump.cc:474
ParameterSetMap psm_
Definition: EdmProvDump.cc:477
ParameterSet const & getParameterSet(std::string const &) const
void dumpParameterSetForID_(edm::ParameterSetID const &id)
Definition: EdmProvDump.cc:580
HistoryNode historyGraph_
Definition: EdmProvDump.cc:478
std::string const & processHistoryBranchName()
Definition: BranchType.cc:177
std::vector< BranchID > const & parents() const
Definition: Parentage.h:44
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:172
void dumpEventFilteringParameterSets_(TFile *file)
Definition: EdmProvDump.cc:551
assert(be >=bs)
std::string const & parameterSetMapBranchName()
Definition: BranchType.cc:168
edm::ProcessHistoryVector phv_
Definition: EdmProvDump.cc:476
std::string const & productDescriptionBranchName()
Definition: BranchType.cc:162
static std::string const input
Definition: EdmProvDump.cc:50
ProductID branchIDToProductID(BranchID const &bid, BranchIDListHelper const &branchIDListHelper, std::vector< ProcessIndex > const &branchListIndexToProcessIndex)
constexpr element_type const * get() const
std::string const & BranchTypeToMetaDataTreeName(BranchType const &branchType)
Definition: BranchType.cc:105
bool getMapped(key_type const &k, value_type &result) const
std::string const & processHistoryMapBranchName()
Definition: BranchType.cc:174
ParameterSetID id() const
ParameterSet const & registerIt()
edm::propagate_const< std::unique_ptr< TFile > > inputFile_
Definition: EdmProvDump.cc:470
std::string const & BranchTypeToProductTreeName(BranchType const &branchType)
Definition: BranchType.cc:95
std::map< std::pair< std::string, std::string >, IdToBranches > ModuleToIdBranches
Definition: EdmProvDump.cc:40
bool empty() const
Definition: ParameterSet.h:202
Long64_t numEntries(TFile *hdl, std::string const &trname)
Definition: CollUtil.cc:50
def unique(seq, keepstr=True)
Definition: tier0.py:24
void addDescendants(edm::BranchID const &branchID, std::set< edm::BranchID > &descendantBranchIDs, std::ostringstream &sout, std::map< edm::BranchID, std::set< edm::BranchID >> &parentToChildren) const
std::string const & parameterSetsTreeName()
Definition: BranchType.cc:216
std::string const & BranchTypeToProductProvenanceBranchName(BranchType const &BranchType)
Definition: BranchType.cc:139
bool insertMapped(value_type const &v, bool forceUpdate=false)
Definition: Registry.cc:32
std::string const & parentageBranchName()
Definition: BranchType.cc:156
static std::string const triggerResults
Definition: EdmProvDump.cc:47
Hash< ParameterSetType > ParameterSetID
std::string const & idToParameterSetBlobsBranchName()
Definition: BranchType.cc:218
static std::ostream & prettyPrint(std::ostream &oStream, edm::ParameterSet const &iPSet, std::string const &iIndent, std::string const &iIndentDelta)
Definition: EdmProvDump.cc:404
std::map< std::string, std::vector< edm::BranchDescription > > IdToBranches
Definition: EdmProvDump.cc:39
void dumpProcessHistory_()
Definition: EdmProvDump.cc:602
edm::ProcessConfigurationVector phc_
Definition: EdmProvDump.cc:475
void sort_all(RandomAccessSequence &s)
wrappers for std::sort
Definition: Algorithms.h:92
std::string const & parentageTreeName()
Definition: BranchType.cc:154
ProductList & productListUpdator()
std::vector< std::string > findMatch_
Definition: EdmProvDump.cc:486
std::map< ParameterSetID, ParameterSetBlob > ParameterSetMap
ParentageID id() const
Definition: Parentage.cc:17
bool isRegistered() const
Definition: ParameterSet.h:72
std::optional< std::tuple< edm::BranchIDListHelper, std::vector< edm::ProcessIndex > > > makeBranchIDListHelper()
Definition: EdmProvDump.cc:639
static ParentageRegistry * instance()
static std::string const triggerPaths
Definition: EdmProvDump.cc:48
static std::string const source
Definition: EdmProvDump.cc:49
void setIsMergeable(BranchDescription &)
std::map< ProcessHistoryID, ProcessHistory > ProcessHistoryMap
bool insertMapped(value_type const &v)
static Registry * instance()
Definition: Registry.cc:12
void addAncestors(edm::BranchID const &branchID, std::set< edm::BranchID > &ancestorBranchIDs, std::ostringstream &sout, std::map< edm::BranchID, std::set< edm::ParentageID >> &perProductParentage) const

Member Data Documentation

◆ dontPrintProducts_

bool ProvenanceDumper::dontPrintProducts_
private

Definition at line 487 of file EdmProvDump.cc.

Referenced by work_().

◆ dumpPSetID_

std::string ProvenanceDumper::dumpPSetID_
private

Definition at line 488 of file EdmProvDump.cc.

Referenced by work_().

◆ errorCount_

int ProvenanceDumper::errorCount_
private

Definition at line 473 of file EdmProvDump.cc.

Referenced by printErrors(), and work_().

◆ errorLog_

std::stringstream ProvenanceDumper::errorLog_
private

Definition at line 472 of file EdmProvDump.cc.

Referenced by printErrors(), and work_().

◆ excludeESModules_

bool ProvenanceDumper::excludeESModules_
private

Definition at line 482 of file EdmProvDump.cc.

Referenced by work_().

◆ exitCode_

int ProvenanceDumper::exitCode_
private

Definition at line 471 of file EdmProvDump.cc.

Referenced by exitCode(), and work_().

◆ extendedAncestors_

bool ProvenanceDumper::extendedAncestors_
private

Definition at line 480 of file EdmProvDump.cc.

Referenced by work_().

◆ extendedDescendants_

bool ProvenanceDumper::extendedDescendants_
private

Definition at line 481 of file EdmProvDump.cc.

Referenced by work_().

◆ filename_

std::string ProvenanceDumper::filename_
private

Definition at line 469 of file EdmProvDump.cc.

◆ findMatch_

std::vector<std::string> ProvenanceDumper::findMatch_
private

Definition at line 486 of file EdmProvDump.cc.

Referenced by work_().

◆ historyGraph_

HistoryNode ProvenanceDumper::historyGraph_
private

Definition at line 478 of file EdmProvDump.cc.

Referenced by dumpProcessHistory_(), and work_().

◆ inputFile_

edm::propagate_const<std::unique_ptr<TFile> > ProvenanceDumper::inputFile_
private

Definition at line 470 of file EdmProvDump.cc.

Referenced by makeBranchIDListHelper(), and work_().

◆ phc_

edm::ProcessConfigurationVector ProvenanceDumper::phc_
private

Definition at line 475 of file EdmProvDump.cc.

Referenced by work_().

◆ phv_

edm::ProcessHistoryVector ProvenanceDumper::phv_
private

Definition at line 476 of file EdmProvDump.cc.

Referenced by dumpProcessHistory_(), and work_().

◆ productIDEntry_

int const ProvenanceDumper::productIDEntry_
private

Definition at line 489 of file EdmProvDump.cc.

Referenced by makeBranchIDListHelper().

◆ productRegistryPresent_

bool ProvenanceDumper::productRegistryPresent_
private

Definition at line 484 of file EdmProvDump.cc.

Referenced by work_().

◆ psm_

ParameterSetMap ProvenanceDumper::psm_
private

Definition at line 477 of file EdmProvDump.cc.

Referenced by dumpParameterSetForID_(), and work_().

◆ reg_

edm::ProductRegistry ProvenanceDumper::reg_
private

Definition at line 474 of file EdmProvDump.cc.

Referenced by work_().

◆ showDependencies_

bool ProvenanceDumper::showDependencies_
private

Definition at line 479 of file EdmProvDump.cc.

Referenced by work_().

◆ showOtherModules_

bool ProvenanceDumper::showOtherModules_
private

Definition at line 483 of file EdmProvDump.cc.

Referenced by work_().

◆ showTopLevelPSets_

bool ProvenanceDumper::showTopLevelPSets_
private

Definition at line 485 of file EdmProvDump.cc.

Referenced by work_().