fixed handling of new mlog file writer for musrt0

This commit is contained in:
nemu
2009-05-22 11:39:47 +00:00
parent c89026c018
commit 5d99f6cf8c
4 changed files with 43 additions and 24 deletions

View File

@ -325,7 +325,7 @@ cout << endl;
/** /**
* <p> * <p>
*/ */
int PMsrHandler::WriteMsrLogFile(TString ext) int PMsrHandler::WriteMsrLogFile(const bool messages)
{ {
const unsigned int prec = 6; // output precision for float/doubles const unsigned int prec = 6; // output precision for float/doubles
@ -350,14 +350,8 @@ int PMsrHandler::WriteMsrLogFile(TString ext)
// remove extension // remove extension
str = fFileName; str = fFileName;
str.Remove(idx+1); str.Remove(idx+1);
// add new extension
if (ext.Length() != 0)
str += ext;
else
str += "mlog"; str += "mlog";
ifstream fin; ifstream fin;
ofstream fout; ofstream fout;
@ -826,9 +820,11 @@ int PMsrHandler::WriteMsrLogFile(TString ext)
str += ", chisq/NDF = "; str += ", chisq/NDF = ";
str += fStatistic.fMin / fStatistic.fNdf; str += fStatistic.fMin / fStatistic.fNdf;
fout << str.Data() << endl; fout << str.Data() << endl;
if (messages)
cout << endl << str.Data() << endl; cout << endl << str.Data() << endl;
} else { } else {
fout << "*** FIT DID NOT CONVERGE ***" << endl; fout << "*** FIT DID NOT CONVERGE ***" << endl;
if (messages)
cout << endl << "*** FIT DID NOT CONVERGE ***" << endl; cout << endl << "*** FIT DID NOT CONVERGE ***" << endl;
} }
} else if (sstr.BeginsWith("maxLH")) { } else if (sstr.BeginsWith("maxLH")) {
@ -840,9 +836,11 @@ int PMsrHandler::WriteMsrLogFile(TString ext)
str += ", maxLH/NDF = "; str += ", maxLH/NDF = ";
str += fStatistic.fMin / fStatistic.fNdf; str += fStatistic.fMin / fStatistic.fNdf;
fout << str.Data() << endl; fout << str.Data() << endl;
if (messages)
cout << endl << str.Data() << endl; cout << endl << str.Data() << endl;
} else { } else {
fout << "*** FIT DID NOT CONVERGE ***" << endl; fout << "*** FIT DID NOT CONVERGE ***" << endl;
if (messages)
cout << endl << "*** FIT DID NOT CONVERGE ***" << endl; cout << endl << "*** FIT DID NOT CONVERGE ***" << endl;
} }
} else if (sstr.BeginsWith("*** FIT DID NOT CONVERGE ***")) { } else if (sstr.BeginsWith("*** FIT DID NOT CONVERGE ***")) {
@ -855,6 +853,7 @@ int PMsrHandler::WriteMsrLogFile(TString ext)
str += ", chisq/NDF = "; str += ", chisq/NDF = ";
str += fStatistic.fMin / fStatistic.fNdf; str += fStatistic.fMin / fStatistic.fNdf;
fout << str.Data() << endl; fout << str.Data() << endl;
if (messages)
cout << endl << str.Data() << endl; cout << endl << str.Data() << endl;
} else { // max. log. liklihood } else { // max. log. liklihood
str = " maxLH = "; str = " maxLH = ";
@ -864,10 +863,12 @@ int PMsrHandler::WriteMsrLogFile(TString ext)
str += ", maxLH/NDF = "; str += ", maxLH/NDF = ";
str += fStatistic.fMin / fStatistic.fNdf; str += fStatistic.fMin / fStatistic.fNdf;
fout << str.Data() << endl; fout << str.Data() << endl;
if (messages)
cout << endl << str.Data() << endl; cout << endl << str.Data() << endl;
} }
} else { } else {
fout << "*** FIT DID NOT CONVERGE ***" << endl; fout << "*** FIT DID NOT CONVERGE ***" << endl;
if (messages)
cout << endl << "*** FIT DID NOT CONVERGE ***" << endl; cout << endl << "*** FIT DID NOT CONVERGE ***" << endl;
} }
} else { } else {

View File

@ -51,7 +51,7 @@ class PMsrHandler
virtual ~PMsrHandler(); virtual ~PMsrHandler();
virtual int ReadMsrFile(); virtual int ReadMsrFile();
virtual int WriteMsrLogFile(TString ext=TString("")); virtual int WriteMsrLogFile(const bool messages = true);
virtual TString* GetMsrTitle() { return &fTitle; } virtual TString* GetMsrTitle() { return &fTitle; }
virtual PMsrParamList* GetMsrParamList() { return &fParam; } virtual PMsrParamList* GetMsrParamList() { return &fParam; }

View File

@ -490,7 +490,7 @@ int main(int argc, char *argv[])
bool keep_mn2_output = false; bool keep_mn2_output = false;
bool chisq_only = false; bool chisq_only = false;
TString dump(""); TString dump("");
char filename[256]; char filename[1024];
// check syntax // check syntax
if (argc < 2) { if (argc < 2) {

View File

@ -39,6 +39,7 @@ using namespace std;
#include <TApplication.h> #include <TApplication.h>
#include <TSAXParser.h> #include <TSAXParser.h>
#include <TROOT.h> #include <TROOT.h>
#include <TSystem.h>
#include "PMusr.h" #include "PMusr.h"
#include "PStartupHandler.h" #include "PStartupHandler.h"
@ -55,7 +56,7 @@ using namespace std;
void musrt0_syntax() void musrt0_syntax()
{ {
cout << endl << "usage: musrt0 <msr-file> | --version | --help"; cout << endl << "usage: musrt0 <msr-file> | --version | --help";
cout << endl << " <msr-file>: msr/mlog input file"; cout << endl << " <msr-file>: msr input file";
cout << endl << " 'musrt0 <msr-file>' will execute musrt0"; cout << endl << " 'musrt0 <msr-file>' will execute musrt0";
cout << endl << " 'musrt0' or 'musrt0 --help' will show this help"; cout << endl << " 'musrt0' or 'musrt0 --help' will show this help";
cout << endl << " 'musrt0 --version' will print the musrt0 version"; cout << endl << " 'musrt0 --version' will print the musrt0 version";
@ -135,6 +136,7 @@ int main(int argc, char *argv[])
bool show_syntax = false; bool show_syntax = false;
int status; int status;
bool success = true; bool success = true;
char filename[1024];
switch (argc) { switch (argc) {
case 1: case 1:
@ -149,9 +151,11 @@ int main(int argc, char *argv[])
show_syntax = true; show_syntax = true;
} else { } else {
// check if filename has extension msr or mlog // check if filename has extension msr or mlog
if (!strstr(argv[1], ".msr") && !strstr(argv[1], ".mlog")) { if (!strstr(argv[1], ".msr")) {
cout << endl << "**ERROR** " << argv[1] << " is not a msr/mlog-file!" << endl; cout << endl << "**ERROR** " << argv[1] << " is not a msr-file!" << endl;
show_syntax = true; show_syntax = true;
} else {
strncpy(filename, argv[1], sizeof(filename));
} }
} }
break; break;
@ -190,15 +194,15 @@ int main(int argc, char *argv[])
startupHandler->CheckLists(); startupHandler->CheckLists();
// read msr-file // read msr-file
PMsrHandler *msrHandler = new PMsrHandler(argv[1]); PMsrHandler *msrHandler = new PMsrHandler(filename);
status = msrHandler->ReadMsrFile(); status = msrHandler->ReadMsrFile();
if (status != PMUSR_SUCCESS) { if (status != PMUSR_SUCCESS) {
switch (status) { switch (status) {
case PMUSR_MSR_FILE_NOT_FOUND: case PMUSR_MSR_FILE_NOT_FOUND:
cout << endl << "**ERROR** couldn't find '" << argv[1] << "'" << endl << endl; cout << endl << "**ERROR** couldn't find '" << filename << "'" << endl << endl;
break; break;
case PMUSR_MSR_SYNTAX_ERROR: case PMUSR_MSR_SYNTAX_ERROR:
cout << endl << "**SYNTAX ERROR** in file " << argv[1] << ", full stop here." << endl << endl; cout << endl << "**SYNTAX ERROR** in file " << filename << ", full stop here." << endl << endl;
break; break;
default: default:
cout << endl << "**UNKNOWN ERROR** when trying to read the msr-file" << endl << endl; cout << endl << "**UNKNOWN ERROR** when trying to read the msr-file" << endl << endl;
@ -287,7 +291,21 @@ int main(int argc, char *argv[])
} }
// write msr-file // write msr-file
msrHandler->WriteMsrLogFile("msr"); msrHandler->WriteMsrLogFile(false);
// swap msr- and mlog-file
// copy msr-file -> __temp.msr
gSystem->CopyFile(filename, "__temp.msr", kTRUE);
// copy mlog-file -> msr-file
TString fln = TString(filename);
char ext[32];
strcpy(ext, ".mlog");
fln.ReplaceAll(".msr", 4, ext, strlen(ext));
gSystem->CopyFile(fln.Data(), filename, kTRUE);
// copy __temp.msr -> mlog-file
gSystem->CopyFile("__temp.msr", fln.Data(), kTRUE);
// delete __temp.msr
gSystem->Exec("rm __temp.msr");
// clean up // clean up
musrt0_cleanup(saxParser, startupHandler, msrHandler, dataHandler); musrt0_cleanup(saxParser, startupHandler, msrHandler, dataHandler);