Skip to content

Commit 1f2a005

Browse files
authored
Merge pull request #38850 from mantidproject/38840-ornl-next
Simplify NeXus logging -- `ornl-next`
2 parents 2c6560a + f67942d commit 1f2a005

File tree

9 files changed

+13
-214
lines changed

9 files changed

+13
-214
lines changed

Framework/API/inc/MantidAPI/FrameworkManager.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ class MANTID_API_DLL FrameworkManagerImpl {
7676
void loadPluginsUsingKey(const std::string &locationKey, const std::string &excludeKey);
7777
/// Set up the global locale
7878
void setGlobalNumericLocaleToC();
79-
/// Silence NeXus output
80-
void disableNexusOutput();
8179
/// Starts asynchronous tasks that are done as part of Start-up
8280
void asynchronousStartupTasks();
8381
/// Setup Usage Reporting if enabled

Framework/API/src/FrameworkManager.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "MantidKernel/MultiThreaded.h"
1717
#include "MantidKernel/PropertyManagerDataService.h"
1818
#include "MantidKernel/UsageService.h"
19-
#include "MantidNexusCpp/NeXusFile.hpp"
2019

2120
#include <boost/algorithm/string/classification.hpp>
2221
#include <boost/algorithm/string/split.hpp>
@@ -64,15 +63,6 @@ const char *PLUGINS_DIR_KEY = "framework.plugins.directory";
6463
const char *PLUGINS_EXCLUDE_KEY = "framework.plugins.exclude";
6564
} // namespace
6665

67-
/** This is a function called every time NeXuS raises an error.
68-
* This swallows the errors and outputs nothing.
69-
*/
70-
// Prevent clang-tidy trying to change the signature for ext. interface
71-
// NOLINTNEXTLINE(readability-non-const-parameter)
72-
void NexusErrorFunction(void *, const char *) {
73-
// Do nothing.
74-
}
75-
7666
#ifdef __linux__
7767
/**
7868
* Print current backtrace to the given stream
@@ -133,7 +123,6 @@ FrameworkManagerImpl::FrameworkManagerImpl() {
133123
ConfigService::Instance();
134124
g_log.notice() << Mantid::welcomeMessage() << '\n';
135125
loadPlugins();
136-
disableNexusOutput();
137126
setNumOMPThreadsToConfigValue();
138127

139128
g_log.debug() << "FrameworkManager created.\n";
@@ -339,9 +328,6 @@ void FrameworkManagerImpl::setGlobalNumericLocaleToC() {
339328
setlocale(LC_NUMERIC, "C");
340329
}
341330

342-
/// Silence NeXus output
343-
void FrameworkManagerImpl::disableNexusOutput() { NXMSetError(nullptr, NexusErrorFunction); }
344-
345331
/// Starts asynchronous tasks that are done as part of Start-up.
346332
void FrameworkManagerImpl::asynchronousStartupTasks() {
347333
auto instrumentUpdates = Kernel::ConfigService::Instance().getValue<bool>("UpdateInstrumentDefinitions.OnStartup");

Framework/DataHandling/src/SaveNexusProcessed.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ void SaveNexusProcessed::getWSIndexList(std::vector<int> &indices, const MatrixW
204204
void SaveNexusProcessed::doExec(const Workspace_sptr &inputWorkspace,
205205
std::shared_ptr<Mantid::NeXus::NexusFileIO> &nexusFile, const bool keepFile,
206206
optional_size_t entryNumber) {
207-
// TODO: Remove?
208-
NXMEnableErrorReporting();
207+
//
208+
//
209209

210210
// Retrieve the filename from the properties
211211
const std::string filename = getPropertyValue("Filename");

Framework/LegacyNexus/inc/MantidLegacyNexus/napi.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -770,12 +770,6 @@ MANTID_LEGACYNEXUS_DLL void NXMSetError(void *pData, ErrFunc newErr);
770770
*/
771771
MANTID_LEGACYNEXUS_DLL void NXMSetTError(void *pData, ErrFunc newErr);
772772

773-
/**
774-
* Retrieve the current error display function
775-
* \return The current error display function.
776-
*/
777-
MANTID_LEGACYNEXUS_DLL ErrFunc NXMGetError();
778-
779773
/**
780774
* Suppress error reports from the NeXus-API
781775
*/

Framework/LegacyNexus/src/napi.cpp

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -238,18 +238,20 @@ NXstatus NXsetcache(long newVal) {
238238
}
239239

240240
/*-------------------------------------------------------------------------*/
241-
static void NXNXNXReportError(void *pData, const char *string) {
241+
static void NXNXNoReport(void *pData, const char *string) {
242+
// do nothing but declare the variables unused
242243
UNUSED_ARG(pData);
243-
fprintf(stderr, "%s \n", string);
244+
UNUSED_ARG(string);
244245
}
245246

246247
/*---------------------------------------------------------------------*/
247248

248249
static void *NXEHpData = NULL;
249-
static void (*NXEHIReportError)(void *pData, const char *string) = NXNXNXReportError;
250+
// default to no logging
251+
static ErrFunc NXEHIReportError = NXNXNoReport;
250252
#ifdef HAVE_TLS
251253
static THREAD_LOCAL void *NXEHpTData = NULL;
252-
static THREAD_LOCAL void (*NXEHIReportTError)(void *pData, const char *string) = NULL;
254+
static THREAD_LOCAL ErrFunc NXEHIReportTError = NULL;
253255
#endif
254256

255257
void NXIReportError(void *pData, const char *string) {
@@ -273,13 +275,13 @@ void NXReportError(const char *string) {
273275
}
274276

275277
/*---------------------------------------------------------------------*/
276-
extern void NXMSetError(void *pData, void (*NewError)(void *pD, const char *text)) {
278+
extern void NXMSetError(void *pData, ErrFunc NewError) {
277279
NXEHpData = pData;
278280
NXEHIReportError = NewError;
279281
}
280282

281283
/*----------------------------------------------------------------------*/
282-
extern void NXMSetTError(void *pData, void (*NewError)(void *pD, const char *text)) {
284+
extern void NXMSetTError(void *pData, ErrFunc NewError) {
283285
#ifdef HAVE_TLS
284286
NXEHpTData = pData;
285287
NXEHIReportTError = NewError;
@@ -288,26 +290,9 @@ extern void NXMSetTError(void *pData, void (*NewError)(void *pD, const char *tex
288290
#endif
289291
}
290292

291-
/*----------------------------------------------------------------------*/
292-
extern ErrFunc NXMGetError() {
293-
#ifdef HAVE_TLS
294-
if (NXEHIReportTError) {
295-
return NXEHIReportTError;
296-
}
297-
#endif
298-
return NXEHIReportError;
299-
}
300-
301-
/*----------------------------------------------------------------------*/
302-
static void NXNXNoReport(void *pData, const char *string) {
303-
// do nothing but declare the variables unused
304-
(void)pData;
305-
(void)string;
306-
}
307-
308293
/*----------------------------------------------------------------------*/
309294

310-
static ErrFunc last_global_errfunc = NXNXNXReportError;
295+
static ErrFunc last_global_errfunc = NXEHIReportError;
311296
#ifdef HAVE_TLS
312297
static THREAD_LOCAL ErrFunc last_thread_errfunc = NULL;
313298
#endif

Framework/NexusCpp/inc/MantidNexusCpp/napi.h

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -738,60 +738,11 @@ MANTID_NEXUSCPP_DLL NXstatus NXgetrawinfo(NXhandle handle, int *rank, int dimens
738738
*/
739739
MANTID_NEXUSCPP_DLL NXstatus NXgetrawinfo64(NXhandle handle, int *rank, int64_t dimension[], NXnumtype *datatype);
740740

741-
/** \typedef void (*ErrFunc)(void *data, const char *text)
742-
* All NeXus error reporting happens through this special function, the
743-
* ErrFunc. The NeXus-API allows this error reporting function to be replaced
744-
* through a user defined implementation. The default error function prints to stderr. User
745-
* defined ones may pop up dialog boxes or whatever.
746-
* \param data A pointer to some user defined data structure
747-
* \param text The text of the error message to display.
748-
*/
749-
typedef void (*ErrFunc)(void *data, const char *text);
750-
751-
/**
752-
* Set a global error function.
753-
* Not threadsafe.
754-
* \param pData A pointer to a user defined data structure which be passed to
755-
* the error display function.
756-
* \param newErr The new error display function.
757-
*/
758-
MANTID_NEXUSCPP_DLL void NXMSetError(void *pData, ErrFunc newErr);
759-
760741
/**
761-
* Set an error function for the current thread.
762-
* When used this overrides anything set in NXMSetError (for the current thread).
763-
* Use this method in threaded applications.
764-
* \param pData A pointer to a user defined data structure which be passed to
765-
* the error display function.
766-
* \param newErr The new error display function.
767-
*/
768-
MANTID_NEXUSCPP_DLL void NXMSetTError(void *pData, ErrFunc newErr);
769-
770-
/**
771-
* Retrieve the current error display function
772-
* \return The current error display function.
773-
*/
774-
MANTID_NEXUSCPP_DLL ErrFunc NXMGetError();
775-
776-
/**
777-
* Suppress error reports from the NeXus-API
778-
*/
779-
MANTID_NEXUSCPP_DLL void NXMDisableErrorReporting();
780-
781-
/**
782-
* Enable error reports from the NeXus-API
783-
*/
784-
MANTID_NEXUSCPP_DLL void NXMEnableErrorReporting();
785-
786-
/**
787-
* Dispatches the error message to the error function defined by NXMSetTError
742+
* Dispatches the error message
788743
*/
789744
MANTID_NEXUSCPP_DLL void NXReportError(const char *text);
790745

791-
/**
792-
* Do not use, first parameter should be set by NXMSetTError
793-
*/
794-
MANTID_NEXUSCPP_DLL void NXIReportError(void *pData, const char *text);
795746
/* extern void *NXpData; */
796747
MANTID_NEXUSCPP_DLL char *NXIformatNeXusTime();
797748

Framework/NexusCpp/src/napi.cpp

Lines changed: 1 addition & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -237,108 +237,9 @@ NXstatus NXsetcache(long newVal) {
237237
return NXstatus::NX_ERROR;
238238
}
239239

240-
/*-------------------------------------------------------------------------*/
241-
static void NXNXNXReportError(void *pData, const char *string) {
242-
UNUSED_ARG(pData);
243-
fprintf(stderr, "%s \n", string);
244-
}
245-
246-
/*---------------------------------------------------------------------*/
247-
248-
static void *NXEHpData = NULL;
249-
static void (*NXEHIReportError)(void *pData, const char *string) = NXNXNXReportError;
250-
#ifdef HAVE_TLS
251-
static THREAD_LOCAL void *NXEHpTData = NULL;
252-
static THREAD_LOCAL void (*NXEHIReportTError)(void *pData, const char *string) = NULL;
253-
#endif
254-
255-
void NXIReportError(void *pData, const char *string) {
256-
UNUSED_ARG(pData);
257-
fprintf(
258-
stderr,
259-
"Your application uses NXIReportError, but its first parameter is ignored now - you should use NXReportError.");
260-
NXReportError(string);
261-
}
262-
263-
void NXReportError(const char *string) {
264-
#ifdef HAVE_TLS
265-
if (NXEHIReportTError) {
266-
(*NXEHIReportTError)(NXEHpTData, string);
267-
return;
268-
}
269-
#endif
270-
if (NXEHIReportError) {
271-
(*NXEHIReportError)(NXEHpData, string);
272-
}
273-
}
274-
275-
/*---------------------------------------------------------------------*/
276-
extern void NXMSetError(void *pData, void (*NewError)(void *pD, const char *text)) {
277-
NXEHpData = pData;
278-
NXEHIReportError = NewError;
279-
}
280-
281240
/*----------------------------------------------------------------------*/
282-
extern void NXMSetTError(void *pData, void (*NewError)(void *pD, const char *text)) {
283-
#ifdef HAVE_TLS
284-
NXEHpTData = pData;
285-
NXEHIReportTError = NewError;
286-
#else
287-
NXMSetError(pData, NewError);
288-
#endif
289-
}
290241

291-
/*----------------------------------------------------------------------*/
292-
extern ErrFunc NXMGetError() {
293-
#ifdef HAVE_TLS
294-
if (NXEHIReportTError) {
295-
return NXEHIReportTError;
296-
}
297-
#endif
298-
return NXEHIReportError;
299-
}
300-
301-
/*----------------------------------------------------------------------*/
302-
static void NXNXNoReport(void *pData, const char *string) {
303-
// do nothing but declare the variables unused
304-
(void)pData;
305-
(void)string;
306-
}
307-
308-
/*----------------------------------------------------------------------*/
309-
310-
static ErrFunc last_global_errfunc = NXNXNXReportError;
311-
#ifdef HAVE_TLS
312-
static THREAD_LOCAL ErrFunc last_thread_errfunc = NULL;
313-
#endif
314-
315-
extern void NXMDisableErrorReporting() {
316-
#ifdef HAVE_TLS
317-
if (NXEHIReportTError) {
318-
last_thread_errfunc = NXEHIReportTError;
319-
NXEHIReportTError = NXNXNoReport;
320-
return;
321-
}
322-
#endif
323-
if (NXEHIReportError) {
324-
last_global_errfunc = NXEHIReportError;
325-
NXEHIReportError = NXNXNoReport;
326-
}
327-
}
328-
329-
extern void NXMEnableErrorReporting() {
330-
#ifdef HAVE_TLS
331-
if (last_thread_errfunc) {
332-
NXEHIReportTError = last_thread_errfunc;
333-
last_thread_errfunc = NULL;
334-
return;
335-
}
336-
#endif
337-
if (last_global_errfunc) {
338-
NXEHIReportError = last_global_errfunc;
339-
last_global_errfunc = NULL;
340-
}
341-
}
242+
void NXReportError(const char *string) { UNUSED_ARG(string); }
342243

343244
/*----------------------------------------------------------------------*/
344245
#ifdef WITH_HDF5
@@ -690,10 +591,8 @@ NXstatus NXopengroup(NXhandle fid, CONSTCHAR *name, CONSTCHAR *nxclass) {
690591
if (status == NXstatus::NX_OK) {
691592
pushPath(fileStack, name);
692593
}
693-
NXMDisableErrorReporting();
694594
char nxurl[1024];
695595
attStatus = NXgetattr(fid, "napimount", nxurl, &length, &type);
696-
NXMEnableErrorReporting();
697596
if (attStatus == NXstatus::NX_OK) {
698597
// this is an external linking group
699598
char exfile[512];
@@ -813,10 +712,8 @@ NXstatus NXopendata(NXhandle fid, CONSTCHAR *name) {
813712
pushPath(fileStack, name);
814713
}
815714

816-
NXMDisableErrorReporting();
817715
char nxurl[1024];
818716
attStatus = NXgetattr(fid, "napimount", nxurl, &length, &type);
819-
NXMEnableErrorReporting();
820717
if (attStatus == NXstatus::NX_OK) {
821718
// this is an external linking group
822719
char exfile[512];
@@ -1271,9 +1168,7 @@ NXstatus NXisexternalgroup(NXhandle fid, CONSTCHAR *name, CONSTCHAR *nxclass, ch
12711168
if (status != NXstatus::NX_OK) {
12721169
return status;
12731170
}
1274-
NXMDisableErrorReporting();
12751171
attStatus = NXgetattr(fid, "napimount", nxurl, &length, &type);
1276-
NXMEnableErrorReporting();
12771172
LOCKED_CALL(pFunc->nxclosegroup(pFunc->pNexusData));
12781173
if (attStatus == NXstatus::NX_OK) {
12791174
length = (int)strlen(nxurl);
@@ -1308,10 +1203,8 @@ NXstatus NXisexternaldataset(NXhandle fid, CONSTCHAR *name, char *url, int urlLe
13081203
if (status != NXstatus::NX_OK) {
13091204
return status;
13101205
}
1311-
NXMDisableErrorReporting();
13121206
int length = 1023;
13131207
attStatus = NXgetattr(fid, "napimount", nxurl, &length, &type);
1314-
NXMEnableErrorReporting();
13151208
LOCKED_CALL(pFunc->nxclosedata(pFunc->pNexusData));
13161209
if (attStatus == NXstatus::NX_OK) {
13171210
length = static_cast<int>(strlen(nxurl));
@@ -1355,9 +1248,7 @@ NXstatus NXlinkexternal(NXhandle fid, CONSTCHAR *name, CONSTCHAR *nxclass, CONST
13551248
return NXstatus::NX_OK;
13561249
}
13571250

1358-
NXMDisableErrorReporting();
13591251
LOCKED_CALL(pFunc->nxmakegroup(pFunc->pNexusData, name, nxclass));
1360-
NXMEnableErrorReporting();
13611252

13621253
status = LOCKED_CALL(pFunc->nxopengroup(pFunc->pNexusData, name, nxclass));
13631254
if (status != NXstatus::NX_OK) {

Framework/NexusCpp/src/napi4.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,13 +1096,11 @@ NXstatus NX4getdataID(NXhandle fid, NXlink *sRes) {
10961096
} else {
10971097
sRes->iTag = DFTAG_NDG;
10981098
sRes->iRef = SDidtoref(pFile->iCurrentSDS);
1099-
NXMDisableErrorReporting();
11001099
datalen = 1024;
11011100
memset(&sRes->targetPath, 0, 1024);
11021101
if (NX4getattr(fid, "target", &sRes->targetPath, &datalen, &type) != NXstatus::NX_OK) {
11031102
NXIbuildPath(pFile, sRes->targetPath, 1024);
11041103
}
1105-
NXMEnableErrorReporting();
11061104
return NXstatus::NX_OK;
11071105
}
11081106
sRes->iTag = static_cast<int>(NXstatus::NX_ERROR);

0 commit comments

Comments
 (0)