Project
Loading...
Searching...
No Matches
IRFrameReaderSpec.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 <cassert>
18#include "Framework/Task.h"
19#include "Framework/Logger.h"
23#include "TFile.h"
24#include "TTree.h"
25
26using namespace o2::framework;
27
28namespace o2
29{
30namespace globaltracking
31{
32
34{
35 public:
37 ~IRFrameReaderSpec() override = default;
38 void init(o2::framework::InitContext& ic) final;
40
41 protected:
42 void connectTree(const std::string& filename);
44 uint32_t mSubSpec = 0;
45 std::vector<o2::dataformats::IRFrame> mIRF, *mIRFInp = &mIRF;
46 std::unique_ptr<TFile> mFile;
47 std::unique_ptr<TTree> mTree;
48 std::string mInputFileName = "";
49 std::string mTreeName = "o2sim";
50 std::string mBranchName = "IRFrames";
51};
52
54{
56 ic.options().get<std::string>("irframe-infile"));
58}
59
61{
62 auto ent = mTree->GetReadEntry() + 1;
63 // A timeframe holds no collision at all whenever the interaction rate is low enough, and
64 // the tree then has no entry to read. Publish empty containers instead of reading past the
65 // end and pushing branch addresses that GetEntry has not filled, so that the consumers
66 // downstream still see the timeframe. (This used to be an assert, which is compiled out of
67 // every production build since ENABLE_CASSERT defaults to OFF.)
68 const bool noEntry = ent >= mTree->GetEntries();
69 if (noEntry) {
70 LOG(info) << "no entry to read, publishing empty output";
71 } else {
72 mTree->GetEntry(ent);
73 }
74 LOG(debug) << "Pushing " << mIRF.size() << " IR-frames in at entry " << ent;
75 pc.outputs().snapshot(Output{mDataOrigin, "IRFRAMES", mSubSpec}, mIRF);
76
77 if (noEntry || mTree->GetReadEntry() + 1 >= mTree->GetEntries()) {
79 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
80 }
81}
82
84{
85 mTree.reset(nullptr); // in case it was already loaded
86 mFile.reset(TFile::Open(filename.c_str()));
87 assert(mFile && !mFile->IsZombie());
88 mTree.reset((TTree*)mFile->Get(mTreeName.c_str()));
89 assert(mTree);
90 assert(mTree->GetBranch(mBranchName.c_str()));
91
92 mTree->SetBranchAddress(mBranchName.c_str(), &mIRFInp);
93 LOG(info) << "Loaded tree from " << filename << " with " << mTree->GetEntries() << " entries";
94}
95
96DataProcessorSpec getIRFrameReaderSpec(o2::header::DataOrigin origin, uint32_t subSpec, const std::string& devName, const std::string& defFileName)
97{
98 std::vector<OutputSpec> outputSpec;
99
100 return DataProcessorSpec{
101 devName,
102 Inputs{},
103 Outputs{{origin, "IRFRAMES", subSpec, Lifetime::Timeframe}},
104 AlgorithmSpec{adaptFromTask<IRFrameReaderSpec>(origin, subSpec)},
105 Options{
106 {"irframe-infile", VariantType::String, defFileName, {"Name of the input IRFrames file"}},
107 {"input-dir", VariantType::String, "none", {"Input directory"}}}};
108}
109
110} // namespace globaltracking
111} // namespace o2
header::DataOrigin origin
std::ostringstream debug
Class to delimit start and end IR of certain time period.
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
IRFrameReaderSpec(o2::header::DataOrigin origin, uint32_t subSpec)
void run(o2::framework::ProcessingContext &pc) final
void init(o2::framework::InitContext &ic) final
void connectTree(const std::string &filename)
std::vector< o2::dataformats::IRFrame > mIRF
std::vector< o2::dataformats::IRFrame > * mIRFInp
constexpr o2::header::DataOrigin gDataOriginInvalid
Definition DataHeader.h:561
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > Inputs
std::vector< OutputSpec > Outputs
framework::DataProcessorSpec getIRFrameReaderSpec(o2::header::DataOrigin origin, uint32_t subSpec, const std::string &devName, const std::string &defFileName)
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"