CMS 3D CMS Logo

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

Go to the documentation of this file.
00001 
00011 #include <iostream>
00012 #include <string>
00013 
00014 
00015 #include "FWCore/Framework/interface/Event.h"
00016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00017 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00018 #include "IOMC/Input/interface/HepMCFileReader.h" 
00019 #include "IOMC/Input/interface/MCFileSource.h"
00020 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
00021 
00022 namespace edm {
00023 
00024 //-------------------------------------------------------------------------
00025 MCFileSource::MCFileSource(const ParameterSet & pset, InputSourceDescription const& desc) :
00026   ProducerSourceFromFiles(pset, desc, false),
00027   reader_(HepMCFileReader::instance()), evt_(0)
00028 {
00029   LogInfo("MCFileSource") << "Reading HepMC file:" << fileNames()[0];
00030   std::string fileName = fileNames()[0];
00031   // strip the file: 
00032   if (fileName.find("file:") == 0){
00033     fileName.erase(0,5);
00034   }  
00035   
00036   reader_->initialize(fileName);  
00037   produces<HepMCProduct>();
00038 }
00039 
00040 
00041 //-------------------------------------------------------------------------
00042 MCFileSource::~MCFileSource(){
00043 }
00044 
00045 //-------------------------------------------------------------------------
00046 bool MCFileSource::setRunAndEventInfo(EventID&, TimeValue_t&) {
00047   // Read one HepMC event
00048   LogInfo("MCFileSource") << "Start Reading";
00049   evt_ = reader_->fillCurrentEventData(); 
00050   return(evt_ != nullptr);
00051 }
00052 
00053 //-------------------------------------------------------------------------
00054 void MCFileSource::produce(Event &e) {
00055   // Store one HepMC event in the Event.
00056 
00057   std::auto_ptr<HepMCProduct> bare_product(new HepMCProduct());  
00058   bare_product->addHepMCData(evt_);
00059   e.put(bare_product);
00060 }
00061 
00062 }