Marlin  01.17.01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TestProcessor.cc
Go to the documentation of this file.
1 #include "marlin/TestProcessor.h"
2 #include "marlin/Exceptions.h"
3 #include <iostream>
4 #include <sstream>
5 
7 
8 
9 #include "streamlog/streamlog.h"
10 
11 namespace marlin{
12 
13 
14 
16 
17 
19  _nRun (-1),
20  _nEvt(-1),
21  _doCalibration(false),
22  _nLoops(-1) {
23 
24  _description = "Simple processor to test the marlin application."
25  " Prints run and event number." ;
26  }
27 
29 
30  streamlog_out( MESSAGE ) << "TestProcessor::init() " << name()
31  << std::endl
32  << " parameters: " << std::endl
33  << *parameters()
34  << std::endl ;
35 
36 
37 #ifdef MARLIN_VERSION_GE
38 #if MARLIN_VERSION_GE( 0, 9, 8 )
39  streamlog_out( DEBUG ) << " marlin version is g.e. 0.9.8 " << std::endl ;
40 #endif
41 #endif
42 
43  _nRun = 0 ;
44  _nEvt = 0 ;
45  _doCalibration = false ;
46  _nLoops = 0 ;
47 
48 
49  }
50 
51  void TestProcessor::processRunHeader( LCRunHeader* run) {
52 
53 
54  streamlog_out( MESSAGE ) << " processRun() "
55  << run->getRunNumber()
56  << std::endl ;
57 
58  _nRun++ ;
59  }
60 
61  void TestProcessor::processEvent( LCEvent * evt ) {
62 
63 
64  _nEvt ++ ;
65 
66  //------------ example code that tests/demonstrates ------------
67  //------------ the usage of Exceptions to steer program flow ------------
68  //
69  // --- skip every 7th event --------------
70 
71  //if( !( _nEvt % 7 ) )
72  // throw SkipEventException( this ) ;
73 
74  // --- stop afteer processing 80 events -----
75 
76  // if( _nEvt == 80 )
77  // throw StopProcessingException( this ) ;
78 
79  // --- loop 3 times over the first 3 events and do a 'calibration' ) ------
80 
81  if( isFirstEvent() ){
82  _doCalibration = true ;
83  _nLoops = 0 ;
84 
85  streamlog_out( DEBUG ) << " initialize _doCalibration and _nLoops in first event : " << evt->getEventNumber()
86  << " run " << evt->getRunNumber() << std::endl ;
87  }
88 
89  setReturnValue( "Calibrating" , false ) ;
90 
91  if( _doCalibration ) {
92 
93  setReturnValue( "Calibrating" , true ) ;
94 
95  // message<MESSAGE>( log()
96  streamlog_out( MESSAGE) << "processEvent() ---CALIBRATING ------ "
97  << " in event " << evt->getEventNumber() << " (run "
98  << evt->getRunNumber() << ") "
99  << std::endl ;
100 
101 // ) ;
102 
103 
104  // your calibration goes here ....
105 
106 
107 
108  // ---------------
109  if( _nEvt == 3 ){
110 
111  _nEvt = 0 ;
112  ++_nLoops ;
113 
114  if( _nLoops == 3 ){
115 
116  _doCalibration = false ;
117 
118  }else{
119 
120  throw RewindDataFilesException( this ) ;
121  }
122  }
123  }
124 
125  //---------end example code ----------------------------------------
126 
127  streamlog_out(MESSAGE) << " processing event " << evt->getEventNumber()
128  << " in run " << evt->getRunNumber()
129  << std::endl ;
130 
131 
132 // streamlog_out(DEBUG) << "(DEBUG) local verbosity level: " << logLevelName() << std::endl ;
133  streamlog_out(MESSAGE) << "(MESSAGE) local verbosity level: " << logLevelName() << std::endl ;
134 // streamlog_out(WARNING) << "(WARNING) local verbosity level: " << logLevelName() << std::endl ;
135 // streamlog_out(ERROR) << "(ERROR) local verbosity level: " << logLevelName() << std::endl ;
136 
137 
138 
139 
140  // always return true for ProcessorName
141  setReturnValue( true ) ;
142 
143  // set ProcessorName.EvenNumberOfEvents == true if this processor has been called 2n (n=0,1,2,...) times
144  setReturnValue("EvenNumberOfEvents", !( _nEvt % 2 ) ) ;
145 
146 
147  }
148 
149  void TestProcessor::check( LCEvent * evt ) {
150 
151  streamlog_out(DEBUG) << " check() " // << dummy_method()
152  << evt->getEventNumber()
153  << " (run " << evt->getRunNumber() << ") "
154  << std::endl ;
155 
156 
157  }
158 
160 
161  printEndMessage() ;
162 
163  }
164 
166 
167  streamlog_out(MESSAGE) << " end() "
168  << " processed " << _nEvt << " events in "
169  << _nRun << " runs " << std::endl
170  << std::endl ;
171 
172 
173  // test deprecated method message
174  message<DEBUG>( " and this is really the final DEBUG message ....") ;
175  }
176 
177 }// namespace marlin
virtual void check(LCEvent *evt)
Called for every event - right after processEvent() has been called for this processor.
RewindDataFilesException used to stop the current proccessing of events, rewind to the first event an...
Definition: Exceptions.h:70
virtual const std::string & name() const
Return name of this processor.
Definition: Processor.h:132
virtual void processRunHeader(LCRunHeader *run)
Called for every run.
T endl(T...args)
TestProcessor aTestProcessor
virtual std::shared_ptr< StringParameters > parameters()
Return parameters defined for this Processor.
Definition: Processor.h:141
void setReturnValue(bool val)
Set the return value for this processor - typically at end of processEvent().
Definition: Processor.cc:232
virtual const std::string & logLevelName() const
Return name of the local verbosity level of this processor - &quot;&quot; if not set.
Definition: Processor.h:136
bool isFirstEvent()
True if first event in processEvent(evt) - use this e.g.
Definition: Processor.h:198
void printEndMessage() const
Test method for const.
virtual void processEvent(LCEvent *evt)
Called for every event - the working horse.
Base class for Marlin processors.
Definition: Processor.h:64
virtual void init()
Called at the begin of the job before anything is read.
std::string _description
Describes what the processor does.
Definition: Processor.h:452
virtual void end()
Called after data processing for clean up.
Simple processor for testing.
Definition: TestProcessor.h:26