Skip to content

Commit

Permalink
Merge pull request #490 from rest-for-physics/jgalan_restRoot
Browse files Browse the repository at this point in the history
Some core but minor changes. Including some non-critical fixes.
  • Loading branch information
jgalan authored Nov 16, 2023
2 parents 7434500 + 2725ad5 commit 52a45c2
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 17 deletions.
2 changes: 2 additions & 0 deletions macros/REST_OpenInputFile.C
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ void REST_OpenInputFile(const std::string& fileName) {
printf("\n%s\n", " - dSet->PrintMetadata()");
printf("%s\n", " - dSet->GetDataFrame().GetColumnNames()");
printf("%s\n\n", " - dSet->GetTree()->GetEntries()");
printf("%s\n\n", " - dSet->GetDataFrame().Display({\"colName1,colName2\"})->Print()");
if (dSet) delete dSet;
dSet = new TRestDataSet();
dSet->EnableMultiThreading(false);
dSet->Import(fileName);
} else {
printf("\n%s is not a valid TRestRun or TRestDataSet\n", fileName.c_str());
Expand Down
2 changes: 1 addition & 1 deletion pipeline/validateMacros.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os, sys

os.system("restRoot -b -q -m 1 > error.log 2>&1")
os.system("restRoot -b -q --m 1 > error.log 2>&1")

with open("error.log") as f:
lines = f.readlines()
Expand Down
8 changes: 8 additions & 0 deletions source/bin/restRoot.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ int main(int argc, char* argv[]) {
// set the env and debug status
setenv("REST_VERSION", REST_RELEASE, 1);

printf("Setting verbose level to info. You may change level using `restRoot -v N`.\n");
printf("Use `restRoot --help` for additional info.\n");
gVerbose = StringToVerboseLevel("2");

Bool_t loadMacros = false;
for (int i = 1; i < argc; i++) {
char* c = &argv[i][0];
Expand Down Expand Up @@ -100,6 +104,10 @@ int main(int argc, char* argv[]) {

for (int i = 1; i < argc; i++) {
const string opt = (string)argv[i];
if (opt.at(0) == ('-') && opt.length() > 1 && opt.at(1) == ('-')) {
i++;
continue;
}
if (opt.at(0) == ('-')) continue;

if (opt.find("http") == string::npos && !TRestTools::fileExists(opt)) {
Expand Down
6 changes: 6 additions & 0 deletions source/framework/core/inc/TRestDataSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ class TRestDataSet : public TRestMetadata {
/// A list of new columns together with its corresponding expressions added to the dataset
std::vector<std::pair<std::string, std::string>> fColumnNameExpressions;

/// A flag to enable Multithreading during dataframe generation
Bool_t fMT = false; //<

inline auto GetAddedColumns() const { return fColumnNameExpressions; }
/// The resulting RDF::RNode object after initialization
ROOT::RDF::RNode fDataSet = ROOT::RDataFrame(0); //!

Expand All @@ -125,6 +129,8 @@ class TRestDataSet : public TRestMetadata {

void SetDataFrame(const ROOT::RDF::RNode& dS) { fDataSet = dS; }

void EnableMultiThreading(Bool_t enable = true) { fMT = enable; }

/// Gives access to the tree
TTree* GetTree() const {
if (fTree == nullptr) {
Expand Down
4 changes: 2 additions & 2 deletions source/framework/core/inc/TRestMetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,10 @@ class TRestMetadata : public TNamed {
void AddLog(std::string log = "", bool print = true);

/// A metadata class may use this method to signal that something went wrong
void SetError(std::string message = "", bool print = true);
void SetError(std::string message = "", bool print = true, int maxPrint = 5);

/// A metadata class may use this method to signal that something went wrong
void SetWarning(std::string message = "", bool print = true);
void SetWarning(std::string message = "", bool print = true, int maxPrint = 5);

/// Returns a std::string containing the error message
TString GetErrorMessage();
Expand Down
27 changes: 19 additions & 8 deletions source/framework/core/src/TRestDataSet.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,6 @@ TRestDataSet::TRestDataSet() { Initialize(); }
///
TRestDataSet::TRestDataSet(const char* cfgFileName, const std::string& name) : TRestMetadata(cfgFileName) {
LoadConfigFromFile(fConfigFileName, name);

if (GetVerboseLevel() >= TRestStringOutput::REST_Verbose_Level::REST_Info) PrintMetadata();
}

///////////////////////////////////////////////
Expand Down Expand Up @@ -343,7 +341,10 @@ void TRestDataSet::GenerateDataSet() {
std::sort(finalList.begin(), finalList.end());
finalList.erase(std::unique(finalList.begin(), finalList.end()), finalList.end());

ROOT::EnableImplicitMT();
if (fMT)
ROOT::EnableImplicitMT();
else
ROOT::DisableImplicitMT();

RESTInfo << "Initializing dataset" << RESTendl;
fDataSet = ROOT::RDataFrame("AnalysisTree", fFileSelection);
Expand Down Expand Up @@ -621,8 +622,11 @@ void TRestDataSet::PrintMetadata() {
if (!fColumnNameExpressions.empty()) {
RESTMetadata << " New columns added to generated dataframe: " << RESTendl;
RESTMetadata << " ---------------------------------------- " << RESTendl;
for (const auto& [cName, cExpression] : fColumnNameExpressions)
RESTMetadata << " - Name : " << cName << " Expression: " << cExpression << RESTendl;
for (const auto& [cName, cExpression] : fColumnNameExpressions) {
RESTMetadata << " - Name : " << cName << RESTendl;
RESTMetadata << " - Expression: " << cExpression << RESTendl;
RESTMetadata << " " << RESTendl;
}
}

if (fMergedDataset) {
Expand All @@ -638,6 +642,12 @@ void TRestDataSet::PrintMetadata() {
for (const auto& fn : fImportedFiles) RESTMetadata << " - " << fn << RESTendl;
}

RESTMetadata << " " << RESTendl;
if (fMT)
RESTMetadata << " - Multithreading was enabled" << RESTendl;
else
RESTMetadata << " - Multithreading was NOT enabled" << RESTendl;

RESTMetadata << "----" << RESTendl;
}

Expand Down Expand Up @@ -944,8 +954,6 @@ void TRestDataSet::Import(const std::string& fileName) {
if (REST_Reflection::GetClassQuick(kName.c_str()) != nullptr &&
REST_Reflection::GetClassQuick(kName.c_str())->InheritsFrom("TRestDataSet")) {
dS = file->Get<TRestDataSet>(key->GetName());
if (GetVerboseLevel() >= TRestStringOutput::REST_Verbose_Level::REST_Info)
dS->PrintMetadata();
*this = *dS;
}
}
Expand All @@ -956,7 +964,10 @@ void TRestDataSet::Import(const std::string& fileName) {
return;
}

ROOT::EnableImplicitMT();
if (fMT)
ROOT::EnableImplicitMT();
else
ROOT::DisableImplicitMT();

fDataSet = ROOT::RDataFrame("AnalysisTree", fileName);

Expand Down
8 changes: 4 additions & 4 deletions source/framework/core/src/TRestMetadata.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2632,23 +2632,23 @@ void TRestMetadata::AddLog(string log, bool print) {
}
}

void TRestMetadata::SetError(string message, bool print) {
void TRestMetadata::SetError(string message, bool print, int maxPrint) {
fError = true;
fNErrors++;
if (message != "") {
fErrorMessage += message + "\n";
if (print) {
if (print && fNErrors < maxPrint) {
cout << message << endl;
}
}
}

void TRestMetadata::SetWarning(string message, bool print) {
void TRestMetadata::SetWarning(string message, bool print, int maxPrint) {
fWarning = true;
fNWarnings++;
if (message != "") {
fWarningMessage += message + "\n";
if (print) {
if (print && fNWarnings < maxPrint) {
RESTWarning << message << RESTendl;
}
}
Expand Down
7 changes: 6 additions & 1 deletion source/framework/core/src/startup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ string VectorToString(vector<T> vec) {
template <class T>
vector<T> StringToVector(string vec) {
vector<T> result;

if (vec.empty()) return result;

if (vec[0] == '{' && vec[vec.size() - 1] == '}') {
vec.erase(vec.begin());
vec.erase(vec.end() - 1);
Expand All @@ -288,7 +291,9 @@ vector<T> StringToVector(string vec) {
}

} else {
cout << "illegal format!" << endl;
cout << "Startup. StringToVector. Illegal format!" << endl;
cout << "The vector string is : " << vec << endl;
cout << "A vector should be defined using brackets and comma separated elements: {a,b,c,d}" << endl;
return vector<T>{};
}

Expand Down
2 changes: 1 addition & 1 deletion source/framework/tools/inc/TRestStringHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Float_t StringToFloat(std::string in);
Double_t StringToDouble(std::string in);
Int_t StringToInteger(std::string in);
std::string IntegerToString(Int_t n, std::string format = "%d");
std::string DoubleToString(Double_t d, std::string format = "%4.2lf");
std::string DoubleToString(Double_t d, std::string format = "%8.6e");
Bool_t StringToBool(std::string booleanString);
Long64_t StringToLong(std::string in);
TVector3 StringTo3DVector(std::string in);
Expand Down

0 comments on commit 52a45c2

Please sign in to comment.