Project
Loading...
Searching...
No Matches
DigitReaderSpec.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
16#include "TTree.h"
17
20#include "Framework/Logger.h"
28
29using namespace o2::framework;
30
31namespace o2
32{
33namespace zdc
34{
35
37{
38 auto filename = o2::utils::Str::concat_string(o2::utils::Str::rectifyDirectory(ic.options().get<std::string>("input-dir")), ic.options().get<std::string>("zdc-digit-infile"));
39 mFirstEntry = ic.options().get<int>("first-entry");
40 mLastEntry = ic.options().get<int>("last-entry");
41 mFile.reset(TFile::Open(filename.c_str()));
42 if (!mFile->IsOpen()) {
43 LOG(error) << "Cannot open the " << filename.c_str() << " file !";
44 throw std::runtime_error("cannot open input digits file");
45 }
46 mTree.reset((TTree*)mFile->Get("o2sim"));
47 if (!mTree) {
48 LOG(error) << "Did not find o2sim tree in " << filename.c_str();
49 throw std::runtime_error("Did not fine o2sim file in ZDC digits tree");
50 }
51}
52
54{
55
56 std::vector<o2::zdc::OrbitData> zdcOrbitData, *zdcOrbitDataPtr = &zdcOrbitData;
57 std::vector<o2::zdc::BCData> zdcBCData, *zdcBCDataPtr = &zdcBCData;
58 std::vector<o2::zdc::ChannelData> zdcChData, *zdcChDataPtr = &zdcChData;
59
60 mTree->SetBranchAddress("ZDCDigitOrbit", &zdcOrbitDataPtr);
61 mTree->SetBranchAddress("ZDCDigitBC", &zdcBCDataPtr);
62 mTree->SetBranchAddress("ZDCDigitCh", &zdcChDataPtr);
64 if (mUseMC) {
65 mTree->SetBranchAddress("ZDCDigitLabels", &plabels);
66 }
67
68 auto ent = mTree->GetReadEntry() < 0 ? mTree->GetReadEntry() + mFirstEntry + 1 : mTree->GetReadEntry() + 1;
69 // A timeframe holds no collision at all whenever the interaction rate is low enough, and
70 // the tree then has no entry to read. Publish empty containers instead of reading past the
71 // end and pushing branch addresses that GetEntry has not filled, so that the consumers
72 // downstream still see the timeframe. (This used to be an assert, which is compiled out of
73 // every production build since ENABLE_CASSERT defaults to OFF.)
74 const bool noEntry = ent >= mTree->GetEntries();
75 if (noEntry) {
76 LOG(info) << "no entry to read, publishing empty output";
77 } else {
78 mTree->GetEntry(ent);
79 }
80 LOG(info) << "ZDCDigitReader pushed " << zdcOrbitData.size() << " orbits with " << zdcBCData.size() << " bcs and " << zdcChData.size() << " digits";
81 pc.outputs().snapshot(Output{"ZDC", "DIGITSPD", 0}, zdcOrbitData);
82 pc.outputs().snapshot(Output{"ZDC", "DIGITSBC", 0}, zdcBCData);
83 pc.outputs().snapshot(Output{"ZDC", "DIGITSCH", 0}, zdcChData);
84 if (mUseMC) {
85 pc.outputs().snapshot(Output{"ZDC", "DIGITSLBL", 0}, labels);
86 }
87 uint64_t nextEntry = mTree->GetReadEntry() + 1;
88 if (noEntry || nextEntry >= mTree->GetEntries() || (mLastEntry >= 0 && nextEntry > mLastEntry)) {
90 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
91 }
92}
93
95{
96 std::vector<OutputSpec> outputs;
97 outputs.emplace_back("ZDC", "DIGITSBC", 0, Lifetime::Timeframe);
98 outputs.emplace_back("ZDC", "DIGITSCH", 0, Lifetime::Timeframe);
99 outputs.emplace_back("ZDC", "DIGITSPD", 0, Lifetime::Timeframe);
100 if (useMC) {
101 outputs.emplace_back("ZDC", "DIGITSLBL", 0, Lifetime::Timeframe);
102 }
103 return DataProcessorSpec{
104 "zdc-digit-reader",
105 Inputs{},
106 outputs,
107 AlgorithmSpec{adaptFromTask<DigitReader>(useMC)},
108 Options{
109 {"zdc-digit-infile", VariantType::String, "zdcdigits.root", {"Name of the input file"}},
110 {"input-dir", VariantType::String, "none", {"Input directory"}},
111 {"first-entry", o2::framework::VariantType::Int, 0, {"First digit entry"}},
112 {"last-entry", o2::framework::VariantType::Int, -1, {"Last digit entry"}}}};
113}
114
115} // namespace zdc
116} // namespace o2
std::vector< std::string > labels
Class to describe fired triggered and/or stored channels for the BC and to refer to channel data.
Definition of a container to keep Monte Carlo truth external to simulation objects.
Definition of the Names Generator class.
Class to describe pedestal data accumulated over the orbit.
Container class to store NTimeBinsPerBC ADC values of single ZDC channel.
A container to hold and manage MC truth information/labels.
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 run(framework::ProcessingContext &pc) final
void init(framework::InitContext &ic) final
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > Inputs
struct o2::upgrades_utils::@478 zdc
structure to keep FT0 information
framework::DataProcessorSpec getDigitReaderSpec(bool useMC)
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"