Project
Loading...
Searching...
No Matches
TOFMatchedReaderSpec.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#include "TFile.h"
18
22#include "Headers/DataHeader.h"
30
31using namespace o2::framework;
32
33namespace o2
34{
35namespace tof
36{
37static constexpr o2::header::DataDescription ddMatchInfo[4] = {"MTC_TPC", "MTC_ITSTPC", "MTC_TPCTRD", "MTC_ITSTPCTRD"};
38static constexpr o2::header::DataDescription ddMCMatchTOF[4] = {"MCMTC_TPC", "MCMTC_ITSTPC", "MCMTC_TPCTRD", "MCMTC_ITSTPCTRD"};
40{
41 // get the option from the init context
42 LOG(debug) << "Init TOF matching info reader!";
43 mInFileName = o2::utils::Str::concat_string(o2::utils::Str::rectifyDirectory(ic.options().get<std::string>("input-dir")),
44 ic.options().get<std::string>("tof-matched-infile"));
45 mInTreeName = ic.options().get<std::string>("treename");
46 connectTree(mInFileName);
47}
48
49void TOFMatchedReader::connectTree(const std::string& filename)
50{
51 mTree.reset(nullptr); // in case it was already loaded
52 mFile.reset(TFile::Open(filename.c_str()));
53 assert(mFile && !mFile->IsZombie());
54 mTree.reset((TTree*)mFile->Get(mInTreeName.c_str()));
55 assert(mTree);
56 mTree->SetBranchAddress("TOFMatchInfo", &mMatchesPtr);
57 if (mReadTracks) {
58 if (!mTree->GetBranch("TPCTOFTracks")) {
59 throw std::runtime_error("TPC-TOF tracks are requested but not found in the tree");
60 }
61 mTree->SetBranchAddress("TPCTOFTracks", &mTracksPtr);
62 }
63 if (mUseMC) {
64 mTree->SetBranchAddress("MatchTOFMCTruth", &mLabelTOFPtr);
65 }
66 LOG(debug) << "Loaded tree from " << filename << " with " << mTree->GetEntries() << " entries";
67}
68
70{
71 auto currEntry = mTree->GetReadEntry() + 1;
72 assert(currEntry < mTree->GetEntries()); // this should not happen
73 mTree->GetEntry(currEntry);
74 LOG(debug) << "Pushing " << mMatches.size() << " TOF matchings at entry " << currEntry;
75
76 uint32_t tpcMatchSS = o2::globaltracking::getSubSpec(mSubSpecStrict && (!mMode) ? o2::globaltracking::MatchingType::Strict : o2::globaltracking::MatchingType::Standard);
77 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, ddMatchInfo[mMode], tpcMatchSS}, mMatches);
78 if (mReadTracks && (!mMode)) {
79 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "TOFTRACKS_TPC", tpcMatchSS}, mTracks);
80 }
81 if (mUseMC) {
82 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, ddMCMatchTOF[mMode], tpcMatchSS}, mLabelTOF);
83 }
84
85 if (mTree->GetReadEntry() + 1 >= mTree->GetEntries()) {
87 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
88 }
89}
90
91DataProcessorSpec getTOFMatchedReaderSpec(bool useMC, int mode, bool readTracks, bool subSpecStrict)
92{
93 const char* match_name[4] = {"TOFMatchedReader_TPC", "TOFMatchedReader_ITSTPC", "TOFMatchedReader_TPCTRD", "TOFMatchedReader_ITSTPCTRD"};
94 const char* match_name_strict[4] = {"TOFMatchedReader_TPC_str", "TOFMatchedReader_ITSTPC_str", "TOFMatchedReader_TPCTRD_str", "TOFMatchedReader_ITSTPCTRD_str"};
95 const char* file_name[4] = {"o2match_tof_tpc.root", "o2match_tof_itstpc.root", "o2match_tof_tpctrd.root", "o2match_tof_itstpctrd.root"};
96 const char* taskName = match_name[mode];
97 const char* fileName = file_name[mode];
98 if (subSpecStrict) {
99 taskName = match_name_strict[mode];
100 }
101
102 std::vector<OutputSpec> outputs;
103 uint32_t tpcMatchSS = o2::globaltracking::getSubSpec(subSpecStrict && (!mode) ? o2::globaltracking::MatchingType::Strict : o2::globaltracking::MatchingType::Standard);
104 outputs.emplace_back(o2::header::gDataOriginTOF, ddMatchInfo[mode], tpcMatchSS, Lifetime::Timeframe);
105 if (!mode && readTracks) {
106 outputs.emplace_back(o2::header::gDataOriginTOF, "TOFTRACKS_TPC", tpcMatchSS, Lifetime::Timeframe);
107 }
108 if (useMC) {
109 outputs.emplace_back(o2::header::gDataOriginTOF, ddMCMatchTOF[mode], tpcMatchSS, Lifetime::Timeframe);
110 }
111
112 return DataProcessorSpec{
113 taskName,
114 Inputs{},
115 outputs,
116 AlgorithmSpec{adaptFromTask<TOFMatchedReader>(useMC, mode, readTracks, subSpecStrict)},
117 Options{
118 {"tof-matched-infile", VariantType::String, fileName, {"Name of the input file"}},
119 {"input-dir", VariantType::String, "none", {"Input directory"}},
120 {"treename", VariantType::String, "matchTOF", {"Name of top-level TTree"}},
121 }};
122}
123} // namespace tof
124} // namespace o2
Global index for barrel track: provides provenance (detectors combination), index in respective array...
Definition of a container to keep Monte Carlo truth external to simulation objects.
Class to store the output of the matching to TOF.
Defintions for the inter-detector matching type.
Definition of the Names Generator class.
std::ostringstream debug
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(o2::framework::ProcessingContext &pc) final
void init(o2::framework::InitContext &ic) final
GLenum mode
Definition glcorearb.h:266
constexpr o2::header::DataOrigin gDataOriginTOF
Definition DataHeader.h:575
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > Inputs
framework::DataProcessorSpec getTOFMatchedReaderSpec(bool useMC, int mode=1, bool readTracks=false, bool subSpecStrict=false)
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"