From 47007ce33728c6419532202b552bdb5f4c09d6ea Mon Sep 17 00:00:00 2001 From: Zhe Zhang Date: Thu, 3 Sep 2015 22:29:00 -0500 Subject: [PATCH 1/2] Fix issue ROOT-7588. cin is not seekable. Temporary stringstream is created to store cin. --- tree/tree/src/TTree.cxx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tree/tree/src/TTree.cxx b/tree/tree/src/TTree.cxx index 531c2107fcaf7..2c70996d23d67 100644 --- a/tree/tree/src/TTree.cxx +++ b/tree/tree/src/TTree.cxx @@ -369,6 +369,7 @@ We encourage you to use TTree::AddFriend rather than adding a branch manually. #include "TFileMergeInfo.h" #include +#include #include #include #include @@ -6831,8 +6832,18 @@ char TTree::GetNewlineValue(std::istream &inputStream) Long64_t TTree::ReadStream(std::istream& inputStream, const char *branchDescriptor, char delimiter) { - char newline = GetNewlineValue(inputStream); - std::istream& in = inputStream; + char newline = 0; + std::stringstream ss; + std::istream *inTemp; + if(&inputStream == &std::cin){ + ss << std::cin.rdbuf(); + newline = GetNewlineValue(ss); + inTemp = &ss; + } else { + newline = GetNewlineValue(inputStream); + inTemp = &inputStream; + } + std::istream& in = *inTemp; Long64_t nlines = 0; TBranch *branch = 0; From 5d75d99c2ac2794389f71bb05172f414b53b1959 Mon Sep 17 00:00:00 2001 From: Zhe Zhang Date: Mon, 4 Jan 2016 21:21:19 -0600 Subject: [PATCH 2/2] Verify inputStream is good and then see if is std::cin by calling tellg() --- tree/tree/src/TTree.cxx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tree/tree/src/TTree.cxx b/tree/tree/src/TTree.cxx index 26662c04fc361..3bd08956b5cb7 100644 --- a/tree/tree/src/TTree.cxx +++ b/tree/tree/src/TTree.cxx @@ -6993,7 +6993,12 @@ Long64_t TTree::ReadStream(std::istream& inputStream, const char *branchDescript char newline = 0; std::stringstream ss; std::istream *inTemp; - if(&inputStream == &std::cin){ + Long_t inPos = inputStream.tellg(); + if (!inputStream.good()) { + Error("ReadStream","Error reading stream"); + return 0; + } + if(inPos == -1){ ss << std::cin.rdbuf(); newline = GetNewlineValue(ss); inTemp = &ss;