From e4f7e2283571905f0baf5f70906c087f398e4375 Mon Sep 17 00:00:00 2001 From: Andreas Suter Date: Wed, 17 May 2023 17:22:47 +0200 Subject: [PATCH] dump_header can dump #counts for each detector now also for mud and nexus. --- src/dump_header.cpp | 26 +++++++++++----- src/external/nexus/PNeXus.cpp | 56 ++++++++++++++++++++++++++++++++++- src/external/nexus/PNeXus.h | 4 ++- 3 files changed, 76 insertions(+), 10 deletions(-) diff --git a/src/dump_header.cpp b/src/dump_header.cpp index 50def83f..960c6a65 100644 --- a/src/dump_header.cpp +++ b/src/dump_header.cpp @@ -293,10 +293,11 @@ int dump_header_root(const std::string fileName, const bool summary, const bool *

dumps the header information of a NeXus file. * * @param fileName file name of the NeXus file. + * @param counts bool, if true dump detector counts * * @return 0 on success, 1 otherwise */ -int dump_header_nexus(const std::string fileName) { +int dump_header_nexus(const std::string fileName, const bool counts) { #ifdef PNEXUS_ENABLED PNeXus *nxs_file = new PNeXus(fileName.c_str()); @@ -309,7 +310,7 @@ int dump_header_nexus(const std::string fileName) { } if (nxs_file->IsValid(false)) { - nxs_file->Dump(); + nxs_file->Dump(counts); } else { std::cerr << std::endl; std::cerr << "**ERROR** found invalid NeXus file." << std::endl; @@ -395,10 +396,11 @@ std::vector dump_header_instrument_info(std::string fileName) * * @param fileName file name of the PSI-BIN * @param fileFormat either PSI-BIN or PSI-MDU + * @param counts bool, if true dump detector counts * * @return 0 on success, 1 otherwise */ -int dump_header_psi_bin(const std::string fileName, const std::string fileFormat) +int dump_header_psi_bin(const std::string fileName, const std::string fileFormat, const bool counts) { MuSR_td_PSI_bin psiBin; int status; @@ -490,7 +492,8 @@ int dump_header_psi_bin(const std::string fileName, const std::string fileFormat std::cout << std::endl << "Time Zero Bin : " << psiBin.GetT0Int(i); std::cout << std::endl << "First Good Bin : " << psiBin.GetFirstGoodInt(i); std::cout << std::endl << "Last Good Bin : " << psiBin.GetLastGoodInt(i); - std::cout << std::endl << "No of Events : " << psiBin.GetEventsHistoLong(i); + if (counts) + std::cout << std::endl << "No of Events : " << psiBin.GetEventsHistoLong(i); } std::cout << std::endl << "-------------------" << std::endl << std::endl; @@ -501,10 +504,11 @@ 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 + * @param counts bool, if true dump detector counts * * @return 0 on success, 1 otherwise */ -int dump_header_mud(const std::string fileName) +int dump_header_mud(const std::string fileName, const bool counts) { int fh; UINT32 type, val; @@ -669,6 +673,12 @@ int dump_header_mud(const std::string fileName) std::cout << std::endl << "Last Good Bin : " << val; else std::cout << std::endl << "Last Good Bin : ???"; + if (counts) { + success = MUD_getHistNumEvents( fh, i+1, &val ); + if (success) { + std::cout << std::endl << "#Events : " << val; + } + } } std::cout << std::endl << "-------------------" << std::endl << std::endl; @@ -986,14 +996,14 @@ int main(int argc, char *argv[]) dump_header_root(pathFln, summary, counts); } else if (boost::iequals(fileFormat, "NeXus")) { #ifdef PNEXUS_ENABLED - dump_header_nexus(pathFln); + dump_header_nexus(pathFln, counts); #else std::cout << std::endl << "Sorry, NeXus is not enabled, hence I cannot help you." << std::endl; #endif } else if (boost::iequals(fileFormat, "PSI-BIN") || boost::iequals(fileFormat, "PSI-MDU")) { - dump_header_psi_bin(pathFln, fileFormat); + dump_header_psi_bin(pathFln, fileFormat, counts); } else if (boost::iequals(fileFormat, "MUD")) { - dump_header_mud(pathFln); + dump_header_mud(pathFln, counts); } else if (boost::iequals(fileFormat, "WKM")) { dump_header_wkm(pathFln); } diff --git a/src/external/nexus/PNeXus.cpp b/src/external/nexus/PNeXus.cpp index 02dd709b..54c74e2c 100644 --- a/src/external/nexus/PNeXus.cpp +++ b/src/external/nexus/PNeXus.cpp @@ -635,6 +635,21 @@ unsigned int PNeXusData1::GetHistoLength(unsigned int histoNo) return fHisto[histoNo].size(); } +//------------------------------------------------------------------------------------------ +// GetHistoLength (public) +//------------------------------------------------------------------------------------------ +unsigned int PNeXusData1::GetHistoCounts(unsigned int histoNo) +{ + if (histoNo >= fHisto.size()) + return 0; + + unsigned int counts=0; + for (unsigned int i=0; iGet number of counts in a given histogram histoNo + * + * \param idx_p period index + * \param idx_s spectrum index + * + * \return the number of entries in the selected histogram histoNo, or 0 if the histoNo is out of scope. + */ +unsigned int PNeXusDetector2::GetHistoCounts(int idx_p, int idx_s) +{ + unsigned counts = 0; + + if (idx_p > 0) + if (idx_p > fNoOfPeriods) + return counts; + + if (idx_s > 0) + if (idx_s > fNoOfSpectra) + return counts; + + for (int i=0; iWrite the content of the NeXus file to stdout. Used for debugging purposes. * + * \param counts flag, if true, also dump the counts for all the histograms */ -void PNeXus::Dump() +void PNeXus::Dump(const bool counts) { double dval; std::string str; @@ -2259,6 +2305,8 @@ void PNeXus::Dump() std::cout << fNxEntry1->GetData()->GetHisto(i)->at(j) << ", "; } std::cout << "..."; + if (counts) + std::cout << " total no of entries: " << fNxEntry1->GetData()->GetHistoCounts(i); } } if (fNxEntry1->GetData()->GetAlpha()->size() == 0) { @@ -2408,6 +2456,8 @@ void PNeXus::Dump() std::cout << fNxEntry2->GetInstrument()->GetDetector()->GetHistoValue(i,j,k) << ", "; } std::cout << "..."; + if (counts) + std::cout << " total number of entries: " << fNxEntry2->GetInstrument()->GetDetector()->GetHistoCounts(i,j); } } } else { @@ -2421,6 +2471,8 @@ void PNeXus::Dump() std::cout << fNxEntry2->GetInstrument()->GetDetector()->GetHistoValue(0,j,k) << ", "; } std::cout << "..."; + if (counts) + std::cout << " total number of entries: " << fNxEntry2->GetInstrument()->GetDetector()->GetHistoCounts(0,j); } } else { // counts[ntc] std::cout << std::endl << " (#bins=" << fNxEntry2->GetInstrument()->GetDetector()->GetNoOfBins() << ")"; @@ -2431,6 +2483,8 @@ void PNeXus::Dump() std::cout << fNxEntry2->GetInstrument()->GetDetector()->GetHistoValue(0,0,k) << ", "; } std::cout << "..."; + if (counts) + std::cout << " total number of entries: " << fNxEntry2->GetInstrument()->GetDetector()->GetHistoCounts(0,0); } } std::cout << std::endl << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"; diff --git a/src/external/nexus/PNeXus.h b/src/external/nexus/PNeXus.h index 704a4864..6dc48083 100644 --- a/src/external/nexus/PNeXus.h +++ b/src/external/nexus/PNeXus.h @@ -254,6 +254,7 @@ class PNeXusData1 { virtual void GetHistoName(unsigned int idx, std::string &name, bool &ok); virtual unsigned int GetNoOfHistos() { return fHisto.size(); } virtual unsigned int GetHistoLength(unsigned int histoNo=0); + virtual unsigned int GetHistoCounts(unsigned int histoNo=0); virtual std::vector *GetHisto(unsigned int histoNo); virtual std::vector *GetGrouping() { return &fGrouping; } virtual std::vector *GetAlpha() { return &fAlpha; } @@ -399,6 +400,7 @@ class PNeXusDetector2 { virtual int GetNoOfPeriods() { return fNoOfPeriods; } virtual int GetNoOfSpectra() { return fNoOfSpectra; } virtual int GetNoOfBins() { return fNoOfBins; } + virtual unsigned int GetHistoCounts(int idx_p, int idx_s); virtual int GetHistoValue(int idx_p, int idx_s, int idx_b); virtual int* GetHistos() { return fHisto; } virtual unsigned int GetSpectrumIndexSize() { return fSpectrumIndex.size(); } @@ -586,7 +588,7 @@ class PNeXus { virtual void SetCreator(std::string str) { fCreator = str; } - virtual void Dump(); + virtual void Dump(const bool counts); private: bool fValid;