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#include <TTree.h>
18#include "Framework/Logger.h"
25
26using namespace o2::framework;
27
28namespace o2
29{
30namespace ft0
31{
32
34{
36 ic.options().get<std::string>("ft0-digit-infile"));
37 mFile.reset(TFile::Open(filename.c_str()));
38 if (!mFile->IsOpen()) {
39 LOG(error) << "Cannot open the " << filename.c_str() << " file !";
40 throw std::runtime_error("cannot open input digits file");
41 }
42 mTree.reset((TTree*)mFile->Get("o2sim"));
43 if (!mTree) {
44 LOG(error) << "Did not find o2sim tree in " << filename.c_str();
45 throw std::runtime_error("Did not fine o2sim file in FT0 digits tree");
46 }
47}
48
50{
51 std::vector<o2::ft0::Digit> digits, *pdigits = &digits;
52 std::vector<o2::ft0::DetTrigInput> trgInput, *ptrTrgInput = &trgInput;
53 std::vector<o2::ft0::ChannelData> channels, *pchannels = &channels;
54 mTree->SetBranchAddress("FT0DIGITSBC", &pdigits);
55 mTree->SetBranchAddress("FT0DIGITSCH", &pchannels);
56 if (mUseTrgInput) {
57 mTree->SetBranchAddress("TRIGGERINPUT", &ptrTrgInput);
58 }
60 if (mUseMC) {
61 mTree->SetBranchAddress("FT0DIGITSMCTR", &plabels);
62 }
63 auto ent = mTree->GetReadEntry() + 1;
64 // A timeframe holds no collision at all whenever the interaction rate is low enough, and
65 // the tree then has no entry to read. Publish empty containers instead of reading past the
66 // end and pushing branch addresses that GetEntry has not filled, so that the consumers
67 // downstream still see the timeframe. (This used to be an assert, which is compiled out of
68 // every production build since ENABLE_CASSERT defaults to OFF.)
69 const bool noEntry = ent >= mTree->GetEntries();
70 if (noEntry) {
71 LOG(info) << "no entry to read, publishing empty output";
72 } else {
73 mTree->GetEntry(ent);
74 }
75 LOG(debug) << "FT0DigitReader pushed " << channels.size() << " channels in " << digits.size() << " digits";
76 pc.outputs().snapshot(Output{"FT0", "DIGITSBC", 0}, digits);
77 pc.outputs().snapshot(Output{"FT0", "DIGITSCH", 0}, channels);
78 if (mUseMC) {
79 pc.outputs().snapshot(Output{"FT0", "DIGITSMCTR", 0}, labels);
80 }
81 if (mUseTrgInput) {
82 pc.outputs().snapshot(Output{"FT0", "TRIGGERINPUT", 0}, trgInput);
83 }
84 if (noEntry || mTree->GetReadEntry() + 1 >= mTree->GetEntries()) {
86 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
87 }
88}
89
90DataProcessorSpec getDigitReaderSpec(bool useMC, bool useTrgInput)
91{
92 std::vector<OutputSpec> outputs;
93 outputs.emplace_back("FT0", "DIGITSBC", 0, Lifetime::Timeframe);
94 outputs.emplace_back("FT0", "DIGITSCH", 0, Lifetime::Timeframe);
95 if (useMC) {
96 outputs.emplace_back("FT0", "DIGITSMCTR", 0, Lifetime::Timeframe);
97 }
98 if (useTrgInput) {
99 outputs.emplace_back("FT0", "TRIGGERINPUT", 0, Lifetime::Timeframe);
100 }
101 return DataProcessorSpec{
102 "ft0-digit-reader",
103 Inputs{},
104 outputs,
105 AlgorithmSpec{adaptFromTask<DigitReader>(useMC, useTrgInput)},
106 Options{
107 {"ft0-digit-infile", VariantType::String, "ft0digits.root", {"Name of the input file"}},
108 {"input-dir", VariantType::String, "none", {"Input directory"}}}};
109}
110
111} // namespace ft0
112} // namespace o2
std::vector< std::string > labels
std::ostringstream debug
Class to describe fired and 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.
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
framework::DataProcessorSpec getDigitReaderSpec(bool useMC=false, bool useTrgInput=true)
struct o2::upgrades_utils::@477 ft0
structure to keep V0C information
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"
std::vector< ChannelData > channels
std::vector< Digit > digits