Project
Loading...
Searching...
No Matches
PublisherSpec.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
16#include "Headers/DataHeader.h"
17#include <memory>
18#include <utility>
19
20namespace o2
21{
22
23namespace emcal
24{
25
26o2::framework::DataProcessorSpec createPublisherSpec(PublisherConf const& config, uint32_t subspec, bool propagateMC, workflow_reader::Creator creator)
27{
28 struct ProcessAttributes {
29 std::shared_ptr<o2::framework::RootTreeReader> reader;
30 std::string datatype;
31 bool terminateOnEod;
32 bool finished;
33 };
34
35 auto initFunction = [config, subspec, propagateMC, creator](o2::framework::InitContext& ic) {
36 // get the option from the init context
37 auto filename = o2::utils::Str::concat_string(o2::utils::Str::rectifyDirectory(ic.options().get<std::string>("input-dir")),
38 ic.options().get<std::string>("infile"));
39 auto treename = ic.options().get<std::string>("treename");
40 auto dtbrName = ic.options().get<std::string>(config.databranch.option.c_str()); // databranch name
41 auto trgbrName = ic.options().get<std::string>(config.triggerrecordbranch.option.c_str()); // triggerbranch name
42 auto mcbrName = ic.options().get<std::string>(config.mcbranch.option.c_str()); // mcbranch name
43 auto nofEvents = ic.options().get<int>("nevents");
45
46 auto processAttributes = std::make_shared<ProcessAttributes>();
47 {
48 using Reader = o2::framework::RootTreeReader;
49 using TriggerInputType = std::vector<o2::emcal::TriggerRecord>;
50 processAttributes->terminateOnEod = ic.options().get<bool>("terminate-on-eod");
51 processAttributes->finished = false;
52 processAttributes->datatype = config.databranch.defval;
54 processAttributes->reader = creator(treename.c_str(), // tree name
55 filename.c_str(), // input file name
56 nofEvents, // number of entries to publish
57 publishingMode,
58 dtbrName.c_str(), // databranch name
59 trgbrName.c_str(), // triggerbranch name
60 mcbrName.c_str()); // mcbranch name
61 }
62
63 auto processFunction = [processAttributes, propagateMC](o2::framework::ProcessingContext& pc) {
64 if (processAttributes->finished) {
65 return;
66 }
67
68 auto publish = [&processAttributes, &pc, propagateMC]() {
69 if (processAttributes->reader->next()) {
70 (*processAttributes->reader)(pc);
71 } else {
72 processAttributes->reader.reset();
73 return false;
74 }
75 return true;
76 };
77
78 if (!publish()) {
79 pc.services().get<o2::framework::ControlService>().endOfStream();
80 pc.services().get<o2::framework::ControlService>().readyToQuit(framework::QuitRequest::Me);
81 }
82 };
83
84 return processFunction;
85 };
86
87 auto createOutputSpecs = [&config, subspec, propagateMC]() {
88 std::vector<o2::framework::OutputSpec> outputSpecs;
92 outputSpecs.emplace_back(o2::framework::OutputSpec{{"output"}, dto.origin, dto.description, subspec, o2::framework::Lifetime::Timeframe});
93 outputSpecs.emplace_back(o2::framework::OutputSpec{{"outputTRG"}, tro.origin, tro.description, subspec, o2::framework::Lifetime::Timeframe});
94 if (propagateMC) {
95 outputSpecs.emplace_back(o2::framework::OutputSpec{{"outputMC"}, mco.origin, mco.description, subspec, o2::framework::Lifetime::Timeframe});
96 }
97 return std::move(outputSpecs);
98 };
99
100 auto& dtb = config.databranch;
101 auto& mcb = config.mcbranch;
102 auto& trb = config.triggerrecordbranch;
104 config.processName.c_str(),
105 o2::framework::Inputs{}, // no inputs
106 {createOutputSpecs()},
107 o2::framework::AlgorithmSpec(initFunction),
109 {"infile", o2::framework::VariantType::String, config.defaultFileName, {"Name of the input file"}},
110 {"input-dir", o2::framework::VariantType::String, "none", {"Input directory"}},
111 {"treename", o2::framework::VariantType::String, config.defaultTreeName.c_str(), {"Name of input tree"}},
112 {dtb.option.c_str(), o2::framework::VariantType::String, dtb.defval.c_str(), {dtb.help.c_str()}},
113 {trb.option.c_str(), o2::framework::VariantType::String, trb.defval.c_str(), {trb.help.c_str()}},
114 {mcb.option.c_str(), o2::framework::VariantType::String, mcb.defval.c_str(), {mcb.help.c_str()}},
115 {"nevents", o2::framework::VariantType::Int, -1, {"number of events to run"}},
116 {"terminate-on-eod", o2::framework::VariantType::Bool, true, {"terminate on end-of-data"}},
117 }};
118}
119
120} // namespace emcal
121
122} // namespace o2
bool publish(std::string const &filename, std::string const &path, std::string CCDBpath)
Definition GRPTool.cxx:198
Definition of the Names Generator class.
std::function< std::shared_ptr< Reader >(const char *, const char *, int, Reader::PublishingMode, const char *, const char *, const char *)> Creator
framework::DataProcessorSpec createPublisherSpec(PublisherConf const &config, uint32_t subspec, bool propagateMC, workflow_reader::Creator creator)
GenericRootTreeReader< rtr::DefaultKey > RootTreeReader
@ Me
Only quit this data processor.
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > Inputs
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::string filename()
BranchOptionConfig triggerrecordbranch
BranchOptionConfig databranch
BranchOptionConfig mcbranch
static ConcreteDataTypeMatcher asConcreteDataTypeMatcher(OutputSpec const &spec)
uint32_t SubSpecificationType
Definition DataHeader.h:620
static std::string rectifyDirectory(const std::string_view p)
static std::string concat_string(Ts const &... ts)