-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[treeplayer] Don't mistake formulas for script files in TTree::Draw #22774
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
Open
guitargeek
wants to merge
1
commit into
root-project:master
Choose a base branch
from
guitargeek:ROOT-8000
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+82
−30
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -274,6 +274,46 @@ void TTreePlayer::DeleteSelectorFromFile() | |
| fSelectorClass = nullptr; | ||
| } | ||
|
|
||
| namespace { | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
| /// TTree::Draw can take the name of a C++ script file (optionally with an | ||
| /// ACLiC mode suffix and arguments, e.g. "myscript.C+(2)") instead of a | ||
| /// TTreeFormula expression for both the variable expression and the | ||
| /// selection; see "Drawing a user function accessing the TTree data directly" | ||
| /// in the TTree::Draw documentation. Determine whether 'expression' names | ||
| /// such a script file. | ||
| /// | ||
| /// Besides checking that the file exists, require that it has an extension: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. who does require? |
||
| /// TTreeProxyGenerator::WriteProxy() needs one to derive the name of the | ||
| /// function to call. This avoids misinterpreting an expression like "abs(x)" | ||
| /// as the script "abs" called with argument "(x)" whenever an unrelated file | ||
| /// with that name happens to exist in the current directory (JIRA ROOT-8000). | ||
|
|
||
| bool IsScriptFile(const char *expression) | ||
| { | ||
| if (!expression || !expression[0]) | ||
| return false; | ||
|
|
||
| const TString candidate = expression; | ||
| if (candidate.Index("Alt$") >= 0 || candidate.Index("Entries$") >= 0 || candidate.Index("LocalEntries$") >= 0 || | ||
| candidate.Index("Length$") >= 0 || candidate.Index("Entry$") >= 0 || candidate.Index("LocalEntry$") >= 0 || | ||
| candidate.Index("Min$") >= 0 || candidate.Index("Max$") >= 0 || candidate.Index("MinIf$") >= 0 || | ||
| candidate.Index("MaxIf$") >= 0 || candidate.Index("Iteration$") >= 0 || candidate.Index("Sum$") >= 0 || | ||
| candidate.Index(">") >= 0 || candidate.Index("<") >= 0) | ||
| return false; | ||
|
|
||
| TString aclicMode, arguments, io; | ||
| const TString realname = gSystem->SplitAclicMode(candidate, aclicMode, arguments, io); | ||
| const Ssiz_t dot_pos = realname.Last('.'); | ||
| if (dot_pos == kNPOS || dot_pos < realname.Last('/')) | ||
| return false; | ||
|
|
||
| return gSystem->IsFileInIncludePath(candidate); | ||
| } | ||
|
|
||
| } // anonymous namespace | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
| /// Draw the result of a C++ script. | ||
| /// | ||
|
|
@@ -357,44 +397,23 @@ Long64_t TTreePlayer::DrawSelect(const char *varexp0, const char *selection, Opt | |
| // Let's see if we have a filename as arguments instead of | ||
| // a TTreeFormula expression. | ||
|
|
||
| TString possibleFilename = varexp0; | ||
| Ssiz_t dot_pos = possibleFilename.Last('.'); | ||
| if ( dot_pos != kNPOS | ||
| && possibleFilename.Index("Alt$")<0 && possibleFilename.Index("Entries$")<0 | ||
| && possibleFilename.Index("LocalEntries$")<0 | ||
| && possibleFilename.Index("Length$")<0 && possibleFilename.Index("Entry$")<0 | ||
| && possibleFilename.Index("LocalEntry$")<0 | ||
| && possibleFilename.Index("Min$")<0 && possibleFilename.Index("Max$")<0 | ||
| && possibleFilename.Index("MinIf$")<0 && possibleFilename.Index("MaxIf$")<0 | ||
| && possibleFilename.Index("Iteration$")<0 && possibleFilename.Index("Sum$")<0 | ||
| && possibleFilename.Index(">")<0 && possibleFilename.Index("<")<0 | ||
| && gSystem->IsFileInIncludePath(possibleFilename.Data())) { | ||
|
|
||
| if (selection && strlen(selection) && !gSystem->IsFileInIncludePath(selection)) { | ||
| if (IsScriptFile(varexp0)) { | ||
|
|
||
| if (selection && strlen(selection) && !IsScriptFile(selection)) { | ||
| Error("DrawSelect", | ||
| "Drawing using a C++ file currently requires that both the expression and the selection are files\n\t\"%s\" is not a file", | ||
| selection); | ||
| return 0; | ||
| } | ||
| return DrawScript("generatedSel",varexp0,selection,option,nentries,firstentry); | ||
|
|
||
| } else { | ||
| possibleFilename = selection; | ||
| if (possibleFilename.Index("Alt$")<0 && possibleFilename.Index("Entries$")<0 | ||
| && possibleFilename.Index("LocalEntries$")<0 | ||
| && possibleFilename.Index("Length$")<0 && possibleFilename.Index("Entry$")<0 | ||
| && possibleFilename.Index("LocalEntry$")<0 | ||
| && possibleFilename.Index("Min$")<0 && possibleFilename.Index("Max$")<0 | ||
| && possibleFilename.Index("MinIf$")<0 && possibleFilename.Index("MaxIf$")<0 | ||
| && possibleFilename.Index("Iteration$")<0 && possibleFilename.Index("Sum$")<0 | ||
| && possibleFilename.Index(">")<0 && possibleFilename.Index("<")<0 | ||
| && gSystem->IsFileInIncludePath(possibleFilename.Data())) { | ||
| } else if (IsScriptFile(selection)) { | ||
|
|
||
| Error("DrawSelect", | ||
| "Drawing using a C++ file currently requires that both the expression and the selection are files\n\t\"%s\" is not a file", | ||
| varexp0); | ||
| return 0; | ||
| } | ||
| Error("DrawSelect", | ||
| "Drawing using a C++ file currently requires that both the expression and the selection are " | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. c++ file --> c++ macro? |
||
| "files\n\t\"%s\" is not a file", | ||
| varexp0); | ||
| return 0; | ||
| } | ||
|
|
||
| Long64_t oldEstimate = fTree->GetEstimate(); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.