Project
Loading...
Searching...
No Matches
ClusterReaderSpec.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
22#include "TOFBase/Geo.h"
23
24using namespace o2::framework;
25using namespace o2::tof;
26
27namespace o2
28{
29namespace tof
30{
31
33{
34 LOG(debug) << "Init Cluster reader!";
35 mFileName = o2::utils::Str::concat_string(o2::utils::Str::rectifyDirectory(ic.options().get<std::string>("input-dir")),
36 ic.options().get<std::string>("tof-cluster-infile"));
37 connectTree(mFileName);
38}
39
41{
42 auto ent = mTree->GetReadEntry() + 1;
43 // A timeframe holds no collision at all whenever the interaction rate is low enough, and
44 // the tree then has no entry to read. Publish empty containers instead of reading past the
45 // end and pushing branch addresses that GetEntry has not filled, so that the consumers
46 // downstream still see the timeframe. (This used to be an assert, which is compiled out of
47 // every production build since ENABLE_CASSERT defaults to OFF.)
48 const bool noEntry = ent >= mTree->GetEntries();
49 if (noEntry) {
50 LOG(info) << "no entry to read, publishing empty output";
51 } else {
52 mTree->GetEntry(ent);
53 }
54 LOG(debug) << "Pushing " << mClustersPtr->size() << " TOF clusters at entry " << ent;
55
56 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "CLUSTERS", 0}, mClusters);
57 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "CLUSTERSMULT", 0}, mClustersMult);
58 if (mUseMC) {
59 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "CLUSTERSMCTR", 0}, mLabels);
60 }
61
62 if (noEntry || mTree->GetReadEntry() + 1 >= mTree->GetEntries()) {
64 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
65 }
66}
67
68void ClusterReader::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("o2sim"));
74 assert(mTree);
75 mTree->SetBranchAddress("TOFCluster", &mClustersPtr);
76
77 if (mTree->GetBranch("TOFClusterMult")) {
78 mTree->SetBranchAddress("TOFClusterMult", &mClustersMultPtr);
79 } else {
80 mClustersMult.resize(o2::base::GRPGeomHelper::instance().getNHBFPerTF() * o2::constants::lhc::LHCMaxBunches);
81 }
82
83 if (mUseMC) {
84 mTree->SetBranchAddress("TOFClusterMCTruth", &mLabelsPtr);
85 }
86 LOG(debug) << "Loaded tree from " << filename << " with " << mTree->GetEntries() << " entries";
87}
88
90{
91 std::vector<OutputSpec> outputs;
92 outputs.emplace_back(o2::header::gDataOriginTOF, "CLUSTERS", 0, Lifetime::Timeframe);
93 outputs.emplace_back(o2::header::gDataOriginTOF, "CLUSTERSMULT", 0, Lifetime::Timeframe);
94 if (useMC) {
95 outputs.emplace_back(o2::header::gDataOriginTOF, "CLUSTERSMCTR", 0, Lifetime::Timeframe);
96 }
97
98 return DataProcessorSpec{
99 "tof-cluster-reader",
100 Inputs{},
101 outputs,
102 AlgorithmSpec{adaptFromTask<ClusterReader>(useMC)},
103 Options{
104 {"tof-cluster-infile", VariantType::String, "tofclusters.root", {"Name of the input file"}},
105 {"input-dir", VariantType::String, "none", {"Input directory"}}}};
106}
107
108} // namespace tof
109} // namespace o2
std::ostringstream debug
Helper for geometry and GRP related CCDB requests.
Header of the General Run Parameters object.
Definition of the Names Generator class.
static GRPGeomHelper & instance()
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
void run(ProcessingContext &pc) final
void init(InitContext &ic) final
constexpr o2::header::DataOrigin gDataOriginTOF
Definition DataHeader.h:575
constexpr int LHCMaxBunches
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > Inputs
framework::DataProcessorSpec getClusterReaderSpec(bool useMC)
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"