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"
25
26using namespace o2::framework;
27using namespace o2::tof;
28
29namespace o2
30{
31namespace tof
32{
33
35{
36 LOG(debug) << "Init Digit reader!";
38 ic.options().get<std::string>("tof-digit-infile"));
39 mDelayInMuSec1TF = atof(ic.options().get<std::string>("delay-1st-tf").c_str()) * 1E6;
40
41 mFile.reset(TFile::Open(filename.c_str()));
42 if (!mFile->IsOpen()) {
43 LOG(error) << "Cannot open the " << filename.c_str() << " file !";
44 mState = 0;
45 return;
46 }
47 mState = 1;
48}
49
51{
52 static bool firstCall = true;
53 if (firstCall) {
54 usleep(mDelayInMuSec1TF);
55 }
56 firstCall = false;
57
58 if (mState != 1) {
59 return;
60 }
61
62 std::unique_ptr<TTree> treeDig((TTree*)mFile->Get("o2sim"));
63
64 if (treeDig) {
65 treeDig->SetBranchAddress("TOFDigit", &mPdigits);
66 treeDig->SetBranchAddress("TOFReadoutWindow", &mProw);
67 treeDig->SetBranchAddress("TOFPatterns", &mPpatterns);
68
69 if (mUseMC) {
70 treeDig->SetBranchAddress("TOFDigitMCTruth", &mPlabels);
71 }
72
73 treeDig->GetEntry(mCurrentEntry);
74
75 // fill diagnostic frequencies
76 mFiller.clearCounts();
77 for (auto digit : mDigits) {
78 mFiller.addCount(digit.getChannel());
79 }
80 mFiller.setReadoutWindowData(mRow, mPatterns);
82 mDiagnostic = mFiller.getDiagnosticFrequency();
83 auto creationTime = pc.services().get<o2::framework::TimingInfo>().creation;
84 mDiagnostic.setTimeStamp(creationTime / 1000);
85 // add TFIDInfo
88 mDiagnostic.setTFIDInfo(tfinfo);
89
90 // add digits loaded in the output snapshot
91 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "DIGITS", 0}, mDigits);
92 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "READOUTWINDOW", 0}, mRow);
93 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "PATTERNS", 0}, mPatterns);
94 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "DIAFREQ", 0}, mDiagnostic);
95 if (mUseMC) {
96 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "DIGITSMCTR", 0}, mLabels);
97 }
98
100
101 LOG(debug) << "TOF: Sending ROMode= " << roMode << " to GRPUpdater";
102 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "ROMode", 0}, roMode);
103 } else {
104 LOG(error) << "Cannot read the TOF digits !";
105 return;
106 }
107
108 mCurrentEntry++;
109
110 if (mCurrentEntry >= treeDig->GetEntries()) {
111 mState = 2;
112 //pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
114 }
115}
116
118{
119 std::vector<OutputSpec> outputs;
120 outputs.emplace_back(o2::header::gDataOriginTOF, "DIGITS", 0, Lifetime::Timeframe);
121 outputs.emplace_back(o2::header::gDataOriginTOF, "READOUTWINDOW", 0, Lifetime::Timeframe);
122 outputs.emplace_back(o2::header::gDataOriginTOF, "DIAFREQ", 0, Lifetime::Timeframe);
123 if (useMC) {
124 outputs.emplace_back(o2::header::gDataOriginTOF, "DIGITSMCTR", 0, Lifetime::Timeframe);
125 }
126 outputs.emplace_back(o2::header::gDataOriginTOF, "PATTERNS", 0, Lifetime::Timeframe);
127 outputs.emplace_back(o2::header::gDataOriginTOF, "ROMode", 0, Lifetime::Timeframe);
128
129 return DataProcessorSpec{
130 "tof-digit-reader",
131 Inputs{},
132 outputs,
133 AlgorithmSpec{adaptFromTask<DigitReader>(useMC)},
134 Options{
135 {"tof-digit-infile", VariantType::String, "tofdigits.root", {"Name of the input file"}},
136 {"delay-1st-tf", VariantType::String, "none", {"delay in seconds before 1st TF"}},
137 {"input-dir", VariantType::String, "none", {"Input directory"}}}};
138}
139
140} // namespace tof
141} // namespace o2
Header of the General Run Parameters object.
Definition of the Names Generator class.
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 setTFIDInfo(const o2::dataformats::TFIDInfo &val)
Definition Diagnostic.h:93
void setTimeStamp(int val)
Definition Diagnostic.h:91
void run(ProcessingContext &pc) final
void init(InitContext &ic) final
Diagnostic & getDiagnosticFrequency()
void addCount(int channel)
void setReadoutWindowData(const VROF &row, const VPAT &pattern)
constexpr o2::header::DataOrigin gDataOriginTOF
Definition DataHeader.h:575
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > Inputs
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 void fillTFIDInfo(o2::framework::ProcessingContext &pc, o2::dataformats::TFIDInfo &ti)
static std::string rectifyDirectory(const std::string_view p)
static std::string concat_string(Ts const &... ts)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"