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

cleaning and better string handling of TRestAnalysisTree and TRestEventProcess #339

Merged
merged 9 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
37 changes: 20 additions & 17 deletions source/framework/core/inc/TRestAnalysisTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
#ifndef RestCore_TRestAnalysisTree
#define RestCore_TRestAnalysisTree

#include <TChain.h>
#include <TTree.h>

#include <limits>
#include "TChain.h"

#include "TRestEvent.h"
#include "TRestReflector.h"
#include "TTree.h"

//! REST core data-saving helper based on TTree
class TRestAnalysisTree : public TTree {
Expand Down Expand Up @@ -103,7 +105,7 @@ class TRestAnalysisTree : public TTree {
Int_t GetObservableID(const std::string& obsName);
Int_t GetMatchedObservableID(const std::string& obsName);
Bool_t ObservableExists(const std::string& obsName);
// six basic event prameters
// six basic event parameters
Int_t GetEventID() { return fChain ? ((TRestAnalysisTree*)fChain->GetTree())->GetEventID() : fEventID; }
Int_t GetSubEventID() {
return fChain ? ((TRestAnalysisTree*)fChain->GetTree())->GetSubEventID() : fSubEventID;
Expand All @@ -121,13 +123,13 @@ class TRestAnalysisTree : public TTree {
Int_t GetNumberOfObservables() { return fNObservables; }

// observable method
RESTValue GetObservable(std::string obsName);
RESTValue GetObservable(const std::string& obsName);
RESTValue GetObservable(Int_t n);
TString GetObservableName(Int_t n);
TString GetObservableDescription(Int_t n);
TString GetObservableType(Int_t n);
TString GetObservableType(std::string obsName);
Double_t GetDblObservableValue(std::string obsName);
TString GetObservableType(const std::string& obsName);
Double_t GetDblObservableValue(const std::string& obsName);
Double_t GetDblObservableValue(Int_t n);

///////////////////////////////////////////////
Expand Down Expand Up @@ -252,21 +254,21 @@ class TRestAnalysisTree : public TTree {
void SetEventInfo(TRestEvent* evt);
Int_t Fill();

RESTValue AddObservable(TString observableName, TString observableType = "double",
TString description = "");
RESTValue AddObservable(const TString& observableName, const TString& observableType = "double",
const TString& description = "");
template <typename T>
T& AddObservable(TString observableName, TString description = "") {
return *(T*)AddObservable(observableName, REST_Reflection::GetTypeName<T>(), description);
}

Int_t GetEntry(Long64_t entry = 0, Int_t getall = 0);

Bool_t EvaluateCuts(const std::string expression);
Bool_t EvaluateCut(const std::string expression);
Bool_t EvaluateCuts(const std::string& expression);
Bool_t EvaluateCut(const std::string& expression);

TString GetStringWithObservableNames();

std::vector<std::string> GetCutObservables(const std::string cut_str);
std::vector<std::string> GetCutObservables(const std::string& cut_str);

void EnableBranches(std::vector<std::string> obsNames);
void DisableBranches(std::vector<std::string> obsNames);
Expand All @@ -277,19 +279,20 @@ class TRestAnalysisTree : public TTree {
void EnableQuickObservableValueSetting();
void DisableQuickObservableValueSetting();

Double_t GetObservableAverage(TString obsName, Double_t xLow = -1, Double_t xHigh = -1,
Double_t GetObservableAverage(const TString& obsName, Double_t xLow = -1, Double_t xHigh = -1,
Int_t nBins = 1000);

Double_t GetObservableRMS(TString obsName, Double_t xLow = -1, Double_t xHigh = -1, Int_t nBins = 1000);
Double_t GetObservableRMS(const TString& obsName, Double_t xLow = -1, Double_t xHigh = -1,
Int_t nBins = 1000);

Double_t GetObservableMinimum(TString obsName, Double_t xLow = -1, Double_t xHigh = -1,
Double_t GetObservableMinimum(const TString& obsName, Double_t xLow = -1, Double_t xHigh = -1,
Int_t nBins = 1000);
Double_t GetObservableMaximum(TString obsName, Double_t xLow = -1, Double_t xHigh = -1,
Double_t GetObservableMaximum(const TString& obsName, Double_t xLow = -1, Double_t xHigh = -1,
Int_t nBins = 1000);

Int_t WriteAsTTree(const char* name = 0, Int_t option = 0, Int_t bufsize = 0);

Bool_t AddChainFile(std::string file);
Bool_t AddChainFile(const std::string& file);

TTree* GetTree() const;

Expand Down Expand Up @@ -379,7 +382,7 @@ class TRestAnalysisTree : public TTree {

// Constructor
TRestAnalysisTree();
TRestAnalysisTree(TString name, TString title);
TRestAnalysisTree(const TString& name, const TString& title);
static TRestAnalysisTree* ConvertFromTTree(TTree* tree);
// Destructor
virtual ~TRestAnalysisTree();
Expand Down
60 changes: 32 additions & 28 deletions source/framework/core/inc/TRestEventProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
#ifndef RestCore_TRestEventProcess
#define RestCore_TRestEventProcess

#include <TCanvas.h>
#include <TNamed.h>

#include <limits>
#include "TCanvas.h"
#include "TNamed.h"

#include "TRestAnalysisTree.h"
#include "TRestEvent.h"
#include "TRestMetadata.h"
Expand Down Expand Up @@ -103,9 +105,9 @@ class TRestEventProcess : public TRestMetadata {
std::string type = REST_Reflection::GetTypeName<T>();
return (T*)GetMetadata(type);
}
TRestMetadata* GetMetadata(std::string nameOrType);
TRestEventProcess* GetFriend(std::string nameOrType);
TRestEventProcess* GetFriendLive(std::string nameOrType);
TRestMetadata* GetMetadata(const std::string& nameOrType);
TRestEventProcess* GetFriend(const std::string& nameOrType);
TRestEventProcess* GetFriendLive(const std::string& nameOrType);
inline size_t GetNumberOfParallelProcesses() const { return fParallelProcesses.size(); }
TRestEventProcess* GetParallel(int i);
//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -146,32 +148,34 @@ class TRestEventProcess : public TRestMetadata {
/// If use dynamic observable, it will try to create new observable
/// in the AnalysisTree if the observable is not found
template <class T>
inline void SetObservableValue(std::string name, const T& value) {
if (fAnalysisTree != nullptr) {
std::string obsName = this->GetName() + (std::string) "_" + (std::string)name;
inline void SetObservableValue(const std::string& name, const T& value) {
if (fAnalysisTree == nullptr) {
return;
}

std::string obsName = std::string(this->GetName()) + "_" + name;

if (fValidateObservables) {
int id = fAnalysisTree->GetObservableID(obsName);
if (id != -1) {
if (fValidateObservables) {
int id = fAnalysisTree->GetObservableID(obsName);
if (id != -1) {
fObservablesDefined[obsName] = id;
fObservablesUpdated[obsName] = id;
fAnalysisTree->SetObservable(obsName, value);
} else if (fDynamicObs) {
fAnalysisTree->SetObservable(obsName, value);
int n = fAnalysisTree->GetObservableID(obsName);
if (n != -1) {
fObservablesDefined[obsName] = id;
fObservablesUpdated[obsName] = id;
fAnalysisTree->SetObservable(obsName, value);
} else if (fDynamicObs) {
fAnalysisTree->SetObservable(obsName, value);
int n = fAnalysisTree->GetObservableID(obsName);
if (n != -1) {
fObservablesDefined[obsName] = id;
fObservablesUpdated[obsName] = id;
}
}
} else {
int id = fAnalysisTree->GetObservableID(obsName);
if (id != -1) {
fAnalysisTree->SetObservableValue(id, value);
} else if (fDynamicObs) {
fAnalysisTree->SetObservableValue(obsName, value);
}
}
} else {
int id = fAnalysisTree->GetObservableID(obsName);
if (id != -1) {
fAnalysisTree->SetObservableValue(id, value);
} else if (fDynamicObs) {
fAnalysisTree->SetObservableValue(obsName, value);
}
}
}

Expand Down Expand Up @@ -205,9 +209,9 @@ class TRestEventProcess : public TRestMetadata {
}
std::vector<std::string> ReadObservables();
// open a list of input files to be processed, only used if is external process
virtual Bool_t OpenInputFiles(std::vector<std::string> files);
virtual Bool_t OpenInputFiles(const std::vector<std::string>& files);
// add an input file during process
virtual Bool_t AddInputFile(std::string file) { return false; }
virtual Bool_t AddInputFile(const std::string& file) { return false; }
// reset the entry by moving file ptr to 0 with fseek
virtual Bool_t ResetEntry() { return false; }

Expand Down
Loading