test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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, HashEqual
ObjectMap
 
typedef std::map< lat::Socket
*, ImplPeer
PeerMap
 
- 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 359 of file DQMNet.h.

Member Typedef Documentation

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

Definition at line 362 of file DQMNet.h.

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

Definition at line 365 of file DQMNet.h.

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

Definition at line 366 of file DQMNet.h.

Constructor & Destructor Documentation

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

Definition at line 374 of file DQMNet.h.

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

Definition at line 378 of file DQMNet.h.

379  {}

Member Function Documentation

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

Implements DQMNet.

Definition at line 490 of file DQMNet.h.

491  {
492  ImplPeer *ip = &peers_[s];
493  ip->socket = 0;
494  ip->sendq = 0;
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 = 0;
503  return ip;
504  }
PeerMap peers_
Definition: DQMNet.h:606
template<class ObjType>
virtual Object* DQMImplNet< ObjType >::findObject ( Peer p,
const std::string &  name,
Peer **  owner = 0 
)
inlineprotectedvirtual

Implements DQMNet.

Definition at line 383 of file DQMNet.h.

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

Implements DQMNet.

Definition at line 482 of file DQMNet.h.

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

Implements DQMNet.

Definition at line 426 of file DQMNet.h.

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

Implements DQMNet.

Definition at line 451 of file DQMNet.h.

452  {
453  uint64_t minreq
454  = (lat::Time::current()
455  - lat::TimeSpan(0, 0, 5 /* minutes */, 0, 0)).ns();
456  ImplPeer *ip = static_cast<ImplPeer *>(p);
457  typename ObjectMap::iterator i, e;
458  for (i = ip->objs.begin(), e = ip->objs.end(); i != e; ++i)
459  {
460  if (i->lastreq && i->lastreq < minreq)
461  const_cast<ObjType &>(*i).lastreq = 0;
462  const_cast<ObjType &>(*i).flags |= DQM_PROP_DEAD;
463  }
464  }
int i
Definition: DBlmapReader.cc:9
static const uint32_t DQM_PROP_DEAD
Definition: DQMNet.h:61
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 468 of file DQMNet.h.

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

Implements DQMNet.

Definition at line 507 of file DQMNet.h.

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

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

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

Implements DQMNet.

Definition at line 565 of file DQMNet.h.

566  {
567  typename PeerMap::iterator i, e;
568  typename ObjectMap::iterator oi, oe;
569  for (i = peers_.begin(), e = peers_.end(); i != e; ++i)
570  {
571  ImplPeer &p = i->second;
572  if (! p.update)
573  continue;
574 
575  if (debug_)
576  logme()
577  << "DEBUG: notifying " << p.peeraddr << std::endl;
578 
579  Bucket msg;
580  msg.next = 0;
581  sendObjectListToPeer(&msg, !p.updated || all, true);
582 
583  if (! msg.data.empty())
584  {
585  Bucket **prev = &p.sendq;
586  while (*prev)
587  prev = &(*prev)->next;
588 
589  *prev = new Bucket;
590  (*prev)->next = 0;
591  (*prev)->data.swap(msg.data);
592  }
593  p.updated = true;
594  }
595  }
int i
Definition: DBlmapReader.cc:9
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:526
bool debug_
Definition: DQMNet.h:317
PeerMap peers_
Definition: DQMNet.h:606
template<class ObjType>
virtual void DQMImplNet< ObjType >::updatePeerMasks ( void  )
inlineprotectedvirtual

Implements DQMNet.

Definition at line 598 of file DQMNet.h.

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

Member Data Documentation

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