00001 /*---------------------------------------------------------------------- 00002 ----------------------------------------------------------------------*/ 00003 00004 #include <algorithm> 00005 #include <iterator> 00006 #include <ostream> 00007 #include <iostream> 00008 #include <string> 00009 #include "FWCore/Framework/interface/OutputModule.h" 00010 #include "FWCore/Framework/interface/EventPrincipal.h" 00011 #include "FWCore/Framework/interface/MakerMacros.h" 00012 #include "DataFormats/Provenance/interface/Provenance.h" 00013 #include "FWCore/ParameterSet/interface/ParameterSet.h" 00014 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" 00015 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h" 00016 #include "FWCore/MessageLogger/interface/MessageLogger.h" 00017 00018 namespace edm { 00019 class AsciiOutputModule : public OutputModule { 00020 public: 00021 // We do not take ownership of passed stream. 00022 explicit AsciiOutputModule(ParameterSet const& pset); 00023 virtual ~AsciiOutputModule(); 00024 static void fillDescriptions(ConfigurationDescriptions& descriptions); 00025 00026 private: 00027 virtual void write(EventPrincipal const& e); 00028 virtual void writeLuminosityBlock(LuminosityBlockPrincipal const&){} 00029 virtual void writeRun(RunPrincipal const&){} 00030 int prescale_; 00031 int verbosity_; 00032 int counter_; 00033 }; 00034 00035 AsciiOutputModule::AsciiOutputModule(ParameterSet const& pset) : 00036 OutputModule(pset), 00037 prescale_(pset.getUntrackedParameter<unsigned int>("prescale")), 00038 verbosity_(pset.getUntrackedParameter<unsigned int>("verbosity")), 00039 counter_(0) { 00040 if (prescale_ == 0) prescale_ = 1; 00041 } 00042 00043 AsciiOutputModule::~AsciiOutputModule() { 00044 LogAbsolute("AsciiOut") << ">>> processed " << counter_ << " events" << std::endl; 00045 } 00046 00047 void 00048 AsciiOutputModule::write(EventPrincipal const& e) { 00049 00050 if ((++counter_ % prescale_) != 0 || verbosity_ <= 0) return; 00051 00052 // Run const& run = evt.getRun(); // this is still unused 00053 LogAbsolute("AsciiOut")<< ">>> processing event # " << e.id() << " time " << e.time().value() << std::endl; 00054 00055 if (verbosity_ <= 1) return; 00056 00057 // Write out non-EDProduct contents... 00058 00059 // ... list of process-names 00060 for (ProcessHistory::const_iterator it = e.processHistory().begin(), itEnd = e.processHistory().end(); 00061 it != itEnd; ++it) { 00062 LogAbsolute("AsciiOut") << it->processName() << " "; 00063 } 00064 00065 // ... collision id 00066 LogAbsolute("AsciiOut") << '\n' << e.id() << '\n'; 00067 00068 // Loop over products, and write some output for each... 00069 00070 std::vector<Provenance const*> provs; 00071 e.getAllProvenance(provs); 00072 for(std::vector<Provenance const*>::const_iterator i = provs.begin(), 00073 iEnd = provs.end(); 00074 i != iEnd; 00075 ++i) { 00076 BranchDescription const& desc = (*i)->product(); 00077 if (selected(desc)) { 00078 LogAbsolute("AsciiOut") << **i << '\n'; 00079 } 00080 } 00081 } 00082 00083 void 00084 AsciiOutputModule::fillDescriptions(ConfigurationDescriptions& descriptions) { 00085 ParameterSetDescription desc; 00086 desc.setComment("Outputs event information into text file."); 00087 desc.addUntracked("prescale", 1U) 00088 ->setComment("prescale factor"); 00089 desc.addUntracked("verbosity", 1U) 00090 ->setComment("0: no output\n" 00091 "1: event ID and timestamp only\n" 00092 ">1: full output"); 00093 OutputModule::fillDescription(desc); 00094 descriptions.add("asciiOutput", desc); 00095 } 00096 } 00097 00098 using edm::AsciiOutputModule; 00099 DEFINE_FWK_MODULE(AsciiOutputModule);