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

Merge branch 'lintao/gen/index' into 'master'

StdHepRdr: Add StartIndex.

See merge request !137
parents a8517ccf e7316103
No related branches found
No related tags found
No related merge requests found
#ifndef GenReader_h
#define GenReader_h 1
/*
* GenReader is a base class for the gentools which load events from file
*/
#include "GenEvent.h"
#include "IGenTool.h"
using namespace std;
class GenReader: virtual public IGenTool{
public:
~GenReader();
virtual ~GenReader() = 0;
virtual bool configure_gentool()=0;
virtual bool mutate(MyHepMC::GenEvent& event)=0;
virtual bool finish()=0;
virtual bool isEnd()=0;
// The start index is used to skip the first n events.
// if start index is 0, then the first event is the first event in the file
virtual int startIndex() { return 0; };
};
#endif
......@@ -31,9 +31,9 @@ StdHepRdr::~StdHepRdr(){
}
bool StdHepRdr::mutate(MyHepMC::GenEvent& event){
++m_processed_event;
if(isEnd()) return false;
LCCollectionVec* mc_vec = m_stdhep_rdr->readEvent();
m_processed_event ++;
int n_mc = mc_vec->getNumberOfElements();
//std::cout<<"Debug: Read event :"<< m_processed_event <<", mc size :"<< n_mc <<std::endl;
std::map<int, int> pmcid_lmcid; // mapping between the obj idx in edm4hep and the idx in stdhep
......@@ -85,8 +85,12 @@ bool StdHepRdr::mutate(MyHepMC::GenEvent& event){
}
bool StdHepRdr::isEnd(){
if(m_processed_event == m_total_event) {std::cout<<"Have read all events, end now."<<std::endl; return true;}
else return false;
if(m_processed_event == m_total_event) {
std::cout<<"Have read all events, end now."<<std::endl;
return true;
} else {
return false;
}
}
bool StdHepRdr::configure_gentool(){
......@@ -96,8 +100,8 @@ bool StdHepRdr::configure_gentool(){
return false;
}
m_total_event = m_stdhep_rdr->getNumberOfEvents() - 1 ;
m_processed_event=0;
m_total_event = m_stdhep_rdr->getNumberOfEvents();
m_processed_event=-1;
return true;
}
......@@ -114,6 +118,18 @@ StdHepRdr::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;
if(isEnd()) return StatusCode::FAILURE;
LCCollectionVec* mc_vec = m_stdhep_rdr->readEvent();
delete mc_vec;
}
info() << "Skip the first " << startIndex() << " events." << endmsg;
}
return sc;
}
......@@ -126,3 +142,7 @@ StdHepRdr::finalize() {
}
return sc;
}
int StdHepRdr::startIndex(){
return m_startIndex.value();
}
\ No newline at end of file
......@@ -27,6 +27,8 @@ public:
bool mutate(MyHepMC::GenEvent& event) override;
bool finish() override;
bool isEnd() override;
int startIndex() override;
private:
lcio::LCStdHepRdrNew* m_stdhep_rdr{nullptr};
long m_total_event{-1};
......@@ -34,7 +36,8 @@ private:
// input file name
Gaudi::Property<std::string> m_filename{this, "Input"};
Gaudi::Property<double> m_starttime{this, "StartTime", 0, "Default start time"};
Gaudi::Property<double> m_starttime{this, "StartTime", 0, "Default start time"};
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