From 0cb578724163603c23ef61bd8c1d81884349891f Mon Sep 17 00:00:00 2001 From: macndev Date: Tue, 22 Mar 2022 16:08:09 -0500 Subject: [PATCH 1/9] compatibility fixes for SubRun objects for art v3_11 --- EventGenerator/src/CORSIKAEventGenerator_module.cc | 2 +- EventGenerator/src/CRYEventGenerator_module.cc | 2 +- EventGenerator/src/GenEventCounter_module.cc | 2 +- EventMixing/src/Mu2eProductMixer.cc | 4 ++-- EventMixing/src/ProtonBunchIntensityFlat_module.cc | 2 +- EventMixing/src/ProtonBunchIntensityLogNormal_module.cc | 2 +- Filters/src/CompressPhysicalVolumes_module.cc | 2 +- Mu2eG4/src/IonProducer_module.cc | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/EventGenerator/src/CORSIKAEventGenerator_module.cc b/EventGenerator/src/CORSIKAEventGenerator_module.cc index d96a3c8923..4e0e582fce 100644 --- a/EventGenerator/src/CORSIKAEventGenerator_module.cc +++ b/EventGenerator/src/CORSIKAEventGenerator_module.cc @@ -132,7 +132,7 @@ namespace mu2e { { std::unique_ptr livetime(new CosmicLivetime(_primaries, _area, _lowE, _highE, _fluxConstant)); std::cout << *livetime << std::endl; - subrun.put(std::move(livetime)); + subrun.put(std::move(livetime), art::subRunFragment()); } void CorsikaEventGenerator::produce(art::Event &evt) diff --git a/EventGenerator/src/CRYEventGenerator_module.cc b/EventGenerator/src/CRYEventGenerator_module.cc index 37ebb89fd1..16a7786014 100644 --- a/EventGenerator/src/CRYEventGenerator_module.cc +++ b/EventGenerator/src/CRYEventGenerator_module.cc @@ -83,7 +83,7 @@ namespace mu2e { 1.8e4, // http://pdg.lbl.gov/2018/reviews/rpp2018-rev-cosmic-rays.pdf eq. 29.2 cryGen->getLiveTime() )); std::cout << *livetime << std::endl; - subrun.put(std::move(livetime)); + subrun.put(std::move(livetime), art::subRunFragment()); } } diff --git a/EventGenerator/src/GenEventCounter_module.cc b/EventGenerator/src/GenEventCounter_module.cc index 265fb5dec2..763f0978f8 100644 --- a/EventGenerator/src/GenEventCounter_module.cc +++ b/EventGenerator/src/GenEventCounter_module.cc @@ -71,7 +71,7 @@ namespace mu2e { mf::LogInfo("Summary")<<"Creating GenEventCount record: "<(new GenEventCount(seenEvents_))); + sr.put(std::unique_ptr(new GenEventCount(seenEvents_)), art::subRunFragment()); seenEvents_ = 0; // in case the job has more than one subrun } diff --git a/EventMixing/src/Mu2eProductMixer.cc b/EventMixing/src/Mu2eProductMixer.cc index 8a7a9e17a1..54b66d152a 100644 --- a/EventMixing/src/Mu2eProductMixer.cc +++ b/EventMixing/src/Mu2eProductMixer.cc @@ -186,14 +186,14 @@ namespace mu2e { (*col)[stage].insert(subrunVolumes_[stage].begin(), subrunVolumes_[stage].end()); } - sr.put(std::move(col), subrunVolInstanceName_); + sr.put(std::move(col), subrunVolInstanceName_, art::subRunFragment()); } if (mixCosmicLivetimes_) { if(generatedEvents_ == 0)throw cet::exception("BADINPUT")<<"Mu2eProductMixer: generated event count =0; was the mixin file opened correctly?" << std::endl; float scaling = resampledEvents_ / generatedEvents_; auto livetime = std::make_unique(totalPrimaries_ * scaling, area_, lowE_, highE_, fluxConstant_, livetime_ * scaling); - sr.put(std::move(livetime), subrunLivetimeInstanceName_); + sr.put(std::move(livetime), subrunLivetimeInstanceName_, art::subRunFragment()); } } diff --git a/EventMixing/src/ProtonBunchIntensityFlat_module.cc b/EventMixing/src/ProtonBunchIntensityFlat_module.cc index bb2e70ac55..1d597f887a 100644 --- a/EventMixing/src/ProtonBunchIntensityFlat_module.cc +++ b/EventMixing/src/ProtonBunchIntensityFlat_module.cc @@ -74,7 +74,7 @@ namespace mu2e { } void ProtonBunchIntensityFlat::beginSubRun(art::SubRun & subrun ) { - subrun.put(std::make_unique(static_cast(llrint(mean_))),"MeanIntensity"); + subrun.put(std::make_unique(static_cast(llrint(mean_))),"MeanIntensity", art::fullSubRun()); } } diff --git a/EventMixing/src/ProtonBunchIntensityLogNormal_module.cc b/EventMixing/src/ProtonBunchIntensityLogNormal_module.cc index 75e2d6db7e..a32bf0ccfd 100644 --- a/EventMixing/src/ProtonBunchIntensityLogNormal_module.cc +++ b/EventMixing/src/ProtonBunchIntensityLogNormal_module.cc @@ -119,7 +119,7 @@ namespace mu2e { //================================================================ void ProtonBunchIntensityLogNormal::beginSubRun(art::SubRun & subrun ) { - subrun.put(std::make_unique(static_cast(llrint(mean_))),"MeanIntensity"); + subrun.put(std::make_unique(static_cast(llrint(mean_))),"MeanIntensity", art::fullSubRun()); } //================================================================ diff --git a/Filters/src/CompressPhysicalVolumes_module.cc b/Filters/src/CompressPhysicalVolumes_module.cc index 3dd1012701..6b78980877 100644 --- a/Filters/src/CompressPhysicalVolumes_module.cc +++ b/Filters/src/CompressPhysicalVolumes_module.cc @@ -140,7 +140,7 @@ namespace mu2e { } } - sr.put(std::move(out)); + sr.put(std::move(out), art::subRunFragment()); mf::LogInfo("Summary") << "CompressPhysicalVolumes stats: passed " diff --git a/Mu2eG4/src/IonProducer_module.cc b/Mu2eG4/src/IonProducer_module.cc index 4db0d883f5..fc3734aebc 100644 --- a/Mu2eG4/src/IonProducer_module.cc +++ b/Mu2eG4/src/IonProducer_module.cc @@ -82,7 +82,7 @@ namespace mu2e { // content for the ion test use, but we still need a stage count. mvi->resize(1); - sr.put(std::move(mvi)); + sr.put(std::move(mvi), art::fullSubRun()); } //================================================================ From eb6e19eb88e1a894d57d5e442c00babb0c44d11c Mon Sep 17 00:00:00 2001 From: macndev Date: Tue, 22 Mar 2022 16:10:14 -0500 Subject: [PATCH 2/9] obsolete files not compatible with art v3_11 --- .../src/TestKalRepProvenanceHelpers_module.cc | 87 ------------------- .../src/GeometryRecorder_module.cc | 81 ----------------- Mu2eUtilities/inc/KalRepCollectionInfo.hh | 53 ----------- Mu2eUtilities/inc/decodeTrackPatRecType.hh | 26 ------ Mu2eUtilities/src/KalRepCollectionInfo.cc | 52 ----------- Mu2eUtilities/src/decodeTrackPatRecType.cc | 29 ------- 6 files changed, 328 deletions(-) delete mode 100644 Analyses/src/TestKalRepProvenanceHelpers_module.cc delete mode 100644 GeometryService/src/GeometryRecorder_module.cc delete mode 100644 Mu2eUtilities/inc/KalRepCollectionInfo.hh delete mode 100644 Mu2eUtilities/inc/decodeTrackPatRecType.hh delete mode 100644 Mu2eUtilities/src/KalRepCollectionInfo.cc delete mode 100644 Mu2eUtilities/src/decodeTrackPatRecType.cc diff --git a/Analyses/src/TestKalRepProvenanceHelpers_module.cc b/Analyses/src/TestKalRepProvenanceHelpers_module.cc deleted file mode 100644 index e4126966ee..0000000000 --- a/Analyses/src/TestKalRepProvenanceHelpers_module.cc +++ /dev/null @@ -1,87 +0,0 @@ -// -// Module used to develop, test and illustrate the use of some -// helper functions/classes to access provenance information about -// KalRepCollections. -// -// Original author Rob Kutschke -// - -#include "Offline/Mu2eUtilities/inc/decodeTrackPatRecType.hh" -#include "Offline/Mu2eUtilities/inc/KalRepCollectionInfo.hh" -#include "Offline/Mu2eUtilities/inc/TrackPatRecType.hh" -#include "Offline/Mu2eUtilities/inc/TrkSpecies.hh" - -#include "Offline/RecoDataProducts/inc/KalRepPtrCollection.hh" -#include "Offline/RecoDataProducts/inc/KalRepCollection.hh" -#include "Offline/RecoDataProducts/inc/TrkFitDirection.hh" - -#include "art/Framework/Core/EDAnalyzer.h" -#include "art/Framework/Principal/Event.h" -#include "art/Framework/Principal/Handle.h" -#include "art/Framework/Core/ModuleMacros.h" -#include "canvas/Utilities/InputTag.h" - -#include -#include - -using namespace std; - -namespace mu2e { - - class TestKalRepProvenanceHelpers : public art::EDAnalyzer { - public: - - explicit TestKalRepProvenanceHelpers(fhicl::ParameterSet const& pset); - void analyze(const art::Event& e) override; - - private: - - // Module label of the module that created a KalRepPtrCollection. - art::InputTag _tracksTag; - - }; -} // end namespace mu2e - -mu2e::TestKalRepProvenanceHelpers::TestKalRepProvenanceHelpers(fhicl::ParameterSet const& pset) : - art::EDAnalyzer(pset), - _tracksTag(pset.get("tracksTag")){ - TrackPatRecType::printAll(cout); -} - -void mu2e::TestKalRepProvenanceHelpers::analyze(const art::Event& event) { - - // Test the collection level helper. - art::Handle kalReps; - if ( event.getByLabel(_tracksTag, kalReps) ) { - KalRepCollectionInfo info( kalReps ); - cout << "KalReps: " - << kalReps->size() << " | " - << info.patRecType() << " " - << info.instanceName() << " " - << info.direction().name() << " " - << info.particleType() << " " - << info.charge() - << endl; - } - - // Test the ptr level helpers. - auto ptrs = event.getValidHandle(_tracksTag); - cout << "KalRep ptrs: " << ptrs->size() << endl; - for ( auto const& ptr : *ptrs ){ - KalRepCollectionInfo info( ptr, event); - TrackPatRecType type = decodeTrackPatRecType( ptr, event); - cout << " : " - << _tracksTag.label() << " " - << ptr << " " - << info.patRecType() << " " - << type << " | " - << info.instanceName() << " " - << info.direction().name() << " " - << info.particleType() << " " - << info.charge() - << endl; - } - -} // end analyze - -DEFINE_ART_MODULE(mu2e::TestKalRepProvenanceHelpers); diff --git a/GeometryService/src/GeometryRecorder_module.cc b/GeometryService/src/GeometryRecorder_module.cc deleted file mode 100644 index ec54880dfa..0000000000 --- a/GeometryService/src/GeometryRecorder_module.cc +++ /dev/null @@ -1,81 +0,0 @@ -// Attach select GeometryService data to the run object. -// -// Andrei Gaponenko, 2012 - -#include - -#include "Offline/GeometryService/inc/GeometryService.hh" -#include "Offline/GeometryService/inc/GeomHandle.hh" -#include "Offline/GeometryService/inc/WorldG4.hh" -#include "Offline/GeometryService/inc/Mu2eEnvelope.hh" -#include "Offline/Mu2eHallGeom/inc/Mu2eHall.hh" -#include "Offline/ProductionTargetGeom/inc/ProductionTarget.hh" -#include "Offline/ProtonBeamDumpGeom/inc/ProtonBeamDump.hh" -#include "Offline/ExtinctionMonitorFNAL/Geometry/inc/ExtMonFNALBuilding.hh" -#include "Offline/ExtinctionMonitorFNAL/Geometry/inc/ExtMonFNAL.hh" -#include "Offline/ProductionSolenoidGeom/inc/PSEnclosure.hh" -#include "Offline/ProductionSolenoidGeom/inc/PSShield.hh" -#include "Offline/ProductionSolenoidGeom/inc/PSVacuum.hh" - -// art includes. -#include "fhiclcpp/ParameterSet.h" -#include "art/Framework/Core/EDProducer.h" -#include "art/Framework/Principal/Run.h" -#include "art/Framework/Core/ModuleMacros.h" - -namespace mu2e { - - //================================================================ - class GeometryRecorder : public art::EDProducer { - template void put(art::Run& run) { - run.put(std::unique_ptr(new DET(*GeomHandle()))); - } - - public: - explicit GeometryRecorder(const fhicl::ParameterSet& pset); - virtual void produce(art::Event&) {/*No per-event actions*/} - virtual void endRun(art::Run&); - }; - - //================================================================ - GeometryRecorder::GeometryRecorder(const fhicl::ParameterSet& pset) : - art::EDProducer{pset} - { - produces(); - produces(); - produces(); - produces(); - produces(); - produces(); - produces(); - produces(); - produces(); - - produces(); - } - - //================================================================ - // Better do the work in endRun() than beginRun(), otherwise - // the WorldG4 object may not yet be available. - void GeometryRecorder::endRun(art::Run& run) { - put(run); - put(run); - put(run); - put(run); - put(run); - put(run); - put(run); - put(run); - put(run); - - art::ServiceHandle geom; - if(geom->hasElement()) { - put(run); - } - } - - //================================================================ - -} // namespace mu2e - -DEFINE_ART_MODULE(mu2e::GeometryRecorder); diff --git a/Mu2eUtilities/inc/KalRepCollectionInfo.hh b/Mu2eUtilities/inc/KalRepCollectionInfo.hh deleted file mode 100644 index a81821352d..0000000000 --- a/Mu2eUtilities/inc/KalRepCollectionInfo.hh +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef Mu2eUtilities_KalRepCollectionInfo_hh -#define Mu2eUtilities_KalRepCollectionInfo_hh -// -// Convenience class to access provenance information about a KalRepCollection. -// -// If the only information you need is the TrackPatRecType from a KalRepPtr, -// then prefer to use Mu2eUtilities/inc/decodeTrackPatRecType.hh which runs -// faster. -// -// Contact person, Rob Kutschke -// - -#include - -#include "Offline/RecoDataProducts/inc/KalRepCollection.hh" -#include "Offline/RecoDataProducts/inc/KalRepPtrCollection.hh" -#include "Offline/RecoDataProducts/inc/TrkFitDirection.hh" -#include "art/Framework/Principal/Event.h" - -#include "Offline/Mu2eUtilities/inc/KalRepInstanceNameDecoder.hh" -#include "Offline/Mu2eUtilities/inc/TrackPatRecType.hh" -#include "Offline/Mu2eUtilities/inc/TrkSpecies.hh" - -namespace art { class Event; } -namespace art { class ProductID; } -namespace art { template class Handle; } -namespace art { template class ValidHandle; } - -namespace mu2e { - - class KalRepCollectionInfo { - public: - KalRepCollectionInfo( art::Handle const& handle ); - KalRepCollectionInfo( art::ValidHandle const& handle ); - KalRepCollectionInfo( KalRepPtr const& ptr, art::Event const& event ); - KalRepCollectionInfo( art::ProductID const& id, art::Event const& event ); - - TrackPatRecType patRecType() const { return patRecType_; } - TrkFitDirection direction() const { return instance_.direction(); } - TrkSpecies particleType() const { return instance_.particleType(); } - int charge() const { return instance_.charge(); } - std::string const& instanceName() const { return instance_.instanceName(); } - - private: - TrackPatRecType patRecType_; - KalRepInstanceNameDecoder instance_; - - }; - - -} - -#endif diff --git a/Mu2eUtilities/inc/decodeTrackPatRecType.hh b/Mu2eUtilities/inc/decodeTrackPatRecType.hh deleted file mode 100644 index 675795273d..0000000000 --- a/Mu2eUtilities/inc/decodeTrackPatRecType.hh +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef Mu2eUtilities_decodeTrackPatRecType_hh -#define Mu2eUtilities_decodeTrackPatRecType_hh -// -// Report the type of pattern recognition used -// reconstruct a given track. -// -// If the only information you need is this, -// prefer this function to KalRepCollectionInfo -// which looks for more information and is slower. -// - -#include "Offline/RecoDataProducts/inc/KalRepPtrCollection.hh" -#include "art/Framework/Principal/Event.h" -#include "fhiclcpp/ParameterSet.h" - -#include "Offline/Mu2eUtilities/inc/TrackPatRecType.hh" - -namespace art { class Event; } - -namespace mu2e { - - TrackPatRecType decodeTrackPatRecType( KalRepPtr const& ptr, art::Event const& event ); - -} - -#endif /* Mu2eUtilities_decodeTrackPatRecType_hh */ diff --git a/Mu2eUtilities/src/KalRepCollectionInfo.cc b/Mu2eUtilities/src/KalRepCollectionInfo.cc deleted file mode 100644 index aad6f85b3f..0000000000 --- a/Mu2eUtilities/src/KalRepCollectionInfo.cc +++ /dev/null @@ -1,52 +0,0 @@ -// -// Convenience class to access provenance information about a KalRepCollection. -// -// Contact person, Rob Kutschke -// - -#include -#include -#include - -#include "art/Framework/Principal/Event.h" -#include "art/Framework/Principal/Handle.h" -#include "art/Framework/Principal/Provenance.h" -#include "canvas/Persistency/Provenance/ProductID.h" -#include "fhiclcpp/ParameterSet.h" -#include "fhiclcpp/exception.h" - -#include "Offline/Mu2eUtilities/inc/KalRepCollectionInfo.hh" - -namespace { - - // Helper function to access a handle; used to enable delegation of c'tor. - art::Handle handleGetter(art::ProductID id, art::Event const& event ){ - art::Handle handle; - event.get(id, handle); - return handle; - } - -} - -namespace mu2e { - - KalRepCollectionInfo::KalRepCollectionInfo( art::Handle const& handle ): - patRecType_(handle.provenance()->parameterSet().get("module_type")), - instance_(handle.provenance()->productInstanceName()){ - } - - KalRepCollectionInfo::KalRepCollectionInfo( art::ValidHandle const& handle ): - patRecType_(handle.provenance()->parameterSet().get("module_type")), - instance_(handle.provenance()->productInstanceName()){ - } - - // Other c'tors delegate. - KalRepCollectionInfo::KalRepCollectionInfo( KalRepPtr const& ptr, art::Event const& event ): - KalRepCollectionInfo( ptr.id(), event){ - } - - KalRepCollectionInfo::KalRepCollectionInfo( art::ProductID const& id, art::Event const& event ): - KalRepCollectionInfo( handleGetter(id,event) ){ - } - -} diff --git a/Mu2eUtilities/src/decodeTrackPatRecType.cc b/Mu2eUtilities/src/decodeTrackPatRecType.cc deleted file mode 100644 index cfe9d3223d..0000000000 --- a/Mu2eUtilities/src/decodeTrackPatRecType.cc +++ /dev/null @@ -1,29 +0,0 @@ -// -// Report the type of pattern recognition used -// reconstruct a given track. -// - -#include -#include -#include -#include - -#include "Offline/RecoDataProducts/inc/KalRepCollection.hh" -#include "art/Framework/Principal/Event.h" -#include "art/Framework/Principal/Handle.h" -#include "art/Framework/Principal/Provenance.h" -#include "fhiclcpp/ParameterSet.h" -#include "fhiclcpp/exception.h" - -#include "Offline/Mu2eUtilities/inc/decodeTrackPatRecType.hh" - -namespace mu2e { - - TrackPatRecType decodeTrackPatRecType( KalRepPtr const& ptr, art::Event const& event ){ - art::Handle handle; - event.get(ptr.id(), handle); - fhicl::ParameterSet const& pset = handle.provenance()->parameterSet(); - return TrackPatRecType(pset.get("module_type")); - } -} - From f480646657f948fc470c2c683598d06c6c87619d Mon Sep 17 00:00:00 2001 From: macndev Date: Tue, 22 Mar 2022 16:10:52 -0500 Subject: [PATCH 3/9] updates to SConscript files with cetlib for art v3_11 --- GlobalConstantsService/src/SConscript | 2 ++ Sandbox/src/SConscript | 2 ++ 2 files changed, 4 insertions(+) diff --git a/GlobalConstantsService/src/SConscript b/GlobalConstantsService/src/SConscript index 901580f3e0..c21b784c15 100644 --- a/GlobalConstantsService/src/SConscript +++ b/GlobalConstantsService/src/SConscript @@ -30,6 +30,8 @@ helper.make_plugins( [ mainlib, 'art_Utilities', 'canvas', 'boost_filesystem', + 'cetlib', + 'cetlib_except', ] ) # This tells emacs to view this file in python mode. diff --git a/Sandbox/src/SConscript b/Sandbox/src/SConscript index c8f71ab135..18c33e7994 100644 --- a/Sandbox/src/SConscript +++ b/Sandbox/src/SConscript @@ -61,6 +61,8 @@ helper.make_plugin( 'FooService_service.cc', 'canvas', 'fhiclcpp', 'boost_filesystem', + 'cetlib', + 'cetlib_except', 'Core' ], ) From 84dfa9003f700763d69afe85ee32459663210939 Mon Sep 17 00:00:00 2001 From: macndev Date: Tue, 22 Mar 2022 16:11:59 -0500 Subject: [PATCH 4/9] art v3_11 fixes for art ptrs --- Validation/src/ValStepPointMC.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Validation/src/ValStepPointMC.cc b/Validation/src/ValStepPointMC.cc index a4b015ab3a..3ac9e03378 100644 --- a/Validation/src/ValStepPointMC.cc +++ b/Validation/src/ValStepPointMC.cc @@ -36,7 +36,7 @@ int mu2e::ValStepPointMC::fill(const mu2e::StepPointMCCollection & coll, _hVer->Fill(1.0); _hN->Fill(coll.size()); - art::Handle sph; + mu2e::SimParticleCollection const* sph = nullptr; art::ProductID oldId(0); for(auto sp : coll) { @@ -45,12 +45,11 @@ int mu2e::ValStepPointMC::fill(const mu2e::StepPointMCCollection & coll, // can point to missing SimParticles, this code catches that case // (none of the art::Ptr checks will tell us this, those only abort) if(sp.simParticle().id()!=oldId) { - event.get(sp.simParticle().id(),sph); + sph = &sp.simParticle().parentAs>(); oldId = sp.simParticle().id(); } - auto const& coll = *sph; auto key = cet::map_vector_key( sp.simParticle().key() ); - bool hasSim = coll.find(key)!=coll.end(); + bool hasSim = sph->find(key)!=sph->end(); if(hasSim) _id.fill(sp.simParticle()->pdgId()); _hp->Fill(sp.momentum().mag()); From 70bc5c4d9a9a814383de03eb4cd58940725d632b Mon Sep 17 00:00:00 2001 From: macndev Date: Tue, 22 Mar 2022 16:21:59 -0500 Subject: [PATCH 5/9] This commit addresses the deprecation of art::Event::get(art::ProductID) from the interface of art::Event . The return type of the function Mu2eG4Inputs::inputSimParticles can no longer be an art::Handle because there is no way that I know of to construct such an handle in all cases with the tools available in art v3.11 . To address this, I defined a small helper class to serve as the new return type: Mu2eG4Inputs::InputSimsInfo . The two classes that use this function need two things that they can get from the Handle: the data product itself, and the art::ProductID of the data product. The two data members of the new class are a smart pointer to the data product itself and the art::ProductID. The smart pointer uses the class template maybe_ref which comes from the cetlib library; it behaves like a minimal handle class template but returns it??s payload by reference not pointer. I considered std::optional instead of maybe_ref. I chose maybe_ref because it throws an exception if one forgets to check isValid and tries to use the referent from an invalid object; on the other, when I tested std::optional it seg faulted when tried to use the referent from an invalid object. --- Mu2eG4/inc/Mu2eG4Inputs.hh | 33 +++++++++++++++++++--- Mu2eG4/src/Mu2eG4Inputs.cc | 44 +++++++++--------------------- Mu2eG4/src/Mu2eG4TrackingAction.cc | 14 +++++----- Mu2eG4/src/SimParticleHelper.cc | 9 ++++-- 4 files changed, 55 insertions(+), 45 deletions(-) diff --git a/Mu2eG4/inc/Mu2eG4Inputs.hh b/Mu2eG4/inc/Mu2eG4Inputs.hh index 7a1708c1f4..2a4d87dc98 100644 --- a/Mu2eG4/inc/Mu2eG4Inputs.hh +++ b/Mu2eG4/inc/Mu2eG4Inputs.hh @@ -7,6 +7,7 @@ #include #include +#include "cetlib/maybe_ref.h" #include "canvas/Utilities/InputTag.h" #include "Offline/Mu2eG4/inc/Mu2eG4Config.hh" #include "Offline/Mu2eG4/inc/Mu2eG4PrimaryType.hh" @@ -25,6 +26,33 @@ namespace mu2e { class Mu2eG4Inputs { public: + + // The two elements of the return value of the function inputSimParticles. + // The maybe_ref is not valid if there are no input sim particles, either for + // initial stage jobs, or for non-filtered multistage input when the + // input event has no primaries for the current stage. + struct InputSimsInfo{ + cet::maybe_ref const > sims; + art::ProductID id; + + InputSimsInfo (): + sims(), id(){ + } + + InputSimsInfo ( cet::map_vector const& asims + , art::ProductID const& aid): + sims(asims), id(aid){ + } + + void reseat( cet::map_vector const& asims + , art::ProductID const& aid){ + sims.reseat(asims); + id = aid; + } + + bool isValid() const { return sims.isValid(); }; + }; + explicit Mu2eG4Inputs(const Mu2eG4Config::Inputs_& conf); bool multiStage() const { return multiStage_; } @@ -41,10 +69,7 @@ namespace mu2e { const std::optional& updateEventLevelVolumeInfos() const { return elvi_; } - // The handle is not valid if there are no input sim particles, either for - // initial stage jobs, or for non-filtered multistage input when the - // input event has no primaries for the current stage. - art::Handle inputSimParticles(const art::Event& evt) const; + InputSimsInfo inputSimParticles(const art::Event& evt) const; private: Mu2eG4PrimaryType primaryType_; diff --git a/Mu2eG4/src/Mu2eG4Inputs.cc b/Mu2eG4/src/Mu2eG4Inputs.cc index a59903ea37..1de067bbda 100644 --- a/Mu2eG4/src/Mu2eG4Inputs.cc +++ b/Mu2eG4/src/Mu2eG4Inputs.cc @@ -28,9 +28,9 @@ namespace mu2e { } //================================================================ - art::Handle + Mu2eG4Inputs::InputSimsInfo Mu2eG4Inputs::inputSimParticles(const art::Event& evt) const { - art::Handle res; + InputSimsInfo res; switch(primaryType_.id()) { default: throw cet::exception("CONFIG") @@ -42,17 +42,14 @@ namespace mu2e { break; // No input sims for GenParticle jobs case Mu2eG4PrimaryType::StepPoints: { + art::Ptr simPtr; std::optional simid; auto const h = evt.getValidHandle(primaryTag_); for(const auto& hit : *h) { if(!simid) { simid = hit.simParticle().id(); - - // We have to read the pointed-to product into memory by hand - // for the get(ProductID, &handle) call below to work. - // See Kyle's e-mail on the art-users list on 2021-03-10. - *hit.simParticle(); + simPtr = hit.simParticle(); } else { if(*simid != hit.simParticle().id()) { @@ -66,42 +63,34 @@ namespace mu2e { } if(simid) { // nothing to retrieve if primary inputs are emtpy - evt.get(*simid, res); - if(!res.isValid()) { - throw cet::exception("BADINPUT") - <<"Mu2eG4Inputs::inputSimParticles(): could not get SimParticleCollection " - <<"pointed to by step points in " - <>(), *simid); + } } break; // StepPoints case Mu2eG4PrimaryType::SimParticleLeaves: { - evt.getByLabel(primaryTag_, res); - if(!res.isValid()) { + art::Handle sph; + evt.getByLabel(primaryTag_, sph); + if(!sph.isValid()) { throw cet::exception("BADINPUT") <<"Mu2eG4Inputs::inputSimParticles(): could not get SimParticleCollection " < simPtr; std::optional simid; auto const h = evt.getValidHandle(primaryTag_); for(const auto& s : *h) { if(!simid) { simid = s.parent().id(); - - // We have to read the pointed-to product into memory by hand - // for the get(ProductID, &handle) call below to work. - // See Kyle's e-mail on the art-users list on 2021-03-10. - *s.parent(); + simPtr = s.parent(); } else { if(*simid != s.parent().id()) { @@ -115,14 +104,7 @@ namespace mu2e { } if(simid) { // nothing to retrieve if primary inputs are emtpy - evt.get(*simid, res); - if(!res.isValid()) { - throw cet::exception("BADINPUT") - <<"Mu2eG4Inputs::inputSimParticles(): could not get SimParticleCollection " - <<"pointed to by StageParticles in " - <>(), *simid); } } break; // StageParticles diff --git a/Mu2eG4/src/Mu2eG4TrackingAction.cc b/Mu2eG4/src/Mu2eG4TrackingAction.cc index 20af06aedc..21b199df26 100644 --- a/Mu2eG4/src/Mu2eG4TrackingAction.cc +++ b/Mu2eG4/src/Mu2eG4TrackingAction.cc @@ -240,12 +240,12 @@ namespace mu2e { const Mu2eG4IOConfigHelper& ioconf = perThreadObjects_->ioconf; // Read in data products from previous stages and reseat SimParticle pointers - // The returned handle is not valid for GenParticle driven jobs - // but also for non-filtered events in subsequent stages which do not - // have any primary StepPointMCs, for example. - const auto inputSimHandle = ioconf.inputs().inputSimParticles(*perThreadObjects_->artEvent); - if(inputSimHandle.isValid()) { - const SimParticleCollection& inputSims = *inputSimHandle; + // The returned object is allowed to be in an invalid state for GenParticle driven jobs + // and non-filtered events in subsequent stages which do not have any primary + // StepPointMCs, for example. + auto simsInfo = ioconf.inputs().inputSimParticles(*perThreadObjects_->artEvent); + if( simsInfo.isValid()) { + const SimParticleCollection& inputSims = simsInfo.sims.ref(); // We do not compress anything here, but use the call to reseat the pointers // while copying the inputs to _transientMap. compressSimParticleCollection(perThreadObjects_->simParticleHelper->productID(), @@ -256,7 +256,7 @@ namespace mu2e { // old -> new particle remapping for(const auto& sim: inputSims) { - art::ProductID oldID(inputSimHandle.id()); + art::ProductID oldID(simsInfo.id); auto key(sim.second.id().asUint()); art::Ptr oldSim(oldID, key, perThreadObjects_->simParticleHelper->otherProductGetter(oldID)); art::Ptr newSim(perThreadObjects_->simParticleHelper->productID(), key, perThreadObjects_->simParticleHelper->productGetter()); diff --git a/Mu2eG4/src/SimParticleHelper.cc b/Mu2eG4/src/SimParticleHelper.cc index 6a91aaab9a..42817bf287 100644 --- a/Mu2eG4/src/SimParticleHelper.cc +++ b/Mu2eG4/src/SimParticleHelper.cc @@ -23,9 +23,12 @@ namespace mu2e { { // particleNumberOffset_ is set per event, based on the highest number // used by SimParticles in previous simulation stages. - const auto sph = inputs.inputSimParticles(*event); - if(sph.isValid() && !sph->empty()) { - particleNumberOffset_ = sph->back().first.asUint(); + const auto simsData = inputs.inputSimParticles(*event); + if(simsData.isValid()) { + auto sp = simsData.sims.ref(); + if ( !sp.empty() ){ + particleNumberOffset_ = sp.back().first.asUint(); + } } } From 44d9e1ac7f8ad3ba503335cef698a1a58add5131 Mon Sep 17 00:00:00 2001 From: macndev Date: Tue, 22 Mar 2022 18:00:24 -0500 Subject: [PATCH 6/9] change endSubRun put calls back to using fullSubRun, not fragment --- EventGenerator/src/CORSIKAEventGenerator_module.cc | 2 +- EventGenerator/src/CRYEventGenerator_module.cc | 2 +- EventGenerator/src/GenEventCounter_module.cc | 2 +- EventMixing/src/Mu2eProductMixer.cc | 4 ++-- Filters/src/CompressPhysicalVolumes_module.cc | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/EventGenerator/src/CORSIKAEventGenerator_module.cc b/EventGenerator/src/CORSIKAEventGenerator_module.cc index 4e0e582fce..93dfc2e2ef 100644 --- a/EventGenerator/src/CORSIKAEventGenerator_module.cc +++ b/EventGenerator/src/CORSIKAEventGenerator_module.cc @@ -132,7 +132,7 @@ namespace mu2e { { std::unique_ptr livetime(new CosmicLivetime(_primaries, _area, _lowE, _highE, _fluxConstant)); std::cout << *livetime << std::endl; - subrun.put(std::move(livetime), art::subRunFragment()); + subrun.put(std::move(livetime), art::fullSubRun()); } void CorsikaEventGenerator::produce(art::Event &evt) diff --git a/EventGenerator/src/CRYEventGenerator_module.cc b/EventGenerator/src/CRYEventGenerator_module.cc index 16a7786014..a4217075bd 100644 --- a/EventGenerator/src/CRYEventGenerator_module.cc +++ b/EventGenerator/src/CRYEventGenerator_module.cc @@ -83,7 +83,7 @@ namespace mu2e { 1.8e4, // http://pdg.lbl.gov/2018/reviews/rpp2018-rev-cosmic-rays.pdf eq. 29.2 cryGen->getLiveTime() )); std::cout << *livetime << std::endl; - subrun.put(std::move(livetime), art::subRunFragment()); + subrun.put(std::move(livetime), art::fullSubRun()); } } diff --git a/EventGenerator/src/GenEventCounter_module.cc b/EventGenerator/src/GenEventCounter_module.cc index 763f0978f8..7dd62d462e 100644 --- a/EventGenerator/src/GenEventCounter_module.cc +++ b/EventGenerator/src/GenEventCounter_module.cc @@ -71,7 +71,7 @@ namespace mu2e { mf::LogInfo("Summary")<<"Creating GenEventCount record: "<(new GenEventCount(seenEvents_)), art::subRunFragment()); + sr.put(std::unique_ptr(new GenEventCount(seenEvents_)), art::fullSubRun()); seenEvents_ = 0; // in case the job has more than one subrun } diff --git a/EventMixing/src/Mu2eProductMixer.cc b/EventMixing/src/Mu2eProductMixer.cc index 54b66d152a..ff1657e617 100644 --- a/EventMixing/src/Mu2eProductMixer.cc +++ b/EventMixing/src/Mu2eProductMixer.cc @@ -186,14 +186,14 @@ namespace mu2e { (*col)[stage].insert(subrunVolumes_[stage].begin(), subrunVolumes_[stage].end()); } - sr.put(std::move(col), subrunVolInstanceName_, art::subRunFragment()); + sr.put(std::move(col), subrunVolInstanceName_, art::fullSubRun()); } if (mixCosmicLivetimes_) { if(generatedEvents_ == 0)throw cet::exception("BADINPUT")<<"Mu2eProductMixer: generated event count =0; was the mixin file opened correctly?" << std::endl; float scaling = resampledEvents_ / generatedEvents_; auto livetime = std::make_unique(totalPrimaries_ * scaling, area_, lowE_, highE_, fluxConstant_, livetime_ * scaling); - sr.put(std::move(livetime), subrunLivetimeInstanceName_, art::subRunFragment()); + sr.put(std::move(livetime), subrunLivetimeInstanceName_, art::fullSubRun()); } } diff --git a/Filters/src/CompressPhysicalVolumes_module.cc b/Filters/src/CompressPhysicalVolumes_module.cc index 6b78980877..1ccbad20e9 100644 --- a/Filters/src/CompressPhysicalVolumes_module.cc +++ b/Filters/src/CompressPhysicalVolumes_module.cc @@ -140,7 +140,7 @@ namespace mu2e { } } - sr.put(std::move(out), art::subRunFragment()); + sr.put(std::move(out), art::fullSubRun()); mf::LogInfo("Summary") << "CompressPhysicalVolumes stats: passed " From e668e36314bcf27ad5400ff12024fd290e1c0b00 Mon Sep 17 00:00:00 2001 From: macndev Date: Wed, 23 Mar 2022 16:38:31 -0500 Subject: [PATCH 7/9] change template arrangement to use different syntax for event and subrun objects for art v3_11, now uses anonymous namespace --- Mu2eG4/src/writePhysicalVolumes.cc | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Mu2eG4/src/writePhysicalVolumes.cc b/Mu2eG4/src/writePhysicalVolumes.cc index 4abf1c504f..7bf66000df 100644 --- a/Mu2eG4/src/writePhysicalVolumes.cc +++ b/Mu2eG4/src/writePhysicalVolumes.cc @@ -8,6 +8,23 @@ #include "art/Framework/Principal/SubRun.h" #include "art/Framework/Principal/Handle.h" +namespace { + + // Helper functions to work around the problem that, starting in art v3.11, + // the signature of put is different for events and subruns. + // A better solution would be to use template logic to make the decision. + using Collection_t = mu2e::PhysicalVolumeInfoMultiCollection; + + void storeIt (art::SubRun& sr, std::unique_ptr& up, const std::string& outInstanceName ){ + sr.put( std::move(up), outInstanceName, art::fullSubRun()); + } + + void storeIt (art::Event& e, std::unique_ptr& up, const std::string& outInstanceName ){ + e.put( std::move(up), outInstanceName); + } + +} + namespace mu2e { template @@ -32,7 +49,7 @@ namespace mu2e { // Append info for the current stage mvi->emplace_back(vi); - store.put(std::move(mvi), outInstanceName); + storeIt ( store, mvi, outInstanceName); return simStage; } From 3ff41c999af63a718ce314f35d0f9ae19b6b6b54 Mon Sep 17 00:00:00 2001 From: macndev Date: Wed, 23 Mar 2022 16:42:41 -0500 Subject: [PATCH 8/9] .muse envset update to p022 --- .muse | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.muse b/.muse index 94e0d0c115..0272402828 100644 --- a/.muse +++ b/.muse @@ -1,5 +1,5 @@ # prefer to build with this environment -ENVSET p021 +ENVSET p022 # add these to python path PYTHONPATH Trigger/python # add Offline/bin to path From 7128256903d88be5837ee7ac41e3f7b9e8833d53 Mon Sep 17 00:00:00 2001 From: macndev Date: Thu, 24 Mar 2022 08:54:40 -0500 Subject: [PATCH 9/9] Kyle's additions to writePhysicalVolumes --- Mu2eG4/src/writePhysicalVolumes.cc | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/Mu2eG4/src/writePhysicalVolumes.cc b/Mu2eG4/src/writePhysicalVolumes.cc index 7bf66000df..7ecba1facc 100644 --- a/Mu2eG4/src/writePhysicalVolumes.cc +++ b/Mu2eG4/src/writePhysicalVolumes.cc @@ -8,23 +8,6 @@ #include "art/Framework/Principal/SubRun.h" #include "art/Framework/Principal/Handle.h" -namespace { - - // Helper functions to work around the problem that, starting in art v3.11, - // the signature of put is different for events and subruns. - // A better solution would be to use template logic to make the decision. - using Collection_t = mu2e::PhysicalVolumeInfoMultiCollection; - - void storeIt (art::SubRun& sr, std::unique_ptr& up, const std::string& outInstanceName ){ - sr.put( std::move(up), outInstanceName, art::fullSubRun()); - } - - void storeIt (art::Event& e, std::unique_ptr& up, const std::string& outInstanceName ){ - e.put( std::move(up), outInstanceName); - } - -} - namespace mu2e { template @@ -49,7 +32,13 @@ namespace mu2e { // Append info for the current stage mvi->emplace_back(vi); - storeIt ( store, mvi, outInstanceName); + // Signature of put depends on the type PRINCIPAL. + if constexpr (std::is_same_v) { + store.put(std::move(mvi), outInstanceName, art::fullSubRun()); + } + else { + store.put(std::move(mvi), outInstanceName); + } return simStage; }