test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
LHEProxy.cc
Go to the documentation of this file.
1 #include <map>
2 
3 #include <boost/thread.hpp>
4 #include <boost/shared_ptr.hpp>
5 #include <boost/weak_ptr.hpp>
6 
8 
9 using namespace lhef;
10 
12 
13 typedef std::map< LHEProxy::ProxyID, boost::weak_ptr<LHEProxy> > ProxyMap;
14 
16 {
17  static struct Sentinel {
18  Sentinel() : instance(new ProxyMap) {}
19  ~Sentinel() { delete instance; instance = 0; }
20 
22  } sentinel;
23 
24  return sentinel.instance;
25 }
26 
28  id(id)
29 {
30 }
31 
33 {
34  boost::mutex::scoped_lock scoped_lock(mutex);
35 
37  if (map)
38  map->erase(id);
39 }
40 
41 boost::shared_ptr<LHEProxy> LHEProxy::create()
42 {
43  static LHEProxy::ProxyID nextProxyID = 0;
44 
45  boost::mutex::scoped_lock scoped_lock(mutex);
46 
47  boost::shared_ptr<LHEProxy> proxy(new LHEProxy(++nextProxyID));
48 
50  if (map)
51  map->insert(ProxyMap::value_type(proxy->getID(), proxy));
52 
53  return proxy;
54 }
55 
56 boost::shared_ptr<LHEProxy> LHEProxy::find(ProxyID id)
57 {
58  boost::mutex::scoped_lock scoped_lock(mutex);
59 
61  if (!map)
62  return boost::shared_ptr<LHEProxy>();
63 
64  ProxyMap::const_iterator pos = map->find(id);
65  if (pos == map->end())
66  return boost::shared_ptr<LHEProxy>();
67 
68  return boost::shared_ptr<LHEProxy>(pos->second);
69 }
static boost::mutex mutex
Definition: LHEProxy.cc:11
static PFTauRenderPlugin instance
LHEProxy(ProxyID id)
Definition: LHEProxy.cc:27
static ProxyMap * getProxyMapInstance()
Definition: LHEProxy.cc:15
unsigned long ProxyID
Definition: LHEProxy.h:14
std::map< LHEProxy::ProxyID, boost::weak_ptr< LHEProxy > > ProxyMap
Definition: LHEProxy.cc:13
static boost::shared_ptr< LHEProxy > find(ProxyID id)
Definition: LHEProxy.cc:56
static boost::shared_ptr< LHEProxy > create()
Definition: LHEProxy.cc:41