msr2data becomes more tolerant
Non-existing msr-files in the specified list of runs are now ignored as far as possible! Still a warning for each non-existing file will be issued! Before, encountering such a file led to the termination of the program. Also the writing of the empty lines at the end of the data-output-file should be fixed now in this case. It is needed to get a "correct db-file". Before, when the program has been aborted before the last run was processed, these empty lines had not been appended to the file.
This commit is contained in:
parent
8f5882897a
commit
decd363404
@ -1,6 +1,6 @@
|
||||
#---------------------------------------------------------------------
|
||||
# ChangeLog
|
||||
# AS, 2011/01/22
|
||||
# AS, 2011/01/29
|
||||
# $Id$
|
||||
#---------------------------------------------------------------------
|
||||
|
||||
@ -17,6 +17,7 @@ FIXED 2 little annoying problems: (i) now it is possible to zoom down to the sin
|
||||
(ii) when switching between data- and difference-view, the x-range doesn't change anymore.
|
||||
FIXED musrt0 crash for histogram number out of range (MUSR-157)
|
||||
FIXED fixes the inadequate attempt to use log max likelihood fit for asymmetry/non-muSR fit (MUSR-148)
|
||||
CHANGED the behavior of msr2data when non-existing files are encountered---as far as possible they should be ignored now
|
||||
CHANGED less strict handling of empty FUNCTION block
|
||||
CHANGED cosmetics in the y-labelling (MUSR-154)
|
||||
CHANGED maximum possible run number for the use in msr2data to numeric_limits<unsigned int>::max() (MUSR-155)
|
||||
|
@ -75,7 +75,7 @@ void writeValues(ofstream &outFile, const double &value, const unsigned int &wid
|
||||
*
|
||||
* \param ext extension/suffix of the msr-files to be processed
|
||||
*/
|
||||
PMsr2Data::PMsr2Data(const string &ext) : fFileExtension(ext), fRunListFile(false), fNumGlobalParam(0), fNumSpecParam(0), fNumTempRunBlocks(0), fRunNumberDigits(4)
|
||||
PMsr2Data::PMsr2Data(const string &ext) : fFileExtension(ext), fRunListFile(false), fNumGlobalParam(0), fNumSpecParam(0), fNumTempRunBlocks(0), fRunNumberDigits(4), fHeaderWritten(false)
|
||||
{
|
||||
fRunVector.clear();
|
||||
fRunVectorIter = fRunVector.end();
|
||||
@ -122,6 +122,8 @@ PMsr2Data::~PMsr2Data()
|
||||
//-------------------------------------------------------------
|
||||
/**
|
||||
* <p> Determines the number of digits used for the run number in the data file name from the first msr-file that is processed
|
||||
* If the specified run number is the first one of the list of runs and it cannot be opened, then the rest of the given runs is checked
|
||||
* until an existing msr-file is found
|
||||
*
|
||||
* <p><b>return:</b>
|
||||
* - 0 if the number has been determined and set successfully
|
||||
@ -129,7 +131,7 @@ PMsr2Data::~PMsr2Data()
|
||||
* - -2 if the msr-file-number does not match the data-file-number
|
||||
* - -3 if the msr-file does not contain a RUN block
|
||||
*
|
||||
* \param runNo run number of an existing msr-file
|
||||
* \param runNo run number of an msr-file
|
||||
* \param normalMode false for global mode
|
||||
*
|
||||
*/
|
||||
@ -139,6 +141,7 @@ int PMsr2Data::DetermineRunNumberDigits(unsigned int runNo, bool normalMode) con
|
||||
strInfile << runNo << fFileExtension << ".msr";
|
||||
ifstream *in = new ifstream(strInfile.str().c_str());
|
||||
if (!in->is_open()) {
|
||||
delete in;
|
||||
if (!normalMode && (runNo == *fRunVectorIter)) {
|
||||
string fileNameCopy(strInfile.str());
|
||||
strInfile.clear();
|
||||
@ -146,12 +149,21 @@ int PMsr2Data::DetermineRunNumberDigits(unsigned int runNo, bool normalMode) con
|
||||
strInfile << runNo << "+global" << fFileExtension << ".msr";
|
||||
in = new ifstream(strInfile.str().c_str());
|
||||
if (!in->is_open()) {
|
||||
cerr << endl << ">> msr2data: **ERROR** Neither the file " << fileNameCopy << " nor the file " << strInfile.str() << " cannot be opened! Please check!";
|
||||
cerr << endl << ">> msr2data: **ERROR** Neither the file " << fileNameCopy << " nor the file " << strInfile.str() << " can be opened! Please check!";
|
||||
cerr << endl;
|
||||
delete in;
|
||||
return -1;
|
||||
}
|
||||
} else if (runNo == *fRunVectorIter) { // the first run of the runlist was given - if it did not exist, try the rest of the runlist
|
||||
if (++fRunVectorIter != fRunVector.end()) {
|
||||
return DetermineRunNumberDigits(*fRunVectorIter, true);
|
||||
} else {
|
||||
cerr << endl << ">> msr2data: **ERROR** None of the given msr-files can be opened! Please check!";
|
||||
cerr << endl;
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
cerr << endl << ">> msr2data: **ERROR** The file " << strInfile.str() << " cannot be opened! Please check!";
|
||||
cerr << endl << ">> msr2data: **ERROR** The given template " << strInfile.str() << " cannot be opened! Please check!";
|
||||
cerr << endl;
|
||||
return -1;
|
||||
}
|
||||
@ -182,7 +194,7 @@ int PMsr2Data::DetermineRunNumberDigits(unsigned int runNo, bool normalMode) con
|
||||
in->close();
|
||||
delete in;
|
||||
in = 0;
|
||||
//cout << endl << "Number of digits: " << fRunNumberDigits << endl;
|
||||
fRunVectorIter = fRunVector.begin(); // set back the runlist-iterator which might have changed during the search for the correct file
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -190,7 +202,7 @@ int PMsr2Data::DetermineRunNumberDigits(unsigned int runNo, bool normalMode) con
|
||||
cerr << endl << ">> msr2data: **ERROR** The first processed run file number does not match the \"file index\"!";
|
||||
cerr << endl << ">> msr2data: **ERROR** The number of digits to be used for formatting the run numbers cannot be determined!";
|
||||
cerr << endl << ">> msr2data: **ERROR** Please check the first msr-file that should be processed;";
|
||||
cerr << endl << ">> msr2data: **ERROR** this is either some template or the first file from the run list.";
|
||||
cerr << endl << ">> msr2data: **ERROR** this is either some template or the first existing file from the run list.";
|
||||
cerr << endl;
|
||||
in->close();
|
||||
delete in;
|
||||
@ -1654,7 +1666,7 @@ int PMsr2Data::WriteOutput(const string &outfile, bool db, bool withHeader, bool
|
||||
PMsrParamList *msrParamList(fMsrHandler->GetMsrParamList());
|
||||
PMsrRunList *msrRunList(fMsrHandler->GetMsrRunList());
|
||||
|
||||
if (global && fRunVectorIter == fRunVector.begin()) {
|
||||
if (global && (fRunVectorIter == fRunVector.begin())) {
|
||||
// since the DB-ASCII-output is in principle independent of the original msr-file-generation
|
||||
// the number of global and run specific parameters as well as the number of RUN blocks per run number have to be determined again
|
||||
// in case no msr-file has been created before.
|
||||
@ -1826,7 +1838,7 @@ int PMsr2Data::WriteOutput(const string &outfile, bool db, bool withHeader, bool
|
||||
value = rawRunData->GetField();
|
||||
if (value != PMUSR_UNDEFINED) {
|
||||
dataParamNames.push_back("dataB");
|
||||
dataParamLabels.push_back("mu0 H (G)");
|
||||
dataParamLabels.push_back("B (G)");
|
||||
dataParam.push_back(value);
|
||||
}
|
||||
|
||||
@ -1939,7 +1951,7 @@ int PMsr2Data::WriteOutput(const string &outfile, bool db, bool withHeader, bool
|
||||
|
||||
if (db) {
|
||||
|
||||
if (withHeader && (fRunVectorIter == fRunVector.begin())) {
|
||||
if (withHeader && !fHeaderWritten) {
|
||||
outFile << "TITLE" << endl;
|
||||
outFile << ">>>Put your title here<<<" << endl << endl;
|
||||
outFile << "Abstract" << endl;
|
||||
@ -2047,6 +2059,8 @@ int PMsr2Data::WriteOutput(const string &outfile, bool db, bool withHeader, bool
|
||||
outFile << " " << "RUN" << endl;
|
||||
|
||||
outFile << "\\-e" << endl;
|
||||
|
||||
fHeaderWritten = true;
|
||||
}
|
||||
|
||||
if (fDataHandler) {
|
||||
@ -2163,7 +2177,7 @@ int PMsr2Data::WriteOutput(const string &outfile, bool db, bool withHeader, bool
|
||||
else
|
||||
maxlength += 1; // maximum length of parameter names + ' '
|
||||
|
||||
if (withHeader && (fRunVectorIter == fRunVector.begin())) {
|
||||
if (withHeader && !fHeaderWritten) {
|
||||
|
||||
if (fDataHandler) {
|
||||
for (unsigned int i(0); i < dataParamNames.size(); ++i) {
|
||||
@ -2226,6 +2240,8 @@ int PMsr2Data::WriteOutput(const string &outfile, bool db, bool withHeader, bool
|
||||
outFile << setw(maxlength) << left << "maxLHred";
|
||||
|
||||
outFile << setw(maxlength) << left << "RUN" << endl;
|
||||
|
||||
fHeaderWritten = true;
|
||||
}
|
||||
|
||||
if (fDataHandler) {
|
||||
@ -2302,8 +2318,6 @@ int PMsr2Data::WriteOutput(const string &outfile, bool db, bool withHeader, bool
|
||||
|
||||
fRunVectorIter++;
|
||||
|
||||
if (fRunVectorIter == fRunVector.end())
|
||||
outFile << endl << endl;
|
||||
outFile.close();
|
||||
|
||||
if (!global || (fRunVectorIter == fRunVector.end())) {
|
||||
|
@ -93,6 +93,7 @@ class PMsr2Data
|
||||
mutable unsigned int fNumSpecParam;
|
||||
mutable unsigned int fNumTempRunBlocks;
|
||||
mutable unsigned int fRunNumberDigits;
|
||||
mutable bool fHeaderWritten;
|
||||
};
|
||||
|
||||
|
||||
|
@ -39,6 +39,7 @@
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <cstdlib>
|
||||
#include <limits>
|
||||
using namespace std;
|
||||
@ -48,6 +49,7 @@ using namespace std;
|
||||
using namespace boost::algorithm;
|
||||
|
||||
#include <boost/lexical_cast.hpp> // for atoi-replacement
|
||||
// #include <boost/filesystem.hpp> // for a clean way to check if a file exists
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
@ -680,9 +682,11 @@ int main(int argc, char *argv[])
|
||||
// Processing the run list, do the fitting and write the data to the DB or data output file
|
||||
bool firstrun(true);
|
||||
unsigned int oldtemp(0); // should be accessed only when updated before...
|
||||
ostringstream strInfile;
|
||||
|
||||
while (msr2dataHandler.GetPresentRun()) {
|
||||
ostringstream strInfile;
|
||||
strInfile.clear();
|
||||
strInfile.str("");
|
||||
strInfile << msr2dataHandler.GetPresentRun() << msrExtension << ".msr";
|
||||
|
||||
// if fitting should be done, prepare a new input file
|
||||
@ -728,8 +732,14 @@ int main(int argc, char *argv[])
|
||||
if (realOutput) {
|
||||
status = msr2dataHandler.ReadMsrFile(strInfile.str());
|
||||
if (status != PMUSR_SUCCESS) {
|
||||
arg.clear();
|
||||
return status;
|
||||
// if the msr-file cannot be read, write no output but proceed to the next run
|
||||
status = msr2dataHandler.WriteOutput("none", db, writeHeader);
|
||||
if (status != PMUSR_SUCCESS) {
|
||||
arg.clear();
|
||||
return status;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -746,6 +756,29 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure that the empty line at the end of the output file gets written
|
||||
// This is needed to create a "valid db-file", however, we do it for all output files
|
||||
// Unfortunately, this can be done in a coherent way only on that level
|
||||
// Unfortunately, there are also problems with boost::filesystem::exists(outputFile)
|
||||
// Therefore, first try to open the file for reading and if this works, write to it - not clean but it works
|
||||
if(realOutput) {
|
||||
ifstream fileOutputCheck(outputFile.c_str());
|
||||
if (fileOutputCheck.is_open()) {
|
||||
fileOutputCheck.close();
|
||||
ofstream fileOutput(outputFile.c_str(), ios::app);
|
||||
if (fileOutput.is_open()) {
|
||||
fileOutput << endl << endl;
|
||||
fileOutput.close();
|
||||
} else {
|
||||
cerr << endl << ">> msr2data: **ERROR** The output file " << outputFile << " cannot be opened! Please check!";
|
||||
cerr << endl;
|
||||
}
|
||||
} else {
|
||||
cerr << endl << ">> msr2data: **WARNING** No output has been written to the file " << outputFile << "!";
|
||||
cerr << endl << ">> msr2data: **WARNING** Please check the range of runs and the specified options!" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
if (!arg.empty()) {
|
||||
cout << endl << ">> msr2data: **INFO** The following command line arguments have been specified but not been used: " << endl;
|
||||
cout << ">> msr2data: **INFO**";
|
||||
|
Loading…
x
Reference in New Issue
Block a user