Skip to content

Commit

Permalink
Revert "Merge pull request #386 from rest-for-physics/datasetCut"
Browse files Browse the repository at this point in the history
This reverts commit b830b9a, reversing
changes made to a6e0b61.
  • Loading branch information
jgalan committed May 3, 2023
1 parent 0595265 commit 34e81e6
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 272 deletions.
15 changes: 1 addition & 14 deletions source/framework/core/inc/TRestCut.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,8 @@
//! A class to help on cuts definitions. To be used with TRestAnalysisTree
class TRestCut : public TRestMetadata {
private:
/// Vector of TCuts
std::vector<TCut> fCuts;

/// Vector of cut strings e.g. when you use a complex cut
std::vector<std::string> fCutStrings;

/// Vector of parameter cuts, first item is parameter and second is the condition
std::vector<std::pair<std::string, std::string> > fParamCut;

protected:
void Initialize() override;
void InitFromConfigFile() override;
Expand All @@ -47,12 +40,6 @@ class TRestCut : public TRestMetadata {
void AddCut(TCut cut);
TCut GetCut(std::string name);

inline auto GetCutStrings() const { return fCutStrings; }
inline auto GetParamCut() const { return fParamCut; }
inline auto GetCuts() const { return fCuts; }

TRestCut& operator=(TRestCut& cut);

void PrintMetadata() override;

Int_t Write(const char* name, Int_t option, Int_t bufsize) override;
Expand All @@ -62,7 +49,7 @@ class TRestCut : public TRestMetadata {
// Destructor
~TRestCut() {}

ClassDefOverride(TRestCut, 2); // Template for a REST "event process" class inherited from
ClassDefOverride(TRestCut, 1); // Template for a REST "event process" class inherited from
// TRestEventProcess
};
#endif
53 changes: 9 additions & 44 deletions source/framework/core/inc/TRestDataSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

#include <ROOT/RDataFrame.hxx>

#include "TRestCut.h"
#include "TRestMetadata.h"

struct RelevantQuantity {
Expand All @@ -48,10 +47,10 @@ struct RelevantQuantity {
class TRestDataSet : public TRestMetadata {
private:
/// All the selected runs will have a starting date after fStartTime
std::string fFilterStartTime = "2000/01/01"; //<
std::string fStartTime = "2000/01/01"; //<

/// All the selected runs will have an ending date before fEndTime
std::string fFilterEndTime = "3000/12/31"; //<
std::string fEndTime = "3000/12/31"; //<

/// A glob file pattern that must be satisfied by all files
std::string fFilePattern = ""; //<
Expand All @@ -77,41 +76,30 @@ class TRestDataSet : public TRestMetadata {
/// The properties of a relevant quantity that we want to store together with the dataset
std::map<std::string, RelevantQuantity> fQuantity; //<

/// Parameter cuts over the selected dataset
TRestCut* fCut = nullptr;

/// The total integrated run time of selected files
Double_t fTotalDuration = 0; //<

/// A list populated by the FileSelection method using the conditions of the dataset
std::vector<std::string> fFileSelection; //<

/// TimeStamp for the start time of the first file
Double_t fStartTime = REST_StringHelper::StringToTimeStamp(fFilterEndTime);

/// TimeStamp for the end time of the last file
Double_t fEndTime = REST_StringHelper::StringToTimeStamp(fFilterStartTime);

/// The resulting RDF::RNode object after initialization
ROOT::RDF::RNode fDataSet = ROOT::RDataFrame(0); //!
/// The resulting RDataFrame object after initialization
ROOT::RDataFrame fDataSet = 0; //!

/// A pointer to the generated tree
TTree* fTree = nullptr; //!

/// A list populated by the FileSelection method using the conditions of the dataset
std::vector<std::string> fFileSelection; //!

void InitFromConfigFile() override;

protected:
virtual std::vector<std::string> FileSelection();

public:
/// Gives access to the RDataFrame
ROOT::RDF::RNode GetDataFrame() const {
ROOT::RDataFrame GetDataFrame() const {
if (fTree == nullptr) RESTWarning << "DataFrame has not been yet initialized" << RESTendl;
return fDataSet;
}

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

/// Gives access to the tree
TTree* GetTree() const {
if (fTree == nullptr) {
Expand All @@ -134,37 +122,14 @@ class TRestDataSet : public TRestMetadata {
/// It returns the accumulated run time in seconds
Double_t GetTotalTimeInSeconds() const { return fTotalDuration; }

inline auto GetFilterStartTime() const { return fFilterStartTime; }
inline auto GetFilterEndTime() const { return fFilterEndTime; }
inline auto GetStartTime() const { return fStartTime; }
inline auto GetEndTime() const { return fEndTime; }
inline auto GetFilePattern() const { return fFilePattern; }
inline auto GetObservablesList() const { return fObservablesList; }
inline auto GetProcessObservablesList() const { return fProcessObservablesList; }
inline auto GetFilterMetadata() const { return fFilterMetadata; }
inline auto GetFilterContains() const { return fFilterContains; }
inline auto GetFilterGreaterThan() const { return fFilterGreaterThan; }
inline auto GetFilterLowerThan() const { return fFilterLowerThan; }
inline auto GetQuantity() const { return fQuantity; }
inline auto GetCut() const { return fCut; }

inline void SetFilePattern(const std::string& pattern) { fFilePattern = pattern; }

TRestDataSet& operator=(TRestDataSet& dS);
void Import(const std::string& fileName);
void Export(const std::string& filename);

ROOT::RDF::RNode MakeCut(const TRestCut* cut);

void PrintMetadata() override;
void Initialize() override;

void GenerateDataSet();

TRestDataSet();
TRestDataSet(const char* cfgFileName, const std::string& name = "");
~TRestDataSet();

ClassDefOverride(TRestDataSet, 2);
ClassDefOverride(TRestDataSet, 1);
};
#endif
46 changes: 5 additions & 41 deletions source/framework/core/src/TRestCut.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
/// <TRestCut/>
/// <cut name="cc1" value="XX>10 AND XX<90"/>
/// <cut name="cc2" value="sAna_ThresholdIntegral<100e3"/>
/// <cut name="cc3" variable="sAna_ThresholdIntegral" condition=">0">
/// </TRestCut>
///
/// Note that the notations " AND " and " OR " will be replaced by " && " and " || "
Expand All @@ -45,9 +44,6 @@
/// 2021-dec: First concept.
/// Ni Kaixiang
///
/// 2023-March: Updating metadata structures
/// JuanAn García
///
/// \class TRestCut
///
/// <hr>
Expand All @@ -72,44 +68,14 @@ void TRestCut::InitFromConfigFile() {
auto ele = GetElement("cut");
while (ele != nullptr) {
string name = GetParameter("name", ele, "");
if (name.empty() || name == "Not defined") {
RESTError << "< cut does not contain a name!" << RESTendl;
exit(1);
}

string cutStr = GetParameter("value", ele, "");
string variable = GetParameter("variable", ele, "");
string condition = GetParameter("condition", ele, "");

if (!cutStr.empty()) {
cutStr = Replace(cutStr, " AND ", " && ");
cutStr = Replace(cutStr, " OR ", " || ");
fCutStrings.push_back(cutStr);
AddCut(TCut(name.c_str(), cutStr.c_str()));
} else if (!variable.empty() && !condition.empty()) {
fParamCut.push_back(std::make_pair(variable, condition));
string cutVar = variable + condition;
AddCut(TCut(name.c_str(), cutVar.c_str()));
} else {
RESTError << "TRestCut does not contain a valid parameter/condition or cut string!" << RESTendl;
RESTError << "<cut name='cc1' value='XX>10 AND XX<90'/>" << RESTendl;
RESTError << "<cut name='cc3' variable='sAna_ThresholdIntegral' condition='>0'" << RESTendl;
exit(1);
}

cutStr = Replace(cutStr, " AND ", " && ");
cutStr = Replace(cutStr, " OR ", " || ");
AddCut(TCut(name.c_str(), cutStr.c_str()));
ele = GetNextElement(ele);
}
}

TRestCut& TRestCut::operator=(TRestCut& cut) {
SetName(cut.GetName());
SetTitle(cut.GetTitle());
fCuts = cut.GetCuts();
fCutStrings = cut.GetCutStrings();
fParamCut = cut.GetParamCut();
return *this;
}

void TRestCut::AddCut(TCut cut) {
if ((string)cut.GetName() == "") {
RESTWarning << "TRestCut::AddCut: cannot add cut without name!" << RESTendl;
Expand Down Expand Up @@ -139,10 +105,8 @@ TCut TRestCut::GetCut(string name) {
void TRestCut::PrintMetadata() {
TRestMetadata::PrintMetadata();
RESTMetadata << " " << RESTendl;
RESTMetadata << "Cuts added: " << RESTendl;
for (const auto& cut : fCuts) {
RESTMetadata << cut.GetName() << " " << cut.GetTitle() << RESTendl;
}
RESTMetadata << "Number of TCut objects added: " << fCuts.size() << RESTendl;
RESTMetadata << " " << RESTendl;
RESTMetadata << "+++" << RESTendl;
}

Expand Down
Loading

0 comments on commit 34e81e6

Please sign in to comment.