Skip to content

Commit

Permalink
Add an EmptyEventCreator data source for testing and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Nov 16, 2021
1 parent efb4a5f commit ccb7d58
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
38 changes: 38 additions & 0 deletions source/include/marlin/EmptyEventCreator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#ifndef EmptyEventCreator_h
#define EmptyEventCreator_h 1

#include "marlin/DataSourceProcessor.h"

namespace marlin {

/** Creates empty LCIO Events that can then be populated by other processors.
* Useful for testing purposes and examples, where having a dedicated input
* just for "getting the event loop going" is not always practical. This needs
* to be the first active processor and additionally requires that there are no
* LCIO input collections present (i.e. make sure to not set the
* LCIOInputFiles parameter).
*
* <h4>Input</h4>
* None
*
* <h4>Output</4>
* an empty LCEvent
*
* @author: T. Madlener, DESY
*/
class EmptyEventCreator : public DataSourceProcessor {
public:
EmptyEventCreator();

marlin::Processor* newProcessor() override { return new EmptyEventCreator; }

void readDataSource(int numEvents) override;
void init() override;

private:
int m_eventNumber{0};
};

}

#endif
40 changes: 40 additions & 0 deletions source/src/EmptyEventCreator.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "marlin/EmptyEventCreator.h"

#include "marlin/ProcessorMgr.h"

#include "IMPL/LCEventImpl.h"
#include "IMPL/LCRunHeaderImpl.h"

#include <memory>

namespace marlin {
EmptyEventCreator anEmptyEventCreator;

EmptyEventCreator::EmptyEventCreator() : DataSourceProcessor("EmptyEventCreator") {
_description = "Creates empty events that can be filled by other processors";
}

void EmptyEventCreator::init() {
printParameters(); // Do we need to do anything at all?
}

void EmptyEventCreator::readDataSource(int numEvents) {
while (m_eventNumber < numEvents) {
if (isFirstEvent()) {
auto* runHeader = new LCRunHeaderImpl; // who cleans this up?
runHeader->setDescription("Empty events produced to be filled later");
runHeader->setRunNumber(0);

ProcessorMgr::instance()->processRunHeader(runHeader);
_isFirstEvent = false;
}

auto evt = std::make_unique<LCEventImpl>();
evt->setRunNumber(0);
evt->setEventNumber(m_eventNumber++);

ProcessorMgr::instance()->processEvent(evt.get());
}
}

} // namespace marlin

0 comments on commit ccb7d58

Please sign in to comment.