Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
mantid
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mantidproject
mantid
Commits
7b226ee8
Commit
7b226ee8
authored
4 years ago
by
Peterson, Peter
Browse files
Options
Downloads
Patches
Plain Diff
Add registration of NeXusHDF5 file loaders
parent
c4e9150a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Framework/API/inc/MantidAPI/FileLoaderRegistry.h
+15
-4
15 additions, 4 deletions
Framework/API/inc/MantidAPI/FileLoaderRegistry.h
Framework/API/src/FileLoaderRegistry.cpp
+37
-19
37 additions, 19 deletions
Framework/API/src/FileLoaderRegistry.cpp
with
52 additions
and
23 deletions
Framework/API/inc/MantidAPI/FileLoaderRegistry.h
+
15
−
4
View file @
7b226ee8
...
...
@@ -10,15 +10,16 @@
#include
"MantidAPI/IFileLoader.h"
#include
"MantidKernel/FileDescriptor.h"
#include
"MantidKernel/NexusDescriptor.h"
#include
"MantidKernel/NexusHDF5Descriptor.h"
#include
"MantidKernel/SingletonHolder.h"
#ifndef Q_MOC_RUN
#include
<type_traits>
#endif
#include
<array>
#include
<map>
#include
<string>
#include
<vector>
namespace
Mantid
{
namespace
Kernel
{
...
...
@@ -41,7 +42,7 @@ DECLARE_ALGORITHM macro
class
MANTID_API_DLL
FileLoaderRegistryImpl
{
public:
/// Defines types of possible file
enum
LoaderFormat
{
Nexus
,
Generic
};
enum
LoaderFormat
{
Nexus
,
Generic
,
NexusHDF5
};
public
:
/// @returns the number of entries in the registry
...
...
@@ -101,6 +102,16 @@ private:
"API::IFileLoader<Kernel::NexusDescriptor>"
);
}
break
;
case
NexusHDF5
:
if
(
!
std
::
is_base_of
<
IFileLoader
<
Kernel
::
NexusHDF5Descriptor
>
,
T
>::
value
)
{
throw
std
::
runtime_error
(
std
::
string
(
"FileLoaderRegistryImpl::subscribe - Class '"
)
+
typeid
(
T
).
name
()
+
"' registered as NexusHDF5 loader but it does not "
"inherit from "
"API::IFileLoader<Kernel::NexusHDF5Descriptor>"
);
}
break
;
case
Generic
:
if
(
!
std
::
is_base_of
<
IFileLoader
<
Kernel
::
FileDescriptor
>
,
T
>::
value
)
{
throw
std
::
runtime_error
(
...
...
@@ -122,8 +133,8 @@ private:
std
::
multimap
<
std
::
string
,
int
>
&
typedLoaders
);
/// The list of names. The index pointed to by LoaderFormat defines a set for
/// that format
std
::
vector
<
std
::
multimap
<
std
::
string
,
int
>>
m_names
;
/// that format
. The length is equal to the length of the LoaderFormat enum
std
::
array
<
std
::
multimap
<
std
::
string
,
int
>
,
3
>
m_names
;
/// Total number of names registered
size_t
m_totalSize
;
...
...
This diff is collapsed.
Click to expand it.
Framework/API/src/FileLoaderRegistry.cpp
+
37
−
19
View file @
7b226ee8
...
...
@@ -6,7 +6,6 @@
// SPDX - License - Identifier: GPL - 3.0 +
#include
"MantidAPI/FileLoaderRegistry.h"
#include
"MantidAPI/IFileLoader.h"
#include
"MantidKernel/NexusHDF5Descriptor.h"
#include
<Poco/File.h>
...
...
@@ -113,14 +112,23 @@ FileLoaderRegistryImpl::chooseLoader(const std::string &filename) const {
m_log
.
debug
()
<<
filename
<<
" looks like a Nexus file. Checking registered Nexus loaders
\n
"
;
try
{
bestLoader
=
searchForLoader
<
NexusHDF5Descriptor
,
IFileLoader
<
NexusHDF5Descriptor
>>
(
filename
,
m_names
[
Nexus
],
m_log
);
}
catch
(
const
std
::
invalid_argument
&
)
{
// a large subset of NeXus files are actually HDF5 based
if
(
NexusHDF5Descriptor
::
isReadable
(
filename
))
{
try
{
bestLoader
=
searchForLoader
<
NexusHDF5Descriptor
,
IFileLoader
<
NexusHDF5Descriptor
>>
(
filename
,
m_names
[
NexusHDF5
],
m_log
);
}
catch
(
const
std
::
invalid_argument
&
e
)
{
m_log
.
debug
()
<<
"Error in looking for HDF5 based NeXus files: "
<<
e
.
what
()
<<
'\n'
;
}
}
// try generic nexus loaders
if
(
!
bestLoader
)
{
bestLoader
=
searchForLoader
<
NexusDescriptor
,
IFileLoader
<
NexusDescriptor
>>
(
filename
,
m_names
[
Nexus
],
m_log
);
searchForLoader
<
NexusDescriptor
,
IFileLoader
<
NexusDescriptor
>>
(
filename
,
m_names
[
Nexus
],
m_log
);
}
}
else
{
m_log
.
debug
()
<<
"Checking registered non-HDF loaders
\n
"
;
...
...
@@ -147,15 +155,14 @@ bool FileLoaderRegistryImpl::canLoad(const std::string &algorithmName,
const
std
::
string
&
filename
)
const
{
using
Kernel
::
FileDescriptor
;
using
Kernel
::
NexusDescriptor
;
using
Kernel
::
NexusHDF5Descriptor
;
// Check if it is in one of our lists
bool
nexus
(
false
),
nonHDF
(
false
);
if
(
m_names
[
Nexus
].
find
(
algorithmName
)
!=
m_names
[
Nexus
].
end
())
nexus
=
true
;
else
if
(
m_names
[
Generic
].
find
(
algorithmName
)
!=
m_names
[
Generic
].
end
())
nonHDF
=
true
;
const
bool
nexus
=
(
m_names
[
Nexus
].
find
(
algorithmName
)
!=
m_names
[
Nexus
].
end
());
const
bool
nexusHDF5
=
(
m_names
[
NexusHDF5
].
find
(
algorithmName
)
!=
m_names
[
NexusHDF5
].
end
());
const
bool
nonHDF
=
(
m_names
[
Generic
].
find
(
algorithmName
)
!=
m_names
[
Generic
].
end
());
if
(
!
nexus
&&
!
nonHDF
)
if
(
!
(
nexus
||
nexusHDF5
||
nonHDF
)
)
throw
std
::
invalid_argument
(
"FileLoaderRegistryImpl::canLoad - Algorithm '"
+
algorithmName
+
"' is not registered as a loader."
);
...
...
@@ -165,11 +172,21 @@ bool FileLoaderRegistryImpl::canLoad(const std::string &algorithmName,
if
(
nexus
)
{
if
(
NexusDescriptor
::
isReadable
(
filename
))
{
loader
=
searchForLoader
<
NexusDescriptor
,
IFileLoader
<
NexusDescriptor
>>
(
filename
,
names
,
m_log
);
filename
,
names
,
m_log
);
}
}
else
{
}
else
if
(
nexusHDF5
)
{
if
(
NexusHDF5Descriptor
::
isReadable
(
filename
))
{
try
{
loader
=
searchForLoader
<
NexusHDF5Descriptor
,
IFileLoader
<
NexusHDF5Descriptor
>>
(
filename
,
names
,
m_log
);
}
catch
(
const
std
::
invalid_argument
&
e
)
{
m_log
.
debug
()
<<
"Error in looking for HDF5 based NeXus files: "
<<
e
.
what
()
<<
'\n'
;
}
}
}
else
if
(
nonHDF
)
{
loader
=
searchForLoader
<
FileDescriptor
,
IFileLoader
<
FileDescriptor
>>
(
filename
,
names
,
m_log
);
filename
,
names
,
m_log
);
}
return
static_cast
<
bool
>
(
loader
);
}
...
...
@@ -179,10 +196,11 @@ bool FileLoaderRegistryImpl::canLoad(const std::string &algorithmName,
//----------------------------------------------------------------------------------------------
/**
* Creates an empty registry
*
* m_names is initialized in the header
*/
FileLoaderRegistryImpl
::
FileLoaderRegistryImpl
()
:
m_names
(
2
,
std
::
multimap
<
std
::
string
,
int
>
()),
m_totalSize
(
0
),
m_log
(
"FileLoaderRegistry"
)
{}
:
m_totalSize
(
0
),
m_log
(
"FileLoaderRegistry"
)
{}
FileLoaderRegistryImpl
::~
FileLoaderRegistryImpl
()
=
default
;
...
...
This diff is collapsed.
Click to expand it.
WHITFIELDRE email
@rwp
mentioned in commit
ef70476c
·
4 years ago
mentioned in commit
ef70476c
mentioned in commit ef70476cc1014e189dc09e7700539be8697c20c3
Toggle commit list
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment