MarlinMT  0.1.0
Statusmonitor.cc
Go to the documentation of this file.
1 
2 // -- marlinmt headers
3 #include <marlinmt/Processor.h>
5 #include <marlinmt/Logging.h>
6 
7 // -- std headers
8 #include <string>
9 #include <iostream>
10 #include <iomanip>
11 #include <cmath>
12 #include <atomic>
13 
14 namespace marlinmt {
15 
27  class Statusmonitor : public Processor {
28 
29  public:
30  Statusmonitor() ;
31 
32  void init() override ;
33 
36  void processRunHeader( RunHeader* run ) override ;
37 
40  void processEvent( EventStore * evt ) override ;
41 
44  void end() override ;
45 
46  private:
47  UIntParameter _howOften {*this, "howOften",
48  "Print event number every N events", 1 } ;
49 
50  // runtime members
51  int _nRun {0} ;
52  std::atomic<int> _nEvt {0} ;
53  };
54 
55  //--------------------------------------------------------------------------
56  //--------------------------------------------------------------------------
57 
58  Statusmonitor::Statusmonitor() : Processor("Statusmonitor") {
59  // modify processor description
60  setDescription( "Statusmonitor prints out information on running Marlin Job: Prints number of runs run and current number of the event. Counting is sequential and not the run or event ID." ) ;
61  // no need to lock, this processor is thread safe
63  // don't duplicate since it is thread safe and hold no big data
65  }
66 
67  //--------------------------------------------------------------------------
68 
70  log<DEBUG>() << "INIT CALLED " << std::endl ;
71  // usually a good idea to
72  printParameters() ;
73  }
74 
75  //--------------------------------------------------------------------------
76 
78  _nRun++ ;
79  }
80 
81  //--------------------------------------------------------------------------
82 
84  auto eventid = _nEvt.fetch_add(1) ;
85  if (eventid % _howOften == 0) {
86  log<MESSAGE>()
87  << " ===== Run : " << std::setw(7) << _nRun
88  << " Event: " << std::setw(7) << eventid << std::endl;
89  }
90  }
91 
92  //--------------------------------------------------------------------------
93 
95  log<MESSAGE>() << "Statusmonitor::end() " << name() << " processed " << _nEvt << " events in " << _nRun << " runs" << std::endl ;
96  }
97 
98  // processor declaration
100 }
void end() override
Called after data processing for clean up.
const std::string & name() const
Get the component name.
Definition: Component.cc:23
void setRuntimeOption(ERuntimeOption option, bool value)
Force the runtime option to a given boolean value.
Definition: Processor.cc:37
Simple processor for writing out a status message every n-th event.
void init() override
Initialize the processor.
#define MARLINMT_DECLARE_PROCESSOR(Class)
Definition: PluginManager.h:34
void processRunHeader(RunHeader *run) override
Called for every run.
void setDescription(const std::string &desc)
Set the component description.
Definition: Component.cc:41
void processEvent(EventStore *evt) override
Called for every event - the working horse.
Whether the processor has to be executed in a critical section.
RunHeader class.
Definition: RunHeader.h:22
Processor class.
Definition: Processor.h:43
void printParameters() const
Print the component parameters.
Definition: Component.cc:118
std::atomic< int > _nEvt
EventStore class.
Definition: EventStore.h:17