CMS 3D CMS Logo

List of all members | Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes
DQMImplNet< ObjType > Class Template Reference

#include <DQMNet.h>

Inheritance diagram for DQMImplNet< ObjType >:
DQMNet

Classes

struct  ImplPeer
 

Public Types

using DirMap = std::set< std::string >
 
typedef std::unordered_set< ObjType, HashOp, HashEqualObjectMap
 
typedef std::map< lat::Socket *, ImplPeerPeerMap
 
- Public Types inherited from DQMNet
using DataBlob = std::vector< unsigned char >
 
using QReports = std::vector< QValue >
 
using QValue = MonitorElementData::QReport::QValue
 
using TagList = std::vector< uint32_t >
 
using WaitList = std::list< WaitObject >
 

Public Member Functions

 DQMImplNet (const std::string &appname="")
 
 ~DQMImplNet () override=default
 
- Public Member Functions inherited from DQMNet
void debug (bool doit)
 
void delay (int delay)
 
 DQMNet (const std::string &appname="")
 
 DQMNet (const DQMNet &)=delete
 
void listenToCollector (const std::string &host, int port)
 
void lock ()
 Acquire a lock on the DQM net layer. More...
 
DQMNetoperator= (const DQMNet &)=delete
 
void run ()
 
void sendLocalChanges ()
 
void shutdown ()
 Stop the network layer and wait it to finish. More...
 
void staleObjectWaitLimit (lat::TimeSpan time)
 
void start ()
 
void startLocalServer (int port)
 
void startLocalServer (const char *path)
 
void unlock ()
 Release the lock on the DQM net layer. More...
 
void updateToCollector (const std::string &host, int port)
 
virtual ~DQMNet ()
 

Protected Member Functions

PeercreatePeer (lat::Socket *s) override
 
ObjectfindObject (Peer *p, const std::string &name, Peer **owner=nullptr) override
 
PeergetPeer (lat::Socket *s) override
 
ObjectmakeObject (Peer *p, const std::string &name) override
 
void markObjectsDead (Peer *p) override
 
void purgeDeadObjects (Peer *p) override
 
void removePeer (Peer *p, lat::Socket *s) override
 
void sendObjectListToPeer (Bucket *msg, bool all, bool clear) override
 Send all objects to a peer and optionally mark sent objects old. More...
 
void sendObjectListToPeers (bool all) override
 
void updatePeerMasks () override
 
- Protected Member Functions inherited from DQMNet
std::ostream & logme ()
 
virtual bool onMessage (Bucket *msg, Peer *p, unsigned char *data, size_t len)
 
virtual void releaseFromWait (Bucket *msg, WaitObject &w, Object *o)
 
virtual void sendObjectToPeer (Bucket *msg, Object &o, bool data)
 
virtual bool shouldStop ()
 
void updateMask (Peer *p)
 
void waitForData (Peer *p, const std::string &name, const std::string &info, Peer *owner)
 

Protected Attributes

PeerMap peers_
 
- Protected Attributes inherited from DQMNet
bool debug_
 
pthread_mutex_t lock_
 

Additional Inherited Members

- Static Public Member Functions inherited from DQMNet
static size_t dqmhash (const void *key, size_t keylen)
 
static void packQualityData (std::string &into, const QReports &qr)
 
static bool setOrder (const CoreObject &a, const CoreObject &b)
 
static void unpackQualityData (QReports &qr, uint32_t &flags, const char *from)
 
- Static Public Attributes inherited from DQMNet
static const uint32_t DQM_MSG_GET_OBJECT = 3
 
static const uint32_t DQM_MSG_HELLO = 0
 
static const uint32_t DQM_MSG_LIST_OBJECTS = 2
 
static const uint32_t DQM_MSG_UPDATE_ME = 1
 
static const uint32_t DQM_PROP_ACCUMULATE = 0x00004000
 
static const uint32_t DQM_PROP_DEAD = 0x00080000
 
static const uint32_t DQM_PROP_EFFICIENCY_PLOT = 0x00200000
 
static const uint32_t DQM_PROP_HAS_REFERENCE = 0x00001000
 
static const uint32_t DQM_PROP_LUMI = 0x00040000
 
static const uint32_t DQM_PROP_MARKTODELETE = 0x01000000
 
static const uint32_t DQM_PROP_NEW = 0x00010000
 
static const uint32_t DQM_PROP_RECEIVED = 0x00020000
 
static const uint32_t DQM_PROP_REPORT_ALARM = (DQM_PROP_REPORT_ERROR | DQM_PROP_REPORT_WARN | DQM_PROP_REPORT_OTHER)
 
static const uint32_t DQM_PROP_REPORT_CLEAR = 0x00000000
 
static const uint32_t DQM_PROP_REPORT_ERROR = 0x00000100
 
static const uint32_t DQM_PROP_REPORT_MASK = 0x00000f00
 
static const uint32_t DQM_PROP_REPORT_OTHER = 0x00000400
 
static const uint32_t DQM_PROP_REPORT_WARN = 0x00000200
 
static const uint32_t DQM_PROP_RESET = 0x00008000
 
static const uint32_t DQM_PROP_STALE = 0x00100000
 
static const uint32_t DQM_PROP_TAGGED = 0x00002000
 
static const uint32_t DQM_PROP_TYPE_DATABLOB = 0x00000050
 
static const uint32_t DQM_PROP_TYPE_INT = 0x00000001
 
static const uint32_t DQM_PROP_TYPE_INVALID = 0x00000000
 
static const uint32_t DQM_PROP_TYPE_MASK = 0x000000ff
 
static const uint32_t DQM_PROP_TYPE_REAL = 0x00000002
 
static const uint32_t DQM_PROP_TYPE_SCALAR = 0x0000000f
 
static const uint32_t DQM_PROP_TYPE_STRING = 0x00000003
 
static const uint32_t DQM_PROP_TYPE_TH1D = 0x00000012
 
static const uint32_t DQM_PROP_TYPE_TH1F = 0x00000010
 
static const uint32_t DQM_PROP_TYPE_TH1I = 0x00000013
 
static const uint32_t DQM_PROP_TYPE_TH1S = 0x00000011
 
static const uint32_t DQM_PROP_TYPE_TH2D = 0x00000022
 
static const uint32_t DQM_PROP_TYPE_TH2F = 0x00000020
 
static const uint32_t DQM_PROP_TYPE_TH2I = 0x00000023
 
static const uint32_t DQM_PROP_TYPE_TH2S = 0x00000021
 
static const uint32_t DQM_PROP_TYPE_TH3D = 0x00000032
 
static const uint32_t DQM_PROP_TYPE_TH3F = 0x00000030
 
static const uint32_t DQM_PROP_TYPE_TH3S = 0x00000031
 
static const uint32_t DQM_PROP_TYPE_TPROF = 0x00000040
 
static const uint32_t DQM_PROP_TYPE_TPROF2D = 0x00000041
 
static const uint32_t DQM_REPLY_LIST_BEGIN = 101
 
static const uint32_t DQM_REPLY_LIST_END = 102
 
static const uint32_t DQM_REPLY_NONE = 103
 
static const uint32_t DQM_REPLY_OBJECT = 104
 
static const uint32_t MAX_PEER_WAITREQS = 128
 
- Static Protected Member Functions inherited from DQMNet
static void copydata (Bucket *b, const void *data, size_t len)
 
static void discard (Bucket *&b)
 

Detailed Description

template<class ObjType>
class DQMImplNet< ObjType >

Definition at line 380 of file DQMNet.h.

Member Typedef Documentation

◆ DirMap

template<class ObjType>
using DQMImplNet< ObjType >::DirMap = std::set<std::string>

Definition at line 384 of file DQMNet.h.

◆ ObjectMap

template<class ObjType>
typedef std::unordered_set<ObjType, HashOp, HashEqual> DQMImplNet< ObjType >::ObjectMap

Definition at line 385 of file DQMNet.h.

◆ PeerMap

template<class ObjType>
typedef std::map<lat::Socket *, ImplPeer> DQMImplNet< ObjType >::PeerMap

Definition at line 386 of file DQMNet.h.

Constructor & Destructor Documentation

◆ DQMImplNet()

template<class ObjType>
DQMImplNet< ObjType >::DQMImplNet ( const std::string &  appname = "")
inline

Definition at line 393 of file DQMNet.h.

393 : DQMNet(appname) {}
DQMNet(const std::string &appname="")
Definition: DQMNet.cc:910

◆ ~DQMImplNet()

template<class ObjType>
DQMImplNet< ObjType >::~DQMImplNet ( )
overridedefault

Member Function Documentation

◆ createPeer()

template<class ObjType>
Peer* DQMImplNet< ObjType >::createPeer ( lat::Socket *  s)
inlineoverrideprotectedvirtual

Implements DQMNet.

Definition at line 487 of file DQMNet.h.

487  {
488  ImplPeer *ip = &peers_[s];
489  ip->socket = nullptr;
490  ip->sendq = nullptr;
491  ip->sendpos = 0;
492  ip->mask = 0;
493  ip->source = false;
494  ip->update = false;
495  ip->updated = false;
496  ip->updates = 0;
497  ip->waiting = 0;
498  ip->automatic = nullptr;
499  return ip;
500  }
PeerMap peers_
Definition: DQMNet.h:589

◆ findObject()

template<class ObjType>
Object* DQMImplNet< ObjType >::findObject ( Peer p,
const std::string &  name,
Peer **  owner = nullptr 
)
inlineoverrideprotectedvirtual

Implements DQMNet.

Definition at line 398 of file DQMNet.h.

398  {
399  size_t slash = name.rfind('/');
400  size_t dirpos = (slash == std::string::npos ? 0 : slash);
401  size_t namepos = (slash == std::string::npos ? 0 : slash + 1);
402  std::string path(name, 0, dirpos);
403  ObjType proto;
404  proto.hash = dqmhash(name.c_str(), name.size());
405  proto.dirname = path;
406  proto.objname.append(name, namepos, std::string::npos);
407 
408  typename ObjectMap::iterator pos;
409  typename PeerMap::iterator i, e;
410  if (owner)
411  *owner = nullptr;
412  if (p) {
413  auto *ip = static_cast<ImplPeer *>(p);
414  pos = ip->objs.find(proto);
415  if (pos == ip->objs.end())
416  return nullptr;
417  else {
418  if (owner)
419  *owner = ip;
420  return const_cast<ObjType *>(&*pos);
421  }
422  } else {
423  for (i = peers_.begin(), e = peers_.end(); i != e; ++i) {
424  pos = i->second.objs.find(proto);
425  if (pos != i->second.objs.end()) {
426  if (owner)
427  *owner = &i->second;
428  return const_cast<ObjType *>(&*pos);
429  }
430  }
431  return nullptr;
432  }
433  }
static size_t dqmhash(const void *key, size_t keylen)
Definition: DQMNet.h:195
PeerMap peers_
Definition: DQMNet.h:589

◆ getPeer()

template<class ObjType>
Peer* DQMImplNet< ObjType >::getPeer ( lat::Socket *  s)
inlineoverrideprotectedvirtual

Implements DQMNet.

Definition at line 481 of file DQMNet.h.

481  {
482  auto pos = peers_.find(s);
483  auto end = peers_.end();
484  return pos == end ? nullptr : &pos->second;
485  }
PeerMap peers_
Definition: DQMNet.h:589

◆ makeObject()

template<class ObjType>
Object* DQMImplNet< ObjType >::makeObject ( Peer p,
const std::string &  name 
)
inlineoverrideprotectedvirtual

Implements DQMNet.

Definition at line 435 of file DQMNet.h.

435  {
436  auto *ip = static_cast<ImplPeer *>(p);
437  size_t slash = name.rfind('/');
438  size_t dirpos = (slash == std::string::npos ? 0 : slash);
439  size_t namepos = (slash == std::string::npos ? 0 : slash + 1);
440  ObjType o;
441  o.flags = 0;
442  o.tag = 0;
443  o.version = 0;
444  o.lastreq = 0;
445  o.dirname = *ip->dirs.insert(name.substr(0, dirpos)).first;
446  o.objname.append(name, namepos, std::string::npos);
447  o.hash = dqmhash(name.c_str(), name.size());
448  return const_cast<ObjType *>(&*ip->objs.insert(o).first);
449  }
static size_t dqmhash(const void *key, size_t keylen)
Definition: DQMNet.h:195

◆ markObjectsDead()

template<class ObjType>
void DQMImplNet< ObjType >::markObjectsDead ( Peer p)
inlineoverrideprotectedvirtual

Implements DQMNet.

Definition at line 458 of file DQMNet.h.

458  {
459  uint64_t minreq = (lat::Time::current() - lat::TimeSpan(0, 0, 5 /* minutes */, 0, 0)).ns();
460  auto *ip = static_cast<ImplPeer *>(p);
461  typename ObjectMap::iterator i, e;
462  for (i = ip->objs.begin(), e = ip->objs.end(); i != e; ++i) {
463  if (i->lastreq && i->lastreq < minreq)
464  const_cast<ObjType &>(*i).lastreq = 0;
465  const_cast<ObjType &>(*i).flags |= DQM_PROP_DEAD;
466  }
467  }
static const uint32_t DQM_PROP_DEAD
Definition: DQMNet.h:63
unsigned long long uint64_t
Definition: Time.h:13

◆ purgeDeadObjects()

template<class ObjType>
void DQMImplNet< ObjType >::purgeDeadObjects ( Peer p)
inlineoverrideprotectedvirtual

Implements DQMNet.

Definition at line 470 of file DQMNet.h.

470  {
471  auto *ip = static_cast<ImplPeer *>(p);
472  typename ObjectMap::iterator i, e;
473  for (i = ip->objs.begin(), e = ip->objs.end(); i != e;) {
474  if (i->flags & DQM_PROP_DEAD)
475  ip->objs.erase(i++);
476  else
477  ++i;
478  }
479  }
static const uint32_t DQM_PROP_DEAD
Definition: DQMNet.h:63

◆ removePeer()

template<class ObjType>
void DQMImplNet< ObjType >::removePeer ( Peer p,
lat::Socket *  s 
)
inlineoverrideprotectedvirtual

Implements DQMNet.

Definition at line 502 of file DQMNet.h.

502  {
503  auto *ip = static_cast<ImplPeer *>(p);
504  bool needflush = !ip->objs.empty();
505 
506  typename ObjectMap::iterator i, e;
507  for (i = ip->objs.begin(), e = ip->objs.end(); i != e;)
508  ip->objs.erase(i++);
509 
510  peers_.erase(s);
511 
512  // If we removed a peer with objects, our list of objects
513  // has changed and we need to update downstream peers.
514  if (needflush)
516  }
void sendLocalChanges()
Definition: DQMNet.cc:1199
PeerMap peers_
Definition: DQMNet.h:589

◆ sendObjectListToPeer()

template<class ObjType>
void DQMImplNet< ObjType >::sendObjectListToPeer ( Bucket msg,
bool  all,
bool  clear 
)
inlineoverrideprotectedvirtual

Send all objects to a peer and optionally mark sent objects old.

Implements DQMNet.

Definition at line 519 of file DQMNet.h.

Referenced by DQMImplNet< DQMNet::Object >::sendObjectListToPeers().

519  {
520  typename PeerMap::iterator pi, pe;
521  typename ObjectMap::iterator oi, oe;
522  size_t size = 0;
523  size_t numobjs = 0;
524  for (pi = peers_.begin(), pe = peers_.end(); pi != pe; ++pi)
525  for (oi = pi->second.objs.begin(), oe = pi->second.objs.end(); oi != oe; ++oi, ++numobjs)
526  if (all || (oi->flags & DQM_PROP_NEW))
527  size += 9 * sizeof(uint32_t) + oi->dirname.size() + oi->objname.size() + 1 + oi->scalar.size() +
528  oi->qdata.size() + (oi->lastreq > 0 ? oi->rawdata.size() : 0);
529 
530  msg->data.reserve(msg->data.size() + size + 8 * sizeof(uint32_t));
531 
532  uint32_t nupdates = 0;
533  uint32_t words[4];
534  words[0] = sizeof(words);
535  words[1] = DQM_REPLY_LIST_BEGIN;
536  words[2] = numobjs;
537  words[3] = all;
538  copydata(msg, &words[0], sizeof(words));
539 
540  for (pi = peers_.begin(), pe = peers_.end(); pi != pe; ++pi)
541  for (oi = pi->second.objs.begin(), oe = pi->second.objs.end(); oi != oe; ++oi)
542  if (all || (oi->flags & DQM_PROP_NEW)) {
543  sendObjectToPeer(msg, const_cast<ObjType &>(*oi), oi->lastreq > 0);
544  if (clear)
545  const_cast<ObjType &>(*oi).flags &= ~DQM_PROP_NEW;
546  ++nupdates;
547  }
548 
549  words[1] = DQM_REPLY_LIST_END;
550  words[2] = nupdates;
551  copydata(msg, &words[0], sizeof(words));
552  }
size
Write out results.
def all(container)
workaround iterator generators for ROOT classes
Definition: cmstools.py:25
static const uint32_t DQM_REPLY_LIST_END
Definition: DQMNet.h:74
const Double_t pi
virtual void sendObjectToPeer(Bucket *msg, Object &o, bool data)
Definition: DQMNet.cc:394
tuple msg
Definition: mps_check.py:286
static const uint32_t DQM_REPLY_LIST_BEGIN
Definition: DQMNet.h:73
static void copydata(Bucket *b, const void *data, size_t len)
Definition: DQMNet.cc:53
static const uint32_t DQM_PROP_NEW
Definition: DQMNet.h:60
void clear(EGIsoObj &c)
Definition: egamma.h:82
PeerMap peers_
Definition: DQMNet.h:589

◆ sendObjectListToPeers()

template<class ObjType>
void DQMImplNet< ObjType >::sendObjectListToPeers ( bool  all)
inlineoverrideprotectedvirtual

Implements DQMNet.

Definition at line 554 of file DQMNet.h.

554  {
555  typename PeerMap::iterator i, e;
556  typename ObjectMap::iterator oi, oe;
557  for (i = peers_.begin(), e = peers_.end(); i != e; ++i) {
558  ImplPeer &p = i->second;
559  if (!p.update)
560  continue;
561 
562  if (debug_)
563  logme() << "DEBUG: notifying " << p.peeraddr << std::endl;
564 
565  Bucket msg;
566  msg.next = nullptr;
567  sendObjectListToPeer(&msg, !p.updated || all, true);
568 
569  if (!msg.data.empty()) {
570  Bucket **prev = &p.sendq;
571  while (*prev)
572  prev = &(*prev)->next;
573 
574  *prev = new Bucket;
575  (*prev)->next = nullptr;
576  (*prev)->data.swap(msg.data);
577  }
578  p.updated = true;
579  }
580  }
def all(container)
workaround iterator generators for ROOT classes
Definition: cmstools.py:25
std::ostream & logme()
Definition: DQMNet.cc:46
tuple msg
Definition: mps_check.py:286
void sendObjectListToPeer(Bucket *msg, bool all, bool clear) override
Send all objects to a peer and optionally mark sent objects old.
Definition: DQMNet.h:519
bool debug_
Definition: DQMNet.h:340
PeerMap peers_
Definition: DQMNet.h:589

◆ updatePeerMasks()

template<class ObjType>
void DQMImplNet< ObjType >::updatePeerMasks ( )
inlineoverrideprotectedvirtual

Implements DQMNet.

Definition at line 582 of file DQMNet.h.

582  {
583  typename PeerMap::iterator i, e;
584  for (i = peers_.begin(), e = peers_.end(); i != e;)
585  updateMask(&(i++)->second);
586  }
void updateMask(Peer *p)
Definition: DQMNet.cc:884
PeerMap peers_
Definition: DQMNet.h:589

Member Data Documentation

◆ peers_

template<class ObjType>
PeerMap DQMImplNet< ObjType >::peers_
protected