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
18#include "Framework/Logger.h"
23#include <cassert>
24#include <stdexcept>
25
26using namespace o2::framework;
27using namespace o2::itsmft;
28
29namespace o2::its3
30{
31
32ITS3DigitReader::ITS3DigitReader(bool useMC, bool doStag, bool useCalib) : mUseMC(useMC), mDoStaggering(doStag), mUseCalib(useCalib), mDetNameLC(mDetName = "IT3"), mDigTreeName("o2sim")
33{
37
38 std::transform(mDetNameLC.begin(), mDetNameLC.end(), mDetNameLC.begin(), ::tolower);
39}
40
42{
43 mFileName = ic.options().get<std::string>((mDetNameLC + "-digit-infile").c_str());
45}
46
48{
49 auto ent = mTree->GetReadEntry() + 1;
50 assert(ent < mTree->GetEntries()); // this should not happen
51
52 mTree->GetEntry(ent);
53 for (uint32_t iLayer = 0; iLayer < (mDoStaggering ? NLayers : 1); ++iLayer) {
54 if (!mDigROFRec[iLayer] || !mDigits[iLayer]) {
55 throw std::runtime_error("ITS3 digit reader requires all 7 layer branches to be present and populated in every entry");
56 }
57 LOG(info) << mDetName << "DigitReader pushes " << mDigROFRec[iLayer]->size() << " ROFRecords, " << mDigits[iLayer]->size() << " digits at entry " << ent << " on layer " << iLayer;
58 pc.outputs().snapshot(Output{mOrigin, "DIGITSROF", iLayer}, *mDigROFRec[iLayer]);
59 pc.outputs().snapshot(Output{mOrigin, "DIGITS", iLayer}, *mDigits[iLayer]);
60 if (mUseMC) {
61 if (!mPLabels[iLayer]) {
62 throw std::runtime_error("ITS3 digit reader requires MC truth branches for all 7 layers to be present and populated in every entry");
63 }
64 auto& sharedlabels = pc.outputs().make<o2::dataformats::ConstMCTruthContainer<o2::MCCompLabel>>(Output{mOrigin, "DIGITSMCTR", iLayer});
65 mPLabels[iLayer]->copyandflatten(sharedlabels);
66 delete mPLabels[iLayer];
67 mPLabels[iLayer] = nullptr;
68 }
69 }
70
71 if (mTree->GetReadEntry() + 1 >= mTree->GetEntries()) {
73 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
74 }
75}
76
77template <typename Ptr>
78void ITS3DigitReader::setBranchAddress(const std::string& base, Ptr& addr, int layer)
79{
80 const auto name = getBranchName(base, layer);
81 if (Int_t ret = mTree->SetBranchAddress(name.c_str(), &addr); ret != 0) {
82 LOGP(fatal, "failed to set branch address for {} ret={}", name, ret);
83 }
84}
85
86void ITS3DigitReader::connectTree(const std::string& filename)
87{
88 mTree.reset(nullptr); // in case it was already loaded
89 mFile.reset(TFile::Open(filename.c_str()));
90 assert(mFile && !mFile->IsZombie());
91 mTree.reset((TTree*)mFile->Get(mDigTreeName.c_str()));
92 assert(mTree);
93 for (int iLayer = 0; iLayer < (mDoStaggering ? NLayers : 1); ++iLayer) {
94 const auto rofBranchName = getBranchName(mDigROFBranchName, iLayer);
95 const auto digBranchName = getBranchName(mDigBranchName, iLayer);
96 if (!mTree->GetBranch(rofBranchName.c_str()) || !mTree->GetBranch(digBranchName.c_str())) {
97 throw std::runtime_error("ITS3 digit reader requires all branches in the input file");
98 }
100 setBranchAddress(mDigBranchName, mDigits[iLayer], iLayer);
101 if (mUseMC) {
102 if (!mTree->GetBranch(getBranchName(mDigMCTruthBranchName, iLayer).c_str())) {
103 throw std::runtime_error("ITS3 digit reader requires MC truth branches for all 7 layers in the input file");
104 }
105 if (!mPLabels[iLayer]) {
107 }
108 }
109 }
110 LOG(info) << "Loaded tree from " << filename << " with " << mTree->GetEntries() << " entries";
111}
112
113DataProcessorSpec getITS3DigitReaderSpec(bool useMC, bool doStag, bool useCalib, std::string defname)
114{
115 std::vector<OutputSpec> outputSpec;
116 for (uint32_t iLayer = 0; iLayer < (doStag ? ITS3DigitReader::NLayers : 1); ++iLayer) {
117 outputSpec.emplace_back("IT3", "DIGITS", iLayer, Lifetime::Timeframe);
118 outputSpec.emplace_back("IT3", "DIGITSROF", iLayer, Lifetime::Timeframe);
119 if (useMC) {
120 outputSpec.emplace_back("IT3", "DIGITSMCTR", iLayer, Lifetime::Timeframe);
121 }
122 }
123
124 return DataProcessorSpec{
125 .name = "its3-digit-reader",
126 .inputs = Inputs{},
127 .outputs = outputSpec,
128 .algorithm = AlgorithmSpec{adaptFromTask<ITS3DigitReader>(useMC, doStag, useCalib)},
129 .options = Options{
130 {"it3-digit-infile", VariantType::String, defname, {"Name of the input digit file"}}}};
131}
132
133} // namespace o2::its3
A const (ready only) version of MCTruthContainer.
A special IO container - splitting a given vector to enable ROOT IO.
A read-only version of MCTruthContainer allowing for storage optimisation.
void snapshot(const Output &spec, T const &object)
decltype(auto) make(const Output &spec, Args... args)
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
std::unique_ptr< TFile > mFile
std::array< std::vector< o2::itsmft::ROFRecord > *, NLayers > mDigROFRec
std::unique_ptr< TTree > mTree
void run(ProcessingContext &pc) final
static constexpr int NLayers
void setBranchAddress(const std::string &base, Ptr &addr, int layer)
std::array< o2::dataformats::IOMCTruthContainerView *, NLayers > mPLabels
void init(InitContext &ic) final
std::string getBranchName(const std::string &base, int index) const
std::array< std::vector< o2::itsmft::Digit > *, NLayers > mDigits
ITS3DigitReader(bool useMC, bool doStag, bool useCalib)
void connectTree(const std::string &filename)
const o2::header::DataOrigin mOrigin
GLuint const GLchar * name
Definition glcorearb.h:781
GLenum GLuint GLint GLint layer
Definition glcorearb.h:1310
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > Inputs
framework::DataProcessorSpec getITS3DigitReaderSpec(bool useMC=true, bool doStag=false, bool useCalib=false, std::string defname="it3digits.root")
std::string filename()
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"