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

typedef std::set< std::string > DirMap
 
typedef __gnu_cxx::hash_set< ObjType, HashOp, HashEqualObjectMap
 
typedef std::map< lat::Socket *, ImplPeerPeerMap
 
- Public Types inherited from DQMNet
typedef std::vector< unsigned char > DataBlob
 
typedef std::vector< QValueQReports
 
typedef std::vector< uint32_t > TagList
 
typedef std::list< WaitObjectWaitList
 

Public Member Functions

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

Protected Member Functions

virtual PeercreatePeer (lat::Socket *s)
 
virtual ObjectfindObject (Peer *p, const std::string &name, Peer **owner=0)
 
virtual PeergetPeer (lat::Socket *s)
 
virtual ObjectmakeObject (Peer *p, const std::string &name)
 
virtual void markObjectsDead (Peer *p)
 
virtual void purgeDeadObjects (Peer *p)
 
virtual void removePeer (Peer *p, lat::Socket *s)
 
virtual void sendObjectListToPeer (Bucket *msg, bool all, bool clear)
 Send all objects to a peer and optionally mark sent objects old. More...
 
virtual void sendObjectListToPeers (bool all)
 
virtual void updatePeerMasks (void)
 
- Protected Member Functions inherited from DQMNet
std::ostream & logme (void)
 
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)
 
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 360 of file DQMNet.h.

Member Typedef Documentation

template<class ObjType>
typedef std::set<std::string> DQMImplNet< ObjType >::DirMap

Definition at line 363 of file DQMNet.h.

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

Definition at line 366 of file DQMNet.h.

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

Definition at line 367 of file DQMNet.h.

Constructor & Destructor Documentation

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

Definition at line 375 of file DQMNet.h.

376  : DQMNet(appname)
377  {}
DQMNet(const std::string &appname="")
Definition: DQMNet.cc:1069
template<class ObjType>
DQMImplNet< ObjType >::~DQMImplNet ( void  )
inline

Definition at line 379 of file DQMNet.h.

380  {}

Member Function Documentation

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

Implements DQMNet.

Definition at line 491 of file DQMNet.h.

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

Implements DQMNet.

Definition at line 384 of file DQMNet.h.

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

Implements DQMNet.

Definition at line 483 of file DQMNet.h.

484  {
485  typename PeerMap::iterator pos = peers_.find(s);
486  typename PeerMap::iterator end = peers_.end();
487  return pos == end ? 0 : &pos->second;
488  }
#define end
Definition: vmac.h:37
PeerMap peers_
Definition: DQMNet.h:607
template<class ObjType>
virtual Object* DQMImplNet< ObjType >::makeObject ( Peer p,
const std::string &  name 
)
inlineprotectedvirtual

Implements DQMNet.

Definition at line 427 of file DQMNet.h.

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

Implements DQMNet.

Definition at line 452 of file DQMNet.h.

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

Implements DQMNet.

Definition at line 469 of file DQMNet.h.

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

Implements DQMNet.

Definition at line 508 of file DQMNet.h.

509  {
510  ImplPeer *ip = static_cast<ImplPeer *>(p);
511  bool needflush = ! ip->objs.empty();
512 
513  typename ObjectMap::iterator i, e;
514  for (i = ip->objs.begin(), e = ip->objs.end(); i != e; )
515  ip->objs.erase(i++);
516 
517  peers_.erase(s);
518 
519  // If we removed a peer with objects, our list of objects
520  // has changed and we need to update downstream peers.
521  if (needflush)
523  }
void sendLocalChanges(void)
Definition: DQMNet.cc:1435
PeerMap peers_
Definition: DQMNet.h:607
template<class ObjType>
virtual void DQMImplNet< ObjType >::sendObjectListToPeer ( Bucket msg,
bool  all,
bool  clear 
)
inlineprotectedvirtual

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

Implements DQMNet.

Definition at line 527 of file DQMNet.h.

528  {
529  typename PeerMap::iterator pi, pe;
530  typename ObjectMap::iterator oi, oe;
531  size_t size = 0;
532  size_t numobjs = 0;
533  for (pi = peers_.begin(), pe = peers_.end(); pi != pe; ++pi)
534  for (oi = pi->second.objs.begin(), oe = pi->second.objs.end(); oi != oe; ++oi, ++numobjs)
535  if (all || (oi->flags & DQM_PROP_NEW))
536  size += 9*sizeof(uint32_t) + oi->dirname->size()
537  + oi->objname.size() + 1 + oi->scalar.size() + oi->qdata.size()
538  + (oi->lastreq > 0 ? oi->rawdata.size() : 0);
539 
540  msg->data.reserve(msg->data.size() + size + 8 * sizeof(uint32_t));
541 
542  uint32_t nupdates = 0;
543  uint32_t words [4];
544  words[0] = sizeof(words);
545  words[1] = DQM_REPLY_LIST_BEGIN;
546  words[2] = numobjs;
547  words[3] = all;
548  copydata(msg, &words[0], sizeof(words));
549 
550  for (pi = peers_.begin(), pe = peers_.end(); pi != pe; ++pi)
551  for (oi = pi->second.objs.begin(), oe = pi->second.objs.end(); oi != oe; ++oi)
552  if (all || (oi->flags & DQM_PROP_NEW))
553  {
554  sendObjectToPeer(msg, const_cast<ObjType &>(*oi), oi->lastreq > 0);
555  if (clear)
556  const_cast<ObjType &>(*oi).flags &= ~DQM_PROP_NEW;
557  ++nupdates;
558  }
559 
560  words[1] = DQM_REPLY_LIST_END;
561  words[2] = nupdates;
562  copydata(msg, &words[0], sizeof(words));
563  }
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
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:607
template<class ObjType>
virtual void DQMImplNet< ObjType >::sendObjectListToPeers ( bool  all)
inlineprotectedvirtual

Implements DQMNet.

Definition at line 566 of file DQMNet.h.

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

Implements DQMNet.

Definition at line 599 of file DQMNet.h.

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

Member Data Documentation

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

Definition at line 607 of file DQMNet.h.