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

[RFC] Replace RangeMap used in Muon hit storage #42917

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Dr15Jones
Copy link
Contributor

PR description:

Changed the use of edm::RangeMap<ID, edm::OwnVector<HIT>> in muon code to edm::IdToHitRange<ID, HIT>. This is a part of the migration away from the use of edm::OwnVector (see #42734 ). The classes modified are those which are stored to either RECO, AOD, or MiniAOD files and the HIT class does not have any inheriting classes so the use of an edm::OwnVector was never needed. The edm::IdToHitRange should take up less memory as well as be easier/faster/smaller to store (measurements need to be done to confirm this).

As part of the change, new EDProducers were introduced to be able to convert edm::RangeMap into the equivalent edm::IdToHitRange. Thes EDProducers can be used to allow reading of old files containing edm::RangeMap and then covert to the new type as needed.

The edm::IdToHitRange is designed to be a drop-in replacement to edm::RangeMap so shares the same API. One of the functions in edm::RangMap allows one to pass in a different comparison function in order to find a range of hits. This is a very dangerous item as it requires the new comparison to be degenerate with respect to the standard comparator used to sort in edm::RangeMap. I added a new unit test for one of the two comparators to prove that it meets that standard (and to guarantee if it is ever change to keep meeting that standard).

PR validation:

Code compiles and new unit tests pass. I ran workflow 12434.0 using the new code.

The hit classes are not polymorphic so OwnVector was unnecessary.
…nVector

Can read files containing data products with RangeMap with OwnVectors using
these modules which read the old class and generate the new class.
Test that comparator used with RangeMap properly functions.
The type is not polymorphic so an std::vector is a better choice.
The classes changed
- have hits which were not being stored polymorphically
- were written to either standard AOD or MiniAOD
The IdToHitRange is easier for ROOT to store as it does not use
an std::map internally.
@Dr15Jones
Copy link
Contributor Author

For further documentation, the two non-standard comparators used with the edm::RangeMap are/were: DTSuperLayerIdComparator and CSCDetIdSameChamberComparator. These were used in

DTSuperLayerIdComparator

DQM/DTMonitorModule/src/DTEfficiencyTask.cc:171
RecoLocalMuon/DTSegment/src/DTMeantimerPatternReco4D.cc:80
RecoLocalMuon/DTSegment/src/DTCombinatorialPatternReco4D.cc
RecoLocalMuon/DTSegment/src/DTClusterer.cc:91
RecoLocalMuon/DTSegment/src/DTRecSegment2DExtendedProducer.cc:100
RecoLocalMuon/DTSegment/src/DTRecSegment2DProducer.cc:96
RecoLocalMuon/DTSegment/test/DTAnalyzerDetailed.cc:524
RecoLocalMuon/DTSegment/test/DTSegAnalyzer.cc:326

CSCDetIdSameChamberComparator

RecoLocalMuon/CSCSegment/src/CSCSegmentBuilder.cc:83
RecoLocalMuon/CSCSegment/test/CSCSegmentVisualise.cc:107

I didn't write a unit test for CSCDetIdSameChamberComparator as I could confirm it was a degenerate case via inspection.

@cmsbuild
Copy link
Contributor

+code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-42917/37058

  • This PR adds an extra 68KB to repository

@cmsbuild
Copy link
Contributor

cmsbuild commented Sep 29, 2023

A new Pull Request was created by @Dr15Jones (Chris Jones) for master.

It involves the following packages:

  • AnalysisDataFormats/SUSYBSMObjects (analysis)
  • CommonTools/RecoAlgos (reconstruction)
  • DataFormats/CSCRecHit (reconstruction)
  • DataFormats/Common (core)
  • DataFormats/DTRecHit (reconstruction)
  • DataFormats/GEMRecHit (upgrade, reconstruction)
  • DataFormats/MuonDetId (simulation)
  • DataFormats/MuonReco (reconstruction)
  • DataFormats/RPCRecHit (reconstruction)
  • FWCore/Utilities (core)
  • RecoLocalMuon/CSCRecHitD (reconstruction)
  • RecoLocalMuon/CSCSegment (reconstruction)
  • RecoLocalMuon/DTSegment (reconstruction)
  • RecoLocalMuon/GEMRecHit (upgrade, reconstruction)
  • RecoLocalMuon/GEMSegment (upgrade, reconstruction)
  • RecoLocalMuon/RPCRecHit (reconstruction)

@tvami, @mandrenguyen, @makortel, @civanch, @AdrianoDee, @smuzaffar, @cmsbuild, @srimanob, @jfernan2, @mdhildreth, @Dr15Jones can you please review it and eventually sign? Thanks.
@jshlee, @HuguesBrun, @trocino, @rovere, @jdolen, @gkasieczka, @abbiendi, @andrea21z, @Fedespring, @JanFSchulte, @ahinzmann, @missirol, @amagitte, @watson-ij, @wddgit, @battibass, @CeliaFernandez, @rappoccio, @bellan, @cericeci, @ptcox, @jhgoh, @felicepantaleo, @makortel, @hatakeyamak this is something you requested to watch as well.
@antoniovilela, @rappoccio, @sextonkennedy you are the release manager for this.

cms-bot commands are listed here

@Dr15Jones
Copy link
Contributor Author

I have opened the PR to allow broader testing as well as to start the discussion about such a migration (with further discussions also the appropriate meetings).

@Dr15Jones
Copy link
Contributor Author

please test

@cmsbuild
Copy link
Contributor

-1

Failed Tests: UnitTests RelVals RelVals-INPUT AddOn
Summary: https://cmssdt.cern.ch/SDT/jenkins-artifacts/pull-request-integration/PR-7145dd/34983/summary.html
COMMIT: bd206a5
CMSSW: CMSSW_13_3_X_2023-09-29-1100/el8_amd64_gcc11
User test area: For local testing, you can use /cvmfs/cms-ci.cern.ch/week0/cms-sw/cmssw/42917/34983/install.sh to create a dev area with all the needed externals and cmssw changes.

Unit Tests

I found 14 errors in the following unit tests:

---> test DiMuonVertex had ERRORS
---> test runtestPhysicsToolsPatAlgos had ERRORS
---> test runtestUtilAlgos had ERRORS
and more ...

RelVals

----- Begin Fatal Exception 29-Sep-2023 19:51:09 CEST-----------------------
An exception of category 'FileReadError' occurred while
   [0] Processing  Event run: 305064 lumi: 36 event: 55020723 stream: 0
   [1] Running path 'Flag_HcalStripHaloFilter'
   [2] Prefetching for module HcalStripHaloFilter/'HcalStripHaloFilter'
   [3] While reading from source reco::BeamHaloSummary BeamHaloSummary '' RECO
   [4] Rethrowing an exception that happened on a different read request.
   [5] Processing  Event run: 305064 lumi: 36 event: 55020723 stream: 0
   [6] Running path 'dqmofflineOnPAT_step'
   [7] Prefetching for module SingleTopTChannelLeptonDQM_miniAOD/'singleTopElectronMediumDQM_miniAOD'
   [8] Prefetching for module PATMuonSlimmer/'slimmedMuons'
   [9] Prefetching for module PATMuonSelector/'selectedPatMuons'
   [10] Prefetching for module PATMuonProducer/'patMuons'
   [11] While reading from source std::vector<reco::Muon> muons '' RECO
   [12] Reading branch recoMuons_muons__RECO.
   Additional Info:
      [a] Fatal Root Error: @SUB=TStreamerInfo::BuildOld
Cannot convert reco::MuonSegmentMatch::dtSegmentRef from type: edm::Ref<edm::RangeMap<DTChamberId,edm::OwnVector<DTRecSegment4D,edm::ClonePolicy<DTRecSegment4D> >,edm::ClonePolicy<DTRecSegment4D> >,DTRecSegment4D,edm::refhelper::FindUsingAdvance<edm::RangeMap<DTChamberId,edm::OwnVector<DTRecSegment4D,edm::ClonePolicy<DTRecSegment4D> >,edm::ClonePolicy<DTRecSegment4D> >,DTRecSegment4D> > to type: edm::Ref<edm::IdToHitRange<DTChamberId,DTRecSegment4D>,DTRecSegment4D,edm::refhelper::FindUsingAdvance<edm::IdToHitRange<DTChamberId,DTRecSegment4D>,DTRecSegment4D> >, skip element

----- End Fatal Exception -------------------------------------------------
----- Begin Fatal Exception 29-Sep-2023 19:51:10 CEST-----------------------
An exception of category 'FileReadError' occurred while
   [0] Processing  Event run: 277069 lumi: 81 event: 36026102 stream: 0
   [1] Running path 'Flag_HcalStripHaloFilter'
   [2] Prefetching for module HcalStripHaloFilter/'HcalStripHaloFilter'
   [3] While reading from source reco::BeamHaloSummary BeamHaloSummary '' RECO
   [4] Rethrowing an exception that happened on a different read request.
   [5] Processing  Event run: 277069 lumi: 81 event: 36026102 stream: 0
   [6] Running path 'dqmofflineOnPAT_step'
   [7] Prefetching for module SingleTopTChannelLeptonDQM_miniAOD/'singleTopElectronMediumDQM_miniAOD'
   [8] Prefetching for module PATMuonSlimmer/'slimmedMuons'
   [9] Prefetching for module PATMuonSelector/'selectedPatMuons'
   [10] Prefetching for module PATMuonProducer/'patMuons'
   [11] While reading from source std::vector<reco::Muon> muons '' RECO
   [12] Reading branch recoMuons_muons__RECO.
   Additional Info:
      [a] Fatal Root Error: @SUB=TStreamerInfo::BuildOld
Cannot convert reco::MuonSegmentMatch::dtSegmentRef from type: edm::Ref<edm::RangeMap<DTChamberId,edm::OwnVector<DTRecSegment4D,edm::ClonePolicy<DTRecSegment4D> >,edm::ClonePolicy<DTRecSegment4D> >,DTRecSegment4D,edm::refhelper::FindUsingAdvance<edm::RangeMap<DTChamberId,edm::OwnVector<DTRecSegment4D,edm::ClonePolicy<DTRecSegment4D> >,edm::ClonePolicy<DTRecSegment4D> >,DTRecSegment4D> > to type: edm::Ref<edm::IdToHitRange<DTChamberId,DTRecSegment4D>,DTRecSegment4D,edm::refhelper::FindUsingAdvance<edm::IdToHitRange<DTChamberId,DTRecSegment4D>,DTRecSegment4D> >, skip element

----- End Fatal Exception -------------------------------------------------
----- Begin Fatal Exception 29-Sep-2023 19:51:11 CEST-----------------------
An exception of category 'FileReadError' occurred while
   [0] Processing  Event run: 320822 lumi: 17 event: 26886180 stream: 0
   [1] Running path 'Flag_HcalStripHaloFilter'
   [2] Prefetching for module HcalStripHaloFilter/'HcalStripHaloFilter'
   [3] While reading from source reco::BeamHaloSummary BeamHaloSummary '' RECO
   [4] Rethrowing an exception that happened on a different read request.
   [5] Processing  Event run: 320822 lumi: 17 event: 26886180 stream: 0
   [6] Running path 'dqmofflineOnPAT_step'
   [7] Prefetching for module SingleTopTChannelLeptonDQM_miniAOD/'singleTopElectronMediumDQM_miniAOD'
   [8] Prefetching for module PATMuonSlimmer/'slimmedMuons'
   [9] Prefetching for module PATMuonSelector/'selectedPatMuons'
   [10] Prefetching for module PATMuonProducer/'patMuons'
   [11] While reading from source std::vector<reco::Muon> muons '' RECO
   [12] Reading branch recoMuons_muons__RECO.
   Additional Info:
      [a] Fatal Root Error: @SUB=TStreamerInfo::BuildOld
Cannot convert reco::MuonSegmentMatch::dtSegmentRef from type: edm::Ref<edm::RangeMap<DTChamberId,edm::OwnVector<DTRecSegment4D,edm::ClonePolicy<DTRecSegment4D> >,edm::ClonePolicy<DTRecSegment4D> >,DTRecSegment4D,edm::refhelper::FindUsingAdvance<edm::RangeMap<DTChamberId,edm::OwnVector<DTRecSegment4D,edm::ClonePolicy<DTRecSegment4D> >,edm::ClonePolicy<DTRecSegment4D> >,DTRecSegment4D> > to type: edm::Ref<edm::IdToHitRange<DTChamberId,DTRecSegment4D>,DTRecSegment4D,edm::refhelper::FindUsingAdvance<edm::IdToHitRange<DTChamberId,DTRecSegment4D>,DTRecSegment4D> >, skip element

----- End Fatal Exception -------------------------------------------------
Expand to see more relval errors ...

RelVals-INPUT

  • 134.807134.807_RunDoubleEGPrpt2015C/step2_RunDoubleEGPrpt2015C.log
  • 134.808134.808_RunSingleMuPrpt2015C/step2_RunSingleMuPrpt2015C.log
  • 134.907134.907_RunDoubleEGPrpt2015D/step2_RunDoubleEGPrpt2015D.log
Expand to see more relval errors ...

AddOn Tests

----- Begin Fatal Exception 29-Sep-2023 19:48:28 CEST-----------------------
An exception of category 'FileReadError' occurred while
   [0] Processing  Event run: 1 lumi: 1 event: 2 stream: 0
   [1] Running path 'p'
   [2] Prefetching for module CandidateSummaryTable/'selectedPatCandidateSummary'
   [3] Prefetching for module PATJetSelector/'selectedPatJets'
   [4] Prefetching for module PATJetProducer/'patJets'
   [5] While reading from source std::vector<reco::PFJet> ak4PFJetsCHS '' RECO
   [6] Rethrowing an exception that happened on a different read request.
   [7] Processing  Event run: 1 lumi: 1 event: 2 stream: 0
   [8] Running path 'p'
   [9] Prefetching for module CandidateSummaryTable/'selectedPatCandidateSummary'
   [10] Prefetching for module PATMuonSelector/'selectedPatMuons'
   [11] Prefetching for module PATMuonProducer/'patMuons'
   [12] While reading from source std::vector<reco::Muon> muons '' RECO
   [13] Reading branch recoMuons_muons__RECO.
   Additional Info:
      [a] Fatal Root Error: @SUB=TStreamerInfo::BuildOld
Cannot convert reco::MuonSegmentMatch::dtSegmentRef from type: edm::Ref<edm::RangeMap<DTChamberId,edm::OwnVector<DTRecSegment4D,edm::ClonePolicy<DTRecSegment4D> >,edm::ClonePolicy<DTRecSegment4D> >,DTRecSegment4D,edm::refhelper::FindUsingAdvance<edm::RangeMap<DTChamberId,edm::OwnVector<DTRecSegment4D,edm::ClonePolicy<DTRecSegment4D> >,edm::ClonePolicy<DTRecSegment4D> >,DTRecSegment4D> > to type: edm::Ref<edm::IdToHitRange<DTChamberId,DTRecSegment4D>,DTRecSegment4D,edm::refhelper::FindUsingAdvance<edm::IdToHitRange<DTChamberId,DTRecSegment4D>,DTRecSegment4D> >, skip element

----- End Fatal Exception -------------------------------------------------

Copy link
Contributor

@makortel makortel left a comment

Choose a reason for hiding this comment

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

Some quick comments on a cursory look. The test failures seem to be expected at this time.

<version ClassVersion="10" checksum="3541168201"/>
<version ClassVersion="11" checksum="841063529"/>
Copy link
Contributor

Choose a reason for hiding this comment

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

By quick look I'd think the MuonSegment's DTRecSegment4DRef and CSCSegmentRef members would be broken. The types should point to the new container types, but the Refs ProductID would point to the data products read from the input file.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I see now that ROOT's schema evolution outright fails for the Ref members.

private:
// ---------- member data --------------------------------
edm::EDGetTokenT<edm::RangeMap<ID, edm::OwnVector<T>>> get_;
edm::EDPutTokenT<edm::RangeMap<ID, std::vector<T>>> put_;
Copy link
Contributor

@makortel makortel Sep 29, 2023

Choose a reason for hiding this comment

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

Should this class template really convert from RangeMap<ID, OwnVector<T>> to IdToHitRange<ID, T>? Or am I missing something?

template <typename CMP>
range get(ID id, CMP comparator) const {
if (ids_.size() != offsets_.size()) {
throw edm::Exception(edm::errors::LogicError, "calling get with comparitor before sorting.");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
throw edm::Exception(edm::errors::LogicError, "calling get with comparitor before sorting.");
throw edm::Exception(edm::errors::LogicError, "calling get with comparator before sorting.");

?

Comment on lines +200 to +202
std::vector<ID> ids_;
std::vector<unsigned int> offsets_;
container collection_;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add some comments how the ID element gets mapped to collection_ via offsets_?

Copy link
Contributor

Choose a reason for hiding this comment

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

Is the idea that, previously map<ID,pair<unsigned int,unsigned int> > was storing the start and stop indices, and since the container is contiguous (i.e. start[i+1] = stop[i]), the offsets is sufficient?

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

@@ -65,7 +65,8 @@ initial version number of a class which has never been stored before.
<version ClassVersion="11" checksum="541727491"/>
<version ClassVersion="10" checksum="4050071853"/>
</class>
<class name="reco::MuonSegmentMatch" ClassVersion="11">
<class name="reco::MuonSegmentMatch" ClassVersion="12">
<version ClassVersion="12" checksum="3329152288"/>
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd expect the MuonSegmentMatch member muon hit Refs to be broken here as well.

@@ -83,7 +83,7 @@ namespace edm {
"edm::AssociationMap<edm::OneToManyWithQuality<(.*?), *(.*?), *(.*?), *u[a-z]*> >");
static std::regex const reToVector("edm::AssociationVector<(.*), *(.*), *edm::Ref.*,.*>");
//NOTE: if the item within a clone policy is a template, this substitution will probably fail
static std::regex const reToRangeMap("edm::RangeMap< *(.*), *(.*), *edm::ClonePolicy<([^>]*)> >");
static std::regex const reToRangeMap("edm::RangeMap< *(.*), *(.*), *edm::(Clone|Copy)Policy<([^>]*)> >");
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that the strategy change towards edm::IdToHitRange, are these changes needed?

@smuzaffar smuzaffar added this to the CMSSW_14_0_X milestone Nov 6, 2023
@cmsbuild cmsbuild modified the milestones: CMSSW_14_0_X, CMSSW_13_3_X Nov 6, 2023
@VinInn
Copy link
Contributor

VinInn commented Nov 21, 2023

why not to use edmnew::DetSetVector (that was implemented just for that)?
DataFormats/Common/interface/DetSetVectorNew.h
here the comparison with RangeMap
https://github.com/cms-sw/cmssw/blob/master/DataFormats/Common/test/DetSetNew_t.cpp#L651

the copy (to ease transition) is implemented here
https://github.com/cms-sw/cmssw/blob/master/DataFormats/Common/interface/DetSet2RangeMap.h

@cmsbuild
Copy link
Contributor

cmsbuild commented Feb 6, 2024

Milestone for this pull request has been moved to CMSSW_14_1_X. Please open a backport if it should also go in to CMSSW_14_0_X.

@cmsbuild
Copy link
Contributor

Milestone for this pull request has been moved to CMSSW_14_2_X. Please open a backport if it should also go in to CMSSW_14_1_X.

@antoniovilela
Copy link
Contributor

ping (to make bot change milestone)

@cmsbuild cmsbuild modified the milestones: CMSSW_14_1_X, CMSSW_14_2_X Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants