Project
Loading...
Searching...
No Matches
DigitReaderSpec.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
13
14#include <vector>
15
16#include "TTree.h"
17
20#include "Framework/Logger.h"
25#include <vector>
26
27using namespace o2::framework;
28using namespace o2::fdd;
29
30namespace o2
31{
32namespace fdd
33{
34
36{
37 mUseMC = useMC;
38}
39
41{
42 mInputFileName = o2::utils::Str::concat_string(o2::utils::Str::rectifyDirectory(ic.options().get<std::string>("input-dir")),
43 ic.options().get<std::string>("fdd-digits-infile"));
44
45 mFile.reset(TFile::Open(mInputFileName.c_str()));
46 if (!mFile->IsOpen()) {
47 LOG(error) << "Cannot open the " << mInputFileName.c_str() << " file !";
48 throw std::runtime_error("cannot open input digits file");
49 }
50 mTree.reset((TTree*)mFile->Get("o2sim"));
51 if (!mTree) {
52 LOG(error) << "Did not find o2sim tree in " << mInputFileName.c_str();
53 throw std::runtime_error("Did not fine o2sim file in FDD digits tree");
54 }
55}
56
58{
59 std::vector<o2::fdd::Digit>* digitsBC = nullptr;
60 std::vector<o2::fdd::ChannelData>* digitsCh = nullptr;
61 std::vector<o2::fdd::DetTrigInput>* digitsTrig = nullptr;
62 o2::dataformats::IOMCTruthContainerView* mcTruthRootBuffer = nullptr;
63
64 mTree->SetBranchAddress(mDigitBCBranchName.c_str(), &digitsBC);
65 mTree->SetBranchAddress(mDigitChBranchName.c_str(), &digitsCh);
66 if (mTree->GetBranch(mTriggerBranchName.c_str())) {
67 mTree->SetBranchAddress(mTriggerBranchName.c_str(), &digitsTrig);
68 }
69
70 if (mUseMC) {
71 if (mTree->GetBranch(mDigitMCTruthBranchName.c_str())) {
72 mTree->SetBranchAddress(mDigitMCTruthBranchName.c_str(), &mcTruthRootBuffer);
73 LOG(info) << "Will use MC-truth from " << mDigitMCTruthBranchName;
74 } else {
75 LOG(info) << "MC-truth is missing";
76 mUseMC = false;
77 }
78 }
79 auto ent = mTree->GetReadEntry() + 1;
80 assert(ent < mTree->GetEntries()); // this should not happen
81 mTree->GetEntry(ent);
82
83 LOG(info) << "FDD DigitReader pushes " << digitsBC->size() << " digits";
84 pc.outputs().snapshot(Output{mOrigin, "DIGITSBC", 0}, *digitsBC);
85 pc.outputs().snapshot(Output{mOrigin, "DIGITSCH", 0}, *digitsCh);
86
87 if (mUseMC) {
88 // TODO: To be replaced with sending ConstMCTruthContainer as soon as reco workflow supports it
89 pc.outputs().snapshot(Output{mOrigin, "TRIGGERINPUT", 0}, *digitsTrig);
90
91 std::vector<char> flatbuffer;
92 mcTruthRootBuffer->copyandflatten(flatbuffer);
94 mcTruth.restore_from(flatbuffer.data(), flatbuffer.size());
95 pc.outputs().snapshot(Output{mOrigin, "DIGITLBL", 0}, mcTruth);
96 }
97 if (mTree->GetReadEntry() + 1 >= mTree->GetEntries()) {
99 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
100 }
101}
102
104{
105 std::vector<OutputSpec> outputSpec;
106 outputSpec.emplace_back(o2::header::gDataOriginFDD, "DIGITSBC", 0, Lifetime::Timeframe);
107 outputSpec.emplace_back(o2::header::gDataOriginFDD, "DIGITSCH", 0, Lifetime::Timeframe);
108 if (useMC) {
109 outputSpec.emplace_back(o2::header::gDataOriginFDD, "TRIGGERINPUT", 0, Lifetime::Timeframe);
110 outputSpec.emplace_back(o2::header::gDataOriginFDD, "DIGITLBL", 0, Lifetime::Timeframe);
111 }
112
113 return DataProcessorSpec{
114 "fdd-digit-reader",
115 Inputs{},
116 outputSpec,
117 AlgorithmSpec{adaptFromTask<DigitReader>()},
118 Options{
119 {"fdd-digits-infile", VariantType::String, "fdddigits.root", {"Name of the input file"}},
120 {"input-dir", VariantType::String, "none", {"Input directory"}}}};
121}
122
123} // namespace fdd
124} // namespace o2
A special IO container - splitting a given vector to enable ROOT IO.
Definition of a container to keep Monte Carlo truth external to simulation objects.
Definition of the Names Generator class.
void copyandflatten(std::vector< char, Alloc > &output) const
A container to hold and manage MC truth information/labels.
void restore_from(const char *buffer, size_t bufferSize)
void run(ProcessingContext &pc) final
void init(InitContext &ic) final
DigitReader(bool useMC=true)
void snapshot(const Output &spec, T const &object)
ConfigParamRegistry const & options()
Definition InitContext.h:33
DataAllocator & outputs()
The data allocator is used to allocate memory for the output data.
ServiceRegistryRef services()
The services registry associated with this processing context.
virtual void endOfStream(EndOfStreamContext &context)
This is invoked whenever we have an EndOfStream event.
Definition Task.h:43
constexpr o2::header::DataOrigin gDataOriginFDD
Definition DataHeader.h:568
framework::DataProcessorSpec getFDDDigitReaderSpec(bool useMC)
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > Inputs
struct o2::upgrades_utils::@459 fdd
Collision labels.
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
static std::string rectifyDirectory(const std::string_view p)
static std::string concat_string(Ts const &... ts)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"