Skip to content

Commit

Permalink
Merge pull request #174 from rest-for-physics/lobis-add-const-to-getters
Browse files Browse the repository at this point in the history
Made some methods const
  • Loading branch information
lobis authored Apr 5, 2022
2 parents 5b37f51 + 7531f6d commit 99a43c8
Show file tree
Hide file tree
Showing 10 changed files with 464 additions and 417 deletions.
8 changes: 4 additions & 4 deletions .github/pr-badge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
message: "$payload.pull_request.user.login"
color: "blue"
- label: "PR Size"
message: "Large"
message: "Large: $additions"
color: "red"
when: "$additions > 200"
- label: "PR Size"
message: "Medium"
message: "Medium: $additions"
color: "orange"
when: "$additions > 100"
when: "$additions > 100 and $additions < 201"
- label: "PR Size"
message: "Ok"
message: "Ok: $additions"
color: "green"
when: "$additions < 100"
- imageUrl: "https://gitlab.cern.ch/rest-for-physics/framework/badges/$branchName/pipeline.svg"
Expand Down
40 changes: 20 additions & 20 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Validate Code:
- python3 pipeline/validateProcesses.py source/libraries/

Build and Test:
type: test
stage: test
script:
- cd ${CI_PROJECT_DIR}
- python3 pull-submodules.py --force --dontask --latest:${CI_COMMIT_BRANCH}
Expand All @@ -93,7 +93,7 @@ Build and Test:
expire_in: 1 day

Build and Install:
type: build
stage: build
script:
- cd ${CI_PROJECT_DIR}
- python3 pull-submodules.py --force --dontask --latest:${CI_COMMIT_BRANCH}
Expand All @@ -110,21 +110,21 @@ Build and Install:
expire_in: 1 day

Load REST Libraries:
type: install
stage: install
script:
- echo ${CI_PROJECT_DIR}/install/thisREST.sh
- cat ${CI_PROJECT_DIR}/install/thisREST.sh
- source ${CI_PROJECT_DIR}/install/thisREST.sh
- restRoot -b -q

List REST Macros:
type: install
stage: install
script:
- source ${CI_PROJECT_DIR}/install/thisREST.sh
- restManager ListMacros

01_NLDBD:
type: restG4
stage: restG4
script:
- source ${CI_PROJECT_DIR}/install/thisREST.sh
- cd ${CI_PROJECT_DIR}/install/examples/restG4/01.NLDBD/
Expand All @@ -137,7 +137,7 @@ List REST Macros:
expire_in: 1 day

02_PandaXiiiMC:
type: restG4
stage: restG4
script:
- source ${CI_PROJECT_DIR}/install/thisREST.sh
- cd ${CI_PROJECT_DIR}/pipeline/pandaxiii_MC
Expand All @@ -149,7 +149,7 @@ List REST Macros:
expire_in: 1 day

Load Gas:
type: metadata
stage: metadata
script:
- source ${CI_PROJECT_DIR}/install/thisREST.sh
- cd ${CI_PROJECT_DIR}/pipeline/metadata/gas/
Expand All @@ -159,7 +159,7 @@ Load Gas:
- $CI_SERVER_HOST == "lfna.unizar.es"

Generate Gas:
type: metadata
stage: metadata
script:
- source ${CI_PROJECT_DIR}/install/thisREST.sh
- cd ${CI_PROJECT_DIR}/pipeline/metadata/gas/
Expand All @@ -169,14 +169,14 @@ Generate Gas:
- $CI_SERVER_HOST == "lfna.unizar.es"

AnalysisTree:
type: core
stage: core
script:
- source ${CI_PROJECT_DIR}/install/thisREST.sh
- cd ${CI_PROJECT_DIR}/pipeline/analysistree/
- restRoot -b -q simpleTree.cpp

Generate Readout:
type: metadata
stage: metadata
script:
- source ${CI_PROJECT_DIR}/install/thisREST.sh
- cd ${CI_PROJECT_DIR}/pipeline/metadata/readout/
Expand All @@ -187,7 +187,7 @@ Generate Readout:
# - diff validation.txt print.txt

Basic Readout:
type: metadata
stage: metadata
script:
- source ${CI_PROJECT_DIR}/install/thisREST.sh
- cd ${CI_PROJECT_DIR}/projects/basic-readouts/
Expand All @@ -198,7 +198,7 @@ Basic Readout:
- restRoot -b -q BasicValidation.C'("basic.root", "pixelDecoding")'

Test Metadata:
type: restManager_generate
stage: restManager_generate
script:
- source ${CI_PROJECT_DIR}/install/thisREST.sh
- cd ${CI_PROJECT_DIR}/install/examples
Expand All @@ -209,7 +209,7 @@ Test Metadata:
expire_in: 1 day

TREX-DM Latest Data:
type: restManager_process
stage: restManager_process
script:
- source ${CI_PROJECT_DIR}/install/thisREST.sh
- cd ${CI_PROJECT_DIR}/pipeline/trex
Expand All @@ -228,7 +228,7 @@ TREX-DM Latest Data:
expire_in: 1 day

PandaXIII Topological:
type: restManager_process
stage: restManager_process
script:
- source ${CI_PROJECT_DIR}/install/thisREST.sh
- cd ${CI_PROJECT_DIR}/pipeline/pandaxiii_MC
Expand All @@ -242,7 +242,7 @@ PandaXIII Topological:
expire_in: 1 week

PandaXIII Topological from Geant4:
type: restManager_process
stage: restManager_process
script:
- source ${CI_PROJECT_DIR}/install/thisREST.sh
- cd ${CI_PROJECT_DIR}/pipeline/pandaxiii_MC
Expand All @@ -256,7 +256,7 @@ PandaXIII Topological from Geant4:
expire_in: 1 week

PandaXIII Data:
type: restManager_process
stage: restManager_process
script:
- source ${CI_PROJECT_DIR}/install/thisREST.sh
- cd ${CI_PROJECT_DIR}/pipeline/pandaxiii_data
Expand All @@ -269,7 +269,7 @@ PandaXIII Data:
expire_in: 1 week

Event Selection:
type: restManager_process
stage: restManager_process
script:
- source ${CI_PROJECT_DIR}/install/thisREST.sh
- cd ${CI_PROJECT_DIR}/pipeline/selection
Expand All @@ -283,22 +283,22 @@ Event Selection:
expire_in: 1 week

AnalysisPlot:
type: postProcessing
stage: postProcessing
script:
- source ${CI_PROJECT_DIR}/install/thisREST.sh
- cd ${CI_PROJECT_DIR}/pipeline/analysisPlot/
- restManager --c summary.rml --f ${CI_PROJECT_DIR}/pipeline/trex/Hits_01928.root

AnalysisPlot2:
type: postProcessing
stage: postProcessing
script:
- source ${CI_PROJECT_DIR}/install/thisREST.sh
- cd ${CI_PROJECT_DIR}/pipeline/analysisPlot/
- restManager --batch --c classify.rml
- restRoot -b -q ValidateClassify.C

Deploy:
type: deploy
stage: deploy
only:
- tags
script:
Expand Down
64 changes: 47 additions & 17 deletions pipeline/MakeBasicTree.C
Original file line number Diff line number Diff line change
@@ -1,37 +1,67 @@
// 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;
}
}

if (run.GetEntries() == 0) {
cout << "ERROR: Macro finished without issues but number of final entries is 0" << 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(validationFilename);
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;
}
Loading

0 comments on commit 99a43c8

Please sign in to comment.