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 // A timeframe holds no collision at all whenever the interaction rate is low enough, and
81 // the tree then has no entry to read. Publish empty containers instead of reading past the
82 // end and pushing branch addresses that GetEntry has not filled, so that the consumers
83 // downstream still see the timeframe. (This used to be an assert, which is compiled out of
84 // every production build since ENABLE_CASSERT defaults to OFF.)
85 const bool noEntry = ent >= mTree->GetEntries();
86 if (noEntry) {
87 LOG(info) << "no entry to read, publishing empty output";
88 } else {
89 mTree->GetEntry(ent);
90 }
91
92 static const std::vector<o2::fdd::Digit> noDigitsBC;
93 static const std::vector<o2::fdd::ChannelData> noDigitsCh;
94 static const std::vector<o2::fdd::DetTrigInput> noDigitsTrig;
95 const auto& digitsBCOut = noEntry ? noDigitsBC : *digitsBC;
96 const auto& digitsChOut = noEntry ? noDigitsCh : *digitsCh;
97 LOG(info) << "FDD DigitReader pushes " << digitsBCOut.size() << " digits";
98 pc.outputs().snapshot(Output{mOrigin, "DIGITSBC", 0}, digitsBCOut);
99 pc.outputs().snapshot(Output{mOrigin, "DIGITSCH", 0}, digitsChOut);
100
101 if (mUseMC) {
102 // TODO: To be replaced with sending ConstMCTruthContainer as soon as reco workflow supports it
103 pc.outputs().snapshot(Output{mOrigin, "TRIGGERINPUT", 0}, noEntry ? noDigitsTrig : *digitsTrig);
104
106 if (!noEntry) {
107 std::vector<char> flatbuffer;
108 mcTruthRootBuffer->copyandflatten(flatbuffer);
109 mcTruth.restore_from(flatbuffer.data(), flatbuffer.size());
110 }
111 pc.outputs().snapshot(Output{mOrigin, "DIGITLBL", 0}, mcTruth);
112 }
113 if (noEntry || mTree->GetReadEntry() + 1 >= mTree->GetEntries()) {
115 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
116 }
117}
118
120{
121 std::vector<OutputSpec> outputSpec;
122 outputSpec.emplace_back(o2::header::gDataOriginFDD, "DIGITSBC", 0, Lifetime::Timeframe);
123 outputSpec.emplace_back(o2::header::gDataOriginFDD, "DIGITSCH", 0, Lifetime::Timeframe);
124 if (useMC) {
125 outputSpec.emplace_back(o2::header::gDataOriginFDD, "TRIGGERINPUT", 0, Lifetime::Timeframe);
126 outputSpec.emplace_back(o2::header::gDataOriginFDD, "DIGITLBL", 0, Lifetime::Timeframe);
127 }
128
129 return DataProcessorSpec{
130 "fdd-digit-reader",
131 Inputs{},
132 outputSpec,
133 AlgorithmSpec{adaptFromTask<DigitReader>()},
134 Options{
135 {"fdd-digits-infile", VariantType::String, "fdddigits.root", {"Name of the input file"}},
136 {"input-dir", VariantType::String, "none", {"Input directory"}}}};
137}
138
139} // namespace fdd
140} // 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 ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > Inputs
struct o2::upgrades_utils::@474 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"