CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DiscardManager.cc
Go to the documentation of this file.
1 // $Id: DiscardManager.cc,v 1.7 2011/04/07 08:01:40 mommsen Exp $
3 
9 
11 
12 #include "toolbox/mem/HeapAllocator.h"
13 #include "toolbox/mem/MemoryPoolFactory.h"
14 #include "toolbox/net/URN.h"
15 
16 
17 namespace stor {
18 
20  (
21  xdaq::ApplicationContext* ctx,
22  xdaq::ApplicationDescriptor* desc,
24  ):
25  appContext_(ctx),
26  appDescriptor_(desc),
27  dataSenderMonCollection_(dsmc)
28  {
29  std::ostringstream poolName;
30  poolName << desc->getClassName() << desc->getInstance();
31  toolbox::net::URN urn("toolbox-mem-pool", poolName.str());
32  toolbox::mem::HeapAllocator* a = new toolbox::mem::HeapAllocator();
33 
34  msgPool_ = toolbox::mem::getMemoryPoolFactory()->createPool(urn, a);
35  }
36 
38  {
39  proxyCache_.clear();
40  }
41 
43  {
44  if (i2oMessage.messageCode() == Header::INVALID)
45  {
47  return false;
48  }
49 
50  unsigned int rbBufferId = i2oMessage.rbBufferId();
51  std::string hltClassName = i2oMessage.hltClassName();
52  unsigned int hltInstance = i2oMessage.hltInstance();
53  FUProxyPtr fuProxyPtr = getProxyFromCache(hltClassName, hltInstance);
54  if (fuProxyPtr.get() == 0)
55  {
57  std::stringstream msg;
58  msg << "Unable to find the resource broker corresponding to ";
59  msg << "classname = \"";
60  msg << hltClassName;
61  msg << "\" and instance = \"";
62  msg << hltInstance;
63  msg << "\".";
64  XCEPT_RAISE(exception::RBLookupFailed, msg.str());
65  }
66  else
67  {
68  if (i2oMessage.messageCode() == Header::DQM_EVENT)
69  {
70  fuProxyPtr->sendDQMDiscard(rbBufferId);
72  }
73  else
74  {
75  fuProxyPtr->sendDataDiscard(rbBufferId);
77  }
78  }
79 
80  return true;
81  }
82 
85  (
86  std::string const& hltClassName,
87  unsigned int const& hltInstance
88  )
89  {
90  HLTSenderKey mapKey = std::make_pair(hltClassName, hltInstance);
91  FUProxyMap::iterator pos = proxyCache_.lower_bound(mapKey);
92 
93  if (pos == proxyCache_.end() || (proxyCache_.key_comp()(mapKey, pos->first)))
94  {
95  // Use pos as a hint to insert a new record, so it can avoid another lookup
96  FUProxyPtr fuProxyPtr = makeNewFUProxy(hltClassName, hltInstance);
97  if (fuProxyPtr.get() != 0)
98  pos = proxyCache_.insert(pos, FUProxyMap::value_type(mapKey, fuProxyPtr));
99 
100  return fuProxyPtr;
101  }
102  else
103  {
104  return pos->second;
105  }
106  }
107 
110  (
111  std::string const& hltClassName,
112  unsigned int const& hltInstance
113  )
114  {
115  FUProxyPtr proxyPtr;
116  std::set<xdaq::ApplicationDescriptor*> setOfRBs=
117  appContext_->getDefaultZone()->
118  getApplicationDescriptors(hltClassName.c_str());
119 
120  std::set<xdaq::ApplicationDescriptor*>::iterator iter;
121  std::set<xdaq::ApplicationDescriptor*>::iterator iterEnd = setOfRBs.end();
122 
123  for (iter = setOfRBs.begin(); iter != iterEnd; ++iter)
124  {
125  if ((*iter)->getInstance() == hltInstance)
126  {
127  proxyPtr.reset(new FUProxy(appDescriptor_, *iter,
128  appContext_, msgPool_));
129  break;
130  }
131  }
132 
133  return proxyPtr;
134  }
135 
136 } // namespace stor
137 
138 
std::pair< std::string, unsigned int > HLTSenderKey
std::string hltClassName() const
Definition: I2OChain.cc:260
FUProxyPtr getProxyFromCache(std::string const &hltClassName, unsigned int const &hltInstance)
unsigned int messageCode() const
Definition: I2OChain.cc:218
unsigned int hltInstance() const
Definition: I2OChain.cc:242
boost::shared_ptr< FUProxy > FUProxyPtr
FUProxyPtr makeNewFUProxy(std::string const &hltClassName, unsigned int const &hltInstance)
Container::value_type value_type
unsigned int rbBufferId() const
Definition: I2OChain.cc:230
double a
Definition: hdecay.h:121
DiscardManager(xdaq::ApplicationContext *, xdaq::ApplicationDescriptor *, DataSenderMonitorCollection &)
DataSenderMonitorCollection & dataSenderMonCollection_
bool sendDiscardMessage(I2OChain const &)