MarlinMT  0.1.0
CPUCrunchingProcessor.cc
Go to the documentation of this file.
1 
2 // -- marlinmt headers
3 #include <marlinmt/Processor.h>
5 #include <marlinmt/Logging.h>
7 
8 // -- std headers
9 #include <cmath>
10 #include <ctime>
11 #include <random>
12 
13 namespace marlinmt {
14 
26 
27  public:
29  void init() override ;
30  void processEvent( EventStore * evt ) override ;
31 
32  private:
33  IntParameter _crunchTime {*this, "CrunchTime",
34  "The crunching time (unit ms)", 200 } ;
35 
36  FloatParameter _crunchSigma {*this, "CrunchSigma",
37  "Smearing factor on the crunching time using a gaussian generator (unit ms)", 0 } ;
38  };
39 
40  //--------------------------------------------------------------------------
41  //--------------------------------------------------------------------------
42 
44  Processor("CPUCrunching") {
45  // modify processor description
46  setDescription( "CPUCrunchingProcessor crunch CPU time for n milliseconds" ) ;
47  // parameters validation
48  _crunchTime.setValidator( validator::greaterEqual<int>(0) ) ;
49  _crunchSigma.setValidator( validator::greaterEqual<float>(0) ) ;
50  }
51 
52  //--------------------------------------------------------------------------
53 
55  log<DEBUG>() << "CPUCrunchingProcessor::init() called" << std::endl ;
56  // usually a good idea to
57  printParameters() ;
59  }
60 
61  //--------------------------------------------------------------------------
62 
64  auto randomSeed = ProcessorApi::getRandomSeed( this, event ) ;
65  std::default_random_engine generator( randomSeed );
66  std::normal_distribution<clock::duration_rep> distribution(0, _crunchSigma);
67  clock::duration_rep totalCrunchTime = static_cast<clock::duration_rep>(_crunchTime) + distribution(generator) ;
68  log<MESSAGE>() << "Will use total crunch time of " << totalCrunchTime << " ms" << std::endl ;
69  // crunch for n milliseconds !
70  clock::crunchFor<clock::milliseconds>(totalCrunchTime) ;
71  }
72 
73  // processor declaration
75 }
void setValidator(ValidatorFunctionT< T > validator)
Set the validator function.
Definition: Parameter.h:589
void init() override
Initialize the processor.
void processEvent(EventStore *evt) override
Process an input event.
#define MARLINMT_DECLARE_PROCESSOR(Class)
Definition: PluginManager.h:34
void setDescription(const std::string &desc)
Set the component description.
Definition: Component.cc:41
static unsigned int getRandomSeed(const Processor *const proc, EventStore *event)
Get a random seed from the event.
Simple processor crunching CPU time for n milliseconds.
float duration_rep
Definition: Utils.h:32
Processor class.
Definition: Processor.h:43
void printParameters() const
Print the component parameters.
Definition: Component.cc:118
static void registerForRandomSeeds(Processor *const proc)
Register the processor to get random seeds.
EventStore class.
Definition: EventStore.h:17