CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/IOMC/NtupleConverter/src/H2RootNtplSource.cc

Go to the documentation of this file.
00001 /* \author: Joanna Weng
00002 *  $Date: 1/2006
00003 */
00004 
00005 #include "IOMC/NtupleConverter/interface/NtupleROOTFile.h"
00006 #include "IOMC/NtupleConverter/interface/H2RootNtplSource.h"
00007 #include "IOMC/NtupleConverter/interface/Ntuple2HepMCFiller.h"
00008 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
00009 #include "FWCore/Framework/interface/Event.h"
00010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00011 #include <iostream>
00012 
00013 
00014 using namespace edm;
00015 using namespace std;
00016 
00017 //used for defaults
00018 
00019 H2RootNtplSource::H2RootNtplSource( const ParameterSet & pset, InputSourceDescription const& desc ) :
00020 ExternalInputSource(pset, desc),  
00021 evt(0), firstEvent_ (pset.getUntrackedParameter<unsigned int>("firstEvent",0)),
00022 reader_( Ntuple2HepMCFiller::instance() ){
00023         
00024 
00025         cout << "H2RootNtplSource: Reading HepMC file: " << fileNames()[0] << endl;
00026         string fileName = fileNames()[0];
00027         // strip the file: 
00028         if ( ! fileName.find("file:")){
00029           fileName.erase(0,5);
00030         }   
00031         //Max number of events processed  
00032         cout << "H2RootNtplSource: Number of events to be processed = " << maxEvents() << endl;
00033         
00034         //First event
00035         firstEvent_ = pset.getUntrackedParameter<unsigned int>("firstEvent",0);
00036         cout << "H2RootNtplSource: Number of first event  = " << firstEvent_ << endl;   
00037 
00038         reader_->initialize(fileName,101);  
00039         reader_->setEvent(firstEvent_);
00040         produces<HepMCProduct>();
00041 
00042 }
00043 
00044 
00045 H2RootNtplSource::~H2RootNtplSource(){
00046         clear();
00047 }
00048 
00049 void H2RootNtplSource::clear() {
00050 }
00051 
00052 bool H2RootNtplSource::produce(Event & e) {
00053         
00054 
00055         // no need to clean up GenEvent memory - now done in HepMCProduct
00056         //if ( evt != NULL ) delete evt ;
00057    
00058                 
00059                 auto_ptr<HepMCProduct> bare_product(new HepMCProduct());  
00060                 cout << "H2RootNtplSource: Start Reading  " << endl;
00061                 evt = reader_->fillCurrentEventData(); 
00062                 if(evt)  {
00063                   bare_product->addHepMCData(evt );
00064                   e.put(bare_product);
00065                   return true;
00066                 }
00067                 else return false;
00068         
00069         
00070 }
00071