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

Member Typedef Documentation

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

Definition at line 361 of file DQMNet.h.

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

Definition at line 364 of file DQMNet.h.

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

Definition at line 365 of file DQMNet.h.

Constructor & Destructor Documentation

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

Definition at line 373 of file DQMNet.h.

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

Definition at line 377 of file DQMNet.h.

378  {}

Member Function Documentation

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

Implements DQMNet.

Definition at line 489 of file DQMNet.h.

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

Implements DQMNet.

Definition at line 382 of file DQMNet.h.

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

Implements DQMNet.

Definition at line 481 of file DQMNet.h.

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

Implements DQMNet.

Definition at line 425 of file DQMNet.h.

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

Implements DQMNet.

Definition at line 450 of file DQMNet.h.

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

468  {
469  ImplPeer *ip = static_cast<ImplPeer *>(p);
470  typename ObjectMap::iterator i, e;
471  for (i = ip->objs.begin(), e = ip->objs.end(); i != e; )
472  {
473  if (i->flags & DQM_PROP_DEAD)
474  ip->objs.erase(i++);
475  else
476  ++i;
477  }
478  }
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 506 of file DQMNet.h.

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

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

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

Implements DQMNet.

Definition at line 564 of file DQMNet.h.

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

Implements DQMNet.

Definition at line 597 of file DQMNet.h.

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

Member Data Documentation

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