CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EdmProvDump.cc
Go to the documentation of this file.
20 
23 
24 #include "Cintex/Cintex.h"
25 #include "TError.h"
26 #include "TFile.h"
27 #include "TTree.h"
28 
29 #include "boost/program_options.hpp"
30 
31 #include <assert.h>
32 #include <iostream>
33 #include <memory>
34 #include <map>
35 #include <set>
36 #include <sstream>
37 #include <vector>
38 
39 typedef std::map<std::string, std::vector<edm::BranchDescription> > IdToBranches;
40 typedef std::map<std::pair<std::string, std::string>, IdToBranches> ModuleToIdBranches;
41 
42 static std::ostream& prettyPrint(std::ostream& oStream, edm::ParameterSet const& iPSet, std::string const& iIndent, std::string const& iIndentDelta);
43 
44 namespace {
45 typedef std::map<edm::ParameterSetID, edm::ParameterSetBlob> ParameterSetMap;
46 
47  class HistoryNode {
48  public:
49  HistoryNode() :
50  config_(),
51  simpleId_(0) {
52  }
53 
54  HistoryNode(edm::ProcessConfiguration const& iConfig, unsigned int iSimpleId) :
55  config_(iConfig),
56  simpleId_(iSimpleId) {
57  }
58 
59  void addChild(HistoryNode const& child) {
60  children_.push_back(child);
61  }
62 
63  edm::ParameterSetID const&
64  parameterSetID() const {
65  return config_.parameterSetID();
66  }
67 
68  std::string const&
69  processName() const {
70  return config_.processName();
71  }
72 
73  std::size_t
74  size() const {
75  return children_.size();
76  }
77 
78  HistoryNode *
79  lastChildAddress() {
80  return &children_.back();
81  }
82 
83  typedef std::vector<HistoryNode>::const_iterator const_iterator;
84  typedef std::vector<HistoryNode>::iterator iterator;
85 
86  iterator begin() { return children_.begin();}
87  iterator end() { return children_.end();}
88 
89  const_iterator begin() const { return children_.begin();}
90  const_iterator end() const { return children_.end();}
91 
92  void print(std::ostream& os) const {
93  os << config_.processName()
94  << " '" << config_.passID() << "' '"
95  << config_.releaseVersion() << "' ["
96  << simpleId_ << "] ("
97  << config_.parameterSetID() << ")"
98  << std::endl;
99  }
100 
101  void printHistory(std::string const& iIndent = std::string(" ")) const;
102  void printEventSetupHistory(ParameterSetMap const& iPSM,
103  std::string const& iFindMatch,
104  std::ostream& oErrorLog) const;
105  void printOtherModulesHistory(ParameterSetMap const& iPSM,
106  ModuleToIdBranches const&,
107  std::string const& iFindMatch,
108  std::ostream& oErrorLog) const;
109  void printTopLevelPSetsHistory(ParameterSetMap const& iPSM,
110  std::string const& iFindMatch,
111  std::ostream& oErrorLog) const;
112 
114  configurationID() const {
115  return config_.id();
116  }
117 
118  static bool sort_;
119  private:
121  std::vector<HistoryNode> children_;
122  unsigned int simpleId_;
123  };
124 
125  std::ostream& operator<<(std::ostream& os, HistoryNode const& node) {
126  node.print(os);
127  return os;
128  }
129  bool HistoryNode::sort_ = false;
130 }
131 
132 std::ostream&
133 operator<<(std::ostream& os, edm::ProcessHistory& iHist) {
134  std::string const indentDelta(" ");
135  std::string indent = indentDelta;
136  for(edm::ProcessHistory::const_iterator i = iHist.begin(), e = iHist.end();
137  i != e;
138  ++i) {
139  os << indent
140  << i->processName() << " '"
141  << i->passID() << "' '"
142  << i->releaseVersion() << "' ("
143  << i->parameterSetID() << ")"
144  << std::endl;
145  indent += indentDelta;
146  }
147  return os;
148 }
149 
150 void HistoryNode::printHistory(std::string const& iIndent) const {
151  std::string const indentDelta(" ");
152  std::string indent = iIndent;
153  for(const_iterator i = begin(), e = end();
154  i != e;
155  ++i) {
156  std::cout << indent << *i;
157  i->printHistory(indent+indentDelta);
158  }
159 }
160 
161 std::string eventSetupComponent(char const* iType,
162  std::string const& iCompName,
163  edm::ParameterSet const& iProcessConfig,
164  std::string const& iProcessName) {
165  std::ostringstream result;
166  edm::ParameterSet const& pset = iProcessConfig.getParameterSet(iCompName);
167  std::string name(pset.getParameter<std::string>("@module_label"));
168  if(0 == name.size()) {
169  name = pset.getParameter<std::string>("@module_type");
170  }
171 
172  result << iType << ": " << name << " " << iProcessName << "\n"
173  << " parameters: ";
174  prettyPrint(result, pset, " ", " ");
175  return result.str();
176 }
177 
178 void HistoryNode::printEventSetupHistory(ParameterSetMap const& iPSM,
179  std::string const& iFindMatch,
180  std::ostream& oErrorLog) const {
181  for(const_iterator itH = begin(), e = end();
182  itH != e;
183  ++itH) {
184  //Get ParameterSet for process
185  ParameterSetMap::const_iterator itFind = iPSM.find(itH->parameterSetID());
186  if(itFind == iPSM.end()){
187  oErrorLog << "No ParameterSetID for " << itH->parameterSetID() << std::endl;
188  } else {
189  edm::ParameterSet processConfig(itFind->second.pset());
190  std::vector<std::string> sourceStrings, moduleStrings;
191  //get the sources
192  std::vector<std::string> sources = processConfig.getParameter<std::vector<std::string> >("@all_essources");
193  for(std::vector<std::string>::iterator itM = sources.begin(); itM != sources.end(); ++itM) {
194  std::string retValue = eventSetupComponent("ESSource",
195  *itM,
196  processConfig,
197  itH->processName());
198  if(iFindMatch.empty() or retValue.find(iFindMatch) != std::string::npos) {
199  sourceStrings.push_back(std::move(retValue));
200  }
201  }
202  //get the modules
203  std::vector<std::string> modules = processConfig.getParameter<std::vector<std::string> >("@all_esmodules");
204  for(std::vector<std::string>::iterator itM = modules.begin(); itM != modules.end(); ++itM) {
205  std::string retValue = eventSetupComponent("ESModule",
206  *itM,
207  processConfig,
208  itH->processName());
209  if(iFindMatch.empty() or retValue.find(iFindMatch) != std::string::npos) {
210  moduleStrings.push_back(std::move(retValue));
211  }
212  }
213  if(sort_) {
214  std::sort(sourceStrings.begin(), sourceStrings.end());
215  std::sort(moduleStrings.begin(), moduleStrings.end());
216  }
217  std::copy(sourceStrings.begin(), sourceStrings.end(),
218  std::ostream_iterator<std::string>(std::cout, "\n"));
219  std::copy(moduleStrings.begin(), moduleStrings.end(),
220  std::ostream_iterator<std::string>(std::cout, "\n"));
221 
222  }
223  itH->printEventSetupHistory(iPSM, iFindMatch, oErrorLog);
224  }
225 }
226 
227 std::string nonProducerComponent(std::string const& iCompName,
228  edm::ParameterSet const& iProcessConfig,
229  std::string const& iProcessName) {
230  std::ostringstream result;
231  edm::ParameterSet const& pset = iProcessConfig.getParameterSet(iCompName);
232  std::string label(pset.getParameter<std::string>("@module_label"));
233 
234  result << "Module: " << label << " " << iProcessName << "\n" << " parameters: ";
235  prettyPrint(result, pset, " ", " ");
236  return result.str();
237 }
238 
239 void HistoryNode::printOtherModulesHistory(ParameterSetMap const& iPSM,
240  ModuleToIdBranches const& iModules,
241  std::string const& iFindMatch,
242  std::ostream& oErrorLog) const {
243  for(const_iterator itH = begin(), e = end();
244  itH != e;
245  ++itH) {
246  //Get ParameterSet for process
247  ParameterSetMap::const_iterator itFind = iPSM.find(itH->parameterSetID());
248  if(itFind == iPSM.end()){
249  oErrorLog << "No ParameterSetID for " << itH->parameterSetID() << std::endl;
250  } else {
251  edm::ParameterSet processConfig(itFind->second.pset());
252  std::vector<std::string> moduleStrings;
253  //get all modules
254  std::vector<std::string> modules = processConfig.getParameter<std::vector<std::string> >("@all_modules");
255  for(std::vector<std::string>::iterator itM = modules.begin(); itM != modules.end(); ++itM) {
256  //if we didn't already handle this from the branches
257  if(iModules.end() == iModules.find(std::make_pair(itH->processName(), *itM))) {
258  std::string retValue(nonProducerComponent(
259  *itM,
260  processConfig,
261  itH->processName()));
262  if(iFindMatch.empty() or retValue.find(iFindMatch) != std::string::npos) {
263  moduleStrings.push_back(std::move(retValue));
264  }
265  }
266  }
267  if(sort_) {
268  std::sort(moduleStrings.begin(), moduleStrings.end());
269  }
270  std::copy(moduleStrings.begin(), moduleStrings.end(),
271  std::ostream_iterator<std::string>(std::cout, "\n"));
272  }
273  itH->printOtherModulesHistory(iPSM, iModules, iFindMatch, oErrorLog);
274  }
275 }
276 
277 static void appendToSet(std::set<std::string>&iSet, std::vector<std::string> const& iFrom){
278  for( auto const& n: iFrom){
279  iSet.insert(n);
280  }
281 }
282 
283 static std::string topLevelPSet(std::string const& iName,
284  edm::ParameterSet const& iProcessConfig,
285  std::string const& iProcessName) {
286  std::ostringstream result;
287  edm::ParameterSet const& pset = iProcessConfig.getParameterSet(iName);
288 
289  result << "PSet: " << iName << " " << iProcessName << "\n" << " parameters: ";
290  prettyPrint(result, pset, " ", " ");
291  return result.str();
292 }
293 
294 
295 void HistoryNode::printTopLevelPSetsHistory(ParameterSetMap const& iPSM,
296  std::string const& iFindMatch,
297  std::ostream& oErrorLog) const {
298  for(const_iterator itH = begin(), e = end();
299  itH != e;
300  ++itH) {
301  //Get ParameterSet for process
302  ParameterSetMap::const_iterator itFind = iPSM.find(itH->parameterSetID());
303  if(itFind == iPSM.end()){
304  oErrorLog << "No ParameterSetID for " << itH->parameterSetID() << std::endl;
305  } else {
306  edm::ParameterSet processConfig(itFind->second.pset());
307  //Need to get the names of PSets which are used by the framework (e.g. names of modules)
308  std::set<std::string> namesToExclude;
309  appendToSet(namesToExclude,processConfig.getParameter<std::vector<std::string> >("@all_modules"));
310  appendToSet(namesToExclude,processConfig.getParameter<std::vector<std::string> >("@all_sources"));
311  appendToSet(namesToExclude,processConfig.getParameter<std::vector<std::string> >("@all_loopers"));
312  //appendToSet(namesToExclude,processConfig.getParameter<std::vector<std::string> >("@all_subprocesses"));//untracked
313  appendToSet(namesToExclude,processConfig.getParameter<std::vector<std::string> >("@all_esmodules"));
314  appendToSet(namesToExclude,processConfig.getParameter<std::vector<std::string> >("@all_essources"));
315  appendToSet(namesToExclude,processConfig.getParameter<std::vector<std::string> >("@all_esprefers"));
316  if (processConfig.existsAs<std::vector<std::string>>("all_aliases")) {
317  appendToSet(namesToExclude,processConfig.getParameter<std::vector<std::string> >("@all_aliases"));
318  }
319 
320  std::vector<std::string> allNames{};
321  processConfig.getParameterSetNames(allNames);
322 
323  std::vector<std::string> results;
324  for(auto const& name: allNames){
325  if (name.size() == 0 || '@' == name[0] || namesToExclude.find(name)!=namesToExclude.end()) {
326  continue;
327  }
328  std::string retValue = topLevelPSet(name,processConfig,itH->processName());
329  if(iFindMatch.empty() or retValue.find(iFindMatch) != std::string::npos) {
330  results.push_back(std::move(retValue));
331  }
332  }
333  if(sort_) {
334  std::sort(results.begin(), results.end());
335  }
336  std::copy(results.begin(), results.end(),
337  std::ostream_iterator<std::string>(std::cout, "\n"));
338  }
339  itH->printTopLevelPSetsHistory(iPSM, iFindMatch, oErrorLog);
340  }
341 }
342 
343 
344 namespace {
345  std::unique_ptr<TFile>
346  makeTFileWithLookup(std::string const& filename) {
347  // See if it is a logical file name.
348  std::auto_ptr<edm::SiteLocalConfig> slcptr(new edm::service::SiteLocalConfigService(edm::ParameterSet()));
349  boost::shared_ptr<edm::serviceregistry::ServiceWrapper<edm::SiteLocalConfig> > slc(new edm::serviceregistry::ServiceWrapper<edm::SiteLocalConfig>(slcptr));
352  std::string override;
353  std::vector<std::string> fileNames;
354  fileNames.push_back(filename);
355  edm::InputFileCatalog catalog(fileNames, override, true);
356  if(catalog.fileNames()[0] == filename) {
357  throw cms::Exception("FileNotFound", "RootFile::RootFile()")
358  << "File " << filename << " was not found or could not be opened.\n";
359  }
360  // filename is a valid LFN.
361  std::unique_ptr<TFile> result(TFile::Open(catalog.fileNames()[0].c_str()));
362  if(!result.get()) {
363  throw cms::Exception("FileNotFound", "RootFile::RootFile()")
364  << "File " << fileNames[0] << " was not found or could not be opened.\n";
365  }
366  return result;
367  }
368 
369  // Open the input file, returning the TFile object that represents it.
370  // The returned unique_ptr will not be null. The argument must not be null.
371  // We first try the file name as a PFN, so that the catalog and related
372  // services are not loaded unless needed.
373  std::unique_ptr<TFile>
374  makeTFile(std::string const& filename) {
375  gErrorIgnoreLevel = kFatal;
376  std::unique_ptr<TFile> result(TFile::Open(filename.c_str()));
377  gErrorIgnoreLevel = kError;
378  if(!result.get()) {
379  // Try again with catalog.
380  return makeTFileWithLookup(filename);
381  }
382  return result;
383  }
384 }
385 
386 
387 static std::ostream& prettyPrint(std::ostream& os, edm::ParameterSetEntry const& psetEntry, std::string const& iIndent, std::string const& iIndentDelta) {
388  char const* trackiness = (psetEntry.isTracked()?"tracked":"untracked");
389  os << "PSet " << trackiness << " = (";
390  prettyPrint(os, psetEntry.pset(), iIndent + iIndentDelta, iIndentDelta);
391  os << ")";
392  return os;
393 }
394 
395 static std::ostream& prettyPrint(std::ostream& os, edm::VParameterSetEntry const& vpsetEntry, std::string const& iIndent, std::string const& iIndentDelta) {
396  std::vector<edm::ParameterSet> const& vps = vpsetEntry.vpset();
397  os << "VPSet " << (vpsetEntry.isTracked() ? "tracked" : "untracked") << " = ({" << std::endl;
398  std::string newIndent = iIndent+iIndentDelta;
399  std::string start;
400  std::string const between(",\n");
401  for(std::vector<edm::ParameterSet>::const_iterator i = vps.begin(), e = vps.end(); i != e; ++i) {
402  os << start << newIndent;
403  prettyPrint(os, *i, newIndent, iIndentDelta);
404  start = between;
405  }
406  if(!vps.empty()) {
407  os << std::endl;
408  }
409  os << iIndent<< "})";
410  return os;
411 }
412 
413 
414 static std::ostream& prettyPrint(std::ostream& oStream, edm::ParameterSet const& iPSet, std::string const& iIndent, std::string const& iIndentDelta) {
415  std::string newIndent = iIndent+iIndentDelta;
416 
417  oStream << "{" << std::endl;
418  for(edm::ParameterSet::table::const_iterator i = iPSet.tbl().begin(), e = iPSet.tbl().end(); i != e; ++i) {
419  // indent a bit
420  oStream << newIndent<< i->first << ": " << i->second << std::endl;
421  }
422  for(edm::ParameterSet::psettable::const_iterator i = iPSet.psetTable().begin(), e = iPSet.psetTable().end(); i != e; ++i) {
423  // indent a bit
424  edm::ParameterSetEntry const& pe = i->second;
425  oStream << newIndent << i->first << ": ";
426  prettyPrint(oStream, pe, iIndent, iIndentDelta);
427  oStream<< std::endl;
428  }
429  for(edm::ParameterSet::vpsettable::const_iterator i = iPSet.vpsetTable().begin(), e = iPSet.vpsetTable().end(); i != e; ++i) {
430  // indent a bit
431  edm::VParameterSetEntry const& pe = i->second;
432  oStream << newIndent << i->first << ": ";
433  prettyPrint(oStream, pe, newIndent, iIndentDelta);
434  oStream<< std::endl;
435  }
436  oStream << iIndent<< "}";
437 
438  return oStream;
439 }
440 
441 
443 public:
444  // It is illegal to call this constructor with a null pointer; a
445  // legal C-style string is required.
446  ProvenanceDumper(std::string const& filename,
447  bool showDependencies,
448  bool excludeESModules,
449  bool showAllModules,
450  bool showTopLevelPSets,
451  std::string const& findMatch);
452 
453  ProvenanceDumper(ProvenanceDumper const&) = delete; // Disallow copying and moving
454  ProvenanceDumper& operator=(ProvenanceDumper const&) = delete; // Disallow copying and moving
455 
456  // Write the provenenace information to the given stream.
457  void dump();
458  void printErrors(std::ostream& os);
459  int exitCode() const;
460 
461 private:
462  std::string filename_;
463  std::unique_ptr<TFile> inputFile_;
465  std::stringstream errorLog_;
470  ParameterSetMap psm_;
471  HistoryNode historyGraph_;
476  std::string findMatch_;
477 
478  void work_();
479  void dumpProcessHistory_();
483 };
484 
485 ProvenanceDumper::ProvenanceDumper(std::string const& filename,
486  bool showDependencies,
487  bool excludeESModules,
488  bool showOtherModules,
489  bool showTopLevelPSets,
490  std::string const& findMatch) :
491  filename_(filename),
492  inputFile_(makeTFile(filename)),
493  exitCode_(0),
494  errorLog_(),
495  errorCount_(0),
496  showDependencies_(showDependencies),
497  excludeESModules_(excludeESModules),
498  showOtherModules_(showOtherModules),
499  showTopLevelPSets_(showTopLevelPSets),
500  findMatch_(findMatch) {
501 }
502 
503 void
505  work_();
506 }
507 
508 void
509 ProvenanceDumper::printErrors(std::ostream& os) {
510  if(errorCount_ > 0) os << errorLog_.str() << std::endl;
511 }
512 
513 int
515  return exitCode_;
516 }
517 
518 void
520  edm::EventSelectionIDVector::size_type num_ids = ids.size();
521  if(num_ids == 0) {
522  std::cout << "No event filtering information is available.\n";
523  std::cout << "------------------------------\n";
524  } else {
525  std::cout << "Event filtering information for "
526  << num_ids
527  << " processing steps is available.\n"
528  << "The ParameterSets will be printed out, "
529  << "with the oldest printed first.\n";
530  for(edm::EventSelectionIDVector::size_type i = 0; i != num_ids; ++i) {
532  }
533  }
534 }
535 
536 void
538 
539  TTree* history = dynamic_cast<TTree*>(file->Get(edm::poolNames::eventHistoryTreeName().c_str()));
540  if(history != 0) {
541  edm::History h;
542  edm::History* ph = &h;
543 
544  history->SetBranchAddress(edm::poolNames::eventHistoryBranchName().c_str(), &ph);
545  if(history->GetEntry(0) <= 0) {
546  std::cout << "No event filtering information is available; the event history tree has no entries\n";
547  } else {
549  }
550  } else {
551  TTree* events = dynamic_cast<TTree*>(file->Get(edm::poolNames::eventTreeName().c_str()));
552  assert (events != 0);
553  TBranch* eventSelectionsBranch = events->GetBranch(edm::poolNames::eventSelectionsBranchName().c_str());
554  assert (eventSelectionsBranch != 0);
556  edm::EventSelectionIDVector* pids = &ids;
557  eventSelectionsBranch->SetAddress(&pids);
558  if(eventSelectionsBranch->GetEntry(0) <= 0) {
559  std::cout << "No event filtering information is available; the event selections branch has no entries\n";
560  } else {
562  }
563  }
564 }
565 
566 void
568  std::cout << "ParameterSetID: " << id << '\n';
569  if(id.isValid()) {
570  ParameterSetMap::const_iterator i = psm_.find(id);
571  if(i == psm_.end()) {
572  std::cout << "We are unable to find the corresponding ParameterSet\n";
574  if(id == empty.id()) {
575  std::cout << "But it would have been empty anyway\n";
576  }
577  } else {
578  edm::ParameterSet ps(i->second.pset());
579  prettyPrint(std::cout, ps, " ", " ");
580  std::cout<< '\n';
581  }
582  } else {
583  std::cout << "This ID is not valid\n";
584  }
585  std::cout << " -------------------------\n";
586 }
587 
588 void
590  std::cout << "Processing History:" << std::endl;
591  if(1 == phv_.size()) {
592  std::cout << *phv_.begin();
593  historyGraph_.addChild(HistoryNode(*(phv_.begin()->begin()), 1));
594  } else {
595  std::map<edm::ProcessConfigurationID, unsigned int> simpleIDs;
596  for(edm::ProcessHistoryVector::const_iterator it = phv_.begin(), itEnd = phv_.end();
597  it != itEnd;
598  ++it) {
599  //loop over the history entries looking for matches
600  HistoryNode* parent = &historyGraph_;
601  for(edm::ProcessHistory::const_iterator itH = it->begin(), e = it->end();
602  itH != e;
603  ++itH) {
604  if(parent->size() == 0) {
605  unsigned int id = simpleIDs[itH->id()];
606  if(0 == id) {
607  id = 1;
608  simpleIDs[itH->id()] = id;
609  }
610  parent->addChild(HistoryNode(*itH, id));
611  parent = parent->lastChildAddress();
612  } else {
613  //see if this is unique
614  bool isUnique = true;
615  for(HistoryNode::iterator itChild = parent->begin(), itChildEnd = parent->end();
616  itChild != itChildEnd;
617  ++itChild) {
618  if(itChild->configurationID() == itH->id()) {
619  isUnique = false;
620  parent = &(*itChild);
621  break;
622  }
623  }
624  if(isUnique) {
625  simpleIDs[itH->id()] = parent->size() + 1;
626  parent->addChild(HistoryNode(*itH, simpleIDs[itH->id()]));
627  parent = parent->lastChildAddress();
628  }
629  }
630  }
631  }
632  historyGraph_.printHistory();
633  }
634 }
635 
636 void
638 
639  TTree* meta = dynamic_cast<TTree*>(inputFile_->Get(edm::poolNames::metaDataTreeName().c_str()));
640  assert(0 != meta);
641 
642  edm::ProductRegistry* pReg = &reg_;
643  meta->SetBranchAddress(edm::poolNames::productDescriptionBranchName().c_str(), &pReg);
644 
645  ParameterSetMap* pPsm = &psm_;
646  if(meta->FindBranch(edm::poolNames::parameterSetMapBranchName().c_str()) != 0) {
647  meta->SetBranchAddress(edm::poolNames::parameterSetMapBranchName().c_str(), &pPsm);
648  } else {
649  TTree* psetTree = dynamic_cast<TTree *>(inputFile_->Get(edm::poolNames::parameterSetsTreeName().c_str()));
650  assert(0 != psetTree);
651  typedef std::pair<edm::ParameterSetID, edm::ParameterSetBlob> IdToBlobs;
652  IdToBlobs idToBlob;
653  IdToBlobs* pIdToBlob = &idToBlob;
654  psetTree->SetBranchAddress(edm::poolNames::idToParameterSetBlobsBranchName().c_str(), &pIdToBlob);
655  for(long long i = 0; i != psetTree->GetEntries(); ++i) {
656  psetTree->GetEntry(i);
657  psm_.insert(idToBlob);
658  }
659  }
661  if(meta->FindBranch(edm::poolNames::processConfigurationBranchName().c_str()) != 0) {
662  meta->SetBranchAddress(edm::poolNames::processConfigurationBranchName().c_str(), &pPhc);
663  }
664 
666  if(meta->FindBranch(edm::poolNames::processHistoryBranchName().c_str()) != 0) {
667  meta->SetBranchAddress(edm::poolNames::processHistoryBranchName().c_str(), &pPhv);
668  }
669 
671  edm::ProcessHistoryMap* pPhm = &phm;
672  if(meta->FindBranch(edm::poolNames::processHistoryMapBranchName().c_str()) != 0) {
673  meta->SetBranchAddress(edm::poolNames::processHistoryMapBranchName().c_str(), &pPhm);
674  }
675 
676  if(meta->FindBranch(edm::poolNames::moduleDescriptionMapBranchName().c_str()) != 0) {
677  if(meta->GetBranch(edm::poolNames::moduleDescriptionMapBranchName().c_str())->GetSplitLevel() != 0) {
678  meta->SetBranchStatus((edm::poolNames::moduleDescriptionMapBranchName() + ".*").c_str(), 0);
679  } else {
680  meta->SetBranchStatus(edm::poolNames::moduleDescriptionMapBranchName().c_str(), 0);
681  }
682  }
683 
684  meta->GetEntry(0);
685  assert(0 != pReg);
686 
688  for(ParameterSetMap::const_iterator i = psm_.begin(), iEnd = psm_.end(); i != iEnd; ++i) {
689  edm::ParameterSet pset(i->second.pset());
690  pset.setID(i->first);
691  psetRegistry.insertMapped(pset);
692  }
693 
694 
695  // backward compatibility
696  if(!phm.empty()) {
697  for(edm::ProcessHistoryMap::const_iterator i = phm.begin(), e = phm.end(); i != e; ++i) {
698  phv_.push_back(i->second);
699  for(edm::ProcessConfigurationVector::const_iterator j = i->second.begin(), f = i->second.end(); j != f; ++j) {
700  phc_.push_back(*j);
701  }
702  }
704  phc_.erase(std::unique(phc_.begin(), phc_.end()), phc_.end());
705  }
706 
708 
709  //Prepare the parentage information if requested
710  std::map<edm::BranchID, std::set<edm::ParentageID> > perProductParentage;
711 
712  if(showDependencies_){
713  TTree* parentageTree = dynamic_cast<TTree*>(inputFile_->Get(edm::poolNames::parentageTreeName().c_str()));
714  if(0 == parentageTree) {
715  std::cerr << "no Parentage tree available so can not show dependencies/n";
716  showDependencies_ = false;
717  } else {
718 
720 
721  std::vector<edm::ParentageID> orderedParentageIDs;
722  orderedParentageIDs.reserve(parentageTree->GetEntries());
723  for(Long64_t i = 0, numEntries = parentageTree->GetEntries(); i < numEntries; ++i) {
724  edm::Parentage parentageBuffer;
725  edm::Parentage *pParentageBuffer = &parentageBuffer;
726  parentageTree->SetBranchAddress(edm::poolNames::parentageBranchName().c_str(), &pParentageBuffer);
727  parentageTree->GetEntry(i);
728  registry.insertMapped(parentageBuffer);
729  orderedParentageIDs.push_back(parentageBuffer.id());
730  }
731  parentageTree->SetBranchAddress(edm::poolNames::parentageBranchName().c_str(), 0);
732 
733  TTree* eventMetaTree = dynamic_cast<TTree*>(inputFile_->Get(edm::BranchTypeToMetaDataTreeName(edm::InEvent).c_str()));
734  if(0 == eventMetaTree) {
735  eventMetaTree = dynamic_cast<TTree*>(inputFile_->Get(edm::BranchTypeToProductTreeName(edm::InEvent).c_str()));
736  }
737  if(0 == eventMetaTree) {
738  std::cerr << "no '" << edm::BranchTypeToProductTreeName(edm::InEvent)<< "' Tree in file so can not show dependencies\n";
739  showDependencies_ = false;
740  } else {
741  TBranch* storedProvBranch = eventMetaTree->GetBranch(edm::BranchTypeToProductProvenanceBranchName(edm::InEvent).c_str());
742 
743  if(0!=storedProvBranch) {
744  std::vector<edm::StoredProductProvenance> info;
745  std::vector<edm::StoredProductProvenance>* pInfo = &info;
746  storedProvBranch->SetAddress(&pInfo);
747  for(Long64_t i = 0, numEntries = eventMetaTree->GetEntries(); i < numEntries; ++i) {
748  storedProvBranch->GetEntry(i);
749  for(std::vector<edm::StoredProductProvenance>::const_iterator it = info.begin(), itEnd = info.end();
750  it != itEnd; ++it) {
751  edm::BranchID bid(it->branchID_);
752  perProductParentage[bid].insert(orderedParentageIDs[it->parentageIDIndex_]);
753  }
754  }
755  } else {
756  //backwards compatible check
757  TBranch* productProvBranch = eventMetaTree->GetBranch(edm::BranchTypeToBranchEntryInfoBranchName(edm::InEvent).c_str());
758  if (0 != productProvBranch) {
759  std::vector<edm::ProductProvenance> info;
760  std::vector<edm::ProductProvenance>* pInfo = &info;
761  productProvBranch->SetAddress(&pInfo);
762  for(Long64_t i = 0, numEntries = eventMetaTree->GetEntries(); i < numEntries; ++i) {
763  productProvBranch->GetEntry(i);
764  for(std::vector<edm::ProductProvenance>::const_iterator it = info.begin(), itEnd = info.end();
765  it != itEnd; ++it) {
766  perProductParentage[it->branchID()].insert(it->parentageID());
767  }
768  }
769  } else {
770  std::cerr <<" could not find provenance information so can not show dependencies\n";
771  showDependencies_=false;
772  }
773  }
774  }
775  }
776  }
777 
778 
780 
782 
783  std::cout << "---------Producers with data in file---------" << std::endl;
784 
785  //using edm::ParameterSetID as the key does not work
786  // typedef std::map<edm::ParameterSetID, std::vector<edm::BranchDescription> > IdToBranches
787  ModuleToIdBranches moduleToIdBranches;
788  //IdToBranches idToBranches;
789 
790  std::map<edm::BranchID, std::string> branchIDToBranchName;
791 
792  for(edm::ProductRegistry::ProductList::const_iterator it =
793  reg_.productList().begin(), itEnd = reg_.productList().end();
794  it != itEnd;
795  ++it) {
796  //force it to rebuild the branch name
797  it->second.init();
798 
799  if(showDependencies_) {
800  branchIDToBranchName[it->second.branchID()] = it->second.branchName();
801  }
802  /*
803  std::cout << it->second.branchName()
804  << " id " << it->second.productID() << std::endl;
805  */
806  for(std::map<edm::ProcessConfigurationID, edm::ParameterSetID>::const_iterator
807  itId = it->second.parameterSetIDs().begin(),
808  itIdEnd = it->second.parameterSetIDs().end();
809  itId != itIdEnd;
810  ++itId) {
811 
812  std::stringstream s;
813  s << itId->second;
814  moduleToIdBranches[std::make_pair(it->second.processName(), it->second.moduleLabel())][s.str()].push_back(it->second);
815  //idToBranches[*itId].push_back(it->second);
816  }
817  }
818  for(ModuleToIdBranches::const_iterator it = moduleToIdBranches.begin(),
819  itEnd = moduleToIdBranches.end();
820  it != itEnd;
821  ++it) {
822  std::ostringstream sout;
823  sout << "Module: " << it->first.second << " " << it->first.first << std::endl;
824  IdToBranches const& idToBranches = it->second;
825  for(IdToBranches::const_iterator itIdBranch = idToBranches.begin(),
826  itIdBranchEnd = idToBranches.end();
827  itIdBranch != itIdBranchEnd;
828  ++itIdBranch) {
829  sout << " PSet id:" << itIdBranch->first << std::endl;
830  sout << " products: {" << std::endl;
831  std::set<edm::BranchID> branchIDs;
832  for(std::vector<edm::BranchDescription>::const_iterator itBranch = itIdBranch->second.begin(),
833  itBranchEnd = itIdBranch->second.end();
834  itBranch != itBranchEnd;
835  ++itBranch) {
836  sout << " " << itBranch->branchName() << std::endl;
837  branchIDs.insert(itBranch->branchID());
838  }
839  sout << " }" << std::endl;
840  edm::ParameterSetID psid(itIdBranch->first);
841  ParameterSetMap::const_iterator itpsm = psm_.find(psid);
842  if(psm_.end() == itpsm) {
843  ++errorCount_;
844  errorLog_ << "No ParameterSetID for " << psid << std::endl;
845  exitCode_ = 1;
846  } else {
847  sout << " parameters: ";
848  prettyPrint(sout, edm::ParameterSet((*itpsm).second.pset()), " ", " ");
849  sout << std::endl;
850  }
851  if(showDependencies_) {
853 
854  sout << " dependencies: {" << std::endl;
855  std::set<edm::ParentageID> parentageIDs;
856  for(std::set<edm::BranchID>::const_iterator itBranch = branchIDs.begin(), itBranchEnd = branchIDs.end();
857  itBranch != itBranchEnd;
858  ++itBranch) {
859  std::set<edm::ParentageID> const& temp = perProductParentage[*itBranch];
860  parentageIDs.insert(temp.begin(), temp.end());
861  }
862  for(std::set<edm::ParentageID>::const_iterator itParentID = parentageIDs.begin(), itEndParentID = parentageIDs.end();
863  itParentID != itEndParentID;
864  ++itParentID) {
865  edm::Parentage const* parentage = registry.getMapped(*itParentID);
866  if(0 != parentage) {
867  for(std::vector<edm::BranchID>::const_iterator itBranch = parentage->parents().begin(), itEndBranch = parentage->parents().end();
868  itBranch != itEndBranch;
869  ++itBranch) {
870  sout << " " << branchIDToBranchName[*itBranch] << std::endl;
871  }
872  } else {
873  sout << " ERROR:parentage info not in registry ParentageID=" << *itParentID << std::endl;
874  }
875  }
876  if(parentageIDs.empty()) {
877  sout << " no dependencies recorded (event may not contain data from this module)" << std::endl;
878  }
879  sout << " }" << std::endl;
880  }
881  if(findMatch_.empty() or sout.str().find(findMatch_) != std::string::npos) {
882  std::cout <<sout.str()<<std::endl;
883  }
884  }
885  }
886  if(showOtherModules_) {
887  std::cout << "---------Other Modules---------" << std::endl;
888  historyGraph_.printOtherModulesHistory(psm_, moduleToIdBranches, findMatch_, errorLog_);
889  }
890 
891  if(!excludeESModules_) {
892  std::cout << "---------EventSetup---------" << std::endl;
893  historyGraph_.printEventSetupHistory(psm_, findMatch_, errorLog_);
894  }
895 
896  if(showTopLevelPSets_) {
897  std::cout << "---------Top Level PSets---------" << std::endl;
898  historyGraph_.printTopLevelPSetsHistory(psm_, findMatch_, errorLog_);
899  }
900  if(errorCount_ != 0) {
901  exitCode_ = 1;
902  }
903 }
904 
905 static char const* const kSortOpt = "sort";
906 static char const* const kSortCommandOpt = "sort,s";
907 static char const* const kDependenciesOpt = "dependencies";
908 static char const* const kDependenciesCommandOpt = "dependencies,d";
909 static char const* const kExcludeESModulesOpt = "excludeESModules";
910 static char const* const kExcludeESModulesCommandOpt = "excludeESModules,e";
911 static char const* const kShowAllModulesOpt = "showAllModules";
912 static char const* const kShowAllModulesCommandOpt = "showAllModules,a";
913 static char const* const kFindMatchOpt = "findMatch";
914 static char const* const kFindMatchCommandOpt = "findMatch,f";
915 static char const* const kShowTopLevelPSetsOpt = "showTopLevelPSets";
916 static char const* const kShowTopLevelPSetsCommandOpt ="showTopLevelPSets,t";
917 static char const* const kHelpOpt = "help";
918 static char const* const kHelpCommandOpt = "help,h";
919 static char const* const kFileNameOpt = "input-file";
920 static char const* const kFileNameCommandOpt = "input-file";
921 
922 int main(int argc, char* argv[]) {
923  using namespace boost::program_options;
924 
925  std::string descString(argv[0]);
926  descString += " [options] <filename>";
927  descString += "\nAllowed options";
928  options_description desc(descString);
929  desc.add_options()
930  (kHelpCommandOpt, "show help message")
931  (kSortCommandOpt
932  , "alphabetially sort EventSetup components")
934  , "print what data each EDProducer is dependent upon")
935  (kExcludeESModulesCommandOpt
936  , "do not print ES module information")
938  , "show all modules (not just those that created data in the file)")
939  (kShowTopLevelPSetsCommandOpt,"show all top level PSets")
940  (kFindMatchCommandOpt, boost::program_options::value<std::string>(),
941  "show only modules whose information contains the matching string")
942  ;
943  //we don't want users to see these in the help messages since this
944  // name only exists since the parser needs it
945  options_description hidden;
946  hidden.add_options()(kFileNameOpt, value<std::string>(), "file name");
947 
948  //full list of options for the parser
949  options_description cmdline_options;
950  cmdline_options.add(desc).add(hidden);
951 
952  positional_options_description p;
953  p.add(kFileNameOpt, -1);
954 
955  variables_map vm;
956  try {
957  store(command_line_parser(argc, argv).options(cmdline_options).positional(p).run(), vm);
958  notify(vm);
959  } catch(error const& iException) {
960  std::cerr << iException.what();
961  return 1;
962  }
963 
964  if(vm.count(kHelpOpt)) {
965  std::cout << desc << std::endl;
966  return 0;
967  }
968 
969  if(vm.count(kSortOpt)) {
970  HistoryNode::sort_ = true;
971  }
972 
973  bool showDependencies = false;
974  if(vm.count(kDependenciesOpt)) {
975  showDependencies = true;
976  }
977 
978  bool excludeESModules = false;
979  if(vm.count(kExcludeESModulesOpt)) {
980  excludeESModules = true;
981  }
982 
983  bool showAllModules = false;
984  if(vm.count(kShowAllModulesOpt)) {
985  showAllModules = true;
986  }
987 
988  bool showTopLevelPSets = false;
989  if(vm.count(kShowTopLevelPSetsOpt)) {
990  showTopLevelPSets=true;
991  }
992 
993  std::string fileName;
994  if(vm.count(kFileNameOpt)) {
995  try {
996  fileName = vm[kFileNameOpt].as<std::string>();
997  } catch(boost::bad_any_cast const& e) {
998  std::cout << e.what() << std::endl;
999  return 2;
1000  }
1001  } else {
1002  std::cout << "Data file not specified." << std::endl;
1003  std::cout << desc << std::endl;
1004  return 2;
1005  }
1006 
1007  std::string findMatch;
1008  if(vm.count(kFindMatchOpt)) {
1009  try {
1010  findMatch = vm[kFindMatchOpt].as<std::string>();
1011  } catch(boost::bad_any_cast const& e) {
1012  std::cout << e.what() << std::endl;
1013  return 2;
1014  }
1015  }
1016 
1017  //silence ROOT warnings about missing dictionaries
1018  gErrorIgnoreLevel = kError;
1019 
1020  //make sure dictionaries can be used for reading
1021  ROOT::Cintex::Cintex::Enable();
1022 
1023  ProvenanceDumper dumper(fileName, showDependencies, excludeESModules, showAllModules, showTopLevelPSets, findMatch);
1024  int exitCode(0);
1025  try {
1026  dumper.dump();
1027  exitCode = dumper.exitCode();
1028  }
1029  catch (cms::Exception const& x) {
1030  std::cerr << "cms::Exception caught\n";
1031  std::cerr << x.what() << '\n';
1032  exitCode = 2;
1033  }
1034  catch (std::exception& x) {
1035  std::cerr << "std::exception caught\n";
1036  std::cerr << x.what() << '\n';
1037  exitCode = 3;
1038  }
1039  catch (...) {
1040  std::cerr << "Unknown exception caught\n";
1041  exitCode = 4;
1042  }
1043 
1044  dumper.printErrors(std::cerr);
1045  return exitCode;
1046 }
std::stringstream errorLog_
Definition: EdmProvDump.cc:465
collection_type::const_iterator const_iterator
virtual char const * what() const
Definition: Exception.cc:141
T getParameter(std::string const &) const
const_iterator begin() const
std::string const & idToParameterSetBlobsBranchName()
Definition: BranchType.cc:249
int i
Definition: DBlmapReader.cc:9
std::string const & BranchTypeToMetaDataTreeName(BranchType const &branchType)
Definition: BranchType.cc:106
static char const *const kDependenciesOpt
Definition: EdmProvDump.cc:907
std::string const & parentageTreeName()
Definition: BranchType.cc:158
static char const *const kFindMatchCommandOpt
Definition: EdmProvDump.cc:914
list parent
Definition: dbtoconf.py:74
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::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
static char const *const kShowTopLevelPSetsCommandOpt
Definition: EdmProvDump.cc:916
ParameterSetID id() const
static ThreadSafeRegistry * instance()
ParentageID id() const
Definition: Parentage.cc:20
std::string print(const Track &, edm::Verbosity=edm::Concise)
Track print utility.
Definition: print.cc:8
edm::ProductRegistry reg_
Definition: EdmProvDump.cc:467
ParameterSetMap psm_
Definition: EdmProvDump.cc:470
void dumpParameterSetForID_(edm::ParameterSetID const &id)
Definition: EdmProvDump.cc:567
bool getMapped(key_type const &k, value_type &result) const
static char const *const kHelpOpt
Definition: EdmProvDump.cc:917
HistoryNode historyGraph_
Definition: EdmProvDump.cc:471
ProcessHistoryRegistry::collection_type ProcessHistoryMap
std::string const & eventSelectionsBranchName()
Definition: BranchType.cc:237
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
void dumpEventFilteringParameterSets_(TFile *file)
Definition: EdmProvDump.cc:537
bool insertMapped(value_type const &v)
uint16_t size_type
ProvenanceDumper(std::string const &filename, bool showDependencies, bool excludeESModules, bool showAllModules, bool showTopLevelPSets, std::string const &findMatch)
Definition: EdmProvDump.cc:485
edm::ProcessHistoryVector phv_
Definition: EdmProvDump.cc:469
void fillProductRegistryTransients(std::vector< ProcessConfiguration > const &pcVec, ProductRegistry const &preg, bool okToRegister=false)
tuple node
Definition: Node.py:50
static ServiceToken createContaining(std::auto_ptr< T > iService)
create a service token that holds the service defined by iService
static char const *const kDependenciesCommandOpt
Definition: EdmProvDump.cc:908
std::vector< EventSelectionID > EventSelectionIDVector
static char const *const kHelpCommandOpt
Definition: EdmProvDump.cc:918
std::string const & parameterSetsTreeName()
Definition: BranchType.cc:245
void setID(ParameterSetID const &id) const
static char const *const kShowTopLevelPSetsOpt
Definition: EdmProvDump.cc:915
int main(int argc, char **argv)
ProcessConfigurationRegistry::vector_type ProcessConfigurationVector
std::vector< BranchID > const & parents() const
Definition: Parentage.h:38
ProductList const & productList() const
static char const *const kShowAllModulesCommandOpt
Definition: EdmProvDump.cc:912
ParameterSet const & pset() const
static char const *const kExcludeESModulesCommandOpt
Definition: EdmProvDump.cc:910
std::string const & processHistoryMapBranchName()
Definition: BranchType.cc:192
static char const *const kSortOpt
Definition: EdmProvDump.cc:905
EventSelectionIDVector const & eventSelectionIDs() const
Definition: History.h:42
static char const *const kExcludeESModulesOpt
Definition: EdmProvDump.cc:909
std::map< std::pair< std::string, std::string >, IdToBranches > ModuleToIdBranches
Definition: EdmProvDump.cc:40
void dumpEventFilteringParameterSets(edm::EventSelectionIDVector const &ids)
Definition: EdmProvDump.cc:519
std::string const & eventHistoryBranchName()
Definition: BranchType.cc:232
std::string findMatch_
Definition: EdmProvDump.cc:476
Long64_t numEntries(TFile *hdl, std::string const &trname)
Definition: CollUtil.cc:50
tuple result
Definition: query.py:137
static char const *const kSortCommandOpt
Definition: EdmProvDump.cc:906
std::string eventSetupComponent(char const *iType, std::string const &iCompName, edm::ParameterSet const &iProcessConfig, std::string const &iProcessName)
Definition: EdmProvDump.cc:161
int j
Definition: DBlmapReader.cc:9
std::string nonProducerComponent(std::string const &iCompName, edm::ParameterSet const &iProcessConfig, std::string const &iProcessName)
Definition: EdmProvDump.cc:227
double f[11][100]
ProcessHistoryRegistry::vector_type ProcessHistoryVector
std::string const & BranchTypeToBranchEntryInfoBranchName(BranchType const &branchType)
Definition: BranchType.cc:126
std::vector< ParameterSet > const & vpset() const
#define end
Definition: vmac.h:38
ProvenanceDumper & operator=(ProvenanceDumper const &)=delete
std::string const & metaDataTreeName()
Definition: BranchType.cc:167
std::string const & BranchTypeToProductTreeName(BranchType const &branchType)
Definition: BranchType.cc:102
std::unique_ptr< TFile > inputFile_
Definition: EdmProvDump.cc:463
std::string const & parameterSetMapBranchName()
Definition: BranchType.cc:182
static void appendToSet(std::set< std::string > &iSet, std::vector< std::string > const &iFrom)
Definition: EdmProvDump.cc:277
static std::ostream & prettyPrint(std::ostream &oStream, edm::ParameterSet const &iPSet, std::string const &iIndent, std::string const &iIndentDelta)
Definition: EdmProvDump.cc:414
std::string const & processHistoryBranchName()
Definition: BranchType.cc:197
std::map< std::string, std::vector< edm::BranchDescription > > IdToBranches
Definition: EdmProvDump.cc:39
void dumpProcessHistory_()
Definition: EdmProvDump.cc:589
edm::ProcessConfigurationVector phc_
Definition: EdmProvDump.cc:468
psettable const & psetTable() const
Definition: ParameterSet.h:258
void sort_all(RandomAccessSequence &s)
wrappers for std::sort
Definition: Algorithms.h:120
std::string filename_
Definition: EdmProvDump.cc:462
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
ParameterSet const & getParameterSet(std::string const &) const
static char const *const kShowAllModulesOpt
Definition: EdmProvDump.cc:911
std::string const & parentageBranchName()
Definition: BranchType.cc:162
tuple argc
Definition: dir2webdir.py:41
std::map< ParameterSetID, ParameterSetBlob > ParameterSetMap
std::string const & productDescriptionBranchName()
Definition: BranchType.cc:172
std::string const & processConfigurationBranchName()
Definition: BranchType.cc:202
const_iterator end() const
#define begin
Definition: vmac.h:31
author Stefano ARGIRO author Bill Tanenbaum
tuple events
Definition: patZpeak.py:19
vpsettable const & vpsetTable() const
Definition: ParameterSet.h:261
static char const *const kFileNameCommandOpt
Definition: EdmProvDump.cc:920
tuple filename
Definition: lut2db_cfg.py:20
static char const *const kFileNameOpt
Definition: EdmProvDump.cc:919
std::string const & BranchTypeToProductProvenanceBranchName(BranchType const &BranchType)
Definition: BranchType.cc:130
std::string const & eventTreeName()
Definition: BranchType.cc:254
tuple cout
Definition: gather_cfg.py:121
tuple fileNames
Definition: LaserDQM_cfg.py:34
Definition: DDAxes.h:10
std::string const & eventHistoryTreeName()
Definition: BranchType.cc:262
static Interceptor::Registry registry("Interceptor")
table const & tbl() const
Definition: ParameterSet.h:255
int exitCode() const
Definition: EdmProvDump.cc:514
tuple size
Write out results.
std::string const & moduleDescriptionMapBranchName()
Definition: BranchType.cc:187
static std::string topLevelPSet(std::string const &iName, edm::ParameterSet const &iProcessConfig, std::string const &iProcessName)
Definition: EdmProvDump.cc:283
void printErrors(std::ostream &os)
Definition: EdmProvDump.cc:509
static char const *const kFindMatchOpt
Definition: EdmProvDump.cc:913