00001 // $Id: MCFileSource.cc,v 1.9 2007/05/29 21:00:00 weng Exp $ 00002 00013 #include <iostream> 00014 #include <string> 00015 00016 00017 #include "FWCore/Framework/interface/Event.h" 00018 #include "FWCore/MessageLogger/interface/MessageLogger.h" 00019 #include "FWCore/ParameterSet/interface/ParameterSet.h" 00020 #include "IOMC/Input/interface/HepMCFileReader.h" 00021 #include "IOMC/Input/interface/MCFileSource.h" 00022 #include "SimDataFormats/HepMCProduct/interface/HepMCProduct.h" 00023 00024 00025 using namespace edm; 00026 using namespace std; 00027 00028 00029 //------------------------------------------------------------------------- 00030 MCFileSource::MCFileSource(const ParameterSet & pset, InputSourceDescription const& desc) : 00031 ExternalInputSource(pset, desc), 00032 reader_(HepMCFileReader::instance()), evt_(0), 00033 useExtendedAscii_(pset.getUntrackedParameter<bool>("useExtendedAscii",false)) 00034 { 00035 edm::LogInfo("MCFileSource") << "Reading HepMC file:" << fileNames()[0]; 00036 string fileName = fileNames()[0]; 00037 // strip the file: 00038 if (fileName.find("file:") == 0){ 00039 fileName.erase(0,5); 00040 } 00041 00042 reader_->initialize(fileName, useExtendedAscii_); 00043 produces<HepMCProduct>(); 00044 } 00045 00046 00047 //------------------------------------------------------------------------- 00048 MCFileSource::~MCFileSource(){ 00049 } 00050 00051 00052 //------------------------------------------------------------------------- 00053 bool MCFileSource::produce(Event &e) { 00054 // Read one HepMC event and store it in the Event. 00055 00056 auto_ptr<HepMCProduct> bare_product(new HepMCProduct()); 00057 00058 edm::LogInfo("MCFileSource") << "Start Reading"; 00059 evt_ = reader_->fillCurrentEventData(); 00060 if (evt_ == 0) return false; 00061 00062 bare_product->addHepMCData(evt_); 00063 e.put(bare_product); 00064 00065 return true; 00066 }