CMS 3D CMS Logo

LHEProxy.cc
Go to the documentation of this file.
1 #include <map>
2 #include <mutex>
3 
5 
6 using namespace lhef;
7 
9 
10 typedef std::map<LHEProxy::ProxyID, std::weak_ptr<LHEProxy> > ProxyMap;
11 
13  static struct Sentinel {
14  Sentinel() : instance(new ProxyMap) {}
15  ~Sentinel() {
16  delete instance;
17  instance = nullptr;
18  }
19 
21  } sentinel;
22 
23  return sentinel.instance;
24 }
25 
27 
29  std::scoped_lock scoped_lock(mutex);
30 
32  if (map)
33  map->erase(id);
34 }
35 
36 std::shared_ptr<LHEProxy> LHEProxy::create() {
37  static LHEProxy::ProxyID nextProxyID = 0;
38 
39  std::scoped_lock scoped_lock(mutex);
40 
41  std::shared_ptr<LHEProxy> proxy(new LHEProxy(++nextProxyID));
42 
44  if (map)
45  map->insert(ProxyMap::value_type(proxy->getID(), proxy));
46 
47  return proxy;
48 }
49 
50 std::shared_ptr<LHEProxy> LHEProxy::find(ProxyID id) {
51  std::scoped_lock scoped_lock(mutex);
52 
54  if (!map)
55  return std::shared_ptr<LHEProxy>();
56 
57  ProxyMap::const_iterator pos = map->find(id);
58  if (pos == map->end())
59  return std::shared_ptr<LHEProxy>();
60 
61  return std::shared_ptr<LHEProxy>(pos->second);
62 }
lhef::LHEProxy::LHEProxy
LHEProxy(ProxyID id)
Definition: LHEProxy.cc:26
getProxyMapInstance
static ProxyMap * getProxyMapInstance()
Definition: LHEProxy.cc:12
pos
Definition: PixelAliasList.h:18
mutex
static std::mutex mutex
Definition: LHEProxy.cc:8
LHEProxy.h
lhef::LHEProxy::~LHEProxy
~LHEProxy()
Definition: LHEProxy.cc:28
ProxyMap
std::map< LHEProxy::ProxyID, std::weak_ptr< LHEProxy > > ProxyMap
Definition: LHEProxy.cc:10
lhef::LHEProxy::create
static std::shared_ptr< LHEProxy > create()
Definition: LHEProxy.cc:36
lhef
Definition: ExhumeHadronizer.h:12
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition: JetExtendedAssociation.h:30
instance
static PFTauRenderPlugin instance
Definition: PFTauRenderPlugin.cc:70
lhef::LHEProxy::ProxyID
unsigned long ProxyID
Definition: LHEProxy.h:14
ProxyMap
std::map< ProxyBase::ProxyID, std::weak_ptr< ProxyBase > > ProxyMap
Definition: Proxy.cc:10
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
genParticles_cff.map
map
Definition: genParticles_cff.py:11
lhef::LHEProxy::find
static std::shared_ptr< LHEProxy > find(ProxyID id)
Definition: LHEProxy.cc:50