MarlinMT  0.1.0
EventSelectorProcessor.cc
Go to the documentation of this file.
1 
2 // -- marlinmt headers
3 #include <marlinmt/Processor.h>
7 
8 // -- lcio headers
9 #include <lcio.h>
10 
11 // -- std headers
12 #include <set>
13 #include <map>
14 
15 namespace marlinmt {
16 
29  using EventNumberSet = std::set< std::pair< int, int > > ;
30 
31  public:
36 
37  // from Processor
38  void init() ;
39  void processEvent( EventStore * evt ) ;
40 
41  protected:
42  IntVectorParameter _evtList {*this, "EventList",
43  "event list - pairs of Eventnumber RunNumber" } ;
46  };
47 
48  //--------------------------------------------------------------------------
49  //--------------------------------------------------------------------------
50 
52  Processor("EventSelector") {
53  // modify processor description
54  setDescription( "EventSelectorProcessor returns true if given event was specified in EventList" ) ;
55  }
56 
57  //--------------------------------------------------------------------------
58 
60  // usually a good idea to
61  printParameters() ;
62  unsigned int nEvts = _evtList.size() ;
63  if( nEvts % 2 != 0 ) {
64  throw Exception( "EventSelectorProcessor: event list size should be even (list of run / event ids)" ) ;
65  }
66  for( unsigned i=0 ; i <nEvts ; i+=2 ) {
67  _evtSet.insert( std::make_pair( _evtList.at(i) , _evtList.at( i+1 ) ) ) ;
68  }
69  }
70 
71  //--------------------------------------------------------------------------
72 
74  auto lcevent = evt->event<EVENT::LCEvent>() ;
75  // if no events specified - always return true
76  if( _evtList.size() == 0 ) {
77  ProcessorApi::setReturnValue( this, evt, true ) ;
78  return ;
79  }
80  auto iter = _evtSet.find( std::make_pair( lcevent->getEventNumber() , lcevent->getRunNumber() ) ) ;
81  const bool isInList = (iter != _evtSet.end() ) ;
82  //-- note: this will not be printed if compiled w/o MARLINMTDEBUG=1 !
83  log<DEBUG>() << " processing event: " << lcevent->getEventNumber()
84  << " in run: " << lcevent->getRunNumber()
85  << " - in event list : " << isInList
86  << std::endl ;
87  ProcessorApi::setReturnValue( this, evt, isInList ) ;
88  }
89 
90  // plugin declaration
92 }
std::shared_ptr< T > event() const
Get the underlying event to a specific type.
Definition: EventStore.h:130
void processEvent(EventStore *evt)
Process an input event.
std::set< std::pair< int, int > > EventNumberSet
Simple event selector processor.
#define MARLINMT_DECLARE_PROCESSOR(Class)
Definition: PluginManager.h:34
void setDescription(const std::string &desc)
Set the component description.
Definition: Component.cc:41
void init()
Initialize the processor.
IntVectorParameter _evtList
The event list as a set.
auto at(typename std::vector< T >::size_type idx) const
Definition: Parameter.h:741
Processor class.
Definition: Processor.h:43
static void setReturnValue(const Processor *const proc, EventStore *event, bool value)
Set the processor return value.
void printParameters() const
Print the component parameters.
Definition: Component.cc:118
Exception class.
Definition: Exceptions.h:60
EventStore class.
Definition: EventStore.h:17