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
24using namespace o2::framework;
25
26namespace o2::iotof
27{
28
30{
31 assert(id == o2::detectors::DetID::TF3);
32 mDetNameLC = mDetName = id.getName();
33 mDigTreeName = "o2sim";
34
38
41
42 mUseMC = useMC;
43 mUseCalib = useCalib;
44 std::transform(mDetNameLC.begin(), mDetNameLC.end(), mDetNameLC.begin(), ::tolower);
45}
46
48{
49 mFileName = ic.options().get<std::string>((mDetNameLC + "-digit-infile").c_str());
51}
52
54{
55 auto ent = mTree->GetReadEntry() + 1;
56 assert(ent < mTree->GetEntries()); // this should not happen
57
59 if (mUseMC) {
60 mTree->SetBranchAddress(mDigtMCTruthBranchName.c_str(), &plabels);
61 }
62 mTree->GetEntry(ent);
63 LOG(info) << mDetName << "TF3DigitReader pushes " << mDigROFRec.size() << " ROFRecords, "
64 << mDigits.size() << " digits at entry " << ent;
65
66 // This is a very ugly way of providing DataDescription, which anyway does not need to contain detector name.
67 // To be fixed once the names-definition class is ready
68 pc.outputs().snapshot(Output{mOrigin, "DIGITSROF", 0}, mDigROFRec);
69 pc.outputs().snapshot(Output{mOrigin, "DIGITS", 0}, mDigits);
70 if (mUseCalib) {
71 // pc.outputs().snapshot(Output{mOrigin, "GBTCALIB", 0}, mCalib);
72 }
73
74 if (mUseMC) {
75 auto& sharedlabels = pc.outputs().make<o2::dataformats::ConstMCTruthContainer<o2::MCCompLabel>>(Output{mOrigin, "DIGITSMCTR", 0});
76 plabels->copyandflatten(sharedlabels);
77 delete plabels;
78 pc.outputs().snapshot(Output{mOrigin, "DIGITSMC2ROF", 0}, mDigMC2ROFs);
79 }
80
81 if (mTree->GetReadEntry() + 1 >= mTree->GetEntries()) {
83 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
84 }
85}
86
87void TF3DigitReader::connectTree(const std::string& filename)
88{
89 mTree.reset(nullptr); // in case it was already loaded
90 mFile.reset(TFile::Open(filename.c_str()));
91 assert(mFile && !mFile->IsZombie());
92 mTree.reset((TTree*)mFile->Get(mDigTreeName.c_str()));
93 assert(mTree);
94
95 mTree->SetBranchAddress(mDigROFBranchName.c_str(), &mDigROFRecPtr);
96 mTree->SetBranchAddress(mDigitBranchName.c_str(), &mDigitsPtr);
97 if (mUseCalib) {
98 if (!mTree->GetBranch(mCalibBranchName.c_str())) {
99 throw std::runtime_error("GBT calibration data requested but not found in the tree");
100 }
101 // mTree->SetBranchAddress(mCalibBranchName.c_str(), &mCalibPtr);
102 }
103 if (mUseMC) {
104 if (!mTree->GetBranch(mDigtMCTruthBranchName.c_str())) {
105 throw std::runtime_error("MC data requested but not found in the tree");
106 }
107 mTree->SetBranchAddress(mDigtMC2ROFBranchName.c_str(), &mDigMC2ROFsPtr);
108 }
109 LOG(info) << "Loaded tree from " << filename << " with " << mTree->GetEntries() << " entries";
110}
111
112DataProcessorSpec getIOTOFDigitReaderSpec(bool useMC, bool useCalib, std::string defname)
113{
114 std::vector<OutputSpec> outputSpec;
115 outputSpec.emplace_back("TF3", "DIGITS", 0, Lifetime::Timeframe);
116 outputSpec.emplace_back("TF3", "DIGITSROF", 0, Lifetime::Timeframe);
117 if (useCalib) {
118 // outputSpec.emplace_back("TF3", "GBTCALIB", 0, Lifetime::Timeframe);
119 }
120 if (useMC) {
121 outputSpec.emplace_back("TF3", "DIGITSMCTR", 0, Lifetime::Timeframe);
122 outputSpec.emplace_back("TF3", "DIGITSMC2ROF", 0, Lifetime::Timeframe);
123 }
124
125 return DataProcessorSpec{
126 "iotof-digit-reader",
127 Inputs{},
128 outputSpec,
129 AlgorithmSpec{adaptFromTask<TF3DigitReader>(o2::detectors::DetID::TF3, useMC, useCalib)},
130 Options{
131 {"tf3-digit-infile", VariantType::String, defname, {"Name of the input digit file"}}}};
132}
133
134} // namespace o2::iotof
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 copyandflatten(std::vector< char, Alloc > &output) const
Static class with identifiers, bitmasks and names for ALICE detectors.
Definition DetID.h:58
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::vector< o2::itsmft::ROFRecord > mDigROFRec
std::vector< o2::itsmft::MC2ROFRecord > * mDigMC2ROFsPtr
std::vector< o2::iotof::Digit > * mDigitsPtr
std::vector< o2::itsmft::ROFRecord > * mDigROFRecPtr
std::vector< o2::iotof::Digit > mDigits
void init(o2::framework::InitContext &ic) final
void connectTree(const std::string &filename)
o2::header::DataOrigin mOrigin
void run(o2::framework::ProcessingContext &pc) final
std::vector< o2::itsmft::MC2ROFRecord > mDigMC2ROFs
std::unique_ptr< TTree > mTree
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > Inputs
o2::framework::DataProcessorSpec getIOTOFDigitReaderSpec(bool useMC=true, bool useCalib=false, std::string defname="iotofdigits.root")
std::string filename()
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"