From f67f748c470a904397d3b7e458e867903768f4a1 Mon Sep 17 00:00:00 2001 From: Javier Galan Date: Wed, 12 Jun 2024 13:11:04 +0200 Subject: [PATCH 1/5] TRestDataSet::fDataSet renamed to fDataFrame. Added methods Range,ApplyRange and GetEntries --- source/framework/core/inc/TRestDataSet.h | 17 ++-- source/framework/core/src/TRestDataSet.cxx | 92 ++++++++++++++-------- 2 files changed, 70 insertions(+), 39 deletions(-) diff --git a/source/framework/core/inc/TRestDataSet.h b/source/framework/core/inc/TRestDataSet.h index 483351510..6f8515dbe 100644 --- a/source/framework/core/inc/TRestDataSet.h +++ b/source/framework/core/inc/TRestDataSet.h @@ -112,7 +112,7 @@ class TRestDataSet : public TRestMetadata { Bool_t fExternal = false; //< /// The resulting RDF::RNode object after initialization - ROOT::RDF::RNode fDataSet = ROOT::RDataFrame(0); //! + ROOT::RDF::RNode fDataFrame = ROOT::RDataFrame(0); //! /// A pointer to the generated tree TChain* fTree = nullptr; //! @@ -127,7 +127,7 @@ class TRestDataSet : public TRestMetadata { ROOT::RDF::RNode GetDataFrame() const { if (!fExternal && fTree == nullptr) RESTWarning << "DataFrame has not been yet initialized" << RESTendl; - return fDataSet; + return fDataFrame; } void EnableMultiThreading(Bool_t enable = true) { fMT = enable; } @@ -136,8 +136,7 @@ class TRestDataSet : public TRestMetadata { TTree* GetTree() const { if (fTree == nullptr && fExternal) { RESTInfo << "The tree is not accessible. Only GetDataFrame can be used in an externally " - "generated dataset" - << RESTendl; + "generated dataset" << RESTendl; RESTInfo << "You may write a tree using GetDataFrame()->Snapshot(\"MyTree\", \"output.root\");" << RESTendl; return fTree; @@ -152,7 +151,7 @@ class TRestDataSet : public TRestMetadata { } /// Number of variables (or observables) - size_t GetNumberOfColumns() { return fDataSet.GetColumnNames().size(); } + size_t GetNumberOfColumns() { return fDataFrame.GetColumnNames().size(); } /// Number of variables (or observables) size_t GetNumberOfBranches() { return GetNumberOfColumns(); } @@ -187,7 +186,7 @@ class TRestDataSet : public TRestMetadata { void SetTotalTimeInSeconds(Double_t seconds) { fTotalDuration = seconds; } void SetDataFrame(const ROOT::RDF::RNode& dS) { - fDataSet = dS; + fDataFrame = dS; fExternal = true; } @@ -198,8 +197,12 @@ class TRestDataSet : public TRestMetadata { void Export(const std::string& filename, std::vector excludeColumns = {}); ROOT::RDF::RNode MakeCut(const TRestCut* cut); + ROOT::RDF::RNode ApplyRange(size_t from, size_t to); + ROOT::RDF::RNode Range(size_t from, size_t to); ROOT::RDF::RNode DefineColumn(const std::string& columnName, const std::string& formula); + size_t GetEntries(); + void PrintMetadata() override; void Initialize() override; @@ -209,6 +212,6 @@ class TRestDataSet : public TRestMetadata { TRestDataSet(const char* cfgFileName, const std::string& name = ""); ~TRestDataSet(); - ClassDefOverride(TRestDataSet, 7); + ClassDefOverride(TRestDataSet, 8); }; #endif diff --git a/source/framework/core/src/TRestDataSet.cxx b/source/framework/core/src/TRestDataSet.cxx index 28a2a8890..d619be797 100644 --- a/source/framework/core/src/TRestDataSet.cxx +++ b/source/framework/core/src/TRestDataSet.cxx @@ -382,25 +382,25 @@ void TRestDataSet::GenerateDataSet() { ROOT::DisableImplicitMT(); RESTInfo << "Initializing dataset" << RESTendl; - fDataSet = ROOT::RDataFrame("AnalysisTree", fFileSelection); + fDataFrame = ROOT::RDataFrame("AnalysisTree", fFileSelection); RESTInfo << "Making cuts" << RESTendl; - fDataSet = MakeCut(fCut); + fDataFrame = MakeCut(fCut); // Adding new user columns added to the dataset - for (const auto& [cName, cExpression] : fColumnNameExpressions) { + for (const auto & [ cName, cExpression ] : fColumnNameExpressions) { RESTInfo << "Adding column to dataset: " << cName << RESTendl; finalList.emplace_back(cName); - fDataSet = DefineColumn(cName, cExpression); + fDataFrame = DefineColumn(cName, cExpression); } RESTInfo << "Generating snapshot." << RESTendl; std::string user = getenv("USER"); std::string fOutName = "/tmp/rest_output_" + user + ".root"; - fDataSet.Snapshot("AnalysisTree", fOutName, finalList); + fDataFrame.Snapshot("AnalysisTree", fOutName, finalList); RESTInfo << "Re-importing analysis tree." << RESTendl; - fDataSet = ROOT::RDataFrame("AnalysisTree", fOutName); + fDataFrame = ROOT::RDataFrame("AnalysisTree", fOutName); TFile* f = TFile::Open(fOutName.c_str()); fTree = (TChain*)f->Get("AnalysisTree"); @@ -419,8 +419,7 @@ std::vector TRestDataSet::FileSelection() { if (!time_stamp_end || !time_stamp_start) { RESTError << "TRestDataSet::FileSelect. Start or end dates not properly formed. Please, check " - "REST_StringHelper::StringToTimeStamp documentation for valid formats" - << RESTendl; + "REST_StringHelper::StringToTimeStamp documentation for valid formats" << RESTendl; return fFileSelection; } @@ -473,7 +472,7 @@ std::vector TRestDataSet::FileSelection() { if (!accept) continue; Double_t acc = 0; - for (auto& [name, properties] : fQuantity) { + for (auto & [ name, properties ] : fQuantity) { std::string value = run.ReplaceMetadataMembers(properties.metadata); const Double_t val = REST_StringHelper::StringToDouble(value); @@ -517,20 +516,37 @@ std::vector TRestDataSet::FileSelection() { return fFileSelection; } +/////////////////////////////////////////////// +/// \brief This method returns a RDataFrame node with the number of +/// samples inside the dataset by selecting a range. It will not +/// modify internally the dataset. See ApplyRange to modify internally +/// the dataset. +/// +ROOT::RDF::RNode TRestDataSet::Range(size_t from, size_t to) { return fDataFrame.Range(from, to); } + +/////////////////////////////////////////////// +/// \brief This method reduces the number of samples inside the +/// dataset by selecting a range. +/// +ROOT::RDF::RNode TRestDataSet::ApplyRange(size_t from, size_t to) { + fDataFrame = fDataFrame.Range(from, to); + return fDataFrame; +} + /////////////////////////////////////////////// /// \brief This function applies a TRestCut to the dataframe /// and returns a dataframe with the applied cuts. Note that /// the cuts are not applied directly to the dataframe on -/// TRestDataSet, to do so you should do fDataSet = MakeCut(fCut); +/// TRestDataSet, to do so you should do fDataFrame = MakeCut(fCut); /// ROOT::RDF::RNode TRestDataSet::MakeCut(const TRestCut* cut) { - auto df = fDataSet; + auto df = fDataFrame; if (cut == nullptr) return df; auto paramCut = cut->GetParamCut(); auto obsList = df.GetColumnNames(); - for (const auto& [param, condition] : paramCut) { + for (const auto & [ param, condition ] : paramCut) { if (std::find(obsList.begin(), obsList.end(), param) != obsList.end()) { std::string pCut = param + condition; RESTDebug << "Applying cut " << pCut << RESTendl; @@ -561,6 +577,20 @@ ROOT::RDF::RNode TRestDataSet::MakeCut(const TRestCut* cut) { return df; } +/////////////////////////////////////////////// +/// \brief It returns the number of entries found inside fDataFrame +/// and prints out a warning if the number of entries inside the +/// tree is not the same. +/// +size_t TRestDataSet::GetEntries() { + auto nEntries = fDataFrame.Count(); + if (*nEntries == (long long unsigned int)GetTree()->GetEntries()) return *nEntries; + RESTWarning << "TRestDataSet::GetEntries. Number of tree entries is not the same as RDataFrame entries." + << RESTendl; + RESTWarning << "Returning RDataFrame entries" << RESTendl; + return *nEntries; +} + /////////////////////////////////////////////// /// \brief This function will add a new column to the RDataFrame using /// the same scheme as the usual RDF::Define method, but it will on top of @@ -574,10 +604,10 @@ ROOT::RDF::RNode TRestDataSet::MakeCut(const TRestCut* cut) { /// \endcode /// ROOT::RDF::RNode TRestDataSet::DefineColumn(const std::string& columnName, const std::string& formula) { - auto df = fDataSet; + auto df = fDataFrame; std::string evalFormula = formula; - for (auto const& [name, properties] : fQuantity) + for (auto const & [ name, properties ] : fQuantity) evalFormula = REST_StringHelper::Replace(evalFormula, name, properties.value); df = df.Define(columnName, evalFormula); @@ -643,7 +673,7 @@ void TRestDataSet::PrintMetadata() { RESTMetadata << " Relevant quantities: " << RESTendl; RESTMetadata << " -------------------- " << RESTendl; - for (auto const& [name, properties] : fQuantity) { + for (auto const & [ name, properties ] : fQuantity) { RESTMetadata << " - Name : " << name << ". Value : " << properties.value << ". Strategy: " << properties.strategy << RESTendl; RESTMetadata << " - Metadata: " << properties.metadata << RESTendl; @@ -655,7 +685,7 @@ void TRestDataSet::PrintMetadata() { if (!fColumnNameExpressions.empty()) { RESTMetadata << " New columns added to generated dataframe: " << RESTendl; RESTMetadata << " ---------------------------------------- " << RESTendl; - for (const auto& [cName, cExpression] : fColumnNameExpressions) { + for (const auto & [ cName, cExpression ] : fColumnNameExpressions) { RESTMetadata << " - Name : " << cName << RESTendl; RESTMetadata << " - Expression: " << cExpression << RESTendl; RESTMetadata << " " << RESTendl; @@ -819,22 +849,21 @@ void TRestDataSet::InitFromConfigFile() { void TRestDataSet::Export(const std::string& filename, std::vector excludeColumns) { RESTInfo << "Exporting dataset" << RESTendl; - std::vector columns = fDataSet.GetColumnNames(); + std::vector columns = fDataFrame.GetColumnNames(); if (!excludeColumns.empty()) { - columns.erase(std::remove_if(columns.begin(), columns.end(), - [&excludeColumns](std::string elem) { - return std::find(excludeColumns.begin(), excludeColumns.end(), - elem) != excludeColumns.end(); - }), + columns.erase(std::remove_if(columns.begin(), columns.end(), [&excludeColumns](std::string elem) { + return std::find(excludeColumns.begin(), excludeColumns.end(), elem) != + excludeColumns.end(); + }), columns.end()); RESTInfo << "Re-Generating snapshot." << RESTendl; std::string user = getenv("USER"); std::string fOutName = "/tmp/rest_output_" + user + ".root"; - fDataSet.Snapshot("AnalysisTree", fOutName, columns); + fDataFrame.Snapshot("AnalysisTree", fOutName, columns); RESTInfo << "Re-importing analysis tree." << RESTendl; - fDataSet = ROOT::RDataFrame("AnalysisTree", fOutName); + fDataFrame = ROOT::RDataFrame("AnalysisTree", fOutName); TFile* f = TFile::Open(fOutName.c_str()); fTree = (TChain*)f->Get("AnalysisTree"); @@ -846,7 +875,7 @@ void TRestDataSet::Export(const std::string& filename, std::vector RESTInfo << "Re-Generating snapshot." << RESTendl; std::string user = getenv("USER"); std::string fOutName = "/tmp/rest_output_" + user + ".root"; - fDataSet.Snapshot("AnalysisTree", fOutName); + fDataFrame.Snapshot("AnalysisTree", fOutName); TFile* f = TFile::Open(fOutName.c_str()); fTree = (TChain*)f->Get("AnalysisTree"); @@ -860,8 +889,7 @@ void TRestDataSet::Export(const std::string& filename, std::vector if (type != "Double_t" && type != "Int_t") { RESTError << "Branch name : " << bName << " is type : " << type << RESTendl; RESTError << "Only Int_t and Double_t types are allowed for " - "exporting to ASCII table" - << RESTendl; + "exporting to ASCII table" << RESTendl; RESTError << "File will not be generated" << RESTendl; return; } @@ -896,7 +924,7 @@ void TRestDataSet::Export(const std::string& filename, std::vector } fprintf(f, "###\n"); fprintf(f, "### Relevant quantities: \n"); - for (auto& [name, properties] : fQuantity) { + for (auto & [ name, properties ] : fQuantity) { fprintf(f, "### - %s : %s - %s\n", name.c_str(), properties.value.c_str(), properties.description.c_str()); } @@ -910,7 +938,7 @@ void TRestDataSet::Export(const std::string& filename, std::vector fprintf(f, "###\n"); fprintf(f, "### Data starts here\n"); - auto obsNames = fDataSet.GetColumnNames(); + auto obsNames = fDataFrame.GetColumnNames(); std::string obsListStr = ""; for (const auto& l : obsNames) { if (!obsListStr.empty()) obsListStr += ":"; @@ -938,7 +966,7 @@ void TRestDataSet::Export(const std::string& filename, std::vector return; } else if (TRestTools::GetFileNameExtension(filename) == "root") { - fDataSet.Snapshot("AnalysisTree", filename); + fDataFrame.Snapshot("AnalysisTree", filename); TFile* f = TFile::Open(filename.c_str(), "UPDATE"); std::string name = this->GetName(); @@ -1038,7 +1066,7 @@ void TRestDataSet::Import(const std::string& fileName) { else ROOT::DisableImplicitMT(); - fDataSet = ROOT::RDataFrame("AnalysisTree", fileName); + fDataFrame = ROOT::RDataFrame("AnalysisTree", fileName); fTree = (TChain*)file->Get("AnalysisTree"); } @@ -1104,7 +1132,7 @@ void TRestDataSet::Import(std::vector fileNames) { } RESTInfo << "Opening list of files. First file: " << fileNames[0] << RESTendl; - fDataSet = ROOT::RDataFrame("AnalysisTree", fileNames); + fDataFrame = ROOT::RDataFrame("AnalysisTree", fileNames); if (fTree != nullptr) { delete fTree; From 72d1dee722a4dd4d49d089a5f31297baa28cd346 Mon Sep 17 00:00:00 2001 From: Javier Galan Date: Wed, 12 Jun 2024 13:15:11 +0200 Subject: [PATCH 2/5] TRestComponentDataSet::fSplitEntries added to split ExtractParameterizationNodes --- .../sensitivity/inc/TRestComponentDataSet.h | 5 +++- .../sensitivity/src/TRestComponentDataSet.cxx | 28 +++++++++++-------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/source/framework/sensitivity/inc/TRestComponentDataSet.h b/source/framework/sensitivity/inc/TRestComponentDataSet.h index 9a2154f05..c58a39603 100644 --- a/source/framework/sensitivity/inc/TRestComponentDataSet.h +++ b/source/framework/sensitivity/inc/TRestComponentDataSet.h @@ -54,6 +54,9 @@ class TRestComponentDataSet : public TRestComponent { /// The dataset used to initialize the distribution TRestDataSet fDataSet; //! + /// It helps to split large datasets when extracting the parameterization nodes + long long unsigned int fSplitEntries = 600000000; + /// It is true of the dataset was loaded without issues Bool_t fDataSetLoaded = false; //! @@ -84,6 +87,6 @@ class TRestComponentDataSet : public TRestComponent { TRestComponentDataSet(const char* cfgFileName, const std::string& name); ~TRestComponentDataSet(); - ClassDefOverride(TRestComponentDataSet, 3); + ClassDefOverride(TRestComponentDataSet, 4); }; #endif diff --git a/source/framework/sensitivity/src/TRestComponentDataSet.cxx b/source/framework/sensitivity/src/TRestComponentDataSet.cxx index 951018acc..2c78a4992 100644 --- a/source/framework/sensitivity/src/TRestComponentDataSet.cxx +++ b/source/framework/sensitivity/src/TRestComponentDataSet.cxx @@ -383,15 +383,17 @@ std::vector TRestComponentDataSet::ExtractParameterizationNodes() { return vs; } - auto parValues = fDataSet.GetDataFrame().Take(fParameter); - for (const auto v : parValues) vs.push_back(v); - - std::vector::iterator ip; - ip = std::unique(vs.begin(), vs.begin() + vs.size()); - vs.resize(std::distance(vs.begin(), ip)); - std::sort(vs.begin(), vs.end()); - ip = std::unique(vs.begin(), vs.end()); - vs.resize(std::distance(vs.begin(), ip)); + auto GetUniqueElements = [](const std::vector& vec) { + std::set uniqueSet(vec.begin(), vec.end()); + return std::vector(uniqueSet.begin(), uniqueSet.end()); + }; + + for (size_t n = 0; n < 1 + fDataSet.GetEntries() / fSplitEntries; n++) { + auto nEn = fDataSet.Range(n * fSplitEntries, (n + 1) * fSplitEntries).Count(); + auto parValues = fDataSet.Range(n * fSplitEntries, (n + 1) * fSplitEntries).Take(fParameter); + std::vector uniqueVec = GetUniqueElements(*parValues); + vs.insert(vs.end(), uniqueVec.begin(), uniqueVec.end()); + } return vs; } @@ -433,7 +435,7 @@ std::vector TRestComponentDataSet::ExtractNodeStatistics() { nEv = fDataSet.GetDataFrame().Filter(filter).Range(fSamples).Count(); } - if ((Int_t)*nEv < fSamples) { + if ((Int_t) * nEv < fSamples) { RESTWarning << "The number of requested samples (" << fSamples << ") is higher than the number of dataset entries (" << *nEv << ")" << RESTendl; } @@ -486,6 +488,7 @@ Bool_t TRestComponentDataSet::LoadDataSets() { if (VariablesOk() && WeightsOk()) { fParameterizationNodes = ExtractParameterizationNodes(); + RESTInfo << "Filling histograms" << RESTendl; FillHistograms(); return fDataSetLoaded; } @@ -515,11 +518,12 @@ Bool_t TRestComponentDataSet::WeightsOk() { Bool_t ok = true; std::vector cNames = fDataSet.GetDataFrame().GetColumnNames(); - for (const auto& var : fWeights) - if (std::count(cNames.begin(), cNames.end(), var) == 0) { + for (const auto& var : fWeights) { + if (!isANumber(var) && std::count(cNames.begin(), cNames.end(), var) == 0) { RESTError << "Weight ---> " << var << " <--- NOT found on dataset" << RESTendl; ok = false; } + } return ok; } From f4c1d675eaed70bc72b84dc3c669d9fff1d9f724 Mon Sep 17 00:00:00 2001 From: Javier Galan Date: Wed, 12 Jun 2024 16:39:16 +0200 Subject: [PATCH 3/5] TRestDataSet::RegenerateTree method added and used when invoking ApplyRange --- source/framework/core/inc/TRestDataSet.h | 2 ++ source/framework/core/src/TRestDataSet.cxx | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/source/framework/core/inc/TRestDataSet.h b/source/framework/core/inc/TRestDataSet.h index 6f8515dbe..81f089180 100644 --- a/source/framework/core/inc/TRestDataSet.h +++ b/source/framework/core/inc/TRestDataSet.h @@ -122,6 +122,8 @@ class TRestDataSet : public TRestMetadata { protected: virtual std::vector FileSelection(); + void RegenerateTree(std::vector finalList = {}); + public: /// Gives access to the RDataFrame ROOT::RDF::RNode GetDataFrame() const { diff --git a/source/framework/core/src/TRestDataSet.cxx b/source/framework/core/src/TRestDataSet.cxx index d619be797..273a70c00 100644 --- a/source/framework/core/src/TRestDataSet.cxx +++ b/source/framework/core/src/TRestDataSet.cxx @@ -394,18 +394,28 @@ void TRestDataSet::GenerateDataSet() { fDataFrame = DefineColumn(cName, cExpression); } + RegenerateTree(finalList); + + RESTInfo << " - Dataset generated!" << RESTendl; +} + +/////////////////////////////////////////////// +/// \brief It regenerates the tree so that it is an exact copy of the present DataFrame +/// +void TRestDataSet::RegenerateTree(std::vector finalList) { RESTInfo << "Generating snapshot." << RESTendl; std::string user = getenv("USER"); std::string fOutName = "/tmp/rest_output_" + user + ".root"; - fDataFrame.Snapshot("AnalysisTree", fOutName, finalList); + if (!finalList.empty()) + fDataFrame.Snapshot("AnalysisTree", fOutName, finalList); + else + fDataFrame.Snapshot("AnalysisTree", fOutName); RESTInfo << "Re-importing analysis tree." << RESTendl; fDataFrame = ROOT::RDataFrame("AnalysisTree", fOutName); TFile* f = TFile::Open(fOutName.c_str()); fTree = (TChain*)f->Get("AnalysisTree"); - - RESTInfo << " - Dataset generated!" << RESTendl; } /////////////////////////////////////////////// @@ -530,6 +540,7 @@ ROOT::RDF::RNode TRestDataSet::Range(size_t from, size_t to) { return fDataFrame /// ROOT::RDF::RNode TRestDataSet::ApplyRange(size_t from, size_t to) { fDataFrame = fDataFrame.Range(from, to); + RegenerateTree(); return fDataFrame; } From c978dba6abffed299576dcb20fff528291084729 Mon Sep 17 00:00:00 2001 From: Javier Galan Date: Wed, 12 Jun 2024 16:41:19 +0200 Subject: [PATCH 4/5] TRestComponentDataSet::fDFRange added to allow reducing the component dataset statistics --- source/framework/sensitivity/inc/TRestComponentDataSet.h | 3 +++ .../framework/sensitivity/src/TRestComponentDataSet.cxx | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/source/framework/sensitivity/inc/TRestComponentDataSet.h b/source/framework/sensitivity/inc/TRestComponentDataSet.h index c58a39603..59e276268 100644 --- a/source/framework/sensitivity/inc/TRestComponentDataSet.h +++ b/source/framework/sensitivity/inc/TRestComponentDataSet.h @@ -57,6 +57,9 @@ class TRestComponentDataSet : public TRestComponent { /// It helps to split large datasets when extracting the parameterization nodes long long unsigned int fSplitEntries = 600000000; + /// It creates a sample subset using a range definition + TVector2 fDFRange = TVector2(0, 0); + /// It is true of the dataset was loaded without issues Bool_t fDataSetLoaded = false; //! diff --git a/source/framework/sensitivity/src/TRestComponentDataSet.cxx b/source/framework/sensitivity/src/TRestComponentDataSet.cxx index 2c78a4992..e81792052 100644 --- a/source/framework/sensitivity/src/TRestComponentDataSet.cxx +++ b/source/framework/sensitivity/src/TRestComponentDataSet.cxx @@ -148,6 +148,11 @@ void TRestComponentDataSet::PrintMetadata() { RESTMetadata << " " << RESTendl; } + if (fDFRange.X() != 0 || fDFRange.Y() != 0) { + RESTMetadata << " DataFrame range: ( " << fDFRange.X() << ", " << fDFRange.Y() << ")" << RESTendl; + RESTMetadata << " " << RESTendl; + } + if (!fParameter.empty() && fParameterizationNodes.empty()) { RESTMetadata << "This component has no nodes!" << RESTendl; RESTMetadata << " Use: LoadDataSets() to initialize the nodes" << RESTendl; @@ -478,6 +483,9 @@ Bool_t TRestComponentDataSet::LoadDataSets() { fDataSet.Import(fullFileNames); fDataSetLoaded = true; + if (fDFRange.X() != 0 || fDFRange.Y() != 0) + fDataSet.ApplyRange((size_t)fDFRange.X(), (size_t)fDFRange.Y()); + if (fDataSet.GetTree() == nullptr) { RESTError << "Problem loading dataset from file list :" << RESTendl; for (const auto& f : fDataSetFileNames) RESTError << " - " << f << RESTendl; From fe6aad78da50631c8929e014d40528fbdb4b06fe Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 12 Jun 2024 14:45:29 +0000 Subject: [PATCH 5/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- source/framework/core/inc/TRestDataSet.h | 3 +- source/framework/core/src/TRestDataSet.cxx | 29 ++++++++++--------- .../sensitivity/src/TRestComponentDataSet.cxx | 2 +- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/source/framework/core/inc/TRestDataSet.h b/source/framework/core/inc/TRestDataSet.h index 81f089180..c70eae202 100644 --- a/source/framework/core/inc/TRestDataSet.h +++ b/source/framework/core/inc/TRestDataSet.h @@ -138,7 +138,8 @@ class TRestDataSet : public TRestMetadata { TTree* GetTree() const { if (fTree == nullptr && fExternal) { RESTInfo << "The tree is not accessible. Only GetDataFrame can be used in an externally " - "generated dataset" << RESTendl; + "generated dataset" + << RESTendl; RESTInfo << "You may write a tree using GetDataFrame()->Snapshot(\"MyTree\", \"output.root\");" << RESTendl; return fTree; diff --git a/source/framework/core/src/TRestDataSet.cxx b/source/framework/core/src/TRestDataSet.cxx index 273a70c00..09c2eaa95 100644 --- a/source/framework/core/src/TRestDataSet.cxx +++ b/source/framework/core/src/TRestDataSet.cxx @@ -388,7 +388,7 @@ void TRestDataSet::GenerateDataSet() { fDataFrame = MakeCut(fCut); // Adding new user columns added to the dataset - for (const auto & [ cName, cExpression ] : fColumnNameExpressions) { + for (const auto& [cName, cExpression] : fColumnNameExpressions) { RESTInfo << "Adding column to dataset: " << cName << RESTendl; finalList.emplace_back(cName); fDataFrame = DefineColumn(cName, cExpression); @@ -429,7 +429,8 @@ std::vector TRestDataSet::FileSelection() { if (!time_stamp_end || !time_stamp_start) { RESTError << "TRestDataSet::FileSelect. Start or end dates not properly formed. Please, check " - "REST_StringHelper::StringToTimeStamp documentation for valid formats" << RESTendl; + "REST_StringHelper::StringToTimeStamp documentation for valid formats" + << RESTendl; return fFileSelection; } @@ -482,7 +483,7 @@ std::vector TRestDataSet::FileSelection() { if (!accept) continue; Double_t acc = 0; - for (auto & [ name, properties ] : fQuantity) { + for (auto& [name, properties] : fQuantity) { std::string value = run.ReplaceMetadataMembers(properties.metadata); const Double_t val = REST_StringHelper::StringToDouble(value); @@ -557,7 +558,7 @@ ROOT::RDF::RNode TRestDataSet::MakeCut(const TRestCut* cut) { auto paramCut = cut->GetParamCut(); auto obsList = df.GetColumnNames(); - for (const auto & [ param, condition ] : paramCut) { + for (const auto& [param, condition] : paramCut) { if (std::find(obsList.begin(), obsList.end(), param) != obsList.end()) { std::string pCut = param + condition; RESTDebug << "Applying cut " << pCut << RESTendl; @@ -618,7 +619,7 @@ ROOT::RDF::RNode TRestDataSet::DefineColumn(const std::string& columnName, const auto df = fDataFrame; std::string evalFormula = formula; - for (auto const & [ name, properties ] : fQuantity) + for (auto const& [name, properties] : fQuantity) evalFormula = REST_StringHelper::Replace(evalFormula, name, properties.value); df = df.Define(columnName, evalFormula); @@ -684,7 +685,7 @@ void TRestDataSet::PrintMetadata() { RESTMetadata << " Relevant quantities: " << RESTendl; RESTMetadata << " -------------------- " << RESTendl; - for (auto const & [ name, properties ] : fQuantity) { + for (auto const& [name, properties] : fQuantity) { RESTMetadata << " - Name : " << name << ". Value : " << properties.value << ". Strategy: " << properties.strategy << RESTendl; RESTMetadata << " - Metadata: " << properties.metadata << RESTendl; @@ -696,7 +697,7 @@ void TRestDataSet::PrintMetadata() { if (!fColumnNameExpressions.empty()) { RESTMetadata << " New columns added to generated dataframe: " << RESTendl; RESTMetadata << " ---------------------------------------- " << RESTendl; - for (const auto & [ cName, cExpression ] : fColumnNameExpressions) { + for (const auto& [cName, cExpression] : fColumnNameExpressions) { RESTMetadata << " - Name : " << cName << RESTendl; RESTMetadata << " - Expression: " << cExpression << RESTendl; RESTMetadata << " " << RESTendl; @@ -862,10 +863,11 @@ void TRestDataSet::Export(const std::string& filename, std::vector std::vector columns = fDataFrame.GetColumnNames(); if (!excludeColumns.empty()) { - columns.erase(std::remove_if(columns.begin(), columns.end(), [&excludeColumns](std::string elem) { - return std::find(excludeColumns.begin(), excludeColumns.end(), elem) != - excludeColumns.end(); - }), + columns.erase(std::remove_if(columns.begin(), columns.end(), + [&excludeColumns](std::string elem) { + return std::find(excludeColumns.begin(), excludeColumns.end(), + elem) != excludeColumns.end(); + }), columns.end()); RESTInfo << "Re-Generating snapshot." << RESTendl; @@ -900,7 +902,8 @@ void TRestDataSet::Export(const std::string& filename, std::vector if (type != "Double_t" && type != "Int_t") { RESTError << "Branch name : " << bName << " is type : " << type << RESTendl; RESTError << "Only Int_t and Double_t types are allowed for " - "exporting to ASCII table" << RESTendl; + "exporting to ASCII table" + << RESTendl; RESTError << "File will not be generated" << RESTendl; return; } @@ -935,7 +938,7 @@ void TRestDataSet::Export(const std::string& filename, std::vector } fprintf(f, "###\n"); fprintf(f, "### Relevant quantities: \n"); - for (auto & [ name, properties ] : fQuantity) { + for (auto& [name, properties] : fQuantity) { fprintf(f, "### - %s : %s - %s\n", name.c_str(), properties.value.c_str(), properties.description.c_str()); } diff --git a/source/framework/sensitivity/src/TRestComponentDataSet.cxx b/source/framework/sensitivity/src/TRestComponentDataSet.cxx index e81792052..94d1ef7bc 100644 --- a/source/framework/sensitivity/src/TRestComponentDataSet.cxx +++ b/source/framework/sensitivity/src/TRestComponentDataSet.cxx @@ -440,7 +440,7 @@ std::vector TRestComponentDataSet::ExtractNodeStatistics() { nEv = fDataSet.GetDataFrame().Filter(filter).Range(fSamples).Count(); } - if ((Int_t) * nEv < fSamples) { + if ((Int_t)*nEv < fSamples) { RESTWarning << "The number of requested samples (" << fSamples << ") is higher than the number of dataset entries (" << *nEv << ")" << RESTendl; }