Skip to content

Commit 95e2d38

Browse files
authored
Merge pull request #47357 from fwyzard/modernize_Handle_OrphanHandle
Modernise Handle and OrphanHandle interface
2 parents 691c5b0 + 3ef1d8b commit 95e2d38

File tree

18 files changed

+231
-311
lines changed

18 files changed

+231
-311
lines changed

CommonTools/RecoUtils/plugins/LeptonFSRProducer.cc

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,21 @@
1010
*/
1111

1212
#include <memory>
13-
#include "FWCore/Framework/interface/Frameworkfwd.h"
14-
#include "FWCore/Framework/interface/global/EDProducer.h"
1513

14+
#include "DataFormats/Candidate/interface/Candidate.h"
15+
#include "DataFormats/Common/interface/ValueMap.h"
16+
#include "DataFormats/Math/interface/LorentzVector.h"
17+
#include "DataFormats/PatCandidates/interface/Electron.h"
18+
#include "DataFormats/PatCandidates/interface/GenericParticle.h"
19+
#include "DataFormats/PatCandidates/interface/Muon.h"
20+
#include "DataFormats/PatCandidates/interface/PackedCandidate.h"
1621
#include "FWCore/Framework/interface/Event.h"
22+
#include "FWCore/Framework/interface/Frameworkfwd.h"
1723
#include "FWCore/Framework/interface/MakerMacros.h"
18-
24+
#include "FWCore/Framework/interface/global/EDProducer.h"
1925
#include "FWCore/ParameterSet/interface/ParameterSet.h"
2026
#include "FWCore/Utilities/interface/StreamID.h"
2127

22-
#include "DataFormats/Candidate/interface/Candidate.h"
23-
#include "DataFormats/PatCandidates/interface/PackedCandidate.h"
24-
#include "DataFormats/PatCandidates/interface/GenericParticle.h"
25-
#include "DataFormats/Math/interface/LorentzVector.h"
26-
27-
#include "DataFormats/PatCandidates/interface/Muon.h"
28-
#include "DataFormats/PatCandidates/interface/Electron.h"
29-
#include "DataFormats/Common/interface/ValueMap.h"
30-
3128
class LeptonFSRProducer : public edm::global::EDProducer<> {
3229
public:
3330
explicit LeptonFSRProducer(const edm::ParameterSet& iConfig)
@@ -217,7 +214,7 @@ void LeptonFSRProducer::produce(edm::StreamID streamID, edm::Event& iEvent, cons
217214
}
218215
} // end of loop over pfCands
219216

220-
edm::OrphanHandle<std::vector<pat::GenericParticle>> oh = iEvent.put(std::move(fsrPhotons));
217+
iEvent.put(std::move(fsrPhotons));
221218

222219
{
223220
std::unique_ptr<edm::ValueMap<int>> bareIdx(new edm::ValueMap<int>());

CommonTools/UtilAlgos/interface/AssociationVectorSelector.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,10 @@ void AssociationVectorSelector<KeyRefProd, CVal, KeySelector, ValSelector>::prod
6868
KeyRefProd ref = evt.getRefBeforePut<collection_t>();
6969
unique_ptr<association_t> selectedAssociation(new association_t(ref, selected.get()));
7070
size = selected->size();
71-
OrphanHandle<collection_t> oh = evt.put(std::move(selected));
72-
for (size_t i = 0; i != size; ++i)
71+
evt.put(std::move(selected));
72+
for (size_t i = 0; i != size; ++i) {
7373
selectedAssociation->setValue(i, selectedValues[i]);
74+
}
7475
evt.put(std::move(selectedAssociation));
7576
}
7677

DataFormats/Common/interface/Handle.h

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef DataFormats_Common_Handle_h
2-
#define DataFormats_Common_Handle_h
1+
#ifndef DataFormats_Common_interface_Handle_h
2+
#define DataFormats_Common_interface_Handle_h
33

44
/*----------------------------------------------------------------------
55
@@ -40,17 +40,10 @@ namespace edm {
4040
Handle(T const* prod, Provenance const* prov);
4141

4242
Handle(std::shared_ptr<HandleExceptionFactory const>&&);
43-
Handle(Handle const&) = default;
44-
Handle& operator=(Handle&&) = default;
45-
Handle& operator=(Handle const&) = default;
46-
47-
~Handle();
4843

4944
T const* product() const;
5045
T const* operator->() const; // alias for product()
5146
T const& operator*() const;
52-
53-
private:
5447
};
5548

5649
template <class T>
@@ -63,9 +56,6 @@ namespace edm {
6356
Handle<T>::Handle(std::shared_ptr<edm::HandleExceptionFactory const>&& iWhyFailed)
6457
: HandleBase(std::move(iWhyFailed)) {}
6558

66-
template <class T>
67-
Handle<T>::~Handle() {}
68-
6959
template <class T>
7060
T const* Handle<T>::product() const {
7161
return static_cast<T const*>(productStorage());
@@ -80,5 +70,7 @@ namespace edm {
8070
T const& Handle<T>::operator*() const {
8171
return *product();
8272
}
73+
8374
} // namespace edm
84-
#endif
75+
76+
#endif // DataFormats_Common_interface_Handle_h

DataFormats/Common/interface/HandleBase.h

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef DataFormats_Common_HandleBase_h
2-
#define DataFormats_Common_HandleBase_h
1+
#ifndef DataFormats_Common_interface_HandleBase_h
2+
#define DataFormats_Common_interface_HandleBase_h
33

44
/*----------------------------------------------------------------------
55
@@ -25,17 +25,18 @@ If failedToGet() returns false but isValid() is also false then no attempt
2525
2626
----------------------------------------------------------------------*/
2727

28+
#include <algorithm>
2829
#include <cassert>
30+
#include <memory>
31+
2932
#include "DataFormats/Provenance/interface/ProductID.h"
3033
#include "DataFormats/Provenance/interface/ProvenanceFwd.h"
3134
#include "DataFormats/Common/interface/HandleExceptionFactory.h"
32-
#include <algorithm>
33-
34-
#include <memory>
3535

3636
namespace cms {
3737
class Exception;
3838
}
39+
3940
namespace edm {
4041
class HandleBase {
4142
public:
@@ -46,7 +47,9 @@ namespace edm {
4647
assert(prov);
4748
}
4849

49-
~HandleBase() {}
50+
///Used when the attempt to get the data failed
51+
HandleBase(std::shared_ptr<HandleExceptionFactory const>&& iWhyFailed)
52+
: product_(nullptr), prov_(nullptr), whyFailedFactory_(iWhyFailed) {}
5053

5154
void clear() {
5255
product_ = nullptr;
@@ -55,16 +58,9 @@ namespace edm {
5558
}
5659

5760
void swap(HandleBase& other) {
58-
using std::swap;
59-
swap(product_, other.product_);
61+
std::swap(product_, other.product_);
6062
std::swap(prov_, other.prov_);
61-
swap(whyFailedFactory_, other.whyFailedFactory_);
62-
}
63-
64-
HandleBase& operator=(HandleBase const& rhs) {
65-
HandleBase temp(rhs);
66-
this->swap(temp);
67-
return *this;
63+
std::swap(whyFailedFactory_, other.whyFailedFactory_);
6864
}
6965

7066
bool isValid() const { return product_ && prov_; }
@@ -75,19 +71,6 @@ namespace edm {
7571

7672
ProductID id() const;
7773

78-
HandleBase(HandleBase const&) = default;
79-
80-
///Used when the attempt to get the data failed
81-
HandleBase(std::shared_ptr<HandleExceptionFactory const>&& iWhyFailed)
82-
: product_(), prov_(nullptr), whyFailedFactory_(iWhyFailed) {}
83-
84-
HandleBase& operator=(HandleBase&& rhs) {
85-
product_ = rhs.product_;
86-
prov_ = rhs.prov_;
87-
whyFailedFactory_ = std::move(rhs.whyFailedFactory_);
88-
return *this;
89-
}
90-
9174
std::shared_ptr<cms::Exception> whyFailed() const {
9275
if (whyFailedFactory_.get()) {
9376
return whyFailedFactory_->make();
@@ -112,6 +95,7 @@ namespace edm {
11295

11396
// Free swap function
11497
inline void swap(HandleBase& a, HandleBase& b) { a.swap(b); }
98+
11599
} // namespace edm
116100

117-
#endif
101+
#endif // DataFormats_Common_interface_HandleBase_h

DataFormats/Common/interface/OrphanHandle.h

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef DataFormats_Common_OrphanHandle_h
2-
#define DataFormats_Common_OrphanHandle_h
1+
#ifndef DataFormats_Common_interface_OrphanHandle_h
2+
#define DataFormats_Common_interface_OrphanHandle_h
33

44
/*----------------------------------------------------------------------
55
@@ -22,23 +22,20 @@ To check validity, one can use the isValid() function.
2222
#include "DataFormats/Common/interface/OrphanHandleBase.h"
2323

2424
namespace edm {
25+
2526
template <typename T>
2627
class OrphanHandle : public OrphanHandleBase {
2728
public:
28-
typedef T element_type;
29+
using element_type = T;
2930

3031
// Default constructed handles are invalid.
3132
OrphanHandle();
3233

3334
OrphanHandle(T const* prod, ProductID const& id);
3435

35-
~OrphanHandle();
36-
3736
T const* product() const;
3837
T const* operator->() const; // alias for product()
3938
T const& operator*() const;
40-
41-
private:
4239
};
4340

4441
template <class T>
@@ -47,9 +44,6 @@ namespace edm {
4744
template <class T>
4845
OrphanHandle<T>::OrphanHandle(T const* prod, ProductID const& theId) : OrphanHandleBase(prod, theId) {}
4946

50-
template <class T>
51-
OrphanHandle<T>::~OrphanHandle() {}
52-
5347
template <class T>
5448
T const* OrphanHandle<T>::product() const {
5549
return static_cast<T const*>(productStorage());
@@ -66,4 +60,5 @@ namespace edm {
6660
}
6761

6862
} // namespace edm
69-
#endif
63+
64+
#endif // DataFormats_Common_interface_OrphanHandle_h

DataFormats/Common/interface/OrphanHandleBase.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef DataFormats_Common_OrphanHandleBase_h
2-
#define DataFormats_Common_OrphanHandleBase_h
1+
#ifndef DataFormats_Common_interface_OrphanHandleBase_h
2+
#define DataFormats_Common_interface_OrphanHandleBase_h
33

44
/*----------------------------------------------------------------------
55
@@ -20,14 +20,16 @@ To check validity, one can use the isValid() function.
2020
2121
----------------------------------------------------------------------*/
2222

23-
#include "DataFormats/Provenance/interface/ProductID.h"
24-
#include <cassert>
2523
#include <algorithm>
24+
#include <cassert>
25+
26+
#include "DataFormats/Provenance/interface/ProductID.h"
2627

2728
namespace edm {
29+
2830
class OrphanHandleBase {
2931
public:
30-
OrphanHandleBase() : product_(), id_(ProductID()) {}
32+
OrphanHandleBase() : product_(nullptr), id_() {}
3133

3234
OrphanHandleBase(void const* iProd, ProductID const& iId) : product_(iProd), id_(iId) { assert(iProd); }
3335

@@ -37,17 +39,16 @@ namespace edm {
3739
}
3840

3941
void swap(OrphanHandleBase& other) {
40-
using std::swap;
41-
swap(product_, other.product_);
42+
std::swap(product_, other.product_);
4243
std::swap(id_, other.id_);
4344
}
4445

4546
bool isValid() const { return product_ && id_ != ProductID(); }
4647

47-
ProductID id() const;
48+
ProductID id() const { return id_; }
4849

4950
protected:
50-
void const* productStorage() const;
51+
void const* productStorage() const { return product_; }
5152

5253
private:
5354
void const* product_;
@@ -56,6 +57,7 @@ namespace edm {
5657

5758
// Free swap function
5859
inline void swap(OrphanHandleBase& a, OrphanHandleBase& b) { a.swap(b); }
60+
5961
} // namespace edm
6062

61-
#endif
63+
#endif // DataFormats_Common_interface_OrphanHandleBase_h

DataFormats/Common/src/OrphanHandleBase.cc

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)