Skip to content

Commit a1739d4

Browse files
victor-gonzalezVictor Gonzalez
andauthored
[PWGCF] DptDpt - Filter and skimming framework fix linter issues (#18702)
Co-authored-by: Victor Gonzalez <victor@cern.ch>
1 parent 0b2823e commit a1739d4

20 files changed

Lines changed: 1325 additions & 1348 deletions

‎PWGCF/TwoParticleCorrelations/Core/EventSelectionFilterAndAnalysis.cxx‎

Lines changed: 72 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
// granted to it by virtue of its status as an Intergovernmental Organization
1010
// or submit itself to any jurisdiction.
1111

12+
/// \file EventSelectionFilterAndAnalysis.cxx
13+
/// \brief Implementation of the EventSelectionFilterAndAnalysis class for
14+
/// filtering collisions for derived data production
15+
/// \author victor.gonzalez.sebastian@gmail.com
16+
1217
#include "EventSelectionFilterAndAnalysis.h"
1318

1419
#include "PWGCF/TwoParticleCorrelations/Core/SelectionFilterAndAnalysis.h"
@@ -35,55 +40,49 @@
3540
#include <vector>
3641

3742
using namespace o2;
38-
using namespace o2::analysis::PWGCF;
43+
using namespace o2::analysis::pwgcf;
3944
using namespace boost;
4045

4146
EventSelectionConfigurable::EventSelectionConfigurable(const std::vector<std::string>& bfieldsel,
4247
std::vector<std::string> multsel,
4348
std::vector<std::string> trigsel,
4449
std::vector<std::string> zvtxsel,
4550
std::vector<std::string> pileuprej)
46-
: mBFiledSel(""),
47-
mMultSel(""),
48-
mTriggerSel(""),
49-
mZVertexSel(""),
50-
mPileUpRejection("")
51+
5152
{
5253
auto storeCutString = [](auto& selvector, const std::string& selname) {
5354
if (selvector.size() != 0) {
5455
if (selvector.size() == 1) {
5556
if (selvector[0].size() != 0) {
5657
return TString::Format("%s{%s}", selname.c_str(), selvector[0].c_str());
57-
} else {
58-
return TString("");
5958
}
60-
} else {
61-
TString scut = selname + "{cwv{";
62-
bool def = true;
63-
bool firstvar = true;
64-
for (const auto& cut : selvector) {
65-
if (def) {
66-
scut += cut + ':';
67-
def = false;
68-
} else {
69-
if (not firstvar) {
70-
scut += ',';
71-
}
72-
scut += cut;
73-
firstvar = false;
59+
return TString("");
60+
}
61+
TString scut = selname + "{cwv{";
62+
bool def = true;
63+
bool firstvar = true;
64+
for (const auto& cut : selvector) {
65+
if (def) {
66+
scut += cut + ':';
67+
def = false;
68+
} else {
69+
if (not firstvar) {
70+
scut += ',';
7471
}
72+
scut += cut;
73+
firstvar = false;
7574
}
76-
scut += "}}";
77-
return scut;
7875
}
76+
scut += "}}";
77+
return scut;
7978
}
8079
return TString("");
8180
};
8281
/* b-field is a bit specific */
8382
{
8483
TString bfield = "bfield{";
8584
bool first = true;
86-
for (auto& pol : bfieldsel) {
85+
for (const auto& pol : bfieldsel) {
8786
if (not first) {
8887
bfield += ',';
8988
}
@@ -108,41 +107,40 @@ const char* multiplicityCorrelators[nNoOfPileUpCorrelators] = {"V0M_TPCOUT", "V0
108107

109108
/// \brief Default constructor
110109
EventSelectionFilterAndAnalysis::EventSelectionFilterAndAnalysis()
111-
: SelectionFilterAndAnalysis(),
112-
mBFieldSelection{},
113-
mMultiplicityClasses(nullptr),
110+
: mMultiplicityClasses(nullptr),
114111
mTriggerSelection(nullptr),
115112
mZVertex(nullptr),
116113
mPileUpRejection(nullptr)
117114
{
118115
}
119116

120117
/// \brief Constructor from regular expression
121-
EventSelectionFilterAndAnalysis::EventSelectionFilterAndAnalysis(const TString& cutstr, selmodes mode)
118+
EventSelectionFilterAndAnalysis::EventSelectionFilterAndAnalysis(const TString& cutstr, Selmodes mode)
122119
: SelectionFilterAndAnalysis("", mode),
123-
mBFieldSelection{},
120+
124121
mMultiplicityClasses(nullptr),
125122
mTriggerSelection(nullptr),
126123
mZVertex(nullptr),
127124
mPileUpRejection(nullptr)
128125
{
129-
ConstructCutFromString(cutstr);
126+
constructCutFromString(cutstr);
130127
}
131128

132129
/// \brief Constructor from the event selection configurable
133-
EventSelectionFilterAndAnalysis::EventSelectionFilterAndAnalysis(const EventSelectionConfigurable& evtsel, selmodes mode)
130+
EventSelectionFilterAndAnalysis::EventSelectionFilterAndAnalysis(const EventSelectionConfigurable& evtsel, Selmodes mode)
134131
: SelectionFilterAndAnalysis("", mode),
135-
mBFieldSelection{},
132+
136133
mMultiplicityClasses(nullptr),
137134
mTriggerSelection(nullptr),
138135
mZVertex(nullptr),
139136
mPileUpRejection(nullptr)
140137
{
141138
TString cutString = "eventsel{";
142139
bool first = true;
140+
constexpr int MaskMaxLength = 64;
143141

144142
auto appendCut = [&cutString, &first](const std::string& str) {
145-
if (str.size() > 0) {
143+
if (!str.empty()) {
146144
if (first) {
147145
cutString += str;
148146
first = false;
@@ -158,29 +156,29 @@ EventSelectionFilterAndAnalysis::EventSelectionFilterAndAnalysis(const EventSele
158156
appendCut(evtsel.mPileUpRejection);
159157

160158
cutString += "}";
161-
ConstructCutFromString(cutString);
162-
if (mMaskLength > 64) {
163-
LOGF(fatal, "EventSelectionFilterAndAnalysis not ready for filter mask of %d bits. Just 64 available for the time being", mMaskLength);
159+
constructCutFromString(cutString);
160+
if (mMaskLength > MaskMaxLength) {
161+
LOGF(fatal, "EventSelectionFilterAndAnalysis not ready for filter mask of %d bits. Just %d available for the time being", mMaskLength, MaskMaxLength);
164162
}
165163
mCutStringSignature = cutString.ReplaceAll("-yes", "").ReplaceAll("-no", "");
166-
if (mode == kAnalysis) {
167-
StoreArmedMask();
164+
if (mode == KAnalysis) {
165+
storeArmedMask();
168166
}
169167
}
170168

171169
/// \brief Calculates the length of the mask needed to store the selection cuts
172-
int EventSelectionFilterAndAnalysis::CalculateMaskLength()
170+
int EventSelectionFilterAndAnalysis::calculateMaskLength()
173171
{
174172
int length = 0;
175173
auto addLength = [&length](auto& brick) {
176174
if (brick != nullptr) {
177-
length += brick->Length();
178-
LOGF(info, "EventSelectionFilterAndAnalysis::CalculateMaskLength, cumulated length: %d", length);
175+
length += brick->length();
176+
LOGF(info, "EventSelectionFilterAndAnalysis::calculateMaskLength, cumulated length: %d", length);
179177
}
180178
};
181179

182-
for (auto brick : mBFieldSelection) {
183-
length += brick->Length();
180+
for (const auto& brick : mBFieldSelection) {
181+
length += brick->length();
184182
}
185183
addLength(mMultiplicityClasses);
186184
addLength(mTriggerSelection);
@@ -240,7 +238,7 @@ void EventSelectionFilterAndAnalysis::MultiplicityBrick::initialize()
240238
}
241239
}
242240
}
243-
if (mAlternateEstimatorIndex.size() != (uint)(varlst.GetEntries())) {
241+
if (mAlternateEstimatorIndex.size() != static_cast<uint>(varlst.GetEntries())) {
244242
LOGF(fatal, "EventSelectionFilterAndAnalysis::InitializeMultiplicityFilter() variant multiplicity class estimators not all implemented");
245243
}
246244
}
@@ -297,13 +295,13 @@ void EventSelectionFilterAndAnalysis::PileUpRejBrick::initialize()
297295
}
298296
}
299297
}
300-
if (mAlternateEstimatorIndex.size() != (uint)(varlst.GetEntries())) {
298+
if (mAlternateEstimatorIndex.size() != static_cast<uint>(varlst.GetEntries())) {
301299
LOGF(fatal, "EventSelectionFilterAndAnalysis::InitializeMultiplicityFilter() variant pile-up correlator estimators not all implemented");
302300
}
303301
}
304302
}
305303

306-
void EventSelectionFilterAndAnalysis::ConstructCutFromString(const TString& cutstr)
304+
void EventSelectionFilterAndAnalysis::constructCutFromString(const TString& cutstr)
307305
{
308306
LOGF(info, "Cut string: %s", cutstr.Data());
309307
/* let's catch the first level */
@@ -312,8 +310,9 @@ void EventSelectionFilterAndAnalysis::ConstructCutFromString(const TString& cuts
312310
smatch m;
313311

314312
bool res = regex_search(in, m, cutregex);
315-
if (not res or m.empty() or (m.size() > 2)) {
316-
LOGF(fatal, "EventSelectionFilterAndAnalysis::ConstructCutFromString", "Wrong RE: %s, try eventsel{bfield{positive-yes,negative-yes},zvtx{cwv{rg{-7.0,7.0}-yes:rg{-10.0,10.0}-no,rg{-3.0,3.0}-no}}} for instance", cutstr.Data());
313+
constexpr int ExpectedMaxLength = 2;
314+
if (not res || m.empty() || (m.size() > ExpectedMaxLength)) {
315+
LOGF(fatal, "EventSelectionFilterAndAnalysis::constructCutFromString", "Wrong RE: %s, try eventsel{bfield{positive-yes,negative-yes},zvtx{cwv{rg{-7.0,7.0}-yes:rg{-10.0,10.0}-no,rg{-3.0,3.0}-no}}} for instance", cutstr.Data());
317316
}
318317
this->SetName("EventSelectionFilterAndAnalysisCuts");
319318
this->SetTitle(cutstr.Data());
@@ -330,25 +329,23 @@ void EventSelectionFilterAndAnalysis::ConstructCutFromString(const TString& cuts
330329
if (lev2str.Length() == 0) {
331330
break;
332331
}
333-
regex cutregex("^(\\w+)\\{((?:[^{}]++|\\{(?2)\\})*)\\}");
334-
std::string in(lev2str.Data());
335-
smatch m;
336-
bool res = regex_search(in, m, cutregex);
332+
cutregex = regex("^(\\w+)\\{((?:[^{}]++|\\{(?2)\\})*)\\}");
333+
in = (lev2str.Data());
334+
res = regex_search(in, m, cutregex);
335+
constexpr int ExpectedComponents = 3;
337336

338-
if (not res or m.empty() or (m.size() != 3)) {
339-
Fatal("EventSelectionFilterAndAnalysis::::ConstructCutFromString", "Wrong RE: %s, try tracksel{ttype{FB32,FB96};nclstpc{th{70}},nxr{cwv{th{70},th{80}}}} for instance", cutstr.Data());
337+
if (not res or m.empty() or (m.size() != ExpectedComponents)) {
338+
Fatal("EventSelectionFilterAndAnalysis::::constructCutFromString", "Wrong RE: %s, try tracksel{ttype{FB32,FB96};nclstpc{th{70}},nxr{cwv{th{70},th{80}}}} for instance", cutstr.Data());
340339
}
341340
LOGF(info, "Captured %s", m[1].str().c_str());
342341
auto storeIntCut = [&m, &allowed](CutBrick<int>*& brickvar) {
343-
if (brickvar != nullptr) {
344-
delete brickvar;
345-
}
342+
delete brickvar;
343+
346344
brickvar = CutBrick<int>::constructBrick(m[1].str().c_str(), m[2].str().c_str(), allowed);
347345
};
348346
auto storeFloatCut = [&m, &allowed](CutBrick<float>*& brickvar) {
349-
if (brickvar != nullptr) {
350-
delete brickvar;
351-
}
347+
delete brickvar;
348+
352349
brickvar = CutBrick<float>::constructBrick(m[1].str().c_str(), m[2].str().c_str(), allowed);
353350
};
354351
/* b-field requires speciat treatment */
@@ -358,7 +355,7 @@ void EventSelectionFilterAndAnalysis::ConstructCutFromString(const TString& cuts
358355
auto addBFieldBrick = [&brickvector](auto name, auto regex, bool arm) {
359356
std::set<std::string> allowed = {"lim", "th"};
360357
CutBrick<float>* brick = CutBrick<float>::constructBrick(name, regex, allowed);
361-
brick->Arm(arm);
358+
brick->arm(arm);
362359
brickvector.push_back(brick);
363360
};
364361
if (TString(regex).Contains("positive")) {
@@ -394,15 +391,15 @@ void EventSelectionFilterAndAnalysis::ConstructCutFromString(const TString& cuts
394391
lev2str.Remove(0, m[0].length());
395392
}
396393
}
397-
mMaskLength = CalculateMaskLength();
394+
mMaskLength = calculateMaskLength();
398395
}
399396

400397
///
401398
void EventSelectionFilterAndAnalysis::ComplexBrickHelper::armedBrick(uint64_t& armedmask, uint64_t& optmask, uint64_t& forcedmask, int& bit)
402399
{
403400
auto armedBrick = [&](auto brick, bool opt = false) {
404-
std::vector<bool> res = brick->IsArmed();
405-
for (auto b : res) {
401+
std::vector<bool> res = brick->isArmed();
402+
for (const auto& b : res) {
406403
if (b) {
407404
SETBIT(armedmask, bit);
408405
if (opt) {
@@ -415,21 +412,21 @@ void EventSelectionFilterAndAnalysis::ComplexBrickHelper::armedBrick(uint64_t& a
415412
}
416413
};
417414

418-
if (mAlternateEstimatorIndex.size() > 0) {
415+
if (!mAlternateEstimatorIndex.empty()) {
419416
/* we have alternative estimators so our brick is of kind cwv */
420417
if (mBrick->IsA() != CutWithVariations<float>::Class()) {
421-
LOGF(fatal, "EventSelectionFilterAndAnalysis::Filter() expected class with variations cut but it is not there");
418+
LOGF(fatal, "EventSelectionFilterAndAnalysis::filter() expected class with variations cut but it is not there");
422419
}
423420
/* first the default */
424421
TList& deflst = dynamic_cast<CutWithVariations<float>*>(mBrick)->getDefaultBricks();
425422
if (deflst.GetEntries() > 1) {
426-
LOGF(fatal, "EventSelectionFilterAndAnalysis::Filter() expected only one default multiplicity class estimator");
423+
LOGF(fatal, "EventSelectionFilterAndAnalysis::filter() expected only one default multiplicity class estimator");
427424
}
428-
armedBrick((CutBrick<float>*)deflst.At(0), true);
425+
armedBrick(dynamic_cast<CutBrick<float>*>(deflst.At(0)), true);
429426
/* and now the variants */
430427
TList& varlst = dynamic_cast<CutWithVariations<float>*>(mBrick)->getVariantBricks();
431428
for (int i = 0; i < varlst.GetEntries(); ++i) {
432-
armedBrick((CutBrick<float>*)varlst.At(i), true);
429+
armedBrick(dynamic_cast<CutBrick<float>*>(varlst.At(i)), true);
433430
}
434431
} else {
435432
/* no alternative estimators, just the default */
@@ -438,7 +435,7 @@ void EventSelectionFilterAndAnalysis::ComplexBrickHelper::armedBrick(uint64_t& a
438435
}
439436

440437
/// \brief Fills the filter cuts mask
441-
void EventSelectionFilterAndAnalysis::StoreArmedMask()
438+
void EventSelectionFilterAndAnalysis::storeArmedMask()
442439
{
443440
uint64_t armedMask = 0UL;
444441
uint64_t optMask = 0UL;
@@ -449,8 +446,8 @@ void EventSelectionFilterAndAnalysis::StoreArmedMask()
449446
int bit = 0;
450447

451448
auto armedBrick = [&](auto brick, bool opt = false) {
452-
std::vector<bool> res = brick->IsArmed();
453-
for (auto b : res) {
449+
std::vector<bool> res = brick->isArmed();
450+
for (const auto& b : res) {
454451
if (b) {
455452
SETBIT(armedMask, bit);
456453
if (opt) {
@@ -464,7 +461,7 @@ void EventSelectionFilterAndAnalysis::StoreArmedMask()
464461
};
465462

466463
optMask = 0UL;
467-
for (auto brick : mBFieldSelection) {
464+
for (const auto& brick : mBFieldSelection) {
468465
armedBrick(brick, true);
469466
}
470467
mOptArmedMask.push_back(optMask);
@@ -480,7 +477,7 @@ void EventSelectionFilterAndAnalysis::StoreArmedMask()
480477
if (mPileUpRejection != nullptr) {
481478
mPileUpRejection->armedBrick(armedMask, optMask, forcedMask, bit);
482479
}
483-
LOGF(info, "EventSelectionFilterAndAnalysis::StoreArmedMask(), masks 0x%016lx, %s, 0x%016lx", armedMask, printOptionalMasks().Data(), forcedMask);
480+
LOGF(info, "EventSelectionFilterAndAnalysis::storeArmedMask(), masks 0x%016lx, %s, 0x%016lx", armedMask, printOptionalMasks().Data(), forcedMask);
484481
mArmedMask = armedMask;
485482
mForcedArmedMask = forcedMask;
486483
}

0 commit comments

Comments
 (0)