Skip to content

Commit 8d6c489

Browse files
committed
pass weight as const&
1 parent bacf057 commit 8d6c489

File tree

4 files changed

+25
-29
lines changed

4 files changed

+25
-29
lines changed

src/EntryConfig.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ struct fill3_struct : public Utils::Visitor<void> {
4747
double val1_, val2_, val3_;
4848
};
4949

50-
EntryConfig::EntryConfig(const Axis& axis, Variable& weight, const std::string& name, Cuts* cuts, bool is_integral)
50+
EntryConfig::EntryConfig(const Axis& axis, const Variable& weight, const std::string& name, Cuts* cuts, bool is_integral)
5151
: name_(name == "" ? axis.GetName() : name),
5252
type_(is_integral ? PlotType::kIntegral1D : PlotType::kHisto1D),
5353
axes_({axis}),
@@ -66,10 +66,10 @@ EntryConfig::EntryConfig(const Axis& axis, Variable& weight, const std::string&
6666
InitPlot();
6767
}
6868

69-
EntryConfig::EntryConfig(const Axis& x, const Axis& y, Variable& weight, const std::string& name, Cuts* cuts, bool is_profile) : type_(is_profile ? PlotType::kProfile : PlotType::kHisto2D),
70-
axes_({x, y}),
71-
var4weight_(weight),
72-
entry_cuts_name_(cuts != nullptr ? cuts->GetName() : "") {
69+
EntryConfig::EntryConfig(const Axis& x, const Axis& y, const Variable& weight, const std::string& name, Cuts* cuts, bool is_profile) : type_(is_profile ? PlotType::kProfile : PlotType::kHisto2D),
70+
axes_({x, y}),
71+
var4weight_(weight),
72+
entry_cuts_name_(cuts != nullptr ? cuts->GetName() : "") {
7373
Set2DName(name);
7474
InitPlot();
7575
}

src/EntryConfig.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ class EntryConfig {
4545
};
4646

4747
EntryConfig() = default;
48-
explicit EntryConfig(const Axis& axis, [[maybe_unused]] Variable& weight, const std::string& name, Cuts* cuts = nullptr, bool is_integral = false);
49-
EntryConfig(const Axis& x, const Axis& y, Variable& weight, const std::string& name, Cuts* cuts = nullptr, bool is_profile = false);
48+
explicit EntryConfig(const Axis& axis, [[maybe_unused]] const Variable& weight, const std::string& name, Cuts* cuts = nullptr, bool is_integral = false);
49+
EntryConfig(const Axis& x, const Axis& y, const Variable& weight, const std::string& name, Cuts* cuts = nullptr, bool is_profile = false);
5050
EntryConfig(const Axis& x, Cuts* cuts_x, const Axis& y, Cuts* cuts_y, const std::string& name);
5151

5252
EntryConfig(const EntryConfig&) = default;

src/Task.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
namespace AnalysisTree {
66
namespace QA {
77

8-
size_t Task::AddH1(const std::string& name, const Axis& x, Cuts* cuts, Variable weight) {
8+
size_t Task::AddH1(const std::string& name, const Axis& x, Cuts* cuts, const Variable& weight) {
99
CreateOutputFileIfNotYet();
10-
weight.IfEmptyVariableConvertToOnes(x);
1110
entries_.emplace_back(x, weight, name, cuts, false);
1211
const std::string dirName = ConstructOutputDirectoryName();
1312
TDirectory* dir = MkDirIfNotYet(out_file_, dirName);
@@ -18,13 +17,12 @@ size_t Task::AddH1(const std::string& name, const Axis& x, Cuts* cuts, Variable
1817
return entries_.size() - 1;
1918
}
2019

21-
size_t Task::AddH1(const Axis& x, Cuts* cuts, Variable weight) {
22-
return AddH1("", x, cuts, std::move(weight));
20+
size_t Task::AddH1(const Axis& x, Cuts* cuts, const Variable& weight) {
21+
return AddH1("", x, cuts, weight);
2322
}
2423

25-
size_t Task::AddH2(const std::string& name, const Axis& x, const Axis& y, Cuts* cuts, Variable weight) {
24+
size_t Task::AddH2(const std::string& name, const Axis& x, const Axis& y, Cuts* cuts, const Variable& weight) {
2625
CreateOutputFileIfNotYet();
27-
weight.IfEmptyVariableConvertToOnes(x);
2826
entries_.emplace_back(x, y, weight, name, cuts);
2927
const std::string dirName = ConstructOutputDirectoryName();
3028
TDirectory* dir = MkDirIfNotYet(out_file_, dirName);
@@ -35,13 +33,12 @@ size_t Task::AddH2(const std::string& name, const Axis& x, const Axis& y, Cuts*
3533
return entries_.size() - 1;
3634
}
3735

38-
size_t Task::AddH2(const Axis& x, const Axis& y, Cuts* cuts, Variable weight) {
39-
return AddH2("", x, y, cuts, std::move(weight));
36+
size_t Task::AddH2(const Axis& x, const Axis& y, Cuts* cuts, const Variable& weight) {
37+
return AddH2("", x, y, cuts, weight);
4038
}
4139

42-
size_t Task::AddProfile(const std::string& name, const Axis& x, const Axis& y, Cuts* cuts, Variable weight) {
40+
size_t Task::AddProfile(const std::string& name, const Axis& x, const Axis& y, Cuts* cuts, const Variable& weight) {
4341
CreateOutputFileIfNotYet();
44-
weight.IfEmptyVariableConvertToOnes(x);
4542
entries_.emplace_back(x, y, weight, name, cuts, true);
4643
const std::string dirName = ConstructOutputDirectoryName();
4744
TDirectory* dir = MkDirIfNotYet(out_file_, dirName);
@@ -52,14 +49,13 @@ size_t Task::AddProfile(const std::string& name, const Axis& x, const Axis& y, C
5249
return entries_.size() - 1;
5350
}
5451

55-
size_t Task::AddProfile(const Axis& x, const Axis& y, Cuts* cuts, Variable weight) {
56-
return AddProfile("", x, y, cuts, std::move(weight));
52+
size_t Task::AddProfile(const Axis& x, const Axis& y, Cuts* cuts, const Variable& weight) {
53+
return AddProfile("", x, y, cuts, weight);
5754
}
5855

5956
size_t Task::AddIntegral(const std::string& name, const Axis& x, Cuts* cuts) {
6057
CreateOutputFileIfNotYet();
61-
Variable weight{};
62-
weight.IfEmptyVariableConvertToOnes(x);
58+
const Variable weight{};
6359
entries_.emplace_back(x, weight, name, cuts, true);
6460
const std::string dirName = ConstructOutputDirectoryName();
6561
TDirectory* dir = MkDirIfNotYet(out_file_, dirName);
@@ -91,7 +87,7 @@ size_t Task::AddIntegral(const Axis& x, const Axis& y, Cuts* cuts_x, Cuts* cuts_
9187
return AddIntegral("", x, y, cuts_x, cuts_y);
9288
}
9389

94-
void Task::FillIntegral(EntryConfig& plot) {
90+
void Task::FillIntegral(EntryConfig& plot) const {
9591
double integral_x{0.};
9692
double integral_y{0.};
9793
const auto& var_ids = plot.GetVariablesId();

src/Task.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ class Task : public AnalysisTask {
3333
void Exec() override;
3434
void Finish() override;
3535

36-
size_t AddH1(const std::string& name, const Axis& x, Cuts* cuts = nullptr, Variable weight = Variable{});
36+
size_t AddH1(const std::string& name, const Axis& x, Cuts* cuts = nullptr, const Variable& weight = {});
3737

38-
size_t AddH1(const Axis& x, Cuts* cuts = nullptr, Variable weight = Variable{});
38+
size_t AddH1(const Axis& x, Cuts* cuts = nullptr, const Variable& weight = {});
3939

40-
size_t AddH2(const std::string& name, const Axis& x, const Axis& y, Cuts* cuts = nullptr, Variable weight = Variable{});
40+
size_t AddH2(const std::string& name, const Axis& x, const Axis& y, Cuts* cuts = nullptr, const Variable& weight = {});
4141

42-
size_t AddH2(const Axis& x, const Axis& y, Cuts* cuts = nullptr, Variable weight = Variable{});
42+
size_t AddH2(const Axis& x, const Axis& y, Cuts* cuts = nullptr, const Variable& weight = {});
4343

44-
size_t AddProfile(const std::string& name, const Axis& x, const Axis& y, Cuts* cuts = nullptr, Variable weight = Variable{});
44+
size_t AddProfile(const std::string& name, const Axis& x, const Axis& y, Cuts* cuts = nullptr, const Variable& weight = {});
4545

46-
size_t AddProfile(const Axis& x, const Axis& y, Cuts* cuts = nullptr, Variable weight = Variable{});
46+
size_t AddProfile(const Axis& x, const Axis& y, Cuts* cuts = nullptr, const Variable& weight = {});
4747

4848
size_t AddIntegral(const std::string& name, const Axis& x, Cuts* cuts = nullptr);
4949

@@ -60,7 +60,7 @@ class Task : public AnalysisTask {
6060
void ResetTopLevelDirName();
6161

6262
private:
63-
void FillIntegral(EntryConfig& plot);
63+
void FillIntegral(EntryConfig& plot) const;
6464

6565
template<typename T>
6666
static TDirectory* MkDirIfNotYet(T* fileOrDirectory, const std::string& name) {

0 commit comments

Comments
 (0)