Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:21:08

0001 /**  
0002 *  See header file for a description of this class.
0003 *
0004 *
0005 *  \author Jo. Weng  - CERN, Ph Division & Uni Karlsruhe
0006 *  \author F.Moortgat - CERN, Ph Division
0007 */
0008 
0009 #include <iostream>
0010 #include <string>
0011 
0012 #include "FWCore/Framework/interface/Event.h"
0013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0015 #include "IOMC/Input/interface/HepMCFileReader.h"
0016 #include "IOMC/Input/interface/MCFileSource.h"
0017 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
0018 #include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h"
0019 
0020 namespace edm {
0021 
0022   //-------------------------------------------------------------------------
0023   MCFileSource::MCFileSource(const ParameterSet& pset, InputSourceDescription const& desc)
0024       : ProducerSourceFromFiles(pset, desc, false), reader_(HepMCFileReader::instance()), evt_(nullptr) {
0025     LogInfo("MCFileSource") << "Reading HepMC file:" << fileNames(0)[0];
0026     std::string fileName = fileNames(0)[0];
0027     // strip the file:
0028     if (fileName.find("file:") == 0) {
0029       fileName.erase(0, 5);
0030     }
0031 
0032     reader_->initialize(fileName);
0033     produces<HepMCProduct>("generator");
0034     produces<GenEventInfoProduct>("generator");
0035   }
0036 
0037   //-------------------------------------------------------------------------
0038   MCFileSource::~MCFileSource() {}
0039 
0040   //-------------------------------------------------------------------------
0041   bool MCFileSource::setRunAndEventInfo(EventID&, TimeValue_t&, EventAuxiliary::ExperimentType&) {
0042     // Read one HepMC event
0043     LogInfo("MCFileSource") << "Start Reading";
0044     evt_ = reader_->fillCurrentEventData();
0045     return (evt_ != nullptr);
0046   }
0047 
0048   //-------------------------------------------------------------------------
0049   void MCFileSource::produce(Event& e) {
0050     // Store one HepMC event in the Event.
0051 
0052     auto bare_product = std::make_unique<HepMCProduct>();
0053     bare_product->addHepMCData(evt_);
0054     e.put(std::move(bare_product), "generator");
0055     std::unique_ptr<GenEventInfoProduct> info(new GenEventInfoProduct(evt_));
0056     e.put(std::move(info), "generator");
0057   }
0058 
0059 }  // namespace edm