diff --git a/src/dump_header.cpp b/src/dump_header.cpp index 98697e99..b75477e9 100644 --- a/src/dump_header.cpp +++ b/src/dump_header.cpp @@ -8,7 +8,7 @@ ***************************************************************************/ /*************************************************************************** - * Copyright (C) 2007-2021 by Andreas Suter * + * Copyright (C) 2007-2022 by Andreas Suter * * andreas.suter@psi.ch * * * * This program is free software; you can redistribute it and/or modify * @@ -57,6 +57,7 @@ #include "git-revision.h" #endif +#include "PFindRun.h" #include "PStartupHandler.h" #include "TMusrRunHeader.h" #include "TLemRunHeader.h" @@ -72,7 +73,7 @@ //------------------------------------------------------------------------ /** - * + *
dump help to stdout.
*/
void dump_header_syntax()
{
@@ -94,9 +95,8 @@ void dump_header_syntax()
std::cout << std::endl << " year is used. If a file name is given, this option has no effect.";
std::cout << std::endl << " -s, --summary : this option is used for LE-uSR data sets only. It will, additionally";
std::cout << std::endl << " to the header information, print the summary file content.";
- std::cout << std::endl << " --psi-bulk dumps header of a ROOT file.
*
+ * @param fileName file name of the ROOT file
+ * @param summary bool, if true dump the summary
+ *
+ * @return 0 on success, otherwise 1.
*/
-int dump_header_root(const std::string fileName, const std::string fileFormat, const bool summary)
+int dump_header_root(const std::string fileName, const bool summary)
{
TFile f(fileName.c_str());
if (f.IsZombie()) {
- return false;
+ std::cerr << std::endl;
+ std::cerr << "**ERROR** couldn't invoke ROOT/MusrRoot file object." << std::endl;
+ std::cerr << std::endl;
+ return 1;
}
UInt_t fileType = DH_MUSR_ROOT;
@@ -142,7 +150,7 @@ int dump_header_root(const std::string fileName, const std::string fileFormat, c
}
std::cout << std::endl << "-------------------";
- std::cout << std::endl << "fileName = " << fileName << ", fileFormat = " << fileFormat;
+ std::cout << std::endl << "fileName = " << fileName << ", fileFormat = ROOT (PSI LEM).";
std::cout << std::endl << "-------------------";
std::cout << std::endl << "Run Title : " << runHeader->GetRunTitle().GetString().Data();
std::cout << std::endl << "Run Number : " << runHeader->GetRunNumber();
@@ -231,15 +239,31 @@ int dump_header_root(const std::string fileName, const std::string fileFormat, c
//------------------------------------------------------------------------
/**
+ * dumps the header information of a NeXus file.
*
+ * @param fileName file name of the NeXus file.
+ *
+ * @return 0 on success, 1 otherwise
*/
int dump_header_nexus(const std::string fileName) {
#ifdef PNEXUS_ENABLED
PNeXus *nxs_file = new PNeXus(fileName.c_str());
+ if (nxs_file == nullptr) {
+ std::cerr << std::endl;
+ std::cerr << "**ERROR** couldn't invoke NeXus file object." << std::endl;
+ std::cerr << std::endl;
+ return 1;
+ }
+
if (nxs_file->IsValid(false)) {
nxs_file->Dump();
+ } else {
+ std::cerr << std::endl;
+ std::cerr << "**ERROR** found invalid NeXus file." << std::endl;
+ std::cerr << std::endl;
+ return 1;
}
if (nxs_file)
@@ -253,7 +277,11 @@ int dump_header_nexus(const std::string fileName) {
//------------------------------------------------------------------------
/**
+ * dump the instrument specific info for the PSI-BIN format.
*
+ * @param fileName file name of the PSI-BIN.
+ *
+ * @return string vector with the instrument specific info.
*/
std::vector dump the header information of a PSI-BIN file.
*
+ * @param fileName file name of the PSI-BIN
+ * @param fileFormat either PSI-BIN or PSI-MDU
+ *
+ * @return 0 on success, 1 otherwise
*/
int dump_header_psi_bin(const std::string fileName, const std::string fileFormat)
{
@@ -415,9 +448,12 @@ int dump_header_psi_bin(const std::string fileName, const std::string fileFormat
//------------------------------------------------------------------------
/**
+ * dump the header information of a MUD file.
+ * @param fileName file name of the MUD file
*
+ * @return 0 on success, 1 otherwise
*/
-int dump_header_mud(const std::string fileName, const std::string fileFormat)
+int dump_header_mud(const std::string fileName)
{
int fh;
UINT32 type, val;
@@ -433,7 +469,7 @@ int dump_header_mud(const std::string fileName, const std::string fileFormat)
}
std::cout << std::endl << "-------------------";
- std::cout << std::endl << "fileName = " << fileName << ", fileFormat = " << fileFormat;
+ std::cout << std::endl << "fileName = " << fileName << ", fileFormat = MUD";
std::cout << std::endl << "-------------------";
// run title
success = MUD_getTitle( fh, str, sizeof(str) );
@@ -593,9 +629,12 @@ int dump_header_mud(const std::string fileName, const std::string fileFormat)
//------------------------------------------------------------------------
/**
+ * dump the header information of a WKM file.
+ * @param fileName file name of the WKM file.
*
+ * @return 0 on success, 1 otherwise
*/
-int dump_header_wkm(const std::string fileName, const std::string fileFormat)
+int dump_header_wkm(const std::string fileName)
{
std::ifstream fin(fileName.c_str(), std::ifstream::in);
if (!fin.is_open()) {
@@ -603,7 +642,7 @@ int dump_header_wkm(const std::string fileName, const std::string fileFormat)
return 1;
}
std::cout << std::endl << "-------------------";
- std::cout << std::endl << "fileName = " << fileName << ", fileFormat = " << fileFormat;
+ std::cout << std::endl << "fileName = " << fileName << ", fileFormat = WKM";
std::cout << std::endl << "-------------------";
char header[256];
while (fin.good()) {
@@ -620,9 +659,11 @@ int dump_header_wkm(const std::string fileName, const std::string fileFormat)
//------------------------------------------------------------------------
/**
- * @brief is_number
- * @param s
- * @return
+ * checks if a string is a number
+ *
+ * @param s number string to be checked
+ *
+ * @return true if 's' is a number, false otherwise
*/
bool dump_is_number(const char *s)
{
@@ -642,8 +683,9 @@ bool dump_is_number(const char *s)
//------------------------------------------------------------------------
/**
- * @brief dump_current_year
- * @return
+ * reads the current year from the system and converts it to a string.
+ *
+ * @return the current year as a string.
*/
int dump_current_year()
{
@@ -660,109 +702,13 @@ int dump_current_year()
//------------------------------------------------------------------------
/**
- * @brief dump_create_fln
- * @param runNo
- * @param year
- * @param fileFormat
- * @return
- */
-std::string dump_create_fln(std::string runNo, std::string year, std::string fileFormat, bool pta, std::string instrument)
-{
- std::string result = "??";
- int yearShort=0;
- int iRunNo=0;
-
- if (fileFormat.empty())
- fileFormat = "MusrRoot";
-
- // make sure that a 'legal' file format has been found
- if (!boost::iequals(fileFormat, "MusrRoot") &&
- !boost::iequals(fileFormat, "NeXus") &&
- !boost::iequals(fileFormat, "ROOT") &&
- !boost::iequals(fileFormat, "PSI-BIN") &&
- !boost::iequals(fileFormat, "PSI-MDU") &&
- !boost::iequals(fileFormat, "MDU") &&
- !boost::iequals(fileFormat, "WKM")) {
- return result;
- }
-
- // if year is an empty string get the current year
- int yy=-1;
- std::stringstream ss;
- if (year.empty()) {
- yy = dump_current_year();
- ss << yy;
- year = ss.str();
- }
- yy = atoi(year.c_str());
- if (yy > 2000)
- yearShort = yy - 2000;
- else
- yearShort = yy - 1900;
-
- iRunNo = atoi(runNo.c_str());
-
- char fln[64];
- char ptatdc[8];
- memset(ptatdc, '\0', sizeof(ptatdc));
- if (pta)
- strcpy(ptatdc, "pta");
- else
- strcpy(ptatdc, "tdc");
- if (boost::iequals(fileFormat, "MusrRoot") || boost::iequals(fileFormat, "ROOT")) {
- if (instrument == "") // i.e. LEM
- snprintf(fln, sizeof(fln), "lem%02d_his_%04d.root", yearShort, iRunNo);
- else
- snprintf(fln, sizeof(fln), "deltat_%s_%s_%s_%04d.root", ptatdc, instrument.c_str(), year.c_str(), iRunNo);
- } else if (boost::iequals(fileFormat, "NeXus")) {
- snprintf(fln, sizeof(fln), "%s.nxs", runNo.c_str());
- } else if (boost::iequals(fileFormat, "PSI-BIN")) {
- snprintf(fln, sizeof(fln), "deltat_%s_%s_%04d.bin", ptatdc, instrument.c_str(), iRunNo);
- } else if (boost::iequals(fileFormat, "PSI-MDU")) {
- snprintf(fln, sizeof(fln), "%s_%s_%s_%05d.mdu", ptatdc, instrument.c_str(), year.c_str(), iRunNo);
- } else if (boost::iequals(fileFormat, "MUD")) {
- snprintf(fln, sizeof(fln), "%06d.msr", iRunNo);
- } else if (boost::iequals(fileFormat, "WKM")) {
-
- }
- result = fln;
-
- return result;
-}
-
-//------------------------------------------------------------------------
-/**
- * @brief dump_file_exists
- * @param pathName
- * @return
- */
-bool dump_file_exists(const std::string pathName)
-{
- bool exists = true;
-
- int res = access(pathName.c_str(), R_OK);
- if (res < 0) {
- if (errno == ENOENT) {
- // file does not exist
- exists = false;
- } else if (errno == EACCES) {
- // file exists but is not readable
- exists = false;
- } else {
- // FAIL
- exists = false;
- }
- }
-
- return exists;
-}
-
-//------------------------------------------------------------------------
-/**
- * @brief main
- * @param argc
- * @param argv
- * @return
+ * dump_header allows to dump the header (meta) information for various
+ * muSR specific file formats.
+ *
+ * @param argc argument count
+ * @param argv argument list
+ *
+ * @return 0 on success, 1 otherwise
*/
int main(int argc, char *argv[])
{
@@ -775,8 +721,7 @@ int main(int argc, char *argv[])
std::string fileName("");
std::string fileFormat("");
std::string year("");
- bool pta(false);
- std::string instrument("");
+ std::string instrument("lem");
bool summary(false);
for (int i=1; i