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

HepevtRdr: add StartIndex and fix potential memory leakage.

parent d315d643
No related branches found
No related tags found
No related merge requests found
......@@ -22,7 +22,6 @@
using namespace lcio;
using namespace IMPL;
using namespace edm4hep;
using namespace std;
typedef enum HEPFILEFORMATS
{
......@@ -46,6 +45,19 @@ StatusCode HepevtRdr::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;
LCCollectionVec* mc_vec = m_hepevt_rdr->readEvent();
if(mc_vec==nullptr) {
break;
}
delete mc_vec;
}
info() << "Skip the first " << startIndex() << " events." << endmsg;
}
return sc;
}
......@@ -68,17 +80,17 @@ bool HepevtRdr::configure_gentool(){
}
m_hepevt_rdr = new UTIL::LCAscHepRdr(m_filename.value().c_str(), format);
m_processed_event=0;
m_processed_event=-1;
std::cout<<"initial hepevt_rdr"<<std::endl;
return true;
}
bool HepevtRdr::mutate(MyHepMC::GenEvent& event){
++m_processed_event;
LCCollectionVec* mc_vec = m_hepevt_rdr->readEvent();
if(mc_vec==nullptr) return false;
m_processed_event ++;
int n_mc = mc_vec->size();
std::cout<<"Read event :"<< m_processed_event <<", mc size :"<< n_mc <<std::endl;
info()<<"Read event :"<< m_processed_event <<", mc size :"<< n_mc <<endmsg;
std::map<int, int> pmcid_lmcid;
for (int i=0; i < n_mc; i++){
MCParticleImpl* mc = (MCParticleImpl*) mc_vec->getElementAt(i);
......@@ -108,19 +120,22 @@ bool HepevtRdr::mutate(MyHepMC::GenEvent& event){
const MCParticleVec & mc_daughters = mc->getDaughters();
auto pmc = event.m_mc_vec.at(i);
//std::cout<<"mc at "<< i<<", parent size "<<mc_parents.size() <<std::endl;
for(unsigned int j=0; j< mc_parents.size(); j++){int p_id = mc_parents.at(j)->id();
//std::cout<<"parent id "<<p_id<<std::endl;
pmc.addToParents( event.m_mc_vec.at( pmcid_lmcid.at(p_id) ) );
}
for(unsigned int j=0; j< mc_parents.size(); j++){
int p_id = mc_parents.at(j)->id();
//std::cout<<"parent id "<<p_id<<std::endl;
pmc.addToParents( event.m_mc_vec.at( pmcid_lmcid.at(p_id) ) );
}
//std::cout<<"mc at "<< i<<", daughter size "<<mc_daughters.size() <<std::endl;
for(unsigned int j=0; j< mc_daughters.size(); j++){int d_id = mc_daughters.at(j)->id();
//std::cout<<"daughter id "<<d_id<<std::endl;
pmc.addToDaughters( event.m_mc_vec.at( pmcid_lmcid.at(d_id) ) );
}
for(unsigned int j=0; j< mc_daughters.size(); j++){
int d_id = mc_daughters.at(j)->id();
//std::cout<<"daughter id "<<d_id<<std::endl;
pmc.addToDaughters( event.m_mc_vec.at( pmcid_lmcid.at(d_id) ) );
}
}
event.SetEventHeader( m_processed_event, -99, 9999, "Generator");
//std::cout<<"end event :"<< m_processed_event <<std::endl;
delete mc_vec;
return true;
}
......@@ -131,3 +146,7 @@ bool HepevtRdr::isEnd(){
bool HepevtRdr::finish(){
return true;
}
int HepevtRdr::startIndex(){
return m_startIndex.value();
}
\ No newline at end of file
......@@ -23,6 +23,8 @@ class HepevtRdr: public extends<AlgTool, GenReader> {
bool mutate(MyHepMC::GenEvent& event);
bool finish();
bool isEnd();
int startIndex() override;
private:
UTIL::LCAscHepRdr* m_hepevt_rdr = nullptr;
long m_total_event = -1;
......@@ -31,6 +33,7 @@ class HepevtRdr: public extends<AlgTool, GenReader> {
// input file name
Gaudi::Property<std::string> m_filename{this, "Input"};
Gaudi::Property<std::string> m_format{this, "Format"};
Gaudi::Property<int> m_startIndex{this, "StartIndex", 0, "Default start index"};
};
#endif
......
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