Project
Loading...
Searching...
No Matches
StrangenessTrackingReaderSpec.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
15
16#include <vector>
17
20#include "Framework/Logger.h"
25#include "TFile.h"
26#include "TTree.h"
27
28using namespace o2::framework;
29
30namespace o2
31{
32namespace strangeness_tracking
33{
34// read strangeness tracking candidates
36{
37 // using RRef = o2::dataformats::RangeReference<int, int>;
39
40 public:
41 StrangenessTrackingReader(bool useMC) : mUseMC(useMC) {}
42 ~StrangenessTrackingReader() override = default;
43 void init(o2::framework::InitContext& ic) final;
45
46 protected:
47 void connectTree();
48
49 bool mUseMC = false;
50 bool mVerbose = false;
51
52 std::vector<StrangeTrack> mStrangeTrack, *mStrangeTrackPtr = &mStrangeTrack;
53 std::vector<o2::MCCompLabel> mStrangeTrackMC, *mStrangeTrackMCPtr = &mStrangeTrackMC;
54 // std::vector<RRef> mPV2V0Ref, *mPV2V0RefPtr = &mPV2V0Ref;
55
56 std::unique_ptr<TFile> mFile;
57 std::unique_ptr<TTree> mTree;
58 std::string mFileName = "";
59 std::string mFileNameMatches = "";
60 std::string mSTrackingTreeName = "o2sim";
61 std::string mStrackBranchName = "StrangeTracks";
62 std::string mStrackMCBranchName = "StrangeTrackMCLab";
63 // std::string mPVertex2V0RefBranchName = "PV2V0Refs";
64};
65
67{
69 ic.options().get<std::string>("strange-tracks-infile"));
71}
72
74{
75 auto ent = mTree->GetReadEntry() + 1;
76 // A timeframe holds no collision at all whenever the interaction rate is low enough, and
77 // the tree then has no entry to read. Publish empty containers instead of reading past the
78 // end and pushing branch addresses that GetEntry has not filled, so that the consumers
79 // downstream still see the timeframe. (This used to be an assert, which is compiled out of
80 // every production build since ENABLE_CASSERT defaults to OFF.)
81 const bool noEntry = ent >= mTree->GetEntries();
82 if (noEntry) {
83 LOG(info) << "no entry to read, publishing empty output";
84 } else {
85 mTree->GetEntry(ent);
86 }
87 LOG(info) << "Pushing " << mStrangeTrack.size() << " strange tracks at entry " << ent;
88 pc.outputs().snapshot(Output{"GLO", "STRANGETRACKS", 0}, mStrangeTrack);
89
90 if (mUseMC) {
91 LOG(info) << "Pushing " << mStrangeTrackMC.size() << " strange tracks MC labels at entry " << ent;
92 pc.outputs().snapshot(Output{"GLO", "STRANGETRACKS_MC", 0}, mStrangeTrackMC);
93 }
94
95 // pc.outputs().snapshot(Output{"GLO", "PVTX_V0REFS", 0}, mPV2V0Ref);
96
97 if (noEntry || mTree->GetReadEntry() + 1 >= mTree->GetEntries()) {
99 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
100 }
101}
102
104{
105 mTree.reset(nullptr); // in case it was already loaded
106 mFile.reset(TFile::Open(mFileName.c_str()));
107 assert(mFile && !mFile->IsZombie());
108 mTree.reset((TTree*)mFile->Get(mSTrackingTreeName.c_str()));
109 assert(mTree);
110 assert(mTree->GetBranch(mStrackBranchName.c_str()));
111
112 mTree->SetBranchAddress(mStrackBranchName.c_str(), &mStrangeTrackPtr);
113 if (mUseMC) {
114 assert(mTree->GetBranch(mStrackMCBranchName.c_str()));
115 mTree->SetBranchAddress(mStrackMCBranchName.c_str(), &mStrangeTrackMCPtr);
116 }
117
118 LOG(info) << "Loaded " << mSTrackingTreeName << " tree from " << mFileName << " with " << mTree->GetEntries() << " entries";
119}
120
122{
123 std::vector<OutputSpec> outputs;
124 outputs.emplace_back("GLO", "STRANGETRACKS", 0, Lifetime::Timeframe); // found strange tracks
125 if (useMC) {
126 outputs.emplace_back("GLO", "STRANGETRACKS_MC", 0, Lifetime::Timeframe); // MC labels
127 }
128
129 return DataProcessorSpec{
130 "strangeness-tracking-reader",
131 Inputs{},
132 outputs,
133 AlgorithmSpec{adaptFromTask<StrangenessTrackingReader>(useMC)},
134 Options{
135 {"strange-tracks-infile", VariantType::String, "o2_strange_tracks.root", {"Name of the input strange tracks file"}},
136 {"input-dir", VariantType::String, "none", {"Input directory"}}}};
137}
138
139} // namespace strangeness_tracking
140} // namespace o2
Definition of the Names Generator class.
Class to refer to the 1st entry and N elements of some group in the continuous container.
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
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > Inputs
o2::framework::DataProcessorSpec getStrangenessTrackingReaderSpec(bool useMC)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
static std::string rectifyDirectory(const std::string_view p)
static std::string concat_string(Ts const &... ts)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"