CMS 3D CMS Logo

Public Types | Public Member Functions | Private Types | Private Attributes

stor::RegistrationCollection Class Reference

#include <RegistrationCollection.h>

List of all members.

Public Types

typedef std::vector
< EventConsRegPtr
ConsumerRegistrations
typedef std::vector
< DQMEventConsRegPtr
DQMConsumerRegistrations

Public Member Functions

bool addRegistrationInfo (RegPtr)
void clearRegistrations ()
void disableConsumerRegistration ()
void enableConsumerRegistration ()
ConsumerID getConsumerId ()
void getDQMEventConsumers (DQMConsumerRegistrations &) const
void getEventConsumers (ConsumerRegistrations &) const
RegPtr getRegistrationInfo (const ConsumerID) const
 RegistrationCollection ()
bool registrationIsAllowed (const ConsumerID) const
 ~RegistrationCollection ()

Private Types

typedef std::map< ConsumerID,
RegPtr
RegistrationMap

Private Attributes

RegistrationMap consumers_
boost::mutex lock_
ConsumerID nextConsumerId_
bool registrationAllowed_

Detailed Description

Keep a collection of registered event and DQM event consumers.

Author:
mommsen
Revision:
1.8
Date:
2011/03/07 15:31:32

Definition at line 29 of file RegistrationCollection.h.


Member Typedef Documentation

Get event consumer registrations.

Definition at line 57 of file RegistrationCollection.h.

Get DQM event consumer registrations.

Definition at line 63 of file RegistrationCollection.h.

Definition at line 94 of file RegistrationCollection.h.


Constructor & Destructor Documentation

RegistrationCollection::RegistrationCollection ( )

Definition at line 11 of file RegistrationCollection.cc.

References lock_, nextConsumerId_, and registrationAllowed_.

{
  boost::mutex::scoped_lock sl( lock_ );
  nextConsumerId_ = ConsumerID(0);
  registrationAllowed_ = false;
}
RegistrationCollection::~RegistrationCollection ( )

Definition at line 18 of file RegistrationCollection.cc.

{}

Member Function Documentation

bool RegistrationCollection::addRegistrationInfo ( RegPtr  ri)

Add registration info. Return false if no registration is allowed.

Definition at line 33 of file RegistrationCollection.cc.

References consumers_, lock_, pos, and registrationAllowed_.

{
  boost::mutex::scoped_lock sl( lock_ );
  if( registrationAllowed_ )
  {
    ConsumerID cid = ri->consumerId();
    RegistrationMap::iterator pos = consumers_.lower_bound(cid);
    
    if ( pos != consumers_.end() && !(consumers_.key_comp()(cid, pos->first)) )
    {
      // The given ConsumerID already exists.
      return false;
    }
    
    consumers_.insert( pos, RegistrationMap::value_type(cid, ri) );
    return true;
  }
  else
  {
    return false;
  }
}
void RegistrationCollection::clearRegistrations ( )

Clear registrations.

Definition at line 113 of file RegistrationCollection.cc.

References consumers_, and lock_.

{
  boost::mutex::scoped_lock sl( lock_ );
  consumers_.clear();
}
void RegistrationCollection::disableConsumerRegistration ( )

Disable registration.

Definition at line 107 of file RegistrationCollection.cc.

References registrationAllowed_.

{
  //boost::mutex::scoped_lock sl( lock_ );
  registrationAllowed_ = false;
}
void RegistrationCollection::enableConsumerRegistration ( )

Enable registration.

Definition at line 101 of file RegistrationCollection.cc.

References registrationAllowed_.

{
  //boost::mutex::scoped_lock sl( lock_ );
  registrationAllowed_ = true;
}
ConsumerID RegistrationCollection::getConsumerId ( )

Return next available consumer ID or 0 if no registration is allowed.

Definition at line 20 of file RegistrationCollection.cc.

References lock_, nextConsumerId_, and registrationAllowed_.

{
  boost::mutex::scoped_lock sl( lock_ );
  
  if( !registrationAllowed_ )
  {
    return ConsumerID(0);
  }
  
  return ++nextConsumerId_;
}
void RegistrationCollection::getDQMEventConsumers ( DQMConsumerRegistrations crs) const

Definition at line 88 of file RegistrationCollection.cc.

References consumers_, and lock_.

{
  boost::mutex::scoped_lock sl( lock_ );
  for( RegistrationMap::const_iterator it = consumers_.begin();
       it != consumers_.end(); ++it )
    {
      DQMEventConsRegPtr dqmEventConsumer =
        boost::dynamic_pointer_cast<DQMEventConsumerRegistrationInfo>( it->second );
      if ( dqmEventConsumer )
        crs.push_back( dqmEventConsumer );
    }
}
void RegistrationCollection::getEventConsumers ( ConsumerRegistrations crs) const

Definition at line 71 of file RegistrationCollection.cc.

References consumers_, lock_, and python::multivaluedict::sort().

{
  boost::mutex::scoped_lock sl( lock_ );
  for( RegistrationMap::const_iterator it = consumers_.begin();
       it != consumers_.end(); ++it )
    {
      EventConsRegPtr eventConsumer =
        boost::dynamic_pointer_cast<EventConsumerRegistrationInfo>( it->second );
      if ( eventConsumer )
        crs.push_back( eventConsumer );
    }
  // sort the event consumers to have identical consumers sharing a queue
  // next to each others.
  utils::ptrComp<EventConsumerRegistrationInfo> comp;
  std::sort(crs.begin(), crs.end(), comp);
}
RegPtr RegistrationCollection::getRegistrationInfo ( const ConsumerID  cid) const

Get registration info for ConsumerID. Returns empty pointer if not found.

Definition at line 57 of file RegistrationCollection.cc.

References consumers_, lock_, and pos.

{
  boost::mutex::scoped_lock sl( lock_ );
  RegPtr regInfo;
  RegistrationMap::const_iterator pos = consumers_.find(cid);
  if ( pos != consumers_.end() )
  {
    pos->second->consumerContact();
    regInfo = pos->second;
  }
  return regInfo;
}
bool RegistrationCollection::registrationIsAllowed ( const ConsumerID  cid) const

Test if registration is allowed.

Definition at line 119 of file RegistrationCollection.cc.

References consumers_, lock_, pos, and registrationAllowed_.

{
  boost::mutex::scoped_lock sl( lock_ );

  RegistrationMap::const_iterator pos = consumers_.find(cid);
  if ( pos == consumers_.end() ) return false;
  pos->second->consumerContact();

  return registrationAllowed_;
}

Member Data Documentation

Definition at line 90 of file RegistrationCollection.h.

Referenced by getConsumerId(), and RegistrationCollection().