Project
Loading...
Searching...
No Matches
TrackCosmicsReaderSpec.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
22
23using namespace o2::framework;
24using namespace o2::globaltracking;
25
26namespace o2
27{
28namespace globaltracking
29{
31{
32 mFileName = o2::utils::Str::concat_string(o2::utils::Str::rectifyDirectory(ic.options().get<std::string>("input-dir")),
33 ic.options().get<std::string>("cosmics-infile"));
34 connectTree(mFileName);
35}
36
38{
39 auto ent = mTree->GetReadEntry() + 1;
40 // A timeframe holds no collision at all whenever the interaction rate is low enough, and
41 // the tree then has no entry to read. Publish empty containers instead of reading past the
42 // end and pushing branch addresses that GetEntry has not filled, so that the consumers
43 // downstream still see the timeframe. (This used to be an assert, which is compiled out of
44 // every production build since ENABLE_CASSERT defaults to OFF.)
45 const bool noEntry = ent >= mTree->GetEntries();
46 if (noEntry) {
47 LOG(info) << "no entry to read, publishing empty output";
48 } else {
49 mTree->GetEntry(ent);
50 }
51 LOG(info) << "Pushing " << mTracks.size() << " Cosmic Tracks at entry " << ent;
52
53 pc.outputs().snapshot(Output{"GLO", "COSMICTRC", 0}, mTracks);
54 if (mUseMC) {
55 pc.outputs().snapshot(Output{"GLO", "COSMICTRC_MC", 0}, mLabels);
56 }
57
58 if (noEntry || mTree->GetReadEntry() + 1 >= mTree->GetEntries()) {
60 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
61 }
62}
63
64void TrackCosmicsReader::connectTree(const std::string& filename)
65{
66 mTree.reset(nullptr); // in case it was already loaded
67 mFile.reset(TFile::Open(filename.c_str()));
68 assert(mFile && !mFile->IsZombie());
69 mTree.reset((TTree*)mFile->Get("cosmics"));
70 assert(mTree);
71 mTree->SetBranchAddress("tracks", &mTracksPtr);
72 if (mUseMC) {
73 mTree->SetBranchAddress("MCTruth", &mLabelsPtr);
74 }
75 LOG(info) << "Loaded tree from " << filename << " with " << mTree->GetEntries() << " entries";
76}
77
79{
80 std::vector<OutputSpec> outputs;
81 outputs.emplace_back("GLO", "COSMICTRC", 0, Lifetime::Timeframe);
82 if (useMC) {
83 outputs.emplace_back("GLO", "COSMICTRC_MC", 0, Lifetime::Timeframe);
84 }
85
86 return DataProcessorSpec{
87 "cosmic-track-reader",
88 Inputs{},
89 outputs,
90 AlgorithmSpec{adaptFromTask<TrackCosmicsReader>(useMC)},
91 Options{
92 {"cosmics-infile", VariantType::String, "cosmics.root", {"Name of the input file"}},
93 {"input-dir", VariantType::String, "none", {"Input directory"}}}};
94}
95
96} // namespace globaltracking
97} // namespace o2
Header of the General Run Parameters object.
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
void run(ProcessingContext &pc) final
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > Inputs
framework::DataProcessorSpec getTrackCosmicsReaderSpec(bool useMC)
create a processor spec to read cosmic tracks from a root file
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"