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

Fix on TRestMetadata and TRestDataSet add-ons #427

Merged
merged 15 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from 10 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
29 changes: 29 additions & 0 deletions macros/REST_GenerateDataSets.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "TRestDataSet.h"
#include "TRestTask.h"

#ifndef RestTask_GenerateDataSets
#define RestTask_GenerateDataSets

//*******************************************************************************************************
//*** Description: This macro will launch the generation of datasets defined
//*** inside a particular RML file `datasets.rml` that contains the dataset
//*** definitions. The second argument will allow to specify the datasets
//*** to be generated from the existing ones inside `dataset.rml`.
//***
//*** --------------
//*** Usage: restManager GenerateDataSets datasets.rml set1,set2,set3
//***
//*******************************************************************************************************

Int_t REST_GenerateDataSets(const std::string& inputRML, const std::string& datasets) {
std::vector<std::string> sets = REST_StringHelper::Split(datasets, ",");

for (const auto& set : sets) {
std::cout << "Set : " << set << std::endl;
TRestDataSet d(inputRML.c_str(), set.c_str());
d.GenerateDataSet();
d.Export("Dataset_" + set + ".root");
}
return 0;
}
#endif
8 changes: 6 additions & 2 deletions source/framework/core/inc/TRestDataSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class TRestDataSet : public TRestMetadata {
/// A list of metadata members where filters will be applied
std::vector<std::string> fFilterMetadata; //<

/// If not empty it will check if the metadata member contains the value
/// If not empty it will check if the metadata member contains the string
std::vector<std::string> fFilterContains; //<

/// If the corresponding element is not empty it will check if the metadata member is greater
Expand All @@ -74,6 +74,9 @@ class TRestDataSet : public TRestMetadata {
/// If the corresponding element is not empty it will check if the metadata member is lower
std::vector<Double_t> fFilterLowerThan; //<

/// If the corresponding element is not empty it will check if the metadata member is equal
std::vector<Double_t> fFilterEqualsTo; //<

/// The properties of a relevant quantity that we want to store together with the dataset
std::map<std::string, RelevantQuantity> fQuantity; //<

Expand Down Expand Up @@ -116,7 +119,7 @@ class TRestDataSet : public TRestMetadata {
TTree* GetTree() const {
if (fTree == nullptr) {
RESTError << "Tree has not been yet initialized" << RESTendl;
RESTError << "You should invoke TRestDataSet::Initialize() before trying to access the tree"
RESTError << "You should invoke TRestDataSet::GenerateDataSet() before trying to access the tree"
<< RESTendl;
}
return fTree;
Expand Down Expand Up @@ -145,6 +148,7 @@ class TRestDataSet : public TRestMetadata {
inline auto GetFilterContains() const { return fFilterContains; }
inline auto GetFilterGreaterThan() const { return fFilterGreaterThan; }
inline auto GetFilterLowerThan() const { return fFilterLowerThan; }
inline auto GetFilterEqualsTo() const { return fFilterEqualsTo; }
inline auto GetQuantity() const { return fQuantity; }
inline auto GetCut() const { return fCut; }

Expand Down
11 changes: 10 additions & 1 deletion source/framework/core/src/TRestDataSet.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ void TRestDataSet::Initialize() { SetSectionName(this->ClassName()); }
///
void TRestDataSet::GenerateDataSet() {
if (fTree != nullptr) {
RESTWarning << "Tree has already been loaded. Skipping TRestDataSet::Initialize ... " << RESTendl;
RESTWarning << "Tree has already been loaded. Skipping TRestDataSet::GenerateDataSet ... "
<< RESTendl;
return;
}

Expand Down Expand Up @@ -378,6 +379,9 @@ std::vector<std::string> TRestDataSet::FileSelection() {
if (fFilterLowerThan[n] != -1)
if (StringToDouble(mdValue) >= fFilterLowerThan[n]) accept = false;

if (fFilterEqualsTo[n] != -1)
if (StringToDouble(mdValue) != fFilterEqualsTo[n]) accept = false;

n++;
}

Expand Down Expand Up @@ -511,6 +515,7 @@ void TRestDataSet::PrintMetadata() {
if (!fFilterContains[n].empty()) RESTMetadata << " Contains: " << fFilterContains[n];
if (fFilterGreaterThan[n] != -1) RESTMetadata << " Greater than: " << fFilterGreaterThan[n];
if (fFilterLowerThan[n] != -1) RESTMetadata << " Lower than: " << fFilterLowerThan[n];
if (fFilterEqualsTo[n] != -1) RESTMetadata << " Equals to: " << fFilterEqualsTo[n];

RESTMetadata << RESTendl;
n++;
Expand Down Expand Up @@ -559,10 +564,12 @@ void TRestDataSet::InitFromConfigFile() {
if (contains == "Not defined") contains = "";
Double_t greaterThan = StringToDouble(GetFieldValue("greaterThan", filterDefinition));
Double_t lowerThan = StringToDouble(GetFieldValue("lowerThan", filterDefinition));
Double_t equalsTo = StringToDouble(GetFieldValue("equalsTo", filterDefinition));

fFilterContains.push_back(contains);
fFilterGreaterThan.push_back(greaterThan);
fFilterLowerThan.push_back(lowerThan);
fFilterEqualsTo.push_back(equalsTo);

filterDefinition = GetNextElement(filterDefinition);
}
Expand Down Expand Up @@ -688,6 +695,7 @@ void TRestDataSet::Export(const std::string& filename) {
if (!fFilterContains[n].empty()) fprintf(f, " Contains: %s.", fFilterContains[n].c_str());
if (fFilterGreaterThan[n] != -1) fprintf(f, " Greater than: %6.3lf.", fFilterGreaterThan[n]);
if (fFilterLowerThan[n] != -1) fprintf(f, " Lower than: %6.3lf.", fFilterLowerThan[n]);
if (fFilterEqualsTo[n] != -1) fprintf(f, " Equals to: %6.3lf.", fFilterLowerThan[n]);
fprintf(f, "\n");
n++;
}
Expand Down Expand Up @@ -763,6 +771,7 @@ TRestDataSet& TRestDataSet::operator=(TRestDataSet& dS) {
fFilterContains = dS.GetFilterContains();
fFilterGreaterThan = dS.GetFilterGreaterThan();
fFilterLowerThan = dS.GetFilterLowerThan();
fFilterEqualsTo = dS.GetFilterEqualsTo();
fQuantity = dS.GetQuantity();
fTotalDuration = dS.GetTotalTimeInSeconds();
fCut = dS.GetCut();
Expand Down
2 changes: 2 additions & 0 deletions source/framework/core/src/TRestMetadata.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2327,6 +2327,8 @@ std::vector<string> TRestMetadata::GetDataMemberValues(string memberName, Int_t

result = Replace(result, "{", "");
result = Replace(result, "}", "");
result = Replace(result, "(", "");
result = Replace(result, ")", "");

std::vector<std::string> results = REST_StringHelper::Split(result, ",");

Expand Down