Project
Loading...
Searching...
No Matches
GlobalFwdTrackReaderSpec.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#include "TFile.h"
16#include "TTree.h"
17#include "Framework/Task.h"
26#include <fairlogger/Logger.h>
27
28using namespace o2::framework;
29using namespace o2::globaltracking;
30
31namespace o2
32{
33namespace globaltracking
34{
35
37{
38 public:
39 GlobalFwdTrackReader(bool useMC) : mUseMC(useMC) {}
40 ~GlobalFwdTrackReader() override = default;
41 void init(InitContext& ic) final;
42 void run(ProcessingContext& pc) final;
43
44 private:
45 void connectTree(const std::string& filename);
46 bool mUseMC = true;
47 std::unique_ptr<TFile> mFile;
48 std::unique_ptr<TTree> mTree;
49 std::string mFileName = "";
50 std::vector<o2::dataformats::GlobalFwdTrack> mTracks, *mTracksPtr = &mTracks;
51 std::vector<o2::MCCompLabel> mLabels, *mLabelsPtr = &mLabels;
52};
53
55{
56 mFileName = o2::utils::Str::concat_string(o2::utils::Str::rectifyDirectory(ic.options().get<std::string>("input-dir")),
57 ic.options().get<std::string>("globalfwd-track-infile"));
58 connectTree(mFileName);
59}
60
62{
63 auto ent = mTree->GetReadEntry() + 1;
64 assert(ent < mTree->GetEntries()); // this should not happen
65 mTree->GetEntry(ent);
66 LOG(info) << "Pushing " << mTracks.size() << " Global Forward tracks at entry " << ent;
67
68 pc.outputs().snapshot(Output{"GLO", "GLFWD", 0}, mTracks);
69 if (mUseMC) {
70 pc.outputs().snapshot(Output{"GLO", "GLFWD_MC", 0}, mLabels);
71 }
72
73 if (mTree->GetReadEntry() + 1 >= mTree->GetEntries()) {
75 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
76 }
77}
78
79void GlobalFwdTrackReader::connectTree(const std::string& filename)
80{
81 mTree.reset(nullptr); // in case it was already loaded
82 mFile.reset(TFile::Open(filename.c_str()));
83 assert(mFile && !mFile->IsZombie());
84 mTree.reset((TTree*)mFile->Get("GlobalFwdTracks"));
85 assert(mTree);
86 mTree->SetBranchAddress("fwdtracks", &mTracksPtr);
87 if (mUseMC) {
88 mTree->SetBranchAddress("MCTruth", &mLabelsPtr);
89 }
90 LOG(info) << "Loaded tree from " << filename << " with " << mTree->GetEntries() << " entries";
91}
92
94{
95 std::vector<OutputSpec> outputs;
96 outputs.emplace_back("GLO", "GLFWD", 0, Lifetime::Timeframe);
97 if (useMC) {
98 outputs.emplace_back("GLO", "GLFWD_MC", 0, Lifetime::Timeframe);
99 }
100 return DataProcessorSpec{
101 "globalfwd-track-reader",
102 Inputs{},
103 outputs,
104 AlgorithmSpec{adaptFromTask<GlobalFwdTrackReader>(useMC)},
105 Options{
106 {"globalfwd-track-infile", VariantType::String, "globalfwdtracks.root", {"Name of the input file"}},
107 {"input-dir", VariantType::String, "none", {"Input directory"}}}};
108}
109
110} // namespace globaltracking
111} // namespace o2
Header of the General Run Parameters object.
Global Forward Muon tracks.
Definition of the Names Generator class.
Type wrappers for enfording a specific serialization method.
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
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > Inputs
framework::DataProcessorSpec getGlobalFwdTrackReaderSpec(bool useMC)
create a processor spec
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"