CMS 3D CMS Logo

AsciiOutputModule.cc
Go to the documentation of this file.
1 /*----------------------------------------------------------------------
2 ----------------------------------------------------------------------*/
3 
4 #include <algorithm>
5 #include <iterator>
6 #include <ostream>
7 #include <iostream>
8 #include <string>
20 
21 namespace edm {
22 
23  class ModuleCallingContext;
24 
26  public:
27  // We do not take ownership of passed stream.
28  explicit AsciiOutputModule(ParameterSet const& pset);
29  ~AsciiOutputModule() override;
30  static void fillDescriptions(ConfigurationDescriptions& descriptions);
31 
32  private:
33  void write(EventForOutput const& e) override;
35  void writeRun(RunForOutput const&) override {}
36  int prescale_;
38  int counter_;
39  };
40 
42  : global::OutputModuleBase(pset),
43  global::OutputModule<>(pset),
44  prescale_(pset.getUntrackedParameter<unsigned int>("prescale")),
45  verbosity_(pset.getUntrackedParameter<unsigned int>("verbosity")),
46  counter_(0) {
47  if (prescale_ == 0)
48  prescale_ = 1;
49  }
50 
52  LogAbsolute("AsciiOut") << ">>> processed " << counter_ << " events" << std::endl;
53  }
54 
56  if ((++counter_ % prescale_) != 0 || verbosity_ <= 0)
57  return;
58 
59  // RunForOutput const& run = evt.getRun(); // this is still unused
60  LogAbsolute("AsciiOut") << ">>> processing event # " << e.id() << " time " << e.time().value() << std::endl;
61 
62  if (verbosity_ <= 1)
63  return;
64 
65  // Write out non-EDProduct contents...
66 
67  // ... list of process-names
68  for (auto const& process : e.processHistory()) {
69  LogAbsolute("AsciiOut") << process.processName() << " ";
70  }
71 
72  // ... collision id
73  LogAbsolute("AsciiOut") << '\n' << e.id() << '\n';
74 
75  // Loop over products, and write some output for each...
77  for (auto const& prod : reg->productList()) {
78  BranchDescription const& desc = prod.second;
79  if (selected(desc)) {
80  if (desc.isAlias()) {
81  LogAbsolute("AsciiOut") << "ModuleLabel " << desc.moduleLabel() << " is an alias for";
82  }
83 
84  auto const& prov = e.getProvenance(desc.originalBranchID());
85  LogAbsolute("AsciiOut") << prov;
86 
87  if (verbosity_ > 2) {
88  BranchDescription const& desc2 = prov.branchDescription();
89  std::string const& process = desc2.processName();
90  std::string const& label = desc2.moduleLabel();
91  ProcessHistory const* processHistory = prov.processHistoryPtr();
92 
93  if (processHistory) {
94  for (ProcessConfiguration const& pc : *processHistory) {
95  if (pc.processName() == process) {
96  ParameterSetID const& psetID = pc.parameterSetID();
97  pset::Registry const* psetRegistry = pset::Registry::instance();
98  ParameterSet const* processPset = psetRegistry->getMapped(psetID);
99  if (processPset) {
100  if (desc.isAlias()) {
101  LogAbsolute("AsciiOut") << "Alias PSet\n" << processPset->getParameterSet(desc.moduleLabel());
102  }
103  LogAbsolute("AsciiOut") << processPset->getParameterSet(label) << "\n";
104  }
105  }
106  }
107  }
108  }
109  }
110  }
111  }
112 
115  desc.setComment("Outputs event information into text file.");
116  desc.addUntracked("prescale", 1U)->setComment("prescale factor");
117  desc.addUntracked("verbosity", 1U)
118  ->setComment(
119  "0: no output\n"
120  "1: event ID and timestamp only\n"
121  "2: provenance for each kept product\n"
122  ">2: PSet and provenance for each kept product");
124  descriptions.add("asciiOutput", desc);
125  }
126 } // namespace edm
127 
void setComment(std::string const &value)
void writeLuminosityBlock(LuminosityBlockForOutput const &) override
virtual ProcessHistory const & processHistory() const
EventID const & id() const
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
static void fillDescriptions(ConfigurationDescriptions &descriptions)
std::string const & processName() const
void writeRun(RunForOutput const &) override
char const * label
void setComment(std::string const &value)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::string const & moduleLabel() const
bool selected(BranchDescription const &desc) const
static void fillDescription(ParameterSetDescription &desc, std::vector< std::string > const &iDefaultOutputCommands=ProductSelectorRules::defaultSelectionStrings())
Timestamp const & time() const
bool getMapped(key_type const &k, value_type &result) const
Definition: Registry.cc:17
AsciiOutputModule(ParameterSet const &pset)
Provenance getProvenance(BranchID const &theID) const
ParameterSet const & getParameterSet(std::string const &) const
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void write(EventForOutput const &e) override
HLT enums.
BranchID const & originalBranchID() const
TimeValue_t value() const
Definition: Timestamp.h:45
static Registry * instance()
Definition: Registry.cc:12