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 = e.processHistory();
92 
93  for (ProcessConfiguration const& pc : processHistory) {
94  if (pc.processName() == process) {
95  ParameterSetID const& psetID = pc.parameterSetID();
96  pset::Registry const* psetRegistry = pset::Registry::instance();
97  ParameterSet const* processPset = psetRegistry->getMapped(psetID);
98  if (processPset) {
99  if (desc.isAlias()) {
100  LogAbsolute("AsciiOut") << "Alias PSet\n" << processPset->getParameterSet(desc.moduleLabel());
101  }
102  LogAbsolute("AsciiOut") << processPset->getParameterSet(label) << "\n";
103  }
104  }
105  }
106  }
107  }
108  }
109  }
110 
113  desc.setComment("Outputs event information into text file.");
114  desc.addUntracked("prescale", 1U)->setComment("prescale factor");
115  desc.addUntracked("verbosity", 1U)
116  ->setComment(
117  "0: no output\n"
118  "1: event ID and timestamp only\n"
119  "2: provenance for each kept product\n"
120  ">2: PSet and provenance for each kept product");
121  OutputModule::fillDescription(desc);
122  descriptions.add("asciiOutput", desc);
123  }
124 } // namespace edm
125 
void writeLuminosityBlock(LuminosityBlockForOutput const &) override
bool getMapped(key_type const &k, value_type &result) const
Definition: Registry.cc:17
static void fillDescriptions(ConfigurationDescriptions &descriptions)
ParameterSet const & getParameterSet(std::string const &) const
std::string const & processName() const
bool selected(BranchDescription const &desc) const
void writeRun(RunForOutput const &) override
char const * label
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
AsciiOutputModule(ParameterSet const &pset)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void write(EventForOutput const &e) override
HLT enums.
Log< level::System, true > LogAbsolute
std::string const & moduleLabel() const
static Registry * instance()
Definition: Registry.cc:12