-
Notifications
You must be signed in to change notification settings - Fork 508
Expand file tree
/
Copy pathCompressedInspectorTask.cxx
More file actions
187 lines (164 loc) · 6.71 KB
/
Copy pathCompressedInspectorTask.cxx
File metadata and controls
187 lines (164 loc) · 6.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
/// @file CompressedInspectorTask.cxx
/// @author Roberto Preghenella
/// @since 2020-01-25
/// @brief TOF compressed data inspector task
#include "TOFWorkflowUtils/CompressedInspectorTask.h"
#include "Framework/ControlService.h"
#include "Framework/ConfigParamRegistry.h"
#include "Framework/Logger.h"
#include "Headers/RAWDataHeader.h"
#include "DataFormatsTOF/CompressedDataFormat.h"
#include "TFile.h"
#include "TH1F.h"
#include "TH2F.h"
using namespace o2::framework;
namespace o2
{
namespace tof
{
template <typename RDH>
void CompressedInspectorTask<RDH>::init(InitContext& ic)
{
LOG(info) << "CompressedInspector init";
auto filename = ic.options().get<std::string>("tof-compressed-inspector-filename");
auto verbose = ic.options().get<bool>("tof-compressed-inspector-decoder-verbose");
DecoderBaseT<RDH>::setDecoderVerbose(verbose);
/** open file **/
if (mFile && mFile->IsOpen()) {
LOG(warning) << "a file was already open, closing";
mFile->Close();
delete mFile;
}
mFile = TFile::Open(filename.c_str(), "RECREATE");
if (!mFile || !mFile->IsOpen()) {
LOG(error) << "cannot open output file: " << filename;
mStatus = true;
return;
}
mHistos1D["hHisto"] = new TH1F("hHisto", "", 1000, 0., 1000.);
mHistos1D["time"] = new TH1F("hTime", ";time (24.4 ps)", 2097152, 0., 2097152.);
mHistos1D["timebc"] = new TH1F("hTimeBC", ";time (24.4 ps)", 1024, 0., 1024.);
mHistos1D["tot"] = new TH1F("hTOT", ";ToT (48.8 ps)", 2048, 0., 2048.);
mHistos1D["indexE"] = new TH1F("hIndexE", ";index EO", 172800, 0., 172800.);
mHistos2D["slotPartMask"] = new TH2F("hSlotPartMask", ";crate;slot", 72, 0., 72., 12, 1., 13.);
mHistos2D["diagnostic"] = new TH2F("hDiagnostic", ";crate;slot", 72, 0., 72., 13, 0., 13.);
mHistos1D["Nerror"] = new TH1F("hNError", ";number of error", 1000, 0., 1000.);
mHistos1D["Ntest"] = new TH1F("hNTest", ";number of test", 1000, 0., 1000.);
mHistos1D["errorBit"] = new TH1F("hErrorBit", ";TDC error bit", 15, 0., 15.);
mHistos2D["error"] = new TH2F("hError", ";slot;TDC", 24, 1., 13., 15, 0., 15.);
mHistos2D["test"] = new TH2F("hTest", ";slot;TDC", 24, 1., 13., 15, 0., 15.);
mHistos2D["crateBC"] = new TH2F("hCrateBC", ";crate;BC", 72, 0., 72., 4096, 0., 4096.);
mHistos2D["crateOrbit"] = new TH2F("hCrateOrbit", ";crate;orbit", 72, 0., 72., 4096, 0., 4096.);
auto finishFunction = [this]() {
LOG(info) << "CompressedInspector finish";
for (auto& histo : mHistos1D) {
histo.second->Write();
}
for (auto& histo : mHistos2D) {
histo.second->Write();
}
mFile->Close();
};
ic.services().get<CallbackService>().set<CallbackService::Id::Stop>(finishFunction);
}
template <typename RDH>
void CompressedInspectorTask<RDH>::run(ProcessingContext& pc)
{
LOG(debug) << "CompressedInspector run";
/** check status **/
if (mStatus) {
pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
return;
}
/** loop over inputs routes **/
for (auto iit = pc.inputs().begin(), iend = pc.inputs().end(); iit != iend; ++iit) {
if (!iit.isValid()) {
continue;
}
/** loop over input parts **/
for (auto const& ref : iit.parts()) {
const auto* headerIn = DataRefUtils::getHeader<o2::header::DataHeader*>(ref);
auto payloadIn = ref.payload;
auto payloadInSize = DataRefUtils::getPayloadSize(ref);
DecoderBaseT<RDH>::setDecoderBuffer(payloadIn);
DecoderBaseT<RDH>::setDecoderBufferSize(payloadInSize);
DecoderBaseT<RDH>::run();
}
}
}
template <typename RDH>
void CompressedInspectorTask<RDH>::headerHandler(const CrateHeader_t* crateHeader, const CrateOrbit_t* crateOrbit)
{
mHistos2D["crateBC"]->Fill(crateHeader->drmID, crateHeader->bunchID);
mHistos2D["crateOrbit"]->Fill(crateHeader->drmID, crateOrbit->orbitID % 4096);
for (int ibit = 0; ibit < 11; ++ibit) {
if (crateHeader->slotPartMask & (1 << ibit)) {
mHistos2D["slotPartMask"]->Fill(crateHeader->drmID, ibit + 2);
}
}
};
template <typename RDH>
void CompressedInspectorTask<RDH>::frameHandler(const CrateHeader_t* crateHeader, const CrateOrbit_t* crateOrbit,
const FrameHeader_t* frameHeader, const PackedHit_t* packedHits)
{
mHistos1D["hHisto"]->Fill(frameHeader->numberOfHits);
for (int i = 0; i < frameHeader->numberOfHits; ++i) {
auto packedHit = packedHits + i;
auto indexE = packedHit->channel +
8 * packedHit->tdcID +
120 * packedHit->chain +
240 * (frameHeader->trmID - 3) +
2400 * crateHeader->drmID;
int time = packedHit->time;
int timebc = time % 1024;
time += (frameHeader->frameID << 13);
mHistos1D["indexE"]->Fill(indexE);
mHistos1D["time"]->Fill(time);
mHistos1D["timebc"]->Fill(timebc);
mHistos1D["tot"]->Fill(packedHit->tot);
}
};
template <typename RDH>
void CompressedInspectorTask<RDH>::trailerHandler(const CrateHeader_t* crateHeader, const CrateOrbit_t* crateOrbit,
const CrateTrailer_t* crateTrailer, const Diagnostic_t* diagnostics,
const Error_t* errors)
{
mHistos2D["diagnostic"]->Fill(crateHeader->drmID, 0);
for (int i = 0; i < crateTrailer->numberOfDiagnostics; ++i) {
auto diagnostic = diagnostics + i;
mHistos2D["diagnostic"]->Fill(crateHeader->drmID, diagnostic->slotID);
}
int nError = 0, nTest = 0;
for (int i = 0; i < crateTrailer->numberOfErrors; ++i) {
auto error = errors + i;
if (error->undefined) {
nTest++;
mHistos2D["test"]->Fill(error->slotID + 0.5 * error->chain, error->tdcID);
} else {
nError++;
mHistos2D["error"]->Fill(error->slotID + 0.5 * error->chain, error->tdcID);
for (int ibit = 0; ibit < 15; ++ibit) {
if (error->errorFlags & (1 << ibit)) {
mHistos1D["errorBit"]->Fill(ibit);
}
}
}
}
mHistos1D["Nerror"]->Fill(nError);
mHistos1D["Ntest"]->Fill(nTest);
};
template class CompressedInspectorTask<o2::header::RAWDataHeaderV4>;
template class CompressedInspectorTask<o2::header::RAWDataHeaderV6>;
template class CompressedInspectorTask<o2::header::RAWDataHeaderV7>;
} // namespace tof
} // namespace o2