Skip to content

Commit

Permalink
Addressing #189 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
lobis committed Apr 27, 2022
1 parent 7c62362 commit 2c2e66c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 29 deletions.
29 changes: 1 addition & 28 deletions source/framework/core/inc/TRestEventProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,34 +114,7 @@ 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;

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;
}
}
} else {
int id = fAnalysisTree->GetObservableID(obsName);
if (id != -1) {
fAnalysisTree->SetObservableValue(id, value);
} else if (fDynamicObs) {
fAnalysisTree->SetObservableValue(obsName, value);
}
}
}
}
void SetObservableValue(const std::string& name, const T& value);

/// Create the canvas
inline void CreateCanvas() {
Expand Down
32 changes: 31 additions & 1 deletion source/framework/core/src/TRestEventProcess.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,36 @@ TRestEventProcess* TRestEventProcess::GetParallel(int i) {
return nullptr;
}

template <class T>
void TRestEventProcess::SetObservableValue(const string& name, const T& value) {
if (fAnalysisTree != nullptr) {
string obsName = this->GetName() + (string) "_" + (string)name;

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;
}
}
} else {
int id = fAnalysisTree->GetObservableID(obsName);
if (id != -1) {
fAnalysisTree->SetObservableValue(id, value);
} else if (fDynamicObs) {
fAnalysisTree->SetObservableValue(obsName, value);
}
}
}
}

//////////////////////////////////////////////////////////////////////////
/// \brief Apply cut according to the cut conditions saved in fCut
///
Expand Down Expand Up @@ -496,7 +526,7 @@ TRestAnalysisTree* TRestEventProcess::GetFullAnalysisTree() {

//////////////////////////////////////////////////////////////////////////
/// Get list of observables, convert map to vector.
std::vector<string> TRestEventProcess::GetListOfAddedObservables() {
vector<string> TRestEventProcess::GetListOfAddedObservables() {
vector<string> list;
auto iter = fObservablesDefined.begin();
while (iter != fObservablesDefined.end()) {
Expand Down

0 comments on commit 2c2e66c

Please sign in to comment.