Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made some methods const #174

Merged
merged 21 commits into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
bb8a120
TRestEvent - made methods consts, used const references, increased cl…
lobis Apr 1, 2022
634364a
TRestHits - made some methods const
lobis Apr 1, 2022
52ec934
TRestHits - made all possible methods const
lobis Apr 1, 2022
e6da8d7
TRestHits - GetMostEnergeticHitInRange fixed bug
lobis Apr 1, 2022
aa5b537
TRestHits - made all function argument `TVector3` passed by const ref…
lobis Apr 1, 2022
6bad675
Geant4Lib - made most compatible methods const and fixed errors
lobis Apr 1, 2022
7d23903
TRestHits.cxx - added back bug to see if pipeline is fixed
lobis Apr 1, 2022
4073148
TRestEvent.h - reverted increase of class version
lobis Apr 1, 2022
2b138ed
pipeline - updated `MakeBasicTree.C` macro with more checks
lobis Apr 3, 2022
7e1732c
pipeline - updated `ValidateTrees.C` macro, more readable variable names
lobis Apr 3, 2022
092d4da
pipeline - renamed some variables in `MakeBasicTree.C` macro, more pr…
lobis Apr 3, 2022
1d06419
pipeline - fixed typo https://github.com/rest-for-physics/framework/p…
lobis Apr 4, 2022
80d87e3
pipeline/MakeBasicTree.C - added error on empty tree
lobis Apr 4, 2022
cede9bc
.gitlab-ci.yml - updated pipeline
lobis Apr 4, 2022
cdcb061
Adding const methods to TRestVolumeHits
juanangp Apr 5, 2022
4cdfdb1
Merge remote-tracking branch 'origin/master' into lobis-add-const-to-…
lobis Apr 5, 2022
4f45a62
TRestVolumeHits - made a few more methods const
lobis Apr 5, 2022
047d268
Merge branch 'master' into lobis-add-const-to-getters
jgalan Apr 5, 2022
d1f56b0
Merge branch 'master' into lobis-add-const-to-getters
jgalan Apr 5, 2022
99c0aea
Updating PR badge
jgalan Apr 5, 2022
7531f6d
Merge branch 'lobis-add-const-to-getters' of github.com:rest-for-phys…
jgalan Apr 5, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 42 additions & 17 deletions pipeline/MakeBasicTree.C
Original file line number Diff line number Diff line change
@@ -1,37 +1,62 @@
// This macro will extract the double observables and will fill a tree with std::vector<double>
Int_t MakeBasicTree(string fname) {
TRestRun* run = new TRestRun(fname);
Int_t MakeBasicTree(const char* inputFilename, const char* outputFilename = "results.root",
Bool_t check = true) {
TRestRun run(inputFilename);

TRestAnalysisTree* aTree = run->GetAnalysisTree();
TRestAnalysisTree* analysisTree = run.GetAnalysisTree();

std::vector<double> obsValues;
for (int n = 0; n < aTree->GetNumberOfObservables(); n++) {
if (aTree->GetObservableType(n) == "double") obsValues.push_back(0);
for (int n = 0; n < analysisTree->GetNumberOfObservables(); n++) {
if (analysisTree->GetObservableType(n) == "double") obsValues.push_back(0);
}

TFile* outFile = new TFile("results.root", "RECREATE");
TTree* myTree = new TTree("bTree", "basicTree");
TFile* outFile = new TFile(outputFilename, "RECREATE");
TTree* outTree = new TTree("bTree", "basicTree");

myTree->Branch("doubleObservables", &obsValues);
outTree->Branch("doubleObservables", &obsValues);

for (int n = 0; n < run->GetEntries(); n++) {
run->GetEntry(n);
for (int n = 0; n < run.GetEntries(); n++) {
run.GetEntry(n);
// cout << "Entry : " << n << endl;

obsValues.clear();
for (int m = 0; m < aTree->GetNumberOfObservables(); m++) {
if (aTree->GetObservableType(m) == "double") {
for (int m = 0; m < analysisTree->GetNumberOfObservables(); m++) {
if (analysisTree->GetObservableType(m) == "double") {
if (n == 0) {
cout << "index: " << obsValues.size() << ", obsName: " << aTree->GetObservableName(m)
<< " value: " << aTree->GetObservableValue<Double_t>(m) << endl;
cout << "index: " << obsValues.size()
<< ", obsName: " << analysisTree->GetObservableName(m)
<< " value: " << analysisTree->GetObservableValue<Double_t>(m) << endl;
}
obsValues.push_back(aTree->GetObservableValue<Double_t>(m));
obsValues.push_back(analysisTree->GetObservableValue<Double_t>(m));
}
}
myTree->Fill();
outTree->Fill();
}

myTree->Write();
// check all trees have the same number of elements
if (run.GetEntries() != analysisTree->GetEntries() || run.GetEntries() != outTree->GetEntries()) {
cout << "ERROR: mismatch in number of tree entries" << endl;
return 1;
}
outTree->Write();
outFile->Close();

// check output file tree has the correct number of entries
if (check) {
TFile outFileCheck(outputFilename, "READ");
TTree* outTreeCheck = outFileCheck.Get<TTree>("bTree");
if (outTreeCheck == nullptr) {
cout << "ERROR: tree was not correctly written into file" << endl;
return 1;
}

if (outTreeCheck->GetEntries() != run.GetEntries()) {
cout << "ERROR: output file check - mismatch in number of tree entries" << endl;
return 1;
}
}

cout << "Finished `MakeBasicTree.C` macro. Number of entries: " << run.GetEntries() << endl;

return 0;
}
62 changes: 35 additions & 27 deletions pipeline/ValidateTrees.C
Original file line number Diff line number Diff line change
@@ -1,52 +1,60 @@
#include <TFile.h>
#include <TTree.h>

#include <iostream>
#include <vector>
Int_t ValidateTrees(TString validationFile) {
TFile* f = new TFile("results.root");
TTree* tr = (TTree*)f->Get("bTree");
std::vector<double>* vr = 0;
tr->SetBranchAddress("doubleObservables", &vr);

TFile* fV = new TFile(validationFile);
TTree* tV = (TTree*)fV->Get("bTree");
std::vector<double>* vV = 0;
tV->SetBranchAddress("doubleObservables", &vV);

if (tr->GetEntries() != tV->GetEntries()) {

Int_t ValidateTrees(const char* validationFilename, const char* inputFilename = "results.root") {
TFile inputFile(inputFilename);
TTree* inputTree = inputFile.Get<TTree>("bTree");
std::vector<double>* inputObservableVector = 0;
inputTree->SetBranchAddress("doubleObservables", &inputObservableVector);

TFile validationFile(inputFilename);
lobis marked this conversation as resolved.
Show resolved Hide resolved
TTree* validationTree = validationFile.Get<TTree>("bTree");
std::vector<double>* validationObservableVector = 0;
validationTree->SetBranchAddress("doubleObservables", &validationObservableVector);

if (inputTree->GetEntries() != validationTree->GetEntries()) {
cout << "Number of entries is not the same!" << endl;
cout << "result: " << tr->GetEntries() << endl;
cout << "anticipated: " << tV->GetEntries() << endl;
cout << "result: " << inputTree->GetEntries() << endl;
cout << "anticipated: " << validationTree->GetEntries() << endl;
return 1;
}

bool obsValErr = false;
for (int n = 0; n < tr->GetEntries(); n++) {
tr->GetEntry(n);
tV->GetEntry(n);
for (int n = 0; n < inputTree->GetEntries(); n++) {
inputTree->GetEntry(n);
validationTree->GetEntry(n);

if ((*vr).size() != (*vV).size()) {
if ((*inputObservableVector).size() != (*validationObservableVector).size()) {
cout << "Vectors are different size at entry " << n << "!!" << endl;
cout << "results.root vector size : " << (*vr).size() << endl;
cout << "validation.root vector size : " << (*vV).size() << endl;
cout << "results.root vector size : " << (*inputObservableVector).size() << endl;
cout << "validation.root vector size : " << (*validationObservableVector).size() << endl;

cout << "Validation vector contents: " << endl;
for (int m = 0; m < (*vV).size(); m++) cout << (*vV)[m] << "\t";
for (int m = 0; m < (*validationObservableVector).size(); m++)
cout << (*validationObservableVector)[m] << "\t";
cout << endl;

cout << "Results vector contents: " << endl;
for (int m = 0; m < (*vr).size(); m++) cout << (*vr)[m] << "\t";
for (int m = 0; m < (*inputObservableVector).size(); m++)
cout << (*inputObservableVector)[m] << "\t";
cout << endl;
return 2;
}

for (int m = 0; m < (*vr).size(); m++) {
if ((Int_t)(1000. * (*vr)[m]) != (Int_t)(1000. * (*vV)[m])) {
for (int m = 0; m < (*inputObservableVector).size(); m++) {
if ((Int_t)(1000. * (*inputObservableVector)[m]) !=
(Int_t)(1000. * (*validationObservableVector)[m])) {
cout << "Double Observable with index " << m << " in entry " << n
<< " is not the same value!!" << endl;
printf(" value: %.15f, should be: %.15f\n", (*vr)[m], (*vV)[m]);
printf(" value: %.15f, should be: %.15f\n", (*inputObservableVector)[m],
(*validationObservableVector)[m]);

if (!TMath::IsNaN((*vr)[m] - (*vV)[m]) && abs(((*vr)[m] - (*vV)[m]) / (*vr)[m]) < 1e-15) {
if (!TMath::IsNaN((*inputObservableVector)[m] - (*validationObservableVector)[m]) &&
abs(((*inputObservableVector)[m] - (*validationObservableVector)[m]) /
(*inputObservableVector)[m]) < 1e-15) {
cout << " (ignored)" << endl;
} else {
obsValErr = true;
Expand All @@ -56,6 +64,6 @@ Int_t ValidateTrees(TString validationFile) {
}
if (obsValErr) return 3;

cout << "Tree validation sucess!" << endl;
cout << "Tree validation success!" << endl;
return 0;
}
40 changes: 20 additions & 20 deletions source/framework/core/inc/TRestEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,45 +55,45 @@ class TRestEvent : public TObject {

public:
// Setters
void SetRunOrigin(Int_t run_origin) { fRunOrigin = run_origin; }
void SetSubRunOrigin(Int_t sub_run_origin) { fSubRunOrigin = sub_run_origin; }
inline void SetRunOrigin(Int_t run_origin) { fRunOrigin = run_origin; }
inline void SetSubRunOrigin(Int_t sub_run_origin) { fSubRunOrigin = sub_run_origin; }

void SetID(Int_t id) { fEventID = id; }
void SetSubID(Int_t id) { fSubEventID = id; }
void SetSubEventTag(TString tag) { fSubEventTag = tag; }
inline void SetID(Int_t id) { fEventID = id; }
inline void SetSubID(Int_t id) { fSubEventID = id; }
inline void SetSubEventTag(const TString& tag) { fSubEventTag = tag; }

void SetTime(Double_t time);
void SetTime(Double_t seconds, Double_t nanoseconds);
void SetTimeStamp(TTimeStamp time) { fEventTime = time; }
inline void SetTimeStamp(const TTimeStamp& time) { fEventTime = time; }

void SetState(Bool_t state) { fOk = state; }
void SetOK(Bool_t state) { fOk = state; }
inline void SetState(Bool_t state) { fOk = state; }
inline void SetOK(Bool_t state) { fOk = state; }

void SetEventInfo(TRestEvent* eve);

// Getters
Int_t GetID() { return fEventID; }
Int_t GetSubID() { return fSubEventID; }
TString GetSubEventTag() { return fSubEventTag; }
inline Int_t GetID() const { return fEventID; }
inline Int_t GetSubID() const { return fSubEventID; }
inline TString GetSubEventTag() const { return fSubEventTag; }

Int_t GetRunOrigin() { return fRunOrigin; }
Int_t GetSubRunOrigin() { return fSubRunOrigin; }
inline Int_t GetRunOrigin() const { return fRunOrigin; }
inline Int_t GetSubRunOrigin() const { return fSubRunOrigin; }

Double_t GetTime() { return fEventTime.AsDouble(); }
TTimeStamp GetTimeStamp() { return fEventTime; }
inline Double_t GetTime() const { return fEventTime.AsDouble(); }
inline TTimeStamp GetTimeStamp() const { return fEventTime; }

Bool_t isOk() { return fOk; }
inline Bool_t isOk() const { return fOk; }

virtual void Initialize() = 0;
virtual void InitializeWithMetadata(TRestRun* r);

virtual void PrintEvent();
virtual void PrintEvent() const;

//////////////////////////////////////////////////////////////////////////
/// \brief Draw the event
///
/// To be implemented in the derived class
virtual TPad* DrawEvent(TString option = "") {
virtual TPad* DrawEvent(const TString& option = "") {
UNUSED(option);
return new TPad();
}
Expand All @@ -105,6 +105,6 @@ class TRestEvent : public TObject {
// Destructor
virtual ~TRestEvent();

ClassDef(TRestEvent, 1); // REST event superclass
ClassDef(TRestEvent, 1);
};
#endif
#endif
Loading