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
12#include <vector>
13
14#include "TTree.h"
15
18#include "Framework/Logger.h"
23#include <cassert>
24
25using namespace o2::framework;
26using namespace o2::itsmft;
27
28namespace o2
29{
30namespace trk
31{
32
33DigitReader::DigitReader(o2::detectors::DetID id, bool useMC, bool useCalib)
34{
35 assert(id == o2::detectors::DetID::TRK);
36 mDetNameLC = mDetName = id.getName();
37 mDigTreeName = "o2sim";
38
39 mDigits.resize(mLayers, nullptr);
40 mDigROFRec.resize(mLayers, nullptr);
41 mPLabels.resize(mLayers, nullptr);
42
46
48
49 mUseMC = useMC;
50 mUseCalib = useCalib;
51 std::transform(mDetNameLC.begin(), mDetNameLC.end(), mDetNameLC.begin(), ::tolower);
52}
53
55{
56 mFileName = ic.options().get<std::string>((mDetNameLC + "-digit-infile").c_str());
58}
59
61{
62 auto ent = mTree->GetReadEntry() + 1;
63 assert(ent < mTree->GetEntries()); // this should not happen
64 mTree->GetEntry(ent);
65
66 for (int iLayer = 0; iLayer < mLayers; ++iLayer) {
67 LOG(info) << mDetName << "DigitReader on layer " << iLayer << " pushes " << mDigROFRec[iLayer]->size() << " ROFRecords, "
68 << mDigits[iLayer]->size() << " digits at entry " << ent;
69
70 pc.outputs().snapshot(Output{mOrigin, "DIGITSROF", static_cast<o2::framework::DataAllocator::SubSpecificationType>(iLayer)}, *mDigROFRec[iLayer]);
71 pc.outputs().snapshot(Output{mOrigin, "DIGITS", static_cast<o2::framework::DataAllocator::SubSpecificationType>(iLayer)}, *mDigits[iLayer]);
72
73 if (mUseMC) {
75 mPLabels[iLayer]->copyandflatten(sharedlabels);
76 delete mPLabels[iLayer];
77 mPLabels[iLayer] = nullptr;
78 }
79 }
80
81 if (mUseCalib) {
82 pc.outputs().snapshot(Output{mOrigin, "GBTCALIB", 0}, mCalib);
83 }
84
85 if (mTree->GetReadEntry() + 1 >= mTree->GetEntries()) {
87 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
88 }
89}
90
91void DigitReader::connectTree(const std::string& filename)
92{
93 mTree.reset(nullptr); // in case it was already loaded
94 mFile.reset(TFile::Open(filename.c_str()));
95 assert(mFile && !mFile->IsZombie());
96 mTree.reset((TTree*)mFile->Get(mDigTreeName.c_str()));
97 assert(mTree);
98
99 for (int iLayer = 0; iLayer < mLayers; ++iLayer) {
101 setBranchAddress(mDigitBranchName, mDigits[iLayer], iLayer);
102 if (mUseMC) {
103 const auto mctruthBranch = getBranchName(mDigtMCTruthBranchName, iLayer);
104 if (!mTree->GetBranch(mctruthBranch.c_str())) {
105 throw std::runtime_error("MC data requested but missing branch(es) at layer " + std::to_string(iLayer) +
106 ": " + mctruthBranch);
107 }
109 }
110 }
111
112 if (mUseCalib) {
113 if (!mTree->GetBranch(mCalibBranchName.c_str())) {
114 throw std::runtime_error("GBT calibration data requested but not found in the tree");
115 }
117 }
118 LOG(info) << "Loaded tree from " << filename << " with " << mTree->GetEntries() << " entries";
119}
120
121std::string DigitReader::getBranchName(const std::string& base, int index) const
122{
123 if (index >= 0) {
124 return base + "_" + std::to_string(index);
125 }
126 return base;
127}
128
129template <typename Ptr>
130void DigitReader::setBranchAddress(const std::string& base, Ptr& addr, int layer)
131{
132 const auto name = getBranchName(base, layer);
133 if (Int_t ret = mTree->SetBranchAddress(name.c_str(), &addr); ret != 0) {
134 LOGP(fatal, "failed to set branch address for {} ret={}", name, ret);
135 }
136}
137
138DataProcessorSpec getTRKDigitReaderSpec(bool useMC, bool useCalib, std::string defname)
139{
140 static constexpr int nLayers = o2::trk::AlmiraParam::kNLayers;
141 std::vector<OutputSpec> outputSpec;
142 for (int iLayer = 0; iLayer < nLayers; ++iLayer) {
143 outputSpec.emplace_back("TRK", "DIGITS", iLayer, Lifetime::Timeframe);
144 outputSpec.emplace_back("TRK", "DIGITSROF", iLayer, Lifetime::Timeframe);
145 if (useMC) {
146 outputSpec.emplace_back("TRK", "DIGITSMCTR", iLayer, Lifetime::Timeframe);
147 }
148 }
149 if (useCalib) {
150 outputSpec.emplace_back("TRK", "GBTCALIB", 0, Lifetime::Timeframe);
151 }
152
153 return DataProcessorSpec{
154 "trk-digit-reader",
155 Inputs{},
156 outputSpec,
157 AlgorithmSpec{adaptFromTask<TRKDigitReader>(useMC, useCalib)},
158 Options{
159 {"trk-digit-infile", VariantType::String, defname, {"Name of the input digit file"}}}};
160}
161
162} // namespace trk
163} // namespace o2
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.
Static class with identifiers, bitmasks and names for ALICE detectors.
Definition DetID.h:58
void snapshot(const Output &spec, T const &object)
o2::header::DataHeader::SubSpecificationType SubSpecificationType
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
static constexpr int mLayers
void run(ProcessingContext &pc) final
std::unique_ptr< TTree > mTree
std::vector< std::vector< o2::itsmft::ROFRecord > * > mDigROFRec
std::vector< o2::dataformats::IOMCTruthContainerView * > mPLabels
std::string mDigtMCTruthBranchName
o2::header::DataOrigin mOrigin
void setBranchAddress(const std::string &base, Ptr &addr, int layer=-1)
std::string mDigitBranchName
std::vector< o2::itsmft::GBTCalibData > * mCalibPtr
std::vector< std::vector< o2::itsmft::Digit > * > mDigits
std::string mCalibBranchName
std::unique_ptr< TFile > mFile
std::string getBranchName(const std::string &base, int index) const
void init(InitContext &ic) final
std::string mDigROFBranchName
std::vector< o2::itsmft::GBTCalibData > mCalib
void connectTree(const std::string &filename)
GLuint index
Definition glcorearb.h:781
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 getTRKDigitReaderSpec(bool useMC=true, bool useCalib=false, std::string defname="trkdigits.root")
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52
std::string filename()
static constexpr size_t kNLayers
Definition AlmiraParam.h:28
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"