-
Notifications
You must be signed in to change notification settings - Fork 163
Expand file tree
/
Copy pathEveryObject.cxx
More file actions
164 lines (142 loc) · 4.92 KB
/
EveryObject.cxx
File metadata and controls
164 lines (142 loc) · 4.92 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
// 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 EveryObject.cxx
/// \author Piotr Konopka
///
#include <TCanvas.h>
#include <TH1.h>
#include "QualityControl/QcInfoLogger.h"
#include "Example/EveryObject.h"
#include <Framework/InputRecord.h>
#include <Framework/InputRecordWalker.h>
#include <Framework/DataRefUtils.h>
#include <TH1F.h>
#include <TH2F.h>
#include <TH3F.h>
#include <THnSparse.h>
#include <TCanvas.h>
constexpr Double_t rangeLimiter = 16 * 64000;
namespace o2::quality_control_modules::example
{
EveryObject::~EveryObject()
{
delete mTH1F;
delete mTH2F;
delete mTH3F;
delete mTHnSparseF;
delete mTCanvas; // TCanvas should delete the contained plots, given that we set kCanDelete
}
void EveryObject::initialize(o2::framework::InitContext& /*ctx*/)
{
ILOG(Debug, Devel) << "initialize EveryObject" << ENDM; // QcInfoLogger is used. FairMQ logs will go to there as well.
// todo: enable/disable with config flags (this is why objects are always accessed after checking if not null)
// todo: ttree, tefficiency, tprofile
mTH1F = new TH1F("th1f", "th1f", 64000, 0, rangeLimiter);
getObjectsManager()->startPublishing(mTH1F, PublicationPolicy::Forever);
mTH2F = new TH2F("th2f", "th2f", 250, 0, rangeLimiter, 250, 0, rangeLimiter);
getObjectsManager()->startPublishing(mTH2F, PublicationPolicy::Forever);
mTH3F = new TH3F("th3f", "th3f", 40, 0, rangeLimiter, 40, 0, rangeLimiter, 40, 0, rangeLimiter);
getObjectsManager()->startPublishing(mTH3F, PublicationPolicy::Forever);
{
const size_t bins = 1000;
const size_t dim = 5;
const Double_t min = 0.0;
const Double_t max = rangeLimiter;
const std::vector<Int_t> binsDims(dim, bins);
const std::vector<Double_t> mins(dim, min);
const std::vector<Double_t> maxs(dim, max);
mTHnSparseF = new THnSparseF("thnsparsef", "thnsparsef", dim, binsDims.data(), mins.data(), maxs.data());
getObjectsManager()->startPublishing(mTHnSparseF, PublicationPolicy::Forever);
}
{
mTCanvas = new TCanvas("tcanvas", "tcanvas", 1000, 1000);
mTCanvas->Clear();
mTCanvas->Divide(2, 2);
for (size_t i = 0; i < 4; i++) {
auto name = std::string("tcanvas_th2f_") + std::to_string(i);
mTCanvasMembers[i] = new TH2F(name.c_str(), name.c_str(), 250, 0, rangeLimiter, 250, 0, rangeLimiter);
mTCanvas->cd(i + 1);
mTCanvasMembers[i]->Draw();
mTCanvasMembers[i]->SetBit(TObject::kCanDelete);
}
getObjectsManager()->startPublishing<true>(mTCanvas, PublicationPolicy::Forever);
}
}
void EveryObject::startOfActivity(const Activity& activity)
{
ILOG(Debug, Devel) << "startOfActivity " << activity.mId << ENDM;
}
void EveryObject::startOfCycle()
{
ILOG(Debug, Devel) << "startOfCycle" << ENDM;
}
void EveryObject::monitorData(o2::framework::ProcessingContext& ctx)
{
for (auto&& input : framework::InputRecordWalker(ctx.inputs())) {
const auto* header = framework::DataRefUtils::getHeader<header::DataHeader*>(input);
const auto payloadSize = framework::DataRefUtils::getPayloadSize(input);
auto value1 = (Float_t)(payloadSize % (size_t)rangeLimiter);
auto value2 = (Float_t)((header->tfCounter + payloadSize) % (size_t)rangeLimiter);
auto value3 = (Float_t)((header->tfCounter * payloadSize) % (size_t)rangeLimiter);
if (mTH1F) {
mTH1F->Fill(value1);
}
if (mTH2F) {
mTH2F->Fill(value1, value3);
}
if (mTH3F) {
mTH3F->Fill(value1, value2, value3);
}
if (mTHnSparseF) {
std::array<Double_t, 5> values{ value1, value2, value3, value2 / (value1 + 1), value2 / (value3 + 1) };
mTHnSparseF->Fill(values.data());
}
if (mTCanvas) {
mTCanvasMembers[0]->Fill(value1, value3);
mTCanvasMembers[1]->Fill(value3, value1);
mTCanvasMembers[2]->Fill(value2, value3);
mTCanvasMembers[3]->Fill(value3, value2);
}
}
}
void EveryObject::endOfCycle()
{
ILOG(Debug, Devel) << "endOfCycle" << ENDM;
}
void EveryObject::endOfActivity(const Activity& /*activity*/)
{
ILOG(Debug, Devel) << "endOfActivity" << ENDM;
}
void EveryObject::reset()
{
ILOG(Debug, Devel) << "Resetting the objects" << ENDM;
if (mTH1F) {
mTH1F->Reset();
}
if (mTH2F) {
mTH2F->Reset();
}
if (mTH3F) {
mTH3F->Reset();
}
if (mTHnSparseF) {
mTHnSparseF->Reset();
}
if (mTCanvas) {
for (const auto member : mTCanvasMembers) {
if (member) {
member->Reset();
}
}
}
}
} // namespace o2::quality_control_modules::example