Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 21 additions & 98 deletions Generators/include/Generators/AODToHepMC.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,25 +257,20 @@ struct AODToHepMC {
* framework::OptionManager<AODToHepMC> that propagates the options
* to the program.
*/
struct : framework::ConfigurableGroup {
struct {
/** Option for dumping HepMC event structures to disk. Takes one
* argument - the name of the file to write to. */
framework::Configurable<std::string> dump{"hepmc-dump", "",
"Dump HepMC event to output"};
std::string dump{""};
/** Option for only storing particles from the event generator.
* Note, if a particle is stored down, then its mothers will also
* be stored. */
framework::Configurable<bool> onlyGen{"hepmc-only-generated", false,
"Only export generated"};
bool onlyGen{false};
/** Use HepMC's tree parsing for building event structure */
framework::Configurable<bool> useTree{"hepmc-use-tree", false,
"Export as tree"};
bool useTree{false};
/** Floating point precision used when writing to disk */
framework::Configurable<int> precision{"hepmc-precision", 8,
"Export precision in dump"};
int precision{8};
/** Recenter event at IP=(0,0,0,0). */
framework::Configurable<bool> recenter{"hepmc-recenter", false,
"Recenter the events at (0,0,0,0)"};
bool recenter{false};
} configs;
/**
* @{
Expand Down Expand Up @@ -585,99 +580,27 @@ struct AODToHepMC {

namespace framework
{
/**
* This specialisation of o2::framework::OutputManager ensures that
* we can call the post-processing routine of o2::eventgen::AODToHepMC
* and thus ensure that the possible HepMC is written to disk.
*
* The O2 framework (via o2::framework::adoptAnalysisTask<T>) inspects
* the members of the passed class (@c T) and creates
* o2::framework::OutputManager callbacks for every member. The
* default template for this does nothing.
*
* Thus, to delegate a call to a member of the analysis task (of class
* @c T), we can specialise the @c o2::framework::OutputManager
* template on the @e member type. We will then effectively have
* call-backs for
*
* - @c appendOutput - when the task is constructed
* - @c prepare - when a new set of data is recieved
* - @c finalize - when a set of data has been processed
* - @c postRun - when the run is over
*
* Concretely, we use the @c postRun to flush the HepMC data file
* to disk.
*
* For this to work, the AODToHepMC object must be a member of the
* "Task" class, e.g.,
*
* @code
* struct Task {
* o2::eventgen::AODToHepMC mConverter;
* ...
* };
*
* WorkflowSpec defineDataProcessing(ConfigContext const& cfg) {
* return WorkflowSpec{adaptAnalysisTask<Task>(cfg)};
* }
* @endcode
*/
template <>
struct OutputManager<eventgen::AODToHepMC> {
/** Type of the target */
using Target = eventgen::AODToHepMC;
/** Called when task is constructed */
static bool appendOutput(std::vector<OutputSpec>&, Target&, uint32_t) { return true; }
/** Called when new data is received */
static bool prepare(ProcessingContext&, Target&) { return true; }
/** Called when all data has been received */
static bool postRun(EndOfStreamContext&, Target& t) { return t.postRun(); }
/** Called when the job finishes */
static bool finalize(ProcessingContext&, Target& t) { return true; }
};
struct AODToHepMCPostRun {
static AODToHepMCPostRun& instance()
{
static AODToHepMCPostRun inst{};
return inst;
}

/**
* Spacialisation to pull in configurables from the converter.
*
* Ideally, the converter should simply derive from ConfigurableGroup
* and all should flow automatically, but that doesn't work for some
* reason.
*
* For this to work, the AODToHepMC object must be a member of the
* "Task" class, e.g.,
*
* @code
* struct Task {
* o2::eventgen::AODToHepMC mConverter;
* ...
* };
*
* WorkflowSpec defineDataProcessing(ConfigContext const& cfg) {
* return WorkflowSpec{adaptAnalysisTask<Task>(cfg)};
* }
* @endcode
*/
template <>
struct OptionManager<eventgen::AODToHepMC> {
/** type of the target */
using Target = eventgen::AODToHepMC;
/** Called when the task is constructed */
static bool
appendOption(std::vector<o2::framework::ConfigParamSpec>& options,
Target& target)
AODToHepMCPostRun(eventgen::AODToHepMC* ptr_ = nullptr)
: ptr{ptr_}
{
OptionManager<ConfigurableGroup>::appendOption(options, target.configs);
return true;
}
/** Called when options are processed */
static bool
prepare(o2::framework::InitContext& ic, Target& target)

void endOfStream()
{
OptionManager<ConfigurableGroup>::prepare(ic, target.configs);
return true;
if (ptr != nullptr) {
ptr->postRun();
}
}
};

eventgen::AODToHepMC* ptr = nullptr;
};
} // namespace framework
} // namespace o2

Expand Down
28 changes: 27 additions & 1 deletion run/o2aod_mc_to_hepmc.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,33 @@ struct AodToHepmc {
/** Alias the converter type */
using Converter = o2::eventgen::AODToHepMC;

struct : o2::framework::ConfigurableGroup {
/** Option for dumping HepMC event structures to disk. Takes one
* argument - the name of the file to write to. */
o2::framework::Configurable<std::string> dump{"hepmc-dump", "",
"Dump HepMC event to output"};
/** Option for only storing particles from the event generator.
* Note, if a particle is stored down, then its mothers will also
* be stored. */
o2::framework::Configurable<bool> onlyGen{"hepmc-only-generated", false,
"Only export generated"};
/** Use HepMC's tree parsing for building event structure */
o2::framework::Configurable<bool> useTree{"hepmc-use-tree", false,
"Export as tree"};
/** Floating point precision used when writing to disk */
o2::framework::Configurable<int> precision{"hepmc-precision", 8,
"Export precision in dump"};
/** Recenter event at IP=(0,0,0,0). */
o2::framework::Configurable<bool> recenter{"hepmc-recenter", false,
"Recenter the events at (0,0,0,0)"};
} configs;

/** Our converter */
Converter mConverter;

/** Post-run trigger service **/
o2::framework::Service<o2::framework::AODToHepMCPostRun> trigger;

/** @{
* @name Container types */
/** Alias converter header table type */
Expand All @@ -75,9 +99,11 @@ struct AodToHepmc {
/** @} */

/** Initialize the job */
void init(o2::framework::InitContext& ic)
void init(o2::framework::InitContext&)
{
mConverter.configs = {(std::string)configs.dump, (bool)configs.onlyGen, (bool)configs.useTree, (int)configs.precision, (bool)configs.recenter};
mConverter.init();
trigger->ptr = &mConverter;
}
/** Processing of event to extract extra HepMC information
*
Expand Down