diff --git a/src/addRun.cpp b/src/addRun.cpp index 5c5ada53..d56b65cf 100644 --- a/src/addRun.cpp +++ b/src/addRun.cpp @@ -797,5 +797,8 @@ int main(int argc, char *argv[]) } } + if (!isGood) + return PMUSR_DATA_FILE_READ_ERROR; + return PMUSR_SUCCESS; } diff --git a/src/any2many.cpp b/src/any2many.cpp index f3f78dfd..9b4cc874 100644 --- a/src/any2many.cpp +++ b/src/any2many.cpp @@ -533,6 +533,7 @@ int main(int argc, char *argv[]) bool success = dataHandler->IsAllDataAvailable(); if (!success) { std::cerr << std::endl << ">> any2many **ERROR** Couldn't read all data files, will quit ..." << std::endl; + return PMUSR_DATA_FILE_READ_ERROR; } return PMUSR_SUCCESS; diff --git a/src/dump_header.cpp b/src/dump_header.cpp index 1897c33d..d7285bab 100644 --- a/src/dump_header.cpp +++ b/src/dump_header.cpp @@ -1083,21 +1083,23 @@ int main(int argc, char *argv[]) boost::to_lower(fileFormat); + int status = 0; if (boost::iequals(fileFormat, "MusrRoot") || boost::iequals(fileFormat, "ROOT")) { - dump_header_root(pathFln, summary, counts); + status = dump_header_root(pathFln, summary, counts); } else if (boost::iequals(fileFormat, "NeXus")) { #ifdef PNEXUS_ENABLED - dump_header_nexus(pathFln, counts); + status = dump_header_nexus(pathFln, counts); #else std::cout << std::endl << "Sorry, NeXus is not enabled, hence I cannot help you." << std::endl; + status = 1; #endif } else if (boost::iequals(fileFormat, "PSI-BIN") || boost::iequals(fileFormat, "PSI-MDU")) { - dump_header_psi_bin(pathFln, fileFormat, counts); + status = dump_header_psi_bin(pathFln, fileFormat, counts); } else if (boost::iequals(fileFormat, "MUD")) { - dump_header_mud(pathFln, counts); + status = dump_header_mud(pathFln, counts); } else if (boost::iequals(fileFormat, "WKM")) { - dump_header_wkm(pathFln); + status = dump_header_wkm(pathFln); } - return 0; + return status; } diff --git a/src/msr2data.cpp b/src/msr2data.cpp index 6044e1e8..8408f2c1 100644 --- a/src/msr2data.cpp +++ b/src/msr2data.cpp @@ -1005,5 +1005,5 @@ int main(int argc, char *argv[]) std::cout << std::endl << ">> msr2data: done ..." << std::endl; - return 1; + return 0; } diff --git a/src/msr2msr.cpp b/src/msr2msr.cpp index 30b8eca9..14242bcc 100644 --- a/src/msr2msr.cpp +++ b/src/msr2msr.cpp @@ -676,12 +676,13 @@ int main(int argc, char *argv[]) // check if conversion seems to be OK if (!success) { + std::cerr << std::endl << "**ERROR** conversion of " << argv[1] << " failed, removing " << argv[2] << "." << std::endl; std::error_code ec; std::filesystem::remove_all(std::filesystem::path(argv[2]), ec); if (ec) { std::cerr << "**ERROR** couldn't remove " << argv[2] << ": " << ec.message() << std::endl; - return 0; } + return 1; } if (theoryTag != -1) { @@ -690,5 +691,5 @@ int main(int argc, char *argv[]) std::cout << std::endl << "done ..." << std::endl; - return 1; + return 0; } diff --git a/src/musrFT.cpp b/src/musrFT.cpp index 4934bcf3..db5ea13b 100644 --- a/src/musrFT.cpp +++ b/src/musrFT.cpp @@ -1449,6 +1449,8 @@ Int_t main(Int_t argc, Char_t *argv[]) std::unique_ptr fourierCanvas; + Int_t result = PMUSR_SUCCESS; + // if Fourier dumped if whished do it now if (startupParam.dumpFln.Length() > 0) { musrFT_dumpData(startupParam.dumpFln, fourier, startupParam.fourierRange[0], startupParam.fourierRange[1]); @@ -1495,6 +1497,7 @@ Int_t main(Int_t argc, Char_t *argv[]) std::cerr << std::endl << ">> musrFT **SEVERE ERROR** Couldn't invoke all necessary objects, will quit."; std::cerr << std::endl; ok = false; + result = PMUSR_MSR_RUN_ERROR; } else { // connect signal/slot TQObject::Connect("TCanvas", "Closed()", "PFourierCanvas", fourierCanvas.get(), "LastCanvasClosed()"); @@ -1524,5 +1527,5 @@ Int_t main(Int_t argc, Char_t *argv[]) app.Run(); } - return PMUSR_SUCCESS; + return result; } diff --git a/src/musrRootValidation.cpp b/src/musrRootValidation.cpp index 9185fe8a..0b6e78d4 100644 --- a/src/musrRootValidation.cpp +++ b/src/musrRootValidation.cpp @@ -680,10 +680,13 @@ int main(int argc, char *argv[]) return -1; } + bool valid = true; + if (is_valid(doc, argv[2])) { std::cout << std::endl << "xml-file " << argv[1] << " validates against xml-schema " << argv[2] << std::endl << std::endl; } else { std::cerr << std::endl << "**ERROR** xml-file " << argv[1] << " fails to validate against xml-schema " << argv[2] << std::endl << std::endl; + valid = false; } // do some further consistency checks @@ -692,6 +695,7 @@ int main(int argc, char *argv[]) std::cerr << std::endl << " with the header; found " << dump.GetNoOfDecayHistos() << " histograms in the DecayAnaModule,"; std::cerr << std::endl << " but in the header: No of Histos = " << dump.GetNoOfHistos() << "; # RedGreen Offsets = " << dump.GetNoOfRedGreenOffsets(); std::cerr << std::endl << std::endl; + valid = false; } if (dump.GetNoOfDecayHistos() != dump.GetNoOfDetectors()) { @@ -700,7 +704,11 @@ int main(int argc, char *argv[]) std::cerr << std::endl << " Found " << dump.GetNoOfDecayHistos() << " histograms in the DecayAnaModule,"; std::cerr << std::endl << " but " << dump.GetNoOfDetectors() << " number of Detector entries."; std::cerr << std::endl << std::endl; + valid = false; } + if (!valid) + return -1; + return 0; } diff --git a/src/musrfit.cpp b/src/musrfit.cpp index 61185d49..0eeca6aa 100644 --- a/src/musrfit.cpp +++ b/src/musrfit.cpp @@ -700,9 +700,12 @@ int main(int argc, char *argv[]) dataHandler->ReadData(); + int result = PMUSR_SUCCESS; + bool success = dataHandler->IsAllDataAvailable(); if (!success) { std::cerr << std::endl << ">> musrfit **ERROR** Couldn't read all data files, will quit ..." << std::endl; + result = PMUSR_DATA_FILE_READ_ERROR; } // if present, replace the run title of the with the run title of the FIRST run in the run block of the msr-file @@ -711,12 +714,14 @@ int main(int argc, char *argv[]) if (rl->empty()) { success = false; std::cerr << std::endl << ">> musrfit **ERROR** no run list present." << std::endl; + result = PMUSR_MSR_RUN_ERROR; } if (success) { TString *name = rl->at(0).GetRunName(); if (name == nullptr) { std::cerr << std::endl << ">> musrfit **ERROR** to obtain run list name." << std::endl; success = false; + result = PMUSR_MSR_RUN_ERROR; } PRawRunData *rrd = nullptr; if (success) { @@ -724,6 +729,7 @@ int main(int argc, char *argv[]) if (rrd == nullptr) { std::cerr << std::endl << ">> musrfit **ERROR** no raw run data avaliable." << std::endl; success = false; + result = PMUSR_MSR_RUN_ERROR; } } if (success) { @@ -736,13 +742,14 @@ int main(int argc, char *argv[]) // generate the necessary fit histogramms for the fit std::unique_ptr runListCollection; if (success) { - // feed all the necessary histogramms for the fit + // feed all the necessary histogramms for the fit runListCollection = std::make_unique(msrHandler.get(), dataHandler.get()); for (unsigned int i=0; i < msrHandler->GetMsrRunList()->size(); i++) { success = runListCollection->Add(i, kFit); if (!success) { std::cout << std::endl << ">> musrfit **ERROR** Couldn't handle run no " << i+1 << ": "; std::cout << (*msrHandler->GetMsrRunList())[i].GetRunName()->Data(); + result = PMUSR_MSR_RUN_ERROR; break; } } @@ -840,7 +847,7 @@ int main(int argc, char *argv[]) std::cout << std::endl << "done ..." << std::endl; - return PMUSR_SUCCESS; + return result; } // end --------------------------------------------------------------------- diff --git a/src/musrt0.cpp b/src/musrt0.cpp index 0f6a8909..192f30d0 100644 --- a/src/musrt0.cpp +++ b/src/musrt0.cpp @@ -312,6 +312,8 @@ Int_t main(Int_t argc, Char_t *argv[]) } msrHandler->CopyMsrStatisticBlock(); // just copy the statistics block since no fit is performed + Int_t result = PMUSR_SUCCESS; + // check if the fittype is not NonMusr PMsrRunList *runList = msrHandler->GetMsrRunList(); for (UInt_t i=0; isize(); i++) { @@ -322,6 +324,7 @@ Int_t main(Int_t argc, Char_t *argv[]) if (fitType == MSR_FITTYPE_NON_MUSR) { std::cout << std::endl << ">> musrt0 **ERROR** t0 setting for NonMusr fit type doesn't make any sense, will quit ..." << std::endl; success = false; + result = PMUSR_UNSUPPORTED_FEATURE; break; } } @@ -339,6 +342,7 @@ Int_t main(Int_t argc, Char_t *argv[]) success = dataHandler->IsAllDataAvailable(); if (!success) { std::cout << std::endl << ">> musrt0 **ERROR** Couldn't read all data files, will quit ..." << std::endl; + result = PMUSR_DATA_FILE_READ_ERROR; } } @@ -1160,6 +1164,9 @@ Int_t main(Int_t argc, Char_t *argv[]) } } + if (!success) + return result; + // write msr-file msrHandler->WriteMsrLogFile(false); diff --git a/src/musrview.cpp b/src/musrview.cpp index 2f629414..dd8a1ac1 100644 --- a/src/musrview.cpp +++ b/src/musrview.cpp @@ -369,6 +369,7 @@ int main(int argc, char *argv[]) if (show_errMsgBox) musrview_error_msg(errMsg.str()); ok = false; + result = PMUSR_MSR_RUN_ERROR; break; } if (!musrCanvas->IsValid()) { @@ -377,6 +378,7 @@ int main(int argc, char *argv[]) if (show_errMsgBox) musrview_error_msg(errMsg.str()); ok = false; + result = PMUSR_MSR_RUN_ERROR; delete musrCanvas; break; } @@ -393,6 +395,7 @@ int main(int argc, char *argv[]) if (!musrCanvas->IsValid()) { // something went wrong ok = false; + result = PMUSR_MSR_RUN_ERROR; break; } diff --git a/src/write_musrRoot_runHeader.cpp b/src/write_musrRoot_runHeader.cpp index 30992c0f..0e8cd154 100644 --- a/src/write_musrRoot_runHeader.cpp +++ b/src/write_musrRoot_runHeader.cpp @@ -245,8 +245,11 @@ int main(int argc, char *argv[]) // root file header related things TFolder *runHeader = new TFolder("RunHeader", "MusrRoot Run Header Info"); - if (header->FillFolder(runHeader)) { + bool success = header->FillFolder(runHeader); + if (success) { runHeader->Write(); + } else { + std::cerr << std::endl << "**ERROR** couldn't fill the MusrRoot run header folder." << std::endl; } f->Close(); @@ -255,5 +258,8 @@ int main(int argc, char *argv[]) delete f; delete header; + if (!success) + return -1; + return 0; }