CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/IOMC/Input/src/MCFileSource.cc

Go to the documentation of this file.
00001 // $Id: MCFileSource.cc,v 1.16 2009/12/01 19:23:11 fabstoec 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/GeneratorProducts/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 {
00034   edm::LogInfo("MCFileSource") << "Reading HepMC file:" << fileNames()[0];
00035   string fileName = fileNames()[0];
00036   // strip the file: 
00037   if (fileName.find("file:") == 0){
00038     fileName.erase(0,5);
00039   }  
00040   
00041   reader_->initialize(fileName);  
00042   produces<HepMCProduct>();
00043 }
00044 
00045 
00046 //-------------------------------------------------------------------------
00047 MCFileSource::~MCFileSource(){
00048 }
00049 
00050 
00051 //-------------------------------------------------------------------------
00052 bool MCFileSource::produce(Event &e) {
00053   // Read one HepMC event and store it in the Event.
00054 
00055   auto_ptr<HepMCProduct> bare_product(new HepMCProduct());  
00056 
00057   edm::LogInfo("MCFileSource") << "Start Reading";
00058   evt_ = reader_->fillCurrentEventData(); 
00059   if (evt_ == 0) return false;
00060 
00061   bare_product->addHepMCData(evt_);
00062   e.put(bare_product);
00063 
00064   return true;
00065 }