CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/EventFilter/StorageManager/src/EventStreamSelector.cc

Go to the documentation of this file.
00001 // $Id: EventStreamSelector.cc,v 1.14 2011/03/07 15:31:32 mommsen Exp $
00003 
00004 #include <cstdlib>
00005 #include <ctime>
00006 #include <vector>
00007 
00008 #include <boost/lambda/lambda.hpp>
00009 
00010 #include "EventFilter/StorageManager/interface/EventStreamSelector.h"
00011 #include "EventFilter/StorageManager/interface/Exception.h"
00012 
00013 #include "FWCore/Utilities/interface/EDMException.h"
00014 
00015 
00016 namespace stor {
00017   
00018   EventStreamSelector::EventStreamSelector( const EventStreamConfigurationInfo& configInfo ):
00019   initialized_( false ),
00020   outputModuleId_(0),
00021   configInfo_( configInfo )
00022   {
00023     srand( time(0) );
00024   }
00025   
00026   
00027   void EventStreamSelector::initialize( const InitMsgView& imv )
00028   {
00029     
00030     if( initialized_ ) return;
00031     
00032     if( configInfo_.outputModuleLabel() != imv.outputModuleLabel() ) return; 
00033     
00034     outputModuleId_ = imv.outputModuleId();
00035     
00036     edm::ParameterSet pset;
00037     pset.addParameter<std::string>( "TriggerSelector", configInfo_.triggerSelection() );
00038     pset.addParameter<Strings>( "SelectEvents", configInfo_.eventSelection() );
00039     
00040     Strings tnames;
00041     imv.hltTriggerNames( tnames );
00042     
00043     std::ostringstream errorMsg;
00044     errorMsg << "Cannot initialize edm::EventSelector for stream " <<
00045       configInfo_.streamLabel() << " requesting output module ID" <<
00046       outputModuleId_ << " with label " << configInfo_.outputModuleLabel() <<
00047       " and HLT trigger names";
00048     boost::lambda::placeholder1_type arg1;
00049     std::for_each(tnames.begin(), tnames.end(), errorMsg << boost::lambda::constant(" ") << arg1);
00050     try
00051     {
00052       eventSelector_.reset( new TriggerSelector( pset, tnames ) );
00053     }
00054     catch ( edm::Exception& e )
00055     {
00056       errorMsg << e.what();
00057       
00058       XCEPT_RAISE(stor::exception::InvalidEventSelection, errorMsg.str());
00059     }
00060     catch( std::exception &e )
00061     {
00062       errorMsg << e.what();
00063       
00064       XCEPT_RAISE(stor::exception::InvalidEventSelection, errorMsg.str());
00065     }
00066     catch(...)
00067     {
00068       errorMsg << "Unknown exception";
00069       
00070       XCEPT_RAISE(stor::exception::InvalidEventSelection, errorMsg.str());
00071     }
00072     
00073     initialized_ = true;
00074     
00075   }
00076   
00077   bool EventStreamSelector::acceptEvent( const I2OChain& ioc )
00078   {
00079     if( !initialized_ ) return false;
00080     
00081     if ( configInfo_.fractionToDisk() == 0 ) return false;
00082     
00083     if( ioc.outputModuleId() != outputModuleId_ ) return false;
00084     
00085     std::vector<unsigned char> hlt_out;
00086     ioc.hltTriggerBits( hlt_out );
00087     
00088     if ( ! eventSelector_->acceptEvent( &hlt_out[0], ioc.hltTriggerCount() ) )
00089       return false;
00090     
00091     if ( configInfo_.fractionToDisk() < 1 )
00092     {
00093       double rand = static_cast<double>(std::rand())/static_cast<double>(RAND_MAX);
00094       if ( rand > configInfo_.fractionToDisk() ) return false;
00095     }
00096     
00097     return true;
00098   }
00099   
00100 } // namespace stor
00101 
00102