Project
Loading...
Searching...
No Matches
CompressedInspectorTask.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
16
20#include "Framework/Logger.h"
23
24#include "TFile.h"
25#include "TH1F.h"
26#include "TH2F.h"
27
28using namespace o2::framework;
29
30namespace o2
31{
32namespace tof
33{
34
35template <typename RDH>
37{
38 LOG(info) << "CompressedInspector init";
39 auto filename = ic.options().get<std::string>("tof-compressed-inspector-filename");
40 auto verbose = ic.options().get<bool>("tof-compressed-inspector-decoder-verbose");
41
43
45 if (mFile && mFile->IsOpen()) {
46 LOG(warning) << "a file was already open, closing";
47 mFile->Close();
48 delete mFile;
49 }
50 mFile = TFile::Open(filename.c_str(), "RECREATE");
51 if (!mFile || !mFile->IsOpen()) {
52 LOG(error) << "cannot open output file: " << filename;
53 mStatus = true;
54 return;
55 }
56
57 mHistos1D["hHisto"] = new TH1F("hHisto", "", 1000, 0., 1000.);
58 mHistos1D["time"] = new TH1F("hTime", ";time (24.4 ps)", 2097152, 0., 2097152.);
59 mHistos1D["timebc"] = new TH1F("hTimeBC", ";time (24.4 ps)", 1024, 0., 1024.);
60 mHistos1D["tot"] = new TH1F("hTOT", ";ToT (48.8 ps)", 2048, 0., 2048.);
61 mHistos1D["indexE"] = new TH1F("hIndexE", ";index EO", 172800, 0., 172800.);
62 mHistos2D["slotPartMask"] = new TH2F("hSlotPartMask", ";crate;slot", 72, 0., 72., 12, 1., 13.);
63 mHistos2D["diagnostic"] = new TH2F("hDiagnostic", ";crate;slot", 72, 0., 72., 13, 0., 13.);
64 mHistos1D["Nerror"] = new TH1F("hNError", ";number of error", 1000, 0., 1000.);
65 mHistos1D["Ntest"] = new TH1F("hNTest", ";number of test", 1000, 0., 1000.);
66 mHistos1D["errorBit"] = new TH1F("hErrorBit", ";TDC error bit", 15, 0., 15.);
67 mHistos2D["error"] = new TH2F("hError", ";slot;TDC", 24, 1., 13., 15, 0., 15.);
68 mHistos2D["test"] = new TH2F("hTest", ";slot;TDC", 24, 1., 13., 15, 0., 15.);
69 mHistos2D["crateBC"] = new TH2F("hCrateBC", ";crate;BC", 72, 0., 72., 4096, 0., 4096.);
70 mHistos2D["crateOrbit"] = new TH2F("hCrateOrbit", ";crate;orbit", 72, 0., 72., 4096, 0., 4096.);
71
72 auto finishFunction = [this]() {
73 LOG(info) << "CompressedInspector finish";
74 for (auto& histo : mHistos1D) {
75 histo.second->Write();
76 }
77 for (auto& histo : mHistos2D) {
78 histo.second->Write();
79 }
80 mFile->Close();
81 };
82 ic.services().get<CallbackService>().set<CallbackService::Id::Stop>(finishFunction);
83}
84
85template <typename RDH>
87{
88 LOG(debug) << "CompressedInspector run";
89
91 if (mStatus) {
92 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
93 return;
94 }
95
97 for (auto iit = pc.inputs().begin(), iend = pc.inputs().end(); iit != iend; ++iit) {
98 if (!iit.isValid()) {
99 continue;
100 }
101
103 for (auto const& ref : iit) {
104
105 const auto* headerIn = DataRefUtils::getHeader<o2::header::DataHeader*>(ref);
106 auto payloadIn = ref.payload;
107 auto payloadInSize = DataRefUtils::getPayloadSize(ref);
108
112 }
113 }
114}
115
116template <typename RDH>
117void CompressedInspectorTask<RDH>::headerHandler(const CrateHeader_t* crateHeader, const CrateOrbit_t* crateOrbit)
118{
119 mHistos2D["crateBC"]->Fill(crateHeader->drmID, crateHeader->bunchID);
120 mHistos2D["crateOrbit"]->Fill(crateHeader->drmID, crateOrbit->orbitID % 4096);
121
122 for (int ibit = 0; ibit < 11; ++ibit) {
123 if (crateHeader->slotPartMask & (1 << ibit)) {
124 mHistos2D["slotPartMask"]->Fill(crateHeader->drmID, ibit + 2);
125 }
126 }
127};
128
129template <typename RDH>
130void CompressedInspectorTask<RDH>::frameHandler(const CrateHeader_t* crateHeader, const CrateOrbit_t* crateOrbit,
131 const FrameHeader_t* frameHeader, const PackedHit_t* packedHits)
132{
133 mHistos1D["hHisto"]->Fill(frameHeader->numberOfHits);
134 for (int i = 0; i < frameHeader->numberOfHits; ++i) {
135 auto packedHit = packedHits + i;
136 auto indexE = packedHit->channel +
137 8 * packedHit->tdcID +
138 120 * packedHit->chain +
139 240 * (frameHeader->trmID - 3) +
140 2400 * crateHeader->drmID;
141 int time = packedHit->time;
142 int timebc = time % 1024;
143 time += (frameHeader->frameID << 13);
144
145 mHistos1D["indexE"]->Fill(indexE);
146 mHistos1D["time"]->Fill(time);
147 mHistos1D["timebc"]->Fill(timebc);
148 mHistos1D["tot"]->Fill(packedHit->tot);
149 }
150};
151
152template <typename RDH>
153void CompressedInspectorTask<RDH>::trailerHandler(const CrateHeader_t* crateHeader, const CrateOrbit_t* crateOrbit,
154 const CrateTrailer_t* crateTrailer, const Diagnostic_t* diagnostics,
155 const Error_t* errors)
156{
157 mHistos2D["diagnostic"]->Fill(crateHeader->drmID, 0);
158 for (int i = 0; i < crateTrailer->numberOfDiagnostics; ++i) {
159 auto diagnostic = diagnostics + i;
160 mHistos2D["diagnostic"]->Fill(crateHeader->drmID, diagnostic->slotID);
161 }
162 int nError = 0, nTest = 0;
163 for (int i = 0; i < crateTrailer->numberOfErrors; ++i) {
164 auto error = errors + i;
165 if (error->undefined) {
166 nTest++;
167 mHistos2D["test"]->Fill(error->slotID + 0.5 * error->chain, error->tdcID);
168 } else {
169 nError++;
170 mHistos2D["error"]->Fill(error->slotID + 0.5 * error->chain, error->tdcID);
171 for (int ibit = 0; ibit < 15; ++ibit) {
172 if (error->errorFlags & (1 << ibit)) {
173 mHistos1D["errorBit"]->Fill(ibit);
174 }
175 }
176 }
177 }
178 mHistos1D["Nerror"]->Fill(nError);
179 mHistos1D["Ntest"]->Fill(nTest);
180};
181
182template class CompressedInspectorTask<o2::header::RAWDataHeaderV4>;
183template class CompressedInspectorTask<o2::header::RAWDataHeaderV6>;
184template class CompressedInspectorTask<o2::header::RAWDataHeaderV7>;
185
186} // namespace tof
187} // namespace o2
TOF compressed data inspector task.
int16_t time
Definition RawEventData.h:4
int32_t i
Definition of the RAW Data Header.
std::ostringstream debug
ServiceRegistryRef services()
Definition InitContext.h:34
ConfigParamRegistry const & options()
Definition InitContext.h:33
const_iterator begin() const
const_iterator end() const
InputRecord & inputs()
The inputs associated with this processing context.
ServiceRegistryRef services()
The services registry associated with this processing context.
void setDecoderBuffer(const char *val)
Definition DecoderBase.h:66
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::string filename()
static o2::header::DataHeader::PayloadSizeType getPayloadSize(const DataRef &ref)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"