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 assert(ent < mTree->GetEntries()); // this should not happen
72 mTree->GetEntry(ent);
73
74 pc.outputs().snapshot(Output{"HMP", "CLUSTERS", 0}, mClustersFromFile);
75 pc.outputs().snapshot(Output{"HMP", "INTRECORDS1", 0}, mClusterTriggersFromFile);
76 mClustersReceived += mClustersFromFile.size();
77 LOG(info) << "[HMPID ClusterReader - run() ] clusters = " << mClustersFromFile.size();
78
79 if (mTree->GetReadEntry() + 1 >= mTree->GetEntries()) {
81 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
82 mExTimer.stop();
83 mExTimer.logMes("End ClusterReader ! clusters = " +
84 std::to_string(mClustersReceived));
85 }
86}
87
88void ClusterReaderTask::initFileIn(const std::string& filename)
89{
90 // Create the TFIle
91 mTree.reset(nullptr);
92 mFile = std::make_unique<TFile>(filename.c_str(), "OLD");
93 assert(mFile && !mFile->IsZombie());
94
95 if (!mFile->IsOpen() || mFile == nullptr) {
96 LOG(error) << "HMPID ClusterReaderTask::init() : Did not find any Clusters file " << filename.c_str() << " file !";
97 throw std::runtime_error("cannot open input clusters file");
98 } else {
99 LOG(info) << "HMPID ClusterReaderTask::init() : Found Clusters file " << filename.c_str();
100 }
101
102 if ((TTree*)mFile->Get("o2hmp")) {
103 mTree.reset((TTree*)mFile->Get("o2hmp"));
104 } else if ((TTree*)mFile->Get("o2sim")) {
105 mTree.reset((TTree*)mFile->Get("o2sim"));
106 } else {
107 LOG(error)
108 << "HMPID ClusterReaderTask::init() : Did not find either Tree o2sim or o2hmp tree in "
109 << filename.c_str();
110 throw std::runtime_error(
111 "HMPID ClusterReaderTask::init() : Did not find "
112 "o2sim file in clusters tree");
113 }
114
115 if (mTree->GetBranchStatus("HMPIDClusters") == 1) {
116 mTree->SetBranchAddress("HMPIDClusters", &mClustersFromFilePtr);
117 } else if (mTree->GetBranchStatus("HMPIDclusters") == 1) {
118 mTree->SetBranchAddress("HMPIDclusters", &mClustersFromFilePtr);
119 } else {
120 LOG(error)
121 << "HMPID ClusterReaderTask::init() : Did not find Branch in "
122 << filename.c_str();
123 throw std::runtime_error(
124 "HMPID ClusterReaderTask::init() : Did not find Branch HMPIDClusters in clusters tree");
125 }
126
127 mTree->SetBranchAddress("InteractionRecords", &mClusterTriggersFromFilePtr);
128 mTree->Print("toponly");
129}
130
131//_________________________________________________________________________________________________
132
134{
135
136 std::vector<o2::framework::OutputSpec> outputs;
137 outputs.emplace_back("HMP", "CLUSTERS", 0, o2::framework::Lifetime::Timeframe);
138 outputs.emplace_back("HMP", "INTRECORDS1", 0, o2::framework::Lifetime::Timeframe);
139
140 return DataProcessorSpec{
141 "HMP-ClusterReader",
142 Inputs{},
143 outputs,
144 AlgorithmSpec{adaptFromTask<ClusterReaderTask>()},
145 Options{{"hmpid-cluster-infile" /*"qc-hmpid-clusters"*/, VariantType::String, "hmpidclusters.root", {"Name of the input file with clusters"}},
146 {"input-dir", VariantType::String, "./", {"Input directory"}}}};
147}
148
149} // namespace hmpid
150} // 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 PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
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"