#include <string>
#include <vector>
#include <bitset>
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/Common/interface/View.h"
#if CMSSW_MAJOR_VERSION > 7 || (CMSSW_MAJOR_VERSION == 7 && CMSSW_MINOR_VERSION >= 4)
#include "DataFormats/HepMCCandidate/interface/GenStatusFlags.h"
#endif
: input_(config.getParameter<
edm::InputTag>(
"input")),
branch_(config.getParameter<
std::string>(
"branch")),
store_mothers_(config.getParameter<bool>("includeMothers")),
store_daughters_(config.getParameter<bool>("includeDaughters")),
store_statusFlags_(config.getParameter<bool>("includeStatusFlags")){
consumes<edm::View<reco::GenParticle>>(input_);
particles_ = new std::vector<ic::GenParticle>();
}
void ICGenParticleProducer::produce(edm::Event& event,
const edm::EventSetup& setup) {
edm::Handle<edm::View<reco::GenParticle> > parts_handle;
event.getByLabel(input_, parts_handle);
particles_->clear();
for (unsigned i = 0; i < parts_handle->size(); ++i) {
reco::GenParticle const& src = parts_handle->at(i);
dest.
set_id(particle_hasher_(&src));
dest.
set_index(static_cast<int>((parts_handle->refAt(i).key())));
#if CMSSW_MAJOR_VERSION > 7 || (CMSSW_MAJOR_VERSION == 7 && CMSSW_MINOR_VERSION >= 4 )
if (store_statusFlags_){
reco::GenStatusFlags statusflags = src.statusFlags();
if(statusflags.flags_.size()!=15){
throw cms::Exception("OptionNotSupported")<<"size of status flags bitset is "<<statusflags.flags_.size()<<" which is different to what was expected\n";
}
else{
std::vector<bool> statusflags_;
for(unsigned iFlag=0;iFlag<statusflags.flags_.size();iFlag++){
statusflags_.push_back(statusflags.flags_[iFlag]);
}
}
}
#endif
if (store_mothers_) {
std::vector<int> mothers(src.motherRefVector().size(), 0);
for (unsigned j = 0; j < src.motherRefVector().size(); ++j) {
mothers[j] = static_cast<int>(src.motherRefVector().at(j).key());
}
}
if (store_daughters_) {
std::vector<int> daughters(src.daughterRefVector().size(), 0);
for (unsigned j = 0; j < src.daughterRefVector().size(); ++j) {
daughters[j] = static_cast<int>(src.daughterRefVector().at(j).key());
}
}
}
}
void ICGenParticleProducer::beginJob() {
#if !(CMSSW_MAJOR_VERSION > 7 || (CMSSW_MAJOR_VERSION == 7 && CMSSW_MINOR_VERSION >= 4))
if(store_statusFlags_){
throw cms::Exception("OptionNotSupported")<<"status flags not supported for CMSSW versions before 7_4_X\n";
}
#endif
}
void ICGenParticleProducer::endJob() {}