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

Member Typedef Documentation

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

Definition at line 345 of file DQMNet.h.

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

Definition at line 348 of file DQMNet.h.

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

Definition at line 349 of file DQMNet.h.

Constructor & Destructor Documentation

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

Definition at line 357 of file DQMNet.h.

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

Definition at line 361 of file DQMNet.h.

362  {}

Member Function Documentation

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

Implements DQMNet.

Definition at line 473 of file DQMNet.h.

474  {
475  ImplPeer *ip = &peers_[s];
476  ip->socket = 0;
477  ip->sendq = 0;
478  ip->sendpos = 0;
479  ip->mask = 0;
480  ip->source = false;
481  ip->update = false;
482  ip->updated = false;
483  ip->updates = 0;
484  ip->waiting = 0;
485  ip->automatic = 0;
486  return ip;
487  }
PeerMap peers_
Definition: DQMNet.h:589
template<class ObjType>
virtual Object* DQMImplNet< ObjType >::findObject ( Peer p,
const std::string &  name,
Peer **  owner = 0 
)
inlineprotectedvirtual

Implements DQMNet.

Definition at line 366 of file DQMNet.h.

367  {
368  size_t slash = name.rfind('/');
369  size_t dirpos = (slash == std::string::npos ? 0 : slash);
370  size_t namepos = (slash == std::string::npos ? 0 : slash+1);
371  std::string path(name, 0, dirpos);
372  ObjType proto;
373  proto.hash = dqmhash(name.c_str(), name.size());
374  proto.dirname = &path;
375  proto.objname.append(name, namepos, std::string::npos);
376 
377  typename ObjectMap::iterator pos;
378  typename PeerMap::iterator i, e;
379  if (owner)
380  *owner = 0;
381  if (p)
382  {
383  ImplPeer *ip = static_cast<ImplPeer *>(p);
384  pos = ip->objs.find(proto);
385  if (pos == ip->objs.end())
386  return 0;
387  else
388  {
389  if (owner) *owner = ip;
390  return const_cast<ObjType *>(&*pos);
391  }
392  }
393  else
394  {
395  for (i = peers_.begin(), e = peers_.end(); i != e; ++i)
396  {
397  pos = i->second.objs.find(proto);
398  if (pos != i->second.objs.end())
399  {
400  if (owner) *owner = &i->second;
401  return const_cast<ObjType *>(&*pos);
402  }
403  }
404  return 0;
405  }
406  }
int i
Definition: DBlmapReader.cc:9
list path
Definition: scaleCards.py:51
static size_t dqmhash(const void *key, size_t keylen)
Definition: DQMNet.h:199
ObjType
Definition: DisplayCommon.h:6
PeerMap peers_
Definition: DQMNet.h:589
template<class ObjType>
virtual Peer* DQMImplNet< ObjType >::getPeer ( lat::Socket *  s)
inlineprotectedvirtual

Implements DQMNet.

Definition at line 465 of file DQMNet.h.

466  {
467  typename PeerMap::iterator pos = peers_.find(s);
468  typename PeerMap::iterator end = peers_.end();
469  return pos == end ? 0 : &pos->second;
470  }
#define end
Definition: vmac.h:38
PeerMap peers_
Definition: DQMNet.h:589
template<class ObjType>
virtual Object* DQMImplNet< ObjType >::makeObject ( Peer p,
const std::string &  name 
)
inlineprotectedvirtual

Implements DQMNet.

Definition at line 409 of file DQMNet.h.

410  {
411  ImplPeer *ip = static_cast<ImplPeer *>(p);
412  size_t slash = name.rfind('/');
413  size_t dirpos = (slash == std::string::npos ? 0 : slash);
414  size_t namepos = (slash == std::string::npos ? 0 : slash+1);
415  ObjType o;
416  o.flags = 0;
417  o.tag = 0;
418  o.version = 0;
419  o.lastreq = 0;
420  o.dirname = &*ip->dirs.insert(name.substr(0, dirpos)).first;
421  o.objname.append(name, namepos, std::string::npos);
422  o.hash = dqmhash(name.c_str(), name.size());
423  return const_cast<ObjType *>(&*ip->objs.insert(o).first);
424  }
static size_t dqmhash(const void *key, size_t keylen)
Definition: DQMNet.h:199
bool first
Definition: L1TdeRCT.cc:94
ObjType
Definition: DisplayCommon.h:6
template<class ObjType>
virtual void DQMImplNet< ObjType >::markObjectsDead ( Peer p)
inlineprotectedvirtual

Implements DQMNet.

Definition at line 434 of file DQMNet.h.

435  {
436  uint64_t minreq
437  = (lat::Time::current()
438  - lat::TimeSpan(0, 0, 5 /* minutes */, 0, 0)).ns();
439  ImplPeer *ip = static_cast<ImplPeer *>(p);
440  typename ObjectMap::iterator i, e;
441  for (i = ip->objs.begin(), e = ip->objs.end(); i != e; ++i)
442  {
443  if (i->lastreq && i->lastreq < minreq)
444  const_cast<ObjType &>(*i).lastreq = 0;
445  const_cast<ObjType &>(*i).flags |= DQM_PROP_DEAD;
446  }
447  }
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
ObjType
Definition: DisplayCommon.h:6
template<class ObjType>
virtual void DQMImplNet< ObjType >::purgeDeadObjects ( Peer p)
inlineprotectedvirtual

Implements DQMNet.

Definition at line 451 of file DQMNet.h.

452  {
453  ImplPeer *ip = static_cast<ImplPeer *>(p);
454  typename ObjectMap::iterator i, e;
455  for (i = ip->objs.begin(), e = ip->objs.end(); i != e; )
456  {
457  if (i->flags & DQM_PROP_DEAD)
458  ip->objs.erase(i++);
459  else
460  ++i;
461  }
462  }
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 490 of file DQMNet.h.

491  {
492  ImplPeer *ip = static_cast<ImplPeer *>(p);
493  bool needflush = ! ip->objs.empty();
494 
495  typename ObjectMap::iterator i, e;
496  for (i = ip->objs.begin(), e = ip->objs.end(); i != e; )
497  ip->objs.erase(i++);
498 
499  peers_.erase(s);
500 
501  // If we removed a peer with objects, our list of objects
502  // has changed and we need to update downstream peers.
503  if (needflush)
505  }
int i
Definition: DBlmapReader.cc:9
void sendLocalChanges(void)
Definition: DQMNet.cc:1430
PeerMap peers_
Definition: DQMNet.h:589
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 509 of file DQMNet.h.

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

510  {
511  typename PeerMap::iterator pi, pe;
512  typename ObjectMap::iterator oi, oe;
513  size_t size = 0;
514  size_t numobjs = 0;
515  for (pi = peers_.begin(), pe = peers_.end(); pi != pe; ++pi)
516  for (oi = pi->second.objs.begin(), oe = pi->second.objs.end(); oi != oe; ++oi, ++numobjs)
517  if (all || (oi->flags & DQM_PROP_NEW))
518  size += 9*sizeof(uint32_t) + oi->dirname->size()
519  + oi->objname.size() + 1 + oi->scalar.size() + oi->qdata.size()
520  + (oi->lastreq > 0 ? oi->rawdata.size() : 0);
521 
522  msg->data.reserve(msg->data.size() + size + 8 * sizeof(uint32_t));
523 
524  uint32_t nupdates = 0;
525  uint32_t words [4];
526  words[0] = sizeof(words);
527  words[1] = DQM_REPLY_LIST_BEGIN;
528  words[2] = numobjs;
529  words[3] = all;
530  copydata(msg, &words[0], sizeof(words));
531 
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)
534  if (all || (oi->flags & DQM_PROP_NEW))
535  {
536  sendObjectToPeer(msg, const_cast<ObjType &>(*oi), oi->lastreq > 0);
537  if (clear)
538  const_cast<ObjType &>(*oi).flags &= ~DQM_PROP_NEW;
539  ++nupdates;
540  }
541 
542  words[1] = DQM_REPLY_LIST_END;
543  words[2] = nupdates;
544  copydata(msg, &words[0], sizeof(words));
545  }
static const uint32_t DQM_REPLY_LIST_END
Definition: DQMNet.h:71
const Double_t pi
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
Definition: matutil.cc:168
virtual void sendObjectToPeer(Bucket *msg, Object &o, bool data)
Definition: DQMNet.cc:413
static const uint32_t DQM_REPLY_LIST_BEGIN
Definition: DQMNet.h:70
ObjType
Definition: DisplayCommon.h:6
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:589
tuple size
Write out results.
template<class ObjType>
virtual void DQMImplNet< ObjType >::sendObjectListToPeers ( bool  all)
inlineprotectedvirtual

Implements DQMNet.

Definition at line 548 of file DQMNet.h.

549  {
550  typename PeerMap::iterator i, e;
551  typename ObjectMap::iterator oi, oe;
552  for (i = peers_.begin(), e = peers_.end(); i != e; ++i)
553  {
554  ImplPeer &p = i->second;
555  if (! p.update)
556  continue;
557 
558  if (debug_)
559  logme()
560  << "DEBUG: notifying " << p.peeraddr << std::endl;
561 
562  Bucket msg;
563  msg.next = 0;
564  sendObjectListToPeer(&msg, !p.updated || all, true);
565 
566  if (! msg.data.empty())
567  {
568  Bucket **prev = &p.sendq;
569  while (*prev)
570  prev = &(*prev)->next;
571 
572  *prev = new Bucket;
573  (*prev)->next = 0;
574  (*prev)->data.swap(msg.data);
575  }
576  p.updated = true;
577  }
578  }
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:509
bool debug_
Definition: DQMNet.h:300
PeerMap peers_
Definition: DQMNet.h:589
template<class ObjType>
virtual void DQMImplNet< ObjType >::updatePeerMasks ( void  )
inlineprotectedvirtual

Implements DQMNet.

Definition at line 581 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  }
int i
Definition: DBlmapReader.cc:9
void updateMask(Peer *p)
Definition: DQMNet.cc:1034
PeerMap peers_
Definition: DQMNet.h:589

Member Data Documentation

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