Skip to content
Snippets Groups Projects
Commit e9be2cf5 authored by lintao@ihep.ac.cn's avatar lintao@ihep.ac.cn
Browse files

HepMCRdr: add StartIndex.

parent ae0e5f41
No related branches found
No related tags found
No related merge requests found
......@@ -25,14 +25,14 @@ using namespace edm4hep;
DECLARE_COMPONENT(HepMCRdr)
HepMCRdr::~HepMCRdr(){
delete ascii_in;
delete ascii_in;
}
bool HepMCRdr::mutate(MyHepMC::GenEvent& event){
++m_processed_event;
HepMC::GenEvent* evt = ascii_in->read_next_event();
if(!evt) return false;
m_processed_event ++;
int n_mc = evt->particles_size();
//std::cout<<"Read event :"<< m_processed_event <<", mc size :"<< n_mc <<std::endl;
std::map<int, int> pmcid_lmcid;
......@@ -93,13 +93,13 @@ bool HepMCRdr::mutate(MyHepMC::GenEvent& event){
}
bool HepMCRdr::isEnd(){
return false;
return false;
}
bool HepMCRdr::configure_gentool(){
ascii_in = new HepMC::IO_GenEvent(m_filename.value().c_str(),std::ios::in);
m_processed_event=0;
m_processed_event=-1;
return true;
}
......@@ -115,6 +115,17 @@ HepMCRdr::initialize() {
return StatusCode::FAILURE;
}
// skip the first n events if startIndex is not 0.
if (startIndex() > 0) {
for (int i=0; i<startIndex(); ++i) {
++m_processed_event;
HepMC::GenEvent* evt = ascii_in->read_next_event();
if(!evt) break;
delete evt;
}
info() << "Skip the first " << startIndex() << " events." << endmsg;
}
return sc;
}
......@@ -127,3 +138,7 @@ HepMCRdr::finalize() {
}
return sc;
}
int HepMCRdr::startIndex(){
return m_startIndex.value();
}
\ No newline at end of file
......@@ -23,6 +23,8 @@ class HepMCRdr: public extends<AlgTool, GenReader> {
bool mutate(MyHepMC::GenEvent& event);
bool finish();
bool isEnd();
int startIndex() override;
private:
HepMC::IO_GenEvent *ascii_in{nullptr};
long m_total_event{-1};
......@@ -30,6 +32,7 @@ class HepMCRdr: public extends<AlgTool, GenReader> {
// input file name
Gaudi::Property<std::string> m_filename{this, "Input"};
Gaudi::Property<int> m_startIndex{this, "StartIndex", 0, "Default start index"};
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment