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) prescale_ = 1;
48  }
49 
51  LogAbsolute("AsciiOut") << ">>> processed " << counter_ << " events" << std::endl;
52  }
53 
54  void
56 
57  if ((++counter_ % prescale_) != 0 || verbosity_ <= 0) 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) return;
63 
64  // Write out non-EDProduct contents...
65 
66  // ... list of process-names
67  for (auto const& process : e.processHistory()) {
68  LogAbsolute("AsciiOut") << process.processName() << " ";
69  }
70 
71  // ... collision id
72  LogAbsolute("AsciiOut") << '\n' << e.id() << '\n';
73 
74  // Loop over products, and write some output for each...
76  for(auto const& prod: reg->productList()) {
77  BranchDescription const& desc = prod.second;
78  if(selected(desc)) {
79  if(desc.isAlias()) {
80  LogAbsolute("AsciiOut") << "ModuleLabel " << desc.moduleLabel() << " is an alias for";
81  }
82 
83  auto const& prov = e.getProvenance(desc.originalBranchID());
84  LogAbsolute("AsciiOut") << prov;
85 
86  if(verbosity_ > 2) {
87  BranchDescription const& desc2 = prov.branchDescription();
88  std::string const& process = desc2.processName();
89  std::string const& label = desc2.moduleLabel();
90  ProcessHistory const* processHistory = prov.processHistoryPtr();
91 
92  if (processHistory) {
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  }
111 
112  void
115  desc.setComment("Outputs event information into text file.");
116  desc.addUntracked("prescale", 1U)
117  ->setComment("prescale factor");
118  desc.addUntracked("verbosity", 1U)
119  ->setComment("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 }
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)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::string const & processName() const
void writeRun(RunForOutput const &) override
char const * label
void setComment(std::string const &value)
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:19
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:56
static Registry * instance()
Definition: Registry.cc:13