CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EventStreamSelector.cc
Go to the documentation of this file.
1 // $Id: EventStreamSelector.cc,v 1.14 2011/03/07 15:31:32 mommsen Exp $
3 
4 #include <cstdlib>
5 #include <ctime>
6 #include <vector>
7 
8 #include <boost/lambda/lambda.hpp>
9 
12 
14 
15 
16 namespace stor {
17 
19  initialized_( false ),
20  outputModuleId_(0),
21  configInfo_( configInfo )
22  {
23  srand( time(0) );
24  }
25 
26 
28  {
29 
30  if( initialized_ ) return;
31 
32  if( configInfo_.outputModuleLabel() != imv.outputModuleLabel() ) return;
33 
35 
36  edm::ParameterSet pset;
37  pset.addParameter<std::string>( "TriggerSelector", configInfo_.triggerSelection() );
38  pset.addParameter<Strings>( "SelectEvents", configInfo_.eventSelection() );
39 
40  Strings tnames;
41  imv.hltTriggerNames( tnames );
42 
43  std::ostringstream errorMsg;
44  errorMsg << "Cannot initialize edm::EventSelector for stream " <<
45  configInfo_.streamLabel() << " requesting output module ID" <<
46  outputModuleId_ << " with label " << configInfo_.outputModuleLabel() <<
47  " and HLT trigger names";
48  boost::lambda::placeholder1_type arg1;
49  std::for_each(tnames.begin(), tnames.end(), errorMsg << boost::lambda::constant(" ") << arg1);
50  try
51  {
52  eventSelector_.reset( new TriggerSelector( pset, tnames ) );
53  }
54  catch ( edm::Exception& e )
55  {
56  errorMsg << e.what();
57 
58  XCEPT_RAISE(stor::exception::InvalidEventSelection, errorMsg.str());
59  }
60  catch( std::exception &e )
61  {
62  errorMsg << e.what();
63 
64  XCEPT_RAISE(stor::exception::InvalidEventSelection, errorMsg.str());
65  }
66  catch(...)
67  {
68  errorMsg << "Unknown exception";
69 
70  XCEPT_RAISE(stor::exception::InvalidEventSelection, errorMsg.str());
71  }
72 
73  initialized_ = true;
74 
75  }
76 
78  {
79  if( !initialized_ ) return false;
80 
81  if ( configInfo_.fractionToDisk() == 0 ) return false;
82 
83  if( ioc.outputModuleId() != outputModuleId_ ) return false;
84 
85  std::vector<unsigned char> hlt_out;
86  ioc.hltTriggerBits( hlt_out );
87 
88  if ( ! eventSelector_->acceptEvent( &hlt_out[0], ioc.hltTriggerCount() ) )
89  return false;
90 
91  if ( configInfo_.fractionToDisk() < 1 )
92  {
93  double rand = static_cast<double>(std::rand())/static_cast<double>(RAND_MAX);
94  if ( rand > configInfo_.fractionToDisk() ) return false;
95  }
96 
97  return true;
98  }
99 
100 } // namespace stor
101 
102 
virtual char const * what() const
Definition: Exception.cc:141
const std::string & triggerSelection() const
std::vector< std::string > Strings
Definition: MsgTools.h:18
EventStreamSelector(const EventStreamConfigurationInfo &)
bool acceptEvent(const I2OChain &)
void hltTriggerNames(Strings &save_here) const
Definition: InitMessage.cc:142
void hltTriggerBits(std::vector< unsigned char > &bitList) const
Definition: I2OChain.cc:565
TriggerSelectorPtr eventSelector_
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:145
std::string outputModuleLabel() const
Definition: InitMessage.cc:132
void initialize(const InitMsgView &)
uint32 outputModuleId() const
Definition: InitMessage.h:76
uint32_t hltTriggerCount() const
Definition: I2OChain.cc:555
Signal rand(Signal arg)
Definition: vlib.cc:442
const EventStreamConfigurationInfo configInfo_
const std::string & outputModuleLabel() const
uint32_t outputModuleId() const
Definition: I2OChain.cc:505