CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
26 LHEProxy::LHEProxy(ProxyID id) : id(id) {}
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 }
LHEProxy(const LHEProxy &orig)=delete
static PFTauRenderPlugin instance
std::map< ProxyBase::ProxyID, std::weak_ptr< ProxyBase > > ProxyMap
Definition: Proxy.cc:10
static std::shared_ptr< LHEProxy > find(ProxyID id)
Definition: LHEProxy.cc:50
static std::shared_ptr< LHEProxy > create()
Definition: LHEProxy.cc:36
static ProxyMap * getProxyMapInstance()
Definition: LHEProxy.cc:12
unsigned long ProxyID
Definition: LHEProxy.h:14
static std::mutex mutex
Definition: LHEProxy.cc:8