48 throw std::invalid_argument(
"need TPC sector and output id configuration");
51 enum struct SectorMode {
56 std::vector<int> sectors;
57 std::vector<int> outputIds;
58 std::vector<o2::header::DataHeader::SubSpecificationType> zeroLengthOutputs;
59 uint64_t activeSectors = 0;
60 std::array<std::shared_ptr<RootTreeReader>, NSectors> readers;
61 bool terminateOnEod =
false;
62 bool finished =
false;
63 SectorMode sectorMode = SectorMode::Sector;
66 auto initFunction = [config, propagateMC, creator](
InitContext& ic) {
69 ic.options().get<std::string>(
"infile"));
70 auto treename = ic.options().get<std::string>(
"treename");
71 auto clbrName = ic.options().get<std::string>(config.
databranch.
option.c_str());
72 auto mcbrName = ic.options().get<std::string>(config.
mcbranch.
option.c_str());
73 auto nofEvents = ic.options().get<
int>(
"nevents");
79 auto checkSectorMode = [&
filename, &treename, &clbrName]() -> SectorMode {
80 std::unique_ptr<TFile>
file(TFile::Open(
filename.c_str()));
82 TTree*
tree =
reinterpret_cast<TTree*
>(
file->GetObjectChecked(treename.c_str(),
"TTree"));
84 const auto brlist =
tree->GetListOfBranches();
86 if (clbrName ==
entry->GetName()) {
87 return SectorMode::Full;
93 return SectorMode::Sector;
96 auto processAttributes = std::make_shared<ProcessAttributes>();
98 processAttributes->terminateOnEod = ic.options().get<
bool>(
"terminate-on-eod");
99 processAttributes->sectorMode = checkSectorMode();
100 auto& sectors = processAttributes->sectors;
101 auto& activeSectors = processAttributes->activeSectors;
102 auto& readers = processAttributes->readers;
103 auto& outputIds = processAttributes->outputIds;
104 auto& sectorMode = processAttributes->sectorMode;
108 for (
auto const& s : sectors) {
111 std::string
message = std::string(
"invalid sector range specified, allowed 0-") +
std::to_string(NSectors - 1);
115 throw std::invalid_argument(
message);
117 activeSectors |= (uint64_t)0x1 << s;
123 auto outputId = outputIds.begin();
124 for (
auto const& sector : sectors) {
127 if (
filename.find(
'%') != std::string::npos) {
128 std::vector<char> formattedname(
filename.length() + 10, 0);
129 snprintf(formattedname.data(), formattedname.size() - 1,
filename.c_str(), sector);
130 sectorfile = formattedname.data();
132 std::string clusterbranchname = clbrName;
133 std::string mcbranchname = mcbrName;
134 if (sectorMode == SectorMode::Sector) {
138 readers[sector] = creator(treename.c_str(),
143 clusterbranchname.c_str(),
144 mcbranchname.c_str(),
146 if (sectorMode == SectorMode::Full) {
149 if (++outputId == outputIds.end()) {
150 outputId = outputIds.begin();
153 if (sectorMode == SectorMode::Full) {
157 processAttributes->zeroLengthOutputs.assign(++outputId, outputIds.end());
168 if (processAttributes->finished) {
173 auto const& sectors = processAttributes->sectors;
174 for (
auto const& sector : sectors) {
175 auto& activeSectors = processAttributes->activeSectors;
176 auto& readers = processAttributes->readers;
178 if (processAttributes->sectorMode == SectorMode::Full) {
181 header.activeSectors = activeSectors;
182 auto&
r = *(readers[sector].get());
190 readers[sector].reset();
196 processAttributes->finished =
true;
205 header.activeSectors = processAttributes->activeSectors;
206 for (
auto const& subSpec : processAttributes->zeroLengthOutputs) {
207 pc.outputs().make<
char>({dto.origin, dto.description, subSpec, {header}});
208 if (pc.outputs().isAllowed({mco.origin, mco.description, subSpec})) {
209 pc.outputs().make<
char>({mco.origin, mco.description, subSpec, {header}});
217 return processingFct;
220 auto createOutputSpecs = [&config, propagateMC]() {
221 std::vector<OutputSpec> outputSpecs;
226 outputSpecs.emplace_back(
OutputSpec{{
"output"}, dto.origin, dto.description, subSpec, Lifetime::Timeframe});
228 outputSpecs.emplace_back(
OutputSpec{{
"outputMC"}, mco.origin, mco.description, subSpec, Lifetime::Timeframe});
231 return std::move(outputSpecs);
238 {createOutputSpecs()},
241 {
"infile", VariantType::String, config.
defaultFileName.c_str(), {
"Name of the input file"}},
242 {
"input-dir", VariantType::String,
"none", {
"Input directory"}},
243 {
"treename", VariantType::String, config.
defaultTreeName.c_str(), {
"Name of input tree"}},
244 {dtb.option.c_str(), VariantType::String, dtb.defval.c_str(), {dtb.help.c_str()}},
245 {mcb.option.c_str(), VariantType::String, mcb.defval.c_str(), {mcb.help.c_str()}},
246 {
"nevents", VariantType::Int, -1, {
"number of events to run"}},
247 {
"terminate-on-eod", VariantType::Bool,
true, {
"terminate on end-of-data"}},