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 __gnu_cxx::hash_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 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_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_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 384 of file DQMNet.h.

Member Typedef Documentation

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

Definition at line 388 of file DQMNet.h.

template<class ObjType>
typedef __gnu_cxx::hash_set<ObjType, HashOp, HashEqual> DQMImplNet< ObjType >::ObjectMap

Definition at line 389 of file DQMNet.h.

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

Definition at line 390 of file DQMNet.h.

Constructor & Destructor Documentation

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

Definition at line 397 of file DQMNet.h.

397 : DQMNet(appname) {}
DQMNet(const std::string &appname="")
Definition: DQMNet.cc:897
template<class ObjType>
DQMImplNet< ObjType >::~DQMImplNet ( )
overridedefault

Member Function Documentation

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

Implements DQMNet.

Definition at line 491 of file DQMNet.h.

491  {
492  ImplPeer *ip = &peers_[s];
493  ip->socket = nullptr;
494  ip->sendq = nullptr;
495  ip->sendpos = 0;
496  ip->mask = 0;
497  ip->source = false;
498  ip->update = false;
499  ip->updated = false;
500  ip->updates = 0;
501  ip->waiting = 0;
502  ip->automatic = nullptr;
503  return ip;
504  }
PeerMap peers_
Definition: DQMNet.h:593
template<class ObjType>
Object* DQMImplNet< ObjType >::findObject ( Peer p,
const std::string &  name,
Peer **  owner = nullptr 
)
inlineoverrideprotectedvirtual

Implements DQMNet.

Definition at line 402 of file DQMNet.h.

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

Implements DQMNet.

Definition at line 485 of file DQMNet.h.

485  {
486  auto pos = peers_.find(s);
487  auto end = peers_.end();
488  return pos == end ? nullptr : &pos->second;
489  }
#define end
Definition: vmac.h:39
PeerMap peers_
Definition: DQMNet.h:593
template<class ObjType>
Object* DQMImplNet< ObjType >::makeObject ( Peer p,
const std::string &  name 
)
inlineoverrideprotectedvirtual

Implements DQMNet.

Definition at line 439 of file DQMNet.h.

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

Implements DQMNet.

Definition at line 462 of file DQMNet.h.

462  {
463  uint64_t minreq = (lat::Time::current() - lat::TimeSpan(0, 0, 5 /* minutes */, 0, 0)).ns();
464  auto *ip = static_cast<ImplPeer *>(p);
465  typename ObjectMap::iterator i, e;
466  for (i = ip->objs.begin(), e = ip->objs.end(); i != e; ++i) {
467  if (i->lastreq && i->lastreq < minreq)
468  const_cast<ObjType &>(*i).lastreq = 0;
469  const_cast<ObjType &>(*i).flags |= DQM_PROP_DEAD;
470  }
471  }
static const uint32_t DQM_PROP_DEAD
Definition: DQMNet.h:59
unsigned long long uint64_t
Definition: Time.h:13
template<class ObjType>
void DQMImplNet< ObjType >::purgeDeadObjects ( Peer p)
inlineoverrideprotectedvirtual

Implements DQMNet.

Definition at line 474 of file DQMNet.h.

474  {
475  auto *ip = static_cast<ImplPeer *>(p);
476  typename ObjectMap::iterator i, e;
477  for (i = ip->objs.begin(), e = ip->objs.end(); i != e;) {
478  if (i->flags & DQM_PROP_DEAD)
479  ip->objs.erase(i++);
480  else
481  ++i;
482  }
483  }
static const uint32_t DQM_PROP_DEAD
Definition: DQMNet.h:59
template<class ObjType>
void DQMImplNet< ObjType >::removePeer ( Peer p,
lat::Socket *  s 
)
inlineoverrideprotectedvirtual

Implements DQMNet.

Definition at line 506 of file DQMNet.h.

506  {
507  auto *ip = static_cast<ImplPeer *>(p);
508  bool needflush = !ip->objs.empty();
509 
510  typename ObjectMap::iterator i, e;
511  for (i = ip->objs.begin(), e = ip->objs.end(); i != e;)
512  ip->objs.erase(i++);
513 
514  peers_.erase(s);
515 
516  // If we removed a peer with objects, our list of objects
517  // has changed and we need to update downstream peers.
518  if (needflush)
520  }
void sendLocalChanges()
Definition: DQMNet.cc:1191
PeerMap peers_
Definition: DQMNet.h:593
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 523 of file DQMNet.h.

523  {
524  typename PeerMap::iterator pi, pe;
525  typename ObjectMap::iterator oi, oe;
526  size_t size = 0;
527  size_t numobjs = 0;
528  for (pi = peers_.begin(), pe = peers_.end(); pi != pe; ++pi)
529  for (oi = pi->second.objs.begin(), oe = pi->second.objs.end(); oi != oe; ++oi, ++numobjs)
530  if (all || (oi->flags & DQM_PROP_NEW))
531  size += 9 * sizeof(uint32_t) + oi->dirname->size() + oi->objname.size() + 1 + oi->scalar.size() +
532  oi->qdata.size() + (oi->lastreq > 0 ? oi->rawdata.size() : 0);
533 
534  msg->data.reserve(msg->data.size() + size + 8 * sizeof(uint32_t));
535 
536  uint32_t nupdates = 0;
537  uint32_t words[4];
538  words[0] = sizeof(words);
539  words[1] = DQM_REPLY_LIST_BEGIN;
540  words[2] = numobjs;
541  words[3] = all;
542  copydata(msg, &words[0], sizeof(words));
543 
544  for (pi = peers_.begin(), pe = peers_.end(); pi != pe; ++pi)
545  for (oi = pi->second.objs.begin(), oe = pi->second.objs.end(); oi != oe; ++oi)
546  if (all || (oi->flags & DQM_PROP_NEW)) {
547  sendObjectToPeer(msg, const_cast<ObjType &>(*oi), oi->lastreq > 0);
548  if (clear)
549  const_cast<ObjType &>(*oi).flags &= ~DQM_PROP_NEW;
550  ++nupdates;
551  }
552 
553  words[1] = DQM_REPLY_LIST_END;
554  words[2] = nupdates;
555  copydata(msg, &words[0], sizeof(words));
556  }
size
Write out results.
static const uint32_t DQM_REPLY_LIST_END
Definition: DQMNet.h:70
const Double_t pi
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
Definition: matutil.cc:151
virtual void sendObjectToPeer(Bucket *msg, Object &o, bool data)
Definition: DQMNet.cc:381
tuple msg
Definition: mps_check.py:285
static const uint32_t DQM_REPLY_LIST_BEGIN
Definition: DQMNet.h:69
static void copydata(Bucket *b, const void *data, size_t len)
Definition: DQMNet.cc:48
static const uint32_t DQM_PROP_NEW
Definition: DQMNet.h:56
PeerMap peers_
Definition: DQMNet.h:593
template<class ObjType>
void DQMImplNet< ObjType >::sendObjectListToPeers ( bool  all)
inlineoverrideprotectedvirtual

Implements DQMNet.

Definition at line 558 of file DQMNet.h.

558  {
559  typename PeerMap::iterator i, e;
560  typename ObjectMap::iterator oi, oe;
561  for (i = peers_.begin(), e = peers_.end(); i != e; ++i) {
562  ImplPeer &p = i->second;
563  if (!p.update)
564  continue;
565 
566  if (debug_)
567  logme() << "DEBUG: notifying " << p.peeraddr << std::endl;
568 
569  Bucket msg;
570  msg.next = nullptr;
571  sendObjectListToPeer(&msg, !p.updated || all, true);
572 
573  if (!msg.data.empty()) {
574  Bucket **prev = &p.sendq;
575  while (*prev)
576  prev = &(*prev)->next;
577 
578  *prev = new Bucket;
579  (*prev)->next = nullptr;
580  (*prev)->data.swap(msg.data);
581  }
582  p.updated = true;
583  }
584  }
std::ostream & logme()
Definition: DQMNet.cc:41
tuple msg
Definition: mps_check.py:285
void sendObjectListToPeer(Bucket *msg, bool all, bool clear) override
Send all objects to a peer and optionally mark sent objects old.
Definition: DQMNet.h:523
bool debug_
Definition: DQMNet.h:344
PeerMap peers_
Definition: DQMNet.h:593
template<class ObjType>
void DQMImplNet< ObjType >::updatePeerMasks ( )
inlineoverrideprotectedvirtual

Implements DQMNet.

Definition at line 586 of file DQMNet.h.

586  {
587  typename PeerMap::iterator i, e;
588  for (i = peers_.begin(), e = peers_.end(); i != e;)
589  updateMask(&(i++)->second);
590  }
void updateMask(Peer *p)
Definition: DQMNet.cc:871
PeerMap peers_
Definition: DQMNet.h:593

Member Data Documentation

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

Definition at line 593 of file DQMNet.h.