Project
Loading...
Searching...
No Matches
CellReaderSpec.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::phos;
23
24namespace o2
25{
26namespace phos
27{
28
30{
31 mUseMC = useMC;
32}
33
35{
37 ic.options().get<std::string>("phos-cells-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 " << mCells.size() << " Cells in " << mTRs.size() << " TriggerRecords at entry " << ent;
56 pc.outputs().snapshot(Output{mOrigin, "CELLS", 0}, mCells);
57 pc.outputs().snapshot(Output{mOrigin, "CELLTRIGREC", 0}, mTRs);
58 if (mUseMC) {
59 pc.outputs().snapshot(Output{mOrigin, "CELLSMCTR", 0}, mMCTruth);
60 }
61
62 if (noEntry || mTree->GetReadEntry() + 1 >= mTree->GetEntries()) {
64 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
65 }
66}
67
68void CellReader::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(mCellTreeName.c_str()));
74 assert(mTree);
75 assert(mTree->GetBranch(mTRBranchName.c_str()));
76
77 mTree->SetBranchAddress(mTRBranchName.c_str(), &mTRsInp);
78 mTree->SetBranchAddress(mCellBranchName.c_str(), &mCellsInp);
79 if (mUseMC) {
80 if (mTree->GetBranch(mCellMCTruthBranchName.c_str())) {
81 mTree->SetBranchAddress(mCellMCTruthBranchName.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("PHS", "CELLS", 0, Lifetime::Timeframe);
93 outputSpec.emplace_back("PHS", "CELLTRIGREC", 0, Lifetime::Timeframe);
94 if (useMC) {
95 outputSpec.emplace_back("PHS", "CELLSMCTR", 0, Lifetime::Timeframe);
96 }
97
98 return DataProcessorSpec{
99 "phos-cells-reader",
100 Inputs{},
101 outputSpec,
102 AlgorithmSpec{adaptFromTask<CellReader>(useMC)},
103 Options{
104 {"phos-cells-infile", VariantType::String, "phoscells.root", {"Name of the input Cell file"}},
105 {"input-dir", VariantType::String, "none", {"Input directory"}}}};
106}
107
108} // namespace phos
109} // namespace o2
Definition of the Names Generator class.
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
std::string mCellTreeName
std::vector< o2::phos::Cell > mCells
o2::dataformats::MCTruthContainer< o2::phos::MCLabel > mMCTruth
void connectTree(const std::string &filename)
std::vector< o2::phos::Cell > * mCellsInp
void init(o2::framework::InitContext &ic) final
CellReader(bool useMC=true)
o2::header::DataOrigin mOrigin
o2::dataformats::MCTruthContainer< o2::phos::MCLabel > * mMCTruthInp
std::vector< o2::phos::TriggerRecord > * mTRsInp
std::string mTRBranchName
std::string mCellMCTruthBranchName
std::vector< o2::phos::TriggerRecord > mTRs
std::unique_ptr< TFile > mFile
void run(o2::framework::ProcessingContext &pc) final
std::string mInputFileName
std::unique_ptr< TTree > mTree
std::string mCellBranchName
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > Inputs
framework::DataProcessorSpec getPHOSCellReaderSpec(bool useMC=true)
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"