From f0d05d35cda35d10082ca319a6a6db268bddab80 Mon Sep 17 00:00:00 2001 From: "Bastian M. Wojek" Date: Tue, 14 Jun 2011 09:42:24 +0000 Subject: [PATCH] Refined the data-file search --- ChangeLog | 1 - src/classes/PRunDataHandler.cpp | 103 +++++++++++++++++++++----------- src/include/PRunDataHandler.h | 2 +- 3 files changed, 68 insertions(+), 38 deletions(-) diff --git a/ChangeLog b/ChangeLog index b6ea185a1..423a2d51f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -19,7 +19,6 @@ FIXED ASCII export from musrview in case of a Fourier-Power- or Fourier-Phase-di FIXED bug in asymmetry fit with fixed background CHANGED the data-file-name handling (MUSR-195). It is now possible to specify the full file name in the RUN block (including the extension). - The data files that are looked for have to have either full lower-case (e.g. .nxs) or full upper-case (e.g. .NXS) extensions. CHANGED cosmetics in the musrview legend concerning the units CHANGED the user-function dependency from libPMusr to libPUserFcnBase diff --git a/src/classes/PRunDataHandler.cpp b/src/classes/PRunDataHandler.cpp index ab59b425f..9f127ce7d 100644 --- a/src/classes/PRunDataHandler.cpp +++ b/src/classes/PRunDataHandler.cpp @@ -574,47 +574,78 @@ Bool_t PRunDataHandler::FileAlreadyRead(TString runName) *

Tests if a file exists (with or without given extension). * The given file-name string will be modified to show the found file name or an empty string if no file is found. * - * \param runName run name to be checked + * \param runName run name with full path to be checked * \param ext extension to be checked */ -void PRunDataHandler::TestFileName(TString &runName, TString &ext) +void PRunDataHandler::TestFileName(TString &runName, const TString &ext) { - TString tmpStr(runName); - // check first if the file exists with a lower-case extension - ext.ToLower(); + TString tmpStr(runName), tmpExt(ext); + + // check first if the file exists with the default extension which is not given with the run name runName += TString(".") + ext; - if (gSystem->AccessPathName(runName.Data())!=true) { // found + if (gSystem->AccessPathName(runName.Data()) != true) { // found return; - } else { - runName = tmpStr; - if (tmpStr.EndsWith(ext.Data())) { // assume the lower-case extension is already part of the file name, therefore, do not append it - if (gSystem->AccessPathName(runName.Data())!=true) { // found - return; - } else { // assume a lower-case extension is part of the given file name but the real data file ends with an upper-case extension - ext.ToUpper(); - runName = runName.Replace(static_cast(runName.Length()-ext.Length()), ext.Length(), ext); - if (gSystem->AccessPathName(runName.Data()) != true) { - return; - } - } - } else { - ext.ToUpper(); - if (tmpStr.EndsWith(ext.Data())) { // assume the upper-case extension is already part of the file name, therefore, do not append it - if (gSystem->AccessPathName(runName.Data())!=true) { // found - return; - } else { // assume an upper-case extension is part of the given file name but the real data file ends with a lower-case extension - ext.ToLower(); - runName = runName.Replace(static_cast(runName.Length()-ext.Length()), ext.Length(), ext); - if (gSystem->AccessPathName(runName.Data()) != true) { - return; - } - } - } else { - runName += TString(".") + ext; // test if the extension is given in upper-case letters and is not included in the file name - if (gSystem->AccessPathName(runName.Data())!=true) { // found - return; - } - } + } + + // test if the file exists with only upper-case letters + runName.ToUpper(); + if (gSystem->AccessPathName(runName.Data()) != true) { // found + return; + } + + // test if the file exists with only lower-case letters + runName.ToLower(); + if (gSystem->AccessPathName(runName.Data()) != true) { // found + return; + } + + // test if the file exists with the given run name but an only upper-case extension which is not included in the file name + runName = tmpStr; + tmpExt.ToUpper(); + runName += TString(".") + tmpExt; + if (gSystem->AccessPathName(runName.Data()) != true) { // found + return; + } + + // test if the file exists with the given run name but an only lower-case extension which is not included in the file name + tmpExt.ToLower(); + runName = runName.Replace(static_cast(runName.Length()-tmpExt.Length()), tmpExt.Length(), tmpExt); + if (gSystem->AccessPathName(runName.Data()) != true) { // found + return; + } + + runName = tmpStr; + + // the extension is already part of the file name, therefore, do not append it + if (runName.EndsWith(ext.Data(), TString::kIgnoreCase)) { + if (gSystem->AccessPathName(runName.Data()) != true) { // found + return; + } + + // assume some extension is part of the given file name but the real data file ends with an lower-case extension + tmpExt.ToLower(); + runName = runName.Replace(static_cast(runName.Length()-tmpExt.Length()), tmpExt.Length(), tmpExt); + if (gSystem->AccessPathName(runName.Data()) != true) { // found + return; + } + + // assume some extension is part of the given file name but the real data file ends with an upper-case extension + tmpExt.ToUpper(); + runName = runName.Replace(static_cast(runName.Length()-tmpExt.Length()), tmpExt.Length(), tmpExt); + if (gSystem->AccessPathName(runName.Data()) != true) { // found + return; + } + + // test if the file exists with only lower-case letters and the extension already included in the file name + runName.ToLower(); + if (gSystem->AccessPathName(runName.Data()) != true) { // found + return; + } + + // test if the file exists with only upper-case letters and the extension already included in the file name + runName.ToUpper(); + if (gSystem->AccessPathName(runName.Data()) != true) { // found + return; } } diff --git a/src/include/PRunDataHandler.h b/src/include/PRunDataHandler.h index ce690508e..049afaf7d 100644 --- a/src/include/PRunDataHandler.h +++ b/src/include/PRunDataHandler.h @@ -67,7 +67,7 @@ class PRunDataHandler virtual Bool_t ReadFilesMsr(); virtual Bool_t ReadWriteFilesList(); virtual Bool_t FileAlreadyRead(TString runName); - virtual void TestFileName(TString &runName, TString &ext); + virtual void TestFileName(TString &runName, const TString &ext); virtual Bool_t FileExistsCheck(PMsrRunBlock &runInfo, const UInt_t idx); virtual Bool_t FileExistsCheck(const Bool_t fileName, const Int_t idx); virtual Bool_t ReadRootFile(UInt_t tag);