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
16#include "TTree.h"
17
20#include "Framework/Logger.h"
22#include <cassert>
24
25using namespace o2::framework;
26using namespace o2::itsmft;
27
28namespace o2
29{
30namespace its3
31{
32
33ClusterReader::ClusterReader(bool useMC, bool usePatterns)
34{
35 mUseMC = useMC;
36 mUsePatterns = usePatterns;
37}
38
40{
41 mFileName = o2::utils::concat_string(o2::base::NameConf::rectifyDirectory(ic.options().get<std::string>("input-dir")),
42 ic.options().get<std::string>((mDetNameLC + "-cluster-infile").c_str()));
44}
45
47{
48 auto ent = mTree->GetReadEntry() + 1;
49 assert(ent < mTree->GetEntries()); // this should not happen
50 mTree->GetEntry(ent);
51 LOG(info) << mDetNameReal << "ClusterReader pushes " << mClusROFRec.size() << " ROFRecords,"
52 << mClusterCompArray.size() << " compact clusters at entry " << ent;
53
54 // This is a very ugly way of providing DataDescription, which anyway does not need to contain detector name.
55 // To be fixed once the names-definition class is ready
56 pc.outputs().snapshot(Output{mOrigin, "CLUSTERSROF", 0}, mClusROFRec);
57 pc.outputs().snapshot(Output{mOrigin, "COMPCLUSTERS", 0}, mClusterCompArray);
58 if (mUsePatterns) {
59 pc.outputs().snapshot(Output{mOrigin, "PATTERNS", 0}, mPatternsArray);
60 }
61 if (mUseMC) {
62 pc.outputs().snapshot(Output{mOrigin, "CLUSTERSMCTR", 0}, mClusterMCTruth);
63 pc.outputs().snapshot(Output{mOrigin, "CLUSTERSMC2ROF", 0}, mClusMC2ROFs);
64 }
65
66 if (mTree->GetReadEntry() + 1 >= mTree->GetEntries()) {
68 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
69 }
70}
71
72void ClusterReader::connectTree(const std::string& filename)
73{
74 mTree.reset(nullptr); // in case it was already loaded
75 mFile.reset(TFile::Open(filename.c_str()));
76 assert(mFile && !mFile->IsZombie());
77 mTree.reset((TTree*)mFile->Get(mClusTreeName.c_str()));
78 assert(mTree);
79
80 mTree->SetBranchAddress((mDetName + mClusROFBranchName).c_str(), &mClusROFRecPtr);
81 mTree->SetBranchAddress((mDetName + mClusterCompBranchName).c_str(), &mClusterCompArrayPtr);
82 if (mUsePatterns) {
83 mTree->SetBranchAddress((mDetName + mClusterPattBranchName).c_str(), &mPatternsArrayPtr);
84 }
85 if (mUseMC) {
86 if (mTree->GetBranch((mDetName + mClustMCTruthBranchName).c_str()) &&
87 mTree->GetBranch((mDetName + mClustMC2ROFBranchName).c_str())) {
88 mTree->SetBranchAddress((mDetName + mClustMCTruthBranchName).c_str(), &mClusterMCTruthPtr);
89 mTree->SetBranchAddress((mDetName + mClustMC2ROFBranchName).c_str(), &mClusMC2ROFsPtr);
90 } else {
91 LOG(info) << "MC-truth is missing";
92 mUseMC = false;
93 }
94 }
95 LOG(info) << "Loaded tree from " << filename << " with " << mTree->GetEntries() << " entries";
96}
97
98DataProcessorSpec getITS3ClusterReaderSpec(bool useMC, bool usePatterns)
99{
100 std::vector<OutputSpec> outputSpec;
101 outputSpec.emplace_back("IT3", "CLUSTERSROF", 0, Lifetime::Timeframe);
102 outputSpec.emplace_back("IT3", "COMPCLUSTERS", 0, Lifetime::Timeframe);
103 if (usePatterns) {
104 outputSpec.emplace_back("IT3", "PATTERNS", 0, Lifetime::Timeframe);
105 }
106 if (useMC) {
107 outputSpec.emplace_back("IT3", "CLUSTERSMCTR", 0, Lifetime::Timeframe);
108 outputSpec.emplace_back("IT3", "CLUSTERSMC2ROF", 0, Lifetime::Timeframe);
109 }
110
111 return DataProcessorSpec{
112 "its3-cluster-reader",
113 Inputs{},
114 outputSpec,
115 AlgorithmSpec{adaptFromTask<ClusterReader>(useMC, usePatterns)},
116 Options{
117 {"its-cluster-infile", VariantType::String, "o2clus_its.root", {"Name of the input cluster file"}},
118 {"input-dir", VariantType::String, "none", {"Input directory"}}}};
119}
120
121} // namespace its3
122} // 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
void connectTree(const std::string &filename)
std::unique_ptr< TTree > mTree
std::unique_ptr< TFile > mFile
std::vector< o2::itsmft::ROFRecord > mClusROFRec
void run(ProcessingContext &pc) final
std::vector< unsigned char > mPatternsArray
void init(InitContext &ic) final
std::vector< o2::itsmft::CompClusterExt > mClusterCompArray
std::vector< o2::itsmft::MC2ROFRecord > mClusMC2ROFs
std::vector< o2::itsmft::ROFRecord > * mClusROFRecPtr
o2::dataformats::MCTruthContainer< o2::MCCompLabel > * mClusterMCTruthPtr
std::vector< o2::itsmft::CompClusterExt > * mClusterCompArrayPtr
o2::dataformats::MCTruthContainer< o2::MCCompLabel > mClusterMCTruth
std::vector< o2::itsmft::MC2ROFRecord > * mClusMC2ROFsPtr
std::vector< unsigned char > * mPatternsArrayPtr
o2::header::DataOrigin mOrigin
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > Inputs
framework::DataProcessorSpec getITS3ClusterReaderSpec(bool useMC=true, bool usePatterns=true)
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"