diff --git a/ChangeLog b/ChangeLog index c02e69c1..6276e874 100644 --- a/ChangeLog +++ b/ChangeLog @@ -29,6 +29,8 @@ NEW 2012-05-12 added dump_header. This is a little program which dumps the NEW 2012-04-24 added a first version for negative muon fitting. At the same time substaintial bug fixing has been carried out (mainly the logx/logy handling). +FIXED 2013-01-21 fixed any2many bug concerning input file lists as described + in MUSR-247. Rewrote the template browser. FIXED 2012-12-18 fixed a shortcoming of the outdated TLemRunHeader class (see MUSR-246). FIXED 2012-11-19 fixes issue with too many t0's in the msr-file (see diff --git a/src/any2many.cpp b/src/any2many.cpp index 8b922cd2..16942245 100644 --- a/src/any2many.cpp +++ b/src/any2many.cpp @@ -87,7 +87,7 @@ void any2many_syntax() cout << endl << " -p : where is the output path for the"; cout << endl << " converted files. If nothing is given, the current directory"; cout << endl << " will be used, unless the option '-s' is used."; - cout << endl << " -y : if the option -y is used, here a year in the form 'yy' can"; + cout << endl << " -y : if the option -y is used, here a year in the form 'yy' or 'yyyy' can"; cout << endl << " be given, if this is the case, any automatic file name"; cout << endl << " generation needs a year, this number will be used."; cout << endl << " -s : with this option the output data file will be sent to the stdout."; @@ -214,6 +214,12 @@ int main(int argc, char *argv[]) if (!strcmp(argv[i], "-y")) { // handle year option if (i+1 < argc) { + // check that date if it is either of the form 'yy' or 'yyyy' + if ((strlen(argv[i+1]) != 2) && (strlen(argv[i+1]) != 4)) { + cerr << endl << ">> any2many **ERROR** found in option '-y' the argument '" << argv[i+1] << "' which is neither of the form 'yy' nor 'yyyy'." << endl; + show_syntax = true; + break; + } ival=0; status = sscanf(argv[i+1], "%d", &ival); if (status == 1) { diff --git a/src/classes/PRunDataHandler.cpp b/src/classes/PRunDataHandler.cpp index e5be2d5e..4743945c 100644 --- a/src/classes/PRunDataHandler.cpp +++ b/src/classes/PRunDataHandler.cpp @@ -257,7 +257,6 @@ void PRunDataHandler::ReadData() else fAllDataAvailable = true; } else if (!fRunPathName.IsWhitespace()) { // i.e. file name triggered - cerr << endl << "debug>> fFileFormat=\"" << fFileFormat << "\"" << endl; if ((fFileFormat == "MusrRoot") || (fFileFormat == "musrroot")) { fAllDataAvailable = ReadRootFile(); } else if ((fFileFormat == "NeXus") || (fFileFormat == "nexus")) { @@ -497,8 +496,6 @@ Bool_t PRunDataHandler::ReadWriteFilesList() success = ReadRootFile(); break; case A2M_PSIBIN: - success = ReadPsiBinFile(); - break; case A2M_PSIMDU: success = ReadPsiBinFile(); break; @@ -580,6 +577,9 @@ Bool_t PRunDataHandler::ReadWriteFilesList() cerr << endl << ">> PRunDataHandler::ReadWriteFilesList(): **ERROR** Couldn't write converted output file." << endl; return false; } + + // throw away the current data set + fData.clear(); } } @@ -600,8 +600,6 @@ Bool_t PRunDataHandler::ReadWriteFilesList() success = ReadRootFile(); break; case A2M_PSIBIN: - success = ReadPsiBinFile(); - break; case A2M_PSIMDU: success = ReadPsiBinFile(); break; @@ -1261,8 +1259,6 @@ Bool_t PRunDataHandler::FileExistsCheck(const TString fileName) fRunPathName = pathName; - cerr << endl << "debug-> fRunPathName=" << fRunPathName << endl; - return true; } @@ -1716,7 +1712,7 @@ Bool_t PRunDataHandler::ReadRootFile() else if (!prop.GetUnit().CompareTo("us") || !prop.GetUnit().CompareTo("microsec")) dval = prop.GetValue()*1.0e3; else - cerr << endl << "debug> Found unrecognized Time Resolution unit: " << prop.GetUnit(); + cerr << endl << ">> PRunDataHandler::ReadRootFile: **ERROR** Found unrecognized Time Resolution unit: " << prop.GetUnit() << endl; runData.SetTimeResolution(dval); } @@ -5957,87 +5953,77 @@ TString PRunDataHandler::GetFileName(const TString extension, Bool_t &ok) TString PRunDataHandler::FileNameFromTemplate(TString &fileNameTemplate, Int_t run, TString &year, Bool_t &ok) { TString result(""); - TString str = fileNameTemplate; - Int_t tag = 0; - Int_t yearStart = -1; - Int_t yearLength = 0; - Int_t runStart = -1; - Int_t runLength = 0; + TObjArray *tok=0; + TObjString *ostr; + TString str; - // find position and length of the year tag - Bool_t foundLeft = false, foundRight = false; - for (Int_t i=0; i> PRunDataHandler::FileNameFromTemplate: **ERROR** year needs to be of the format"; + cerr << endl << ">> 'yy' or 'yyyy', found " << year << endl; + return result; + } - if (str[i] == '[') { - foundLeft = true; - tag = 1; - continue; - } else if (str[i] == ']') { - foundRight = true; - tag = 0; - continue; - } + // make a short year version 'yy' and a long year version 'yyyy' + TString yearShort="", yearLong=""; + if (year.Length() == 2) { + yearShort = year; + yearLong = "20" ; + yearLong += year; + } else { + yearShort = year[2]; + yearShort += year[3]; + yearLong = year; + } - if (tag == 1) { - if (str[i] == 'y') { - if (yearStart == -1) - yearStart = i-1; - yearLength++; + // tokenize template string + tok = fileNameTemplate.Tokenize("[]"); + if (tok == 0) { + cerr << endl << ">> PRunDataHandler::FileNameFromTemplate: **ERROR** couldn't tokenize template!" << endl; + return result; + } + if (tok->GetEntries()==1) { + cerr << endl << ">> PRunDataHandler::FileNameFromTemplate: **WARNING** template without tags." << endl; + } + + // go through the tokens and generate the result string + for (Int_t i=0; iGetEntries(); i++) { + ostr = (TObjString*)tok->At(i); + str = ostr->GetString(); + + // check tokens + if (!str.CompareTo("yy", TString::kExact)) { // check for 'yy' + result += yearShort; + } else if (!str.CompareTo("yyyy", TString::kExact)) { // check for 'yyyy' + result += yearLong; + } else if (str.Contains("rr")) { // check for run + // make sure ONLY 'r' are present + Int_t idx; + for (idx=0; idx> PRunDataHandler::FileNameFromTemplate(): **ERROR** run template not ok." << endl; - ok = false; - } else { - TString runStr(""); - char fmt[128]; - sprintf(fmt , "%%0%dd", runLength); - runStr.Form(fmt, run); - runLength += 2; // including the [] - str.Replace(runStart, runLength, runStr); - ok = true; - } - } - - if (ok) - result = str; + // everything fine here + ok = true; return result; }