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 assert(ent < mTree->GetEntries()); // this should not happen
44 mTree->GetEntry(ent);
45 LOG(debug) << "Pushing " << mClustersPtr->size() << " TOF clusters at entry " << ent;
46
47 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "CLUSTERS", 0}, mClusters);
48 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "CLUSTERSMULT", 0}, mClustersMult);
49 if (mUseMC) {
50 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "CLUSTERSMCTR", 0}, mLabels);
51 }
52
53 if (mTree->GetReadEntry() + 1 >= mTree->GetEntries()) {
55 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
56 }
57}
58
59void ClusterReader::connectTree(const std::string& filename)
60{
61 mTree.reset(nullptr); // in case it was already loaded
62 mFile.reset(TFile::Open(filename.c_str()));
63 assert(mFile && !mFile->IsZombie());
64 mTree.reset((TTree*)mFile->Get("o2sim"));
65 assert(mTree);
66 mTree->SetBranchAddress("TOFCluster", &mClustersPtr);
67
68 if (mTree->GetBranch("TOFClusterMult")) {
69 mTree->SetBranchAddress("TOFClusterMult", &mClustersMultPtr);
70 } else {
71 mClustersMult.resize(o2::base::GRPGeomHelper::instance().getNHBFPerTF() * o2::constants::lhc::LHCMaxBunches);
72 }
73
74 if (mUseMC) {
75 mTree->SetBranchAddress("TOFClusterMCTruth", &mLabelsPtr);
76 }
77 LOG(debug) << "Loaded tree from " << filename << " with " << mTree->GetEntries() << " entries";
78}
79
81{
82 std::vector<OutputSpec> outputs;
83 outputs.emplace_back(o2::header::gDataOriginTOF, "CLUSTERS", 0, Lifetime::Timeframe);
84 outputs.emplace_back(o2::header::gDataOriginTOF, "CLUSTERSMULT", 0, Lifetime::Timeframe);
85 if (useMC) {
86 outputs.emplace_back(o2::header::gDataOriginTOF, "CLUSTERSMCTR", 0, Lifetime::Timeframe);
87 }
88
89 return DataProcessorSpec{
90 "tof-cluster-reader",
91 Inputs{},
92 outputs,
93 AlgorithmSpec{adaptFromTask<ClusterReader>(useMC)},
94 Options{
95 {"tof-cluster-infile", VariantType::String, "tofclusters.root", {"Name of the input file"}},
96 {"input-dir", VariantType::String, "none", {"Input directory"}}}};
97}
98
99} // namespace tof
100} // namespace o2
Helper for geometry and GRP related CCDB requests.
Header of the General Run Parameters object.
Definition of the Names Generator class.
std::ostringstream debug
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 PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
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"