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 assert(ent < mTree->GetEntries()); // this should not happen
77 mTree->GetEntry(ent);
78 LOG(info) << "Pushing " << mStrangeTrack.size() << " strange tracks at entry " << ent;
79 pc.outputs().snapshot(Output{"GLO", "STRANGETRACKS", 0}, mStrangeTrack);
80
81 if (mUseMC) {
82 LOG(info) << "Pushing " << mStrangeTrackMC.size() << " strange tracks MC labels at entry " << ent;
83 pc.outputs().snapshot(Output{"GLO", "STRANGETRACKS_MC", 0}, mStrangeTrackMC);
84 }
85
86 // pc.outputs().snapshot(Output{"GLO", "PVTX_V0REFS", 0}, mPV2V0Ref);
87
88 if (mTree->GetReadEntry() + 1 >= mTree->GetEntries()) {
90 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
91 }
92}
93
95{
96 mTree.reset(nullptr); // in case it was already loaded
97 mFile.reset(TFile::Open(mFileName.c_str()));
98 assert(mFile && !mFile->IsZombie());
99 mTree.reset((TTree*)mFile->Get(mSTrackingTreeName.c_str()));
100 assert(mTree);
101 assert(mTree->GetBranch(mStrackBranchName.c_str()));
102
103 mTree->SetBranchAddress(mStrackBranchName.c_str(), &mStrangeTrackPtr);
104 if (mUseMC) {
105 assert(mTree->GetBranch(mStrackMCBranchName.c_str()));
106 mTree->SetBranchAddress(mStrackMCBranchName.c_str(), &mStrangeTrackMCPtr);
107 }
108
109 LOG(info) << "Loaded " << mSTrackingTreeName << " tree from " << mFileName << " with " << mTree->GetEntries() << " entries";
110}
111
113{
114 std::vector<OutputSpec> outputs;
115 outputs.emplace_back("GLO", "STRANGETRACKS", 0, Lifetime::Timeframe); // found strange tracks
116 if (useMC) {
117 outputs.emplace_back("GLO", "STRANGETRACKS_MC", 0, Lifetime::Timeframe); // MC labels
118 }
119
120 return DataProcessorSpec{
121 "strangeness-tracking-reader",
122 Inputs{},
123 outputs,
124 AlgorithmSpec{adaptFromTask<StrangenessTrackingReader>(useMC)},
125 Options{
126 {"strange-tracks-infile", VariantType::String, "o2_strange_tracks.root", {"Name of the input strange tracks file"}},
127 {"input-dir", VariantType::String, "none", {"Input directory"}}}};
128}
129
130} // namespace strangeness_tracking
131} // 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 PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
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"