|
| 1 | +// Copyright CERN and copyright holders of ALICE O2. This software is |
| 2 | +// distributed under the terms of the GNU General Public License v3 (GPL |
| 3 | +// Version 3), copied verbatim in the file "COPYING". |
| 4 | +// |
| 5 | +// See http://alice-o2.web.cern.ch/license for full licensing information. |
| 6 | +// |
| 7 | +// In applying this license CERN does not waive the privileges and immunities |
| 8 | +// granted to it by virtue of its status as an Intergovernmental Organization |
| 9 | +// or submit itself to any jurisdiction. |
| 10 | + |
| 11 | +/// @file FileReaderWorkflow.cxx |
| 12 | + |
| 13 | +#include "TPCWorkflow/PublisherSpec.h" |
| 14 | +#include "TPCWorkflow/TrackReaderSpec.h" |
| 15 | + |
| 16 | +#include "Algorithm/RangeTokenizer.h" |
| 17 | + |
| 18 | +#include "SimulationDataFormat/IOMCTruthContainerView.h" |
| 19 | +#include "SimulationDataFormat/ConstMCTruthContainer.h" |
| 20 | +#include "SimulationDataFormat/MCCompLabel.h" |
| 21 | + |
| 22 | +// add workflow options, note that customization needs to be declared before |
| 23 | +// including Framework/runDataProcessing |
| 24 | +void customize(std::vector<o2::framework::ConfigParamSpec>& workflowOptions) |
| 25 | +{ |
| 26 | + using namespace o2::framework; |
| 27 | + |
| 28 | + std::vector<ConfigParamSpec> options{ |
| 29 | + {"input-type", VariantType::String, "clusters", {"clusters, tracks"}}, |
| 30 | + {"disable-mc", VariantType::Bool, false, {"disable sending of MC information"}}}; |
| 31 | + |
| 32 | + std::swap(workflowOptions, options); |
| 33 | +} |
| 34 | + |
| 35 | +#include "Framework/runDataProcessing.h" // the main driver |
| 36 | + |
| 37 | +using namespace o2::framework; |
| 38 | + |
| 39 | +enum struct Input { Clusters, |
| 40 | + Tracks |
| 41 | +}; |
| 42 | + |
| 43 | +const std::unordered_map<std::string, Input> InputMap{ |
| 44 | + {"clusters", Input::Clusters}, |
| 45 | + {"tracks", Input::Tracks}}; |
| 46 | + |
| 47 | +/// MC info is processed by default, disabled by using command line option `--disable-mc` |
| 48 | +/// |
| 49 | +/// This function hooks up the the workflow specifications into the DPL driver. |
| 50 | +WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) |
| 51 | +{ |
| 52 | + WorkflowSpec specs; |
| 53 | + |
| 54 | + auto inputType = cfgc.options().get<std::string>("input-type"); |
| 55 | + bool doMC = not cfgc.options().get<bool>("disable-mc"); |
| 56 | + |
| 57 | + std::vector<Input> inputTypes; |
| 58 | + try { |
| 59 | + inputTypes = o2::RangeTokenizer::tokenize<Input>(inputType, [](std::string const& token) { return InputMap.at(token); }); |
| 60 | + } catch (std::out_of_range&) { |
| 61 | + throw std::invalid_argument(std::string("invalid input type: ") + inputType); |
| 62 | + } |
| 63 | + auto isEnabled = [&inputTypes](Input type) { |
| 64 | + return std::find(inputTypes.begin(), inputTypes.end(), type) != inputTypes.end(); |
| 65 | + }; |
| 66 | + |
| 67 | + if (isEnabled(Input::Clusters)) { |
| 68 | + |
| 69 | + // We provide a special publishing method for labels which have been stored in a split format and need |
| 70 | + // to be transformed into a contiguous shareable container before publishing. For other branches/types this returns |
| 71 | + // false and the generic RootTreeWriter publishing proceeds |
| 72 | + static RootTreeReader::SpecialPublishHook hook{[](std::string_view name, ProcessingContext& context, o2::framework::Output const& output, char* data) -> bool { |
| 73 | + if (TString(name.data()).Contains("TPCDigitMCTruth") || TString(name.data()).Contains("TPCClusterHwMCTruth") || TString(name.data()).Contains("TPCClusterNativeMCTruth")) { |
| 74 | + auto storedlabels = reinterpret_cast<o2::dataformats::IOMCTruthContainerView const*>(data); |
| 75 | + o2::dataformats::ConstMCTruthContainer<o2::MCCompLabel> flatlabels; |
| 76 | + storedlabels->copyandflatten(flatlabels); |
| 77 | + LOG(INFO) << "PUBLISHING CONST LABELS " << flatlabels.getNElements(); |
| 78 | + context.outputs().snapshot(output, flatlabels); |
| 79 | + return true; |
| 80 | + } |
| 81 | + return false; |
| 82 | + }}; |
| 83 | + |
| 84 | + std::vector<int> tpcSectors(36); |
| 85 | + std::iota(tpcSectors.begin(), tpcSectors.end(), 0); |
| 86 | + std::vector<int> laneConfiguration = tpcSectors; |
| 87 | + |
| 88 | + specs.emplace_back(o2::tpc::getPublisherSpec(o2::tpc::PublisherConf{ |
| 89 | + "tpc-native-cluster-reader", |
| 90 | + "tpcrec", |
| 91 | + {"clusterbranch", "TPCClusterNative", "Branch with TPC native clusters"}, |
| 92 | + {"clustermcbranch", "TPCClusterNativeMCTruth", "MC label branch"}, |
| 93 | + OutputSpec{"TPC", "CLUSTERNATIVE"}, |
| 94 | + OutputSpec{"TPC", "CLNATIVEMCLBL"}, |
| 95 | + tpcSectors, |
| 96 | + laneConfiguration, |
| 97 | + &hook}, |
| 98 | + doMC)); |
| 99 | + } |
| 100 | + |
| 101 | + if (isEnabled(Input::Tracks)) { |
| 102 | + |
| 103 | + specs.push_back(o2::tpc::getTPCTrackReaderSpec(doMC)); |
| 104 | + } |
| 105 | + |
| 106 | + return std::move(specs); |
| 107 | +} |
0 commit comments