Repository navigation
Matching: store all pairs in CSR layout (fixes lost 1:n / n:1 pairs) - #156
Conversation
|
@lubynets Dear Oleksii, this is an update on the matching with structural changes, there old AT versions will not be able to read newer AT files anymore. If you are fine with the changes proposed here, we would need to have an updated version for external usage. Many thanks, Frederic. |
lubynets
left a comment
There was a problem hiding this comment.
Hi Frederic, thanks for the development!
- The PR is fine for me with one minor comment (in the code).
- It's fine that the newly created files are not readable by old AT versions, provided that the reading is possible other way around: old files with the updated AT (afaiu it is?)
- By updated version for external usage you mean creating a new tag, am I right?
| */ | ||
| class MatchRange { | ||
| public: | ||
| MatchRange() = default; |
There was a problem hiding this comment.
Can this constructor be deleted? - since there is no use case to have member variables as nullptr (please correct me if I am wrong), and there is no way to change them once default constructor was called.
There was a problem hiding this comment.
The default constructor is used: GetMatchesDirect() / GetMatchesInverted() return {} when an object has no partner (Matching.cpp, lines 32 and 42). {nullptr, nullptr} is a valid empty range (begin() == end(), size() == 0, empty() == true, range-for does nothing). And MatchRange is a read-only view by design, so it is never modified after construction anyway.
If you prefer, I can remove the default constructor and return MatchRange(nullptr, nullptr) explicitly instead. The behaviour is identical, it only makes the empty case more visible in the code.
There was a problem hiding this comment.
(2) Yes, exactly. Old files (Matching version ≤ 2, two std::maps) are readable with the updated AnalysisTree. An I/O read rule in AnalysisTreeCoreLinkDef.h converts the two legacy maps into the new CSR layout during reading, so no user action is needed. The conversion even takes the pairs from both legacy maps, so old files regain pairs that were lost in one of them (e.g. 1:n matchings like VtxTracks2FsdHits). GetMatch() returns the same result as before.
The conversion logic itself is covered by the unit test Matching.LegacyMaps. Reading a real v2 file is not part of CI yet because there is no v2 reference file in the repo; I checked it manually with a cbm production file.
There was a problem hiding this comment.
(1) Sorry, I overlooked that the default constructor is used. Let it be as is (provided that subtraction of two same-type nullptrs is guaranteed to be zero, which I am not 100% sure, and a quick digest of AI overview gives contradicting answers). If there is a chance that size() will be called to an empty object, it is better to foresee this case explicitly.
(2-3) OK
There was a problem hiding this comment.
Now fixed, however needed to bring back the maps for backward compatibility. So even in the new files, there are still written, but as emply maps, so its cost only few kB which I would consider acceptable.
Another option would be to have a full legacy class for that, but then reading with ROOT only (just the ttree) would results in problems and one would have to apply the legacy matching manually.
What do you think? @lubynets
There was a problem hiding this comment.
If writing of empty maps costs only few KB of memory, and does not confuse users or bring to errors, I think it's ok.
|
@lubynets I think the failed job is not an issue of my code changes. Can you rerun? It seems I do not have rights to do so... |
Seems like a network problem, maybe try again later. |
I tried twice and it crashes again and again, but indeed the crash seems to be unrelated to the PR. I'll check it later, in personal fork. |
|
@lubynets Yes, from my side everything is in and working. |
@fjlinz new tag https://github.com/HeavyIonAnalysis/AnalysisTree/releases/tag/v2.5.0 published |
Motivation
Matchingstored two persistentstd::map<int,int>(direct and inverted). A map keeps one value per key andinsert()silently ignores duplicates, so:VtxTracks2FsdHitsholds ~3 pairs/event inmatch_but ~120 inmatch_inverted_; forTofHits2SimParticlesthe inverted map drops hits sharing one SimParticle.Changes
New storage (CSR layout),
ClassDef(Matching, 3)GetEntry().AddMatch()is O(1) for increasingid1and inserts in place otherwise (e.g. converters looping over hits).id2 → id1) is transient: it is built on first use and invalidated byAddMatch(),Clear()and an I/O read rule after each read.Backward compatibility (reading)
API
GetMatchesDirect(id),GetMatchesInverted(id),GetMatches(id, is_inverted)→MatchRangeGetMatch(id, is_inverted)id1instead of first inserted)GetMatches(bool)→const std::map&GetNumberOfPairs(),GetNumberOfIds(is_inverted)SetMatches(), constructor taking mapsAddMatch()now throwsstd::invalid_argumentfor negative ids (ids are channel indices).Adapted users:
AnalysisEntryand infra-1.0VarManagerEntryloop over ids withGetMatch()and keep their behaviour (first partner per object). No users of the removed map API were found in AnalysisTreeQA, cbmatqa, cbmroot/analysis, Centrality, Efficiency, EventMixer or Tools.Tests
New tests in
core/Matching.test.cpp: