MarlinMT  0.1.0
TestProcessor.cc
Go to the documentation of this file.
1 
2 // -- marlinmt headers
3 #include <marlinmt/Processor.h>
6 #include <marlinmt/Exceptions.h>
7 #include <marlinmt/Logging.h>
9 
10 // -- std headers
11 #include <iostream>
12 #include <sstream>
13 #include <atomic>
14 
15 namespace marlinmt {
16 
30  class TestProcessor : public Processor {
31  public:
32  TestProcessor() ;
33 
37  void init() override ;
38 
41  void processRunHeader( RunHeader* run ) override ;
42 
45  void processEvent( EventStore * evt ) override ;
46 
49  void end() override ;
50 
51  protected:
52 
54  void printEndMessage() const ;
55 
56  int _nRun {0} ;
57  std::atomic_int _nEvt {0} ;
58  bool _doCalibration {false} ;
59  } ;
60 
61  //--------------------------------------------------------------------------
62  //--------------------------------------------------------------------------
63 
65  Processor("TestProcessor") {
66  setDescription( "Simple processor to test the marlinmt application."
67  " Prints run and event number." ) ;
68  }
69 
70  //--------------------------------------------------------------------------
71 
73  log<MESSAGE>() << "TestProcessor::init() " << name() << std::endl ;
74  printParameters() ;
75  }
76 
77  //--------------------------------------------------------------------------
78 
80  log<MESSAGE>() << " processRun() "
81  << run->runNumber()
82  << std::endl ;
83  _nRun++ ;
84  }
85 
86  //--------------------------------------------------------------------------
87 
89  // event counter: add +1 and get the old value.
90  // For example, if _nEvt is 0, it adds +1 and returns 0
91  auto eventCounter = _nEvt.fetch_add(1) ;
92  // This how we know if we are currently processing the first event
93  const bool firstEvent = ProcessorApi::isFirstEvent( evt ) ;
94  // Get the processor runtime conditions (not conditions data)
95  // You can use them to set boolean values that next processors
96  // in the chain can use as conditions
97  // An example usage in this processor ...
98  const bool calibrate = (eventCounter % 3 ) == 0 ;
99 
100  if( firstEvent ) {
101  log<DEBUG>() << " This is the first event ! uid = " << evt->uid() << std::endl ;
102  }
103  ProcessorApi::setReturnValue( this, evt, "Calibrating", calibrate ) ;
104 
105  if( calibrate ) {
106  log<MESSAGE>() << "processEvent() ---CALIBRATING ------ "
107  << " in event uid " << evt->uid()
108  << std::endl ;
109  }
110 
111  log<MESSAGE>() << " processing event uid " << evt->uid() << std::endl ;
112 
113  log<MESSAGE>() << "(MESSAGE) local verbosity level: " << verbosity() << std::endl ;
114 
115  // always return true for this processor
116  ProcessorApi::setReturnValue( this, evt, true ) ;
117  // set ProcessorName.EvenNumberOfEvents == true if this processor has been called 2n (n=0,1,2,...) times
118  ProcessorApi::setReturnValue( this , evt, "EvenNumberOfEvents", !( eventCounter % 2 ) ) ;
119  }
120 
121  //--------------------------------------------------------------------------
122 
124  printEndMessage() ;
125  }
126 
127  //--------------------------------------------------------------------------
128 
130  log<MESSAGE>() << " end() "
131  << " processed " << _nEvt << " events in "
132  << _nRun << " runs " << std::endl
133  << std::endl ;
134  }
135 
136  // processor declaration
138 }
static bool isFirstEvent(EventStore *event)
Whether the event is the first event to be processed.
const std::string & name() const
Get the component name.
Definition: Component.cc:23
void end() override
Called after data processing for clean up.
std::size_t uid() const
Get the event unique id.
Definition: EventStore.h:123
void init() override
Called at the begin of the job before anything is read.
std::atomic_int _nEvt
void processEvent(EventStore *evt) override
Called for every event - the working horse.
#define MARLINMT_DECLARE_PROCESSOR(Class)
Definition: PluginManager.h:34
void setDescription(const std::string &desc)
Set the component description.
Definition: Component.cc:41
void processRunHeader(RunHeader *run) override
Called for every run.
void printEndMessage() const
Test method for const.
Simple processor for testing.
const std::string & verbosity() const
Get the verbosity level.
Definition: Component.cc:77
RunHeader class.
Definition: RunHeader.h:22
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
int runNumber() const
Get the run number.
Definition: RunHeader.h:123
EventStore class.
Definition: EventStore.h:17