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#include <cassert>
20
21using namespace o2::framework;
22using namespace o2::cpv;
23
24namespace o2
25{
26namespace cpv
27{
28
30{
31 mUseMC = useMC;
32}
33
35{
37 ic.options().get<std::string>("cpv-digits-infile"));
39}
40
42{
43 auto ent = mTree->GetReadEntry() + 1;
44 // A timeframe holds no collision at all whenever the interaction rate is low enough, and
45 // the tree then has no entry to read. Publish empty containers instead of reading past the
46 // end and pushing branch addresses that GetEntry has not filled, so that the consumers
47 // downstream still see the timeframe. (This used to be an assert, which is compiled out of
48 // every production build since ENABLE_CASSERT defaults to OFF.)
49 const bool noEntry = ent >= mTree->GetEntries();
50 if (noEntry) {
51 LOG(info) << "no entry to read, publishing empty output";
52 } else {
53 mTree->GetEntry(ent);
54 }
55 LOG(info) << "Pushing " << mDigits.size() << " Digits in " << mTRs.size() << " TriggerRecords at entry " << ent;
56 pc.outputs().snapshot(Output{mOrigin, "DIGITS", 0}, mDigits);
57 pc.outputs().snapshot(Output{mOrigin, "DIGITTRIGREC", 0}, mTRs);
58 if (mUseMC) {
59 pc.outputs().snapshot(Output{mOrigin, "DIGITSMCTR", 0}, mMCTruth);
60 }
61
62 if (noEntry || mTree->GetReadEntry() + 1 >= mTree->GetEntries()) {
64 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
65 }
66}
67
68void DigitReader::connectTree(const std::string& filename)
69{
70 mTree.reset(nullptr); // in case it was already loaded
71 mFile.reset(TFile::Open(filename.c_str()));
72 assert(mFile && !mFile->IsZombie());
73 mTree.reset((TTree*)mFile->Get(mDigitTreeName.c_str()));
74 assert(mTree);
75 assert(mTree->GetBranch(mTRBranchName.c_str()));
76
77 mTree->SetBranchAddress(mTRBranchName.c_str(), &mTRsInp);
78 mTree->SetBranchAddress(mDigitBranchName.c_str(), &mDigitsInp);
79 if (mUseMC) {
80 if (mTree->GetBranch(mDigitMCTruthBranchName.c_str())) {
81 mTree->SetBranchAddress(mDigitMCTruthBranchName.c_str(), &mMCTruthInp);
82 } else {
83 LOG(warning) << "MC-truth is missing, message will be empty";
84 }
85 }
86 LOG(info) << "Loaded tree from " << filename << " with " << mTree->GetEntries() << " entries";
87}
88
90{
91 std::vector<OutputSpec> outputSpec;
92 outputSpec.emplace_back("CPV", "DIGITS", 0, Lifetime::Timeframe);
93 outputSpec.emplace_back("CPV", "DIGITTRIGREC", 0, Lifetime::Timeframe);
94 if (useMC) {
95 outputSpec.emplace_back("CPV", "DIGITSMCTR", 0, Lifetime::Timeframe);
96 }
97
98 return DataProcessorSpec{
99 "cpv-digit-reader",
100 Inputs{},
101 outputSpec,
102 AlgorithmSpec{adaptFromTask<DigitReader>(useMC)},
103 Options{
104 {"cpv-digits-infile", VariantType::String, "cpvdigits.root", {"Name of the input Digit file"}},
105 {"input-dir", VariantType::String, "none", {"Input directory"}}}};
106}
107
108} // namespace cpv
109} // namespace o2
Definition of the Names Generator class.
std::vector< o2::cpv::TriggerRecord > mTRs
std::string mDigitBranchName
std::vector< o2::cpv::Digit > * mDigitsInp
o2::dataformats::MCTruthContainer< o2::MCCompLabel > mMCTruth
o2::header::DataOrigin mOrigin
std::vector< o2::cpv::Digit > mDigits
void connectTree(const std::string &filename)
std::vector< o2::cpv::TriggerRecord > * mTRsInp
std::unique_ptr< TFile > mFile
DigitReader(bool useMC=true)
std::string mDigitMCTruthBranchName
void init(o2::framework::InitContext &ic) final
void run(o2::framework::ProcessingContext &pc) final
o2::dataformats::MCTruthContainer< o2::MCCompLabel > * mMCTruthInp
std::unique_ptr< TTree > mTree
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
framework::DataProcessorSpec getCPVDigitReaderSpec(bool useMC=true)
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > Inputs
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::string filename()
static std::string rectifyDirectory(const std::string_view p)
static std::string concat_string(Ts const &... ts)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"