Project
Loading...
Searching...
No Matches
CalibClusReaderSpec.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
19#include "Framework/Logger.h"
20
21using namespace o2::framework;
22using namespace o2::tof;
23
24namespace o2
25{
26namespace tof
27{
28
30{
31 LOG(debug) << "Init Cluster reader!";
32 auto filename = ic.options().get<std::string>("tof-calclus-infile");
33 connectTree(filename);
34}
35
37{
38 auto ent = mTree->GetReadEntry() + 1;
39 // A timeframe holds no collision at all whenever the interaction rate is low enough, and
40 // the tree then has no entry to read. Publish empty containers instead of reading past the
41 // end and pushing branch addresses that GetEntry has not filled, so that the consumers
42 // downstream still see the timeframe. (This used to be an assert, which is compiled out of
43 // every production build since ENABLE_CASSERT defaults to OFF.)
44 const bool noEntry = ent >= mTree->GetEntries();
45 if (noEntry) {
46 LOG(info) << "no entry to read, publishing empty output";
47 } else {
48 mTree->GetEntry(ent);
49 }
50 LOG(debug) << "Pushing " << mPclusInfos->size() << " TOF clusters calib info at entry " << ent;
51 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "INFOCALCLUS", 0}, mClusInfos);
52
53 if (mIsCosmics) {
54 LOG(debug) << "Pushing " << mPcosmicInfo->size() << " TOF cosmics info at entry " << ent;
55 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "INFOCOSMICS", 0}, mCosmicInfo);
56 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "INFOTRACKCOS", 0}, mCosmicTrack);
57 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "INFOTRACKSIZE", 0}, mCosmicTrackSize);
58 }
59
60 if (noEntry || mTree->GetReadEntry() + 1 >= mTree->GetEntries()) {
62 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
63 }
64}
65
66void CalibClusReader::connectTree(const std::string& filename)
67{
68 mTree.reset(nullptr); // in case it was already loaded
69 mFile.reset(TFile::Open(filename.c_str()));
70 assert(mFile && !mFile->IsZombie());
71 mTree.reset((TTree*)mFile->Get("o2sim"));
72 assert(mTree);
73 mTree->SetBranchAddress("TOFClusterCalInfo", &mPclusInfos);
74 if (mIsCosmics) {
75 mTree->SetBranchAddress("TOFCosmics", &mPcosmicInfo);
76 mTree->SetBranchAddress("TOFTracks", &mPcosmicTrack);
77 mTree->SetBranchAddress("TOFTracksSize", &mPcosmicTrackSize);
78 }
79 LOG(debug) << "Loaded tree from " << filename << " with " << mTree->GetEntries() << " entries";
80}
81
83{
84 std::vector<OutputSpec> outputs;
85 outputs.emplace_back(o2::header::gDataOriginTOF, "INFOCALCLUS", 0, Lifetime::Timeframe);
86 if (isCosmics) {
87 outputs.emplace_back(o2::header::gDataOriginTOF, "INFOCOSMICS", 0, Lifetime::Timeframe);
88 outputs.emplace_back(o2::header::gDataOriginTOF, "INFOTRACKCOS", 0, Lifetime::Timeframe);
89 outputs.emplace_back(o2::header::gDataOriginTOF, "INFOTRACKSIZE", 0, Lifetime::Timeframe);
90 }
91
92 return DataProcessorSpec{
93 "tof-calclus-reader",
94 Inputs{},
95 outputs,
96 AlgorithmSpec{adaptFromTask<CalibClusReader>(isCosmics)},
97 Options{
98 {"tof-calclus-infile", VariantType::String, "tofclusCalInfo.root", {"Name of the input file"}}}};
99}
100
101} // namespace tof
102} // namespace o2
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
void init(InitContext &ic) final
void run(ProcessingContext &pc) final
constexpr o2::header::DataOrigin gDataOriginTOF
Definition DataHeader.h:575
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > Inputs
DataProcessorSpec getCalibClusReaderSpec(bool isCosmics)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::string filename()
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"