Skip to content

Commit

Permalink
Loading filter rule dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
kjvbrt committed Nov 28, 2023
1 parent a79cb65 commit be4eff6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 12 deletions.
51 changes: 39 additions & 12 deletions k4Gen/src/components/GenEventFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
// Datamodel
#include "edm4hep/MCParticleCollection.h"

// ROOT
#include "TInterpreter.h"

DECLARE_COMPONENT(GenEventFilter)

GenEventFilter::GenEventFilter(
Expand Down Expand Up @@ -39,13 +42,41 @@ StatusCode GenEventFilter::initialize() {

m_eventProcessor = service("ApplicationMgr");

{
bool success = gInterpreter->Declare("#include \"edm4hep/MCParticleCollection.h\"");
if (!success) {
error() << "Unable to find edm4hep::MCParticleCollection header file!" << endmsg;
return StatusCode::FAILURE;
}
debug() << "Found edm4hep::MCParticleCollection header file." << endmsg;
}

{
bool success = gInterpreter->Declare("bool filterRule(const edm4hep::MCParticleCollection& inColl){return inColl.size() > 1000;}");
if (!success) {
error() << "Unable to compile filter rule!" << endmsg;
return StatusCode::FAILURE;
}
debug() << "Filter rule compiled successfully." << endmsg;
}

{
enum TInterpreter::EErrorCode err = TInterpreter::kProcessing;
m_filterRulePtr = (bool (*)(const edm4hep::MCParticleCollection*)) gInterpreter->ProcessLineSynch("&filterRule", &err);
if (err != TInterpreter::kNoError) {
error() << "Unable to obtain filter rule pointer!" << endmsg;
return StatusCode::FAILURE;
}
debug() << "Filter rule pointer obtained successfully." << endmsg;
}

return StatusCode::SUCCESS;
}

StatusCode GenEventFilter::execute() {
const edm4hep::MCParticleCollection* inParticles = m_inColl.get();
m_nEventsSeen++;
bool accept = true;

/*
int cntr = 0;
for (auto ptc : (*inParticles)) {
Expand All @@ -62,15 +93,7 @@ StatusCode GenEventFilter::execute() {
*/


Gaudi::Property<int> go;
go.assign(m_property->getProperty("Go"));
debug() << "Go: " << go << endmsg;

if (inParticles->size() < 1000) {
accept = false;
}

if (!accept) {
if (!(*m_filterRulePtr)(inParticles)) {
debug() << "Skipping event..." << endmsg;

{
Expand All @@ -97,9 +120,13 @@ StatusCode GenEventFilter::execute() {
<< endmsg;
debug() << "Remaining number of event to generate: "
<< m_nEventsTarget - m_nEventsAccepted << endmsg;
debug() << "Number of events seen: " << m_nEventsSeen << endmsg;
debug() << "Number of events seen so far: " << m_nEventsSeen << endmsg;

return StatusCode::SUCCESS;
}

StatusCode GenEventFilter::finalize() { return GaudiAlgorithm::finalize(); }
StatusCode GenEventFilter::finalize() {
debug() << "Number of events seen: " << m_nEventsSeen << endmsg;

return GaudiAlgorithm::finalize();
}
2 changes: 2 additions & 0 deletions k4Gen/src/components/GenEventFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class GenEventFilter : public GaudiAlgorithm {
SmartIF<IIncidentSvc> m_incidentSvc;
/// Pointer to the event processor.
SmartIF<IEventProcessor> m_eventProcessor;
/// Filter rule pointer.
bool (*m_filterRulePtr)(const edm4hep::MCParticleCollection*);
};

#endif // GENERATION_GENEVENTFILTER_H

0 comments on commit be4eff6

Please sign in to comment.