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
 
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 361 of file DQMNet.h.

Member Typedef Documentation

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

Definition at line 366 of file DQMNet.h.

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

Definition at line 367 of file DQMNet.h.

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

Definition at line 368 of file DQMNet.h.

Constructor & Destructor Documentation

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

Definition at line 376 of file DQMNet.h.

377  : DQMNet(appname)
378  {}
DQMNet(const std::string &appname="")
Definition: DQMNet.cc:1069
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 492 of file DQMNet.h.

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

Implements DQMNet.

Definition at line 385 of file DQMNet.h.

386  {
387  size_t slash = name.rfind('/');
388  size_t dirpos = (slash == std::string::npos ? 0 : slash);
389  size_t namepos = (slash == std::string::npos ? 0 : slash+1);
390  std::string path(name, 0, dirpos);
391  ObjType proto;
392  proto.hash = dqmhash(name.c_str(), name.size());
393  proto.dirname = &path;
394  proto.objname.append(name, namepos, std::string::npos);
395 
396  typename ObjectMap::iterator pos;
397  typename PeerMap::iterator i, e;
398  if (owner)
399  *owner = nullptr;
400  if (p)
401  {
402  auto *ip = static_cast<ImplPeer *>(p);
403  pos = ip->objs.find(proto);
404  if (pos == ip->objs.end())
405  return nullptr;
406  else
407  {
408  if (owner) *owner = ip;
409  return const_cast<ObjType *>(&*pos);
410  }
411  }
412  else
413  {
414  for (i = peers_.begin(), e = peers_.end(); i != e; ++i)
415  {
416  pos = i->second.objs.find(proto);
417  if (pos != i->second.objs.end())
418  {
419  if (owner) *owner = &i->second;
420  return const_cast<ObjType *>(&*pos);
421  }
422  }
423  return nullptr;
424  }
425  }
static size_t dqmhash(const void *key, size_t keylen)
Definition: DQMNet.h:217
PeerMap peers_
Definition: DQMNet.h:608
template<class ObjType>
Peer* DQMImplNet< ObjType >::getPeer ( lat::Socket *  s)
inlineoverrideprotectedvirtual

Implements DQMNet.

Definition at line 484 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:608
template<class ObjType>
Object* DQMImplNet< ObjType >::makeObject ( Peer p,
const std::string &  name 
)
inlineoverrideprotectedvirtual

Implements DQMNet.

Definition at line 428 of file DQMNet.h.

429  {
430  auto *ip = static_cast<ImplPeer *>(p);
431  size_t slash = name.rfind('/');
432  size_t dirpos = (slash == std::string::npos ? 0 : slash);
433  size_t namepos = (slash == std::string::npos ? 0 : slash+1);
434  ObjType o;
435  o.flags = 0;
436  o.tag = 0;
437  o.version = 0;
438  o.lastreq = 0;
439  o.dirname = &*ip->dirs.insert(name.substr(0, dirpos)).first;
440  o.objname.append(name, namepos, std::string::npos);
441  o.hash = dqmhash(name.c_str(), name.size());
442  return const_cast<ObjType *>(&*ip->objs.insert(o).first);
443  }
static size_t dqmhash(const void *key, size_t keylen)
Definition: DQMNet.h:217
template<class ObjType>
void DQMImplNet< ObjType >::markObjectsDead ( Peer p)
inlineoverrideprotectedvirtual

Implements DQMNet.

Definition at line 453 of file DQMNet.h.

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

Implements DQMNet.

Definition at line 470 of file DQMNet.h.

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

Implements DQMNet.

Definition at line 509 of file DQMNet.h.

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

529  {
530  typename PeerMap::iterator pi, pe;
531  typename ObjectMap::iterator oi, oe;
532  size_t size = 0;
533  size_t numobjs = 0;
534  for (pi = peers_.begin(), pe = peers_.end(); pi != pe; ++pi)
535  for (oi = pi->second.objs.begin(), oe = pi->second.objs.end(); oi != oe; ++oi, ++numobjs)
536  if (all || (oi->flags & DQM_PROP_NEW))
537  size += 9*sizeof(uint32_t) + oi->dirname->size()
538  + oi->objname.size() + 1 + oi->scalar.size() + oi->qdata.size()
539  + (oi->lastreq > 0 ? oi->rawdata.size() : 0);
540 
541  msg->data.reserve(msg->data.size() + size + 8 * sizeof(uint32_t));
542 
543  uint32_t nupdates = 0;
544  uint32_t words [4];
545  words[0] = sizeof(words);
546  words[1] = DQM_REPLY_LIST_BEGIN;
547  words[2] = numobjs;
548  words[3] = all;
549  copydata(msg, &words[0], sizeof(words));
550 
551  for (pi = peers_.begin(), pe = peers_.end(); pi != pe; ++pi)
552  for (oi = pi->second.objs.begin(), oe = pi->second.objs.end(); oi != oe; ++oi)
553  if (all || (oi->flags & DQM_PROP_NEW))
554  {
555  sendObjectToPeer(msg, const_cast<ObjType &>(*oi), oi->lastreq > 0);
556  if (clear)
557  const_cast<ObjType &>(*oi).flags &= ~DQM_PROP_NEW;
558  ++nupdates;
559  }
560 
561  words[1] = DQM_REPLY_LIST_END;
562  words[2] = nupdates;
563  copydata(msg, &words[0], sizeof(words));
564  }
size
Write out results.
static const uint32_t DQM_REPLY_LIST_END
Definition: DQMNet.h:73
const Double_t pi
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
Definition: matutil.cc:167
virtual void sendObjectToPeer(Bucket *msg, Object &o, bool data)
Definition: DQMNet.cc:418
tuple msg
Definition: mps_check.py:279
static const uint32_t DQM_REPLY_LIST_BEGIN
Definition: DQMNet.h:72
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:59
PeerMap peers_
Definition: DQMNet.h:608
template<class ObjType>
void DQMImplNet< ObjType >::sendObjectListToPeers ( bool  all)
inlineoverrideprotectedvirtual

Implements DQMNet.

Definition at line 567 of file DQMNet.h.

568  {
569  typename PeerMap::iterator i, e;
570  typename ObjectMap::iterator oi, oe;
571  for (i = peers_.begin(), e = peers_.end(); i != e; ++i)
572  {
573  ImplPeer &p = i->second;
574  if (! p.update)
575  continue;
576 
577  if (debug_)
578  logme()
579  << "DEBUG: notifying " << p.peeraddr << std::endl;
580 
581  Bucket msg;
582  msg.next = nullptr;
583  sendObjectListToPeer(&msg, !p.updated || all, true);
584 
585  if (! msg.data.empty())
586  {
587  Bucket **prev = &p.sendq;
588  while (*prev)
589  prev = &(*prev)->next;
590 
591  *prev = new Bucket;
592  (*prev)->next = nullptr;
593  (*prev)->data.swap(msg.data);
594  }
595  p.updated = true;
596  }
597  }
std::ostream & logme()
Definition: DQMNet.cc:42
tuple msg
Definition: mps_check.py:279
void sendObjectListToPeer(Bucket *msg, bool all, bool clear) override
Send all objects to a peer and optionally mark sent objects old.
Definition: DQMNet.h:528
bool debug_
Definition: DQMNet.h:318
PeerMap peers_
Definition: DQMNet.h:608
template<class ObjType>
void DQMImplNet< ObjType >::updatePeerMasks ( )
inlineoverrideprotectedvirtual

Implements DQMNet.

Definition at line 600 of file DQMNet.h.

601  {
602  typename PeerMap::iterator i, e;
603  for (i = peers_.begin(), e = peers_.end(); i != e; )
604  updateMask(&(i++)->second);
605  }
void updateMask(Peer *p)
Definition: DQMNet.cc:1039
PeerMap peers_
Definition: DQMNet.h:608

Member Data Documentation

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

Definition at line 608 of file DQMNet.h.