Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REFACTOR] New RangeManager #5703

Merged
merged 12 commits into from
Dec 20, 2021
Merged

Conversation

cbielow
Copy link
Contributor

@cbielow cbielow commented Dec 14, 2021

Description

Replace the old RangeManager with a modern implementation, which supports more operations on Ranges (RT, m/z, Intensity, Mobility etc), and is safer to use, e.g. instead of map.getMin()[0] which could mean anything, you now use map.getMinRT().

The new RangeManager supports arbitrary, but explicitly specified dimensions by using variadic templates, e.g.
RangeManager<RangeRT, RangeMZ> can manage RT and m/z dimensions.
Ranges with different dimensions can interact, e.g. a range of a PeakMap (rt,mz,intensity) can be updated by the range of a spectrum (mz,intensity) by simply doing map.extendRange(spec).
This usually leads to a reduction in code size, and much cleaner code, e.g. see
https://github.com/OpenMS/OpenMS/pull/5703/files#diff-c819ce9062138032f71bd4408e255d4cd375069116192fcc9a01a6fbcf0f6656L314

RangeManager is implemented for all core datastructures, such as Spectrum, PeakMap, FeatureMap, ConsensusMap etc
and is used by the GUI Layers (further refactoring is needed there for the plotting canvas, which still uses old-fashioned DIntervalBase, but that change is rather large, and thus not part of this PR).

How can I get additional information on failed tests during CI:

If your PR is failing you can check out

Note:

  • Once you opened a PR try to minimize the number of pushes to it as every push will trigger CI (automated builds and test) and is rather heavy on our infrastructure (e.g., if several pushes per day are performed).

@@ -2984,7 +2972,7 @@ namespace OpenMS
}

// update gradient if the min/max intensity changes
if (tmp.getIntensity() < current_layer.getFeatureMap()->getMinInt() || tmp.getIntensity() > current_layer.getFeatureMap()->getMaxInt())
if (!current_layer.getFeatureMap()->getRange().RangeIntensity::contains(tmp.getIntensity()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the namespaces look a bit strange with the getRange().RangeIntensity::contains ? is this intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. Its a parent-class scope.
One could also add new methods to the RangeIntensity Class, i.e. containsIntensity(). That would avoid the need for the scoping, but its also more code to write in the RangeManager.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say it would be a bit more in line with the getMinIntensity() etc. methods.
How much code would you need to add?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one method per dimension. Four lines each.
I was acutally thinking about using an old-style preprocessor macro, just to avoid writing the same code 4 times (rt, mz, int, mobility). Not sure if thats the right way to go, but it would safe a lot of typing and testing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do others think? I think will not write those rangemanagers that often and a nice interface would outweight the extra work here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jpfeuffer what is your take on that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be better for compilation to have less code, which I am valuing very highly these days.
On the other hand this indeed pretty weird and I wouldn't be able to write that kind of code without looking up namespace rules or finding other usages for the first few times.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right :). @cbielow can you move some code from the header in the cpp file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can move some code, but what is moveable are mostly one-line functions.
The majority is templates and thus unmovable anyway.
I suspect compile time will not be affected in any way, but I can do it of course.

I also suspect that adding explicit functions will not influence compile time :)
So shall I add them?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Pretty please? 🥺

@cbielow
Copy link
Contributor Author

cbielow commented Dec 16, 2021

all tests pass.
Ready for merge.

@timosachsenberg
Copy link
Contributor

Chris will add namespace change to other PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants