CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch2/src/EventFilter/StorageManager/src/RegistrationCollection.cc

Go to the documentation of this file.
00001 // $Id: RegistrationCollection.cc,v 1.11 2011/03/07 15:31:32 mommsen Exp $
00003 
00004 #include "EventFilter/StorageManager/interface/RegistrationCollection.h"
00005 
00006 #include <boost/pointer_cast.hpp>
00007 #include <algorithm>
00008 
00009 using namespace stor;
00010 
00011 RegistrationCollection::RegistrationCollection()
00012 {
00013   boost::mutex::scoped_lock sl( lock_ );
00014   nextConsumerId_ = ConsumerID(0);
00015   registrationAllowed_ = false;
00016 }
00017 
00018 RegistrationCollection::~RegistrationCollection() {}
00019 
00020 ConsumerID RegistrationCollection::getConsumerId()
00021 {
00022   boost::mutex::scoped_lock sl( lock_ );
00023   
00024   if( !registrationAllowed_ )
00025   {
00026     return ConsumerID(0);
00027   }
00028   
00029   return ++nextConsumerId_;
00030 }
00031 
00032 bool
00033 RegistrationCollection::addRegistrationInfo( const RegPtr ri )
00034 {
00035   boost::mutex::scoped_lock sl( lock_ );
00036   if( registrationAllowed_ )
00037   {
00038     ConsumerID cid = ri->consumerId();
00039     RegistrationMap::iterator pos = consumers_.lower_bound(cid);
00040     
00041     if ( pos != consumers_.end() && !(consumers_.key_comp()(cid, pos->first)) )
00042     {
00043       // The given ConsumerID already exists.
00044       return false;
00045     }
00046     
00047     consumers_.insert( pos, RegistrationMap::value_type(cid, ri) );
00048     return true;
00049   }
00050   else
00051   {
00052     return false;
00053   }
00054 }
00055 
00056 
00057 RegPtr RegistrationCollection::getRegistrationInfo( const ConsumerID cid ) const
00058 {
00059   boost::mutex::scoped_lock sl( lock_ );
00060   RegPtr regInfo;
00061   RegistrationMap::const_iterator pos = consumers_.find(cid);
00062   if ( pos != consumers_.end() )
00063   {
00064     pos->second->consumerContact();
00065     regInfo = pos->second;
00066   }
00067   return regInfo;
00068 }
00069 
00070 
00071 void RegistrationCollection::getEventConsumers( ConsumerRegistrations& crs ) const
00072 {
00073   boost::mutex::scoped_lock sl( lock_ );
00074   for( RegistrationMap::const_iterator it = consumers_.begin();
00075        it != consumers_.end(); ++it )
00076     {
00077       EventConsRegPtr eventConsumer =
00078         boost::dynamic_pointer_cast<EventConsumerRegistrationInfo>( it->second );
00079       if ( eventConsumer )
00080         crs.push_back( eventConsumer );
00081     }
00082   // sort the event consumers to have identical consumers sharing a queue
00083   // next to each others.
00084   utils::ptrComp<EventConsumerRegistrationInfo> comp;
00085   std::sort(crs.begin(), crs.end(), comp);
00086 }
00087 
00088 void RegistrationCollection::getDQMEventConsumers( DQMConsumerRegistrations& crs ) const
00089 {
00090   boost::mutex::scoped_lock sl( lock_ );
00091   for( RegistrationMap::const_iterator it = consumers_.begin();
00092        it != consumers_.end(); ++it )
00093     {
00094       DQMEventConsRegPtr dqmEventConsumer =
00095         boost::dynamic_pointer_cast<DQMEventConsumerRegistrationInfo>( it->second );
00096       if ( dqmEventConsumer )
00097         crs.push_back( dqmEventConsumer );
00098     }
00099 }
00100 
00101 void RegistrationCollection::enableConsumerRegistration()
00102 {
00103   //boost::mutex::scoped_lock sl( lock_ );
00104   registrationAllowed_ = true;
00105 }
00106 
00107 void RegistrationCollection::disableConsumerRegistration()
00108 {
00109   //boost::mutex::scoped_lock sl( lock_ );
00110   registrationAllowed_ = false;
00111 }
00112 
00113 void RegistrationCollection::clearRegistrations()
00114 {
00115   boost::mutex::scoped_lock sl( lock_ );
00116   consumers_.clear();
00117 }
00118 
00119 bool RegistrationCollection::registrationIsAllowed( const ConsumerID cid ) const
00120 {
00121   boost::mutex::scoped_lock sl( lock_ );
00122 
00123   RegistrationMap::const_iterator pos = consumers_.find(cid);
00124   if ( pos == consumers_.end() ) return false;
00125   pos->second->consumerContact();
00126 
00127   return registrationAllowed_;
00128 }
00129 
00130