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:
36 IRFrameReaderSpec(o2::header::DataOrigin origin, uint32_t subSpec) : mDataOrigin(origin), mSubSpec(subSpec) {}
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 assert(ent < mTree->GetEntries()); // this should not happen
64 mTree->GetEntry(ent);
65 LOG(debug) << "Pushing " << mIRF.size() << " IR-frames in at entry " << ent;
66 pc.outputs().snapshot(Output{mDataOrigin, "IRFRAMES", mSubSpec}, mIRF);
67
68 if (mTree->GetReadEntry() + 1 >= mTree->GetEntries()) {
70 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
71 }
72}
73
75{
76 mTree.reset(nullptr); // in case it was already loaded
77 mFile.reset(TFile::Open(filename.c_str()));
78 assert(mFile && !mFile->IsZombie());
79 mTree.reset((TTree*)mFile->Get(mTreeName.c_str()));
80 assert(mTree);
81 assert(mTree->GetBranch(mBranchName.c_str()));
82
83 mTree->SetBranchAddress(mBranchName.c_str(), &mIRFInp);
84 LOG(info) << "Loaded tree from " << filename << " with " << mTree->GetEntries() << " entries";
85}
86
87DataProcessorSpec getIRFrameReaderSpec(o2::header::DataOrigin origin, uint32_t subSpec, const std::string& devName, const std::string& defFileName)
88{
89 std::vector<OutputSpec> outputSpec;
90
91 return DataProcessorSpec{
92 devName,
93 Inputs{},
94 Outputs{{origin, "IRFRAMES", subSpec, Lifetime::Timeframe}},
95 AlgorithmSpec{adaptFromTask<IRFrameReaderSpec>(origin, subSpec)},
96 Options{
97 {"irframe-infile", VariantType::String, defFileName, {"Name of the input IRFrames file"}},
98 {"input-dir", VariantType::String, "none", {"Input directory"}}}};
99}
100
101} // namespace globaltracking
102} // namespace o2
Class to delimit start and end IR of certain time period.
std::ostringstream debug
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 PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
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"