CMS 3D CMS Logo

LHEProxy.cc
Go to the documentation of this file.
1 #include <map>
2 
3 #include <boost/thread.hpp>
4 
6 
7 using namespace lhef;
8 
10 
11 typedef std::map<LHEProxy::ProxyID, std::weak_ptr<LHEProxy> > ProxyMap;
12 
14  static struct Sentinel {
15  Sentinel() : instance(new ProxyMap) {}
16  ~Sentinel() {
17  delete instance;
18  instance = nullptr;
19  }
20 
22  } sentinel;
23 
24  return sentinel.instance;
25 }
26 
28 
30  boost::mutex::scoped_lock scoped_lock(mutex);
31 
33  if (map)
34  map->erase(id);
35 }
36 
37 std::shared_ptr<LHEProxy> LHEProxy::create() {
38  static LHEProxy::ProxyID nextProxyID = 0;
39 
40  boost::mutex::scoped_lock scoped_lock(mutex);
41 
42  std::shared_ptr<LHEProxy> proxy(new LHEProxy(++nextProxyID));
43 
45  if (map)
46  map->insert(ProxyMap::value_type(proxy->getID(), proxy));
47 
48  return proxy;
49 }
50 
51 std::shared_ptr<LHEProxy> LHEProxy::find(ProxyID id) {
52  boost::mutex::scoped_lock scoped_lock(mutex);
53 
55  if (!map)
56  return std::shared_ptr<LHEProxy>();
57 
58  ProxyMap::const_iterator pos = map->find(id);
59  if (pos == map->end())
60  return std::shared_ptr<LHEProxy>();
61 
62  return std::shared_ptr<LHEProxy>(pos->second);
63 }
lhef::LHEProxy::LHEProxy
LHEProxy(ProxyID id)
Definition: LHEProxy.cc:27
getProxyMapInstance
static ProxyMap * getProxyMapInstance()
Definition: LHEProxy.cc:13
pos
Definition: PixelAliasList.h:18
LHEProxy.h
lhef::LHEProxy::~LHEProxy
~LHEProxy()
Definition: LHEProxy.cc:29
ProxyMap
std::map< LHEProxy::ProxyID, std::weak_ptr< LHEProxy > > ProxyMap
Definition: LHEProxy.cc:11
lhef::LHEProxy::create
static std::shared_ptr< LHEProxy > create()
Definition: LHEProxy.cc:37
mutex
static boost::mutex mutex
Definition: LHEProxy.cc:9
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:11
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:51