Project
Loading...
Searching...
No Matches
ClustersReaderSpec.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
18
20
21#include <random>
22#include <iostream>
23#include <fstream>
24#include <stdexcept>
25#include <array>
26#include <functional>
27#include <vector>
28
29#include "CommonUtils/StringUtils.h" // o2::utils::Str
30
34#include "Framework/Lifetime.h"
35#include "Framework/Output.h"
36#include "Framework/Logger.h"
39
43
44namespace o2
45{
46namespace hmpid
47{
48
49using namespace o2;
51using namespace o2::framework;
53
54//
56{
57 LOG(info) << "[HMPID Cluster reader - init() ] ";
58 mClustersReceived = 0;
59 // Build the file name
62 ic.options().get<std::string>("input-dir")),
63 ic.options().get<std::string>("hmpid-cluster-infile" /*"qc-hmpid-clusters"*/));
64 initFileIn(filename);
65}
66
68{
69
70 auto ent = mTree->GetReadEntry() + 1;
71 // A timeframe holds no collision at all whenever the interaction rate is low enough, and
72 // the tree then has no entry to read. Publish empty containers instead of reading past the
73 // end and pushing branch addresses that GetEntry has not filled, so that the consumers
74 // downstream still see the timeframe. (This used to be an assert, which is compiled out of
75 // every production build since ENABLE_CASSERT defaults to OFF.)
76 const bool noEntry = ent >= mTree->GetEntries();
77 if (noEntry) {
78 LOG(info) << "no entry to read, publishing empty output";
79 } else {
80 mTree->GetEntry(ent);
81 }
82
83 pc.outputs().snapshot(Output{"HMP", "CLUSTERS", 0}, mClustersFromFile);
84 pc.outputs().snapshot(Output{"HMP", "INTRECORDS1", 0}, mClusterTriggersFromFile);
85 mClustersReceived += mClustersFromFile.size();
86 LOG(info) << "[HMPID ClusterReader - run() ] clusters = " << mClustersFromFile.size();
87
88 if (noEntry || mTree->GetReadEntry() + 1 >= mTree->GetEntries()) {
90 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
91 mExTimer.stop();
92 mExTimer.logMes("End ClusterReader ! clusters = " +
93 std::to_string(mClustersReceived));
94 }
95}
96
97void ClusterReaderTask::initFileIn(const std::string& filename)
98{
99 // Create the TFIle
100 mTree.reset(nullptr);
101 mFile = std::make_unique<TFile>(filename.c_str(), "OLD");
102 assert(mFile && !mFile->IsZombie());
103
104 if (!mFile->IsOpen() || mFile == nullptr) {
105 LOG(error) << "HMPID ClusterReaderTask::init() : Did not find any Clusters file " << filename.c_str() << " file !";
106 throw std::runtime_error("cannot open input clusters file");
107 } else {
108 LOG(info) << "HMPID ClusterReaderTask::init() : Found Clusters file " << filename.c_str();
109 }
110
111 if ((TTree*)mFile->Get("o2hmp")) {
112 mTree.reset((TTree*)mFile->Get("o2hmp"));
113 } else if ((TTree*)mFile->Get("o2sim")) {
114 mTree.reset((TTree*)mFile->Get("o2sim"));
115 } else {
116 LOG(error)
117 << "HMPID ClusterReaderTask::init() : Did not find either Tree o2sim or o2hmp tree in "
118 << filename.c_str();
119 throw std::runtime_error(
120 "HMPID ClusterReaderTask::init() : Did not find "
121 "o2sim file in clusters tree");
122 }
123
124 if (mTree->GetBranchStatus("HMPIDClusters") == 1) {
125 mTree->SetBranchAddress("HMPIDClusters", &mClustersFromFilePtr);
126 } else if (mTree->GetBranchStatus("HMPIDclusters") == 1) {
127 mTree->SetBranchAddress("HMPIDclusters", &mClustersFromFilePtr);
128 } else {
129 LOG(error)
130 << "HMPID ClusterReaderTask::init() : Did not find Branch in "
131 << filename.c_str();
132 throw std::runtime_error(
133 "HMPID ClusterReaderTask::init() : Did not find Branch HMPIDClusters in clusters tree");
134 }
135
136 mTree->SetBranchAddress("InteractionRecords", &mClusterTriggersFromFilePtr);
137 mTree->Print("toponly");
138}
139
140//_________________________________________________________________________________________________
141
143{
144
145 std::vector<o2::framework::OutputSpec> outputs;
146 outputs.emplace_back("HMP", "CLUSTERS", 0, o2::framework::Lifetime::Timeframe);
147 outputs.emplace_back("HMP", "INTRECORDS1", 0, o2::framework::Lifetime::Timeframe);
148
149 return DataProcessorSpec{
150 "HMP-ClusterReader",
151 Inputs{},
152 outputs,
153 AlgorithmSpec{adaptFromTask<ClusterReaderTask>()},
154 Options{{"hmpid-cluster-infile" /*"qc-hmpid-clusters"*/, VariantType::String, "hmpidclusters.root", {"Name of the input file with clusters"}},
155 {"input-dir", VariantType::String, "./", {"Input directory"}}}};
156}
157
158} // namespace hmpid
159} // end namespace o2
A raw page parser for DPL input.
A helper class to iteratate over all parts of all input routes.
Definition of the RAW Data Header.
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 init(framework::InitContext &ic) final
void run(framework::ProcessingContext &pc) final
void stop()
stop : stops the timer
Definition Common.h:73
void logMes(std::string const message)
Definition Common.h:81
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > Inputs
o2::framework::DataProcessorSpec getClusterReaderSpec()
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52
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"