Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:12:48

0001 /*----------------------------------------------------------------------
0002 ----------------------------------------------------------------------*/
0003 
0004 #include <algorithm>
0005 #include <iterator>
0006 #include <ostream>
0007 #include <iostream>
0008 #include <string>
0009 #include "FWCore/Framework/interface/global/OutputModule.h"
0010 #include "FWCore/Framework/interface/EventForOutput.h"
0011 #include "FWCore/Framework/interface/MakerMacros.h"
0012 #include "DataFormats/Provenance/interface/Provenance.h"
0013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0014 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0015 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0017 #include "FWCore/ParameterSet/interface/Registry.h"
0018 #include "FWCore/ServiceRegistry/interface/Service.h"
0019 #include "FWCore/Framework/interface/ConstProductRegistry.h"
0020 
0021 namespace edm {
0022 
0023   class ModuleCallingContext;
0024 
0025   class AsciiOutputModule : public global::OutputModule<> {
0026   public:
0027     // We do not take ownership of passed stream.
0028     explicit AsciiOutputModule(ParameterSet const& pset);
0029     ~AsciiOutputModule() override;
0030     static void fillDescriptions(ConfigurationDescriptions& descriptions);
0031 
0032   private:
0033     void write(EventForOutput const& e) override;
0034     void writeLuminosityBlock(LuminosityBlockForOutput const&) override {}
0035     void writeRun(RunForOutput const&) override {}
0036     int prescale_;
0037     int verbosity_;
0038     int counter_;
0039   };
0040 
0041   AsciiOutputModule::AsciiOutputModule(ParameterSet const& pset)
0042       : global::OutputModuleBase(pset),
0043         global::OutputModule<>(pset),
0044         prescale_(pset.getUntrackedParameter<unsigned int>("prescale")),
0045         verbosity_(pset.getUntrackedParameter<unsigned int>("verbosity")),
0046         counter_(0) {
0047     if (prescale_ == 0)
0048       prescale_ = 1;
0049   }
0050 
0051   AsciiOutputModule::~AsciiOutputModule() {
0052     LogAbsolute("AsciiOut") << ">>> processed " << counter_ << " events" << std::endl;
0053   }
0054 
0055   void AsciiOutputModule::write(EventForOutput const& e) {
0056     if ((++counter_ % prescale_) != 0 || verbosity_ <= 0)
0057       return;
0058 
0059     // RunForOutput const& run = evt.getRun(); // this is still unused
0060     LogAbsolute("AsciiOut") << ">>> processing event # " << e.id() << " time " << e.time().value() << std::endl;
0061 
0062     if (verbosity_ <= 1)
0063       return;
0064 
0065     // Write out non-EDProduct contents...
0066 
0067     // ... list of process-names
0068     for (auto const& process : e.processHistory()) {
0069       LogAbsolute("AsciiOut") << process.processName() << " ";
0070     }
0071 
0072     // ... collision id
0073     LogAbsolute("AsciiOut") << '\n' << e.id() << '\n';
0074 
0075     // Loop over products, and write some output for each...
0076     Service<ConstProductRegistry> reg;
0077     for (auto const& prod : reg->productList()) {
0078       BranchDescription const& desc = prod.second;
0079       if (selected(desc)) {
0080         if (desc.isAlias()) {
0081           LogAbsolute("AsciiOut") << "ModuleLabel " << desc.moduleLabel() << " is an alias for";
0082         }
0083 
0084         auto const& prov = e.getProvenance(desc.originalBranchID());
0085         LogAbsolute("AsciiOut") << prov;
0086 
0087         if (verbosity_ > 2) {
0088           BranchDescription const& desc2 = prov.branchDescription();
0089           std::string const& process = desc2.processName();
0090           std::string const& label = desc2.moduleLabel();
0091           ProcessHistory const& processHistory = e.processHistory();
0092 
0093           for (ProcessConfiguration const& pc : processHistory) {
0094             if (pc.processName() == process) {
0095               ParameterSetID const& psetID = pc.parameterSetID();
0096               pset::Registry const* psetRegistry = pset::Registry::instance();
0097               ParameterSet const* processPset = psetRegistry->getMapped(psetID);
0098               if (processPset) {
0099                 if (desc.isAlias()) {
0100                   LogAbsolute("AsciiOut") << "Alias PSet\n" << processPset->getParameterSet(desc.moduleLabel());
0101                 }
0102                 LogAbsolute("AsciiOut") << processPset->getParameterSet(label) << "\n";
0103               }
0104             }
0105           }
0106         }
0107       }
0108     }
0109   }
0110 
0111   void AsciiOutputModule::fillDescriptions(ConfigurationDescriptions& descriptions) {
0112     ParameterSetDescription desc;
0113     desc.setComment("Outputs event information into text file.");
0114     desc.addUntracked("prescale", 1U)->setComment("prescale factor");
0115     desc.addUntracked("verbosity", 1U)
0116         ->setComment(
0117             "0: no output\n"
0118             "1: event ID and timestamp only\n"
0119             "2: provenance for each kept product\n"
0120             ">2: PSet and provenance for each kept product");
0121     OutputModule::fillDescription(desc);
0122     descriptions.add("asciiOutput", desc);
0123   }
0124 }  // namespace edm
0125 
0126 using edm::AsciiOutputModule;
0127 DEFINE_FWK_MODULE(AsciiOutputModule);