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