@@ -289,6 +289,8 @@ TGraphAsymmErrors::TGraphAsymmErrors(const TH1* pass, const TH1* total, Option_t
289289// / - format = `"%lg %lg %lg %lg"` read only 4 first columns into X, Y, EYL, EYH
290290// / - format = `"%lg %lg %lg %lg %lg %lg"` read only 6 first columns into X, Y, EXL, EXH, EYL, EYH
291291// /
292+ // / If format string is empty, suitable value will be provided based on file extension
293+ // /
292294// / For files separated by a specific delimiter different from ' ' and `\\t` (e.g. `;` in csv files)
293295// / you can avoid using `%*s` to bypass this delimiter by explicitly specify the `option` argument,
294296// / e.g. `option=" \\t,;"` for columns of figures separated by any of these characters (`' ', '\\t', ',', ';'`)
@@ -314,18 +316,30 @@ TGraphAsymmErrors::TGraphAsymmErrors(const char *filename, const char *format, O
314316 std::string line;
315317 Int_t np = 0 ;
316318
317- if (strcmp (option, " " ) == 0 ) { // No delimiters specified (standard constructor).
319+ TString format_ = format;
320+
321+ if (!option || !*option) { // No delimiters specified (standard constructor).
322+
323+ Int_t ncol = 6 ;
324+ if (format_.IsNull ()) {
325+ if (fname.EndsWith (" .txt" , TString::kIgnoreCase ))
326+ format_ = " %lg %lg %lg %lg %lg %lg" ;
327+ else if (fname.EndsWith (" .tsv" , TString::kIgnoreCase ))
328+ format_ = " %lg\t %lg\t %lg\t %lg\t %lg\t %lg" ;
329+ else
330+ format_ = " %lg,%lg,%lg,%lg,%lg,%lg" ;
331+ } else
332+ ncol = TGraphErrors::CalculateScanfFields (format); // count number of columns in format
318333
319- Int_t ncol = TGraphErrors::CalculateScanfFields (format); // count number of columns in format
320334 Int_t res;
321335 while (std::getline (infile, line, ' \n ' )) {
322336 exl = exh = eyl = eyh = 0 .;
323337 if (ncol < 3 ) {
324- res = sscanf (line.c_str (), format , &x, &y);
338+ res = sscanf (line.c_str (), format_. Data () , &x, &y);
325339 } else if (ncol < 5 ) {
326- res = sscanf (line.c_str (), format , &x, &y, &eyl, &eyh);
340+ res = sscanf (line.c_str (), format_. Data () , &x, &y, &eyl, &eyh);
327341 } else {
328- res = sscanf (line.c_str (), format , &x, &y, &exl, &exh, &eyl, &eyh);
342+ res = sscanf (line.c_str (), format_. Data () , &x, &y, &exl, &exh, &eyl, &eyh);
329343 }
330344 if (res < 2 ) {
331345 continue ; // skip empty and ill-formed lines
@@ -339,7 +353,6 @@ TGraphAsymmErrors::TGraphAsymmErrors(const char *filename, const char *format, O
339353 } else { // A delimiter has been specified in "option"
340354
341355 // Checking format and creating its boolean equivalent
342- TString format_ = TString (format) ;
343356 format_.ReplaceAll (" " , " " ) ;
344357 format_.ReplaceAll (" \t " , " " ) ;
345358 format_.ReplaceAll (" lg" , " " ) ;
0 commit comments